Skip to content

Commit 8aea22d

Browse files
AlexPerrotkripken
authored andcommitted
Merge EXTRA_EXPORTED_RUNTIME_METHODS (#5023)
* merging EXTRA_EXPORTED_RUNTIME_METHODS with EXPORTED_RUNTIME_METHODS to ensure it is used everywhere * also empty EXTRA_EXPORTED_RUNTIME_METHODS just to be safe * test that EXTRA_EXPORTED_RUNTIME_METHODS is considered by libraries for methods to export
1 parent 93b11ec commit 8aea22d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/modules.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,11 @@ function cDefine(key) {
267267
throw 'XXX missing C define ' + key + '!';
268268
}
269269

270-
var EXPORTED_RUNTIME_METHODS_SET = null;
270+
var EXPORTED_RUNTIME_METHODS_SET = set(EXPORTED_RUNTIME_METHODS.concat(EXTRA_EXPORTED_RUNTIME_METHODS));
271+
EXPORTED_RUNTIME_METHODS = unset(EXPORTED_RUNTIME_METHODS_SET);
272+
EXTRA_EXPORTED_RUNTIME_METHODS = [];
271273

272274
function maybeExport(name) {
273-
if (!EXPORTED_RUNTIME_METHODS_SET) EXPORTED_RUNTIME_METHODS_SET = set(EXPORTED_RUNTIME_METHODS.concat(EXTRA_EXPORTED_RUNTIME_METHODS));
274275
if (name in EXPORTED_RUNTIME_METHODS_SET) {
275276
return 'Module["' + name + '"] = ' + name + ';';
276277
} else {

tests/test_other.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,37 @@ def test_node_catch_exit(self):
26902690
self.assertContained(reference_error_text,
26912691
run_js ('index.js', engine=NODE_JS, stderr=STDOUT, assert_returncode=None))
26922692

2693+
def test_extra_exported_methods(self):
2694+
# Test with node.js that the EXTRA_EXPORTED_RUNTIME_METHODS setting is considered by libraries
2695+
if NODE_JS not in JS_ENGINES:
2696+
return self.skip("node engine required for this test")
2697+
2698+
open(os.path.join(self.get_dir(), 'count.c'), 'w').write('''
2699+
#include <string.h>
2700+
int count(const char *str) {
2701+
return (int)strlen(str);
2702+
}
2703+
''')
2704+
2705+
open(os.path.join(self.get_dir(), 'index.js'), 'w').write('''
2706+
const count = require('./count.js');
2707+
2708+
console.log(count.FS_writeFile);
2709+
''')
2710+
2711+
reference_error_text = 'undefined';
2712+
2713+
subprocess.check_call([PYTHON, EMCC, os.path.join(self.get_dir(), 'count.c'), '-s', 'FORCE_FILESYSTEM=1', '-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["FS_writeFile"]','-o', 'count.js'])
2714+
2715+
# Check that the Module.FS_writeFile exists
2716+
self.assertNotContained(reference_error_text,
2717+
run_js ('index.js', engine=NODE_JS, stderr=STDOUT, assert_returncode=None))
2718+
2719+
subprocess.check_call([PYTHON, EMCC, os.path.join(self.get_dir(), 'count.c'), '-s', 'FORCE_FILESYSTEM=1', '-o', 'count.js'])
2720+
2721+
# Check that the Module.FS_writeFile is not exported
2722+
self.assertContained(reference_error_text,
2723+
run_js ('index.js', engine=NODE_JS, stderr=STDOUT, assert_returncode=None))
26932724

26942725
def test_fs_stream_proto(self):
26952726
open('src.cpp', 'wb').write(r'''

0 commit comments

Comments
 (0)