···8181}
82828383let safeGlobal: Record<string | symbol, unknown> | void;
8484+let vmGlobals: Record<string | symbol, unknown> = {};
84858586function makeSafeGlobal() {
8687 if (safeGlobal) {
···101102102103 // When we're in the browser, we can go a step further and try to create a
103104 // new JS context and globals in a separate iframe
104104- let vmGlobals = trueGlobal;
105105+ vmGlobals = trueGlobal;
105106 let iframe: HTMLIFrameElement | void;
106107 if (typeof document !== 'undefined') {
107108 try {
···176177 const safeGlobal = makeSafeGlobal();
177178 const code = args.pop();
178179180180+ // Retrieve Function constructor from vm globals
181181+ const Function = vmGlobals.Function as FunctionConstructor | void;
182182+ const Object = vmGlobals.Object as ObjectConstructor;
183183+ const createFunction = (Function || Object.constructor.constructor) as FunctionConstructor;
184184+179185 // We pass in our safe global and use it using `with` (ikr...)
180186 // We then add a wrapper function for strict-mode and a few closing
181187 // statements to prevent the code from escaping the `with` block;
182182- const fn = new Function(
188188+ const fn = createFunction(
183189 'globalThis',
184190 ...args,
185191 'with (globalThis) {\n"use strict";\nreturn (function () {\n' +