Modified: trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp (295376 => 295377)
--- trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp 2022-06-08 05:20:39 UTC (rev 295376)
+++ trunk/Source/_javascript_Core/runtime/ArrayBuffer.cpp 2022-06-08 07:26:02 UTC (rev 295377)
@@ -42,73 +42,6 @@
return destructor.get().copyRef();
}
-SharedArrayBufferContents::SharedArrayBufferContents(void* data, size_t size, ArrayBufferDestructorFunction&& destructor)
- : m_data(data, size)
- , m_destructor(WTFMove(destructor))
- , m_sizeInBytes(size)
-{
-}
-
-SharedArrayBufferContents::~SharedArrayBufferContents()
-{
- if (m_destructor) {
- // FIXME: we shouldn't use getUnsafe here https://bugs.webkit.org/show_bug.cgi?id=197698
- m_destructor->run(m_data.getUnsafe());
- }
-}
-
-ArrayBufferContents::ArrayBufferContents()
-{
- reset();
-}
-
-ArrayBufferContents::ArrayBufferContents(ArrayBufferContents&& other)
-{
- reset();
- other.transferTo(*this);
-}
-
-ArrayBufferContents::ArrayBufferContents(void* data, size_t sizeInBytes, ArrayBufferDestructorFunction&& destructor)
- : m_data(data, sizeInBytes)
- , m_sizeInBytes(sizeInBytes)
-{
- RELEASE_ASSERT(m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
- m_destructor = WTFMove(destructor);
-}
-
-ArrayBufferContents& ArrayBufferContents::operator=(ArrayBufferContents&& other)
-{
- other.transferTo(*this);
- return *this;
-}
-
-ArrayBufferContents::~ArrayBufferContents()
-{
- destroy();
-}
-
-void ArrayBufferContents::clear()
-{
- destroy();
- reset();
-}
-
-void ArrayBufferContents::destroy()
-{
- if (m_destructor) {
- // FIXME: We shouldn't use getUnsafe here: https://bugs.webkit.org/show_bug.cgi?id=197698
- m_destructor->run(m_data.getUnsafe());
- }
-}
-
-void ArrayBufferContents::reset()
-{
- m_data = nullptr;
- m_destructor = nullptr;
- m_shared = nullptr;
- m_sizeInBytes = 0;
-}
-
void ArrayBufferContents::tryAllocate(size_t numElements, unsigned elementByteSize, InitializationPolicy policy)
{
CheckedSize sizeInBytes = numElements;
@@ -143,17 +76,6 @@
m_destructor = nullptr;
}
-void ArrayBufferContents::transferTo(ArrayBufferContents& other)
-{
- other.clear();
- other.m_data = m_data;
- other.m_sizeInBytes = m_sizeInBytes;
- RELEASE_ASSERT(other.m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
- other.m_destructor = WTFMove(m_destructor);
- other.m_shared = m_shared;
- reset();
-}
-
void ArrayBufferContents::copyTo(ArrayBufferContents& other)
{
ASSERT(!other.m_data);
@@ -285,9 +207,6 @@
ArrayBuffer::ArrayBuffer(ArrayBufferContents&& contents)
: m_contents(WTFMove(contents))
- , m_pinCount(0)
- , m_isWasmMemory(false)
- , m_locked(false)
{
}
@@ -384,7 +303,7 @@
return true;
}
- m_contents.transferTo(result);
+ result = WTFMove(m_contents);
notifyDetaching(vm);
return true;
}
@@ -393,8 +312,7 @@
void ArrayBuffer::detach(VM& vm)
{
ASSERT(isWasmMemory());
- ArrayBufferContents unused;
- m_contents.transferTo(unused);
+ ArrayBufferContents unused = WTFMove(m_contents);
notifyDetaching(vm);
}
Modified: trunk/Source/_javascript_Core/runtime/ArrayBuffer.h (295376 => 295377)
--- trunk/Source/_javascript_Core/runtime/ArrayBuffer.h 2022-06-08 05:20:39 UTC (rev 295376)
+++ trunk/Source/_javascript_Core/runtime/ArrayBuffer.h 2022-06-08 07:26:02 UTC (rev 295377)
@@ -56,12 +56,23 @@
class JSArrayBuffer;
using ArrayBufferDestructorFunction = RefPtr<SharedTask<void(void*)>>;
-using PackedArrayBufferDestructorFunction = PackedRefPtr<SharedTask<void(void*)>>;
-class SharedArrayBufferContents : public ThreadSafeRefCounted<SharedArrayBufferContents> {
+class SharedArrayBufferContents final : public ThreadSafeRefCounted<SharedArrayBufferContents> {
public:
- SharedArrayBufferContents(void* data, size_t, ArrayBufferDestructorFunction&&);
- ~SharedArrayBufferContents();
+ SharedArrayBufferContents(void* data, size_t size, ArrayBufferDestructorFunction&& destructor)
+ : m_data(data, size)
+ , m_destructor(WTFMove(destructor))
+ , m_sizeInBytes(size)
+ {
+ }
+
+ ~SharedArrayBufferContents()
+ {
+ if (m_destructor) {
+ // FIXME: we shouldn't use getUnsafe here https://bugs.webkit.org/show_bug.cgi?id=197698
+ m_destructor->run(m_data.getUnsafe());
+ }
+ }
void* data() const { return m_data.getMayBeNull(m_sizeInBytes); }
@@ -68,23 +79,42 @@
private:
using DataType = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>;
DataType m_data;
- PackedArrayBufferDestructorFunction m_destructor;
+ ArrayBufferDestructorFunction m_destructor;
size_t m_sizeInBytes;
};
-class ArrayBufferContents {
+class ArrayBufferContents final {
WTF_MAKE_NONCOPYABLE(ArrayBufferContents);
public:
- JS_EXPORT_PRIVATE ArrayBufferContents();
- JS_EXPORT_PRIVATE ArrayBufferContents(void* data, size_t sizeInBytes, ArrayBufferDestructorFunction&&);
+ ArrayBufferContents() = default;
+ ArrayBufferContents(void* data, size_t sizeInBytes, ArrayBufferDestructorFunction&& destructor)
+ : m_data(data, sizeInBytes)
+ , m_destructor(WTFMove(destructor))
+ , m_sizeInBytes(sizeInBytes)
+ {
+ RELEASE_ASSERT(m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE);
+ }
- JS_EXPORT_PRIVATE ArrayBufferContents(ArrayBufferContents&&);
- JS_EXPORT_PRIVATE ArrayBufferContents& operator=(ArrayBufferContents&&);
+ ArrayBufferContents(ArrayBufferContents&& other)
+ {
+ swap(other);
+ }
- JS_EXPORT_PRIVATE ~ArrayBufferContents();
+ ArrayBufferContents& operator=(ArrayBufferContents&& other)
+ {
+ ArrayBufferContents moved(WTFMove(other));
+ swap(moved);
+ return *this;
+ }
+
+ ~ArrayBufferContents()
+ {
+ if (m_destructor) {
+ // FIXME: We shouldn't use getUnsafe here: https://bugs.webkit.org/show_bug.cgi?id=197698
+ m_destructor->run(m_data.getUnsafe());
+ }
+ }
- JS_EXPORT_PRIVATE void clear();
-
explicit operator bool() { return !!m_data; }
void* data() const { return m_data.getMayBeNull(sizeInBytes()); }
@@ -93,9 +123,23 @@
bool isShared() const { return m_shared; }
+ void swap(ArrayBufferContents& other)
+ {
+ using std::swap;
+ swap(m_data, other.m_data);
+ swap(m_destructor, other.m_destructor);
+ swap(m_shared, other.m_shared);
+ swap(m_sizeInBytes, other.m_sizeInBytes);
+ }
+
private:
- void destroy();
- void reset();
+ void reset()
+ {
+ m_data = nullptr;
+ m_destructor = nullptr;
+ m_shared = nullptr;
+ m_sizeInBytes = 0;
+ }
friend class ArrayBuffer;
@@ -107,18 +151,17 @@
void tryAllocate(size_t numElements, unsigned elementByteSize, InitializationPolicy);
void makeShared();
- void transferTo(ArrayBufferContents&);
void copyTo(ArrayBufferContents&);
void shareWith(ArrayBufferContents&);
using DataType = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>;
- DataType m_data;
- PackedArrayBufferDestructorFunction m_destructor;
- PackedRefPtr<SharedArrayBufferContents> m_shared;
- size_t m_sizeInBytes;
+ DataType m_data { nullptr };
+ ArrayBufferDestructorFunction m_destructor { nullptr };
+ RefPtr<SharedArrayBufferContents> m_shared { nullptr };
+ size_t m_sizeInBytes { 0 };
};
-class ArrayBuffer : public GCIncomingRefCounted<ArrayBuffer> {
+class ArrayBuffer final : public GCIncomingRefCounted<ArrayBuffer> {
public:
JS_EXPORT_PRIVATE static Ref<ArrayBuffer> create(size_t numElements, unsigned elementByteSize);
JS_EXPORT_PRIVATE static Ref<ArrayBuffer> create(ArrayBuffer&);
@@ -188,11 +231,11 @@
public:
Weak<JSArrayBuffer> m_wrapper;
private:
- Checked<unsigned> m_pinCount;
- bool m_isWasmMemory;
+ Checked<unsigned> m_pinCount { 0 };
+ bool m_isWasmMemory { false };
// m_locked == true means that some API user fetched m_contents directly from a TypedArray object,
// the buffer is backed by a WebAssembly.Memory, or is a SharedArrayBuffer.
- bool m_locked;
+ bool m_locked { false };
};
void* ArrayBuffer::data()