node/doc/api
Joyee Cheung d98cfcc581
vm: introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY
This implements a flavor of vm.createContext() and friends
that creates a context without contextifying its global object.
This is suitable when users want to freeze the context (impossible
when the global is contextified i.e. has interceptors installed)
or speed up the global access if they don't need the interceptor
behavior.

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

const context = vm.createContext(vm.constants.DONT_CONTEXTIFY);

// In contexts with contextified global objects, this is false.
// In vanilla contexts this is true.
console.log(vm.runInContext('globalThis', context) === context);

// In contexts with contextified global objects, this would throw,
// but in vanilla contexts freezing the global object works.
vm.runInContext('Object.freeze(globalThis);', context);

// In contexts with contextified global objects, freezing throws
// and won't be effective. In vanilla contexts, freezing works
// and prevents scripts from accidentally leaking globals.
try {
  vm.runInContext('globalThis.foo = 1; foo;', context);
} catch(e) {
  console.log(e); // Uncaught ReferenceError: foo is not defined
}

console.log(context.Array);  // [Function: Array]
```

PR-URL: https://github.com/nodejs/node/pull/54394
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-08-29 09:05:03 +00:00
..
addons.md src: use args.This() instead of Holder 2024-06-18 16:02:42 +00:00
assert.md doc: require node:process in assert doc examples 2024-07-04 19:49:38 +00:00
async_context.md
async_hooks.md doc,tools: enforce use of node: prefix 2024-07-21 15:44:27 +00:00
buffer.md doc: update buffer.constants.MAX_LENGTH size 2024-08-09 19:19:24 +00:00
child_process.md doc: add example for execFileSync method and ref to stdio 2024-05-12 07:18:40 +00:00
cli.md src: add JS APIs for compile cache and NODE_DISABLE_COMPILE_CACHE 2024-08-28 23:22:57 +00:00
cluster.md doc: move numCPUs require to top of file in cluster CJS example 2024-07-30 06:13:52 +00:00
console.md doc: add esm examples to node:console 2024-08-06 09:56:59 +00:00
corepack.md doc: update pnpm link 2024-03-18 14:27:59 +00:00
crypto.md 2024-07-24, Version 20.16.0 'Iron' (LTS) 2024-07-24 14:06:09 +02:00
debugger.md inspector: introduce the --inspect-wait flag 2024-05-11 18:48:30 +00:00
deprecations.md 2024-07-24, Version 20.16.0 'Iron' (LTS) 2024-07-24 14:06:09 +02:00
dgram.md doc: use consistent plural form of "index" 2024-04-07 06:46:29 +00:00
diagnostics_channel.md doc: make some parameters optional in tracingChannel.traceCallback 2024-08-07 15:26:20 +09:30
dns.md doc: add esm examples to node:dns 2024-08-06 18:34:19 +00:00
documentation.md doc: use consistent plural form of "index" 2024-04-07 06:46:29 +00:00
domain.md
embedding.md test,doc: enable running embedtest for Windows 2024-05-23 18:33:40 +00:00
errors.md doc: fix error description of the max header size 2024-08-18 13:09:11 +00:00
esm.md lib,src: drop --experimental-network-imports 2024-07-28 16:33:05 +00:00
events.md doc, typings: events.once accepts symbol event type 2024-06-27 21:56:25 +00:00
fs.md doc: clarify that fs.exists() may return false for existing symlink 2024-06-26 09:38:30 +00:00
globals.md 2024-07-02, Version 22.4.0 (Current) 2024-07-02 10:50:11 +02:00
http2.md doc: add esm examples to node:http2 2024-08-11 22:15:08 +00:00
http.md 2024-07-17, Version 22.5.0 (Current) 2024-07-17 12:11:26 -03:00
https.md doc: add esm examples to node:https 2024-08-19 13:52:40 +00:00
index.md module: add --experimental-strip-types 2024-07-24 16:30:06 +00:00
inspector.md 2024-08-22, Version 22.7.0 (Current) 2024-08-22 11:14:41 -03:00
intl.md
module.md doc: fix module compile cache description 2024-08-29 04:36:46 +00:00
modules.md doc: fix capitalization in module.md 2024-08-23 00:52:53 +00:00
n-api.md node-api: rename nogc to basic 2024-07-26 09:25:02 -07:00
net.md doc: move onread option from socket.connect() to new net.socket() 2024-08-05 23:36:20 +00:00
os.md doc: add esm example for os 2024-06-29 13:57:49 +00:00
packages.md 2024-08-22, Version 22.7.0 (Current) 2024-08-22 11:14:41 -03:00
path.md 2024-08-21, Version 20.17.0 'Iron' (LTS) 2024-08-21 18:14:55 +02:00
perf_hooks.md doc: correct peformance entry types 2024-08-15 11:11:08 +00:00
permissions.md doc: add note on weakness of permission model 2024-08-17 13:03:21 +00:00
process.md 2024-08-22, Version 22.7.0 (Current) 2024-08-22 11:14:41 -03:00
punycode.md
querystring.md
readline.md
repl.md
report.md 2024-05-07, Version 20.13.0 'Iron' (LTS) 2024-05-07 17:32:24 +02:00
single-executable-applications.md doc: fix typo in method name in the sea doc 2024-08-15 11:11:01 +00:00
sqlite.md doc: add --experimental-sqlite note 2024-07-19 19:28:19 +00:00
stream.md 2024-08-21, Version 20.17.0 'Iron' (LTS) 2024-08-21 18:14:55 +02:00
string_decoder.md
synopsis.md
test.md doc: fix information about including coverage files 2024-08-27 19:11:04 +00:00
timers.md timers: fix validation 2024-08-25 07:30:10 +00:00
tls.md 2024-08-21, Version 20.17.0 'Iron' (LTS) 2024-08-21 18:14:55 +02:00
tracing.md doc: include node.module_timer on available categories 2024-07-01 15:18:16 +00:00
tty.md doc,tty: add documentation for ReadStream and WriteStream 2024-07-19 10:53:24 +00:00
typescript.md 2024-08-22, Version 22.7.0 (Current) 2024-08-22 11:14:41 -03:00
url.md url: add missing documentation for URL.parse() 2024-07-05 02:51:03 +00:00
util.md lib: respect terminal capabilities on styleText 2024-08-28 18:00:11 +00:00
v8.md doc: add getHeapStatistics() property descriptions 2024-08-29 05:12:56 +00:00
vm.md vm: introduce vanilla contexts via vm.constants.DONT_CONTEXTIFY 2024-08-29 09:05:03 +00:00
wasi.md doc,tools: enforce use of node: prefix 2024-07-21 15:44:27 +00:00
webcrypto.md 2024-08-21, Version 20.17.0 'Iron' (LTS) 2024-08-21 18:14:55 +02:00
webstreams.md 2024-08-21, Version 20.17.0 'Iron' (LTS) 2024-08-21 18:14:55 +02:00
worker_threads.md doc: fix worker threadId/destination typo 2024-08-02 10:45:49 +00:00
zlib.md 2024-06-20, Version 20.15.0 'Iron' (LTS) 2024-06-20 17:55:41 +02:00