summaryrefslogtreecommitdiff
path: root/lib/vm.js
AgeCommit message (Collapse)Author
2019-02-03inspector,vm: remove --eval wrapperAnna Henningsen
Report the actual source code when running with `--eval` and `--inspect-brk`, by telling the vm module to break on the first line of the script being executed rather than wrapping the source code in a function. PR-URL: https://github.com/nodejs/node/pull/25832 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-12-29tools: enable no-useless-catch lint rulecjihrig
This commit enables ESLint's no-useless-catch rule. PR-URL: https://github.com/nodejs/node/pull/25236 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-12-20lib: switch to object spread where possibleRuben Bridgewater
Use the object spread notation instead of using Object.assign. It is not only easier to read it is also faster as of V8 6.8. PR-URL: https://github.com/nodejs/node/pull/25104 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-12-20vm: reuse validateString of internal/validatorsZYSzys
PR-URL: https://github.com/nodejs/node/pull/25074 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2018-12-16vm: simplify Script constructor options validationcjihrig
This commit combines two related if statements into an if-else statement. PR-URL: https://github.com/nodejs/node/pull/25054 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-11-07src: cache the result of GetOptions() in JS landJoyee Cheung
Instead of calling into C++ each time we need to check the value of a command line option, cache the option map in a new `internal/options` module for faster access to the values in JS land. PR-URL: https://github.com/nodejs/node/pull/24091 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Refael Ackermann <refack@gmail.com>
2018-11-02vm: allow `cachedData` to also be TypedArray|DataViewBenjamin Chen
PR-URL: https://github.com/nodejs/node/pull/22921 Refs: https://github.com/nodejs/node/issues/1826 Refs: https://github.com/nodejs/node/pull/22921#issuecomment-422350213 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
2018-10-13lib: migrate from process.binding to internalBindingAndres Monge
We are migrating towards using internalBinding(\'options\').getOptions() instead of process.binding(\'config\') to access the value of the --experimental-vm-modules command line option. PR-URL: https://github.com/nodejs/node/pull/23586 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2018-10-06vm: add dynamic import supportGus Caplan
PR-URL: https://github.com/nodejs/node/pull/22381 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-10-04bootstrapper: move internalBinding to NativeModuleGus Caplan
internalBinding is used so often that it should just automatically be available for usage in internals. PR-URL: https://github.com/nodejs/node/pull/23025 Refs: https://github.com/nodejs/node/commit/2a9eb31 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-08-29vm: add bindings for v8::CompileFunctionInContextUjjwal Sharma
Adds a method compileFunction to the vm module, which serves as a binding for v8::CompileFunctionInContext with appropriate args for specifying the details, and provide params for the wrapper. Eventually, we would be changing Module._compile to use this internally over the standard Module.wrap PR-URL: https://github.com/nodejs/node/pull/21571 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-08-23vm: move process.binding('contextify') to internalBindingJames M Snell
PR-URL: https://github.com/nodejs/node/pull/22419 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-08-04src: remove unused env->vm_parsing_context_symbolJon Moss
Stopped being used via 77b52fd58f7398a81999c81afd21fe2e156c0766, was originally added in d932e802317f9f61bd10988189fa43ed03ad0f61. For the one remaining usecase inside of `lib/vm.js`, define a Symbol at the top of the file. PR-URL: https://github.com/nodejs/node/pull/22034 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-07-31vm: rename vm.Module to vm.SourceTextModuleGus Caplan
At the last TC39 meeting, a new type of Module Records backed by JavaScript source called Dynamic Module Records was discussed, and it is now at Stage 1. Regardless of whether that proposal makes it all the way into the spec, SourceTextModule is indeed a more descriptive and accurate name for what this class represents. PR-URL: https://github.com/nodejs/node/pull/22007 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
2018-04-26lib: introduce internal/validatorsMichaël Zasso
Create a file to centralize argument validators that are used in multiple internal modules. Move validateInt32 and validateUint32 to this file. PR-URL: https://github.com/nodejs/node/pull/19973 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-03vm: move options checks from C++ to JSMichaël Zasso
Also introduces stronger type validations for options passed to vm functions. PR-URL: https://github.com/nodejs/node/pull/19398 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-03-28lib: rename js source to lower snake_caseDaniel Bevenius
This commit renames all JavaScript source files in lib to lower snake_case. PR-URL: https://github.com/nodejs/node/pull/19556 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-03-22vm: migrate isContext to internal/errorsdustinnewman98
PR-URL: https://github.com/nodejs/node/pull/19268 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-03-12vm: add code generation optionsGus Caplan
Adds options to a VM Context to disable code generation from strings (such as eval or new Function) and WASM code generation (WebAssembly.compile). PR-URL: https://github.com/nodejs/node/pull/19016 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-03-05lib: port errors to new systemMichaël Zasso
This is a first batch of updates that touches non-underscored modules in lib. PR-URL: https://github.com/nodejs/node/pull/19034 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-22vm: consolidate validationTimothy O. Peters
PR-URL: https://github.com/nodejs/node/pull/18816 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-01-30vm: add modulesGus Caplan
Adds vm.Module, which wraps around ModuleWrap to provide an interface for developers to work with modules in a more reflective manner. Co-authored-by: Timothy Gu <timothygu99@gmail.com> PR-URL: https://github.com/nodejs/node/pull/17560 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2017-12-23vm: allow modifying context name in inspectorTimothy Gu
The `auxData` field is not exposed to JavaScript, as DevTools uses it for its `isDefault` parameter, which is implemented faithfully, contributing to the nice indentation in the context selection panel. Without the indentation, when `Target` domain gets implemented (along with a single Inspector for cluster) in #16627, subprocesses and VM contexts will be mixed up, causing confusion. PR-URL: https://github.com/nodejs/node/pull/17720 Refs: https://github.com/nodejs/node/pull/14231#issuecomment-315924067 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-12-14events: remove reaches into _events internalsAnatoli Papirovski
Refactor lib & src code to eliminate all deep reaches into the internal _events dictionary object, instead use available APIs and add an extra method to EventEmitter: rawListeners. PR-URL: https://github.com/nodejs/node/pull/17440 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-12-05vm: never abort on caught syntax errorAnna Henningsen
Keep track of C++ `TryCatch` state to avoid aborting when an exception is thrown inside one, and re-throw in JS to make sure the exception is being picked up a second time by a second uncaught exception handler, if necessary. Add a bit of a hack to `AppendExceptionLine` to avoid overriding the line responsible for re-throwing the exception. PR-URL: https://github.com/nodejs/node/pull/17394 Fixes: https://github.com/nodejs/node/issues/13258 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-24lib,src: remove vm.runInDebugContext()Ben Noordhuis
The V8 API it is based on is deprecated and scheduled for removal later this year. Remove it. PR-URL: https://github.com/nodejs/node/pull/13295 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-10-23vm: deprecate vm.runInDebugContextJosh Gavant
PR-URL: https://github.com/nodejs/node/pull/12815 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-09-05vm: support parsing a script in a specific contextTimothy Gu
PR-URL: https://github.com/nodejs/node/pull/14888 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2017-02-17vm: refactor vm moduleJames M Snell
Switch to the more efficient module.exports = {} pattern. PR-URL: https://github.com/nodejs/node/pull/11392 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-01-18vm: improve performance of vm.runIn*()Rich Trott
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: https://github.com/nodejs/node/pull/10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-11-06vm: name anonymous functionssolebox
Name anonymous arrow function in vm module to improve readability PR-URL: https://github.com/nodejs/node/pull/9388 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <inglor@gmail.com> Ref: #8913
2016-09-08vm: change ContextifyScript to Script in commentDaniel Bevenius
Reading the comment at the top of the vm.js, I think that ContextifyScript should perhaps just be Script. PR-URL: https://github.com/nodejs/node/pull/8415 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franzih@chromium.org> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-18vm: add ability to break on sigint/ctrl+cAnna Henningsen
- Adds the `breakEvalOnSigint` option to `vm.runIn(This)Context`. This uses a watchdog thread to wait for SIGINT and generally works just like the existing `timeout` option. - Adds a method to the existing timer-based watchdog to check if it stopped regularly or by running into the timeout. This is used to tell a SIGINT abort from a timer-based one. - Adds (internal) `process._{start,stop}SigintWatchdog` methods to start/stop the watchdog thread used by the above option manually. This will be used in the REPL to set up SIGINT handling before entering terminal raw mode, so that there is no time window in which Ctrl+C fully aborts the process. PR-URL: https://github.com/nodejs/node/pull/6635 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31lib: reduce util.is*() usagecjihrig
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: https://github.com/iojs/io.js/issues/607 PR-URL: https://github.com/iojs/io.js/pull/647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21lib: use const to define constantscjihrig
This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-12Remove excessive copyright/license boilerplateisaacs
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2014-11-22lib: turn on strict modeBen Noordhuis
Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-09-16lib, src: add vm.runInDebugContext()Ben Noordhuis
Compiles and executes source code in V8's debugger context. Provides a programmatic way to get access to the debug object by executing: var Debug = vm.runInDebugContext('Debug'); Fixes #7886. Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2013-08-28vm: update API to use options argumentDomenic Denicola
Passing a filename is still supported in place of certain options arguments, for backward-compatibility, but timeout and display-errors are not translated since those were undocumented. Also managed to eliminate an extra stack trace line by not calling through the `createScript` export. Added a few message tests to show how `displayErrors` works.
2013-08-28vm: add isContext; prevent double-contextifyingDomenic Denicola
Previously, calling `vm.createContext(o)` repeatedly on the same `o` would cause new C++ `ContextifyContext`s to be created and stored on `o`, while the previous resident went off into leaked-memory limbo. Now, repeatedly trying to contextify a sandbox will do nothing after the first time. To detect this, an independently-useful `vm.isContext(sandbox)` export was added.
2013-08-21vm: Put back display_errors flagisaacs
This is an important part of the repl use-case. TODO: The arg parsing in vm.runIn*Context() is rather wonky. It would be good to move more of that into the Script class, and/or an options object.
2013-08-21vm, core, module: re-do vm to fix known issuesDomenic Denicola
As documented in #3042 and in [1], the existing vm implementation has many problems. All of these are solved by @brianmcd's [contextify][2] package. This commit uses contextify as a conceptual base and its code core to overhaul the vm module and fix its many edge cases and caveats. Functionally, this fixes #3042. In particular: - A context is now indistinguishable from the object it is based on (the "sandbox"). A context is simply a sandbox that has been marked by the vm module, via `vm.createContext`, with special internal information that allows scripts to be run inside of it. - Consequently, items added to the context from anywhere are immediately visible to all code that can access that context, both inside and outside the virtual machine. This commit also smooths over the API very slightly: - Parameter defaults are now uniformly triggered via `undefined`, per ES6 semantics and previous discussion at [3]. - Several undocumented and problematic features have been removed, e.g. the conflation of `vm.Script` with `vm` itself, and the fact that `Script` instances also had all static `vm` methods. The API is now exactly as documented (although arguably the existence of the `vm.Script` export is not yet documented, just the `Script` class itself). In terms of implementation, this replaces node_script.cc with node_contextify.cc, which is derived originally from [4] (see [5]) but has since undergone extensive modifications and iterations to expose the most useful C++ API and use the coding conventions and utilities of Node core. The bindings exposed by `process.binding('contextify')` (node_contextify.cc) replace those formerly exposed by `process.binding('evals')` (node_script.cc). They are: - ContextifyScript(code, [filename]), with methods: - runInThisContext() - runInContext(sandbox, [timeout]) - makeContext(sandbox) From this, the vm.js file builds the entire documented vm module API. node.js and module.js were modified to use this new native binding, or the vm module itself where possible. This introduces an extra line or two into the stack traces of module compilation (and thus into most stack traces), explaining the changed tests. The tests were also updated slightly, with all vm-related simple tests consolidated as test/simple/test-vm-* (some of them were formerly test/simple/test-script-*). At the same time they switched from `common.debug` to `console.error` and were updated to use `assert.throws` instead of rolling their own error-testing methods. New tests were also added, of course, demonstrating the new capabilities and fixes. [1]: http://nodejs.org/docs/v0.10.16/api/vm.html#vm_caveats [2]: https://github.com/brianmcd/contextify [3]: https://github.com/joyent/node/issues/5323#issuecomment-20250726 [4]: https://github.com/kkoopa/contextify/blob/bf123f3ef960f0943d1e30bda02e3163a004e964/src/contextify.cc [5]: https://gist.github.com/domenic/6068120
2013-08-01src: Replace macros with util functionsisaacs
2013-07-24lib: macro-ify type checksBen Noordhuis
Increases the grep factor. Makes it easier to harmonize type checks across the code base.
2012-03-03lintisaacs
2012-02-27Wrap NodeScript binding class in JavaScript layerisaacs
This makes it easy to prevent errors where Script methods are called on non-script objects, resulting in Assertion failures.
2011-09-08Revert "vm context with accessors"Ryan Dahl
This reverts commit 4527de8cba3bf5f107fcefcf43dbdaa308881ba4. Causes segfault in test/message/undefined_reference_in_new_context.js
2011-09-08vm context with accessorsFedor Indutny
true copy of sandbox properties catch sealed errors, pass global's prototype to CloneObject Fixes #1673
2011-03-30Don't conflict with V8's Script classRyan Dahl
Closes GH-203.