Use the (current) global context when running the file, i.e. script.runInThisContext. This change gives us the piece of mind going forward when dealing with the global context. We still patch somethings, like adding alert, confirm, and prompt. We also patch the global.module and global.require to make sure the context thinks we're in the entrypoint file rather than the repl.js file.
Bug
When running with an entrypoint, the entry point's globals/context is different from required modules. This breaks some packages such as math.js that rely on instanceof. You can see the bug in the newly added asserts https://github.com/replit/prybar/commit/10c16f9e064d0ec3f522df76276c1f4f5eaf9b2e.
Fix
Use the (current) global context when running the file, i.e.
script.runInThisContext
. This change gives us the piece of mind going forward when dealing with the global context. We still patch somethings, like addingalert
,confirm
, andprompt
. We also patch theglobal.module
andglobal.require
to make sure the context thinks we're in the entrypoint file rather than therepl.js
file.I also fixed a bunch of tests that were broken.