[v8] move persistent::new and ::dispose into same class
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Feb 2013 19:48:39 +0000 (19:48 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Feb 2013 19:48:39 +0000 (19:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109065

Patch by Dan Carney <dcarney@google.com> on 2013-02-07
Reviewed by Adam Barth.

No new tests. No change in functionality.

* bindings/scripts/CodeGeneratorV8.pm:
(GenerateSingleConstructorCallback):
(GenerateEventConstructorCallback):
(GenerateNamedConstructorCallback):
(GenerateToV8Converters):
* bindings/scripts/test/V8/V8Float64Array.cpp:
(WebCore::V8Float64Array::createWrapper):
* bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
(WebCore::V8TestActiveDOMObject::createWrapper):
* bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp:
(WebCore::V8TestCustomNamedGetter::createWrapper):
* bindings/scripts/test/V8/V8TestEventConstructor.cpp:
(WebCore::V8TestEventConstructor::constructorCallback):
(WebCore::V8TestEventConstructor::createWrapper):
* bindings/scripts/test/V8/V8TestEventTarget.cpp:
(WebCore::V8TestEventTarget::createWrapper):
* bindings/scripts/test/V8/V8TestException.cpp:
(WebCore::V8TestException::createWrapper):
* bindings/scripts/test/V8/V8TestInterface.cpp:
(WebCore::V8TestInterface::constructorCallback):
(WebCore::V8TestInterface::createWrapper):
* bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp:
(WebCore::V8TestMediaQueryListListener::createWrapper):
* bindings/scripts/test/V8/V8TestNamedConstructor.cpp:
(WebCore::V8TestNamedConstructorConstructorCallback):
(WebCore::V8TestNamedConstructor::createWrapper):
* bindings/scripts/test/V8/V8TestNode.cpp:
(WebCore::V8TestNode::constructorCallback):
(WebCore::V8TestNode::createWrapper):
* bindings/scripts/test/V8/V8TestObj.cpp:
(WebCore::V8TestObj::constructorCallback):
(WebCore::V8TestObj::createWrapper):
* bindings/scripts/test/V8/V8TestOverloadedConstructors.cpp:
(WebCore::V8TestOverloadedConstructors::constructor1Callback):
(WebCore::V8TestOverloadedConstructors::constructor2Callback):
(WebCore::V8TestOverloadedConstructors::constructor3Callback):
(WebCore::V8TestOverloadedConstructors::constructor4Callback):
(WebCore::V8TestOverloadedConstructors::createWrapper):
* bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
(WebCore::V8TestSerializedScriptValueInterface::constructorCallback):
(WebCore::V8TestSerializedScriptValueInterface::createWrapper):
* bindings/v8/DOMDataStore.cpp:
* bindings/v8/DOMDataStore.h:
(WebCore::DOMDataStore::setWrapper):
(DOMDataStore):
(WebCore::DOMDataStore::set):
(WebCore::DOMDataStore::setWrapperInObject):
* bindings/v8/DOMWrapperMap.h:
(WebCore::DOMWrapperMap::get):
(WebCore::DOMWrapperMap::set):
(WebCore::DOMWrapperMap::removeAndDispose):
(WebCore::DOMWrapperMap::defaultWeakCallback):
* bindings/v8/ScriptWrappable.h:
(WebCore::ScriptWrappable::wrapper):
(WebCore::ScriptWrappable::setWrapper):
(WebCore::ScriptWrappable::reportMemoryUsage):
(ScriptWrappable):
(WebCore::ScriptWrappable::disposeWrapper):
(WebCore::ScriptWrappable::weakCallback):
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::installDOMWindow):
* bindings/v8/V8DOMWrapper.h:
(V8DOMWrapper):
(WebCore::V8DOMWrapper::associateObjectWithWrapper):
* bindings/v8/V8NPObject.cpp:
(WebCore::weakNPObjectCallback):
(WebCore::createV8ObjectForNPObject):
(WebCore::forgetV8ObjectForNPObject):
* bindings/v8/WorkerScriptController.cpp:
(WebCore::WorkerScriptController::initializeContextIfNeeded):
* bindings/v8/WrapperTypeInfo.h:
(WebCore):
(WrapperConfiguration):
(WebCore::WrapperConfiguration::configureWrapper):
(WebCore::buildWrapperConfiguration):
* bindings/v8/custom/V8ArrayBufferCustom.cpp:
(WebCore::V8ArrayBuffer::constructorCallbackCustom):
* bindings/v8/custom/V8ArrayBufferViewCustom.h:
(WebCore::wrapArrayBufferView):
(WebCore::constructWebGLArray):
* bindings/v8/custom/V8AudioContextCustom.cpp:
(WebCore::V8AudioContext::constructorCallbackCustom):
* bindings/v8/custom/V8DOMFormDataCustom.cpp:
(WebCore::V8DOMFormData::constructorCallbackCustom):
* bindings/v8/custom/V8DataViewCustom.cpp:
(WebCore::V8DataView::constructorCallbackCustom):
* bindings/v8/custom/V8HTMLImageElementConstructor.cpp:
(WebCore::v8HTMLImageElementConstructorCallback):
* bindings/v8/custom/V8IntentCustom.cpp:
(WebCore::V8Intent::constructorCallbackCustom):
* bindings/v8/custom/V8MessageChannelCustom.cpp:
(WebCore::V8MessageChannel::constructorCallbackCustom):
* bindings/v8/custom/V8MutationObserverCustom.cpp:
(WebCore::V8MutationObserver::constructorCallbackCustom):
* bindings/v8/custom/V8WebKitPointCustom.cpp:
(WebCore::V8WebKitPoint::constructorCallbackCustom):
* bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
(WebCore::V8XMLHttpRequest::constructorCallbackCustom):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142159 268f45cc-cd09-0410-ab3c-d52691b4dbfc

35 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/V8/V8Float64Array.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestEventConstructor.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestEventTarget.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestException.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestNamedConstructor.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestOverloadedConstructors.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/v8/DOMDataStore.cpp
Source/WebCore/bindings/v8/DOMDataStore.h
Source/WebCore/bindings/v8/DOMWrapperMap.h
Source/WebCore/bindings/v8/ScriptWrappable.h
Source/WebCore/bindings/v8/V8DOMWindowShell.cpp
Source/WebCore/bindings/v8/V8DOMWrapper.h
Source/WebCore/bindings/v8/V8NPObject.cpp
Source/WebCore/bindings/v8/WorkerScriptController.cpp
Source/WebCore/bindings/v8/WrapperTypeInfo.h
Source/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp
Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h
Source/WebCore/bindings/v8/custom/V8AudioContextCustom.cpp
Source/WebCore/bindings/v8/custom/V8DOMFormDataCustom.cpp
Source/WebCore/bindings/v8/custom/V8DataViewCustom.cpp
Source/WebCore/bindings/v8/custom/V8HTMLImageElementConstructor.cpp
Source/WebCore/bindings/v8/custom/V8IntentCustom.cpp
Source/WebCore/bindings/v8/custom/V8MessageChannelCustom.cpp
Source/WebCore/bindings/v8/custom/V8MutationObserverCustom.cpp
Source/WebCore/bindings/v8/custom/V8WebKitPointCustom.cpp
Source/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp

index 5d2e7cfa80495429d2a2180f9b0ea1772bc099c8..c9a6d66d6515acefe399c36225efe02fad1660d2 100644 (file)
@@ -1,3 +1,111 @@
+2013-02-07  Dan Carney  <dcarney@google.com>
+
+        [v8] move persistent::new and ::dispose into same class
+        https://bugs.webkit.org/show_bug.cgi?id=109065
+
+        Reviewed by Adam Barth.
+
+        No new tests. No change in functionality.
+
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateSingleConstructorCallback):
+        (GenerateEventConstructorCallback):
+        (GenerateNamedConstructorCallback):
+        (GenerateToV8Converters):
+        * bindings/scripts/test/V8/V8Float64Array.cpp:
+        (WebCore::V8Float64Array::createWrapper):
+        * bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
+        (WebCore::V8TestActiveDOMObject::createWrapper):
+        * bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp:
+        (WebCore::V8TestCustomNamedGetter::createWrapper):
+        * bindings/scripts/test/V8/V8TestEventConstructor.cpp:
+        (WebCore::V8TestEventConstructor::constructorCallback):
+        (WebCore::V8TestEventConstructor::createWrapper):
+        * bindings/scripts/test/V8/V8TestEventTarget.cpp:
+        (WebCore::V8TestEventTarget::createWrapper):
+        * bindings/scripts/test/V8/V8TestException.cpp:
+        (WebCore::V8TestException::createWrapper):
+        * bindings/scripts/test/V8/V8TestInterface.cpp:
+        (WebCore::V8TestInterface::constructorCallback):
+        (WebCore::V8TestInterface::createWrapper):
+        * bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp:
+        (WebCore::V8TestMediaQueryListListener::createWrapper):
+        * bindings/scripts/test/V8/V8TestNamedConstructor.cpp:
+        (WebCore::V8TestNamedConstructorConstructorCallback):
+        (WebCore::V8TestNamedConstructor::createWrapper):
+        * bindings/scripts/test/V8/V8TestNode.cpp:
+        (WebCore::V8TestNode::constructorCallback):
+        (WebCore::V8TestNode::createWrapper):
+        * bindings/scripts/test/V8/V8TestObj.cpp:
+        (WebCore::V8TestObj::constructorCallback):
+        (WebCore::V8TestObj::createWrapper):
+        * bindings/scripts/test/V8/V8TestOverloadedConstructors.cpp:
+        (WebCore::V8TestOverloadedConstructors::constructor1Callback):
+        (WebCore::V8TestOverloadedConstructors::constructor2Callback):
+        (WebCore::V8TestOverloadedConstructors::constructor3Callback):
+        (WebCore::V8TestOverloadedConstructors::constructor4Callback):
+        (WebCore::V8TestOverloadedConstructors::createWrapper):
+        * bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
+        (WebCore::V8TestSerializedScriptValueInterface::constructorCallback):
+        (WebCore::V8TestSerializedScriptValueInterface::createWrapper):
+        * bindings/v8/DOMDataStore.cpp:
+        * bindings/v8/DOMDataStore.h:
+        (WebCore::DOMDataStore::setWrapper):
+        (DOMDataStore):
+        (WebCore::DOMDataStore::set):
+        (WebCore::DOMDataStore::setWrapperInObject):
+        * bindings/v8/DOMWrapperMap.h:
+        (WebCore::DOMWrapperMap::get):
+        (WebCore::DOMWrapperMap::set):
+        (WebCore::DOMWrapperMap::removeAndDispose):
+        (WebCore::DOMWrapperMap::defaultWeakCallback):
+        * bindings/v8/ScriptWrappable.h:
+        (WebCore::ScriptWrappable::wrapper):
+        (WebCore::ScriptWrappable::setWrapper):
+        (WebCore::ScriptWrappable::reportMemoryUsage):
+        (ScriptWrappable):
+        (WebCore::ScriptWrappable::disposeWrapper):
+        (WebCore::ScriptWrappable::weakCallback):
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::installDOMWindow):
+        * bindings/v8/V8DOMWrapper.h:
+        (V8DOMWrapper):
+        (WebCore::V8DOMWrapper::associateObjectWithWrapper):
+        * bindings/v8/V8NPObject.cpp:
+        (WebCore::weakNPObjectCallback):
+        (WebCore::createV8ObjectForNPObject):
+        (WebCore::forgetV8ObjectForNPObject):
+        * bindings/v8/WorkerScriptController.cpp:
+        (WebCore::WorkerScriptController::initializeContextIfNeeded):
+        * bindings/v8/WrapperTypeInfo.h:
+        (WebCore):
+        (WrapperConfiguration):
+        (WebCore::WrapperConfiguration::configureWrapper):
+        (WebCore::buildWrapperConfiguration):
+        * bindings/v8/custom/V8ArrayBufferCustom.cpp:
+        (WebCore::V8ArrayBuffer::constructorCallbackCustom):
+        * bindings/v8/custom/V8ArrayBufferViewCustom.h:
+        (WebCore::wrapArrayBufferView):
+        (WebCore::constructWebGLArray):
+        * bindings/v8/custom/V8AudioContextCustom.cpp:
+        (WebCore::V8AudioContext::constructorCallbackCustom):
+        * bindings/v8/custom/V8DOMFormDataCustom.cpp:
+        (WebCore::V8DOMFormData::constructorCallbackCustom):
+        * bindings/v8/custom/V8DataViewCustom.cpp:
+        (WebCore::V8DataView::constructorCallbackCustom):
+        * bindings/v8/custom/V8HTMLImageElementConstructor.cpp:
+        (WebCore::v8HTMLImageElementConstructorCallback):
+        * bindings/v8/custom/V8IntentCustom.cpp:
+        (WebCore::V8Intent::constructorCallbackCustom):
+        * bindings/v8/custom/V8MessageChannelCustom.cpp:
+        (WebCore::V8MessageChannel::constructorCallbackCustom):
+        * bindings/v8/custom/V8MutationObserverCustom.cpp:
+        (WebCore::V8MutationObserver::constructorCallbackCustom):
+        * bindings/v8/custom/V8WebKitPointCustom.cpp:
+        (WebCore::V8WebKitPoint::constructorCallbackCustom):
+        * bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
+        (WebCore::V8XMLHttpRequest::constructorCallbackCustom):
+
 2013-02-07  Zan Dobersek  <zdobersek@igalia.com>
 
         [Autotools] Remove uses of Automake FARSTREAM_(CFLAGS|LIBS) variables, USE_FARSTREAM conditional
index 5cd5e0377a30d4f03351142dcd2a499779b45be7..e1b4f5bf0a1705716f65aeca6ffaf99898a653b6 100644 (file)
@@ -1964,7 +1964,7 @@ END
 
     push(@implContent, <<END);
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 END
 
@@ -2039,7 +2039,7 @@ END
     RefPtr<${interfaceName}> event = ${interfaceName}::create(type, eventInit);
 
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(event.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(event.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -2180,7 +2180,7 @@ END
 
     push(@implContent, <<END);
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &${v8InterfaceName}Constructor::info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &${v8InterfaceName}Constructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 END
 
@@ -3536,9 +3536,7 @@ END
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 END
index 021c15b1bbd49ad7e4bc6d1fbc949373775fdfb8..fae83978c878a8dcf6f37ddcdc0c1b4911055fe2 100644 (file)
@@ -180,9 +180,7 @@ v8::Handle<v8::Object> V8Float64Array::createWrapper(PassRefPtr<Float64Array> im
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8Float64Array::derefObject(void* object)
index 3aae796f55f9f089f910fccaeb8af5ba5586d5a0..1c9fe98b5d14d3331a1f9e5355dcf3b6edf7fa2c 100644 (file)
@@ -207,9 +207,7 @@ v8::Handle<v8::Object> V8TestActiveDOMObject::createWrapper(PassRefPtr<TestActiv
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestActiveDOMObject::derefObject(void* object)
index 3cc3243606b0a3e87dc76582dd07106db4eebec5..730cc291cc7aae1b5dc265f8fc3f00556a379e45 100644 (file)
@@ -145,9 +145,7 @@ v8::Handle<v8::Object> V8TestCustomNamedGetter::createWrapper(PassRefPtr<TestCus
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestCustomNamedGetter::derefObject(void* object)
index 0966f4b2715c12feedfdeb5f412ea40831145b34..a8aacf78af4650940ef5dee50a2faadfb8d5b0b0 100644 (file)
@@ -103,7 +103,7 @@ v8::Handle<v8::Value> V8TestEventConstructor::constructorCallback(const v8::Argu
     RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, eventInit);
 
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(event.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(event.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -177,9 +177,7 @@ v8::Handle<v8::Object> V8TestEventConstructor::createWrapper(PassRefPtr<TestEven
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestEventConstructor::derefObject(void* object)
index 9abbb92ee30099ee19fbd3deab2b2cbea7d5b5d1..0a37eadbe2dc66684872b76fb349bf54bf5102a5 100644 (file)
@@ -211,9 +211,7 @@ v8::Handle<v8::Object> V8TestEventTarget::createWrapper(PassRefPtr<TestEventTarg
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestEventTarget::derefObject(void* object)
index 1a228c3315a4a9852224481a9ed870fe977e2d2c..6b08657bd9e9119d1175a6d513d5453970f25d0d 100644 (file)
@@ -136,9 +136,7 @@ v8::Handle<v8::Object> V8TestException::createWrapper(PassRefPtr<TestException>
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestException::derefObject(void* object)
index 6f24619ab82af785f315373da26bb4c8ee237aea..ea9ec08269d235428a7401c37eefaf30e25d9311 100644 (file)
@@ -273,7 +273,7 @@ v8::Handle<v8::Value> V8TestInterface::constructorCallback(const v8::Arguments&
     if (ec)
         goto fail;
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
   fail:
     return setDOMException(ec, args.GetIsolate());
@@ -366,9 +366,7 @@ v8::Handle<v8::Object> V8TestInterface::createWrapper(PassRefPtr<TestInterface>
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestInterface::derefObject(void* object)
index bf5f4f409d5a6b0f92e13d9b126ad9d7f0faee6b..9c4e8a5cd6a8fa46d31f6c96a30f39f7713a17fc 100644 (file)
@@ -145,9 +145,7 @@ v8::Handle<v8::Object> V8TestMediaQueryListListener::createWrapper(PassRefPtr<Te
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestMediaQueryListListener::derefObject(void* object)
index bc8afd6c0a10f472c46b41d30ecbb0e7cba75303..f9214291fc92c5da8e60400c1828aa2b235db939 100644 (file)
@@ -92,7 +92,7 @@ static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8:
     if (ec)
         goto fail;
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNamedConstructorConstructor::info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNamedConstructorConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
   fail:
     return setDOMException(ec, args.GetIsolate());
@@ -184,9 +184,7 @@ v8::Handle<v8::Object> V8TestNamedConstructor::createWrapper(PassRefPtr<TestName
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestNamedConstructor::derefObject(void* object)
index 402bf16cb661a7219abd3b5668ea3ecf59b10e72..0c9f1ee07cd4032dc9f7572c08b727a4ac862cb3 100644 (file)
@@ -75,7 +75,7 @@ v8::Handle<v8::Value> V8TestNode::constructorCallback(const v8::Arguments& args)
     RefPtr<TestNode> impl = TestNode::create();
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -149,9 +149,7 @@ v8::Handle<v8::Object> V8TestNode::createWrapper(PassRefPtr<TestNode> impl, v8::
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestNode::derefObject(void* object)
index 88c91d646b411708e7d3ea0b51e6c9b2a4593624..b9849d2a5610866236f78234fe58a4c35d26040a 100644 (file)
@@ -2090,7 +2090,7 @@ v8::Handle<v8::Value> V8TestObj::constructorCallback(const v8::Arguments& args)
     RefPtr<TestObj> impl = TestObj::create(testCallback);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -2291,9 +2291,7 @@ v8::Handle<v8::Object> V8TestObj::createWrapper(PassRefPtr<TestObj> impl, v8::Ha
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestObj::derefObject(void* object)
index fbfe1aa302f1622766f56d73b7c81b6c7a6c9a2e..d587402425796096afa8d59b759be3cdc2e0f9d0 100644 (file)
@@ -76,7 +76,7 @@ v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor1Callback(const v
     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBuffer);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -88,7 +88,7 @@ v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor2Callback(const v
     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(arrayBufferView);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -100,7 +100,7 @@ v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor3Callback(const v
     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(blob);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -112,7 +112,7 @@ v8::Handle<v8::Value> V8TestOverloadedConstructors::constructor4Callback(const v
     RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create(string);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -200,9 +200,7 @@ v8::Handle<v8::Object> V8TestOverloadedConstructors::createWrapper(PassRefPtr<Te
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestOverloadedConstructors::derefObject(void* object)
index 20b2d512a2cf9c04615ade6e312a5f4a8afad4ca..eef862048268da5309ec3c6f59c28212ee84c7a4 100644 (file)
@@ -246,7 +246,7 @@ v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback(
     RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueInterface::create(hello, data, messagePortArrayTransferList);
     v8::Handle<v8::Object> wrapper = args.Holder();
 
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
@@ -318,9 +318,7 @@ v8::Handle<v8::Object> V8TestSerializedScriptValueInterface::createWrapper(PassR
         return wrapper;
 
     installPerContextProperties(wrapper, impl.get(), isolate);
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
-    if (!hasDependentLifetime)
-        wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasDependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Independent);
     return wrapper;
 }
 void V8TestSerializedScriptValueInterface::derefObject(void* object)
index ccb9b8a0c6fd0d158782f94541bb513d2aa23fd8..12a52fe406eaa3d9a036428c74ad6a78c4e0ba6b 100644 (file)
@@ -80,24 +80,4 @@ void DOMDataStore::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     info.addMember(m_wrapperMap, "wrapperMap");
 }
 
-void DOMDataStore::weakCallback(v8::Isolate* isolate, v8::Persistent<v8::Value> value, void* context)
-{
-    ScriptWrappable* key = static_cast<ScriptWrappable*>(context);
-    ASSERT(value->IsObject());
-    v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::Cast(value);
-    ASSERT(key->wrapper() == wrapper);
-    // Note: |object| might not be equal to |key|, e.g., if ScriptWrappable isn't a left-most base class.
-    void* object = toNative(wrapper);
-    WrapperTypeInfo* info = toWrapperTypeInfo(wrapper);
-    ASSERT(info->derefObjectFunction);
-
-    key->clearWrapper();
-    value.Dispose();
-    value.Clear();
-    // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed
-    // inside key->deref(), which causes Node destructions. We should
-    // make Node destructions incremental.
-    info->derefObject(object);
-}
-
 } // namespace WebCore
index c98b5e41cfea34eec3795afb499270c561301da4..059e019c0e8c14f751e83d88d0753078b4df4221 100644 (file)
@@ -89,15 +89,15 @@ public:
     }
 
     template<typename T>
-    static void setWrapper(T* object, v8::Persistent<v8::Object> wrapper, v8::Isolate* isolate)
+    static void setWrapper(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
     {
         if (mainWorldWrapperIsStoredInObject(object) && isMainWorldObject(object)) {
             if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
-                setWrapperInObject(object, wrapper, isolate);
+                setWrapperInObject(object, wrapper, isolate, configuration);
                 return;
             }
         }
-        return current(isolate)->set(object, wrapper, isolate);
+        return current(isolate)->set(object, wrapper, isolate, configuration);
     }
 
     template<typename T>
@@ -108,21 +108,21 @@ public:
         return m_wrapperMap.get(object);
     }
 
+    void reportMemoryUsage(MemoryObjectInfo*) const;
+
+private:
     template<typename T>
-    inline void set(T* object, v8::Persistent<v8::Object> wrapper, v8::Isolate* isolate)
+    inline void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
     {
         ASSERT(!!object);
         ASSERT(!wrapper.IsEmpty());
         if (mainWorldWrapperIsStoredInObject(object) && m_type == MainWorld) {
-            setWrapperInObject(object, wrapper, isolate);
+            setWrapperInObject(object, wrapper, isolate, configuration);
             return;
         }
-        m_wrapperMap.set(object, wrapper);
+        m_wrapperMap.set(object, wrapper, configuration);
     }
 
-    void reportMemoryUsage(MemoryObjectInfo*) const;
-
-private:
     static DOMDataStore* mainWorldStore();
 
     static bool mainWorldWrapperIsStoredInObject(void*) { return false; }
@@ -154,26 +154,20 @@ private:
         return object->wrapper();
     }
 
-    static void setWrapperInObject(void*, v8::Persistent<v8::Object>, v8::Isolate*)
+    static void setWrapperInObject(void*, v8::Handle<v8::Object>, v8::Isolate*, const WrapperConfiguration&)
     {
         ASSERT_NOT_REACHED();
     }
-    static void setWrapperInObject(ScriptWrappable* object, v8::Persistent<v8::Object> wrapper, v8::Isolate* isolate)
+    static void setWrapperInObject(ScriptWrappable* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
     {
-        ASSERT(object->wrapper().IsEmpty());
-        object->setWrapper(wrapper);
-        wrapper.MakeWeak(isolate, object, weakCallback);
+        object->setWrapper(wrapper, isolate, configuration);
     }
-    static void setWrapperInObject(Node* object, v8::Persistent<v8::Object> wrapper, v8::Isolate* isolate)
+    static void setWrapperInObject(Node* object, v8::Persistent<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
     {
-        ASSERT(object->wrapper().IsEmpty());
-        object->setWrapper(wrapper);
+        object->setWrapper(wrapper, isolate, configuration);
         V8GCController::didCreateWrapperForNode(object);
-        wrapper.MakeWeak(isolate, static_cast<ScriptWrappable*>(object), weakCallback);
     }
 
-    static void weakCallback(v8::Isolate*, v8::Persistent<v8::Value>, void* context);
-
     Type m_type;
     DOMWrapperMap<void> m_wrapperMap;
 };
index 00c03e0974370c685123eb4e5e568f3c8784c994..af0f8967276de3dbd0d42c141be9100d018c2fb7 100644 (file)
@@ -50,17 +50,19 @@ public:
     {
     }
 
-    v8::Persistent<v8::Object> get(KeyType* key)
+    v8::Handle<v8::Object> get(KeyType* key)
     {
         return m_map.get(key);
     }
 
-    void set(KeyType* key, v8::Persistent<v8::Object> wrapper)
+    void set(KeyType* key, v8::Handle<v8::Object> wrapper, const WrapperConfiguration& configuration)
     {
         ASSERT(!m_map.contains(key));
         ASSERT(static_cast<KeyType*>(toNative(wrapper)) == key);
-        wrapper.MakeWeak(m_isolate, this, m_callback);
-        m_map.set(key, wrapper);
+        v8::Persistent<v8::Object> persistent = v8::Persistent<v8::Object>::New(m_isolate, wrapper);
+        configuration.configureWrapper(persistent, m_isolate);
+        persistent.MakeWeak(m_isolate, this, m_callback);
+        m_map.set(key, persistent);
     }
 
     void clear()
@@ -81,12 +83,15 @@ public:
         info.ignoreMember(m_callback);
     }
 
-    void remove(KeyType* key, v8::Persistent<v8::Object> wrapper)
+    void removeAndDispose(KeyType* key, v8::Handle<v8::Object> value, v8::Isolate* isolate)
     {
+        v8::Persistent<v8::Object> wrapper(*value);
         typename MapType::iterator it = m_map.find(key);
         ASSERT(it != m_map.end());
         ASSERT(it->value == wrapper);
         m_map.remove(it);
+        wrapper.Dispose(isolate);
+        value.Clear();
     }
 
 private:
@@ -98,10 +103,7 @@ private:
         WrapperTypeInfo* type = toWrapperTypeInfo(wrapper);
         ASSERT(type->derefObjectFunction);
         KeyType* key = static_cast<KeyType*>(toNative(wrapper));
-
-        map->remove(key, wrapper);
-        wrapper.Dispose();
-        wrapper.Clear();
+        map->removeAndDispose(key, wrapper, isolate);
         type->derefObject(key);
     }
 
index 655001745aeffcc2e3fb57aa01a6fbd4833c734e..16bc78a944c7122805953c08c0ecb96b0d0eef24 100644 (file)
@@ -32,6 +32,7 @@
 #define ScriptWrappable_h
 
 #include "WebCoreMemoryInstrumentation.h"
+#include "WrapperTypeInfo.h"
 #include <v8.h>
 
 namespace WebCore {
@@ -40,37 +41,35 @@ class ScriptWrappable {
 public:
     ScriptWrappable() { }
 
-    v8::Persistent<v8::Object> wrapper() const
+    v8::Handle<v8::Object> wrapper() const
     {
-        return v8::Persistent<v8::Object>(maskOrUnmaskPointer(*m_maskedWrapper));
+        return v8::Handle<v8::Object>(maskOrUnmaskPointer(*m_maskedWrapper));
     }
 
-    void setWrapper(v8::Persistent<v8::Object> wrapper)
+    void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
     {
-        m_maskedWrapper = maskOrUnmaskPointer(*wrapper);
+        ASSERT(m_maskedWrapper.IsEmpty());
+        v8::Persistent<v8::Object> persistent = v8::Persistent<v8::Object>::New(wrapper);
+        configuration.configureWrapper(persistent, isolate);
+        persistent.MakeWeak(isolate, this, weakCallback);
+        m_maskedWrapper = maskOrUnmaskPointer(*persistent);
     }
 
-    void clearWrapper()
+    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     {
-        ASSERT(!m_maskedWrapper.IsEmpty());
-        m_maskedWrapper.Clear();
+        MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
+        info.ignoreMember(m_maskedWrapper);
     }
 
-    void disposeWrapper()
+private:
+    inline void disposeWrapper(v8::Persistent<v8::Value> value)
     {
         ASSERT(!m_maskedWrapper.IsEmpty());
-        m_maskedWrapper = wrapper();
-        m_maskedWrapper.Dispose();
+        ASSERT(*value == maskOrUnmaskPointer(*m_maskedWrapper));
+        value.Dispose();
         m_maskedWrapper.Clear();
     }
 
-    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
-    {
-        MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
-        info.ignoreMember(m_maskedWrapper);
-    }
-
-private:
     v8::Persistent<v8::Object> m_maskedWrapper;
 
     static inline v8::Object* maskOrUnmaskPointer(const v8::Object* object)
@@ -79,6 +78,25 @@ private:
         const uintptr_t randomMask = ~(reinterpret_cast<uintptr_t>(&WebCoreMemoryTypes::DOM) >> 13); // Entropy via ASLR.
         return reinterpret_cast<v8::Object*>((objectPointer ^ randomMask) & (!objectPointer - 1)); // Preserve null without branching.
     }
+
+    static void weakCallback(v8::Isolate* isolate, v8::Persistent<v8::Value> value, void* context)
+    {
+        ScriptWrappable* key = static_cast<ScriptWrappable*>(context);
+        ASSERT(value->IsObject());
+        v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::Cast(value);
+        ASSERT(key->wrapper() == wrapper);
+        key->disposeWrapper(value);
+
+        // Note: |object| might not be equal to |key|, e.g., if ScriptWrappable isn't a left-most base class.
+        void* object = toNative(wrapper);
+        WrapperTypeInfo* info = toWrapperTypeInfo(wrapper);
+        ASSERT(info->derefObjectFunction);
+
+        // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed
+        // inside key->deref(), which causes Node destructions. We should
+        // make Node destructions incremental.
+        info->derefObject(object);
+    }
 };
 
 } // namespace WebCore
index ca600999321f38d1cbf5652675c0e7ce9999cb9b..f998e16c80aacda86c4deca4f2009b05404a84a1 100644 (file)
@@ -335,7 +335,7 @@ bool V8DOMWindowShell::installDOMWindow()
     v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_context.get());
     V8DOMWrapper::setNativeInfo(innerGlobalObject, &V8DOMWindow::info, window);
     innerGlobalObject->SetPrototype(windowWrapper);
-    V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<DOMWindow>(window), &V8DOMWindow::info, windowWrapper, m_isolate);
+    V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<DOMWindow>(window), &V8DOMWindow::info, windowWrapper, m_isolate, WrapperConfiguration::Dependent);
     return true;
 }
 
index d8ff2861fd705f2c66cd4ff00cecd77a1c7708b2..a91cbb4c302411fa62c1e2d1c8a00431b7f8f5d2 100644 (file)
@@ -56,11 +56,9 @@ namespace WebCore {
         static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creationContext, WrapperTypeInfo*, void*, v8::Isolate*);
 
         template<typename T>
-        static inline v8::Persistent<v8::Object> associateObjectWithWrapper(PassRefPtr<T>, WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*);
+        static inline v8::Handle<v8::Object> associateObjectWithWrapper(PassRefPtr<T>, WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfiguration::Lifetime);
         static inline void setNativeInfo(v8::Handle<v8::Object>, WrapperTypeInfo*, void*);
         static inline void clearNativeInfo(v8::Handle<v8::Object>, WrapperTypeInfo*);
-        static inline void setWrapperClass(void*, v8::Persistent<v8::Object>);
-        static inline void setWrapperClass(Node*, v8::Persistent<v8::Object>);
 
         static bool isDOMWrapper(v8::Handle<v8::Value>);
         static bool isWrapperOfType(v8::Handle<v8::Value>, WrapperTypeInfo*);
@@ -69,16 +67,6 @@ namespace WebCore {
         static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child);
     };
 
-    inline void V8DOMWrapper::setWrapperClass(void*, v8::Persistent<v8::Object> wrapper)
-    {
-        wrapper.SetWrapperClassId(v8DOMObjectClassId);
-    }
-
-    inline void V8DOMWrapper::setWrapperClass(Node*, v8::Persistent<v8::Object> wrapper)
-    {
-        wrapper.SetWrapperClassId(v8DOMNodeClassId);
-    }
-
     inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, WrapperTypeInfo* type, void* object)
     {
         ASSERT(wrapper->InternalFieldCount() >= 2);
@@ -97,14 +85,13 @@ namespace WebCore {
     }
 
     template<typename T>
-    inline v8::Persistent<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<T> object, WrapperTypeInfo* type, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate)
+    inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<T> object, WrapperTypeInfo* type, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, WrapperConfiguration::Lifetime lifetime)
     {
         setNativeInfo(wrapper, type, object.get());
-        v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
-        ASSERT(maybeDOMWrapper(wrapperHandle));
-        setWrapperClass(object.get(), wrapperHandle);
-        DOMDataStore::setWrapper(object.leakRef(), wrapperHandle, isolate);
-        return wrapperHandle;
+        ASSERT(maybeDOMWrapper(wrapper));
+        WrapperConfiguration configuration = buildWrapperConfiguration(object.get(), lifetime);
+        DOMDataStore::setWrapper(object.leakRef(), wrapper, isolate, configuration);
+        return wrapper;
     }
 
 }
index 45bea2eb51a8394b91258e0254694f7beafc0964..4c9db8508cd0a66d6bdf470dcb631d694e4f48ba 100644 (file)
@@ -402,9 +402,7 @@ static void weakNPObjectCallback(v8::Isolate* isolate, v8::Persistent<v8::Value>
 
     // Must remove from our map before calling _NPN_ReleaseObject(). _NPN_ReleaseObject can
     // call forgetV8ObjectForNPObject, which uses the table as well.
-    staticNPObjectMap().remove(npObject, wrapper);
-    wrapper.Dispose();
-    wrapper.Clear();
+    staticNPObjectMap().removeAndDispose(npObject, wrapper, isolate);
 
     if (_NPN_IsAlive(npObject))
         _NPN_ReleaseObject(npObject);
@@ -448,27 +446,24 @@ v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root
         return value;
 
     V8DOMWrapper::setNativeInfo(value, npObjectTypeInfo(), object);
-    v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(value);
-    V8DOMWrapper::setWrapperClass(object, wrapperHandle);
 
     // KJS retains the object as part of its wrapper (see Bindings::CInstance).
     _NPN_RetainObject(object);
     _NPN_RegisterObject(object, root);
 
-    staticNPObjectMap().set(object, wrapperHandle);
-    ASSERT(V8DOMWrapper::maybeDOMWrapper(wrapperHandle));
+    WrapperConfiguration configuration = buildWrapperConfiguration(object, WrapperConfiguration::Dependent);
+    staticNPObjectMap().set(object, value, configuration);
+    ASSERT(V8DOMWrapper::maybeDOMWrapper(value));
     return value;
 }
 
 void forgetV8ObjectForNPObject(NPObject* object)
 {
-    v8::Persistent<v8::Object> wrapper = staticNPObjectMap().get(object);
+    v8::Handle<v8::Object> wrapper = staticNPObjectMap().get(object);
     if (!wrapper.IsEmpty()) {
         v8::HandleScope scope;
         V8DOMWrapper::clearNativeInfo(wrapper, npObjectTypeInfo());
-        staticNPObjectMap().remove(object, wrapper);
-        wrapper.Dispose();
-        wrapper.Clear();
+        staticNPObjectMap().removeAndDispose(object, wrapper, v8::Isolate::GetCurrent());
         _NPN_ReleaseObject(object);
     }
 }
index 2c9ede866efe52677318d12e599534a1c723a3be..bc460938279fe4df33a2a81500c68c1a63057991 100644 (file)
@@ -127,7 +127,7 @@ bool WorkerScriptController::initializeContextIfNeeded()
         return false;
     }
 
-    V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<WorkerContext>(m_workerContext), contextType, jsWorkerContext, m_isolate);
+    V8DOMWrapper::associateObjectWithWrapper(PassRefPtr<WorkerContext>(m_workerContext), contextType, jsWorkerContext, m_isolate, WrapperConfiguration::Dependent);
 
     // Insert the object instance as the prototype of the shadow object.
     v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_context->Global()->GetPrototype());
index 9b6385d65659463dcd9e90986b727a7077e9bb66..1934eb1015c054e1d55fac522af3e6132216d7cc 100644 (file)
@@ -38,6 +38,7 @@ namespace WebCore {
     class ActiveDOMObject;
     class DOMDataStore;
     class EventTarget;
+    class Node;
 
     static const int v8DOMWrapperTypeIndex = 0;
     static const int v8DOMWrapperObjectIndex = 1;
@@ -141,6 +142,34 @@ namespace WebCore {
         return static_cast<WrapperTypeInfo*>(object->GetAlignedPointerFromInternalField(v8DOMWrapperTypeIndex));
     }
 
+    struct WrapperConfiguration {
+
+        enum Lifetime {
+            Dependent, Independent
+        };
+
+        void configureWrapper(v8::Persistent<v8::Object> wrapper, v8::Isolate* isolate) const
+        {
+            wrapper.SetWrapperClassId(classId);
+            if (lifetime == Independent)
+                wrapper.MarkIndependent(isolate);
+        }
+
+        const uint16_t classId;
+        const Lifetime lifetime;
+    };
+
+    inline WrapperConfiguration buildWrapperConfiguration(void*, WrapperConfiguration::Lifetime lifetime)
+    {
+        WrapperConfiguration configuration = {v8DOMObjectClassId, lifetime};
+        return configuration;
+    }
+
+    inline WrapperConfiguration buildWrapperConfiguration(Node*, WrapperConfiguration::Lifetime lifetime)
+    {
+        WrapperConfiguration configuration = {v8DOMNodeClassId, lifetime};
+        return configuration;
+    }
 }
 
 #endif // WrapperTypeInfo_h
index d972c31e7f8d9fbe965a7b1e86be6fb592f2c2ff..227172f2e28165b8578a0095061c17a6cc28df8b 100644 (file)
@@ -76,7 +76,7 @@ v8::Handle<v8::Value> V8ArrayBuffer::constructorCallbackCustom(const v8::Argumen
     v8::V8::AdjustAmountOfExternalAllocatedMemory(buffer->byteLength());
     // Transform the holder into a wrapper object for the array.
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(buffer.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(buffer.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index 8321cda45a386b1c6c0b499362c088f4752855ef..eab684c25f997700b9b074f2aebd49cbe9e2f492 100644 (file)
@@ -55,8 +55,7 @@ v8::Handle<v8::Value> wrapArrayBufferView(const v8::Arguments& args, WrapperType
     if (hasIndexer)
         args.Holder()->SetIndexedPropertiesToExternalArrayData(array.get()->baseAddress(), arrayType, array.get()->length());
     v8::Handle<v8::Object> wrapper = args.Holder();
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(array.release(), type, wrapper, args.GetIsolate());
-    wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(array.release(), type, wrapper, args.GetIsolate(), WrapperConfiguration::Independent);
     return wrapper;
 }
 
@@ -225,8 +224,7 @@ v8::Handle<v8::Value> constructWebGLArray(const v8::Arguments& args, WrapperType
     }
 
     v8::Handle<v8::Object> wrapper = args.Holder();
-    v8::Persistent<v8::Object> wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(array.release(), type, wrapper, args.GetIsolate());
-    wrapperHandle.MarkIndependent();
+    V8DOMWrapper::associateObjectWithWrapper(array.release(), type, wrapper, args.GetIsolate(), WrapperConfiguration::Independent);
     return wrapper;
 }
 
index 98d225eb0ec30cb952b33d9cfd35261ee0747e20..b13049655db31c3f51f5faa4ec65379cee2bb333 100644 (file)
@@ -73,7 +73,7 @@ v8::Handle<v8::Value> V8AudioContext::constructorCallbackCustom(const v8::Argume
     
     // Transform the holder into a wrapper object for the audio context.
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(audioContext.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(audioContext.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     
     return wrapper;
 }
index 054538476cb76b7561854eaa9116296513b52c83..39a3d115d4ad0a20714d7bcbc328177baff4c248 100644 (file)
@@ -47,7 +47,7 @@ v8::Handle<v8::Value> V8DOMFormData::constructorCallbackCustom(const v8::Argumen
     RefPtr<DOMFormData> domFormData = DOMFormData::create(form);
 
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(domFormData.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(domFormData.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index 7bd7a91f683efe6b1d281743e4295908de0683e3..6233cec861963935c208445014eb83c80c3ec0c8 100644 (file)
@@ -39,7 +39,7 @@ v8::Handle<v8::Value> V8DataView::constructorCallbackCustom(const v8::Arguments&
         // 'new DataView()' and the call used to construct the cached DataView object.
         RefPtr<DataView> dataView = DataView::create(0);
         v8::Handle<v8::Object> wrapper = args.Holder();
-        V8DOMWrapper::associateObjectWithWrapper(dataView.release(), &info, wrapper, args.GetIsolate());
+        V8DOMWrapper::associateObjectWithWrapper(dataView.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
         return wrapper;
     }
     if (args[0]->IsNull() || !V8ArrayBuffer::HasInstance(args[0], args.GetIsolate()))
index 3b53bb90dce5f81a1f0e3789861dbeb15aa9520f..5026adf2aa9c2813fff878851007e8fe787387f2 100644 (file)
@@ -77,7 +77,7 @@ static v8::Handle<v8::Value> v8HTMLImageElementConstructorCallback(const v8::Arg
 
     RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight);
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(image.release(), &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(image.release(), &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index ab6467ecd19881a6d85d922db79b78fb548eb3a4..a8670627d4a98004ee8e149d55e9dc5381ead740 100644 (file)
@@ -57,7 +57,7 @@ v8::Handle<v8::Value> V8Intent::constructorCallbackCustom(const v8::Arguments& a
             return setDOMException(ec, args.GetIsolate());
 
         v8::Handle<v8::Object> wrapper = args.Holder();
-        V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+        V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
         return wrapper;
     }
 
@@ -80,7 +80,7 @@ v8::Handle<v8::Value> V8Intent::constructorCallbackCustom(const v8::Arguments& a
         return setDOMException(ec, args.GetIsolate());
 
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index 33a0a234d9a1633346f09ac62951cd9e5691fff5..9133afa5a768e451fbf546466280116c678c3670 100644 (file)
@@ -57,7 +57,7 @@ v8::Handle<v8::Value> V8MessageChannel::constructorCallbackCustom(const v8::Argu
     V8DOMWrapper::setNamedHiddenReference(wrapper, "port1", toV8(obj->port1(), args.Holder(), args.GetIsolate()));
     V8DOMWrapper::setNamedHiddenReference(wrapper, "port2", toV8(obj->port2(), args.Holder(), args.GetIsolate()));
 
-    V8DOMWrapper::associateObjectWithWrapper(obj.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(obj.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index 977bcb38f6d03c256c402406cbc8a1da04ffe58a..588e91127eba26542c2a5bee7481b6c11c95673a 100644 (file)
@@ -56,7 +56,7 @@ v8::Handle<v8::Value> V8MutationObserver::constructorCallbackCustom(const v8::Ar
     RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context, wrapper, args.GetIsolate());
     RefPtr<MutationObserver> observer = MutationObserver::create(callback.release());
 
-    V8DOMWrapper::associateObjectWithWrapper(observer.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(observer.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index 3f10de45ee93b8e29469814e67aedf3e44b933bf..decf76cb56d37a851fc586524a46614cac507e9e 100644 (file)
@@ -57,7 +57,7 @@ v8::Handle<v8::Value> V8WebKitPoint::constructorCallbackCustom(const v8::Argumen
     }
     RefPtr<WebKitPoint> point = WebKitPoint::create(x, y);
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(point.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(point.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }
 
index 95dc363a2a143ca54473b693409a6a4d1944e6a4..4237f9c64f576a41a8645a715ebddd054590ad7d 100644 (file)
@@ -61,7 +61,7 @@ v8::Handle<v8::Value> V8XMLHttpRequest::constructorCallbackCustom(const v8::Argu
     RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
 
     v8::Handle<v8::Object> wrapper = args.Holder();
-    V8DOMWrapper::associateObjectWithWrapper(xmlHttpRequest.release(), &info, wrapper, args.GetIsolate());
+    V8DOMWrapper::associateObjectWithWrapper(xmlHttpRequest.release(), &info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
     return wrapper;
 }