Skip to content

Commit c94f916

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 c4ecb13 commit c94f916

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
/** @type{Object} */
2727
var Module;

test/test_other.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6884,6 +6884,19 @@ def test_modularize_sync_compilation(self):
68846884
after
68856885
''', self.run_js('a.out.js'))
68866886

6887+
def test_modularize_argument_misuse(self):
6888+
create_file('test.c', '''
6889+
#include <emscripten.h>
6890+
EMSCRIPTEN_KEEPALIVE int foo() { return 42; }''')
6891+
6892+
create_file('post.js', r'''
6893+
var arg = { bar: 1 };
6894+
var promise = Module(arg);
6895+
arg._foo();''')
6896+
6897+
expected = "Aborted(Access to module property ('_foo') is no longer possible via the module constructor argument; Instead, use the result of the module constructor"
6898+
self.do_runf('test.c', expected, assert_returncode=NON_ZERO, emcc_args=['--no-entry', '-sMODULARIZE', '--extern-post-js=post.js'])
6899+
68876900
def test_export_all_3142(self):
68886901
create_file('src.cpp', r'''
68896902
typedef unsigned int Bit32u;

0 commit comments

Comments
 (0)