webcontainer-core icon indicating copy to clipboard operation
webcontainer-core copied to clipboard

Node `vm.runInNewContext` doesn’t return new context

Open GeoffreyBooth opened this issue 7 months ago • 1 comments

Describe the bug

Running require('vm').runInNewContext('this') should return a clean globalThis without any overridden prototypes. In real Node it does, but in StackBlitz it does not.

Link to the blitz that caused the error

https://stackblitz.com/edit/stackblitz-starters-ta5fme?file=index.cjs

Steps to reproduce

  1. Go to https://stackblitz.com/edit/stackblitz-starters-ta5fme?file=index.cjs
  2. Run node index.cjs
  3. Observe that the last logged number is 666. If you run this same file in real Node on your local machine, the last logged number is 1.

Expected behavior

The output should be:

Original lastIndexOf: 1
Polluted lastIndexOf: 666
Restored lastIndexOf: 1

Parity with Local

Screenshots

No response

Platform

Browser name  = Chrome
Full version  = 126.0.0.0
Major version = 126
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
performance.memory = {
  "totalJSHeapSize": 84778612,
  "usedJSHeapSize": 80715932,
  "jsHeapSizeLimit": 4294705152
}
Hash = 70dbe416

Additional context

Related to https://github.com/stackblitz/webcontainer-core/issues/309.

GeoffreyBooth avatar Jul 11 '24 05:07 GeoffreyBooth