UNPKG

@takeshape/vm2

Version:

vm2 is a sandbox that can run untrusted code with whitelisted Node's built-in modules. Securely!

59 lines (52 loc) 105 kB
/* eslint-disable global-require, no-use-before-define, max-len */ 'use strict'; /** * This callback will be called to transform a script to JavaScript. * * @callback compileCallback * @param {string} code - Script code to transform to JavaScript. * @param {string} filename - Filename of this script. * @return {string} JavaScript code that represents the script code. */ /** * This callback will be called to resolve a module if it couldn't be found. * * @callback resolveCallback * @param {string} moduleName - Name of the module to resolve. * @param {string} dirname - Name of the current directory. * @return {(string|undefined)} The file or directory to use to load the requested module. */ const fs = require('fs'); const vm = require('vm'); const pa = require('path'); const {EventEmitter} = require('events'); const {INSPECT_MAX_BYTES} = require('buffer'); const helpers = require('./helpers.js'); const importModuleDynamically = () => { // We can't throw an error object here because since vm.Script doesn't store a context, we can't properly contextify that error object. // eslint-disable-next-line no-throw-literal throw 'Dynamic imports are not allowed.'; }; const MODULE_PREFIX = '(function (exports, require, module, __filename, __dirname) { '; const STRICT_MODULE_PREFIX = MODULE_PREFIX + '"use strict"; '; const MODULE_SUFFIX = '\n});'; /** * Load a script from a file and compile it. * * @private * @param {string} filename - File name * @param {string} data - Script body * @param {string} prefix - Prefix for the script. * @param {string} suffix - Suffix for the script. * @return {vm.Script} The compiled script. */ function compileScript(filename, data, prefix, suffix) { return new vm.Script(prefix + data + suffix, { filename, displayErrors: false, importModuleDynamically }); } const contextifyJS = "/* global host */\n/* eslint-disable block-spacing, no-multi-spaces, brace-style, no-array-constructor, new-cap, no-use-before-define */\n\n'use strict';\n\n// eslint-disable-next-line no-invalid-this, no-shadow\nconst global = this;\n\nconst local = host.Object.create(null);\nlocal.Object = Object;\nlocal.Array = Array;\nlocal.Reflect = host.Object.create(null);\nlocal.Reflect.ownKeys = Reflect.ownKeys;\nlocal.Reflect.enumerate = Reflect.enumerate;\nlocal.Reflect.getPrototypeOf = Reflect.getPrototypeOf;\nlocal.Reflect.construct = Reflect.construct;\nlocal.Reflect.apply = Reflect.apply;\nlocal.Reflect.set = Reflect.set;\nlocal.Reflect.deleteProperty = Reflect.deleteProperty;\nlocal.Reflect.has = Reflect.has;\nlocal.Reflect.defineProperty = Reflect.defineProperty;\nlocal.Reflect.setPrototypeOf = Reflect.setPrototypeOf;\nlocal.Reflect.isExtensible = Reflect.isExtensible;\nlocal.Reflect.preventExtensions = Reflect.preventExtensions;\nlocal.Reflect.getOwnPropertyDescriptor = Reflect.getOwnPropertyDescriptor;\n\nfunction uncurryThis(func) {\n\treturn (thiz, args) => local.Reflect.apply(func, thiz, args);\n}\n\nconst FunctionBind = uncurryThis(Function.prototype.bind);\n\n// global is originally prototype of host.Object so it can be used to climb up from the sandbox.\nObject.setPrototypeOf(global, Object.prototype);\n\nObject.defineProperties(global, {\n\tglobal: {value: global},\n\tGLOBAL: {value: global},\n\troot: {value: global},\n\tisVM: {value: true}\n});\n\nconst DEBUG = false;\nconst OPNA = 'Operation not allowed on contextified object.';\nconst captureStackTrace = Error.captureStackTrace;\n\nconst RETURN_FALSE = () => false;\n\nconst FROZEN_TRAPS = {\n\t__proto__: null,\n\tset(target, key, value, receiver) {\n\t\treturn local.Reflect.defineProperty(receiver, key, {\n\t\t\t__proto__: null,\n\t\t\tvalue: value,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true\n\t\t});\n\t},\n\tsetPrototypeOf: RETURN_FALSE,\n\tdefineProperty: RETURN_FALSE,\n\tdeleteProperty: RETURN_FALSE,\n\tisExtensible: RETURN_FALSE,\n\tpreventExtensions: RETURN_FALSE\n};\n\n// Map of contextified objects to original objects\nconst Contextified = new host.WeakMap();\nconst Decontextified = new host.WeakMap();\n\n// We can't use host's hasInstance method\nconst ObjectHasInstance = uncurryThis(local.Object[Symbol.hasInstance]);\nfunction instanceOf(value, construct) {\n\ttry {\n\t\treturn ObjectHasInstance(construct, [value]);\n\t} catch (ex) {\n\t\t// Never pass the handled exception through!\n\t\tthrow new VMError('Unable to perform instanceOf check.');\n\t\t// This exception actually never get to the user. It only instructs the caller to return null because we wasn't able to perform instanceOf check.\n\t}\n}\n\nconst SHARED_OBJECT = {__proto__: null};\nfunction SHARED_FUNCTION() {}\n\nfunction createBaseObject(obj) {\n\tlet base;\n\tif (typeof obj === 'function') {\n\t\ttry {\n\t\t\t// eslint-disable-next-line no-new\n\t\t\tnew new host.Proxy(obj, {\n\t\t\t\t__proto__: null,\n\t\t\t\tconstruct() {\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t})();\n\t\t\t// Bind the function since bound functions do not have a prototype property.\n\t\t\tbase = FunctionBind(SHARED_FUNCTION, [null]);\n\t\t} catch (e) {\n\t\t\tbase = () => {};\n\t\t}\n\t} else if (host.Array.isArray(obj)) {\n\t\tbase = [];\n\t} else {\n\t\treturn {__proto__: null};\n\t}\n\tif (!local.Reflect.setPrototypeOf(base, null)) {\n\t\t// Should not happen\n\t\treturn null;\n\t}\n\treturn base;\n}\n\n/**\n * VMError definition.\n */\n\nclass VMError extends Error {\n\tconstructor(message, code) {\n\t\tsuper(message);\n\n\t\tthis.name = 'VMError';\n\t\tthis.code = code;\n\n\t\tcaptureStackTrace(this, this.constructor);\n\t}\n}\n\nglobal.VMError = VMError;\n\n/*\n * This function will throw a TypeError for accessing properties\n * on a strict mode function\n */\nfunction throwCallerCalleeArgumentsAccess(key) {\n\t'use strict';\n\tthrowCallerCalleeArgumentsAccess[key];\n\treturn new VMError('Unreachable');\n}\n\nfunction unexpected() {\n\tthrow new VMError('Should not happen');\n}\n\nfunction doPreventExtensions(target, object, doProxy) {\n\tconst keys = local.Reflect.ownKeys(object);\n\tfor (let i = 0; i < keys.length; i++) {\n\t\tconst key = keys[i];\n\t\tlet desc = local.Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (!desc) continue;\n\t\tif (!local.Reflect.setPrototypeOf(desc, null)) unexpected();\n\t\tif (!desc.configurable) {\n\t\t\tconst current = local.Reflect.getOwnPropertyDescriptor(target, key);\n\t\t\tif (current && !current.configurable) continue;\n\t\t\tif (desc.get || desc.set) {\n\t\t\t\tdesc.get = doProxy(desc.get);\n\t\t\t\tdesc.set = doProxy(desc.set);\n\t\t\t} else {\n\t\t\t\tdesc.value = doProxy(desc.value);\n\t\t\t}\n\t\t} else {\n\t\t\tif (desc.get || desc.set) {\n\t\t\t\tdesc = {\n\t\t\t\t\t__proto__: null,\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: desc.enumerable,\n\t\t\t\t\twritable: true,\n\t\t\t\t\tvalue: null\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tdesc.value = null;\n\t\t\t}\n\t\t}\n\t\tif (!local.Reflect.defineProperty(target, key, desc)) unexpected();\n\t}\n\tif (!local.Reflect.preventExtensions(target)) unexpected();\n}\n\n/**\n * Decontextify.\n */\n\nconst Decontextify = host.Object.create(null);\nDecontextify.proxies = new host.WeakMap();\n\nDecontextify.arguments = args => {\n\tif (!host.Array.isArray(args)) return new host.Array();\n\n\ttry {\n\t\tconst arr = new host.Array();\n\t\tfor (let i = 0, l = args.length; i < l; i++) arr[i] = Decontextify.value(args[i]);\n\t\treturn arr;\n\t} catch (e) {\n\t\t// Never pass the handled exception through!\n\t\treturn new host.Array();\n\t}\n};\nDecontextify.instance = (instance, klass, deepTraps, flags, toStringTag) => {\n\tif (typeof instance === 'function') return Decontextify.function(instance);\n\n\t// We must not use normal object because there's a chance object already contains malicious code in the prototype\n\tconst base = host.Object.create(null);\n\n\tbase.get = (target, key, receiver) => {\n\t\ttry {\n\t\t\tif (key === 'vmProxyTarget' && DEBUG) return instance;\n\t\t\tif (key === 'isVMProxy') return true;\n\t\t\tif (key === 'constructor') return klass;\n\t\t\tif (key === '__proto__') return klass.prototype;\n\t\t} catch (e) {\n\t\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\t\treturn null;\n\t\t}\n\n\t\tif (key === '__defineGetter__') return host.Object.prototype.__defineGetter__;\n\t\tif (key === '__defineSetter__') return host.Object.prototype.__defineSetter__;\n\t\tif (key === '__lookupGetter__') return host.Object.prototype.__lookupGetter__;\n\t\tif (key === '__lookupSetter__') return host.Object.prototype.__lookupSetter__;\n\t\tif (key === host.Symbol.toStringTag && toStringTag) return toStringTag;\n\n\t\ttry {\n\t\t\treturn Decontextify.value(instance[key], null, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.getPrototypeOf = (target) => {\n\t\treturn klass && klass.prototype;\n\t};\n\n\treturn Decontextify.object(instance, base, deepTraps, flags);\n};\nDecontextify.function = (fnc, traps, deepTraps, flags, mock) => {\n\t// We must not use normal object because there's a chance object already contains malicious code in the prototype\n\tconst base = host.Object.create(null);\n\t// eslint-disable-next-line prefer-const\n\tlet proxy;\n\n\tbase.apply = (target, context, args) => {\n\t\tcontext = Contextify.value(context);\n\n\t\t// Set context of all arguments to vm's context.\n\t\targs = Contextify.arguments(args);\n\n\t\ttry {\n\t\t\treturn Decontextify.value(fnc.apply(context, args));\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.construct = (target, args, newTarget) => {\n\t\targs = Contextify.arguments(args);\n\n\t\ttry {\n\t\t\treturn Decontextify.instance(new fnc(...args), proxy, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.get = (target, key, receiver) => {\n\t\ttry {\n\t\t\tif (key === 'vmProxyTarget' && DEBUG) return fnc;\n\t\t\tif (key === 'isVMProxy') return true;\n\t\t\tif (mock && host.Object.prototype.hasOwnProperty.call(mock, key)) return mock[key];\n\t\t\tif (key === 'constructor') return host.Function;\n\t\t\tif (key === '__proto__') return host.Function.prototype;\n\t\t} catch (e) {\n\t\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\t\treturn null;\n\t\t}\n\n\t\tif (key === '__defineGetter__') return host.Object.prototype.__defineGetter__;\n\t\tif (key === '__defineSetter__') return host.Object.prototype.__defineSetter__;\n\t\tif (key === '__lookupGetter__') return host.Object.prototype.__lookupGetter__;\n\t\tif (key === '__lookupSetter__') return host.Object.prototype.__lookupSetter__;\n\n\t\ttry {\n\t\t\treturn Decontextify.value(fnc[key], null, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.getPrototypeOf = (target) => {\n\t\treturn host.Function.prototype;\n\t};\n\n\tproxy = Decontextify.object(fnc, host.Object.assign(base, traps), deepTraps);\n\treturn proxy;\n};\nDecontextify.object = (object, traps, deepTraps, flags, mock) => {\n\t// We must not use normal object because there's a chance object already contains malicious code in the prototype\n\tconst base = host.Object.create(null);\n\n\tbase.get = (target, key, receiver) => {\n\t\ttry {\n\t\t\tif (key === 'vmProxyTarget' && DEBUG) return object;\n\t\t\tif (key === 'isVMProxy') return true;\n\t\t\tif (mock && host.Object.prototype.hasOwnProperty.call(mock, key)) return mock[key];\n\t\t\tif (key === 'constructor') return host.Object;\n\t\t\tif (key === '__proto__') return host.Object.prototype;\n\t\t} catch (e) {\n\t\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\t\treturn null;\n\t\t}\n\n\t\tif (key === '__defineGetter__') return host.Object.prototype.__defineGetter__;\n\t\tif (key === '__defineSetter__') return host.Object.prototype.__defineSetter__;\n\t\tif (key === '__lookupGetter__') return host.Object.prototype.__lookupGetter__;\n\t\tif (key === '__lookupSetter__') return host.Object.prototype.__lookupSetter__;\n\n\t\ttry {\n\t\t\treturn Decontextify.value(object[key], null, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.set = (target, key, value, receiver) => {\n\t\tvalue = Contextify.value(value);\n\n\t\ttry {\n\t\t\treturn local.Reflect.set(object, key, value);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.getOwnPropertyDescriptor = (target, prop) => {\n\t\tlet def;\n\n\t\ttry {\n\t\t\tdef = local.Object.getOwnPropertyDescriptor(object, prop);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\n\t\t// Following code prevents V8 to throw\n\t\t// TypeError: 'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property '<prop>'\n\t\t// which is either non-existant or configurable in the proxy target\n\n\t\tlet desc;\n\t\tif (!def) {\n\t\t\treturn undefined;\n\t\t} else if (def.get || def.set) {\n\t\t\tdesc = {\n\t\t\t\t__proto__: null,\n\t\t\t\tget: Decontextify.value(def.get) || undefined,\n\t\t\t\tset: Decontextify.value(def.set) || undefined,\n\t\t\t\tenumerable: def.enumerable === true,\n\t\t\t\tconfigurable: def.configurable === true\n\t\t\t};\n\t\t} else {\n\t\t\tdesc = {\n\t\t\t\t__proto__: null,\n\t\t\t\tvalue: Decontextify.value(def.value),\n\t\t\t\twritable: def.writable === true,\n\t\t\t\tenumerable: def.enumerable === true,\n\t\t\t\tconfigurable: def.configurable === true\n\t\t\t};\n\t\t}\n\t\tif (!desc.configurable) {\n\t\t\ttry {\n\t\t\t\tdef = local.Object.getOwnPropertyDescriptor(target, prop);\n\t\t\t\tif (!def || def.configurable || def.writable !== desc.writable) {\n\t\t\t\t\tlocal.Reflect.defineProperty(target, prop, desc);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Should not happen.\n\t\t\t}\n\t\t}\n\t\treturn desc;\n\t};\n\tbase.defineProperty = (target, key, descriptor) => {\n\t\tlet success = false;\n\t\ttry {\n\t\t\tsuccess = local.Reflect.setPrototypeOf(descriptor, null);\n\t\t} catch (e) {\n\t\t\t// Should not happen\n\t\t}\n\t\tif (!success) return false;\n\t\t// There's a chance accessing a property throws an error so we must not access them\n\t\t// in try catch to prevent contextifying local objects.\n\n\t\tconst propertyDescriptor = host.Object.create(null);\n\t\tif (descriptor.get || descriptor.set) {\n\t\t\tpropertyDescriptor.get = Contextify.value(descriptor.get, null, deepTraps, flags) || undefined;\n\t\t\tpropertyDescriptor.set = Contextify.value(descriptor.set, null, deepTraps, flags) || undefined;\n\t\t\tpropertyDescriptor.enumerable = descriptor.enumerable === true;\n\t\t\tpropertyDescriptor.configurable = descriptor.configurable === true;\n\t\t} else {\n\t\t\tpropertyDescriptor.value = Contextify.value(descriptor.value, null, deepTraps, flags);\n\t\t\tpropertyDescriptor.writable = descriptor.writable === true;\n\t\t\tpropertyDescriptor.enumerable = descriptor.enumerable === true;\n\t\t\tpropertyDescriptor.configurable = descriptor.configurable === true;\n\t\t}\n\n\t\ttry {\n\t\t\tsuccess = local.Reflect.defineProperty(object, key, propertyDescriptor);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t\tif (success && !descriptor.configurable) {\n\t\t\ttry {\n\t\t\t\tlocal.Reflect.defineProperty(target, key, descriptor);\n\t\t\t} catch (e) {\n\t\t\t\t// This should not happen.\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn success;\n\t};\n\tbase.deleteProperty = (target, prop) => {\n\t\ttry {\n\t\t\treturn Decontextify.value(local.Reflect.deleteProperty(object, prop));\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.getPrototypeOf = (target) => {\n\t\treturn host.Object.prototype;\n\t};\n\tbase.setPrototypeOf = (target) => {\n\t\tthrow new host.Error(OPNA);\n\t};\n\tbase.has = (target, key) => {\n\t\ttry {\n\t\t\treturn Decontextify.value(local.Reflect.has(object, key));\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.isExtensible = target => {\n\t\tlet result;\n\t\ttry {\n\t\t\tresult = local.Reflect.isExtensible(object);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t\tif (!result) {\n\t\t\ttry {\n\t\t\t\tif (local.Reflect.isExtensible(target)) {\n\t\t\t\t\tdoPreventExtensions(target, object, obj => Contextify.value(obj, null, deepTraps, flags));\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Should not happen\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t};\n\tbase.ownKeys = target => {\n\t\ttry {\n\t\t\treturn Decontextify.value(local.Reflect.ownKeys(object));\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\tbase.preventExtensions = target => {\n\t\tlet success;\n\t\ttry {\n\t\t\tsuccess = local.Reflect.preventExtensions(object);\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t\tif (success) {\n\t\t\ttry {\n\t\t\t\tif (local.Reflect.isExtensible(target)) {\n\t\t\t\t\tdoPreventExtensions(target, object, obj => Contextify.value(obj, null, deepTraps, flags));\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Should not happen\n\t\t\t}\n\t\t}\n\t\treturn success;\n\t};\n\tbase.enumerate = target => {\n\t\ttry {\n\t\t\treturn Decontextify.value(local.Reflect.enumerate(object));\n\t\t} catch (e) {\n\t\t\tthrow Decontextify.value(e);\n\t\t}\n\t};\n\n\thost.Object.assign(base, traps, deepTraps);\n\n\tlet shallow;\n\tif (host.Array.isArray(object)) {\n\t\tconst origGet = base.get;\n\t\tshallow = {\n\t\t\t__proto__: null,\n\t\t\townKeys: base.ownKeys,\n\t\t\t// TODO this get will call getOwnPropertyDescriptor of target all the time.\n\t\t\tget: origGet\n\t\t};\n\t\tbase.ownKeys = target => {\n\t\t\ttry {\n\t\t\t\tconst keys = local.Reflect.ownKeys(object);\n\t\t\t\t// Do this hack so that console.log(decontextify([1,2,3])) doesn't write the properties twice\n\t\t\t\t// a la [1,2,3,'0':1,'1':2,'2':3]\n\t\t\t\treturn Decontextify.value(keys.filter(key=>typeof key!=='string' || !key.match(/^\\d+$/)));\n\t\t\t} catch (e) {\n\t\t\t\tthrow Decontextify.value(e);\n\t\t\t}\n\t\t};\n\t\tbase.get = (target, key, receiver) => {\n\t\t\tif (key === host.Symbol.toStringTag) return;\n\t\t\treturn origGet(target, key, receiver);\n\t\t};\n\t} else {\n\t\tshallow = SHARED_OBJECT;\n\t}\n\n\tconst proxy = new host.Proxy(createBaseObject(object), base);\n\tDecontextified.set(proxy, object);\n\t// We need two proxies since nodes inspect just removes one.\n\tconst proxy2 = new host.Proxy(proxy, shallow);\n\tDecontextify.proxies.set(object, proxy2);\n\tDecontextified.set(proxy2, object);\n\treturn proxy2;\n};\nDecontextify.value = (value, traps, deepTraps, flags, mock) => {\n\ttry {\n\t\tif (Contextified.has(value)) {\n\t\t\t// Contextified object has returned back from vm\n\t\t\treturn Contextified.get(value);\n\t\t} else if (Decontextify.proxies.has(value)) {\n\t\t\t// Decontextified proxy already exists, reuse\n\t\t\treturn Decontextify.proxies.get(value);\n\t\t}\n\n\t\tswitch (typeof value) {\n\t\t\tcase 'object':\n\t\t\t\tif (value === null) {\n\t\t\t\t\treturn null;\n\t\t\t\t} else if (instanceOf(value, Number)) { return Decontextify.instance(value, host.Number, deepTraps, flags, 'Number');\n\t\t\t\t} else if (instanceOf(value, String)) { return Decontextify.instance(value, host.String, deepTraps, flags, 'String');\n\t\t\t\t} else if (instanceOf(value, Boolean)) { return Decontextify.instance(value, host.Boolean, deepTraps, flags, 'Boolean');\n\t\t\t\t} else if (instanceOf(value, Date)) { return Decontextify.instance(value, host.Date, deepTraps, flags, 'Date');\n\t\t\t\t} else if (instanceOf(value, RangeError)) { return Decontextify.instance(value, host.RangeError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, ReferenceError)) { return Decontextify.instance(value, host.ReferenceError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, SyntaxError)) { return Decontextify.instance(value, host.SyntaxError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, TypeError)) { return Decontextify.instance(value, host.TypeError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, VMError)) { return Decontextify.instance(value, host.VMError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, EvalError)) { return Decontextify.instance(value, host.EvalError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, URIError)) { return Decontextify.instance(value, host.URIError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, Error)) { return Decontextify.instance(value, host.Error, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, Array)) { return Decontextify.instance(value, host.Array, deepTraps, flags, 'Array');\n\t\t\t\t} else if (instanceOf(value, RegExp)) { return Decontextify.instance(value, host.RegExp, deepTraps, flags, 'RegExp');\n\t\t\t\t} else if (instanceOf(value, Map)) { return Decontextify.instance(value, host.Map, deepTraps, flags, 'Map');\n\t\t\t\t} else if (instanceOf(value, WeakMap)) { return Decontextify.instance(value, host.WeakMap, deepTraps, flags, 'WeakMap');\n\t\t\t\t} else if (instanceOf(value, Set)) { return Decontextify.instance(value, host.Set, deepTraps, flags, 'Set');\n\t\t\t\t} else if (instanceOf(value, WeakSet)) { return Decontextify.instance(value, host.WeakSet, deepTraps, flags, 'WeakSet');\n\t\t\t\t} else if (typeof Promise === 'function' && instanceOf(value, Promise)) {\n\t\t\t\t\treturn Decontextify.instance(value, host.Promise, deepTraps, flags, 'Promise');\n\t\t\t\t} else if (local.Reflect.getPrototypeOf(value) === null) {\n\t\t\t\t\treturn Decontextify.instance(value, null, deepTraps, flags);\n\t\t\t\t} else {\n\t\t\t\t\treturn Decontextify.object(value, traps, deepTraps, flags, mock);\n\t\t\t\t}\n\t\t\tcase 'function':\n\t\t\t\treturn Decontextify.function(value, traps, deepTraps, flags, mock);\n\n\t\t\tcase 'undefined':\n\t\t\t\treturn undefined;\n\n\t\t\tcase 'string':\n\t\t\tcase 'number':\n\t\t\tcase 'boolean':\n\t\t\tcase 'symbol':\n\t\t\tcase 'bigint':\n\t\t\t\treturn value;\n\n\t\t\tdefault: // new, unknown types can be dangerous\n\t\t\t\treturn null;\n\t\t}\n\t} catch (ex) {\n\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\treturn null;\n\t}\n};\n\n/**\n * Contextify.\n */\n\nconst Contextify = host.Object.create(null);\nContextify.proxies = new host.WeakMap();\n\nContextify.arguments = args => {\n\tif (!host.Array.isArray(args)) return new local.Array();\n\n\ttry {\n\t\tconst arr = new local.Array();\n\t\tfor (let i = 0, l = args.length; i < l; i++) arr[i] = Contextify.value(args[i]);\n\t\treturn arr;\n\t} catch (e) {\n\t\t// Never pass the handled exception through!\n\t\treturn new local.Array();\n\t}\n};\nContextify.instance = (instance, klass, deepTraps, flags, toStringTag) => {\n\tif (typeof instance === 'function') return Contextify.function(instance);\n\n\t// We must not use normal object because there's a chance object already contains malicious code in the prototype\n\tconst base = host.Object.create(null);\n\n\tbase.get = (target, key, receiver) => {\n\t\ttry {\n\t\t\tif (key === 'vmProxyTarget' && DEBUG) return instance;\n\t\t\tif (key === 'isVMProxy') return true;\n\t\t\tif (key === 'constructor') return klass;\n\t\t\tif (key === '__proto__') return klass.prototype;\n\t\t} catch (e) {\n\t\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\t\treturn null;\n\t\t}\n\n\t\tif (key === '__defineGetter__') return local.Object.prototype.__defineGetter__;\n\t\tif (key === '__defineSetter__') return local.Object.prototype.__defineSetter__;\n\t\tif (key === '__lookupGetter__') return local.Object.prototype.__lookupGetter__;\n\t\tif (key === '__lookupSetter__') return local.Object.prototype.__lookupSetter__;\n\t\tif (key === host.Symbol.toStringTag && toStringTag) return toStringTag;\n\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.get(instance, key), null, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.getPrototypeOf = (target) => {\n\t\treturn klass && klass.prototype;\n\t};\n\n\treturn Contextify.object(instance, base, deepTraps, flags);\n};\nContextify.function = (fnc, traps, deepTraps, flags, mock) => {\n\t// We must not use normal object because there's a chance object already contains malicious code in the prototype\n\tconst base = host.Object.create(null);\n\t// eslint-disable-next-line prefer-const\n\tlet proxy;\n\n\tbase.apply = (target, context, args) => {\n\t\t// Fixes buffer unsafe allocation for node v6/7\n\t\tif (host.version < 8 && fnc === host.Buffer && 'number' === typeof args[0]) {\n\t\t\targs[0] = new local.Array(args[0]).fill(0);\n\t\t}\n\n\t\tcontext = Decontextify.value(context);\n\n\t\t// Set context of all arguments to host's context.\n\t\targs = Decontextify.arguments(args);\n\n\t\ttry {\n\t\t\treturn Contextify.value(fnc.apply(context, args));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.construct = (target, args, newTarget) => {\n\t\t// Fixes buffer unsafe allocation for node v6/7\n\t\tif (host.version < 8 && fnc === host.Buffer && 'number' === typeof args[0]) {\n\t\t\targs[0] = new local.Array(args[0]).fill(0);\n\t\t}\n\n\t\targs = Decontextify.arguments(args);\n\n\t\ttry {\n\t\t\treturn Contextify.instance(new fnc(...args), proxy, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.get = (target, key, receiver) => {\n\t\ttry {\n\t\t\tif (key === 'vmProxyTarget' && DEBUG) return fnc;\n\t\t\tif (key === 'isVMProxy') return true;\n\t\t\tif (mock && host.Object.prototype.hasOwnProperty.call(mock, key)) return mock[key];\n\t\t\tif (key === 'constructor') return Function;\n\t\t\tif (key === '__proto__') return Function.prototype;\n\t\t} catch (e) {\n\t\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\t\treturn null;\n\t\t}\n\n\t\tif (key === '__defineGetter__') return local.Object.prototype.__defineGetter__;\n\t\tif (key === '__defineSetter__') return local.Object.prototype.__defineSetter__;\n\t\tif (key === '__lookupGetter__') return local.Object.prototype.__lookupGetter__;\n\t\tif (key === '__lookupSetter__') return local.Object.prototype.__lookupSetter__;\n\n\t\tif (key === 'caller' || key === 'callee' || key === 'arguments') throw throwCallerCalleeArgumentsAccess(key);\n\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.get(fnc, key), null, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.getPrototypeOf = (target) => {\n\t\treturn Function.prototype;\n\t};\n\n\tproxy = Contextify.object(fnc, host.Object.assign(base, traps), deepTraps);\n\treturn proxy;\n};\nContextify.object = (object, traps, deepTraps, flags, mock) => {\n\t// We must not use normal object because there's a chance object already contains malicious code in the prototype\n\tconst base = host.Object.create(null);\n\n\tbase.get = (target, key, receiver) => {\n\t\ttry {\n\t\t\tif (key === 'vmProxyTarget' && DEBUG) return object;\n\t\t\tif (key === 'isVMProxy') return true;\n\t\t\tif (mock && host.Object.prototype.hasOwnProperty.call(mock, key)) return mock[key];\n\t\t\tif (key === 'constructor') return Object;\n\t\t\tif (key === '__proto__') return Object.prototype;\n\t\t} catch (e) {\n\t\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\t\treturn null;\n\t\t}\n\n\t\tif (key === '__defineGetter__') return local.Object.prototype.__defineGetter__;\n\t\tif (key === '__defineSetter__') return local.Object.prototype.__defineSetter__;\n\t\tif (key === '__lookupGetter__') return local.Object.prototype.__lookupGetter__;\n\t\tif (key === '__lookupSetter__') return local.Object.prototype.__lookupSetter__;\n\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.get(object, key), null, deepTraps, flags);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.set = (target, key, value, receiver) => {\n\t\tif (key === '__proto__') return false;\n\t\tif (flags && flags.protected && typeof value === 'function') return false;\n\n\t\tvalue = Decontextify.value(value);\n\n\t\ttry {\n\t\t\treturn host.Reflect.set(object, key, value);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.getOwnPropertyDescriptor = (target, prop) => {\n\t\tlet def;\n\n\t\ttry {\n\t\t\tdef = host.Object.getOwnPropertyDescriptor(object, prop);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\n\t\t// Following code prevents V8 to throw\n\t\t// TypeError: 'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property '<prop>'\n\t\t// which is either non-existant or configurable in the proxy target\n\n\t\tlet desc;\n\t\tif (!def) {\n\t\t\treturn undefined;\n\t\t} else if (def.get || def.set) {\n\t\t\tdesc = {\n\t\t\t\t__proto__: null,\n\t\t\t\tget: Contextify.value(def.get, null, deepTraps, flags) || undefined,\n\t\t\t\tset: Contextify.value(def.set, null, deepTraps, flags) || undefined,\n\t\t\t\tenumerable: def.enumerable === true,\n\t\t\t\tconfigurable: def.configurable === true\n\t\t\t};\n\t\t} else {\n\t\t\tdesc = {\n\t\t\t\t__proto__: null,\n\t\t\t\tvalue: Contextify.value(def.value, null, deepTraps, flags),\n\t\t\t\twritable: def.writable === true,\n\t\t\t\tenumerable: def.enumerable === true,\n\t\t\t\tconfigurable: def.configurable === true\n\t\t\t};\n\t\t}\n\t\tif (!desc.configurable) {\n\t\t\ttry {\n\t\t\t\tdef = host.Object.getOwnPropertyDescriptor(target, prop);\n\t\t\t\tif (!def || def.configurable || def.writable !== desc.writable) {\n\t\t\t\t\tlocal.Reflect.defineProperty(target, prop, desc);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Should not happen.\n\t\t\t}\n\t\t}\n\t\treturn desc;\n\t};\n\tbase.defineProperty = (target, key, descriptor) => {\n\t\tlet success = false;\n\t\ttry {\n\t\t\tsuccess = local.Reflect.setPrototypeOf(descriptor, null);\n\t\t} catch (e) {\n\t\t\t// Should not happen\n\t\t}\n\t\tif (!success) return false;\n\t\t// There's a chance accessing a property throws an error so we must not access them\n\t\t// in try catch to prevent contextifying local objects.\n\n\t\tconst descGet = descriptor.get;\n\t\tconst descSet = descriptor.set;\n\t\tconst descValue = descriptor.value;\n\n\t\tif (flags && flags.protected) {\n\t\t\tif (descGet || descSet || typeof descValue === 'function') return false;\n\t\t}\n\n\t\tconst propertyDescriptor = host.Object.create(null);\n\t\tif (descGet || descSet) {\n\t\t\tpropertyDescriptor.get = Decontextify.value(descGet, null, deepTraps, flags) || undefined;\n\t\t\tpropertyDescriptor.set = Decontextify.value(descSet, null, deepTraps, flags) || undefined;\n\t\t\tpropertyDescriptor.enumerable = descriptor.enumerable === true;\n\t\t\tpropertyDescriptor.configurable = descriptor.configurable === true;\n\t\t} else {\n\t\t\tpropertyDescriptor.value = Decontextify.value(descValue, null, deepTraps, flags);\n\t\t\tpropertyDescriptor.writable = descriptor.writable === true;\n\t\t\tpropertyDescriptor.enumerable = descriptor.enumerable === true;\n\t\t\tpropertyDescriptor.configurable = descriptor.configurable === true;\n\t\t}\n\n\t\ttry {\n\t\t\tsuccess = host.Reflect.defineProperty(object, key, propertyDescriptor);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t\tif (success && !descriptor.configurable) {\n\t\t\ttry {\n\t\t\t\tlocal.Reflect.defineProperty(target, key, descriptor);\n\t\t\t} catch (e) {\n\t\t\t\t// This should not happen.\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn success;\n\t};\n\tbase.deleteProperty = (target, prop) => {\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.deleteProperty(object, prop));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.getPrototypeOf = (target) => {\n\t\treturn local.Object.prototype;\n\t};\n\tbase.setPrototypeOf = (target) => {\n\t\tthrow new VMError(OPNA);\n\t};\n\tbase.has = (target, key) => {\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.has(object, key));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.isExtensible = target => {\n\t\tlet result;\n\t\ttry {\n\t\t\tresult = host.Reflect.isExtensible(object);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t\tif (!result) {\n\t\t\ttry {\n\t\t\t\tif (local.Reflect.isExtensible(target)) {\n\t\t\t\t\tdoPreventExtensions(target, object, obj => Decontextify.value(obj, null, deepTraps, flags));\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Should not happen\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t};\n\tbase.ownKeys = target => {\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.ownKeys(object));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\tbase.preventExtensions = target => {\n\t\tlet success;\n\t\ttry {\n\t\t\tsuccess = local.Reflect.preventExtensions(object);\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t\tif (success) {\n\t\t\ttry {\n\t\t\t\tif (local.Reflect.isExtensible(target)) {\n\t\t\t\t\tdoPreventExtensions(target, object, obj => Decontextify.value(obj, null, deepTraps, flags));\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\t// Should not happen\n\t\t\t}\n\t\t}\n\t\treturn success;\n\t};\n\tbase.enumerate = target => {\n\t\ttry {\n\t\t\treturn Contextify.value(host.Reflect.enumerate(object));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t};\n\n\tconst proxy = new host.Proxy(createBaseObject(object), host.Object.assign(base, traps, deepTraps));\n\tContextify.proxies.set(object, proxy);\n\tContextified.set(proxy, object);\n\treturn proxy;\n};\nContextify.value = (value, traps, deepTraps, flags, mock) => {\n\ttry {\n\t\tif (Decontextified.has(value)) {\n\t\t\t// Decontextified object has returned back to vm\n\t\t\treturn Decontextified.get(value);\n\t\t} else if (Contextify.proxies.has(value)) {\n\t\t\t// Contextified proxy already exists, reuse\n\t\t\treturn Contextify.proxies.get(value);\n\t\t}\n\n\t\tswitch (typeof value) {\n\t\t\tcase 'object':\n\t\t\t\tif (value === null) {\n\t\t\t\t\treturn null;\n\t\t\t\t} else if (instanceOf(value, host.Number)) { return Contextify.instance(value, Number, deepTraps, flags, 'Number');\n\t\t\t\t} else if (instanceOf(value, host.String)) { return Contextify.instance(value, String, deepTraps, flags, 'String');\n\t\t\t\t} else if (instanceOf(value, host.Boolean)) { return Contextify.instance(value, Boolean, deepTraps, flags, 'Boolean');\n\t\t\t\t} else if (instanceOf(value, host.Date)) { return Contextify.instance(value, Date, deepTraps, flags, 'Date');\n\t\t\t\t} else if (instanceOf(value, host.RangeError)) { return Contextify.instance(value, RangeError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.ReferenceError)) { return Contextify.instance(value, ReferenceError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.SyntaxError)) { return Contextify.instance(value, SyntaxError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.TypeError)) { return Contextify.instance(value, TypeError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.VMError)) { return Contextify.instance(value, VMError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.EvalError)) { return Contextify.instance(value, EvalError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.URIError)) { return Contextify.instance(value, URIError, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.Error)) { return Contextify.instance(value, Error, deepTraps, flags, 'Error');\n\t\t\t\t} else if (instanceOf(value, host.Array)) { return Contextify.instance(value, Array, deepTraps, flags, 'Array');\n\t\t\t\t} else if (instanceOf(value, host.RegExp)) { return Contextify.instance(value, RegExp, deepTraps, flags, 'RegExp');\n\t\t\t\t} else if (instanceOf(value, host.Map)) { return Contextify.instance(value, Map, deepTraps, flags, 'Map');\n\t\t\t\t} else if (instanceOf(value, host.WeakMap)) { return Contextify.instance(value, WeakMap, deepTraps, flags, 'WeakMap');\n\t\t\t\t} else if (instanceOf(value, host.Set)) { return Contextify.instance(value, Set, deepTraps, flags, 'Set');\n\t\t\t\t} else if (instanceOf(value, host.WeakSet)) { return Contextify.instance(value, WeakSet, deepTraps, flags, 'WeakSet');\n\t\t\t\t} else if (typeof Promise === 'function' && instanceOf(value, host.Promise)) {\n\t\t\t\t\treturn Contextify.instance(value, Promise, deepTraps, flags, 'Promise');\n\t\t\t\t} else if (instanceOf(value, host.Buffer)) { return Contextify.instance(value, LocalBuffer, deepTraps, flags, 'Uint8Array');\n\t\t\t\t} else if (host.Reflect.getPrototypeOf(value) === null) {\n\t\t\t\t\treturn Contextify.instance(value, null, deepTraps, flags);\n\t\t\t\t} else {\n\t\t\t\t\treturn Contextify.object(value, traps, deepTraps, flags, mock);\n\t\t\t\t}\n\t\t\tcase 'function':\n\t\t\t\treturn Contextify.function(value, traps, deepTraps, flags, mock);\n\n\t\t\tcase 'undefined':\n\t\t\t\treturn undefined;\n\n\t\t\tcase 'string':\n\t\t\tcase 'number':\n\t\t\tcase 'boolean':\n\t\t\tcase 'symbol':\n\t\t\tcase 'bigint':\n\t\t\t\treturn value;\n\n\t\t\tdefault: // new, unknown types can be dangerous\n\t\t\t\treturn null;\n\t\t}\n\t} catch (ex) {\n\t\t// Never pass the handled exception through! This block can't throw an exception under normal conditions.\n\t\treturn null;\n\t}\n};\nContextify.setGlobal = (name, value) => {\n\tconst prop = Contextify.value(name);\n\ttry {\n\t\tglobal[prop] = Contextify.value(value);\n\t} catch (e) {\n\t\tthrow Decontextify.value(e);\n\t}\n};\nContextify.getGlobal = (name) => {\n\tconst prop = Contextify.value(name);\n\ttry {\n\t\treturn Decontextify.value(global[prop]);\n\t} catch (e) {\n\t\tthrow Decontextify.value(e);\n\t}\n};\nContextify.readonly = (value, mock) => {\n\treturn Contextify.value(value, null, FROZEN_TRAPS, null, mock);\n};\nContextify.protected = (value, mock) => {\n\treturn Contextify.value(value, null, null, {protected: true}, mock);\n};\nContextify.connect = (outer, inner) => {\n\tDecontextified.set(outer, inner);\n\tContextified.set(inner, outer);\n};\nContextify.makeModule = ()=>({exports: {}});\nContextify.isVMProxy = (obj) => Decontextified.has(obj);\n\nconst BufferMock = host.Object.create(null);\nBufferMock.allocUnsafe = function allocUnsafe(size) {\n\treturn this.alloc(size);\n};\nBufferMock.allocUnsafeSlow = function allocUnsafeSlow(size) {\n\treturn this.alloc(size);\n};\nconst BufferOverride = host.Object.create(null);\nBufferOverride.inspect = function inspect(recurseTimes, ctx) {\n\t// Mimic old behavior, could throw but didn't pass a test.\n\tconst max = host.INSPECT_MAX_BYTES;\n\tconst actualMax = Math.min(max, this.length);\n\tconst remaining = this.length - max;\n\tlet str = this.hexSlice(0, actualMax).replace(/(.{2})/g, '$1 ').trim();\n\tif (remaining > 0) str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;\n\treturn `<${this.constructor.name} ${str}>`;\n};\nconst LocalBuffer = global.Buffer = Contextify.readonly(host.Buffer, BufferMock);\nContextify.connect(host.Buffer.prototype.inspect, BufferOverride.inspect);\nContextify.connect(host.Function.prototype.bind, Function.prototype.bind);\n\nconst oldPrepareStackTraceDesc = Reflect.getOwnPropertyDescriptor(Error, 'prepareStackTrace');\n\nlet currentPrepareStackTrace = Error.prepareStackTrace;\nconst wrappedPrepareStackTrace = new host.WeakMap();\nif (typeof currentPrepareStackTrace === 'function') {\n\twrappedPrepareStackTrace.set(currentPrepareStackTrace, currentPrepareStackTrace);\n}\n\nlet OriginalCallSite;\nError.prepareStackTrace = (e, sst) => {\n\tOriginalCallSite = sst[0].constructor;\n};\nnew Error().stack;\nif (typeof OriginalCallSite === 'function') {\n\tError.prepareStackTrace = undefined;\n\n\tfunction makeCallSiteGetters(list) {\n\t\tconst callSiteGetters = [];\n\t\tfor (let i=0; i<list.length; i++) {\n\t\t\tconst name = list[i];\n\t\t\tconst func = OriginalCallSite.prototype[name];\n\t\t\tcallSiteGetters[i] = {__proto__: null,\n\t\t\t\tname,\n\t\t\t\tpropName: '_' + name,\n\t\t\t\tfunc: (thiz) => {\n\t\t\t\t\treturn local.Reflect.apply(func, thiz, []);\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t\treturn callSiteGetters;\n\t}\n\n\tfunction applyCallSiteGetters(callSite, getters) {\n\t\tconst properties = {__proto__: null};\n\t\tfor (let i=0; i<getters.length; i++) {\n\t\t\tconst getter = getters[i];\n\t\t\tproperties[getter.propName] = {\n\t\t\t\t__proto__: null,\n\t\t\t\tvalue: getter.func(callSite)\n\t\t\t};\n\t\t}\n\t\treturn properties;\n\t}\n\n\tconst callSiteGetters = makeCallSiteGetters([\n\t\t'getTypeName',\n\t\t'getFunctionName',\n\t\t'getMethodName',\n\t\t'getFileName',\n\t\t'getLineNumber',\n\t\t'getColumnNumber',\n\t\t'getEvalOrigin',\n\t\t'isToplevel',\n\t\t'isEval',\n\t\t'isNative',\n\t\t'isConstructor',\n\t\t'isAsync',\n\t\t'isPromiseAll',\n\t\t'getPromiseIndex'\n\t]);\n\n\tclass CallSite {\n\t\tconstructor(callSite) {\n\t\t\tObject.defineProperties(this, applyCallSiteGetters(callSite, callSiteGetters));\n\t\t}\n\t\tgetThis() {return undefined;}\n\t\tgetFunction() {return undefined;}\n\t\ttoString() {return 'CallSite {}';}\n\t}\n\n\t(function setupCallSite() {\n\t\tfor (let i=0; i<callSiteGetters.length; i++) {\n\t\t\tconst name = callSiteGetters[i].name;\n\t\t\tconst funcProp = Object.getOwnPropertyDescriptor(OriginalCallSite.prototype, name);\n\t\t\tif (funcProp === undefined) continue;\n\t\t\tconst propertyName = callSiteGetters[i].propName;\n\t\t\tconst func = {func() {\n\t\t\t\treturn this[propertyName];\n\t\t\t}}.func;\n\t\t\tconst nameProp = Object.getOwnPropertyDescriptor(func, 'name');\n\t\t\tnameProp.value = name;\n\t\t\tObject.defineProperty(func, 'name', nameProp);\n\t\t\tfuncProp.value = func;\n\t\t\tObject.defineProperty(CallSite.prototype, name, funcProp);\n\t\t}\n\t})();\n\n\tObject.defineProperty(Error, 'prepareStackTrace', {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\tget() {\n\t\t\treturn currentPrepareStackTrace;\n\t\t},\n\t\tset(value) {\n\t\t\tif (typeof(value) !== 'function') {\n\t\t\t\tcurrentPrepareStackTrace = value;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst wrapped = wrappedPrepareStackTrace.get(value);\n\t\t\tif (wrapped) {\n\t\t\t\tcurrentPrepareStackTrace = wrapped;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst newWrapped = (error, sst) => {\n\t\t\t\tif (host.Array.isArray(sst)) {\n\t\t\t\t\tfor (let i=0; i<sst.length; i++) {\n\t\t\t\t\t\tconst cs = sst[i];\n\t\t\t\t\t\tif (typeof cs === 'object' && local.Reflect.getPrototypeOf(cs) === OriginalCallSite.prototype) {\n\t\t\t\t\t\t\tsst[i] = new CallSite(cs);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn value(error, sst);\n\t\t\t};\n\t\t\twrappedPrepareStackTrace.set(value, newWrapped);\n\t\t\twrappedPrepareStackTrace.set(newWrapped, newWrapped);\n\t\t\tcurrentPrepareStackTrace = newWrapped;\n\t\t}\n\t});\n} else if (oldPrepareStackTraceDesc) {\n\tReflect.defineProperty(Error, 'prepareStackTrace', oldPrepareStackTraceDesc);\n} else {\n\tReflect.deleteProperty(Error, 'prepareStackTrace');\n}\n\n\nconst exportsMap = host.Object.create(null);\nexportsMap.Contextify = Contextify;\nexportsMap.Decontextify = Decontextify;\nexportsMap.Buffer = LocalBuffer;\nexportsMap.sandbox = Decontextify.value(global);\nexportsMap.Function = Function;\n\nreturn exportsMap;\n"; const fixAsyncJS = "'use strict';\n\n// eslint-disable-next-line no-invalid-this, no-shadow\nconst {GeneratorFunction, AsyncFunction, AsyncGeneratorFunction, global, internal, host, hook} = this;\nconst {Contextify, Decontextify} = internal;\n// eslint-disable-next-line no-shadow\nconst {Function, eval: eval_, Promise, Object, Reflect} = global;\nconst {getOwnPropertyDescriptor, defineProperty, assign} = Object;\nconst {apply: rApply, construct: rConstruct} = Reflect;\n\nconst FunctionHandler = {\n\t__proto__: null,\n\tapply(target, thiz, args) {\n\t\tconst type = this.type;\n\t\targs = Decontextify.arguments(args);\n\t\ttry {\n\t\t\targs = Contextify.value(hook(type, args));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t\treturn rApply(target, thiz, args);\n\t},\n\tconstruct(target, args, newTarget) {\n\t\tconst type = this.type;\n\t\targs = Decontextify.arguments(args);\n\t\ttry {\n\t\t\targs = Contextify.value(hook(type, args));\n\t\t} catch (e) {\n\t\t\tthrow Contextify.value(e);\n\t\t}\n\t\treturn rConstruct(target, args, newTarget);\n\t}\n};\n\nfunction makeCheckFunction(type) {\n\treturn assign({\n\t\t__proto__: null,\n\t\ttype\n\t}, FunctionHandler);\n}\n\nfunction override(obj, prop, value) {\n\tconst desc = getOwnPropertyDescriptor(obj, prop);\n\tdesc.value = value;\n\tdefineProperty(obj, prop, desc);\n}\n\nconst proxiedFunction = new host.Proxy(Function, makeCheckFunction('function'));\noverride(Function.prototype, 'constructor', proxiedFunction);\nif (GeneratorFunction) {\n\tObject.setPrototypeOf(GeneratorFunction, proxiedFunction);\n\toverride(GeneratorFunction.prototype, 'constructor', new host.Proxy(GeneratorFunction, makeCheckFunction('generator_function')));\n}\nif (AsyncFunction) {\n\tObject.setPrototypeOf(AsyncFunction, proxiedFunction);\n\toverride(AsyncFunction.prototype, 'constructor', new host.Proxy(AsyncFunction, makeCheckFunction('async_function')));\n}\nif (AsyncGeneratorFunction) {\n\tObject.setPrototypeOf(AsyncGeneratorFunction, proxiedFunction);\n\toverride(AsyncGeneratorFunction.prototype, 'constructor', new host.Proxy(AsyncGeneratorFunction, makeCheckFunction('async_generator_function')));\n}\n\nglobal.Function = proxiedFunction;\nglobal.eval = new host.Proxy(eval_, makeCheckFunction('eval'));\n\nif (Promise) {\n\n\tPromise.prototype.then = new host.Proxy(Promise.prototype.then, makeCheckFunction('promise_then'));\n\t// This seems not to work, and will produce\n\t// UnhandledPromiseRejectionWarning: TypeError: Method Promise.prototype.then called on incompatible receiver [object Object].\n\t// This is likely caused since the host.Promise.prototype.then cannot use the VM Proxy object.\n\t// Contextify.connect(host.Promise.prototype.then, Promise.prototype.then);\n\n\tif (Promise.prototype.finally) {\n\t\tPromise.prototype.finally = new host.Proxy(Promise.prototype.finally, makeCheckFunction('promise_finally'));\n\t\t// Contextify.connect(host.Promise.prototype.finally, Promise.prototype.finally);\n\t}\n\tif (Promise.prototype.catch) {\n\t\tPromise.prototype.catch = new host.Proxy(Promise.prototype.catch, makeCheckFunction('promise_catch'));\n\t\t// Contextify.connect(host.Promise.prototype.catch, Promise.prototype.catch);\n\t}\n\n}\n"; const sandboxJS = "/* eslint-disable no-shadow, no-invalid-this */\n/* global vm, host, Contextify, Decontextify, VMError, options */\n\n'use strict';\n\nconst {Script} = host.require('vm');\nconst fs = host.require('fs');\nconst pa = host.require('path');\n\nconst BUILTIN_MODULES = host.process.binding('natives');\nconst parseJSON = JSON.parse;\nconst importModuleDynamically = () => {\n\t// We can't throw an error object here because since vm.Script doesn't store a context, we can't properly contextify that error object.\n\t// eslint-disable-next-line no-throw-literal\n\tthrow 'Dynamic imports are not allowed.';\n};\n\n/**\n * @param {Object} host Hosts's internal objects.\n */\n\nreturn ((vm, host) => {\n\t'use strict';\n\n\tconst global = this;\n\n\tconst TIMERS = new host.WeakMap(); // Contains map of timers created inside sandbox\n\tconst BUILTINS = {__proto__: null};\n\tconst CACHE = {__proto__: null};\n\tconst EXTENSIONS = {\n\t\t__proto__: null,\n\t\t['.json'](module, filename) {\n\t\t\ttry {\n\t\t\t\tconst code = fs.readFileSync(filename, 'utf8');\n\t\t\t\tmodule.exports = parseJSON(code);\n\t\t\t} catch (e) {\n\t\t\t\tthrow Contextify.value(e);\n\t\t\t}\n\t\t},\n\t\t['.node'](module, filename) {\n\t\t\tif (vm.options.require.context === 'sandbox') throw new VMError('Native modules can be required only with context set to \\'host\\'.');\n\n\t\t\ttry {\n\t\t\t\tmodule.exports = Contextify.readonly(host.require(filename));\n\t\t\t} catch (e) {\n\t\t\t\tthrow Contextify.value(e);\n\t\t\t}\n\t\t}\n\t};\n\n\tfor (let i = 0; i < vm.options.sourceExtensions.length; i++) {\n\t\tconst ext = vm.options.sourceExtensions[i];\n\n\t\tEXTENSIONS['.' + ext] = (module, filename, dirname) => {\n\t\t\tif (vm.options.require.context !== 'sandbox') {\n\t\t\t\ttry {\n\t\t\t\t\tmodule.exports = Contextify.readonly(host.require(filename));\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow Contextify.value(e);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlet script;\n\n\t\t\t\ttry {\n\t\t\t\t\t// Load module\n\t\t\t\t\tlet contents = fs.readFileSync(filename, 'utf8');\n\t\t\t\t\tcontents = vm._compiler(contents, filename);\n\n\t\t\t\t\tconst code = host.STRICT_MODULE_PREFIX + contents + host.MODULE_SUFFIX;\n\n\t\t\t\t\tconst ccode = vm._hook('run', host.Array.of(code))[0];\n\n\t\t\t\t\t// Precompile script\n\t\t\t\t\tscript = new Script(ccode, {\n\t\t\t\t\t\t__proto__: null,\n\t\t\t\t\t\tfilename: filename || 'vm.js',\n\t\t\t\t\t\tdisplayErrors: false,\n\t\t\t\t\t\timportModuleDynamically\n\t\t\t\t\t});\n\n\t\t\t\t} catch (ex) {\n\t\t\t\t\tthrow Contextify.value(ex);\n\t\t\t\t}\n\n\t\t\t\tconst closure = script.runInContext(global, {\n\t\t\t\t\t__proto__: null,\n\t\t\t\t\tfilename: filename || 'vm.js',\n\t\t\t\t\tdisplayErrors: false,\n\t\t\t\t\timportModuleDynamically\n\t\t\t\t});\n\n\t\t\t\t// run the script\n\t\t\t\tclosure(module.exports, module.require, module, filename, dirname);\n\t\t\t}\n\t\t};\n\t}\n\n\tconst _parseExternalOptions = (options) => {\n\t\tif (host.