1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 04:27:45 +00:00

LibJS+LibWeb: Reduce use of GlobalObject as an intermediary

- Prefer VM::current_realm() over GlobalObject::associated_realm()
- Prefer VM::heap() over GlobalObject::heap()
- Prefer Cell::vm() over Cell::global_object()
- Prefer Wrapper::vm() over Wrapper::global_object()
- Inline Realm::global_object() calls used to access intrinsics as they
  will later perform a direct lookup without going through the global
  object
This commit is contained in:
Linus Groh 2022-08-22 19:00:49 +01:00
parent e3895e6c80
commit b345a0acca
58 changed files with 157 additions and 231 deletions

View file

@ -40,8 +40,7 @@ ThrowCompletionOr<Value> AggregateErrorConstructor::call()
ThrowCompletionOr<Object*> AggregateErrorConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto* aggregate_error = TRY(ordinary_create_from_constructor<AggregateError>(vm, new_target, &GlobalObject::aggregate_error_prototype));

View file

@ -50,8 +50,7 @@ ThrowCompletionOr<Value> ArrayConstructor::call()
ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &GlobalObject::array_prototype));

View file

@ -34,7 +34,6 @@ void AsyncFromSyncIteratorPrototype::initialize(Realm& realm)
static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, PromiseCapability& promise_capability)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. NOTE: Because promiseCapability is derived from the intrinsic %Promise%, the calls to promiseCapability.[[Reject]] entailed by the use IfAbruptRejectPromise below are guaranteed not to throw.
// 2. Let done be Completion(IteratorComplete(result)).
@ -47,7 +46,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro
// 6. Let valueWrapper be PromiseResolve(%Promise%, value).
// 7. IfAbruptRejectPromise(valueWrapper, promiseCapability).
auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *global_object.promise_constructor(), value));
auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *realm.global_object().promise_constructor(), value));
// 8. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called:
auto unwrap = [done](VM& vm) -> ThrowCompletionOr<Value> {

View file

@ -986,8 +986,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
static ThrowCompletionOr<Intl::DateTimeFormat*> construct_date_time_format(VM& vm, Value locales, Value options)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
auto* date_time_format = TRY(construct(vm, *global_object.intl_date_time_format_constructor(), locales, options));
auto* date_time_format = TRY(construct(vm, *realm.global_object().intl_date_time_format_constructor(), locales, options));
return static_cast<Intl::DateTimeFormat*>(date_time_format);
}

View file

@ -318,8 +318,7 @@ void ECMAScriptFunctionObject::make_method(Object& home_object)
ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantiation(Interpreter* interpreter)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto& callee_context = vm.running_execution_context();
@ -780,8 +779,7 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi
Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
auto* bytecode_interpreter = Bytecode::Interpreter::current();
if (m_kind == FunctionKind::AsyncGenerator)
@ -865,7 +863,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
// AsyncFunctionBody : FunctionBody
else if (m_kind == FunctionKind::Async) {
// 1. Let promiseCapability be ! NewPromiseCapability(%Promise%).
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
// 2. Let declResult be Completion(FunctionDeclarationInstantiation(functionObject, argumentsList)).
auto declaration_result = function_declaration_instantiation(ast_interpreter);

View file

@ -247,7 +247,7 @@ ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(FlyString c
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].
auto& global_object = verify_cast<GlobalObject>(m_object_record->binding_object());
auto& global_object = m_object_record->binding_object();
// 3. Let hasProperty be ? HasOwnProperty(globalObject, N).
auto has_property = TRY(global_object.has_own_property(name));

View file

@ -532,7 +532,6 @@ static Optional<StringView> resolve_day_period(StringView locale, StringView cal
ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, Vector<PatternPartition> pattern_parts, double time, Unicode::CalendarPattern const* range_format_options)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let x be TimeClip(x).
time = time_clip(time);
@ -546,7 +545,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
auto const& data_locale = date_time_format.data_locale();
auto construct_number_format = [&](auto* options) -> ThrowCompletionOr<NumberFormat*> {
auto* number_format = TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, locale), options));
auto* number_format = TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale), options));
return static_cast<NumberFormat*>(number_format);
};
@ -849,7 +848,6 @@ ThrowCompletionOr<String> format_date_time(VM& vm, DateTimeFormat& date_time_for
ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date_time_format, double time)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let parts be ? PartitionDateTimePattern(dateTimeFormat, x).
auto parts = TRY(partition_date_time_pattern(vm, date_time_format, time));
@ -863,7 +861,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@ -1164,7 +1162,6 @@ ThrowCompletionOr<String> format_date_time_range(VM& vm, DateTimeFormat& date_ti
ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat& date_time_format, double start, double end)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, x, y).
auto parts = TRY(partition_date_time_range_pattern(vm, date_time_format, start, end));
@ -1178,7 +1175,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
// 4. For each Record { [[Type]], [[Value]], [[Source]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%ObjectPrototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -36,8 +36,8 @@ void DateTimeFormatFunction::initialize(Realm& realm)
ThrowCompletionOr<Value> DateTimeFormatFunction::call()
{
auto& global_object = this->global_object();
auto& vm = global_object.vm();
auto& vm = this->vm();
auto& realm = *vm.current_realm();
auto date = vm.argument(0);
@ -49,7 +49,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
// 3. If date is not provided or is undefined, then
if (date.is_undefined()) {
// a. Let x be ! Call(%Date.now%, undefined).
date_value = MUST(JS::call(vm, global_object.date_constructor_now_function(), js_undefined())).as_double();
date_value = MUST(JS::call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double();
}
// 4. Else,
else {

View file

@ -307,7 +307,6 @@ static String convert_number_format_pattern_to_duration_format_template(Unicode:
ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM& vm, DurationFormat const& duration_format, Temporal::DurationRecord const& duration)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let result be a new empty List.
Vector<PatternPartition> result;
@ -403,7 +402,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// o. Let nf be ? Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
// FIXME: durationFormat.[[NumberFormat]] is not a thing, the spec likely means 'nf' in this case
// p. Let num be ! FormatNumeric(durationFormat.[[NumberFormat]], value).
@ -432,7 +431,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
// t. Else,
else {
// i. Let pr be ? Construct(%PluralRules%, « durationFormat.[[Locale]] »).
auto* plural_rules = TRY(construct(vm, *global_object.intl_plural_rules_constructor(), js_string(vm, duration_format.locale())));
auto* plural_rules = TRY(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, duration_format.locale())));
// ii. Let prv be ! ResolvePlural(pr, value).
auto plurality = resolve_plural(static_cast<PluralRules&>(*plural_rules), value);
@ -480,7 +479,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// 3. Let lf be ? Construct(%ListFormat%, « durationFormat.[[Locale]] »).
auto* list_format = static_cast<Intl::ListFormat*>(TRY(construct(vm, *global_object.intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
auto* list_format = static_cast<Intl::ListFormat*>(TRY(construct(vm, *realm.global_object().intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
// so we try to hack something together from it that looks mostly right

View file

@ -204,7 +204,6 @@ String format_list(ListFormat const& list_format, Vector<String> const& list)
Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String> const& list)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
auto parts = create_parts_from_list(list_format, list);
@ -218,7 +217,7 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -908,7 +908,6 @@ String format_numeric(VM& vm, NumberFormat& number_format, MathematicalValue num
Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, MathematicalValue number)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let parts be ? PartitionNumberPattern(numberFormat, x).
// Note: Our implementation of PartitionNumberPattern does not throw.
@ -923,7 +922,7 @@ Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, Mathematical
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@ -1825,7 +1824,6 @@ ThrowCompletionOr<String> format_numeric_range(VM& vm, NumberFormat& number_form
ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& number_format, MathematicalValue start, MathematicalValue end)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y).
auto parts = TRY(partition_number_range_pattern(vm, number_format, move(start), move(end)));
@ -1839,7 +1837,7 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -244,7 +244,6 @@ ThrowCompletionOr<String> format_relative_time(VM& vm, RelativeTimeFormat& relat
ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit).
auto parts = TRY(partition_relative_time_pattern(vm, relative_time_format, value, unit));
@ -258,7 +257,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
// 4. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -79,7 +79,6 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatConstructor::supported_locales_of)
ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, RelativeTimeFormat& relative_time_format, Value locales_value, Value options_value)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
@ -139,11 +138,11 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
relative_time_format.set_numeric(numeric.as_string().string());
// 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »).
auto* number_format = MUST(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, locale)));
auto* number_format = MUST(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale)));
relative_time_format.set_number_format(static_cast<NumberFormat*>(number_format));
// 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
auto* plural_rules = MUST(construct(vm, *global_object.intl_plural_rules_constructor(), js_string(vm, locale)));
auto* plural_rules = MUST(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, locale)));
relative_time_format.set_plural_rules(static_cast<PluralRules*>(plural_rules));
// 21. Return relativeTimeFormat.

View file

@ -48,7 +48,6 @@ StringView Segmenter::segmenter_granularity_string() const
Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View const& string, double start_index, double end_index)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let len be the length of string.
auto length = string.length_in_code_units();
@ -63,7 +62,7 @@ Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View
VERIFY(start_index < end_index);
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
auto* result = Object::create(realm, global_object.object_prototype());
auto* result = Object::create(realm, realm.global_object().object_prototype());
// 6. Let segment be the substring of string from startIndex to endIndex.
auto segment = string.substring_view(start_index, end_index - start_index);

View file

@ -187,10 +187,9 @@ Completion async_iterator_close(VM& vm, Iterator const& iterator_record, Complet
Object* create_iterator_result_object(VM& vm, Value value, bool done)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let obj be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// 2. Perform ! CreateDataPropertyOrThrow(obj, "value", value).
MUST(object->create_data_property_or_throw(vm.names.value, value));

View file

@ -46,7 +46,6 @@ void JSONObject::initialize(Realm& realm)
ThrowCompletionOr<String> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
StringifyState state;
@ -102,7 +101,7 @@ ThrowCompletionOr<String> JSONObject::stringify_impl(VM& vm, Value value, Value
state.gap = String::empty();
}
auto* wrapper = Object::create(realm, global_object.object_prototype());
auto* wrapper = Object::create(realm, realm.global_object().object_prototype());
MUST(wrapper->create_data_property_or_throw(String::empty(), value));
return serialize_json_property(vm, state, String::empty(), wrapper);
}

View file

@ -369,9 +369,8 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
// NOTE: This has been flattened for readability, so some `else` branches in the
// spec text have been replaced with `continue`s in the loop below.
auto& global_object = this->global_object();
auto& vm = this->vm();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let ownKeys be ? O.[[OwnPropertyKeys]]().
auto own_keys = TRY(internal_own_property_keys());

View file

@ -67,14 +67,13 @@ ThrowCompletionOr<Value> ObjectConstructor::call()
ThrowCompletionOr<Object*> ObjectConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
if (&new_target != this)
return TRY(ordinary_create_from_constructor<Object>(vm, new_target, &GlobalObject::object_prototype));
auto value = vm.argument(0);
if (value.is_nullish())
return Object::create(realm, global_object.object_prototype());
return Object::create(realm, realm.global_object().object_prototype());
return value.to_object(vm);
}

View file

@ -58,8 +58,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / create_resolving_functions()]", this);
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 1. Let alreadyResolved be the Record { [[Value]]: false }.
auto* already_resolved = vm.heap().allocate_without_realm<AlreadyResolved>();

View file

@ -68,8 +68,7 @@ PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index,
ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 8. Set values[index] to x.
m_values.values()[m_index] = vm.argument(0);
@ -101,11 +100,10 @@ PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction
ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_element()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 9. Let obj be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled").
MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "fulfilled"sv)));
@ -143,11 +141,10 @@ PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(s
ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 9. Let obj be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, global_object.object_prototype());
auto* object = Object::create(realm, realm.global_object().object_prototype());
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected").
MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "rejected"sv)));
@ -185,8 +182,7 @@ PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, P
ThrowCompletionOr<Value> PromiseAnyRejectElementFunction::resolve_element()
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// 8. Set errors[index] to x.
m_values.values()[m_index] = vm.argument(0);

View file

@ -743,8 +743,7 @@ ThrowCompletionOr<MarkedVector<Value>> ProxyObject::internal_own_property_keys()
ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedVector<Value> arguments_list)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// A Proxy exotic object only has a [[Call]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Call]] internal method.
// TODO: We should be able to turn this into a VERIFY(), this must be checked at the call site.
@ -792,8 +791,7 @@ bool ProxyObject::has_constructor() const
ThrowCompletionOr<Object*> ProxyObject::internal_construct(MarkedVector<Value> arguments_list, FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
// A Proxy exotic object only has a [[Construct]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Construct]] internal method.
// TODO: We should be able to turn this into a VERIFY(), this must be checked at the call site.

View file

@ -86,7 +86,6 @@ Completion Reference::throw_reference_error(VM& vm) const
ThrowCompletionOr<Value> Reference::get_value(VM& vm) const
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. ReturnIfAbrupt(V).
// 2. If V is not a Reference Record, return V.
@ -119,11 +118,11 @@ ThrowCompletionOr<Value> Reference::get_value(VM& vm) const
auto string_value = m_base_value.as_string().get(vm, m_name);
if (string_value.has_value())
return *string_value;
base_obj = global_object.string_prototype();
base_obj = realm.global_object().string_prototype();
} else if (m_base_value.is_number())
base_obj = global_object.number_prototype();
base_obj = realm.global_object().number_prototype();
else if (m_base_value.is_boolean())
base_obj = global_object.boolean_prototype();
base_obj = realm.global_object().boolean_prototype();
else
base_obj = TRY(m_base_value.to_object(vm));

View file

@ -53,8 +53,7 @@ ThrowCompletionOr<Value> StringConstructor::call()
ThrowCompletionOr<Object*> StringConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto& realm = *global_object.associated_realm();
auto& realm = *vm.current_realm();
PrimitiveString* primitive_string;
if (!vm.argument_count())

View file

@ -64,14 +64,13 @@ Span<StringView const> available_calendars()
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, String const& identifier, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: IsBuiltinCalendar(identifier) is true.
VERIFY(is_builtin_calendar(identifier));
// 2. If newTarget is not provided, set newTarget to %Temporal.Calendar%.
if (!new_target)
new_target = global_object.temporal_calendar_constructor();
new_target = realm.global_object().temporal_calendar_constructor();
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
// 4. Set object.[[Identifier]] to identifier.
@ -886,10 +885,9 @@ u8 iso_day(Object& temporal_object)
ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& fields, Object const& additional_fields)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
auto* merged = Object::create(realm, global_object.object_prototype());
auto* merged = Object::create(realm, realm.global_object().object_prototype());
// 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key).
auto fields_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key));

View file

@ -327,7 +327,6 @@ ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(VM&
ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If ! IsValidDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception.
if (!is_valid_duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds))
@ -335,7 +334,7 @@ ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, doub
// 2. If newTarget is not present, set newTarget to %Temporal.Duration%.
if (!new_target)
new_target = global_object.temporal_duration_constructor();
new_target = realm.global_object().temporal_duration_constructor();
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Duration.prototype%", « [[InitializedTemporalDuration]], [[Years]], [[Months]], [[Weeks]], [[Days]], [[Hours]], [[Minutes]], [[Seconds]], [[Milliseconds]], [[Microseconds]], [[Nanoseconds]] »).
// 4. Set object.[[Years]] to (𝔽(years)).

View file

@ -53,7 +53,6 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds)
ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_nanoseconds, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: Type(epochNanoseconds) is BigInt.
@ -62,7 +61,7 @@ ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_
// 3. If newTarget is not present, set newTarget to %Temporal.Instant%.
if (!new_target)
new_target = global_object.temporal_instant_constructor();
new_target = realm.global_object().temporal_instant_constructor();
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »).
// 5. Set object.[[Nanoseconds]] to epochNanoseconds.

View file

@ -51,7 +51,6 @@ ISODateRecord create_iso_date_record(i32 year, u8 month, u8 day)
ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear is an integer.
// 2. Assert: isoMonth is an integer.
@ -68,7 +67,7 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_
// 7. If newTarget is not present, set newTarget to %Temporal.PlainDate%.
if (!new_target)
new_target = global_object.temporal_plain_date_constructor();
new_target = realm.global_object().temporal_plain_date_constructor();
// 8. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »).
// 9. Set object.[[ISOYear]] to isoYear.

View file

@ -228,7 +228,6 @@ ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
// 2. Assert: Type(calendar) is Object.
@ -249,7 +248,7 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
// 6. If newTarget is not present, set newTarget to %Temporal.PlainDateTime%.
if (!new_target)
new_target = global_object.temporal_plain_date_time_constructor();
new_target = realm.global_object().temporal_plain_date_time_constructor();
// 7. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDateTime.prototype%", « [[InitializedTemporalDateTime]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
// 8. Set object.[[ISOYear]] to isoYear.

View file

@ -145,7 +145,6 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Obje
ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoMonth, isoDay, and referenceISOYear are integers.
// 2. Assert: Type(calendar) is Object.
@ -160,7 +159,7 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
// 5. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%.
if (!new_target)
new_target = global_object.temporal_plain_month_day_constructor();
new_target = realm.global_object().temporal_plain_month_day_constructor();
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]], [[ISOMonth]], [[ISODay]], [[ISOYear]], [[Calendar]] »).
// 7. Set object.[[ISOMonth]] to isoMonth.

View file

@ -311,7 +311,6 @@ TemporalTime constrain_time(double hour, double minute, double second, double mi
ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers.
@ -321,7 +320,7 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u
// 3. If newTarget is not present, set newTarget to %Temporal.PlainTime%.
if (!new_target)
new_target = global_object.temporal_plain_time_constructor();
new_target = realm.global_object().temporal_plain_time_constructor();
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
// 5. Set object.[[ISOHour]] to hour.

View file

@ -186,7 +186,6 @@ ISOYearMonth balance_iso_year_month(double year, double month)
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: isoYear, isoMonth, and referenceISODay are integers.
// 2. Assert: Type(calendar) is Object.
@ -201,7 +200,7 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye
// 5. If newTarget is not present, set newTarget to %Temporal.PlainYearMonth%.
if (!new_target)
new_target = global_object.temporal_plain_year_month_constructor();
new_target = realm.global_object().temporal_plain_year_month_constructor();
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainYearMonth.prototype%", « [[InitializedTemporalYearMonth]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »).
// 7. Set object.[[ISOYear]] to isoYear.

View file

@ -66,11 +66,10 @@ String default_time_zone()
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, String const& identifier, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%.
if (!new_target)
new_target = global_object.temporal_time_zone_constructor();
new_target = realm.global_object().temporal_time_zone_constructor();
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(vm, *new_target, &GlobalObject::temporal_time_zone_prototype));

View file

@ -268,14 +268,13 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true.
VERIFY(is_valid_epoch_nanoseconds(epoch_nanoseconds));
// 2. If newTarget is not present, set newTarget to %Temporal.ZonedDateTime%.
if (!new_target)
new_target = global_object.temporal_zoned_date_time_constructor();
new_target = realm.global_object().temporal_zoned_date_time_constructor();
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.ZonedDateTime.prototype%", « [[InitializedTemporalZonedDateTime]], [[Nanoseconds]], [[TimeZone]], [[Calendar]] »).
// 4. Set object.[[Nanoseconds]] to epochNanoseconds.

View file

@ -129,7 +129,6 @@ template<typename T>
static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(VM& vm, TypedArray<T>& dest_array, TypedArrayBase& src_array)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let srcData be srcArray.[[ViewedArrayBuffer]].
auto* src_data = src_array.viewed_array_buffer();
@ -169,7 +168,7 @@ static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(VM& vm, T
// 11. Else,
else {
// a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
data = TRY(allocate_array_buffer(vm, *global_object.array_buffer_constructor(), byte_length.value()));
data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length.value()));
// b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
if (src_data->is_detached())
@ -225,7 +224,6 @@ template<typename T>
static ThrowCompletionOr<void> allocate_typed_array_buffer(VM& vm, TypedArray<T>& typed_array, size_t length)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// Enforce 2GB "Excessive Length" limit
if (length > NumericLimits<i32>::max() / sizeof(T))
@ -242,7 +240,7 @@ static ThrowCompletionOr<void> allocate_typed_array_buffer(VM& vm, TypedArray<T>
auto byte_length = element_size * length;
// 4. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength).
auto* data = TRY(allocate_array_buffer(vm, *global_object.array_buffer_constructor(), byte_length));
auto* data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length));
// 5. Set O.[[ViewedArrayBuffer]] to data.
typed_array.set_viewed_array_buffer(data);
@ -345,11 +343,10 @@ ThrowCompletionOr<TypedArrayBase*> typed_array_create(VM& vm, FunctionObject& co
ThrowCompletionOr<TypedArrayBase*> typed_array_create_same_type(VM& vm, TypedArrayBase const& exemplar, MarkedVector<Value> arguments)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Assert: exemplar is an Object that has [[TypedArrayName]] and [[ContentType]] internal slots.
// 2. Let constructor be the intrinsic object listed in column one of Table 63 (points to Table 72) for exemplar.[[TypedArrayName]].
auto* constructor = (global_object.*exemplar.intrinsic_constructor())();
auto* constructor = (realm.global_object().*exemplar.intrinsic_constructor())();
// 3. Let result be ? TypedArrayCreate(constructor, argumentList).
auto* result = TRY(typed_array_create(vm, *constructor, move(arguments)));
@ -514,8 +511,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
ThrowCompletionOr<Object*> ConstructorName::construct(FunctionObject& new_target) \
{ \
auto& vm = this->vm(); \
auto& global_object = this->global_object(); \
auto& realm = *global_object.associated_realm(); \
auto& realm = *vm.current_realm(); \
\
if (vm.argument_count() == 0) \
return TRY(ClassName::create(realm, 0, new_target)); \

View file

@ -144,10 +144,9 @@ static ThrowCompletionOr<void> for_each_item_from_last(VM& vm, String const& nam
static ThrowCompletionOr<TypedArrayBase*> typed_array_species_create(VM& vm, TypedArrayBase const& exemplar, MarkedVector<Value> arguments)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let defaultConstructor be the intrinsic object listed in column one of Table 72 for exemplar.[[TypedArrayName]].
auto* default_constructor = (global_object.*exemplar.intrinsic_constructor())();
auto* default_constructor = (realm.global_object().*exemplar.intrinsic_constructor())();
// 2. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
auto* constructor = TRY(species_constructor(vm, exemplar, *default_constructor));