| 269 | return null; |
| 270 | }; |
| 271 | function registerOnGlobalContext(moduleName: string, exportName: string): void { |
| 272 | if (global[exportName]) { |
| 273 | // already registered |
| 274 | return; |
| 275 | } |
| 276 | Object.defineProperty(global, exportName, { |
| 277 | get: function () { |
| 278 | // We do not need to cache require() call since it is already cached in the runtime. |
| 279 | const m = global.loadModule(moduleName); |
| 280 | |
| 281 | // Redefine the property to make sure the above code is executed only once. |
| 282 | const resolvedValue = m[exportName]; |
| 283 | Object.defineProperty(global, exportName, { |
| 284 | value: resolvedValue, |
| 285 | configurable: true, |
| 286 | writable: true, |
| 287 | }); |
| 288 | |
| 289 | return resolvedValue; |
| 290 | }, |
| 291 | configurable: true, |
| 292 | }); |
| 293 | } |
| 294 | |
| 295 | export function installPolyfills(moduleName: string, exportNames: string[]) { |
| 296 | const shouldInstallEagerly = global.__snapshot || !__COMMONJS__; |