mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibJS: Port PrototypeObject::typed_this_value() to NonnullGCPtr
This commit is contained in:
parent
a23dd88f61
commit
89503a0cfe
Notes:
sideshowbarker
2024-07-17 02:59:43 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/89503a0cfe Pull-request: https://github.com/SerenityOS/serenity/pull/18346
|
@ -40,7 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
|||
|
||||
// 1. Let O be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
|
||||
auto* array_buffer_object = TRY(typed_this_value(vm));
|
||||
auto array_buffer_object = TRY(typed_this_value(vm));
|
||||
|
||||
// 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
|
||||
// FIXME: Check for shared buffer
|
||||
|
@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice)
|
|||
auto new_length = max(final - first, 0.0);
|
||||
|
||||
// 15. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
|
||||
auto* constructor = TRY(species_constructor(vm, *array_buffer_object, realm.intrinsics().array_buffer_constructor()));
|
||||
auto* constructor = TRY(species_constructor(vm, array_buffer_object, realm.intrinsics().array_buffer_constructor()));
|
||||
|
||||
// 16. Let new be ? Construct(ctor, « 𝔽(newLen) »).
|
||||
auto new_array_buffer = TRY(construct(vm, *constructor, Value(new_length)));
|
||||
|
@ -129,7 +129,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::byte_length_getter)
|
|||
{
|
||||
// 1. Let O be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
|
||||
auto* array_buffer_object = TRY(typed_this_value(vm));
|
||||
auto array_buffer_object = TRY(typed_this_value(vm));
|
||||
|
||||
// 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
|
||||
// FIXME: Check for shared buffer
|
||||
|
|
|
@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
|||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* iterator = TRY(typed_this_value(vm));
|
||||
auto iterator = TRY(typed_this_value(vm));
|
||||
auto target_array = iterator->array();
|
||||
if (target_array.is_undefined())
|
||||
return create_iterator_result_object(vm, js_undefined(), true);
|
||||
|
|
|
@ -58,7 +58,7 @@ static ThrowCompletionOr<Value> get_view_value(VM& vm, Value request_index, Valu
|
|||
{
|
||||
// 1. Perform ? RequireInternalSlot(view, [[DataView]]).
|
||||
// 2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
|
||||
auto* view = TRY(DataViewPrototype::typed_this_value(vm));
|
||||
auto view = TRY(DataViewPrototype::typed_this_value(vm));
|
||||
|
||||
// 3. Let getIndex be ? ToIndex(requestIndex).
|
||||
auto get_index = TRY(request_index.to_index(vm));
|
||||
|
@ -103,7 +103,7 @@ static ThrowCompletionOr<Value> set_view_value(VM& vm, Value request_index, Valu
|
|||
{
|
||||
// 1. Perform ? RequireInternalSlot(view, [[DataView]]).
|
||||
// 2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
|
||||
auto* view = TRY(DataViewPrototype::typed_this_value(vm));
|
||||
auto view = TRY(DataViewPrototype::typed_this_value(vm));
|
||||
|
||||
// 3. Let getIndex be ? ToIndex(requestIndex).
|
||||
auto get_index = TRY(request_index.to_index(vm));
|
||||
|
@ -160,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::buffer_getter)
|
|||
// 1. Let O be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(O, [[DataView]]).
|
||||
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
|
||||
auto* data_view = TRY(typed_this_value(vm));
|
||||
auto data_view = TRY(typed_this_value(vm));
|
||||
|
||||
// 4. Let buffer be O.[[ViewedArrayBuffer]].
|
||||
// 5. Return buffer.
|
||||
|
@ -173,7 +173,7 @@ JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::byte_length_getter)
|
|||
// 1. Let O be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(O, [[DataView]]).
|
||||
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
|
||||
auto* data_view = TRY(typed_this_value(vm));
|
||||
auto data_view = TRY(typed_this_value(vm));
|
||||
|
||||
// 4. Let buffer be O.[[ViewedArrayBuffer]].
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
|
@ -191,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::byte_offset_getter)
|
|||
// 1. Let O be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(O, [[DataView]]).
|
||||
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
|
||||
auto* data_view = TRY(typed_this_value(vm));
|
||||
auto data_view = TRY(typed_this_value(vm));
|
||||
|
||||
// 4. Let buffer be O.[[ViewedArrayBuffer]].
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
|
|
|
@ -34,7 +34,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next)
|
|||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* map_iterator = TRY(typed_this_value(vm));
|
||||
auto map_iterator = TRY(typed_this_value(vm));
|
||||
if (map_iterator->done())
|
||||
return create_iterator_result_object(vm, js_undefined(), true);
|
||||
|
||||
|
|
|
@ -47,12 +47,12 @@ public:
|
|||
}
|
||||
|
||||
// Use typed_this_value() when the spec does not coerce |this| value to an object.
|
||||
static ThrowCompletionOr<ObjectType*> typed_this_value(VM& vm)
|
||||
static ThrowCompletionOr<NonnullGCPtr<ObjectType>> typed_this_value(VM& vm)
|
||||
{
|
||||
auto this_value = vm.this_value();
|
||||
if (!this_value.is_object() || !is<ObjectType>(this_value.as_object()))
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, PrototypeType::display_name());
|
||||
return static_cast<ObjectType*>(&this_value.as_object());
|
||||
return static_cast<ObjectType&>(this_value.as_object());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -35,7 +35,7 @@ ThrowCompletionOr<void> RegExpStringIteratorPrototype::initialize(Realm& realm)
|
|||
JS_DEFINE_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next)
|
||||
{
|
||||
// For details, see the 'closure' of: https://tc39.es/ecma262/#sec-createregexpstringiterator
|
||||
auto* iterator = TRY(typed_this_value(vm));
|
||||
auto iterator = TRY(typed_this_value(vm));
|
||||
if (iterator->done())
|
||||
return create_iterator_result_object(vm, js_undefined(), true);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next)
|
|||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* set_iterator = TRY(typed_this_value(vm));
|
||||
auto set_iterator = TRY(typed_this_value(vm));
|
||||
if (set_iterator->done())
|
||||
return create_iterator_result_object(vm, js_undefined(), true);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ ThrowCompletionOr<void> StringIteratorPrototype::initialize(Realm& realm)
|
|||
// 22.1.5.1.1 %StringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next
|
||||
JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next)
|
||||
{
|
||||
auto* iterator = TRY(typed_this_value(vm));
|
||||
auto iterator = TRY(typed_this_value(vm));
|
||||
if (iterator->done())
|
||||
return create_iterator_result_object(vm, js_undefined(), true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue