Skip to content

Commit a751c39

Browse files
committed
Reapply "In MODULARIZE mode avoid modifying the incoming moduleArg. NFC (emscripten-core#21775)"
This change was reverted in emscripten-core#21994 because the file_packager generated code expected to be able to use propertied on the Module object that was passed to the constructor/factor function. However that issue was fixed in emscripten-core#22086 so we can try to land this once again.
1 parent 29e98f8 commit a751c39

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// before the code. Then that object will be used in the code, and you
2222
// can continue to use Module afterwards as well.
2323
#if MODULARIZE
24-
var Module = moduleArg;
24+
var Module = Object.assign({}, moduleArg);
2525
#elif USE_CLOSURE_COMPILER
2626
// if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string
2727
var /** @type {{

test/test_other.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6770,6 +6770,19 @@ def test_modularize_sync_compilation(self):
67706770
after
67716771
''', self.run_js('a.out.js'))
67726772

6773+
def test_modularize_argument_misuse(self):
6774+
create_file('test.c', '''
6775+
#include <emscripten.h>
6776+
EMSCRIPTEN_KEEPALIVE int foo() { return 42; }''')
6777+
6778+
create_file('post.js', r'''
6779+
var arg = { bar: 1 };
6780+
var promise = Module(arg);
6781+
arg._foo();''')
6782+
6783+
expected = "Aborted(Access to module property ('_foo') is no longer possible via the module constructor argument; Instead, use the result of the module constructor"
6784+
self.do_runf('test.c', expected, assert_returncode=NON_ZERO, emcc_args=['--no-entry', '-sMODULARIZE', '--extern-post-js=post.js'])
6785+
67736786
def test_export_all_3142(self):
67746787
create_file('src.cpp', r'''
67756788
typedef unsigned int Bit32u;

0 commit comments

Comments
 (0)