Skip to content

Commit

Permalink
tdweb: temporary fix to access Module.FS before promise is completed
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 32af58ee1994919c75d50f8a2da2643a20bf166c
  • Loading branch information
arseny30 committed Oct 9, 2020
1 parent 8fcf774 commit 00049a8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions example/web/tdweb/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
26 changes: 20 additions & 6 deletions example/web/tdweb/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
Expand All @@ -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;
}

Expand All @@ -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');
},
Expand All @@ -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;
}

Expand Down Expand Up @@ -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'
]),
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
createTdwebModule.ready.FS = Module.FS;

0 comments on commit 00049a8

Please sign in to comment.