Skip to content

Commit 728959d

Browse files
committed
Use library symbols instead of legacyRuntimeElements. NFC
We only had two symbols in `legacyRuntimeElements` and it seems cleaner to handle these legacy aliases via the JS library system that we have for that. This helps with my work towards emscripten-core#8380
1 parent c54609c commit 728959d

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

src/library_legacy.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ legacyFuncs = {
126126
var js = jsStackTrace();
127127
if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
128128
return js;
129-
}
129+
},
130+
131+
// Legacy names for runtime `out`/`err` symbols.
132+
$print: 'out',
133+
$printErr: 'err',
130134
};
131135

132136
if (WARN_DEPRECATED && !INCLUDE_FULL_LIBRARY) {

src/library_pthread.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ var LibraryPThread = {
350350
#endif
351351
];
352352
for (var handler of knownHandlers) {
353-
if (Module.hasOwnProperty(handler)) {
353+
if (Module.propertyIsEnumerable(handler)) {
354354
handlers.push(handler);
355355
}
356356
}

src/modules.mjs

-17
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,6 @@ function addMissingLibraryStubs(unusedLibSymbols) {
370370
function exportRuntime() {
371371
const EXPORTED_RUNTIME_METHODS_SET = new Set(EXPORTED_RUNTIME_METHODS);
372372

373-
const legacyRuntimeElements = new Map([
374-
['print', 'out'],
375-
['printErr', 'err'],
376-
]);
377-
378373
// optionally export something.
379374
// in ASSERTIONS mode we show a useful error if it is used without
380375
// being exported. how we show the message depends on whether it's
@@ -391,8 +386,6 @@ function exportRuntime() {
391386
if (exported.startsWith('FS_')) {
392387
// this is a filesystem value, FS.x exported as FS_x
393388
exported = 'FS.' + exported.substr(3);
394-
} else if (legacyRuntimeElements.has(exported)) {
395-
exported = legacyRuntimeElements.get(exported);
396389
}
397390
return `Module['${name}'] = ${exported};`;
398391
}
@@ -481,16 +474,6 @@ function exportRuntime() {
481474
}
482475
}
483476

484-
// Only export legacy runtime elements when explicitly
485-
// requested.
486-
for (const name of EXPORTED_RUNTIME_METHODS_SET) {
487-
if (legacyRuntimeElements.has(name)) {
488-
const newName = legacyRuntimeElements.get(name);
489-
warn(`deprecated item in EXPORTED_RUNTIME_METHODS: ${name} use ${newName} instead.`);
490-
runtimeElements.push(name);
491-
}
492-
}
493-
494477
// Add JS library elements such as FS, GL, ENV, etc. These are prefixed with
495478
// '$ which indicates they are JS methods.
496479
let runtimeElementsSet = new Set(runtimeElements);

src/runtime_debug.js

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ function missingLibrarySymbol(sym) {
8585
}
8686

8787
function unexportedRuntimeSymbol(sym) {
88+
#if PTHREADS
89+
if (ENVIRONMENT_IS_PTHREAD) {
90+
return;
91+
}
92+
#endif
8893
if (!Object.getOwnPropertyDescriptor(Module, sym)) {
8994
Object.defineProperty(Module, sym, {
9095
configurable: true,

test/test_other.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -8077,19 +8077,18 @@ def test(contents):
80778077
self.assertNotContained(error, read_file('a.out.js'))
80788078

80798079
def test_warn_module_out_err(self):
8080-
error = 'was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)'
8081-
80828080
def test(contents, expected, args=[], assert_returncode=0): # noqa
80838081
create_file('src.c', r'''
8084-
#include <emscripten.h>
8085-
int main() {
8086-
EM_ASM({ %s });
8087-
return 0;
8088-
}
8089-
''' % contents)
8082+
#include <emscripten.h>
8083+
int main() {
8084+
EM_ASM({ %s });
8085+
return 0;
8086+
}
8087+
''' % contents)
80908088
self.do_runf('src.c', expected, emcc_args=args, assert_returncode=assert_returncode)
80918089

80928090
# error shown (when assertions are on)
8091+
error = 'was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)'
80938092
test("Module.out('x')", error, assert_returncode=NON_ZERO)
80948093
test("Module['out']('x')", error, assert_returncode=NON_ZERO)
80958094
test("Module.err('x')", error, assert_returncode=NON_ZERO)

0 commit comments

Comments
 (0)