emulate global context in Node.js & web (#4379)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 13 Dec 2020 18:05:07 +0000 (18:05 +0000)
committerGitHub <noreply@github.com>
Sun, 13 Dec 2020 18:05:07 +0000 (02:05 +0800)
test/compress/ie8.js
test/sandbox.js

index c5b8b15..c28512a 100644 (file)
@@ -588,7 +588,6 @@ issue_3197_1: {
         ie8: false,
     }
     input: {
-        var window = {};
         !function() {
             function Foo() {
                 console.log(this instanceof Foo);
@@ -598,7 +597,6 @@ issue_3197_1: {
         new window.Foo();
     }
     expect: {
-        var window = {};
         window.Foo = function o() {
             console.log(this instanceof o);
         };
@@ -619,7 +617,6 @@ issue_3197_1_ie8: {
         ie8: true,
     }
     input: {
-        var window = {};
         !function() {
             function Foo() {
                 console.log(this instanceof Foo);
@@ -629,7 +626,6 @@ issue_3197_1_ie8: {
         new window.Foo();
     }
     expect: {
-        var window = {};
         window.Foo = function Foo() {
             console.log(this instanceof Foo);
         };
index 46b1a41..f659427 100644 (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":