From 054f63bd3bf628555df8f7e22c52f555e9538ecc Mon Sep 17 00:00:00 2001 From: shirakaba <14055146+shirakaba@users.noreply.github.com> Date: Sat, 2 Dec 2023 11:47:00 +0900 Subject: [PATCH] fix(hermes): wrap registerOnGlobalContext() in try-catch --- packages/core/globals/index.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/core/globals/index.ts b/packages/core/globals/index.ts index 5352d79fb..3e7f2d18f 100644 --- a/packages/core/globals/index.ts +++ b/packages/core/globals/index.ts @@ -15,23 +15,27 @@ interface ExtensionMap { } function registerOnGlobalContext(moduleName: string, exportName: string): void { - Object.defineProperty(global, exportName, { - get: function () { - // We do not need to cache require() call since it is already cached in the runtime. - const m = global.loadModule(moduleName); + try { + Object.defineProperty(global, exportName, { + get: function () { + // 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. - const resolvedValue = m[exportName]; - Object.defineProperty(global, exportName, { - value: resolvedValue, - configurable: true, - writable: true, - }); + // Redefine the property to make sure the above code is executed only once. + const resolvedValue = m[exportName]; + Object.defineProperty(global, exportName, { + value: resolvedValue, + configurable: true, + writable: true, + }); - return resolvedValue; - }, - configurable: true, - }); + return resolvedValue; + }, + configurable: true, + }); + } catch (_e) { + // TODO: On Hermes, some globals are non-configurable and we cannot override them. + } } /**