Skip to content

Commit

Permalink
Avoid adding hooks for globalThis in MODULARIZE mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Sep 26, 2024
1 parent fafea90 commit 9e3bca8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/runtime_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ function isExportedByForceFilesystem(name) {
* their build, or no symbols that no longer exist.
*/
function hookGlobalSymbolAccess(sym, func) {
#if MODULARIZE && !EXPORT_ES6
// In MODULARIZE mode the generated code runs inside a function scope and not
// the global scope, and JavaScript does not provide access to function scopes
// so we cannot dynamically modify the scrope using `defineProperty` in this
// case.
//
// In this mode we simply ignore requests for `hookGlobalSymbolAccess`.
#else
if (typeof globalThis != 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
Object.defineProperty(globalThis, sym, {
configurable: true,
Expand All @@ -65,6 +73,7 @@ function hookGlobalSymbolAccess(sym, func) {
}
});
}
#endif
}

function missingGlobal(sym, msg) {
Expand Down

0 comments on commit 9e3bca8

Please sign in to comment.