on master help sign in
address comments
commit0797e31cdb17593c23c49a4c0643cdb44e35050d authorAmjad Masad <amjad.masad@gmail.com> dateFri 11 Sep 2020, 10:25 (6 years ago) parent19f84e1
2 files changed+22−11
languages/nodejs/repl.js+10−10 test_files/global_bug.js+12−1
languages/nodejs/repl.js+10−10
@@ -1,4 +1,4 @@
1−const util = require('util');
1+const util = require("util");
22const repl = require("repl");
33const path = require("path");
44const fs = require("fs");
@@ -139,11 +139,6 @@ if (process.env.PRYBAR_CODE) {
139139 require: module.require.bind(module),
140140 __dirname: path.dirname(mainPath),
141141 __filename: mainPath,
142−
143− // These are deprecated properties and accessing them will trigger a warning.
144− // We add them manually for backward compat.
145− GLOBAL: global,
146− root: global,
147142 };
148143
149144 console.log(
@@ -152,13 +147,18 @@ if (process.env.PRYBAR_CODE) {
152147 const context = vm.createContext(sandbox);
153148
154149 // Adapted from https://bit.ly/2Fc4WjM
155− const globalBuiltins =
156− new Set(vm.runInNewContext('Object.getOwnPropertyNames(globalThis)'));
150+ const globalBuiltins = new Set(
151+ vm.runInContext("Object.getOwnPropertyNames(globalThis)", context)
152+ );
153+
157154 for (const name of Object.getOwnPropertyNames(global)) {
158155 // Only set properties that do not already exist as a global builtin.
159156 if (!globalBuiltins.has(name)) {
160− Object.defineProperty(context, name,
161− Object.getOwnPropertyDescriptor(global, name));
157+ Object.defineProperty(
158+ context,
159+ name,
160+ Object.getOwnPropertyDescriptor(global, name)
161+ );
162162 }
163163 }
164164 context.global = context;
test_files/global_bug.js+12−1
@@ -1 +1,12 @@
1−console.log([] instanceof global.Array);
1+console.log([] instanceof global.Array);
2+console.assert(process);
3+console.assert(URL);
4+console.assert(URLSearchParams);
5+console.assert(clearImmediate);
6+console.assert(clearInterval);
7+console.assert(clearTimeout);
8+console.assert(setImmediate);
9+console.assert(setInterval);
10+console.assert(setTimeout);
11+console.assert(Buffer);
12+console.assert(globalThis === global);