Skip to content

Commit 5ed0544

Browse files
committed
Remove some Module property assertions. NFC
These are hindering work on other PRs such as emscripten-core#24005. I've tried a few other ways to unify and/or change these but simply removing this mechanism and simplifying things seems like the cleanest approach. All of the API for which were attaching this assertion have been removed for well over a year so I think the loss is very minimal.
1 parent 920fa00 commit 5ed0544

9 files changed

+11
-90
lines changed

Diff for: src/parseTools.mjs

+1-12
Original file line numberDiff line numberDiff line change
@@ -868,12 +868,6 @@ function isSymbolNeeded(symName) {
868868
return false;
869869
}
870870

871-
function makeRemovedModuleAPIAssert(moduleName, localName) {
872-
if (!ASSERTIONS) return '';
873-
localName ||= moduleName;
874-
return `legacyModuleProp('${moduleName}', '${localName}');`;
875-
}
876-
877871
function checkReceiving(name) {
878872
// ALL_INCOMING_MODULE_JS_API contains all valid incoming module API symbols
879873
// so calling makeModuleReceive* with a symbol not in this list is an error
@@ -890,7 +884,6 @@ function makeModuleReceive(localName, moduleName) {
890884
// but sometimes they must differ.
891885
ret = `\nif (Module['${moduleName}']) ${localName} = Module['${moduleName}'];`;
892886
}
893-
ret += makeRemovedModuleAPIAssert(moduleName, localName);
894887
return ret;
895888
}
896889

@@ -903,7 +896,7 @@ function makeModuleReceiveExpr(name, defaultValue) {
903896
}
904897
}
905898

906-
function makeModuleReceiveWithVar(localName, moduleName, defaultValue, noAssert) {
899+
function makeModuleReceiveWithVar(localName, moduleName, defaultValue) {
907900
moduleName ||= localName;
908901
checkReceiving(moduleName);
909902
let ret = `var ${localName}`;
@@ -919,9 +912,6 @@ function makeModuleReceiveWithVar(localName, moduleName, defaultValue, noAssert)
919912
ret += ` = Module['${moduleName}'];`;
920913
}
921914
}
922-
if (!noAssert) {
923-
ret += makeRemovedModuleAPIAssert(moduleName, localName);
924-
}
925915
return ret;
926916
}
927917

@@ -1159,7 +1149,6 @@ addToCompileTimeContext({
11591149
makeModuleReceiveExpr,
11601150
makeModuleReceiveWithVar,
11611151
makeRemovedFSAssert,
1162-
makeRemovedModuleAPIAssert,
11631152
makeRetainedCompilerSettings,
11641153
makeReturn64,
11651154
makeSetValue,

Diff for: src/preamble.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
1616

1717
#if RELOCATABLE
18-
{{{ makeModuleReceiveWithVar('dynamicLibraries', undefined, '[]', true) }}}
18+
{{{ makeModuleReceiveWithVar('dynamicLibraries', undefined, '[]') }}}
1919
#endif
2020

2121
{{{ makeModuleReceiveWithVar('wasmBinary') }}}
@@ -643,7 +643,7 @@ async function getWasmBinary(binaryFile) {
643643
}
644644

645645
#if SPLIT_MODULE
646-
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync', true) }}}
646+
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}}
647647
var splitModuleProxyHandler = {
648648
get(target, prop, receiver) {
649649
return (...args) => {

Diff for: src/runtime_debug.js

-13
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616
})();
1717
#endif
1818

19-
function legacyModuleProp(prop, newName, incoming=true) {
20-
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
21-
Object.defineProperty(Module, prop, {
22-
configurable: true,
23-
get() {
24-
let extra = incoming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : '';
25-
abort(`\`Module.${prop}\` has been replaced by \`${newName}\`` + extra);
26-
27-
}
28-
});
29-
}
30-
}
31-
3219
function consumedModuleProp(prop) {
3320
if (!Object.getOwnPropertyDescriptor(Module, prop)) {
3421
Object.defineProperty(Module, prop, {

Diff for: src/shell.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ if (ENVIRONMENT_IS_NODE) {
395395
defaultPrint = (...args) => fs.writeSync(1, args.map(stringify).join(' ') + '\n');
396396
defaultPrintErr = (...args) => fs.writeSync(2, args.map(stringify).join(' ') + '\n');
397397
}
398-
{{{ makeModuleReceiveWithVar('out', 'print', 'defaultPrint', true) }}}
399-
{{{ makeModuleReceiveWithVar('err', 'printErr', 'defaultPrintErr', true) }}}
398+
{{{ makeModuleReceiveWithVar('out', 'print', 'defaultPrint') }}}
399+
{{{ makeModuleReceiveWithVar('err', 'printErr', 'defaultPrintErr') }}}
400400
#else
401-
{{{ makeModuleReceiveWithVar('out', 'print', 'console.log.bind(console)', true) }}}
402-
{{{ makeModuleReceiveWithVar('err', 'printErr', 'console.error.bind(console)', true) }}}
401+
{{{ makeModuleReceiveWithVar('out', 'print', 'console.log.bind(console)') }}}
402+
{{{ makeModuleReceiveWithVar('err', 'printErr', 'console.error.bind(console)') }}}
403403
#endif
404404

405405
#if ASSERTIONS
@@ -428,10 +428,6 @@ assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has be
428428
assert(typeof Module['ENVIRONMENT'] == 'undefined', 'Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
429429
assert(typeof Module['STACK_SIZE'] == 'undefined', 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time')
430430

431-
{{{ makeRemovedModuleAPIAssert('asm', 'wasmExports', false) }}}
432-
{{{ makeRemovedModuleAPIAssert('readAsync') }}}
433-
{{{ makeRemovedModuleAPIAssert('readBinary') }}}
434-
{{{ makeRemovedModuleAPIAssert('setWindowTitle') }}}
435431
{{{ makeRemovedFSAssert('IDBFS') }}}
436432
{{{ makeRemovedFSAssert('PROXYFS') }}}
437433
{{{ makeRemovedFSAssert('WORKERFS') }}}

Diff for: test/other/codesize/test_codesize_hello_O0.gzsize

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7934
1+
7775

Diff for: test/other/codesize/test_codesize_hello_O0.jssize

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
21291
1+
20699

Diff for: test/other/codesize/test_codesize_minimal_O0.gzsize

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6284
1+
6134

Diff for: test/other/codesize/test_codesize_minimal_O0.jssize

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16651
1+
16118

Diff for: test/test_other.py

-51
Original file line numberDiff line numberDiff line change
@@ -12392,63 +12392,12 @@ def test_exceptions_with_closure_and_without_catching(self):
1239212392
''')
1239312393
self.run_process([EMCC, 'src.cpp', '-fexceptions', '--closure=1'])
1239412394

12395-
def test_assertions_on_internal_api_changes(self):
12396-
create_file('src.c', r'''
12397-
#include <emscripten.h>
12398-
int main(int argc, char **argv) {
12399-
EM_ASM({
12400-
try {
12401-
Module['read'];
12402-
out('it should not be there');
12403-
} catch(e) {
12404-
out('error: ' + e);
12405-
}
12406-
try {
12407-
Module['asm'];
12408-
out('it should not be there');
12409-
} catch(e) {
12410-
out('error: ' + e);
12411-
}
12412-
});
12413-
}
12414-
''')
12415-
expected = [
12416-
'`Module.asm` has been replaced by `wasmExports`',
12417-
]
12418-
self.do_runf('src.c', expected, assert_all=True, emcc_args=['-sASSERTIONS'])
12419-
1242012395
def test_assertions_on_incoming_module_api_changes(self):
1242112396
create_file('pre.js', 'Module.read = () => {};')
1242212397
self.do_runf('hello_world.c', 'Module.read option was removed',
1242312398
emcc_args=['-sASSERTIONS', '--pre-js', 'pre.js'],
1242412399
assert_returncode=NON_ZERO)
1242512400

12426-
def test_assertions_on_outgoing_module_api_changes(self):
12427-
create_file('src.cpp', r'''
12428-
#include <emscripten.h>
12429-
int main() {
12430-
EM_ASM({
12431-
out();
12432-
function check(name) {
12433-
try {
12434-
Module[name];
12435-
out("success: " + name);
12436-
} catch(e) {
12437-
}
12438-
}
12439-
check("read");
12440-
// TODO check("setWindowTitle");
12441-
check("wasmBinary");
12442-
check("arguments");
12443-
});
12444-
}
12445-
''')
12446-
expected = '''
12447-
Aborted(`Module.wasmBinary` has been replaced by `wasmBinary` (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name))
12448-
Aborted(`Module.arguments` has been replaced by `arguments_` (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name))
12449-
'''
12450-
self.do_runf('src.cpp', expected, emcc_args=['-sASSERTIONS'])
12451-
1245212401
def test_modularize_assertions_on_reject_promise(self):
1245312402
# Check that there is an uncaught exception in modularize mode.
1245412403
# Once we added an `uncaughtException` handler to the global process

0 commit comments

Comments
 (0)