mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(hermes): wrap registerOnGlobalContext() in try-catch
This commit is contained in:
@ -15,23 +15,27 @@ interface ExtensionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerOnGlobalContext(moduleName: string, exportName: string): void {
|
function registerOnGlobalContext(moduleName: string, exportName: string): void {
|
||||||
Object.defineProperty(global, exportName, {
|
try {
|
||||||
get: function () {
|
Object.defineProperty(global, exportName, {
|
||||||
// We do not need to cache require() call since it is already cached in the runtime.
|
get: function () {
|
||||||
const m = global.loadModule(moduleName);
|
// We do not need to cache require() call since it is already cached in the runtime.
|
||||||
|
const m = global.loadModule(moduleName);
|
||||||
|
|
||||||
// Redefine the property to make sure the above code is executed only once.
|
// Redefine the property to make sure the above code is executed only once.
|
||||||
const resolvedValue = m[exportName];
|
const resolvedValue = m[exportName];
|
||||||
Object.defineProperty(global, exportName, {
|
Object.defineProperty(global, exportName, {
|
||||||
value: resolvedValue,
|
value: resolvedValue,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
writable: true,
|
writable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return resolvedValue;
|
return resolvedValue;
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
} catch (_e) {
|
||||||
|
// TODO: On Hermes, some globals are non-configurable and we cannot override them.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user