mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
d98cfcc581
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> |
||
---|---|---|
.. | ||
actions | ||
bootstrap | ||
clang-format | ||
configure.d | ||
dep_updaters | ||
doc | ||
eslint | ||
eslint-rules | ||
github_reporter | ||
gyp | ||
icu | ||
inspector_protocol | ||
lint-md | ||
macos-installer | ||
msvs | ||
pip | ||
snapshot | ||
v8 | ||
v8_gypfiles | ||
zos | ||
build_addons.py | ||
certdata.txt | ||
checkimports.py | ||
compress_json.py | ||
copyfile.py | ||
cpplint.py | ||
create_android_makefiles | ||
create_expfile.sh | ||
enable_fips_include.py | ||
executable_wrapper.h | ||
find-inactive-collaborators.mjs | ||
find-inactive-tsc.mjs | ||
gen_node_def.cc | ||
generate_config_gypi.py | ||
getmoduleversion.py | ||
getnapibuildversion.py | ||
getnodeversion.py | ||
getsharedopensslhasquic.py | ||
gyp_node.py | ||
gypi_to_gn.py | ||
install.py | ||
js2c.cc | ||
license2rtf.mjs | ||
license-builder.sh | ||
lint-pr-url.mjs | ||
lint-readme-lists.mjs | ||
lint-sh.mjs | ||
lsan_suppressions.txt | ||
macos-firewall.sh | ||
make-v8.sh | ||
merge-wpt-reports.mjs | ||
mk-ca-bundle.pl | ||
mkssldef.py | ||
osx-codesign.sh | ||
osx-entitlements.plist | ||
osx-notarize.sh | ||
osx-pkg-postinstall.sh | ||
osx-productsign.sh | ||
pseudo-tty.py | ||
release.sh | ||
run-valgrind.py | ||
run-worker.js | ||
search_files.py | ||
sign.bat | ||
specialize_node_d.py | ||
test-npm-package.js | ||
test-v8.bat | ||
test.py | ||
update-timezone.mjs | ||
utils.py | ||
v8-json-to-junit.py | ||
valgrind.supp |