mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Convert ArrayBuffer::create() to NonnullGCPtr
This commit is contained in:
parent
91b0123eaf
commit
947ea92bf6
Notes:
sideshowbarker
2024-07-17 03:18:45 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/947ea92bf6 Pull-request: https://github.com/SerenityOS/serenity/pull/16479 Reviewed-by: https://github.com/davidot ✅
7 changed files with 15 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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); \
|
||||
} \
|
||||
\
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue