Skip to content

Commit

Permalink
doc: document that const c2 = vm.createContext(c1); c1 === c2 is true
Browse files Browse the repository at this point in the history
- As far as I can tell, the documentation didn't say this, so I was left
  wondering if there is a difference between `c1` and `c2` in `const c2
= vm.createContext(c1);` According to my own tests, they are equivalent.
I thought it was worth documenting as it would've saved me a bit of time
if this information were written down.

PR-URL: #51960
Refs: #51946
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
DanKaplanSES authored Mar 9, 2024
1 parent bda66ad commit 8f9f5db
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions doc/api/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1117,13 +1117,13 @@ changes:
[Support of dynamic `import()` in compilation APIs][].
* Returns: {Object} contextified object.

If given a `contextObject`, the `vm.createContext()` method will [prepare
that object][contextified] so that it can be used in calls to
[`vm.runInContext()`][] or [`script.runInContext()`][]. Inside such scripts,
the `contextObject` will be the global object, retaining all of its existing
properties but also having the built-in objects and functions any standard
[global object][] has. Outside of scripts run by the vm module, global variables
will remain unchanged.
If given a `contextObject`, the `vm.createContext()` method will [prepare that
object][contextified] and return a reference to it so that it can be used in
calls to [`vm.runInContext()`][] or [`script.runInContext()`][]. Inside such
scripts, the `contextObject` will be the global object, retaining all of its
existing properties but also having the built-in objects and functions any
standard [global object][] has. Outside of scripts run by the vm module, global
variables will remain unchanged.

```js
const vm = require('node:vm');
Expand Down

0 comments on commit 8f9f5db

Please sign in to comment.