replit / prybar

Pry open those interpreters.
GNU General Public License v2.0
253 stars 52 forks source link

Fix cross module node globals #62

Closed masad-frost closed 3 years ago

masad-frost commented 3 years ago

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 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.

I also fixed a bunch of tests that were broken.

masad-frost commented 3 years ago

https://app.asana.com/0/inbox/974357908413931/1198514514357824/1199218400429100

replbot commented 3 years ago

unbooping: approved