tdweb: temporary fix to access Module.FS before promise is completed

GitOrigin-RevId: 32af58ee1994919c75d50f8a2da2643a20bf166c
This commit is contained in:
Arseny Smirnov 2020-10-09 19:40:13 +03:00
parent 8fcf7740d2
commit 00049a842a
4 changed files with 29 additions and 8 deletions

View File

@ -113,6 +113,7 @@ if (EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s WASM=1")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --post-js ${CMAKE_CURRENT_SOURCE_DIR}/post.js")
endif()
if (NOT OPENSSL_FOUND)

View File

@ -169,7 +169,7 @@ class TdClient {
'receive from worker: ',
JSON.parse(
JSON.stringify(response, (key, value) => {
if (key === 'arr' || key == 'data') {
if (key === 'arr' || key === 'data') {
return undefined;
}
return value;
@ -233,7 +233,12 @@ class TdClient {
}
for (const key in response) {
const field = response[key];
if (field && typeof field === 'object' && key != 'data' && key != 'arr') {
if (
field &&
typeof field === 'object' &&
key !== 'data' &&
key !== 'arr'
) {
response[key] = this.prepareResponse(field);
}
}

View File

@ -70,7 +70,7 @@ async function loadTdlibWasm(onFS, wasmUrl) {
if (wasmUrl) {
td_wasm = wasmUrl;
}
const module = await createTdwebModule({
let module = createTdwebModule({
onRuntimeInitialized: () => {
log.info('runtime intialized');
},
@ -85,8 +85,11 @@ async function loadTdlibWasm(onFS, wasmUrl) {
},
ENVIROMENT: 'WORKER'
});
onFS(module.FS); // hack
log.info('Wait module');
module = await module;
log.info('Got module', module);
onFS(module.FS);
//onFS(module.FS);
return module;
}
@ -97,7 +100,7 @@ async function loadTdlibAsmjs(onFS) {
console.log('got td_asm.js', createTdwebModule);
const fromFile = 'td_asmjs.js.mem';
const toFile = td_asmjs_mem_release;
const module = await createTdwebModule({
let module = createTdwebModule({
onRuntimeInitialized: () => {
console.log('runtime intialized');
},
@ -109,7 +112,11 @@ async function loadTdlibAsmjs(onFS) {
},
ENVIROMENT: 'WORKER'
});
onFS(module.FS);
onFS(module.FS); // hack
log.info('Wait module');
module = await module;
log.info('Got module', module);
//onFS(module.FS);
return module;
}
@ -608,7 +615,10 @@ class TdClient {
log.info('got TdModule');
this.td_functions = {
td_create: this.TdModule.cwrap('td_emscripten_create', 'number', []),
td_send: this.TdModule.cwrap('td_emscripten_send', null, ['number', 'string']),
td_send: this.TdModule.cwrap('td_emscripten_send', null, [
'number',
'string'
]),
td_execute: this.TdModule.cwrap('td_emscripten_execute', 'string', [
'string'
]),
@ -621,7 +631,11 @@ class TdClient {
})
);
},
td_get_timeout: this.TdModule.cwrap('td_emscripten_get_timeout', 'number', [])
td_get_timeout: this.TdModule.cwrap(
'td_emscripten_get_timeout',
'number',
[]
)
};
//this.onFS(this.TdModule.FS);
this.FS = this.TdModule.FS;

1
post.js Normal file
View File

@ -0,0 +1 @@
createTdwebModule.ready.FS = Module.FS;