diff options
author | Andrei Popescu <andreip@google.com> | 2010-03-29 12:03:09 +0100 |
---|---|---|
committer | Andrei Popescu <andreip@google.com> | 2010-03-29 12:03:09 +0100 |
commit | 74b3c146906ea120f97974b0e16aec75c17ebf66 (patch) | |
tree | 529f5893bf30271b7123fa94822c28131bd3bda1 /src | |
parent | 144045c95df339bcbcf35374401289e1eefc1d85 (diff) | |
download | android_external_v8-74b3c146906ea120f97974b0e16aec75c17ebf66.tar.gz android_external_v8-74b3c146906ea120f97974b0e16aec75c17ebf66.tar.bz2 android_external_v8-74b3c146906ea120f97974b0e16aec75c17ebf66.zip |
Cherry pick http://codereview.chromium.org/1207003/show
Implement support for reattaching a global object to a context. This
can be used to use the same global object for different contexts at
different points in time.
Needed to fix b: 2533219
Change-Id: Ib3b0d35f6ce3e0a5f4b8e54561ba2e99a9ab0ab1
Diffstat (limited to 'src')
-rw-r--r-- | src/api.cc | 10 | ||||
-rw-r--r-- | src/bootstrapper.cc | 11 | ||||
-rw-r--r-- | src/bootstrapper.h | 3 |
3 files changed, 24 insertions, 0 deletions
@@ -3007,6 +3007,16 @@ void Context::DetachGlobal() { } +void Context::ReattachGlobal(Handle<Object> global_object) { + if (IsDeadCheck("v8::Context::ReattachGlobal()")) return; + ENTER_V8; + i::Object** ctx = reinterpret_cast<i::Object**>(this); + i::Handle<i::Context> context = + i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); + i::Bootstrapper::ReattachGlobal(context, Utils::OpenHandle(*global_object)); +} + + Local<v8::Object> ObjectTemplate::NewInstance() { ON_BAILOUT("v8::ObjectTemplate::NewInstance()", return Local<v8::Object>()); LOG_API("ObjectTemplate::NewInstance"); diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 6e565e08..225865cf 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -315,6 +315,17 @@ void Bootstrapper::DetachGlobal(Handle<Context> env) { } +void Bootstrapper::ReattachGlobal(Handle<Context> env, + Handle<Object> global_object) { + ASSERT(global_object->IsJSGlobalProxy()); + Handle<JSGlobalProxy> global = Handle<JSGlobalProxy>::cast(global_object); + env->global()->set_global_receiver(*global); + env->set_global_proxy(*global); + SetObjectPrototype(global, Handle<JSObject>(env->global())); + global->set_context(*env); +} + + static Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, InstanceType type, diff --git a/src/bootstrapper.h b/src/bootstrapper.h index f905a28b..89eb381b 100644 --- a/src/bootstrapper.h +++ b/src/bootstrapper.h @@ -68,6 +68,9 @@ class Bootstrapper : public AllStatic { // Detach the environment from its outer global object. static void DetachGlobal(Handle<Context> env); + // Reattach an outer global object to an environment. + static void ReattachGlobal(Handle<Context> env, Handle<Object> global_object); + // Traverses the pointers for memory management. static void Iterate(ObjectVisitor* v); |