@@ -9,7 +9,6 @@ const rl = require(path.join(
99 "nodejs",
1010 "readline-sync.js"
1111));
12−const tty = require("tty");
1312const Module = require("module");
1413
1514let r;
@@ -74,8 +73,8 @@ function handleError(e) {
7473function start(context) {
7574 r = repl.start({
7675 prompt: process.env.PRYBAR_PS1,
76+ useGlobal: true,
7777 });
78− if (context) r.context = context;
7978
8079 // remove the internal error and ours for red etc.
8180 r._domain.removeListener("error", r._domain.listeners("error")[0]);
@@ -133,35 +132,15 @@ if (process.env.PRYBAR_CODE) {
133132 module.paths = Module._nodeModulePaths(path.dirname(mainPath));
134133
135134 process.mainModule = module;
136− const sandbox = {
137− console,
138− module,
139− require: module.require.bind(module),
140− __dirname: path.dirname(mainPath),
141− __filename: mainPath,
142− };
135+
136+ global.module = module;
137+ global.require = module.require.bind(module);
138+ global.__dirname = path.dirname(mainPath);
139+ global.__filename = mainPath;
143140
144141 console.log(
145142 "\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m"
146143 );
147− const context = vm.createContext(sandbox);
148−
149− // Adapted from https://bit.ly/2Fc4WjM
150− const globalBuiltins = new Set(
151− vm.runInContext("Object.getOwnPropertyNames(globalThis)", context)
152− );
153−
154− for (const name of Object.getOwnPropertyNames(global)) {
155− // Only set properties that do not already exist as a global builtin.
156− if (!globalBuiltins.has(name)) {
157− Object.defineProperty(
158− context,
159− name,
160− Object.getOwnPropertyDescriptor(global, name)
161− );
162− }
163− }
164− context.global = context;
165144
166145 let script;
167146 try {
@@ -176,7 +155,7 @@ if (process.env.PRYBAR_CODE) {
176155 if (script) {
177156 let res;
178157 try {
179− res = script.runInContext(context, {
158+ res = script.runInThisContext({
180159 displayErrors: false,
181160 });
182161 } catch (e) {
@@ -191,8 +170,8 @@ if (process.env.PRYBAR_CODE) {
191170 }
192171
193172 if (process.env.PRYBAR_INTERACTIVE) {
194− process.once("SIGINT", () => start(context));
195− process.once("beforeExit", () => start(context));
173+ process.once("SIGINT", () => start());
174+ process.once("beforeExit", () => start());
196175 }
197176} else if (process.env.PRYBAR_INTERACTIVE) {
198177 start();