Skip to content

Commit d4a7433

Browse files
authored
Revert "Ignore EXPORT_NAME in EXPORT_ES6 mode. NFC" (#24149)
Reverts #24138 This change broke the binaryen JS build.
1 parent 50532ec commit d4a7433

File tree

7 files changed

+17
-32
lines changed

7 files changed

+17
-32
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ jobs:
730730
- run-tests:
731731
test_targets: "
732732
core0.test_hello_argc
733-
other.test_modularize_incoming*"
733+
other.test_modularize_incoming
734+
other.test_modularize_incoming_export_name"
734735
test-spidermonkey:
735736
executor: linux-python
736737
steps:

src/wasm_worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ if (ENVIRONMENT_IS_NODE) {
7171
#endif
7272
importScripts(d.js);
7373
#if MODULARIZE
74-
{{{ EXPORT_ES6 ? 'moduleFactory' : EXPORT_NAME }}}(d);
74+
{{{ EXPORT_NAME }}}(d);
7575
#endif
7676
// Drop now unneeded references to from the Module object in this Worker,
7777
// these are not needed anymore.

test/modularize_post_js.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77
// Avoid instantiating the module on pthreads.
88
if (!isPthread)
99
#endif
10-
#if EXPORT_ES6
11-
moduleFactory();
12-
#else
1310
{{{ EXPORT_NAME }}}();
14-
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1301
1+
1298
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2711
1+
2697

test/test_other.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_esm(self, args):
355355
self.run_process([EMCC, '-o', 'hello_world.mjs',
356356
'--extern-post-js', test_file('modularize_post_js.js'),
357357
test_file('hello_world.c')] + args)
358-
self.assertContained('export default moduleFactory;', read_file('hello_world.mjs'))
358+
self.assertContained('export default Module;', read_file('hello_world.mjs'))
359359
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))
360360

361361
@requires_node_canary
@@ -381,7 +381,7 @@ def test_esm_worker(self, args):
381381
src = read_file('subdir/hello_world.mjs')
382382
self.assertContained("new URL('hello_world.wasm', import.meta.url)", src)
383383
self.assertContained("new Worker(new URL('hello_world.mjs', import.meta.url), {", src)
384-
self.assertContained('export default moduleFactory;', src)
384+
self.assertContained('export default Module;', src)
385385
self.assertContained('hello, world!', self.run_js('subdir/hello_world.mjs'))
386386

387387
@node_pthreads
@@ -405,16 +405,12 @@ def test_esm_closure(self):
405405
def test_esm_implies_modularize(self):
406406
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6'])
407407
src = read_file('a.out.js')
408-
self.assertContained('export default moduleFactory;', src)
408+
self.assertContained('export default Module;', src)
409409

410410
def test_esm_requires_modularize(self):
411411
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0'])
412412
self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err)
413413

414-
def test_esm_ignore_export_name(self):
415-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sEXPORT_NAME=Foo', '-Werror'])
416-
self.assertContained('emcc: error: EXPORT_NAME is not used in EXPORT_ES6 mode [-Wunused-command-line-argument] [-Werror]', err)
417-
418414
def test_emcc_out_file(self):
419415
# Verify that "-ofile" works in addition to "-o" "file"
420416
self.run_process([EMCC, '-c', '-ofoo.o', test_file('hello_world.c')])
@@ -7062,7 +7058,8 @@ def test_modularize_new_misuse(self):
70627058

70637059
@parameterized({
70647060
'': ([],),
7065-
'closure': (['--closure=1'],),
7061+
'export_name': (['-sEXPORT_NAME=Foo'],),
7062+
'closure': (['-sEXPORT_NAME=Foo', '--closure=1'],),
70667063
})
70677064
@crossplatform
70687065
def test_modularize_incoming(self, args):
@@ -11163,7 +11160,6 @@ def test_node_js_pthread_module(self, es6):
1116311160
''')
1116411161
else:
1116511162
ext = '.js'
11166-
self.emcc_args += ['-sMODULARIZE', '-sEXPORT_NAME=test_module']
1116711163
create_file('moduleLoader.js', '''
1116811164
const test_module = require("./subdir/module.js");
1116911165
test_module().then((test_module_instance) => {
@@ -11173,7 +11169,7 @@ def test_node_js_pthread_module(self, es6):
1117311169
ensure_dir('subdir')
1117411170

1117511171
# build hello_world.c
11176-
self.run_process([EMCC, test_file('hello_world.c'), '-o', 'subdir/module' + ext, '-pthread', '-sPTHREAD_POOL_SIZE=2'] + self.get_emcc_args())
11172+
self.run_process([EMCC, test_file('hello_world.c'), '-o', 'subdir/module' + ext, '-pthread', '-sPTHREAD_POOL_SIZE=2', '-sMODULARIZE', '-sEXPORT_NAME=test_module'] + self.get_emcc_args())
1117711173

1117811174
# run the module
1117911175
ret = self.run_js('moduleLoader' + ext)

tools/link.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,10 +1796,6 @@ def get_full_import_name(name):
17961796
if not js_manipulation.isidentifier(settings.EXPORT_NAME):
17971797
exit_with_error(f'EXPORT_NAME is not a valid JS identifier: `{settings.EXPORT_NAME}`')
17981798

1799-
if settings.EXPORT_ES6 and 'EXPORT_NAME' in user_settings:
1800-
diagnostics.warning('unused-command-line-argument', 'EXPORT_NAME is not used in EXPORT_ES6 mode')
1801-
settings.EXPORT_NAME = None
1802-
18031799
if settings.EMSCRIPTEN_TRACING:
18041800
add_system_js_lib('libtrace.js')
18051801
if settings.ALLOW_MEMORY_GROWTH:
@@ -2468,15 +2464,11 @@ def modularize():
24682464
'maybe_async': maybe_async,
24692465
'generated_js': generated_js
24702466
}
2471-
if settings.EXPORT_ES6:
2472-
factory_name = 'moduleFactory'
2473-
else:
2474-
factory_name = settings.EXPORT_NAME
24752467

24762468
if settings.MINIMAL_RUNTIME and not settings.PTHREADS:
24772469
# Single threaded MINIMAL_RUNTIME programs do not need access to
24782470
# document.currentScript, so a simple export declaration is enough.
2479-
src = f'var {factory_name} = {wrapper_function};'
2471+
src = f'var {settings.EXPORT_NAME} = {wrapper_function};'
24802472
else:
24812473
script_url_web = ''
24822474
# When MODULARIZE this JS may be executed later,
@@ -2485,12 +2477,12 @@ def modularize():
24852477
if settings.ENVIRONMENT_MAY_BE_WEB and not settings.EXPORT_ES6:
24862478
script_url_web = "var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;"
24872479
src = '''\
2488-
var %(factory_name)s = (() => {
2480+
var %(EXPORT_NAME)s = (() => {
24892481
%(script_url_web)s
24902482
return (%(wrapper_function)s);
24912483
})();
24922484
''' % {
2493-
'factory_name': factory_name,
2485+
'EXPORT_NAME': settings.EXPORT_NAME,
24942486
'script_url_web': script_url_web,
24952487
'wrapper_function': wrapper_function,
24962488
}
@@ -2505,11 +2497,11 @@ def modularize():
25052497
# Module variable name. This should happen even in MINIMAL_RUNTIME builds
25062498
# for MODULARIZE and EXPORT_ES6 to work correctly.
25072499
if settings.AUDIO_WORKLET:
2508-
src += f'globalThis.AudioWorkletModule = {factory_name};\n'
2500+
src += f'globalThis.AudioWorkletModule = {settings.EXPORT_NAME};\n'
25092501

25102502
# Export using a UMD style export, or ES6 exports if selected
25112503
if settings.EXPORT_ES6:
2512-
src += 'export default moduleFactory;\n'
2504+
src += 'export default %s;\n' % settings.EXPORT_NAME
25132505
elif not settings.MINIMAL_RUNTIME:
25142506
src += '''\
25152507
if (typeof exports === 'object' && typeof module === 'object') {
@@ -2538,7 +2530,7 @@ def modularize():
25382530
if settings.MODULARIZE == 'instance':
25392531
src += 'isPthread && init();\n'
25402532
else:
2541-
src += f'isPthread && {factory_name}();\n'
2533+
src += 'isPthread && %s();\n' % settings.EXPORT_NAME
25422534

25432535
final_js += '.modular.js'
25442536
write_file(final_js, src)

0 commit comments

Comments
 (0)