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: nodejs#51960
Refs: nodejs#51946
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
DanKaplanSES authored and rdw-msft committed Mar 26, 2024
1 parent d1173cf commit 5b069a9
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 5b069a9

Please sign in to comment.