You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example this works:
node -e "const vm=require('vm');vm.runInNewContext('let x = y;');"
evalmachine.:1
let x = y;
^
ReferenceError: y is not defined
The text was updated successfully, but these errors were encountered:
That's because console is a built-in object, like Object and Array, except the default implementation in a "plain" context only has no-op methods. Node.js overrides it in "node-y" contexts.
Closing as not-a-bug but let me know if you have follow-up questions and I'll move it to nodejs/help.
Thank you, my question come from: https://stackoverflow.com/questions/39416716/what-is-the-difference-between-new-function-and-vm where it seems that in past version of node.js the behaviour was different. Thanks to your explanation I just found also: #16755. So it could be interesting having somewhere in the nodejs documentation some details on this point(may be doc on console class and vm module). Thanks
What would you document? It's true console wasn't always a built-in but every version of Node.js where that isn't the case has been long out of support.
What steps will reproduce the bug?
from command line:
node -e "const vm=require('vm');vm.runInNewContext('console.log(\"test\")');"
from script:
vm.runInNewContext('console.log("test")');
How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
ReferenceError: console is not defined
What do you see instead?
nothing is printed, ReferenceError is not raised, test is not printed
Additional information
console object seems to be accessibile from new context:
node -p "const vm=require('vm');vm.runInNewContext('typeof console');"
object
For example this works:
node -e "const vm=require('vm');vm.runInNewContext('let x = y;');"
evalmachine.:1
let x = y;
^
ReferenceError: y is not defined
The text was updated successfully, but these errors were encountered: