Skip to content

Commit 1aeffbf

Browse files
authored
Use library symbols instead of legacyRuntimeElements. NFC (#21877)
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 #8380
1 parent dcbeb4a commit 1aeffbf

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

src/library_legacy.js

Lines changed: 5 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 17 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8089,19 +8089,18 @@ def test(contents):
80898089
self.assertNotContained(error, read_file('a.out.js'))
80908090

80918091
def test_warn_module_out_err(self):
8092-
error = 'was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)'
8093-
80948092
def test(contents, expected, args=[], assert_returncode=0): # noqa
80958093
create_file('src.c', r'''
8096-
#include <emscripten.h>
8097-
int main() {
8098-
EM_ASM({ %s });
8099-
return 0;
8100-
}
8101-
''' % contents)
8094+
#include <emscripten.h>
8095+
int main() {
8096+
EM_ASM({ %s });
8097+
return 0;
8098+
}
8099+
''' % contents)
81028100
self.do_runf('src.c', expected, emcc_args=args, assert_returncode=assert_returncode)
81038101

81048102
# error shown (when assertions are on)
8103+
error = 'was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)'
81058104
test("Module.out('x')", error, assert_returncode=NON_ZERO)
81068105
test("Module['out']('x')", error, assert_returncode=NON_ZERO)
81078106
test("Module.err('x')", error, assert_returncode=NON_ZERO)

0 commit comments

Comments
 (0)