emulate global context in Node.js & web (#4379)

This commit is contained in:
Alex Lam S.L
2020-12-13 18:05:07 +00:00
committed by GitHub
parent fcc40d0502
commit f579f1aa47
2 changed files with 10 additions and 5 deletions

View File

@@ -26,10 +26,19 @@ var setupContext = new vm.Script([
]).join("\n"));
function createContext() {
var ctx = vm.createContext(Object.defineProperty({}, "console", { value: { log: log } }));
var ctx = vm.createContext(Object.defineProperties({}, {
console: { value: { log: log } },
global: { get: self },
self: { get: self },
window: { get: self },
}));
var global = setupContext.runInContext(ctx);
return ctx;
function self() {
return this;
}
function safe_log(arg, level) {
if (arg) switch (typeof arg) {
case "function":