Skip to content

Commit 7432ccb

Browse files
authored
Remove use of new.target (#23960)
This syntax is not transpile-able to ES5, so its better to avoid it for now. The error produced without this extra check seems reasonable enough. Fixes: #23959
1 parent c09f5a0 commit 7432ccb

File tree

2 files changed

+1
-14
lines changed

2 files changed

+1
-14
lines changed

test/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7040,7 +7040,7 @@ def test_modularize_new_misuse(self):
70407040
self.run_process([EMCC, test_file('hello_world.c'), '-sMODULARIZE', '-sEXPORT_NAME=Foo'])
70417041
create_file('run.js', 'var m = require("./a.out.js"); new m();')
70427042
err = self.run_js('run.js', assert_returncode=NON_ZERO)
7043-
self.assertContained('Error: Foo() should not be called with `new Foo()`', err)
7043+
self.assertContained('TypeError: m is not a constructor', err)
70447044

70457045
@parameterized({
70467046
'': ([],),

tools/link.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,19 +2469,6 @@ def modularize():
24692469
'wrapper_function': wrapper_function,
24702470
}
24712471

2472-
if settings.ASSERTIONS and settings.MODULARIZE != 'instance':
2473-
src += '''\
2474-
(() => {
2475-
// Create a small, never-async wrapper around %(EXPORT_NAME)s which
2476-
// checks for callers incorrectly using it with `new`.
2477-
var real_%(EXPORT_NAME)s = %(EXPORT_NAME)s;
2478-
%(EXPORT_NAME)s = function(arg) {
2479-
if (new.target) throw new Error("%(EXPORT_NAME)s() should not be called with `new %(EXPORT_NAME)s()`");
2480-
return real_%(EXPORT_NAME)s(arg);
2481-
}
2482-
})();
2483-
''' % {'EXPORT_NAME': settings.EXPORT_NAME}
2484-
24852472
if settings.SOURCE_PHASE_IMPORTS:
24862473
src = f"import source wasmModule from './{settings.WASM_BINARY_FILE}';\n\n" + src
24872474

0 commit comments

Comments
 (0)