Skip to content

Commit

Permalink
LibJS: Port PrototypeObject::typed_this_object() to NonnullGCPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
linusg authored and awesomekling committed Apr 14, 2023
1 parent 15360e5 commit a23dd88
Show file tree
Hide file tree
Showing 36 changed files with 491 additions and 491 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)

// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));

// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
Expand Down Expand Up @@ -102,7 +102,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)

// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));

// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
Expand Down Expand Up @@ -155,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)

// 1. Let O be the this value.
// 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));

// 3. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor()));
Expand Down
34 changes: 17 additions & 17 deletions Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_date)
new_date = time_clip(utc_time(new_date));

// 7. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 8. Return u.
Expand Down Expand Up @@ -435,7 +435,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_full_year)
new_date = time_clip(utc_time(new_date));

// 8. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 9. Return u.
Expand Down Expand Up @@ -487,7 +487,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_hours)
date = time_clip(utc_time(date));

// 13. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(date);

// 14. Return u.
Expand Down Expand Up @@ -522,7 +522,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_milliseconds)
date = time_clip(utc_time(date));

// 7. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(date);

// 8. Return u.
Expand Down Expand Up @@ -569,7 +569,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_minutes)
date = time_clip(utc_time(date));

// 11. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(date);

// 12. Return u.
Expand Down Expand Up @@ -609,7 +609,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_month)
new_date = time_clip(utc_time(new_date));

// 9. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 10. Return u.
Expand Down Expand Up @@ -650,7 +650,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_seconds)
new_date = time_clip(utc_time(new_date));

// 9. Set the [[DateValue]] internal slot of this Date object to u.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 10. Return u.
Expand All @@ -670,7 +670,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_time)
time = time_clip(time);

// 4. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(time);

// 5. Return v.
Expand Down Expand Up @@ -701,7 +701,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_date)
new_date = time_clip(new_date);

// 6. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 7. Return v.
Expand Down Expand Up @@ -736,7 +736,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_full_year)
new_date = time_clip(new_date);

// 8. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 9. Return v.
Expand Down Expand Up @@ -785,7 +785,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_hours)
date = time_clip(date);

// 12. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(date);

// 13. Return v.
Expand Down Expand Up @@ -817,7 +817,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_milliseconds)
date = time_clip(date);

// 6. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(date);

// 7. Return v.
Expand Down Expand Up @@ -861,7 +861,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_minutes)
date = time_clip(date);

// 10. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(date);

// 11. Return v.
Expand Down Expand Up @@ -898,7 +898,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_month)
new_date = time_clip(new_date);

// 8. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 9. Return v.
Expand Down Expand Up @@ -936,7 +936,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_utc_seconds)
new_date = time_clip(new_date);

// 8. Set the [[DateValue]] internal slot of this Date object to v.
auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));
this_object->set_date_value(new_date);

// 9. Return v.
Expand All @@ -962,7 +962,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
// 21.4.4.36 Date.prototype.toISOString ( ), https://tc39.es/ecma262/#sec-date.prototype.toisostring
JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
{
auto* this_object = TRY(typed_this_object(vm));
auto this_object = TRY(typed_this_object(vm));

if (!Value(this_object->date_value()).is_finite_number())
return vm.throw_completion<RangeError>(ErrorType::InvalidTimeValue);
Expand Down Expand Up @@ -1298,7 +1298,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year)
// 3. Let y be ? ToNumber(year).
auto year = TRY(vm.argument(0).to_number(vm)).as_double();

auto* this_object = MUST(typed_this_object(vm));
auto this_object = MUST(typed_this_object(vm));

// 4. If y is NaN, then
if (isnan(year)) {
Expand Down
12 changes: 6 additions & 6 deletions Userland/Libraries/LibJS/Runtime/DisposableStackPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::disposed_getter)
{
// 1. Let disposableStack be the this value.
// 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]).
auto* disposable_stack = TRY(typed_this_object(vm));
auto disposable_stack = TRY(typed_this_object(vm));

// 3. If disposableStack.[[DisposableState]] is disposed, return true.
if (disposable_stack->disposable_state() == DisposableStack::DisposableState::Disposed)
Expand All @@ -59,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::dispose)
{
// 1. Let disposableStack be the this value.
// 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]).
auto* disposable_stack = TRY(typed_this_object(vm));
auto disposable_stack = TRY(typed_this_object(vm));

// 3. If disposableStack.[[DisposableState]] is disposed, return undefined.
if (disposable_stack->disposable_state() == DisposableStack::DisposableState::Disposed)
Expand All @@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::use)

// 1. Let disposableStack be the this value.
// 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]).
auto* disposable_stack = TRY(typed_this_object(vm));
auto disposable_stack = TRY(typed_this_object(vm));

// 3. If disposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception.
if (disposable_stack->disposable_state() == DisposableStack::DisposableState::Disposed)
Expand Down Expand Up @@ -120,7 +120,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::adopt)

// 1. Let disposableStack be the this value.
// 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]).
auto* disposable_stack = TRY(typed_this_object(vm));
auto disposable_stack = TRY(typed_this_object(vm));

// 3. If disposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception.
if (disposable_stack->disposable_state() == DisposableStack::DisposableState::Disposed)
Expand Down Expand Up @@ -161,7 +161,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::defer)

// 1. Let disposableStack be the this value.
// 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]).
auto* disposable_stack = TRY(typed_this_object(vm));
auto disposable_stack = TRY(typed_this_object(vm));

// 3. If disposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception.
if (disposable_stack->disposable_state() == DisposableStack::DisposableState::Disposed)
Expand All @@ -183,7 +183,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisposableStackPrototype::move_)
{
// 1. Let disposableStack be the this value.
// 2. Perform ? RequireInternalSlot(disposableStack, [[DisposableState]]).
auto* disposable_stack = TRY(typed_this_object(vm));
auto disposable_stack = TRY(typed_this_object(vm));

// 3. If disposableStack.[[DisposableState]] is disposed, throw a ReferenceError exception.
if (disposable_stack->disposable_state() == DisposableStack::DisposableState::Disposed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::cleanup_some)

// 1. Let finalizationRegistry be the this value.
// 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]).
auto* finalization_registry = TRY(typed_this_object(vm));
auto finalization_registry = TRY(typed_this_object(vm));

// 3. If callback is present and IsCallable(callback) is false, throw a TypeError exception.
if (vm.argument_count() > 0 && !callback.is_function())
Expand All @@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::register_)

// 1. Let finalizationRegistry be the this value.
// 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]).
auto* finalization_registry = TRY(typed_this_object(vm));
auto finalization_registry = TRY(typed_this_object(vm));

// 3. If target is not an Object, throw a TypeError exception.
if (!can_be_held_weakly(target))
Expand Down Expand Up @@ -93,7 +93,7 @@ JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::unregister)

// 1. Let finalizationRegistry be the this value.
// 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]).
auto* finalization_registry = TRY(typed_this_object(vm));
auto finalization_registry = TRY(typed_this_object(vm));

// 3. If unregisterToken is not an Object, throw a TypeError exception.
if (!can_be_held_weakly(unregister_token))
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ ThrowCompletionOr<void> GeneratorPrototype::initialize(Realm& realm)
JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::next)
{
// 1. Return ? GeneratorResume(this value, value, empty).
auto* generator_object = TRY(typed_this_object(vm));
auto generator_object = TRY(typed_this_object(vm));
return generator_object->resume(vm, vm.argument(0), {});
}

// 27.5.1.3 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.return
JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::return_)
{
// 1. Let g be the this value.
auto* generator_object = TRY(typed_this_object(vm));
auto generator_object = TRY(typed_this_object(vm));

// 2. Let C be Completion Record { [[Type]]: return, [[Value]]: value, [[Target]]: empty }.
auto completion = Completion(Completion::Type::Return, vm.argument(0), {});
Expand All @@ -54,7 +54,7 @@ JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::return_)
JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::throw_)
{
// 1. Let g be the this value.
auto* generator_object = TRY(typed_this_object(vm));
auto generator_object = TRY(typed_this_object(vm));

// 2. Let C be ThrowCompletion(exception).
auto completion = throw_completion(vm.argument(0));
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)

// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(vm));
auto collator = TRY(typed_this_object(vm));

// 3. If collator.[[BoundCompare]] is undefined, then
if (!collator->bound_compare()) {
// a. Let F be a new built-in function object as defined in 10.3.3.1.
// b. Set F.[[Collator]] to collator.
auto function = CollatorCompareFunction::create(realm, *collator);
auto function = CollatorCompareFunction::create(realm, collator);

// c. Set collator.[[BoundCompare]] to F.
collator->set_bound_compare(function);
Expand All @@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)

// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(vm));
auto collator = TRY(typed_this_object(vm));

// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());
Expand Down
Loading

0 comments on commit a23dd88

Please sign in to comment.