diff options
author | Linus Groh <mail@linusgroh.de> | 2022-12-13 20:49:50 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-14 09:59:45 +0000 |
commit | 947ea92bf6f02fc1f921f2b0e1d37b88d342f004 (patch) | |
tree | 98b2031ed9fe309ca8482d2ddb7d5812e04bb45f /Userland | |
parent | 91b0123eaf16afd8a36c3603535860385e75bd81 (diff) | |
download | serenity-947ea92bf6f02fc1f921f2b0e1d37b88d342f004.zip |
LibJS: Convert ArrayBuffer::create() to NonnullGCPtr
Diffstat (limited to 'Userland')
7 files changed, 15 insertions, 15 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp index 66d59f844b..77394e8a2c 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp @@ -11,23 +11,23 @@ namespace JS { -ThrowCompletionOr<ArrayBuffer*> ArrayBuffer::create(Realm& realm, size_t byte_length) +ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> ArrayBuffer::create(Realm& realm, size_t byte_length) { auto buffer = ByteBuffer::create_zeroed(byte_length); if (buffer.is_error()) return realm.vm().throw_completion<RangeError>(ErrorType::NotEnoughMemoryToAllocate, byte_length); - return realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), *realm.intrinsics().array_buffer_prototype()); + return NonnullGCPtr { *realm.heap().allocate<ArrayBuffer>(realm, buffer.release_value(), *realm.intrinsics().array_buffer_prototype()) }; } -ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer buffer) +NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer buffer) { - return realm.heap().allocate<ArrayBuffer>(realm, move(buffer), *realm.intrinsics().array_buffer_prototype()); + return *realm.heap().allocate<ArrayBuffer>(realm, move(buffer), *realm.intrinsics().array_buffer_prototype()); } -ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer* buffer) +NonnullGCPtr<ArrayBuffer> ArrayBuffer::create(Realm& realm, ByteBuffer* buffer) { - return realm.heap().allocate<ArrayBuffer>(realm, buffer, *realm.intrinsics().array_buffer_prototype()); + return *realm.heap().allocate<ArrayBuffer>(realm, buffer, *realm.intrinsics().array_buffer_prototype()); } ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h index 09fc873947..16158e7e7d 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h @@ -25,9 +25,9 @@ class ArrayBuffer : public Object { JS_OBJECT(ArrayBuffer, Object); public: - static ThrowCompletionOr<ArrayBuffer*> create(Realm&, size_t); - static ArrayBuffer* create(Realm&, ByteBuffer); - static ArrayBuffer* create(Realm&, ByteBuffer*); + static ThrowCompletionOr<NonnullGCPtr<ArrayBuffer>> create(Realm&, size_t); + static NonnullGCPtr<ArrayBuffer> create(Realm&, ByteBuffer); + static NonnullGCPtr<ArrayBuffer> create(Realm&, ByteBuffer*); virtual ~ArrayBuffer() override = default; diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 976dec4180..f0de705e98 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -424,13 +424,13 @@ void TypedArrayBase::visit_edges(Visitor& visitor) ThrowCompletionOr<ClassName*> ClassName::create(Realm& realm, u32 length, FunctionObject& new_target) \ { \ auto* prototype = TRY(get_prototype_from_constructor(realm.vm(), new_target, &Intrinsics::snake_name##_prototype)); \ - auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ + auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ return realm.heap().allocate<ClassName>(realm, *prototype, length, *array_buffer); \ } \ \ ThrowCompletionOr<ClassName*> ClassName::create(Realm& realm, u32 length) \ { \ - auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ + auto array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ return create(realm, length, *array_buffer); \ } \ \ diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 1e78969d21..37edb0b28c 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -84,7 +84,7 @@ JS::Promise* SubtleCrypto::digest(DeprecatedString const& algorithm, JS::Handle< return promise; } - auto* result = JS::ArrayBuffer::create(realm, result_buffer.release_value()); + auto result = JS::ArrayBuffer::create(realm, result_buffer.release_value()); // 9. Resolve promise with result. promise->fulfill(result); diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp index fab0a4b274..3624e03c28 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp @@ -39,7 +39,7 @@ JS::Uint8Array* TextEncoder::encode(DeprecatedString const& input) const auto byte_buffer = input.to_byte_buffer(); auto array_length = byte_buffer.size(); - auto* array_buffer = JS::ArrayBuffer::create(realm(), move(byte_buffer)); + auto array_buffer = JS::ArrayBuffer::create(realm(), move(byte_buffer)); return JS::Uint8Array::create(realm(), array_length, *array_buffer); } diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp index 180b834457..485ec4d364 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp @@ -266,7 +266,7 @@ JS::Promise* Blob::array_buffer() promise->reject(buffer_result.release_error().value().release_value()); return promise; } - auto* buffer = buffer_result.release_value(); + auto buffer = buffer_result.release_value(); buffer->buffer().overwrite(0, m_byte_buffer.data(), m_byte_buffer.size()); // 4. Return the result of transforming promise by a fulfillment handler that returns a new ArrayBuffer whose contents are its first argument. diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp index 0bf52aff15..854852f096 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp @@ -50,7 +50,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter) if (!memory) return JS::js_undefined(); - auto* array_buffer = JS::ArrayBuffer::create(realm, &memory->data()); + auto array_buffer = JS::ArrayBuffer::create(realm, &memory->data()); array_buffer->set_detach_key(JS::PrimitiveString::create(vm, "WebAssembly.Memory")); return array_buffer; } |