Made Weak<T> single-owner, adding PassWeak<T>
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 01:56:13 +0000 (01:56 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 01:56:13 +0000 (01:56 +0000)
commitd96a765177a576296cc3fbc06839cf9cca60cebb
treebe9ae904c7ca661183ee340f65723a58dfbda8c9
parentdd7274c798c46f3e04f40df8e52f6313df3c1dc2
Made Weak<T> single-owner, adding PassWeak<T>
https://bugs.webkit.org/show_bug.cgi?id=78740

Reviewed by Sam Weinig.

Source/JavaScriptCore:

This works basically the same way as OwnPtr<T> and PassOwnPtr<T>.

This clarifies the semantics of finalizers: It's ambiguous and probably
a bug to copy a finalizer (i.e., it's a bug to run a C++ destructor
twice), so I've made Weak<T> non-copyable. Anywhere we used to copy a
Weak<T>, we now use PassWeak<T>.

This also makes Weak<T> HashMaps more efficient.

* API/JSClassRef.cpp:
(OpaqueJSClass::prototype): Use PassWeak<T> instead of set(), since
set() is gone now.

* JavaScriptCore.xcodeproj/project.pbxproj: Export!

* heap/PassWeak.h: Added.
(JSC):
(PassWeak):
(JSC::PassWeak::PassWeak):
(JSC::PassWeak::~PassWeak):
(JSC::PassWeak::get):
(JSC::::leakHandle):
(JSC::adoptWeak):
(JSC::operator==):
(JSC::operator!=): This is the Weak<T> version of PassOwnPtr<T>.

* heap/Weak.h:
(Weak):
(JSC::Weak::Weak):
(JSC::Weak::release):
(JSC::Weak::hashTableDeletedValue):
(JSC::=):
(JSC): Changed to be non-copyable, removing a lot of copying-related
APIs. Added hash traits so hash maps still work.

* jit/JITStubs.cpp:
(JSC::JITThunks::hostFunctionStub):
* runtime/RegExpCache.cpp:
(JSC::RegExpCache::lookupOrCreate): Use PassWeak<T>, as required by
our new hash map API.

Source/WebCore:

* bindings/js/JSDOMBinding.cpp:
(WebCore::jsStringSlowCase): Use PassWeak<T>, as required by our new
hash map API.

* bindings/js/JSDOMBinding.h:
(WebCore::getCachedWrapper):
(WebCore::cacheWrapper): Use PassWeak<T> and raw pointer, as required by
our new hash map API.

* bindings/js/JSEventListener.h:
(WebCore::JSEventListener::setWrapper):
* bindings/js/ScriptWrappable.h:
(WebCore::ScriptWrappable::setWrapper):
* bridge/jsc/BridgeJSC.cpp:
(JSC::Bindings::Instance::createRuntimeObject):
* bridge/runtime_root.cpp:
(JSC::Bindings::RootObject::addRuntimeObject): Use PassWeak<T>, as
required by our new hash map and Weak<T> APIs.

Source/WebKit2:

* WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:
(WebKit::NPRuntimeObjectMap::getOrCreateJSObject): Use raw pointer and
PassWeak<T>, as required by our new hash map API.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@108010 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
Source/JavaScriptCore/API/JSClassRef.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/heap/PassWeak.h [new file with mode: 0644]
Source/JavaScriptCore/heap/Weak.h
Source/JavaScriptCore/jit/JITStubs.cpp
Source/JavaScriptCore/runtime/RegExpCache.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSEventListener.h
Source/WebCore/bindings/js/ScriptWrappable.h
Source/WebCore/bridge/jsc/BridgeJSC.cpp
Source/WebCore/bridge/qt/qt_runtime.cpp
Source/WebCore/bridge/runtime_root.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp