summaryrefslogtreecommitdiff
path: root/src/node_contextify.cc
Commit message (Collapse)AuthorAgeFilesLines
* base-object: add BaseObjectTrevor Norris2013-11-121-4/+5
| | | | | | | | BaseObject is a class that just handles the Persistent handle attached to the class instance. This also removed WeakObject. Reordering the inheritance chain helps prevent unneeded calls on instances that don't call MakeCallback.
* src: fix Environment::GetCurrent() usageBen Noordhuis2013-11-111-2/+2
| | | | | | Create a HandleScope before calling the Environment::GetCurrent() that takes a v8::Isolate* as an argument because it creates a handle with the call to v8::Isolate::CurrentContext().
* async-wrap: integrate with WeakObjectTrevor Norris2013-10-311-3/+4
| | | | | Making WeakObject inherit from AsyncWrap allows us to peak into almost all the MakeCallback calls in Node internals.
* src: shorten Object{Wrap,Unwrap}Trevor Norris2013-10-291-7/+7
| | | | | | Going back to the original names of Wrap/Unwrap now that most all the class members that duplicate the name and functionality have been removed.
* src: don't use WeakObject::UnwrapTrevor Norris2013-10-291-1/+1
| | | | Switch out to use UnwrapObject from util.h.
* src: use function to get internal pointerTrevor Norris2013-10-291-11/+13
| | | | Remove the NODE_{WRAP,UNWRAP} macros and instead use template functions.
* vm: Copy missing properties from contextisaacs2013-10-281-0/+74
| | | | | | | | | | | | | | | | | | | | | | | | | This addresses a current shortcoming of the V8 SetNamedPropertyHandler function. It does not provide a way to intercept Object.defineProperty(..) calls. As a result, these properties are not copied onto the contextified sandbox when a new global property is added via either a function declaration or a Object.defineProperty(global, ...) call. Note that any function declarations or Object.defineProperty() globals that are created asynchronously (in a setTimeout, callback, etc.) will happen AFTER the call to copy properties, and thus not be caught. The way to properly fix this is to add some sort of a Object::SetNamedDefinePropertyHandler() function that takes a callback, which receives the property name and property descriptor as arguments. Luckily, such situations are rare, and asynchronously-added globals weren't supported by Node's VM module until 0.12 anyway. But, this should be fixed properly in V8, and this copy function should be removed once there is a better way. Fix #6416
* cpplint: disallow comma-first in C++Fedor Indutny2013-10-171-5/+5
|
* src: remove ObjectWrap dependency from coreBen Noordhuis2013-09-251-4/+11
| | | | | | | | Drop the ObjectWrap dependency in favor of an internal WeakObject class. Let's us stop worrying about API and ABI compatibility when making changes to the way node.js deals with weakly persistent handles internally.
* contextify: fix ContextifyContext leakFedor Indutny2013-09-151-7/+11
| | | | | | | | | | Apparently, context->Global() won't be destroyed if the context itself isn't marked as weak and independent. Also, the weakness flag should be cleared once the weak callback is executed, otherwise we'll get crashes in Debug builds. fix #6115 and #6201
* contextify: dealloc only after global and sandboxFedor Indutny2013-09-121-2/+8
| | | | | | | Functions created using: `vm.runInNewContext('(function() { })')` will reference only `proxy_global_` object and not `sandbox_`. Thus in case, where there're no references to sandbox (such as in example above), `ContextifyContext` will be destroyed and use-after-free might happen.
* src: fix multi-base class ObjectWrap::Unwrap<T>()Ben Noordhuis2013-09-061-11/+11
| | | | | | | | | | | | | | Fix pointer unwrapping when T is a class with more than one base class. Before this commit, the wrapped void* pointer was cast directly to T* without going through ObjectWrap* first, possibly leading to a class instance pointer that points to the wrong vtable. This change required some cleanup in various files; some classes used private rather than public inheritance, others didn't derive from ObjectWrap at all... Fixes #6188.
* src: add multi-context supportBen Noordhuis2013-09-061-63/+64
| | | | | | | | | | | | | | | | | | | | | | | This commit makes it possible to use multiple V8 execution contexts within a single event loop. Put another way, handle and request wrap objects now "remember" the context they belong to and switch back to that context when the time comes to call into JS land. This could have been done in a quick and hacky way by calling v8::Object::GetCreationContext() on the wrap object right before making a callback but that leaves a fairly wide margin for bugs. Instead, we make the context explicit through a new Environment class that encapsulates everything (or almost everything) that belongs to the context. Variables that used to be a static or a global are now members of the aforementioned class. An additional benefit is that this approach should make it relatively straightforward to add full isolate support in due course. There is no JavaScript API yet but that will be added in the near future. This work was graciously sponsored by GitHub, Inc.
* vm: update API to use options argumentDomenic Denicola2013-08-281-37/+68
| | | | | | | | | | | 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/+22
| | | | | | | | | | | 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: use MakeWeak to fix leaking contextsDomenic Denicola2013-08-281-2/+13
| | | | | This is always something you should do when using `SetHiddenValue`, apparently. Fixes #6115. Thanks @tjfontaine for the tips.
* vm: rip out ObjectWrap from ContextifyContextDomenic Denicola2013-08-281-50/+27
| | | | | | | This was a remnant of the original Contextify code, wherein ContextifyContext was a user-exposed object. In vm, it is not, so all of the ObjectWrap and function-template stuff for the ContextifyContext constructor is now unnecessary.
* src: fix up unused/unordered importsBen Noordhuis2013-08-271-1/+1
|
* vm: fix Persistent<Context> leakBen Noordhuis2013-08-231-3/+1
|
* vm: remove unnecessary Persistent<FunctionTemplate>Ben Noordhuis2013-08-231-7/+1
|
* vm: Put back display_errors flagisaacs2013-08-211-5/+24
| | | | | | | | 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-0/+484
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