summaryrefslogtreecommitdiff
path: root/lib/vm.js
Commit message (Collapse)AuthorAgeFilesLines
* lib: reduce util.is*() usagecjihrig2015-01-311-2/+1
| | | | | | | | | | | | 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>
* lib: use const to define constantscjihrig2015-01-211-3/+3
| | | | | | | | 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>
* Remove excessive copyright/license boilerplateisaacs2015-01-121-21/+0
| | | | | | | 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.
* lib: turn on strict modeBen Noordhuis2014-11-221-0/+2
| | | | | | | | | 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>
* lib, src: add vm.runInDebugContext()Ben Noordhuis2014-09-161-0/+4
| | | | | | | | | | | 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>
* vm: update API to use options argumentDomenic Denicola2013-08-281-24/+26
| | | | | | | | | | | 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.
* vm: add isContext; prevent double-contextifyingDomenic Denicola2013-08-281-1/+5
| | | | | | | | | | | 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.
* vm: Put back display_errors flagisaacs2013-08-211-13/+13
| | | | | | | | 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.
* vm, core, module: re-do vm to fix known issuesDomenic Denicola2013-08-211-28/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* src: Replace macros with util functionsisaacs2013-08-011-1/+2
|
* lib: macro-ify type checksBen Noordhuis2013-07-241-1/+1
| | | | | Increases the grep factor. Makes it easier to harmonize type checks across the code base.
* lintisaacs2012-03-031-2/+2
|
* Wrap NodeScript binding class in JavaScript layerisaacs2012-02-271-7/+29
| | | | | This makes it easy to prevent errors where Script methods are called on non-script objects, resulting in Assertion failures.
* Revert "vm context with accessors"Ryan Dahl2011-09-081-13/+0
| | | | | | This reverts commit 4527de8cba3bf5f107fcefcf43dbdaa308881ba4. Causes segfault in test/message/undefined_reference_in_new_context.js
* vm context with accessorsFedor Indutny2011-09-081-0/+13
| | | | | | | | true copy of sandbox properties catch sealed errors, pass global's prototype to CloneObject Fixes #1673
* Don't conflict with V8's Script classRyan Dahl2011-03-301-5/+5
| | | | Closes GH-203.
* Update copyright headersRyan Dahl2011-03-141-0/+21
|
* lintRyan Dahl2010-12-011-1/+1
|
* Rename require('javascript') to require('vm')Ryan Dahl2010-11-151-0/+11