Skip to content

Commit 2b4f08f

Browse files
author
Anders Carlsson
committed
Weak should have a move constructor and move assignment operator
https://bugs.webkit.org/show_bug.cgi?id=121963 Reviewed by Oliver Hunt. This is the first step towards getting rid of PassWeak. * API/JSClassRef.cpp: (OpaqueJSClass::prototype): * heap/Weak.h: * heap/WeakInlines.h: (JSC::::Weak): (JSC::::leakImpl): * runtime/SimpleTypedArrayController.cpp: (JSC::SimpleTypedArrayController::toJS): Canonical link: https://commits.webkit.org/139974@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156469 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent e7f5221 commit 2b4f08f

5 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎Source/JavaScriptCore/API/JSClassRef.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ JSObject* OpaqueJSClass::prototype(ExecState* exec)
207207
prototype->setPrototype(exec->vm(), parentPrototype);
208208
}
209209

210-
jsClassData.cachedPrototype = PassWeak<JSObject>(prototype);
210+
jsClassData.cachedPrototype = Weak<JSObject>(prototype);
211211
return prototype;
212212
}

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2013-09-26 Anders Carlsson <andersca@apple.com>
2+
3+
Weak should have a move constructor and move assignment operator
4+
https://bugs.webkit.org/show_bug.cgi?id=121963
5+
6+
Reviewed by Oliver Hunt.
7+
8+
This is the first step towards getting rid of PassWeak.
9+
10+
* API/JSClassRef.cpp:
11+
(OpaqueJSClass::prototype):
12+
* heap/Weak.h:
13+
* heap/WeakInlines.h:
14+
(JSC::::Weak):
15+
(JSC::::leakImpl):
16+
* runtime/SimpleTypedArrayController.cpp:
17+
(JSC::SimpleTypedArrayController::toJS):
18+
119
2013-09-26 Mark Hahnenberg <mhahnenberg@apple.com>
220

321
op_to_this shouldn't use value profiling

‎Source/JavaScriptCore/heap/Weak.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ template<typename T> class Weak {
5757
bool isHashTableDeletedValue() const;
5858
Weak(HashTableDeletedValueTag);
5959

60+
Weak(Weak&&);
6061
template<typename U> Weak(const PassWeak<U>&);
6162

6263
~Weak()
@@ -65,6 +66,8 @@ template<typename T> class Weak {
6566
}
6667

6768
void swap(Weak&);
69+
70+
Weak& operator=(Weak&&);
6871
Weak& operator=(const PassWeak<T>&);
6972

7073
bool operator!() const;
@@ -79,6 +82,7 @@ template<typename T> class Weak {
7982
operator UnspecifiedBoolType*() const;
8083

8184
PassWeak<T> release();
85+
WeakImpl* leakImpl() WARN_UNUSED_RETURN;
8286
void clear()
8387
{
8488
if (!m_impl)

‎Source/JavaScriptCore/heap/WeakInlines.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ template<typename T> template<typename U> inline Weak<T>::Weak(const PassWeak<U
5353
{
5454
}
5555

56+
template<typename T> inline Weak<T>::Weak(Weak&& other)
57+
: m_impl(other.leakImpl())
58+
{
59+
}
60+
5661
template<class T> inline void swap(Weak<T>& a, Weak<T>& b)
5762
{
5863
a.swap(b);
@@ -70,6 +75,13 @@ template<typename T> inline Weak<T>& Weak<T>::operator=(const PassWeak<T>& o)
7075
return *this;
7176
}
7277

78+
template<typename T> inline auto Weak<T>::operator=(Weak&& other) -> Weak&
79+
{
80+
Weak weak = std::move(other);
81+
swap(weak);
82+
return *this;
83+
}
84+
7385
template<typename T> inline T* Weak<T>::operator->() const
7486
{
7587
ASSERT(m_impl && m_impl->state() == WeakImpl::Live);
@@ -111,6 +123,13 @@ template<typename T> inline PassWeak<T> Weak<T>::release()
111123
return tmp;
112124
}
113125

126+
template<typename T> inline WeakImpl* Weak<T>::leakImpl()
127+
{
128+
WeakImpl* impl = m_impl;
129+
m_impl = nullptr;
130+
return impl;
131+
}
132+
114133
template<typename T> inline WeakImpl* Weak<T>::hashTableDeletedValue()
115134
{
116135
return reinterpret_cast<WeakImpl*>(-1);

‎Source/JavaScriptCore/runtime/SimpleTypedArrayController.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ JSArrayBuffer* SimpleTypedArrayController::toJS(
4444

4545
JSArrayBuffer* result = JSArrayBuffer::create(
4646
exec->vm(), globalObject->arrayBufferStructure(), native);
47-
native->m_wrapper = PassWeak<JSArrayBuffer>(result);
47+
native->m_wrapper = Weak<JSArrayBuffer>(result);
4848
return result;
4949
}
5050

0 commit comments

Comments
 (0)