Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -971,34 +971,6 @@ function to64(x) {
return `BigInt(${x})`;
}

// Add assertions to catch common errors when using the Promise object we
// return from MODULARIZE Module() invocations.
function addReadyPromiseAssertions() {
// Warn on someone doing
//
// var instance = Module();
// ...
// instance._main();
const properties = Array.from(EXPORTED_FUNCTIONS.values());
// Also warn on onRuntimeInitialized which might be a common pattern with
// older MODULARIZE-using codebases.
properties.push('onRuntimeInitialized');
const warningEnding =
' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js';
const res = JSON.stringify(properties);
return (
res +
`.forEach((prop) => {
if (!Object.getOwnPropertyDescriptor(readyPromise, prop)) {
Object.defineProperty(readyPromise, prop, {
get: () => abort('You are getting ' + prop + '${warningEnding}'),
set: () => abort('You are setting ' + prop + '${warningEnding}'),
});
}
});`
);
}

function asyncIf(condition) {
return condition ? 'async' : '';
}
Expand Down Expand Up @@ -1118,7 +1090,6 @@ addToCompileTimeContext({
ENVIRONMENT_IS_WORKER_THREAD,
addAtExit,
addAtInit,
addReadyPromiseAssertions,
asyncIf,
awaitIf,
buildStringArray,
Expand Down
3 changes: 0 additions & 3 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ var readyPromise = new Promise((resolve, reject) => {
readyPromiseResolve = resolve;
readyPromiseReject = reject;
});
#if ASSERTIONS
{{{ addReadyPromiseAssertions() }}}
#endif
#endif

// Determine the runtime environment we are in. You can customize this by
Expand Down
3 changes: 0 additions & 3 deletions src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ var readyPromise = new Promise((resolve, reject) => {
readyPromiseResolve = resolve;
readyPromiseReject = reject;
});
#if ASSERTIONS
{{{ addReadyPromiseAssertions() }}}
#endif
#endif

#if ENVIRONMENT_MAY_BE_NODE
Expand Down
25 changes: 0 additions & 25 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -11963,31 +11963,6 @@ def test_assertions_on_outgoing_module_api_changes(self):
'''
self.do_runf('src.cpp', expected, emcc_args=['-sASSERTIONS'])

def test_modularize_assertions_on_ready_promise(self):
# check that when assertions are on we give useful error messages for
# mistakenly thinking the Promise is an instance. I.e., once you could do
# Module()._main to get an instance and the main function, but after
# the breaking change in #10697 Module() now returns a promise, and to get
# the instance you must use .then() to get a callback with the instance.
create_file('test.js', r'''
try {
Module()._main;
} catch(e) {
console.log(e);
}
try {
Module().onRuntimeInitialized = 42;
} catch(e) {
console.log(e);
}
''')
self.run_process([EMCC, test_file('hello_world.c'), '-sMODULARIZE', '-sASSERTIONS', '--extern-post-js', 'test.js'])
# A return code of 1 is from an uncaught exception not handled by
# the domain or the 'uncaughtException' event handler.
out = self.run_js('a.out.js', assert_returncode=1)
self.assertContained('You are getting _main on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js', out)
self.assertContained('You are setting onRuntimeInitialized on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js', out)

def test_modularize_assertions_on_reject_promise(self):
# Check that there is an uncaught exception in modularize mode.
# Once we added an `uncaughtException` handler to the global process
Expand Down
Loading