LibJS: Port PrototypeObject::typed_this_value() to NonnullGCPtr

This commit is contained in:
Linus Groh 2023-04-13 20:13:29 +02:00 committed by Andreas Kling
parent a23dd88f61
commit 89503a0cfe
Notes: sideshowbarker 2024-07-17 02:59:43 +09:00
8 changed files with 15 additions and 15 deletions

View file

@ -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

View file

@ -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);

View file

@ -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.

View file

@ -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);

View file

@ -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:

View file

@ -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);

View file

@ -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);

View file

@ -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);