Skip to content

Commit 00049a8

Browse files
committed
tdweb: temporary fix to access Module.FS before promise is completed
GitOrigin-RevId: 32af58ee1994919c75d50f8a2da2643a20bf166c
1 parent 8fcf774 commit 00049a8

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ if (EMSCRIPTEN)
113113
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM=1")
114114
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s WASM=1")
115115
endif()
116+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --post-js ${CMAKE_CURRENT_SOURCE_DIR}/post.js")
116117
endif()
117118

118119
if (NOT OPENSSL_FOUND)

example/web/tdweb/src/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class TdClient {
169169
'receive from worker: ',
170170
JSON.parse(
171171
JSON.stringify(response, (key, value) => {
172-
if (key === 'arr' || key == 'data') {
172+
if (key === 'arr' || key === 'data') {
173173
return undefined;
174174
}
175175
return value;
@@ -233,7 +233,12 @@ class TdClient {
233233
}
234234
for (const key in response) {
235235
const field = response[key];
236-
if (field && typeof field === 'object' && key != 'data' && key != 'arr') {
236+
if (
237+
field &&
238+
typeof field === 'object' &&
239+
key !== 'data' &&
240+
key !== 'arr'
241+
) {
237242
response[key] = this.prepareResponse(field);
238243
}
239244
}

example/web/tdweb/src/worker.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async function loadTdlibWasm(onFS, wasmUrl) {
7070
if (wasmUrl) {
7171
td_wasm = wasmUrl;
7272
}
73-
const module = await createTdwebModule({
73+
let module = createTdwebModule({
7474
onRuntimeInitialized: () => {
7575
log.info('runtime intialized');
7676
},
@@ -85,8 +85,11 @@ async function loadTdlibWasm(onFS, wasmUrl) {
8585
},
8686
ENVIROMENT: 'WORKER'
8787
});
88+
onFS(module.FS); // hack
89+
log.info('Wait module');
90+
module = await module;
8891
log.info('Got module', module);
89-
onFS(module.FS);
92+
//onFS(module.FS);
9093
return module;
9194
}
9295

@@ -97,7 +100,7 @@ async function loadTdlibAsmjs(onFS) {
97100
console.log('got td_asm.js', createTdwebModule);
98101
const fromFile = 'td_asmjs.js.mem';
99102
const toFile = td_asmjs_mem_release;
100-
const module = await createTdwebModule({
103+
let module = createTdwebModule({
101104
onRuntimeInitialized: () => {
102105
console.log('runtime intialized');
103106
},
@@ -109,7 +112,11 @@ async function loadTdlibAsmjs(onFS) {
109112
},
110113
ENVIROMENT: 'WORKER'
111114
});
112-
onFS(module.FS);
115+
onFS(module.FS); // hack
116+
log.info('Wait module');
117+
module = await module;
118+
log.info('Got module', module);
119+
//onFS(module.FS);
113120
return module;
114121
}
115122

@@ -608,7 +615,10 @@ class TdClient {
608615
log.info('got TdModule');
609616
this.td_functions = {
610617
td_create: this.TdModule.cwrap('td_emscripten_create', 'number', []),
611-
td_send: this.TdModule.cwrap('td_emscripten_send', null, ['number', 'string']),
618+
td_send: this.TdModule.cwrap('td_emscripten_send', null, [
619+
'number',
620+
'string'
621+
]),
612622
td_execute: this.TdModule.cwrap('td_emscripten_execute', 'string', [
613623
'string'
614624
]),
@@ -621,7 +631,11 @@ class TdClient {
621631
})
622632
);
623633
},
624-
td_get_timeout: this.TdModule.cwrap('td_emscripten_get_timeout', 'number', [])
634+
td_get_timeout: this.TdModule.cwrap(
635+
'td_emscripten_get_timeout',
636+
'number',
637+
[]
638+
)
625639
};
626640
//this.onFS(this.TdModule.FS);
627641
this.FS = this.TdModule.FS;

post.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
createTdwebModule.ready.FS = Module.FS;

0 commit comments

Comments
 (0)