> So where are they kept (the built-ins)? Are the hooked in via prototype chain > to the global object?
Yes, they are. Quoting comments in v8.h: /** * Returns the global proxy object or global object itself for * detached contexts. * * Global proxy object is a thin wrapper whose prototype points to * actual context's global object with the properties like Object, etc. * This is done that way for security reasons (for more details see * https://wiki.mozilla.org/Gecko:SplitWindow). * * Please note that changes to global proxy object prototype most probably * would break VM---v8 expects only global object as a prototype of * global proxy object. * * If DetachGlobal() has been invoked, Global() would return actual global * object until global is reattached with ReattachGlobal(). */ Local<Object> Global(); > So I can just create a new empty global object each time like this Unfortunately no. Normal JavaScript objects do not work with ReattachGlobal. It expects JSGlobalProxy (which cannot be created through an API separately from a Context). Quoting v8.h: /** * Reattaches a global object to a context. This can be used to * restore the connection between a global object and a context * after DetachGlobal has been called. * * \param global_object The global object to reattach to the * context. For this to work, the global object must be the global * object that was associated with this context before a call to * DetachGlobal. */ void ReattachGlobal(Handle<Object> global_object); Unfortunately it seems that your use case is not supported by V8's API. -- Vyacheslav Egorov On Wed, Jun 27, 2012 at 3:58 PM, MikeM <[email protected]> wrote: > > > There is no way. New context means new built-in objects. Also > > reattaching global does not change anything because built-ins are not > > on the global object itself. > > Holy Javascript Batman! That explains a lot! > So where are they kept (the built-ins)? Are the hooked in via prototype chain > to the global object? > > > If you want to reuse the same builtins you don't ultimately need a new > > context. Just use the same all the time. > > Excellent! So I can just create a new empty global object each time like > this and attach to my existing context to give me the same built-ins but a > clean global? > Persistent<Object> globalObject = Persistent<Object>::New(Object::New()); > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
