You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recent runtime refactoring did not add support for exporting the methods that were moved out of Runtime.. This fixes that, and refactors that exporting code to a single convenient location. It also adds a warning if an invalid item is asked to be exported.
@@ -290,42 +290,132 @@ function isExportedByForceFilesystem(name) {
290
290
name==='removeRunDependency';
291
291
}
292
292
293
-
// optionally export something.
294
-
// in ASSERTIONS mode we show a useful error if it is used without
295
-
// being exported. how we show the message depends on whether it's
296
-
// a function (almost all of them) or a number.
297
-
functionmaybeExport(name,isNumber){
298
-
// if requested to be exported, export it
299
-
if(nameinEXPORTED_RUNTIME_METHODS_SET){
300
-
varexported=name;
301
-
if(isFSPrefixed(exported)){
302
-
// this is a filesystem value, FS.x exported as FS_x
303
-
exported='FS.'+exported.substr(3);
293
+
// export parts of the JS runtime that the user asked for
294
+
functionexportRuntime(){
295
+
// optionally export something.
296
+
// in ASSERTIONS mode we show a useful error if it is used without
297
+
// being exported. how we show the message depends on whether it's
298
+
// a function (almost all of them) or a number.
299
+
functionmaybeExport(name,isNumber){
300
+
// if requested to be exported, export it
301
+
if(nameinEXPORTED_RUNTIME_METHODS_SET){
302
+
varexported=name;
303
+
if(isFSPrefixed(exported)){
304
+
// this is a filesystem value, FS.x exported as FS_x
305
+
exported='FS.'+exported.substr(3);
306
+
}
307
+
return'Module["'+name+'"] = '+exported+';';
304
308
}
305
-
return'Module["'+name+'"] = '+exported+';';
309
+
// do not export it. but if ASSERTIONS, emit a
310
+
// stub with an error, so the user gets a message
311
+
// if it is used, that they should export it
312
+
if(ASSERTIONS){
313
+
// check if it already exists, to support EXPORT_ALL and other cases
314
+
// (we could optimize this, but in ASSERTIONS mode code size doesn't
315
+
// matter anyhow)
316
+
varextra='';
317
+
if(isExportedByForceFilesystem(name)){
318
+
extra='. Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you';
319
+
}
320
+
if(!isNumber){
321
+
return'if (!Module["'+name+'"]) Module["'+name+'"] = function() { abort("\''+name+'\' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)'+extra+'") };';
322
+
}else{
323
+
return'if (!Module["'+name+'"]) Object.defineProperty(Module, "'+name+'", { get: function() { abort("\''+name+'\' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)'+extra+'") } });';
324
+
}
325
+
}
326
+
return'';
327
+
}
328
+
329
+
functionmaybeExportNumber(name){
330
+
returnmaybeExport(name,true);
306
331
}
307
-
// do not export it. but if ASSERTIONS, emit a
308
-
// stub with an error, so the user gets a message
309
-
// if it is used, that they should export it
332
+
333
+
// All possible runtime elements to export
334
+
varruntimeElements=[
335
+
'intArrayFromString',
336
+
'intArrayToString',
337
+
'ccall',
338
+
'cwrap',
339
+
'setValue',
340
+
'getValue',
341
+
'allocate',
342
+
'getMemory',
343
+
'Pointer_stringify',
344
+
'AsciiToString',
345
+
'stringToAscii',
346
+
'UTF8ArrayToString',
347
+
'UTF8ToString',
348
+
'stringToUTF8Array',
349
+
'stringToUTF8',
350
+
'UTF16ToString',
351
+
'stringToUTF16',
352
+
'lengthBytesUTF16',
353
+
'UTF32ToString',
354
+
'stringToUTF32',
355
+
'lengthBytesUTF32',
356
+
'stackTrace',
357
+
'addOnPreRun',
358
+
'addOnInit',
359
+
'addOnPreMain',
360
+
'addOnExit',
361
+
'addOnPostRun',
362
+
'writeStringToMemory',
363
+
'writeArrayToMemory',
364
+
'writeAsciiToMemory',
365
+
'addRunDependency',
366
+
'removeRunDependency',
367
+
'FS',
368
+
'FS_createFolder',
369
+
'FS_createPath',
370
+
'FS_createDataFile',
371
+
'FS_createPreloadedFile',
372
+
'FS_createLazyFile',
373
+
'FS_createLink',
374
+
'FS_createDevice',
375
+
'FS_unlink',
376
+
'GL',
377
+
'staticAlloc',
378
+
'dynamicAlloc',
379
+
'warnOnce',
380
+
'loadDynamicLibrary',
381
+
'loadWebAssemblyModule',
382
+
'getLEB',
383
+
'getFunctionTables',
384
+
'alignFunctionTables',
385
+
'registerFunctions',
386
+
'addFunction',
387
+
'removeFunction',
388
+
'getFuncWrapper',
389
+
'prettyPrint',
390
+
'makeBigInt',
391
+
'dynCall',
392
+
'getCompilerSetting',
393
+
];
394
+
if(SUPPORT_BASE64_EMBEDDING){
395
+
runtimeElements.push('intArrayFromBase64');
396
+
runtimeElements.push('tryParseAsDataURI');
397
+
}
398
+
varruntimeNumbers=[
399
+
'ALLOC_NORMAL',
400
+
'ALLOC_STACK',
401
+
'ALLOC_STATIC',
402
+
'ALLOC_DYNAMIC',
403
+
'ALLOC_NONE',
404
+
];
310
405
if(ASSERTIONS){
311
-
// check if it already exists, to support EXPORT_ALL and other cases
312
-
// (we could optimize this, but in ASSERTIONS mode code size doesn't
313
-
// matter anyhow)
314
-
varextra='';
315
-
if(isExportedByForceFilesystem(name)){
316
-
extra='. Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you';
317
-
}
318
-
if(!isNumber){
319
-
return'if (!Module["'+name+'"]) Module["'+name+'"] = function() { abort("\''+name+'\' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)'+extra+'") };';
320
-
}else{
321
-
return'if (!Module["'+name+'"]) Object.defineProperty(Module, "'+name+'", { get: function() { abort("\''+name+'\' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)'+extra+'") } });';
406
+
// check all exported things exist, warn about typos
407
+
for(varnameinEXPORTED_RUNTIME_METHODS_SET){
408
+
if(runtimeElements.indexOf(name)<0&&
409
+
runtimeNumbers.indexOf(name)<0){
410
+
printErr('warning: invalid item (maybe a typo?) in EXPORTED_RUNTIME_METHODS: '+name);
0 commit comments