From 50428ea8d21045bbc3c5584a16496cff4a38fdc5 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 27 Aug 2022 00:54:55 +0100 Subject: [PATCH] LibJS: Move intrinsics to the realm Intrinsics, i.e. mostly constructor and prototype objects, but also things like empty and new object shape now live on a new heap-allocated JS::Intrinsics object, thus completing the long journey of taking all the magic away from the global object. This represents the Realm's [[Intrinsics]] slot in the spec and matches its existing [[GlobalObject]] / [[GlobalEnv]] slots in terms of architecture. In the majority of cases it should now be possibly to fully allocate a regular object without the global object existing, and in fact that's what we do now - the realm is allocated before the global object, and the intrinsics between both :^) --- .../LibWeb/WrapperGenerator/IDLGenerators.cpp | 20 +- Tests/LibWasm/test-wasm.cpp | 2 +- .../Spreadsheet/JSIntegration.cpp | 6 +- Userland/Libraries/LibJS/AST.cpp | 11 +- Userland/Libraries/LibJS/Bytecode/Op.cpp | 4 +- Userland/Libraries/LibJS/CMakeLists.txt | 1 + .../LibJS/Contrib/Test262/IsHTMLDDA.cpp | 4 +- Userland/Libraries/LibJS/CyclicModule.cpp | 4 +- Userland/Libraries/LibJS/Forward.h | 22 ++ .../LibJS/Runtime/AbstractOperations.cpp | 12 +- .../LibJS/Runtime/AbstractOperations.h | 4 +- .../LibJS/Runtime/AggregateError.cpp | 4 +- .../Runtime/AggregateErrorConstructor.cpp | 6 +- .../LibJS/Runtime/AggregateErrorPrototype.cpp | 4 +- .../LibJS/Runtime/ArgumentsObject.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Array.cpp | 2 +- .../Libraries/LibJS/Runtime/ArrayBuffer.cpp | 10 +- .../LibJS/Runtime/ArrayBufferConstructor.cpp | 4 +- .../LibJS/Runtime/ArrayBufferPrototype.cpp | 4 +- .../LibJS/Runtime/ArrayConstructor.cpp | 6 +- .../Libraries/LibJS/Runtime/ArrayIterator.cpp | 2 +- .../LibJS/Runtime/ArrayIteratorPrototype.cpp | 2 +- .../LibJS/Runtime/ArrayPrototype.cpp | 6 +- .../LibJS/Runtime/AsyncFromSyncIterator.cpp | 2 +- .../AsyncFromSyncIteratorPrototype.cpp | 10 +- .../Runtime/AsyncFunctionConstructor.cpp | 4 +- .../Runtime/AsyncFunctionDriverWrapper.cpp | 2 +- .../LibJS/Runtime/AsyncFunctionPrototype.cpp | 2 +- .../AsyncGeneratorFunctionConstructor.cpp | 4 +- .../AsyncGeneratorFunctionPrototype.cpp | 4 +- .../LibJS/Runtime/AsyncGeneratorPrototype.cpp | 2 +- .../LibJS/Runtime/AsyncIteratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/AtomicsObject.cpp | 2 +- .../LibJS/Runtime/BigIntConstructor.cpp | 4 +- .../Libraries/LibJS/Runtime/BigIntObject.cpp | 4 +- .../LibJS/Runtime/BigIntPrototype.cpp | 4 +- .../LibJS/Runtime/BooleanConstructor.cpp | 6 +- .../Libraries/LibJS/Runtime/BooleanObject.cpp | 2 +- .../LibJS/Runtime/BooleanPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/Completion.cpp | 2 +- .../Libraries/LibJS/Runtime/ConsoleObject.cpp | 2 +- Userland/Libraries/LibJS/Runtime/DataView.cpp | 2 +- .../LibJS/Runtime/DataViewConstructor.cpp | 6 +- .../LibJS/Runtime/DataViewPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Date.cpp | 2 +- .../LibJS/Runtime/DateConstructor.cpp | 6 +- .../Libraries/LibJS/Runtime/DatePrototype.cpp | 4 +- .../Runtime/ECMAScriptFunctionObject.cpp | 18 +- Userland/Libraries/LibJS/Runtime/Error.cpp | 38 +- .../LibJS/Runtime/ErrorConstructor.cpp | 108 ++--- .../LibJS/Runtime/ErrorPrototype.cpp | 4 +- .../FinalizationRegistryConstructor.cpp | 6 +- .../Runtime/FinalizationRegistryPrototype.cpp | 2 +- .../LibJS/Runtime/FunctionConstructor.cpp | 20 +- .../LibJS/Runtime/FunctionPrototype.cpp | 2 +- .../Runtime/GeneratorFunctionConstructor.cpp | 4 +- .../Runtime/GeneratorFunctionPrototype.cpp | 4 +- .../LibJS/Runtime/GeneratorObject.cpp | 4 +- .../LibJS/Runtime/GeneratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/GlobalObject.cpp | 317 ++++----------- .../Libraries/LibJS/Runtime/GlobalObject.h | 145 ------- .../Runtime/Intl/CollatorCompareFunction.cpp | 2 +- .../Runtime/Intl/CollatorConstructor.cpp | 6 +- .../LibJS/Runtime/Intl/CollatorPrototype.cpp | 4 +- .../LibJS/Runtime/Intl/DateTimeFormat.cpp | 6 +- .../Intl/DateTimeFormatConstructor.cpp | 6 +- .../Runtime/Intl/DateTimeFormatFunction.cpp | 4 +- .../Runtime/Intl/DateTimeFormatPrototype.cpp | 6 +- .../LibJS/Runtime/Intl/DisplayNames.cpp | 2 +- .../Runtime/Intl/DisplayNamesConstructor.cpp | 6 +- .../Runtime/Intl/DisplayNamesPrototype.cpp | 4 +- .../LibJS/Runtime/Intl/DurationFormat.cpp | 6 +- .../Intl/DurationFormatConstructor.cpp | 6 +- .../Runtime/Intl/DurationFormatPrototype.cpp | 6 +- .../Libraries/LibJS/Runtime/Intl/Intl.cpp | 22 +- .../LibJS/Runtime/Intl/ListFormat.cpp | 2 +- .../Runtime/Intl/ListFormatConstructor.cpp | 6 +- .../Runtime/Intl/ListFormatPrototype.cpp | 4 +- .../Libraries/LibJS/Runtime/Intl/Locale.cpp | 2 +- .../LibJS/Runtime/Intl/LocaleConstructor.cpp | 8 +- .../LibJS/Runtime/Intl/LocalePrototype.cpp | 6 +- .../LibJS/Runtime/Intl/NumberFormat.cpp | 4 +- .../Runtime/Intl/NumberFormatConstructor.cpp | 6 +- .../Runtime/Intl/NumberFormatFunction.cpp | 2 +- .../Runtime/Intl/NumberFormatPrototype.cpp | 4 +- .../Runtime/Intl/PluralRulesConstructor.cpp | 6 +- .../Runtime/Intl/PluralRulesPrototype.cpp | 4 +- .../LibJS/Runtime/Intl/RelativeTimeFormat.cpp | 2 +- .../Intl/RelativeTimeFormatConstructor.cpp | 10 +- .../Intl/RelativeTimeFormatPrototype.cpp | 4 +- .../LibJS/Runtime/Intl/SegmentIterator.cpp | 2 +- .../Runtime/Intl/SegmentIteratorPrototype.cpp | 2 +- .../LibJS/Runtime/Intl/Segmenter.cpp | 2 +- .../Runtime/Intl/SegmenterConstructor.cpp | 6 +- .../LibJS/Runtime/Intl/SegmenterPrototype.cpp | 4 +- .../Libraries/LibJS/Runtime/Intl/Segments.cpp | 2 +- .../LibJS/Runtime/Intl/SegmentsPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/Intrinsics.cpp | 368 ++++++++++++++++++ Userland/Libraries/LibJS/Runtime/Intrinsics.h | 163 ++++++++ .../LibJS/Runtime/IteratorOperations.cpp | 2 +- .../LibJS/Runtime/IteratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/JSONObject.cpp | 8 +- Userland/Libraries/LibJS/Runtime/Map.cpp | 2 +- .../LibJS/Runtime/MapConstructor.cpp | 6 +- .../Libraries/LibJS/Runtime/MapIterator.cpp | 2 +- .../LibJS/Runtime/MapIteratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/MapPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/MathObject.cpp | 2 +- .../LibJS/Runtime/ModuleNamespaceObject.cpp | 2 +- .../LibJS/Runtime/NativeFunction.cpp | 10 +- .../LibJS/Runtime/NumberConstructor.cpp | 13 +- .../Libraries/LibJS/Runtime/NumberObject.cpp | 2 +- .../LibJS/Runtime/NumberPrototype.cpp | 4 +- Userland/Libraries/LibJS/Runtime/Object.cpp | 12 +- .../LibJS/Runtime/ObjectConstructor.cpp | 12 +- Userland/Libraries/LibJS/Runtime/Promise.cpp | 2 +- .../LibJS/Runtime/PromiseConstructor.cpp | 6 +- .../LibJS/Runtime/PromisePrototype.cpp | 6 +- .../PromiseResolvingElementFunctions.cpp | 12 +- .../Runtime/PromiseResolvingFunction.cpp | 2 +- .../LibJS/Runtime/PropertyDescriptor.cpp | 2 +- .../LibJS/Runtime/ProxyConstructor.cpp | 4 +- .../Libraries/LibJS/Runtime/ProxyObject.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Realm.cpp | 14 +- Userland/Libraries/LibJS/Runtime/Realm.h | 13 +- .../Libraries/LibJS/Runtime/Reference.cpp | 6 +- .../Libraries/LibJS/Runtime/ReflectObject.cpp | 2 +- .../LibJS/Runtime/RegExpConstructor.cpp | 4 +- .../Libraries/LibJS/Runtime/RegExpObject.cpp | 4 +- .../LibJS/Runtime/RegExpPrototype.cpp | 10 +- .../LibJS/Runtime/RegExpStringIterator.cpp | 2 +- .../Runtime/RegExpStringIteratorPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Set.cpp | 4 +- .../LibJS/Runtime/SetConstructor.cpp | 6 +- .../Libraries/LibJS/Runtime/SetIterator.cpp | 2 +- .../LibJS/Runtime/SetIteratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/SetPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/ShadowRealm.cpp | 4 +- .../LibJS/Runtime/ShadowRealmConstructor.cpp | 6 +- .../LibJS/Runtime/ShadowRealmPrototype.cpp | 2 +- .../LibJS/Runtime/StringConstructor.cpp | 6 +- .../LibJS/Runtime/StringIterator.cpp | 2 +- .../LibJS/Runtime/StringIteratorPrototype.cpp | 2 +- .../LibJS/Runtime/StringPrototype.cpp | 4 +- .../LibJS/Runtime/SymbolConstructor.cpp | 4 +- .../Libraries/LibJS/Runtime/SymbolObject.cpp | 2 +- .../LibJS/Runtime/SymbolPrototype.cpp | 2 +- .../LibJS/Runtime/Temporal/Calendar.cpp | 6 +- .../Runtime/Temporal/CalendarConstructor.cpp | 4 +- .../Runtime/Temporal/CalendarPrototype.cpp | 2 +- .../LibJS/Runtime/Temporal/Duration.cpp | 4 +- .../Runtime/Temporal/DurationConstructor.cpp | 4 +- .../Runtime/Temporal/DurationPrototype.cpp | 2 +- .../LibJS/Runtime/Temporal/Instant.cpp | 4 +- .../Runtime/Temporal/InstantConstructor.cpp | 4 +- .../Runtime/Temporal/InstantPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/Temporal/Now.cpp | 2 +- .../LibJS/Runtime/Temporal/PlainDate.cpp | 4 +- .../Runtime/Temporal/PlainDateConstructor.cpp | 4 +- .../Runtime/Temporal/PlainDatePrototype.cpp | 4 +- .../LibJS/Runtime/Temporal/PlainDateTime.cpp | 4 +- .../Temporal/PlainDateTimeConstructor.cpp | 4 +- .../Temporal/PlainDateTimePrototype.cpp | 4 +- .../LibJS/Runtime/Temporal/PlainMonthDay.cpp | 4 +- .../Temporal/PlainMonthDayConstructor.cpp | 4 +- .../Temporal/PlainMonthDayPrototype.cpp | 4 +- .../LibJS/Runtime/Temporal/PlainTime.cpp | 4 +- .../Runtime/Temporal/PlainTimeConstructor.cpp | 4 +- .../Runtime/Temporal/PlainTimePrototype.cpp | 4 +- .../LibJS/Runtime/Temporal/PlainYearMonth.cpp | 4 +- .../Temporal/PlainYearMonthConstructor.cpp | 4 +- .../Temporal/PlainYearMonthPrototype.cpp | 4 +- .../LibJS/Runtime/Temporal/Temporal.cpp | 24 +- .../LibJS/Runtime/Temporal/TimeZone.cpp | 4 +- .../Runtime/Temporal/TimeZoneConstructor.cpp | 4 +- .../Runtime/Temporal/TimeZonePrototype.cpp | 2 +- .../LibJS/Runtime/Temporal/ZonedDateTime.cpp | 4 +- .../Temporal/ZonedDateTimeConstructor.cpp | 4 +- .../Temporal/ZonedDateTimePrototype.cpp | 4 +- .../Libraries/LibJS/Runtime/TypedArray.cpp | 268 ++++++------- Userland/Libraries/LibJS/Runtime/TypedArray.h | 2 +- .../LibJS/Runtime/TypedArrayConstructor.cpp | 4 +- .../LibJS/Runtime/TypedArrayPrototype.cpp | 6 +- Userland/Libraries/LibJS/Runtime/VM.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Value.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakMap.cpp | 2 +- .../LibJS/Runtime/WeakMapConstructor.cpp | 6 +- .../LibJS/Runtime/WeakMapPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakRef.cpp | 4 +- .../LibJS/Runtime/WeakRefConstructor.cpp | 8 +- .../LibJS/Runtime/WeakRefPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakSet.cpp | 2 +- .../LibJS/Runtime/WeakSetConstructor.cpp | 6 +- .../LibJS/Runtime/WeakSetPrototype.cpp | 2 +- .../LibJS/Runtime/WrappedFunction.cpp | 2 +- Userland/Libraries/LibJS/SyntheticModule.cpp | 2 +- .../LibWeb/Bindings/AudioConstructor.cpp | 2 +- .../LibWeb/Bindings/CSSNamespace.cpp | 2 +- .../LibWeb/Bindings/EventListenerWrapper.cpp | 2 +- .../LibWeb/Bindings/ImageConstructor.cpp | 2 +- .../LibWeb/Bindings/LocationConstructor.cpp | 2 +- .../LibWeb/Bindings/LocationPrototype.h | 2 +- .../LibWeb/Bindings/NavigatorConstructor.cpp | 2 +- .../LibWeb/Bindings/NavigatorPrototype.h | 2 +- .../LibWeb/Bindings/OptionConstructor.cpp | 2 +- .../LibWeb/Bindings/WindowConstructor.cpp | 2 +- .../WebAssemblyInstanceConstructor.cpp | 2 +- .../WebAssemblyInstanceObjectPrototype.h | 2 +- .../WebAssemblyMemoryConstructor.cpp | 2 +- .../WebAssembly/WebAssemblyMemoryPrototype.h | 2 +- .../WebAssemblyModuleConstructor.cpp | 2 +- .../WebAssembly/WebAssemblyModulePrototype.h | 2 +- .../LibWeb/WebAssembly/WebAssemblyObject.cpp | 2 +- .../WebAssemblyTableConstructor.cpp | 2 +- .../WebAssembly/WebAssemblyTablePrototype.h | 2 +- .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 2 +- Userland/Utilities/js.cpp | 11 +- 217 files changed, 1305 insertions(+), 1039 deletions(-) create mode 100644 Userland/Libraries/LibJS/Runtime/Intrinsics.cpp create mode 100644 Userland/Libraries/LibJS/Runtime/Intrinsics.h diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 6b3ff0fe32c..f3470bafc55 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -1572,7 +1572,7 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va auto dictionary_generator = scoped_generator.fork(); dictionary_generator.append(R"~~~( - auto* dictionary_object@recursion_depth@ = JS::Object::create(realm, realm.global_object().object_prototype()); + auto* dictionary_object@recursion_depth@ = JS::Object::create(realm, realm.intrinsics().object_prototype()); )~~~"); auto* current_dictionary = &interface.dictionaries.find(type.name)->value; @@ -2933,7 +2933,7 @@ using namespace Web::WebGL; namespace Web::Bindings { @constructor_class@::@constructor_class@(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } @@ -3220,7 +3220,7 @@ namespace Web::Bindings { // https://webidl.spec.whatwg.org/#es-DOMException-specialness // Object.getPrototypeOf(DOMException.prototype) === Error.prototype generator.append(R"~~~( - : Object(*realm.global_object().error_prototype()) + : Object(*realm.intrinsics().error_prototype()) )~~~"); } else if (!interface.parent_name.is_empty()) { generator.append(R"~~~( @@ -3228,7 +3228,7 @@ namespace Web::Bindings { )~~~"); } else { generator.append(R"~~~( - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) )~~~"); } @@ -3324,15 +3324,15 @@ void @prototype_class@::initialize(JS::Realm& realm) if (interface.indexed_property_getter.has_value()) { auto iterator_generator = generator.fork(); iterator_generator.append(R"~~~( - define_direct_property(*vm.well_known_symbol_iterator(), realm.global_object().array_prototype()->get_without_side_effects(vm.names.values), JS::Attribute::Configurable | JS::Attribute::Writable); + define_direct_property(*vm.well_known_symbol_iterator(), realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.values), JS::Attribute::Configurable | JS::Attribute::Writable); )~~~"); if (interface.value_iterator_type.has_value()) { iterator_generator.append(R"~~~( - define_direct_property(vm.names.entries, realm.global_object().array_prototype()->get_without_side_effects(vm.names.entries), default_attributes); - define_direct_property(vm.names.keys, realm.global_object().array_prototype()->get_without_side_effects(vm.names.keys), default_attributes); - define_direct_property(vm.names.values, realm.global_object().array_prototype()->get_without_side_effects(vm.names.values), default_attributes); - define_direct_property(vm.names.forEach, realm.global_object().array_prototype()->get_without_side_effects(vm.names.forEach), default_attributes); + define_direct_property(vm.names.entries, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.entries), default_attributes); + define_direct_property(vm.names.keys, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.keys), default_attributes); + define_direct_property(vm.names.values, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.values), default_attributes); + define_direct_property(vm.names.forEach, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.forEach), default_attributes); )~~~"); } } @@ -3789,7 +3789,7 @@ using namespace Web::WebGL; namespace Web::Bindings { @prototype_class@::@prototype_class@(JS::Realm& realm) - : Object(*realm.global_object().iterator_prototype()) + : Object(*realm.intrinsics().iterator_prototype()) { } diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 936f01a406b..5bb87724d80 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -50,7 +50,7 @@ public: static JS::ThrowCompletionOr create(JS::Realm& realm, Wasm::Module module, HashMap const& imports) { auto& vm = realm.vm(); - auto* instance = realm.heap().allocate(realm, *realm.global_object().object_prototype()); + auto* instance = realm.heap().allocate(realm, *realm.intrinsics().object_prototype()); instance->m_module = move(module); Wasm::Linker linker(*instance->m_module); linker.link(imports); diff --git a/Userland/Applications/Spreadsheet/JSIntegration.cpp b/Userland/Applications/Spreadsheet/JSIntegration.cpp index cbc4369780f..f5e2022fa0d 100644 --- a/Userland/Applications/Spreadsheet/JSIntegration.cpp +++ b/Userland/Applications/Spreadsheet/JSIntegration.cpp @@ -258,7 +258,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name) if (!position.has_value()) return JS::js_undefined(); - auto object = JS::Object::create(realm, realm.global_object().object_prototype()); + auto object = JS::Object::create(realm, realm.intrinsics().object_prototype()); object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.value().column)), JS::default_attributes); object->define_direct_property("row", JS::Value((unsigned)position.value().row), JS::default_attributes); @@ -284,7 +284,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position) auto position = current_cell->position(); - auto object = JS::Object::create(realm, realm.global_object().object_prototype()); + auto object = JS::Object::create(realm, realm.intrinsics().object_prototype()); object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.column)), JS::default_attributes); object->define_direct_property("row", JS::Value((unsigned)position.row), JS::default_attributes); @@ -370,7 +370,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound) } WorkbookObject::WorkbookObject(JS::Realm& realm, Workbook& workbook) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) , m_workbook(workbook) { } diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index ee6e5f07ae3..734eea302ab 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -442,7 +442,7 @@ Completion CallExpression::execute(Interpreter& interpreter) const auto& function = callee.as_function(); - if (&function == realm.global_object().eval_function() + if (&function == realm.intrinsics().eval_function() && callee_reference.is_environment_reference() && callee_reference.name().is_string() && callee_reference.name().as_string() == vm.names.eval.as_string()) { @@ -1829,9 +1829,8 @@ ThrowCompletionOr ClassExpression::class_definition_e class_private_environment->add_private_name({}, opt_private_name.release_value()); } - auto* proto_parent = vm.current_realm()->global_object().object_prototype(); - - auto* constructor_parent = vm.current_realm()->global_object().function_prototype(); + auto* proto_parent = realm.intrinsics().object_prototype(); + auto* constructor_parent = realm.intrinsics().function_prototype(); if (!m_super_class.is_null()) { vm.running_execution_context().lexical_environment = class_environment; @@ -3036,7 +3035,7 @@ Completion ObjectExpression::execute(Interpreter& interpreter) const auto& realm = *vm.current_realm(); // 1. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj. for (auto& property : m_properties) { @@ -3347,7 +3346,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const // Note: options_value is undefined by default. // 6. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 7. Let specifierString be Completion(ToString(specifier)). // 8. IfAbruptRejectPromise(specifierString, promiseCapability). diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 0e08621fd60..6bd57635e02 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -240,7 +240,7 @@ ThrowCompletionOr NewObject::execute_impl(Bytecode::Interpreter& interpret auto& vm = interpreter.vm(); auto& realm = *vm.current_realm(); - interpreter.accumulator() = Object::create(realm, realm.global_object().object_prototype()); + interpreter.accumulator() = Object::create(realm, realm.intrinsics().object_prototype()); return {}; } @@ -262,7 +262,7 @@ ThrowCompletionOr CopyObjectExcludingProperties::execute_impl(Bytecode::In auto* from_object = TRY(interpreter.reg(m_from_object).to_object(vm)); - auto* to_object = Object::create(realm, realm.global_object().object_prototype()); + auto* to_object = Object::create(realm, realm.intrinsics().object_prototype()); HashTable excluded_names; for (size_t i = 0; i < m_excluded_names_count; ++i) diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index bb5d1145350..19f0f282226 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -132,6 +132,7 @@ set(SOURCES Runtime/Intl/SegmentIterator.cpp Runtime/Intl/SegmentIteratorPrototype.cpp Runtime/Intl/SegmentsPrototype.cpp + Runtime/Intrinsics.cpp Runtime/IteratorOperations.cpp Runtime/IteratorPrototype.cpp Runtime/JSONObject.cpp diff --git a/Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp b/Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp index 68b6a37398f..c7fef161284 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp +++ b/Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,7 +11,7 @@ namespace JS::Test262 { IsHTMLDDA::IsHTMLDDA(Realm& realm) // NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it) - : NativeFunction("IsHTMLDDA", *realm.global_object().function_prototype()) + : NativeFunction("IsHTMLDDA", *realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp index 01018730850..61a9e84de34 100644 --- a/Userland/Libraries/LibJS/CyclicModule.cpp +++ b/Userland/Libraries/LibJS/CyclicModule.cpp @@ -201,7 +201,7 @@ ThrowCompletionOr CyclicModule::evaluate(VM& vm) // 6. Let capability be ! NewPromiseCapability(%Promise%). // 7. Set module.[[TopLevelCapability]] to capability. - m_top_level_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + m_top_level_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 8. Let result be Completion(InnerModuleEvaluation(module, stack, 0)). auto result = inner_module_evaluation(vm, stack, 0); @@ -442,7 +442,7 @@ void CyclicModule::execute_async_module(VM& vm) VERIFY(m_has_top_level_await); // 3. Let capability be ! NewPromiseCapability(%Promise%). - auto capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 4. Let fulfilledClosure be a new Abstract Closure with no parameters that captures module and performs the following steps when called: auto fulfilled_closure = [&](VM& vm) -> ThrowCompletionOr { diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h index 740a978e38f..d0e9ff5309d 100644 --- a/Userland/Libraries/LibJS/Forward.h +++ b/Userland/Libraries/LibJS/Forward.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -92,6 +93,14 @@ __JS_ENUMERATE(TimeZone, time_zone, TimeZonePrototype, TimeZoneConstructor) \ __JS_ENUMERATE(ZonedDateTime, zoned_date_time, ZonedDateTimePrototype, ZonedDateTimeConstructor) +#define JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS \ + __JS_ENUMERATE(AtomicsObject, atomics) \ + __JS_ENUMERATE(Intl::Intl, intl) \ + __JS_ENUMERATE(JSONObject, json) \ + __JS_ENUMERATE(MathObject, math) \ + __JS_ENUMERATE(ReflectObject, reflect) \ + __JS_ENUMERATE(Temporal::Temporal, temporal) + #define JS_ENUMERATE_ITERATOR_PROTOTYPES \ __JS_ENUMERATE(Iterator, iterator) \ __JS_ENUMERATE(ArrayIterator, array_iterator) \ @@ -161,6 +170,7 @@ class HandleImpl; class Heap; class HeapBlock; class Interpreter; +class Intrinsics; class Module; class NativeFunction; class ObjectEnvironment; @@ -205,6 +215,11 @@ class GeneratorPrototype; class TypedArrayConstructor; class TypedArrayPrototype; +class AtomicsObject; +class JSONObject; +class MathObject; +class ReflectObject; + // Tag type used to differentiate between u8 as used by Uint8Array and u8 as used by Uint8ClampedArray. struct ClampedU8; @@ -217,6 +232,11 @@ JS_ENUMERATE_NATIVE_ERRORS JS_ENUMERATE_TYPED_ARRAYS #undef __JS_ENUMERATE +#define __JS_ENUMERATE(ClassName, snake_name) \ + class ClassName; \ + JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS +#undef __JS_ENUMERATE + namespace Intl { #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \ class ClassName; \ @@ -225,6 +245,7 @@ namespace Intl { JS_ENUMERATE_INTL_OBJECTS #undef __JS_ENUMERATE +class Intl; class MathematicalValue; // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor @@ -239,6 +260,7 @@ namespace Temporal { class PrototypeName; JS_ENUMERATE_TEMPORAL_OBJECTS #undef __JS_ENUMERATE +class Temporal; struct DurationRecord; struct DateDurationRecord; struct TimeDurationRecord; diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 96f72f372dd..60bbeb9921b 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -362,7 +362,7 @@ bool validate_and_apply_property_descriptor(Object* object, PropertyKey const& p } // 10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ), https://tc39.es/ecma262/#sec-getprototypefromconstructor -ThrowCompletionOr get_prototype_from_constructor(VM& vm, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)()) +ThrowCompletionOr get_prototype_from_constructor(VM& vm, FunctionObject const& constructor, Object* (Intrinsics::*intrinsic_default_prototype)()) { // 1. Assert: intrinsicDefaultProto is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object. @@ -375,7 +375,7 @@ ThrowCompletionOr get_prototype_from_constructor(VM& vm, FunctionObject auto* realm = TRY(get_function_realm(vm, constructor)); // b. Set proto to realm's intrinsic object named intrinsicDefaultProto. - prototype = (realm->global_object().*intrinsic_default_prototype)(); + prototype = (realm->intrinsics().*intrinsic_default_prototype)(); } // 4. Return proto. @@ -1029,7 +1029,7 @@ Object* create_unmapped_arguments_object(VM& vm, Span arguments) // 2. Let obj be OrdinaryObjectCreate(%Object.prototype%, « [[ParameterMap]] »). // 3. Set obj.[[ParameterMap]] to undefined. - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); object->set_has_parameter_map(); // 4. Perform ! DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(len), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). @@ -1048,11 +1048,11 @@ Object* create_unmapped_arguments_object(VM& vm, Span arguments) } // 7. Perform ! DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). - auto* array_prototype_values = realm.global_object().array_prototype_values_function(); + auto* array_prototype_values = realm.intrinsics().array_prototype_values_function(); MUST(object->define_property_or_throw(*vm.well_known_symbol_iterator(), { .value = array_prototype_values, .writable = true, .enumerable = false, .configurable = true })); // 8. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Get]]: %ThrowTypeError%, [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false }). - auto* throw_type_error = realm.global_object().throw_type_error_function(); + auto* throw_type_error = realm.intrinsics().throw_type_error_function(); MUST(object->define_property_or_throw(vm.names.callee, { .get = throw_type_error, .set = throw_type_error, .enumerable = false, .configurable = false })); // 9. Return obj. @@ -1131,7 +1131,7 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector< } // 20. Perform ! DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). - auto* array_prototype_values = realm.global_object().array_prototype_values_function(); + auto* array_prototype_values = realm.intrinsics().array_prototype_values_function(); MUST(object->define_property_or_throw(*vm.well_known_symbol_iterator(), { .value = array_prototype_values, .writable = true, .enumerable = false, .configurable = true })); // 21. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Value]]: func, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }). diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 8f1257f5bd7..a004f1e5990 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -38,7 +38,7 @@ ThrowCompletionOr get_function_realm(VM&, FunctionObject const&); ThrowCompletionOr initialize_bound_name(VM&, FlyString const&, Value, Environment*); bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional const& current); bool validate_and_apply_property_descriptor(Object*, PropertyKey const&, bool extensible, PropertyDescriptor const&, Optional const& current); -ThrowCompletionOr get_prototype_from_constructor(VM&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)()); +ThrowCompletionOr get_prototype_from_constructor(VM&, FunctionObject const& constructor, Object* (Intrinsics::*intrinsic_default_prototype)()); Object* create_unmapped_arguments_object(VM&, Span arguments); Object* create_mapped_arguments_object(VM&, FunctionObject&, Vector const&, Span arguments, Environment&); @@ -131,7 +131,7 @@ ALWAYS_INLINE ThrowCompletionOr construct(VM& vm, FunctionObject& funct // 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor template -ThrowCompletionOr ordinary_create_from_constructor(VM& vm, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args) +ThrowCompletionOr ordinary_create_from_constructor(VM& vm, FunctionObject const& constructor, Object* (Intrinsics::*intrinsic_default_prototype)(), Args&&... args) { auto& realm = *vm.current_realm(); auto* prototype = TRY(get_prototype_from_constructor(vm, constructor, intrinsic_default_prototype)); diff --git a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp index cfca1966b1e..db5a12cf57b 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateError.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateError.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,7 +12,7 @@ namespace JS { AggregateError* AggregateError::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().aggregate_error_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().aggregate_error_prototype()); } AggregateError::AggregateError(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp index 868efa57ba6..9230e26c73a 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp @@ -15,7 +15,7 @@ namespace JS { AggregateErrorConstructor::AggregateErrorConstructor(Realm& realm) - : NativeFunction(static_cast(*realm.global_object().error_constructor())) + : NativeFunction(static_cast(*realm.intrinsics().error_constructor())) { } @@ -25,7 +25,7 @@ void AggregateErrorConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 20.5.7.2.1 AggregateError.prototype, https://tc39.es/ecma262/#sec-aggregate-error.prototype - define_direct_property(vm.names.prototype, realm.global_object().aggregate_error_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().aggregate_error_prototype(), 0); define_direct_property(vm.names.length, Value(2), Attribute::Configurable); } @@ -42,7 +42,7 @@ ThrowCompletionOr AggregateErrorConstructor::construct(FunctionObject& auto& vm = this->vm(); auto& realm = *vm.current_realm(); - auto* aggregate_error = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::aggregate_error_prototype)); + auto* aggregate_error = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::aggregate_error_prototype)); if (!vm.argument(1).is_undefined()) { auto message = TRY(vm.argument(1).to_string(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp index 797b6a1caba..34302bc3f92 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,7 +11,7 @@ namespace JS { AggregateErrorPrototype::AggregateErrorPrototype(Realm& realm) - : Object(*realm.global_object().error_prototype()) + : Object(*realm.intrinsics().error_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp index 924ba893ca5..ffc05bf542f 100644 --- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp @@ -11,7 +11,7 @@ namespace JS { ArgumentsObject::ArgumentsObject(Realm& realm, Environment& environment) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) , m_environment(environment) { } diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index dd91a6444a5..8d732203987 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -27,7 +27,7 @@ ThrowCompletionOr Array::create(Realm& realm, u64 length, Object* protot // 2. If proto is not present, set proto to %Array.prototype%. if (!prototype) - prototype = realm.global_object().array_prototype(); + prototype = realm.intrinsics().array_prototype(); // 3. Let A be MakeBasicObject(« [[Prototype]], [[Extensible]] »). // 4. Set A.[[Prototype]] to proto. diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp index f66b67b7449..66d59f844b2 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp @@ -17,17 +17,17 @@ ThrowCompletionOr ArrayBuffer::create(Realm& realm, size_t byte_le if (buffer.is_error()) return realm.vm().throw_completion(ErrorType::NotEnoughMemoryToAllocate, byte_length); - return realm.heap().allocate(realm, buffer.release_value(), *realm.global_object().array_buffer_prototype()); + return realm.heap().allocate(realm, buffer.release_value(), *realm.intrinsics().array_buffer_prototype()); } ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer buffer) { - return realm.heap().allocate(realm, move(buffer), *realm.global_object().array_buffer_prototype()); + return realm.heap().allocate(realm, move(buffer), *realm.intrinsics().array_buffer_prototype()); } ArrayBuffer* ArrayBuffer::create(Realm& realm, ByteBuffer* buffer) { - return realm.heap().allocate(realm, buffer, *realm.global_object().array_buffer_prototype()); + return realm.heap().allocate(realm, buffer, *realm.intrinsics().array_buffer_prototype()); } ArrayBuffer::ArrayBuffer(ByteBuffer buffer, Object& prototype) @@ -54,7 +54,7 @@ void ArrayBuffer::visit_edges(Cell::Visitor& visitor) ThrowCompletionOr allocate_array_buffer(VM& vm, FunctionObject& constructor, size_t byte_length) { // 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBuffer.prototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]], [[ArrayBufferDetachKey]] »). - auto* obj = TRY(ordinary_create_from_constructor(vm, constructor, &GlobalObject::array_buffer_prototype, nullptr)); + auto* obj = TRY(ordinary_create_from_constructor(vm, constructor, &Intrinsics::array_buffer_prototype, nullptr)); // 2. Let block be ? CreateByteDataBlock(byteLength). auto block = ByteBuffer::create_zeroed(byte_length); @@ -101,7 +101,7 @@ ThrowCompletionOr clone_array_buffer(VM& vm, ArrayBuffer& source_b VERIFY(!source_buffer.is_detached()); // 2. Let targetBuffer be ? AllocateArrayBuffer(%ArrayBuffer%, srcLength). - auto* target_buffer = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), source_length)); + auto* target_buffer = TRY(allocate_array_buffer(vm, *realm.intrinsics().array_buffer_constructor(), source_length)); // 3. Let srcBlock be srcBuffer.[[ArrayBufferData]]. auto& source_block = source_buffer.buffer(); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp index 64519d44ddc..9472b7f3707 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { ArrayBufferConstructor::ArrayBufferConstructor(Realm& realm) - : NativeFunction(vm().names.ArrayBuffer.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.ArrayBuffer.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void ArrayBufferConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 25.1.4.2 ArrayBuffer.prototype, https://tc39.es/ecma262/#sec-arraybuffer.prototype - define_direct_property(vm.names.prototype, realm.global_object().array_buffer_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().array_buffer_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.isView, is_view, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp index d312b5c5c57..5c53ec60cdf 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp @@ -15,7 +15,7 @@ namespace JS { ArrayBufferPrototype::ArrayBufferPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -82,7 +82,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.global_object().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))); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 562d7126ecc..784648874ae 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -17,7 +17,7 @@ namespace JS { ArrayConstructor::ArrayConstructor(Realm& realm) - : NativeFunction(vm().names.Array.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Array.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void ArrayConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 23.1.2.4 Array.prototype, https://tc39.es/ecma262/#sec-array.prototype - define_direct_property(vm.names.prototype, realm.global_object().array_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().array_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); @@ -52,7 +52,7 @@ ThrowCompletionOr ArrayConstructor::construct(FunctionObject& new_targe auto& vm = this->vm(); auto& realm = *vm.current_realm(); - auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &GlobalObject::array_prototype)); + auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::array_prototype)); if (vm.argument_count() == 0) return MUST(Array::create(realm, 0, proto)); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp index c7dde4fb139..b9e45758ec4 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIterator.cpp @@ -11,7 +11,7 @@ namespace JS { ArrayIterator* ArrayIterator::create(Realm& realm, Value array, Object::PropertyKind iteration_kind) { - return realm.heap().allocate(realm, array, iteration_kind, *realm.global_object().array_iterator_prototype()); + return realm.heap().allocate(realm, array, iteration_kind, *realm.intrinsics().array_iterator_prototype()); } ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index ce00356f788..259587414c9 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -15,7 +15,7 @@ namespace JS { ArrayIteratorPrototype::ArrayIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index d34d388260b..47fb1de68aa 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -29,7 +29,7 @@ namespace JS { static HashTable s_array_join_seen_objects; ArrayPrototype::ArrayPrototype(Realm& realm) - : Array(*realm.global_object().object_prototype()) + : Array(*realm.intrinsics().object_prototype()) { } @@ -128,7 +128,7 @@ static ThrowCompletionOr array_species_create(VM& vm, Object& original_ auto* this_realm = vm.current_realm(); auto* constructor_realm = TRY(get_function_realm(vm, constructor_function)); if (constructor_realm != this_realm) { - if (&constructor_function == constructor_realm->global_object().array_constructor()) + if (&constructor_function == constructor_realm->intrinsics().array_constructor()) constructor = js_undefined(); } } @@ -1968,7 +1968,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) // 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%. if (!func.is_function()) - func = realm.global_object().object_prototype_to_string_function(); + func = realm.intrinsics().object_prototype_to_string_function(); // 4. Return ? Call(func, array). return TRY(call(vm, func.as_function(), array)); diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp index a31e5e27299..0044677a93c 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp @@ -17,7 +17,7 @@ AsyncFromSyncIterator* AsyncFromSyncIterator::create(Realm& realm, Iterator sync } AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record) - : Object(*realm.global_object().async_from_sync_iterator_prototype()) + : Object(*realm.intrinsics().async_from_sync_iterator_prototype()) , m_sync_iterator_record(sync_iterator_record) { } diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp index 84f09708add..4e71468cfd1 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp @@ -15,7 +15,7 @@ namespace JS { AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().async_iterator_prototype()) + : PrototypeObject(*realm.intrinsics().async_iterator_prototype()) { } @@ -46,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, *realm.global_object().promise_constructor(), value)); + auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *realm.intrinsics().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 { @@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next) auto* this_object = MUST(typed_this_object(vm)); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. auto& sync_iterator_record = this_object->sync_iterator_record(); @@ -103,7 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_) auto* this_object = MUST(typed_this_object(vm)); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. auto* sync_iterator = this_object->sync_iterator_record().iterator; @@ -156,7 +156,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_) auto* this_object = MUST(typed_this_object(vm)); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. auto* sync_iterator = this_object->sync_iterator_record().iterator; diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp index e4778ffaa9f..b282e66aeaf 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp @@ -13,7 +13,7 @@ namespace JS { AsyncFunctionConstructor::AsyncFunctionConstructor(Realm& realm) - : NativeFunction(vm().names.AsyncFunction.as_string(), *realm.global_object().function_constructor()) + : NativeFunction(vm().names.AsyncFunction.as_string(), *realm.intrinsics().function_constructor()) { } @@ -23,7 +23,7 @@ void AsyncFunctionConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 27.7.2.2 AsyncFunction.prototype, https://tc39.es/ecma262/#sec-async-function-constructor-prototype - define_direct_property(vm.names.prototype, realm.global_object().async_function_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().async_function_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp index f398e8a1339..becbb47c870 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp @@ -19,7 +19,7 @@ ThrowCompletionOr AsyncFunctionDriverWrapper::create(Realm& realm, Genera } AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object) - : Promise(*realm.global_object().promise_prototype()) + : Promise(*realm.intrinsics().promise_prototype()) , m_generator_object(generator_object) , m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm) { return react_to_async_task_completion(vm, vm.argument(0), true); diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.cpp index 4eb27b1e688..a2149557bf2 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.cpp @@ -10,7 +10,7 @@ namespace JS { AsyncFunctionPrototype::AsyncFunctionPrototype(Realm& realm) - : Object(*realm.global_object().function_prototype()) + : Object(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp index bb83045693a..3df767692a4 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp @@ -13,7 +13,7 @@ namespace JS { AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(Realm& realm) - : NativeFunction(vm().names.AsyncGeneratorFunction.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.AsyncGeneratorFunction.as_string(), *realm.intrinsics().function_prototype()) { } @@ -26,7 +26,7 @@ void AsyncGeneratorFunctionConstructor::initialize(Realm& realm) define_direct_property(vm.names.length, Value(1), Attribute::Configurable); // 27.4.2.2 AsyncGeneratorFunction.prototype, https://tc39.es/ecma262/#sec-asyncgeneratorfunction-prototype - define_direct_property(vm.names.prototype, realm.global_object().async_generator_function_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().async_generator_function_prototype(), 0); } // 27.4.1.1 AsyncGeneratorFunction ( p1, p2, … , pn, body ), https://tc39.es/ecma262/#sec-asyncgeneratorfunction diff --git a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.cpp index 7fc40459b69..24cd8741065 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.cpp @@ -12,7 +12,7 @@ namespace JS { AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().function_prototype()) + : PrototypeObject(*realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void AsyncGeneratorFunctionPrototype::initialize(Realm& realm) // The constructor cannot be set at this point since it has not been initialized. // 27.4.3.2 AsyncGeneratorFunction.prototype.prototype, https://tc39.es/ecma262/#sec-asyncgeneratorfunction-prototype-prototype - define_direct_property(vm.names.prototype, realm.global_object().async_generator_prototype(), Attribute::Configurable); + define_direct_property(vm.names.prototype, realm.intrinsics().async_generator_prototype(), Attribute::Configurable); // 27.4.3.3 AsyncGeneratorFunction.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-asyncgeneratorfunction-prototype-tostringtag define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.AsyncGeneratorFunction.as_string()), Attribute::Configurable); diff --git a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.cpp index 745437a78f4..db9f611d715 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.cpp @@ -10,7 +10,7 @@ namespace JS { // 27.6.1 Properties of the AsyncGenerator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-prototype AsyncGeneratorPrototype::AsyncGeneratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().async_iterator_prototype()) + : PrototypeObject(*realm.intrinsics().async_iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.cpp index 20a4bc38628..9ec5c2608d4 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.cpp @@ -9,7 +9,7 @@ namespace JS { AsyncIteratorPrototype::AsyncIteratorPrototype(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp b/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp index 74c5a85561b..32bd982fe52 100644 --- a/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp @@ -123,7 +123,7 @@ static ThrowCompletionOr perform_atomic_operation(VM& vm, TypedArrayBase& } AtomicsObject::AtomicsObject(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp index 6564178d650..f737840715d 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp @@ -18,7 +18,7 @@ namespace JS { static const Crypto::SignedBigInteger BIGINT_ONE { 1 }; BigIntConstructor::BigIntConstructor(Realm& realm) - : NativeFunction(vm().names.BigInt.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.BigInt.as_string(), *realm.intrinsics().function_prototype()) { } @@ -28,7 +28,7 @@ void BigIntConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 21.2.2.3 BigInt.prototype, https://tc39.es/ecma262/#sec-bigint.prototype - define_direct_property(vm.names.prototype, realm.global_object().bigint_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().bigint_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.asIntN, as_int_n, 2, attr); diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp index 9187b3eb807..ce05f949686 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Linus Groh + * Copyright (c) 2020-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,7 +11,7 @@ namespace JS { BigIntObject* BigIntObject::create(Realm& realm, BigInt& bigint) { - return realm.heap().allocate(realm, bigint, *realm.global_object().bigint_prototype()); + return realm.heap().allocate(realm, bigint, *realm.intrinsics().bigint_prototype()); } BigIntObject::BigIntObject(BigInt& bigint, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp index 1f8e9963ebf..d98ea5cba26 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -18,7 +18,7 @@ namespace JS { BigIntPrototype::BigIntPrototype(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } @@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) auto* bigint = TRY(this_bigint_value(vm, vm.this_value())); // 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »). - auto* number_format = static_cast(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), locales, options))); + auto* number_format = static_cast(TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), locales, options))); // 3. Return ? FormatNumeric(numberFormat, x). auto formatted = Intl::format_numeric(vm, *number_format, Value(bigint)); diff --git a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp index 14d8adba337..075a997af9c 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -12,7 +12,7 @@ namespace JS { BooleanConstructor::BooleanConstructor(Realm& realm) - : NativeFunction(vm().names.Boolean.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Boolean.as_string(), *realm.intrinsics().function_prototype()) { } @@ -22,7 +22,7 @@ void BooleanConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 20.3.2.1 Boolean.prototype, https://tc39.es/ecma262/#sec-boolean.prototype - define_direct_property(vm.names.prototype, realm.global_object().boolean_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().boolean_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -42,7 +42,7 @@ ThrowCompletionOr BooleanConstructor::construct(FunctionObject& new_tar auto& vm = this->vm(); auto b = vm.argument(0).to_boolean(); - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::boolean_prototype, b)); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::boolean_prototype, b)); } } diff --git a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp index 5a79c32fb2d..fff4d481f5b 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanObject.cpp @@ -11,7 +11,7 @@ namespace JS { BooleanObject* BooleanObject::create(Realm& realm, bool value) { - return realm.heap().allocate(realm, value, *realm.global_object().boolean_prototype()); + return realm.heap().allocate(realm, value, *realm.intrinsics().boolean_prototype()); } BooleanObject::BooleanObject(bool value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp index 836cd6e0f90..d3dc7036cc0 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -13,7 +13,7 @@ namespace JS { BooleanPrototype::BooleanPrototype(Realm& realm) - : BooleanObject(false, *realm.global_object().object_prototype()) + : BooleanObject(false, *realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp index eaa75d21102..bcf39d8f502 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.cpp +++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp @@ -37,7 +37,7 @@ ThrowCompletionOr await(VM& vm, Value value) // NOTE: This is not needed, as we don't suspend anything. // 2. Let promise be ? PromiseResolve(%Promise%, value). - auto* promise_object = TRY(promise_resolve(vm, *realm.global_object().promise_constructor(), value)); + auto* promise_object = TRY(promise_resolve(vm, *realm.intrinsics().promise_constructor(), value)); Optional success; Value result; diff --git a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp index b44eb60fe39..184b66b0a02 100644 --- a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -13,7 +13,7 @@ namespace JS { ConsoleObject::ConsoleObject(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/DataView.cpp b/Userland/Libraries/LibJS/Runtime/DataView.cpp index bb3909b47bb..1068ae6fe26 100644 --- a/Userland/Libraries/LibJS/Runtime/DataView.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataView.cpp @@ -10,7 +10,7 @@ namespace JS { DataView* DataView::create(Realm& realm, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset) { - return realm.heap().allocate(realm, viewed_buffer, byte_length, byte_offset, *realm.global_object().data_view_prototype()); + return realm.heap().allocate(realm, viewed_buffer, byte_length, byte_offset, *realm.intrinsics().data_view_prototype()); } DataView::DataView(ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp index d56b01a12b1..2b44ddfdafd 100644 --- a/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { DataViewConstructor::DataViewConstructor(Realm& realm) - : NativeFunction(vm().names.DataView.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.DataView.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void DataViewConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 25.3.3.1 DataView.prototype, https://tc39.es/ecma262/#sec-dataview.prototype - define_direct_property(vm.names.prototype, realm.global_object().data_view_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().data_view_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -66,7 +66,7 @@ ThrowCompletionOr DataViewConstructor::construct(FunctionObject& new_ta return vm.throw_completion(ErrorType::InvalidLength, vm.names.DataView); } - auto* data_view = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::data_view_prototype, &array_buffer, view_byte_length, offset)); + auto* data_view = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::data_view_prototype, &array_buffer, view_byte_length, offset)); if (array_buffer.is_detached()) return vm.throw_completion(ErrorType::DetachedArrayBuffer); diff --git a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp index 16fadda126d..a9363d40c36 100644 --- a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp @@ -11,7 +11,7 @@ namespace JS { DataViewPrototype::DataViewPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 83af042624c..2896cb83eae 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -18,7 +18,7 @@ namespace JS { Date* Date::create(Realm& realm, double date_value) { - return realm.heap().allocate(realm, date_value, *realm.global_object().date_prototype()); + return realm.heap().allocate(realm, date_value, *realm.intrinsics().date_prototype()); } Date::Date(double date_value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index 1c7e80ae283..18830dc5d0f 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -163,7 +163,7 @@ static double parse_date_string(String const& date_string) } DateConstructor::DateConstructor(Realm& realm) - : NativeFunction(vm().names.Date.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Date.as_string(), *realm.intrinsics().function_prototype()) { } @@ -173,7 +173,7 @@ void DateConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 21.4.3.3 Date.prototype, https://tc39.es/ecma262/#sec-date.prototype - define_direct_property(vm.names.prototype, realm.global_object().date_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().date_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.now, now, 0, attr); @@ -286,7 +286,7 @@ ThrowCompletionOr DateConstructor::construct(FunctionObject& new_target // 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »). // 7. Set O.[[DateValue]] to dv. // 8. Return O. - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::date_prototype, date_value)); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::date_prototype, date_value)); } // 21.4.3.1 Date.now ( ), https://tc39.es/ecma262/#sec-date.now diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 7ab96f1f378..bbc540fedc4 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -31,7 +31,7 @@ namespace JS { DatePrototype::DatePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -986,7 +986,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json) static ThrowCompletionOr construct_date_time_format(VM& vm, Value locales, Value options) { auto& realm = *vm.current_realm(); - auto* date_time_format = TRY(construct(vm, *realm.global_object().intl_date_time_format_constructor(), locales, options)); + auto* date_time_format = TRY(construct(vm, *realm.intrinsics().intl_date_time_format_constructor(), locales, options)); return static_cast(date_time_format); } diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 4385719a43c..0ea85b9cd7d 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -33,16 +33,16 @@ ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(Realm& realm, FlyStri Object* prototype = nullptr; switch (kind) { case FunctionKind::Normal: - prototype = realm.global_object().function_prototype(); + prototype = realm.intrinsics().function_prototype(); break; case FunctionKind::Generator: - prototype = realm.global_object().generator_function_prototype(); + prototype = realm.intrinsics().generator_function_prototype(); break; case FunctionKind::Async: - prototype = realm.global_object().async_function_prototype(); + prototype = realm.intrinsics().async_function_prototype(); break; case FunctionKind::AsyncGenerator: - prototype = realm.global_object().async_generator_function_prototype(); + prototype = realm.intrinsics().async_generator_function_prototype(); break; } return realm.heap().allocate(realm, move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, parent_environment, private_environment, *prototype, kind, is_strict, might_need_arguments_object, contains_direct_call_to_eval, is_arrow_function, move(class_field_initializer_name)); @@ -114,17 +114,17 @@ void ECMAScriptFunctionObject::initialize(Realm& realm) Object* prototype = nullptr; switch (m_kind) { case FunctionKind::Normal: - prototype = vm.heap().allocate(realm, *realm.global_object().new_ordinary_function_prototype_object_shape()); + prototype = vm.heap().allocate(realm, *realm.intrinsics().new_ordinary_function_prototype_object_shape()); MUST(prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true })); break; case FunctionKind::Generator: // prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) - prototype = Object::create(realm, realm.global_object().generator_function_prototype_prototype()); + prototype = Object::create(realm, realm.intrinsics().generator_function_prototype_prototype()); break; case FunctionKind::Async: break; case FunctionKind::AsyncGenerator: - prototype = Object::create(realm, realm.global_object().async_generator_function_prototype_prototype()); + prototype = Object::create(realm, realm.intrinsics().async_generator_function_prototype_prototype()); break; } // 27.7.4 AsyncFunction Instances, https://tc39.es/ecma262/#sec-async-function-instances @@ -208,7 +208,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::internal_construct(MarkedVe // 3. If kind is base, then if (kind == ConstructorKind::Base) { // a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, "%Object.prototype%"). - this_argument = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::object_prototype)); + this_argument = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::object_prototype)); } ExecutionContext callee_context(heap()); @@ -863,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, realm.global_object().promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 2. Let declResult be Completion(FunctionDeclarationInstantiation(functionObject, argumentsList)). auto declaration_result = function_declaration_instantiation(ast_interpreter); diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index 780aa8b1375..25642c45643 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -16,7 +16,7 @@ namespace JS { Error* Error::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().error_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().error_prototype()); } Error* Error::create(Realm& realm, String const& message) @@ -96,24 +96,24 @@ String Error::stack_string() const return stack_string_builder.build(); } -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - ClassName* ClassName::create(Realm& realm) \ - { \ - return realm.heap().allocate(realm, *realm.global_object().snake_name##_prototype()); /* */ \ - } \ - \ - ClassName* ClassName::create(Realm& realm, String const& message) \ - { \ - auto& vm = realm.vm(); \ - auto* error = ClassName::create(realm); \ - u8 attr = Attribute::Writable | Attribute::Configurable; \ - error->define_direct_property(vm.names.message, js_string(vm, message), attr); \ - return error; \ - } \ - \ - ClassName::ClassName(Object& prototype) \ - : Error(prototype) \ - { \ +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + ClassName* ClassName::create(Realm& realm) \ + { \ + return realm.heap().allocate(realm, *realm.intrinsics().snake_name##_prototype()); \ + } \ + \ + ClassName* ClassName::create(Realm& realm, String const& message) \ + { \ + auto& vm = realm.vm(); \ + auto* error = ClassName::create(realm); \ + u8 attr = Attribute::Writable | Attribute::Configurable; \ + error->define_direct_property(vm.names.message, js_string(vm, message), attr); \ + return error; \ + } \ + \ + ClassName::ClassName(Object& prototype) \ + : Error(prototype) \ + { \ } JS_ENUMERATE_NATIVE_ERRORS diff --git a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp index 6839ace3fb6..4ee0af65864 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -12,7 +12,7 @@ namespace JS { ErrorConstructor::ErrorConstructor(Realm& realm) - : NativeFunction(vm().names.Error.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Error.as_string(), *realm.intrinsics().function_prototype()) { } @@ -22,7 +22,7 @@ void ErrorConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 20.5.2.1 Error.prototype, https://tc39.es/ecma262/#sec-error.prototype - define_direct_property(vm.names.prototype, realm.global_object().error_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().error_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -43,7 +43,7 @@ ThrowCompletionOr ErrorConstructor::construct(FunctionObject& new_targe auto options = vm.argument(1); // 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%Error.prototype%", « [[ErrorData]] »). - auto* error = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::error_prototype)); + auto* error = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::error_prototype)); // 3. If message is not undefined, then if (!message.is_undefined()) { @@ -61,57 +61,57 @@ ThrowCompletionOr ErrorConstructor::construct(FunctionObject& new_targe return error; } -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - ConstructorName::ConstructorName(Realm& realm) \ - : NativeFunction(vm().names.ClassName.as_string(), *static_cast(realm.global_object().error_constructor())) \ - { \ - } \ - \ - void ConstructorName::initialize(Realm& realm) \ - { \ - auto& vm = this->vm(); \ - NativeFunction::initialize(realm); \ - \ - /* 20.5.6.2.1 NativeError.prototype, https://tc39.es/ecma262/#sec-nativeerror.prototype */ \ - define_direct_property(vm.names.prototype, realm.global_object().snake_name##_prototype(), 0); \ - \ - define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \ - } \ - \ - ConstructorName::~ConstructorName() = default; \ - \ - /* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \ - ThrowCompletionOr ConstructorName::call() \ - { \ - /* 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. */ \ - return TRY(construct(*this)); \ - } \ - \ - /* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \ - ThrowCompletionOr ConstructorName::construct(FunctionObject& new_target) \ - { \ - auto& vm = this->vm(); \ - \ - auto message = vm.argument(0); \ - auto options = vm.argument(1); \ - \ - /* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \ - auto* error = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::snake_name##_prototype)); \ - \ - /* 3. If message is not undefined, then */ \ - if (!message.is_undefined()) { \ - /* a. Let msg be ? ToString(message). */ \ - auto msg = TRY(message.to_string(vm)); \ - \ - /* b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \ - error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg))); \ - } \ - \ - /* 4. Perform ? InstallErrorCause(O, options). */ \ - TRY(error->install_error_cause(options)); \ - \ - /* 5. Return O. */ \ - return error; \ +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + ConstructorName::ConstructorName(Realm& realm) \ + : NativeFunction(vm().names.ClassName.as_string(), *static_cast(realm.intrinsics().error_constructor())) \ + { \ + } \ + \ + void ConstructorName::initialize(Realm& realm) \ + { \ + auto& vm = this->vm(); \ + NativeFunction::initialize(realm); \ + \ + /* 20.5.6.2.1 NativeError.prototype, https://tc39.es/ecma262/#sec-nativeerror.prototype */ \ + define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0); \ + \ + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \ + } \ + \ + ConstructorName::~ConstructorName() = default; \ + \ + /* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \ + ThrowCompletionOr ConstructorName::call() \ + { \ + /* 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. */ \ + return TRY(construct(*this)); \ + } \ + \ + /* 20.5.6.1.1 NativeError ( message [ , options ] ), https://tc39.es/ecma262/#sec-nativeerror */ \ + ThrowCompletionOr ConstructorName::construct(FunctionObject& new_target) \ + { \ + auto& vm = this->vm(); \ + \ + auto message = vm.argument(0); \ + auto options = vm.argument(1); \ + \ + /* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \ + auto* error = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::snake_name##_prototype)); \ + \ + /* 3. If message is not undefined, then */ \ + if (!message.is_undefined()) { \ + /* a. Let msg be ? ToString(message). */ \ + auto msg = TRY(message.to_string(vm)); \ + \ + /* b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \ + error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg))); \ + } \ + \ + /* 4. Perform ? InstallErrorCause(O, options). */ \ + TRY(error->install_error_cause(options)); \ + \ + /* 5. Return O. */ \ + return error; \ } JS_ENUMERATE_NATIVE_ERRORS diff --git a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp index ec00be85fd6..fd00dd0adbb 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -16,7 +16,7 @@ namespace JS { ErrorPrototype::ErrorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -125,7 +125,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_setter) #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ PrototypeName::PrototypeName(Realm& realm) \ - : PrototypeObject(*realm.global_object().error_prototype()) \ + : PrototypeObject(*realm.intrinsics().error_prototype()) \ { \ } \ \ diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp index 22e5bb8444c..02cb4e25a64 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { FinalizationRegistryConstructor::FinalizationRegistryConstructor(Realm& realm) - : NativeFunction(vm().names.FinalizationRegistry.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.FinalizationRegistry.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void FinalizationRegistryConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 26.2.2.1 FinalizationRegistry.prototype, https://tc39.es/ecma262/#sec-finalization-registry.prototype - define_direct_property(vm.names.prototype, realm.global_object().finalization_registry_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().finalization_registry_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -56,7 +56,7 @@ ThrowCompletionOr FinalizationRegistryConstructor::construct(FunctionOb // 7. Set finalizationRegistry.[[Cells]] to a new empty List. // NOTE: This is done inside FinalizationRegistry instead of here. // 8. Return finalizationRegistry. - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::finalization_registry_prototype, *realm(), vm.host_make_job_callback(cleanup_callback.as_function()))); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::finalization_registry_prototype, *realm(), vm.host_make_job_callback(cleanup_callback.as_function()))); } } diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp index 029a2f80a46..b10684992e2 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp @@ -10,7 +10,7 @@ namespace JS { FinalizationRegistryPrototype::FinalizationRegistryPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 8fde5b20f8b..a6d470fbe19 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -20,7 +20,7 @@ namespace JS { FunctionConstructor::FunctionConstructor(Realm& realm) - : NativeFunction(vm().names.Function.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Function.as_string(), *realm.intrinsics().function_prototype()) { } @@ -30,7 +30,7 @@ void FunctionConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 20.2.2.2 Function.prototype, https://tc39.es/ecma262/#sec-function.prototype - define_direct_property(vm.names.prototype, realm.global_object().function_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().function_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -49,7 +49,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic new_target = &constructor; StringView prefix; - Object* (GlobalObject::*fallback_prototype)() = nullptr; + Object* (Intrinsics::*fallback_prototype)() = nullptr; switch (kind) { // 4. If kind is normal, then @@ -62,7 +62,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // d. Let parameterSym be the grammar symbol FormalParameters[~Yield, ~Await]. // e. Let fallbackProto be "%Function.prototype%". - fallback_prototype = &GlobalObject::function_prototype; + fallback_prototype = &Intrinsics::function_prototype; break; // 5. Else if kind is generator, then @@ -75,7 +75,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // d. Let parameterSym be the grammar symbol FormalParameters[+Yield, ~Await]. // e. Let fallbackProto be "%GeneratorFunction.prototype%". - fallback_prototype = &GlobalObject::generator_function_prototype; + fallback_prototype = &Intrinsics::generator_function_prototype; break; // 6. Else if kind is async, then @@ -88,7 +88,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // d. Let parameterSym be the grammar symbol FormalParameters[~Yield, +Await]. // e. Let fallbackProto be "%AsyncFunction.prototype%". - fallback_prototype = &GlobalObject::async_function_prototype; + fallback_prototype = &Intrinsics::async_function_prototype; break; // 7. Else, @@ -103,7 +103,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // e. Let parameterSym be the grammar symbol FormalParameters[+Yield, +Await]. // f. Let fallbackProto be "%AsyncGeneratorFunction.prototype%". - fallback_prototype = &GlobalObject::async_generator_function_prototype; + fallback_prototype = &Intrinsics::async_generator_function_prototype; break; default: @@ -232,7 +232,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // 30. If kind is generator, then if (kind == FunctionKind::Generator) { // a. Let prototype be OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%). - prototype = Object::create(realm, realm.global_object().generator_function_prototype_prototype()); + prototype = Object::create(realm, realm.intrinsics().generator_function_prototype_prototype()); // b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }). function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); @@ -240,7 +240,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // 31. Else if kind is asyncGenerator, then else if (kind == FunctionKind::AsyncGenerator) { // a. Let prototype be OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%). - prototype = Object::create(realm, realm.global_object().async_generator_function_prototype_prototype()); + prototype = Object::create(realm, realm.intrinsics().async_generator_function_prototype_prototype()); // b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }). function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); @@ -248,7 +248,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // 32. Else if kind is normal, perform MakeConstructor(F). else if (kind == FunctionKind::Normal) { // FIXME: Implement MakeConstructor - prototype = Object::create(realm, realm.global_object().object_prototype()); + prototype = Object::create(realm, realm.intrinsics().object_prototype()); prototype->define_direct_property(vm.names.constructor, function, Attribute::Writable | Attribute::Configurable); function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); } diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index d9f7b40a138..379f1b8ea56 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -21,7 +21,7 @@ namespace JS { FunctionPrototype::FunctionPrototype(Realm& realm) - : FunctionObject(*realm.global_object().object_prototype()) + : FunctionObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp index 5c73f3e394d..0faac0dbf2d 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp @@ -12,7 +12,7 @@ namespace JS { GeneratorFunctionConstructor::GeneratorFunctionConstructor(Realm& realm) - : NativeFunction(static_cast(*realm.global_object().function_constructor())) + : NativeFunction(static_cast(*realm.intrinsics().function_constructor())) { } @@ -24,7 +24,7 @@ void GeneratorFunctionConstructor::initialize(Realm& realm) // 27.3.2.1 GeneratorFunction.length, https://tc39.es/ecma262/#sec-generatorfunction.length define_direct_property(vm.names.length, Value(1), Attribute::Configurable); // 27.3.2.2 GeneratorFunction.prototype, https://tc39.es/ecma262/#sec-generatorfunction.length - define_direct_property(vm.names.prototype, realm.global_object().generator_function_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().generator_function_prototype(), 0); } // 27.3.1.1 GeneratorFunction ( p1, p2, … , pn, body ), https://tc39.es/ecma262/#sec-generatorfunction diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp index ab6d51e6f47..62e39cbf08a 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp @@ -11,7 +11,7 @@ namespace JS { GeneratorFunctionPrototype::GeneratorFunctionPrototype(Realm& realm) - : Object(*realm.global_object().function_prototype()) + : Object(*realm.intrinsics().function_prototype()) { } @@ -21,7 +21,7 @@ void GeneratorFunctionPrototype::initialize(Realm& realm) Object::initialize(realm); // 27.3.3.2 GeneratorFunction.prototype.prototype, https://tc39.es/ecma262/#sec-generatorfunction.prototype.prototype - define_direct_property(vm.names.prototype, realm.global_object().generator_prototype(), Attribute::Configurable); + define_direct_property(vm.names.prototype, realm.intrinsics().generator_prototype(), Attribute::Configurable); // 27.3.3.3 GeneratorFunction.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-generatorfunction.prototype-@@tostringtag define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "GeneratorFunction"), Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index 80712ab0c7f..5eee673cfe4 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -22,7 +22,7 @@ ThrowCompletionOr GeneratorObject::create(Realm& realm, Value // We implement async functions by transforming them to generator function in the bytecode // interpreter. However an async function does not have a prototype and should not be // changed thus we hardcode the prototype. - generating_function_prototype = realm.global_object().generator_prototype(); + generating_function_prototype = realm.intrinsics().generator_prototype(); } else { generating_function_prototype = TRY(generating_function->get(vm.names.prototype)); } @@ -73,7 +73,7 @@ ThrowCompletionOr GeneratorObject::next_impl(VM& vm, Optional next auto previous_generated_value = TRY(generated_value(m_previous_value)); - auto result = Object::create(realm, realm.global_object().object_prototype()); + auto result = Object::create(realm, realm.intrinsics().object_prototype()); result->define_direct_property("value", previous_generated_value, default_attributes); if (m_done) { diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp index 49c452e24cb..d6040de060d 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp @@ -10,7 +10,7 @@ namespace JS { GeneratorPrototype::GeneratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 4f0b65b597c..2a5fdd34468 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -17,125 +16,70 @@ #include #include #include -#include #include -#include #include -#include #include -#include #include -#include #include -#include #include -#include #include #include -#include #include -#include #include #include -#include #include -#include #include -#include #include #include #include -#include #include -#include #include #include #include #include -#include #include -#include #include -#include #include -#include #include #include -#include #include -#include #include -#include #include -#include #include -#include -#include #include -#include -#include -#include #include #include -#include -#include #include -#include #include -#include #include #include -#include #include -#include #include #include #include #include -#include -#include #include -#include -#include #include -#include #include #include -#include #include #include -#include #include -#include #include -#include #include -#include #include -#include #include -#include #include -#include #include -#include #include -#include #include #include -#include #include -#include #include -#include -#include #include #include -#include #include -#include #include -#include namespace JS { @@ -145,215 +89,100 @@ GlobalObject::GlobalObject(Realm& realm) { } +// 9.3.4 SetDefaultGlobalBindings ( realmRec ), https://tc39.es/ecma262/#sec-setdefaultglobalbindings void GlobalObject::initialize_global_object(Realm& realm) { auto& vm = this->vm(); ensure_shape_is_unique(); - - // These are done first since other prototypes depend on their presence. - m_empty_object_shape = heap().allocate_without_realm(realm); - m_object_prototype = heap().allocate_without_realm(realm); - m_function_prototype = heap().allocate_without_realm(realm); - - m_new_object_shape = vm.heap().allocate_without_realm(realm); - m_new_object_shape->set_prototype_without_transition(m_object_prototype); - - m_new_ordinary_function_prototype_object_shape = vm.heap().allocate_without_realm(realm); - m_new_ordinary_function_prototype_object_shape->set_prototype_without_transition(m_object_prototype); - m_new_ordinary_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable); - - // Normally Heap::allocate() takes care of this, but these are allocated via allocate_without_realm(). - static_cast(m_function_prototype)->initialize(realm); - static_cast(m_object_prototype)->initialize(realm); - - Object::set_prototype(m_object_prototype); - - // This must be initialized before allocating AggregateErrorPrototype, which uses ErrorPrototype as its prototype. - m_error_prototype = heap().allocate(realm, realm); - -#define __JS_ENUMERATE(ClassName, snake_name) \ - if (!m_##snake_name##_prototype) \ - m_##snake_name##_prototype = heap().allocate(realm, realm); - JS_ENUMERATE_ITERATOR_PROTOTYPES -#undef __JS_ENUMERATE - - // These must be initialized separately as they have no companion constructor - m_async_from_sync_iterator_prototype = heap().allocate(realm, realm); - m_async_generator_prototype = heap().allocate(realm, realm); - m_generator_prototype = heap().allocate(realm, realm); - m_intl_segments_prototype = heap().allocate(realm, realm); - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - if (!m_##snake_name##_prototype) \ - m_##snake_name##_prototype = heap().allocate(realm, realm); - JS_ENUMERATE_BUILTIN_TYPES -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - if (!m_intl_##snake_name##_prototype) \ - m_intl_##snake_name##_prototype = heap().allocate(realm, realm); - JS_ENUMERATE_INTL_OBJECTS -#undef __JS_ENUMERATE - - // Must be allocated before `Intl::Intl` below. -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - initialize_constructor(realm, vm.names.ClassName, m_intl_##snake_name##_constructor, m_intl_##snake_name##_prototype); - JS_ENUMERATE_INTL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - if (!m_temporal_##snake_name##_prototype) \ - m_temporal_##snake_name##_prototype = heap().allocate(realm, realm); - JS_ENUMERATE_TEMPORAL_OBJECTS -#undef __JS_ENUMERATE - - // Must be allocated before `Temporal::Temporal` below. -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - initialize_constructor(realm, vm.names.ClassName, m_temporal_##snake_name##_constructor, m_temporal_##snake_name##_prototype); - JS_ENUMERATE_TEMPORAL_OBJECTS -#undef __JS_ENUMERATE + Object::set_prototype(realm.intrinsics().object_prototype()); u8 attr = Attribute::Writable | Attribute::Configurable; - define_native_function(realm, vm.names.gc, gc, 0, attr); - define_native_function(realm, vm.names.isNaN, is_nan, 1, attr); + + // 19.2 Function Properties of the Global Object, https://tc39.es/ecma262/#sec-function-properties-of-the-global-object + define_native_function(realm, vm.names.eval, eval, 1, attr); define_native_function(realm, vm.names.isFinite, is_finite, 1, attr); + define_native_function(realm, vm.names.isNaN, is_nan, 1, attr); define_native_function(realm, vm.names.parseFloat, parse_float, 1, attr); define_native_function(realm, vm.names.parseInt, parse_int, 2, attr); - define_native_function(realm, vm.names.eval, eval, 1, attr); - - // 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror% - m_throw_type_error_function = NativeFunction::create( - realm, [](VM& vm) { - return vm.throw_completion(ErrorType::RestrictedFunctionPropertiesAccess); - }, - 0, "", &realm); - m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0); - m_throw_type_error_function->define_direct_property(vm.names.name, js_string(vm, ""), 0); - MUST(m_throw_type_error_function->internal_prevent_extensions()); - - // 10.2.4 AddRestrictedFunctionProperties ( F, realm ), https://tc39.es/ecma262/#sec-addrestrictedfunctionproperties - m_function_prototype->define_direct_accessor(vm.names.caller, m_throw_type_error_function, m_throw_type_error_function, Attribute::Configurable); - m_function_prototype->define_direct_accessor(vm.names.arguments, m_throw_type_error_function, m_throw_type_error_function, Attribute::Configurable); - - define_native_function(realm, vm.names.encodeURI, encode_uri, 1, attr); define_native_function(realm, vm.names.decodeURI, decode_uri, 1, attr); - define_native_function(realm, vm.names.encodeURIComponent, encode_uri_component, 1, attr); define_native_function(realm, vm.names.decodeURIComponent, decode_uri_component, 1, attr); + define_native_function(realm, vm.names.encodeURI, encode_uri, 1, attr); + define_native_function(realm, vm.names.encodeURIComponent, encode_uri_component, 1, attr); + + // 19.1 Value Properties of the Global Object, https://tc39.es/ecma262/#sec-value-properties-of-the-global-object + define_direct_property(vm.names.globalThis, this, attr); + define_direct_property(vm.names.Infinity, js_infinity(), 0); + define_direct_property(vm.names.NaN, js_nan(), 0); + define_direct_property(vm.names.undefined, js_undefined(), 0); + + // 19.3 Constructor Properties of the Global Object, https://tc39.es/ecma262/#sec-constructor-properties-of-the-global-object + define_direct_property(vm.names.AggregateError, realm.intrinsics().aggregate_error_constructor(), attr); + define_direct_property(vm.names.Array, realm.intrinsics().array_constructor(), attr); + define_direct_property(vm.names.ArrayBuffer, realm.intrinsics().array_buffer_constructor(), attr); + define_direct_property(vm.names.BigInt, realm.intrinsics().bigint_constructor(), attr); + define_direct_property(vm.names.BigInt64Array, realm.intrinsics().big_int64_array_constructor(), attr); + define_direct_property(vm.names.BigUint64Array, realm.intrinsics().big_uint64_array_constructor(), attr); + define_direct_property(vm.names.Boolean, realm.intrinsics().boolean_constructor(), attr); + define_direct_property(vm.names.DataView, realm.intrinsics().data_view_constructor(), attr); + define_direct_property(vm.names.Date, realm.intrinsics().date_constructor(), attr); + define_direct_property(vm.names.Error, realm.intrinsics().error_constructor(), attr); + define_direct_property(vm.names.EvalError, realm.intrinsics().eval_error_constructor(), attr); + define_direct_property(vm.names.FinalizationRegistry, realm.intrinsics().finalization_registry_constructor(), attr); + define_direct_property(vm.names.Float32Array, realm.intrinsics().float32_array_constructor(), attr); + define_direct_property(vm.names.Float64Array, realm.intrinsics().float64_array_constructor(), attr); + define_direct_property(vm.names.Function, realm.intrinsics().function_constructor(), attr); + define_direct_property(vm.names.Int8Array, realm.intrinsics().int8_array_constructor(), attr); + define_direct_property(vm.names.Int16Array, realm.intrinsics().int16_array_constructor(), attr); + define_direct_property(vm.names.Int32Array, realm.intrinsics().int32_array_constructor(), attr); + define_direct_property(vm.names.Map, realm.intrinsics().map_constructor(), attr); + define_direct_property(vm.names.Number, realm.intrinsics().number_constructor(), attr); + define_direct_property(vm.names.Object, realm.intrinsics().object_constructor(), attr); + define_direct_property(vm.names.Promise, realm.intrinsics().promise_constructor(), attr); + define_direct_property(vm.names.Proxy, realm.intrinsics().proxy_constructor(), attr); + define_direct_property(vm.names.RangeError, realm.intrinsics().range_error_constructor(), attr); + define_direct_property(vm.names.ReferenceError, realm.intrinsics().reference_error_constructor(), attr); + define_direct_property(vm.names.RegExp, realm.intrinsics().regexp_constructor(), attr); + define_direct_property(vm.names.Set, realm.intrinsics().set_constructor(), attr); + define_direct_property(vm.names.ShadowRealm, realm.intrinsics().shadow_realm_constructor(), attr); + define_direct_property(vm.names.String, realm.intrinsics().string_constructor(), attr); + define_direct_property(vm.names.Symbol, realm.intrinsics().symbol_constructor(), attr); + define_direct_property(vm.names.SyntaxError, realm.intrinsics().syntax_error_constructor(), attr); + define_direct_property(vm.names.TypeError, realm.intrinsics().type_error_constructor(), attr); + define_direct_property(vm.names.Uint8Array, realm.intrinsics().uint8_array_constructor(), attr); + define_direct_property(vm.names.Uint8ClampedArray, realm.intrinsics().uint8_clamped_array_constructor(), attr); + define_direct_property(vm.names.Uint16Array, realm.intrinsics().uint16_array_constructor(), attr); + define_direct_property(vm.names.Uint32Array, realm.intrinsics().uint32_array_constructor(), attr); + define_direct_property(vm.names.URIError, realm.intrinsics().uri_error_constructor(), attr); + define_direct_property(vm.names.WeakMap, realm.intrinsics().weak_map_constructor(), attr); + define_direct_property(vm.names.WeakRef, realm.intrinsics().weak_ref_constructor(), attr); + define_direct_property(vm.names.WeakSet, realm.intrinsics().weak_set_constructor(), attr); + + // 19.4 Other Properties of the Global Object, https://tc39.es/ecma262/#sec-other-properties-of-the-global-object + define_direct_property(vm.names.Atomics, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Intl, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.JSON, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Math, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Reflect, heap().allocate(realm, realm), attr); + define_direct_property(vm.names.Temporal, heap().allocate(realm, realm), attr); + + // B.2.1 Additional Properties of the Global Object, https://tc39.es/ecma262/#sec-additional-properties-of-the-global-object define_native_function(realm, vm.names.escape, escape, 1, attr); define_native_function(realm, vm.names.unescape, unescape, 1, attr); - define_direct_property(vm.names.NaN, js_nan(), 0); - define_direct_property(vm.names.Infinity, js_infinity(), 0); - define_direct_property(vm.names.undefined, js_undefined(), 0); - - define_direct_property(vm.names.globalThis, this, attr); + // Non-standard + define_direct_property(vm.names.InternalError, realm.intrinsics().internal_error_constructor(), attr); define_direct_property(vm.names.console, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.Atomics, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.Math, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.JSON, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.Reflect, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.Intl, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.Temporal, heap().allocate(realm, realm), attr); + define_native_function(realm, vm.names.gc, gc, 0, attr); - // This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype. - initialize_constructor(realm, vm.names.Error, m_error_constructor, m_error_prototype); - - add_constructor(realm, vm.names.AggregateError, m_aggregate_error_constructor, m_aggregate_error_prototype); - add_constructor(realm, vm.names.Array, m_array_constructor, m_array_prototype); - add_constructor(realm, vm.names.ArrayBuffer, m_array_buffer_constructor, m_array_buffer_prototype); - add_constructor(realm, vm.names.BigInt, m_bigint_constructor, m_bigint_prototype); - add_constructor(realm, vm.names.Boolean, m_boolean_constructor, m_boolean_prototype); - add_constructor(realm, vm.names.DataView, m_data_view_constructor, m_data_view_prototype); - add_constructor(realm, vm.names.Date, m_date_constructor, m_date_prototype); - add_constructor(realm, vm.names.Error, m_error_constructor, m_error_prototype); - add_constructor(realm, vm.names.FinalizationRegistry, m_finalization_registry_constructor, m_finalization_registry_prototype); - add_constructor(realm, vm.names.Function, m_function_constructor, m_function_prototype); - add_constructor(realm, vm.names.Map, m_map_constructor, m_map_prototype); - add_constructor(realm, vm.names.Number, m_number_constructor, m_number_prototype); - add_constructor(realm, vm.names.Object, m_object_constructor, m_object_prototype); - add_constructor(realm, vm.names.Promise, m_promise_constructor, m_promise_prototype); - add_constructor(realm, vm.names.Proxy, m_proxy_constructor, nullptr); - add_constructor(realm, vm.names.RegExp, m_regexp_constructor, m_regexp_prototype); - add_constructor(realm, vm.names.Set, m_set_constructor, m_set_prototype); - add_constructor(realm, vm.names.ShadowRealm, m_shadow_realm_constructor, m_shadow_realm_prototype); - add_constructor(realm, vm.names.String, m_string_constructor, m_string_prototype); - add_constructor(realm, vm.names.Symbol, m_symbol_constructor, m_symbol_prototype); - add_constructor(realm, vm.names.WeakMap, m_weak_map_constructor, m_weak_map_prototype); - add_constructor(realm, vm.names.WeakRef, m_weak_ref_constructor, m_weak_ref_prototype); - add_constructor(realm, vm.names.WeakSet, m_weak_set_constructor, m_weak_set_prototype); - - initialize_constructor(realm, vm.names.TypedArray, m_typed_array_constructor, m_typed_array_prototype); - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - add_constructor(realm, vm.names.ClassName, m_##snake_name##_constructor, m_##snake_name##_prototype); - JS_ENUMERATE_NATIVE_ERRORS - JS_ENUMERATE_TYPED_ARRAYS -#undef __JS_ENUMERATE - - // NOTE: These constructors cannot be initialized with add_constructor as they have no global binding. - initialize_constructor(realm, vm.names.GeneratorFunction, m_generator_function_constructor, m_generator_function_prototype, Attribute::Configurable); - initialize_constructor(realm, vm.names.AsyncGeneratorFunction, m_async_generator_function_constructor, m_async_generator_function_prototype, Attribute::Configurable); - initialize_constructor(realm, vm.names.AsyncFunction, m_async_function_constructor, m_async_function_prototype, Attribute::Configurable); - - // 27.5.1.1 Generator.prototype.constructor, https://tc39.es/ecma262/#sec-generator.prototype.constructor - m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_prototype, Attribute::Configurable); - - // 27.6.1.1 AsyncGenerator.prototype.constructor, https://tc39.es/ecma262/#sec-asyncgenerator-prototype-constructor - m_async_generator_prototype->define_direct_property(vm.names.constructor, m_async_generator_function_prototype, Attribute::Configurable); - - m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function(); - m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function(); - m_eval_function = &get_without_side_effects(vm.names.eval).as_function(); - m_json_parse_function = &get_without_side_effects(vm.names.JSON).as_object().get_without_side_effects(vm.names.parse).as_function(); - m_object_prototype_to_string_function = &m_object_prototype->get_without_side_effects(vm.names.toString).as_function(); + // Assign intrinsics and functions that depend on the GlobalObject's native functions + realm.intrinsics().m_eval_function = &get_without_side_effects(vm.names.eval).as_function(); + realm.intrinsics().m_number_constructor->define_direct_property(vm.names.parseInt, get_without_side_effects(vm.names.parseInt), attr); + realm.intrinsics().m_number_constructor->define_direct_property(vm.names.parseFloat, get_without_side_effects(vm.names.parseFloat), attr); } GlobalObject::~GlobalObject() = default; -void GlobalObject::visit_edges(Visitor& visitor) -{ - Base::visit_edges(visitor); - - visitor.visit(m_empty_object_shape); - visitor.visit(m_new_object_shape); - visitor.visit(m_new_ordinary_function_prototype_object_shape); - visitor.visit(m_proxy_constructor); - visitor.visit(m_async_from_sync_iterator_prototype); - visitor.visit(m_async_generator_prototype); - visitor.visit(m_generator_prototype); - visitor.visit(m_intl_segments_prototype); - visitor.visit(m_array_prototype_values_function); - visitor.visit(m_date_constructor_now_function); - visitor.visit(m_eval_function); - visitor.visit(m_json_parse_function); - visitor.visit(m_object_prototype_to_string_function); - visitor.visit(m_throw_type_error_function); - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - visitor.visit(m_##snake_name##_constructor); \ - visitor.visit(m_##snake_name##_prototype); - JS_ENUMERATE_BUILTIN_TYPES -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - visitor.visit(m_intl_##snake_name##_constructor); \ - visitor.visit(m_intl_##snake_name##_prototype); - JS_ENUMERATE_INTL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - visitor.visit(m_temporal_##snake_name##_constructor); \ - visitor.visit(m_temporal_##snake_name##_prototype); - JS_ENUMERATE_TEMPORAL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name) \ - visitor.visit(m_##snake_name##_prototype); - JS_ENUMERATE_ITERATOR_PROTOTYPES -#undef __JS_ENUMERATE -} - Realm* GlobalObject::associated_realm() { return m_associated_realm; diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index ef9a2ae1c25..6222fcba755 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -27,86 +27,6 @@ public: Realm* associated_realm(); void set_associated_realm(Realm&); - Shape* empty_object_shape() { return m_empty_object_shape; } - - Shape* new_object_shape() { return m_new_object_shape; } - Shape* new_ordinary_function_prototype_object_shape() { return m_new_ordinary_function_prototype_object_shape; } - - // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype - ProxyConstructor* proxy_constructor() { return m_proxy_constructor; } - - // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor - Object* async_from_sync_iterator_prototype() { return m_async_from_sync_iterator_prototype; } - Object* async_generator_prototype() { return m_async_generator_prototype; } - Object* generator_prototype() { return m_generator_prototype; } - - // Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%) - Object* async_generator_function_prototype_prototype() { return m_async_generator_prototype; } - // Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%) - Object* generator_function_prototype_prototype() { return m_generator_prototype; } - - // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor - Object* intl_segments_prototype() { return m_intl_segments_prototype; } - - FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; } - FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; } - FunctionObject* eval_function() const { return m_eval_function; } - FunctionObject* json_parse_function() const { return m_json_parse_function; } - FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; } - FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; } - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - ConstructorName* snake_name##_constructor() \ - { \ - return m_##snake_name##_constructor; \ - } \ - Object* snake_name##_prototype() \ - { \ - return m_##snake_name##_prototype; \ - } - JS_ENUMERATE_BUILTIN_TYPES -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - Intl::ConstructorName* intl_##snake_name##_constructor() \ - { \ - return m_intl_##snake_name##_constructor; \ - } \ - Object* intl_##snake_name##_prototype() \ - { \ - return m_intl_##snake_name##_prototype; \ - } - JS_ENUMERATE_INTL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - Temporal::ConstructorName* temporal_##snake_name##_constructor() \ - { \ - return m_temporal_##snake_name##_constructor; \ - } \ - Object* temporal_##snake_name##_prototype() \ - { \ - return m_temporal_##snake_name##_prototype; \ - } - JS_ENUMERATE_TEMPORAL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name) \ - Object* snake_name##_prototype() \ - { \ - return m_##snake_name##_prototype; \ - } - JS_ENUMERATE_ITERATOR_PROTOTYPES -#undef __JS_ENUMERATE - -protected: - virtual void visit_edges(Visitor&) override; - - template - void initialize_constructor(Realm&, PropertyKey const&, ConstructorType*&, Object* prototype, PropertyAttributes = Attribute::Writable | Attribute::Configurable); - template - void add_constructor(Realm&, PropertyKey const&, ConstructorType*&, Object* prototype); - private: virtual bool is_global_object() const final { return true; } @@ -124,74 +44,9 @@ private: JS_DECLARE_NATIVE_FUNCTION(unescape); NonnullOwnPtr m_console; - WeakPtr m_associated_realm; - - Shape* m_empty_object_shape { nullptr }; - Shape* m_new_object_shape { nullptr }; - Shape* m_new_ordinary_function_prototype_object_shape { nullptr }; - - // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype - ProxyConstructor* m_proxy_constructor { nullptr }; - - // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor - Object* m_async_from_sync_iterator_prototype { nullptr }; - Object* m_async_generator_prototype { nullptr }; - Object* m_generator_prototype { nullptr }; - - // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor - Object* m_intl_segments_prototype { nullptr }; - - FunctionObject* m_array_prototype_values_function { nullptr }; - FunctionObject* m_date_constructor_now_function { nullptr }; - FunctionObject* m_eval_function { nullptr }; - FunctionObject* m_json_parse_function { nullptr }; - FunctionObject* m_object_prototype_to_string_function { nullptr }; - FunctionObject* m_throw_type_error_function { nullptr }; - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ - ConstructorName* m_##snake_name##_constructor { nullptr }; \ - Object* m_##snake_name##_prototype { nullptr }; - JS_ENUMERATE_BUILTIN_TYPES -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - Intl::ConstructorName* m_intl_##snake_name##_constructor { nullptr }; \ - Object* m_intl_##snake_name##_prototype { nullptr }; - JS_ENUMERATE_INTL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ - Temporal::ConstructorName* m_temporal_##snake_name##_constructor { nullptr }; \ - Object* m_temporal_##snake_name##_prototype { nullptr }; - JS_ENUMERATE_TEMPORAL_OBJECTS -#undef __JS_ENUMERATE - -#define __JS_ENUMERATE(ClassName, snake_name) \ - Object* m_##snake_name##_prototype { nullptr }; - JS_ENUMERATE_ITERATOR_PROTOTYPES -#undef __JS_ENUMERATE }; -template -inline void GlobalObject::initialize_constructor(Realm& realm, PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes) -{ - auto& vm = this->vm(); - constructor = heap().allocate(realm, realm); - constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable); - if (prototype) - prototype->define_direct_property(vm.names.constructor, constructor, attributes); -} - -template -inline void GlobalObject::add_constructor(Realm& realm, PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype) -{ - // Some constructors are pre-initialized separately. - if (!constructor) - initialize_constructor(realm, property_key, constructor, prototype); - define_direct_property(property_key, constructor, Attribute::Writable | Attribute::Configurable); -} - inline GlobalObject* Shape::global_object() const { return &static_cast(m_realm.global_object()); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp index 18b2eff6da0..4f1cb868a25 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp @@ -17,7 +17,7 @@ CollatorCompareFunction* CollatorCompareFunction::create(Realm& realm, Collator& } CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) , m_collator(collator) { } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp index 3e0078f8612..d6574943e7a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp @@ -131,7 +131,7 @@ static ThrowCompletionOr initialize_collator(VM& vm, Collator& collat // 10.1 The Intl.Collator Constructor, https://tc39.es/ecma402/#sec-the-intl-collator-constructor CollatorConstructor::CollatorConstructor(Realm& realm) - : NativeFunction(vm().names.Collator.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Collator.as_string(), *realm.intrinsics().function_prototype()) { } @@ -142,7 +142,7 @@ void CollatorConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 10.2.1 Intl.Collator.prototype, https://tc39.es/ecma402/#sec-intl.collator.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_collator_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_collator_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -171,7 +171,7 @@ ThrowCompletionOr CollatorConstructor::construct(FunctionObject& new_ta // a. Append [[CaseFirst]] as the last element of internalSlotsList. // 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%Collator.prototype%", internalSlotsList). - auto* collator = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_collator_prototype)); + auto* collator = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_collator_prototype)); // 6. Return ? InitializeCollator(collator, locales, options). return TRY(initialize_collator(vm, *collator, locales, options)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp index 467e185c653..78c65fd1f9a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp @@ -13,7 +13,7 @@ namespace JS::Intl { // 10.3 Properties of the Intl.Collator Prototype Object, https://tc39.es/ecma402/#sec-properties-of-the-intl-collator-prototype-object CollatorPrototype::CollatorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options) auto* collator = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 3, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index b5ebf23dcad..9737c4d4f35 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -545,7 +545,7 @@ ThrowCompletionOr> format_date_time_pattern(VM& vm, Dat auto const& data_locale = date_time_format.data_locale(); auto construct_number_format = [&](auto* options) -> ThrowCompletionOr { - auto* number_format = TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale), options)); + auto* number_format = TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, locale), options)); return static_cast(number_format); }; @@ -861,7 +861,7 @@ ThrowCompletionOr 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, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); @@ -1175,7 +1175,7 @@ ThrowCompletionOr 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, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp index cba490fe7e5..c514140f417 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp @@ -18,7 +18,7 @@ namespace JS::Intl { // 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor DateTimeFormatConstructor::DateTimeFormatConstructor(Realm& realm) - : NativeFunction(vm().names.DateTimeFormat.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.DateTimeFormat.as_string(), *realm.intrinsics().function_prototype()) { } @@ -29,7 +29,7 @@ void DateTimeFormatConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 11.2.1 Intl.DateTimeFormat.prototype, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_date_time_format_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_date_time_format_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr); @@ -53,7 +53,7 @@ ThrowCompletionOr DateTimeFormatConstructor::construct(FunctionObject& auto options = vm.argument(1); // 2. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%DateTimeFormat.prototype%", « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] »). - auto* date_time_format = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_date_time_format_prototype)); + auto* date_time_format = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_date_time_format_prototype)); // 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options). TRY(initialize_date_time_format(vm, *date_time_format, locales, options)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp index e796859c766..86acca212cc 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatFunction.cpp @@ -16,7 +16,7 @@ namespace JS::Intl { // 11.5.5 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions DateTimeFormatFunction* DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format) { - return realm.heap().allocate(realm, date_time_format, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, date_time_format, *realm.intrinsics().function_prototype()); } DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype) @@ -49,7 +49,7 @@ ThrowCompletionOr 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, realm.global_object().date_constructor_now_function(), js_undefined())).as_double(); + date_value = MUST(JS::call(vm, realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double(); } // 4. Else, else { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp index 19818edda7d..a1edbedcff0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp @@ -15,7 +15,7 @@ namespace JS::Intl { // 11.3 Properties of the Intl.DateTimeFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-datetimeformat-prototype-object DateTimeFormatPrototype::DateTimeFormatPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -78,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts) // 3. If date is undefined, then if (date.is_undefined()) { // a. Let x be ! Call(%Date.now%, undefined). - date_value = MUST(call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double(); + date_value = MUST(call(vm, realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double(); } // 4. Else, else { @@ -155,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options) auto* date_time_format = TRY(typed_this_object(vm)); // 4. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 5. For each row of Table 5, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp index 27ab0c78b55..7eb1d427593 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp @@ -115,7 +115,7 @@ ThrowCompletionOr canonical_code_for_display_names(VM& vm, DisplayNames:: return vm.throw_completion(ErrorType::IntlInvalidLanguageTag, code); // c. Return ! CanonicalizeUnicodeLocaleId(code). - auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id); + auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id); return js_string(vm, move(canonicalized_tag)); } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp index 23639a2748a..1e8d0d508c1 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesConstructor.cpp @@ -17,7 +17,7 @@ namespace JS::Intl { // 12.1 The Intl.DisplayNames Constructor, https://tc39.es/ecma402/#sec-intl-displaynames-constructor DisplayNamesConstructor::DisplayNamesConstructor(Realm& realm) - : NativeFunction(vm().names.DisplayNames.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.DisplayNames.as_string(), *realm.intrinsics().function_prototype()) { } @@ -28,7 +28,7 @@ void DisplayNamesConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 12.2.1 Intl.DisplayNames.prototype, https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_display_names_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_display_names_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr); @@ -52,7 +52,7 @@ ThrowCompletionOr DisplayNamesConstructor::construct(FunctionObject& ne auto options_value = vm.argument(1); // 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[LanguageDisplay]], [[Fields]] »). - auto* display_names = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_display_names_prototype)); + auto* display_names = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_display_names_prototype)); // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp index e1a695c32c1..3d8bf33511c 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp @@ -15,7 +15,7 @@ namespace JS::Intl { // 12.3 Properties of the Intl.DisplayNames Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-displaynames-prototype-object DisplayNamesPrototype::DisplayNamesPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -131,7 +131,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options) auto* display_names = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 8, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index aa87496f489..83d3aa1a0ed 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -402,7 +402,7 @@ ThrowCompletionOr> partition_duration_format_pattern(VM } // o. Let nf be ? Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »). - auto* number_format = static_cast(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options))); + auto* number_format = static_cast(TRY(construct(vm, *realm.intrinsics().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). @@ -431,7 +431,7 @@ ThrowCompletionOr> partition_duration_format_pattern(VM // t. Else, else { // i. Let pr be ? Construct(%PluralRules%, « durationFormat.[[Locale]] »). - auto* plural_rules = TRY(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, duration_format.locale()))); + auto* plural_rules = TRY(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), js_string(vm, duration_format.locale()))); // ii. Let prv be ! ResolvePlural(pr, value). auto plurality = resolve_plural(static_cast(*plural_rules), value); @@ -479,7 +479,7 @@ ThrowCompletionOr> partition_duration_format_pattern(VM } // 3. Let lf be ? Construct(%ListFormat%, « durationFormat.[[Locale]] »). - auto* list_format = static_cast(TRY(construct(vm, *realm.global_object().intl_list_format_constructor(), js_string(vm, duration_format.locale())))); + auto* list_format = static_cast(TRY(construct(vm, *realm.intrinsics().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 diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp index 25ad59d8599..435159b43bd 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp @@ -15,7 +15,7 @@ namespace JS::Intl { // 1.2 The Intl.DurationFormat Constructor, https://tc39.es/proposal-intl-duration-format/#sec-intl-durationformat-constructor DurationFormatConstructor::DurationFormatConstructor(Realm& realm) - : NativeFunction(vm().names.DurationFormat.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.DurationFormat.as_string(), *realm.intrinsics().function_prototype()) { } @@ -26,7 +26,7 @@ void DurationFormatConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 1.3.1 Intl.DurationFormat.prototype, https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_duration_format_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_duration_format_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -49,7 +49,7 @@ ThrowCompletionOr DurationFormatConstructor::construct(FunctionObject& auto options_value = vm.argument(1); // 2. Let durationFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%DurationFormatPrototype%", « [[InitializedDurationFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[YearsStyle]], [[YearsDisplay]], [[MonthsStyle]], [[MonthsDisplay]] , [[WeeksStyle]], [[WeeksDisplay]] , [[DaysStyle]], [[DaysDisplay]] , [[HoursStyle]], [[HoursDisplay]] , [[MinutesStyle]], [[MinutesDisplay]] , [[SecondsStyle]], [[SecondsDisplay]] , [[MillisecondsStyle]], [[MillisecondsDisplay]] , [[MicrosecondsStyle]], [[MicrosecondsDisplay]] , [[NanosecondsStyle]], [[NanosecondsDisplay]], [[FractionalDigits]] »). - auto* duration_format = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_duration_format_prototype)); + auto* duration_format = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_duration_format_prototype)); // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locales)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp index 620e6329208..2ebb5f178d3 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp @@ -12,7 +12,7 @@ namespace JS::Intl { // 1.4 Properties of the Intl.DurationFormat Prototype Object, https://tc39.es/proposal-intl-duration-format/#sec-properties-of-intl-durationformat-prototype-object DurationFormatPrototype::DurationFormatPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts) auto const& part = formatted[n]; // a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%). - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); @@ -117,7 +117,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options) auto* duration_format = TRY(typed_this_object(vm)); // 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 2, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp index 23db1e7bd01..776da44fc4f 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp @@ -29,7 +29,7 @@ namespace JS::Intl { // 8 The Intl Object, https://tc39.es/ecma402/#intl-object Intl::Intl(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } @@ -43,16 +43,16 @@ void Intl::initialize(Realm& realm) define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl"), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; - define_direct_property(vm.names.Collator, realm.global_object().intl_collator_constructor(), attr); - define_direct_property(vm.names.DateTimeFormat, realm.global_object().intl_date_time_format_constructor(), attr); - define_direct_property(vm.names.DisplayNames, realm.global_object().intl_display_names_constructor(), attr); - define_direct_property(vm.names.DurationFormat, realm.global_object().intl_duration_format_constructor(), attr); - define_direct_property(vm.names.ListFormat, realm.global_object().intl_list_format_constructor(), attr); - define_direct_property(vm.names.Locale, realm.global_object().intl_locale_constructor(), attr); - define_direct_property(vm.names.NumberFormat, realm.global_object().intl_number_format_constructor(), attr); - define_direct_property(vm.names.PluralRules, realm.global_object().intl_plural_rules_constructor(), attr); - define_direct_property(vm.names.RelativeTimeFormat, realm.global_object().intl_relative_time_format_constructor(), attr); - define_direct_property(vm.names.Segmenter, realm.global_object().intl_segmenter_constructor(), attr); + define_direct_property(vm.names.Collator, realm.intrinsics().intl_collator_constructor(), attr); + define_direct_property(vm.names.DateTimeFormat, realm.intrinsics().intl_date_time_format_constructor(), attr); + define_direct_property(vm.names.DisplayNames, realm.intrinsics().intl_display_names_constructor(), attr); + define_direct_property(vm.names.DurationFormat, realm.intrinsics().intl_duration_format_constructor(), attr); + define_direct_property(vm.names.ListFormat, realm.intrinsics().intl_list_format_constructor(), attr); + define_direct_property(vm.names.Locale, realm.intrinsics().intl_locale_constructor(), attr); + define_direct_property(vm.names.NumberFormat, realm.intrinsics().intl_number_format_constructor(), attr); + define_direct_property(vm.names.PluralRules, realm.intrinsics().intl_plural_rules_constructor(), attr); + define_direct_property(vm.names.RelativeTimeFormat, realm.intrinsics().intl_relative_time_format_constructor(), attr); + define_direct_property(vm.names.Segmenter, realm.intrinsics().intl_segmenter_constructor(), attr); define_native_function(realm, vm.names.getCanonicalLocales, get_canonical_locales, 1, attr); define_native_function(realm, vm.names.supportedValuesOf, supported_values_of, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index 5401ebd3fcb..1a9d309168e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -217,7 +217,7 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vectorcreate_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp index 4fff63e2265..736db6606da 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatConstructor.cpp @@ -16,7 +16,7 @@ namespace JS::Intl { // 13.1 The Intl.ListFormat Constructor, https://tc39.es/ecma402/#sec-intl-listformat-constructor ListFormatConstructor::ListFormatConstructor(Realm& realm) - : NativeFunction(vm().names.ListFormat.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.ListFormat.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void ListFormatConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 13.2.1 Intl.ListFormat.prototype, https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_list_format_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_list_format_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr); @@ -51,7 +51,7 @@ ThrowCompletionOr ListFormatConstructor::construct(FunctionObject& new_ auto options_value = vm.argument(1); // 2. Let listFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]], [[Type]], [[Style]], [[Templates]] »). - auto* list_format = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_list_format_prototype)); + auto* list_format = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_list_format_prototype)); // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp index 5368c75a423..0e9a563c22a 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp @@ -14,7 +14,7 @@ namespace JS::Intl { // 13.3 Properties of the Intl.ListFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-listformat-prototype-object ListFormatPrototype::ListFormatPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -76,7 +76,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options) auto* list_format = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 10, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp index c3ebe6d052b..19aef1ed8ca 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp @@ -16,7 +16,7 @@ namespace JS::Intl { Locale* Locale::create(Realm& realm, Unicode::LocaleID const& locale_id) { - return realm.heap().allocate(realm, locale_id, *realm.global_object().intl_locale_prototype()); + return realm.heap().allocate(realm, locale_id, *realm.intrinsics().intl_locale_prototype()); } // 14 Locale Objects, https://tc39.es/ecma402/#locale-objects diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp index 4af821bdbc3..c754f6a426e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp @@ -65,7 +65,7 @@ static ThrowCompletionOr apply_options_to_tag(VM& vm, StringView tag, Ob auto region = TRY(get_string_option(vm, options, vm.names.region, Unicode::is_unicode_region_subtag)); // 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag). - auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id); + auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id); // 11. Assert: tag matches the unicode_locale_id production. locale_id = Unicode::parse_unicode_locale_id(canonicalized_tag); @@ -217,7 +217,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey // 14.1 The Intl.Locale Constructor, https://tc39.es/ecma402/#sec-intl-locale-constructor LocaleConstructor::LocaleConstructor(Realm& realm) - : NativeFunction(vm().names.Locale.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Locale.as_string(), *realm.intrinsics().function_prototype()) { } @@ -228,7 +228,7 @@ void LocaleConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 14.2.1 Intl.Locale.prototype, https://tc39.es/ecma402/#sec-Intl.Locale.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_locale_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_locale_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -257,7 +257,7 @@ ThrowCompletionOr LocaleConstructor::construct(FunctionObject& new_targ // a. Append [[Numeric]] as the last element of internalSlotsList. // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, "%Locale.prototype%", internalSlotsList). - auto* locale = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_locale_prototype)); + auto* locale = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_locale_prototype)); String tag; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp index 4408032d8c8..0a48452eb76 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp @@ -15,7 +15,7 @@ namespace JS::Intl { // 14.3 Properties of the Intl.Locale Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-locale-prototype-object LocalePrototype::LocalePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -258,7 +258,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info) auto* locale_object = TRY(typed_this_object(vm)); // 3. Let info be ! ObjectCreate(%Object.prototype%). - auto* info = Object::create(realm, realm.global_object().object_prototype()); + auto* info = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Let dir be ! CharacterDirectionOfLocale(loc). auto direction = character_direction_of_locale(*locale_object); @@ -280,7 +280,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info) [[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm)); // 3. Let info be ! ObjectCreate(%Object.prototype%). - auto* info = Object::create(realm, realm.global_object().object_prototype()); + auto* info = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Let wi be ! WeekInfoOfLocale(loc). auto week_info = week_info_of_locale(*locale_object); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index 23ad1c2be2c..ec1bd9e182d 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -922,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, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); @@ -1837,7 +1837,7 @@ ThrowCompletionOr 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, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp index 9c4df7ca913..92323acc1f0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatConstructor.cpp @@ -15,7 +15,7 @@ namespace JS::Intl { // 15.1 The Intl.NumberFormat Constructor, https://tc39.es/ecma402/#sec-intl-numberformat-constructor NumberFormatConstructor::NumberFormatConstructor(Realm& realm) - : NativeFunction(vm().names.NumberFormat.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.NumberFormat.as_string(), *realm.intrinsics().function_prototype()) { } @@ -26,7 +26,7 @@ void NumberFormatConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 15.2.1 Intl.NumberFormat.prototype, https://tc39.es/ecma402/#sec-intl.numberformat.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_number_format_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_number_format_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr); @@ -50,7 +50,7 @@ ThrowCompletionOr NumberFormatConstructor::construct(FunctionObject& ne auto options = vm.argument(1); // 2. Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormat.prototype%", « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »). - auto* number_format = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_number_format_prototype)); + auto* number_format = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_number_format_prototype)); // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options). TRY(initialize_number_format(vm, *number_format, locales, options)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp index 2bd13528d5f..2d434de3a97 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatFunction.cpp @@ -14,7 +14,7 @@ namespace JS::Intl { // 1.1.4 Number Format Functions, https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-number-format-functions NumberFormatFunction* NumberFormatFunction::create(Realm& realm, NumberFormat& number_format) { - return realm.heap().allocate(realm, number_format, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, number_format, *realm.intrinsics().function_prototype()); } NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp index f3fafaf2a0d..403d8b5f530 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp @@ -15,7 +15,7 @@ namespace JS::Intl { // 15.3 Properties of the Intl.NumberFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-numberformat-prototype-object NumberFormatPrototype::NumberFormatPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -145,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options) auto* number_format = TRY(typed_this_object(vm)); // 4. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 5. For each row of Table 11, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp index aa301d07880..b0dec35b967 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesConstructor.cpp @@ -17,7 +17,7 @@ namespace JS::Intl { // 16.1 The Intl.PluralRules Constructor, https://tc39.es/ecma402/#sec-intl-pluralrules-constructor PluralRulesConstructor::PluralRulesConstructor(Realm& realm) - : NativeFunction(vm().names.PluralRules.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.PluralRules.as_string(), *realm.intrinsics().function_prototype()) { } @@ -28,7 +28,7 @@ void PluralRulesConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 16.2.1 Intl.PluralRules.prototype, https://tc39.es/ecma402/#sec-intl.pluralrules.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_plural_rules_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_plural_rules_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -51,7 +51,7 @@ ThrowCompletionOr PluralRulesConstructor::construct(FunctionObject& new auto options = vm.argument(1); // 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRules.prototype%", « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »). - auto* plural_rules = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_plural_rules_prototype)); + auto* plural_rules = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_plural_rules_prototype)); // 3. Return ? InitializePluralRules(pluralRules, locales, options). return TRY(initialize_plural_rules(vm, *plural_rules, locales, options)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp index 5245d708a53..66f51d233a5 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp @@ -14,7 +14,7 @@ namespace JS::Intl { // 16.3 Properties of the Intl.PluralRules Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-pluralrules-prototype-object PluralRulesPrototype::PluralRulesPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -86,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options) auto* plural_rules = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 13, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp index 96fac8169a3..3781b84ccdd 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp @@ -257,7 +257,7 @@ ThrowCompletionOr 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, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp index 9896a1b62a2..4308395f2ab 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatConstructor.cpp @@ -20,7 +20,7 @@ namespace JS::Intl { // 17.1 The Intl.RelativeTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor RelativeTimeFormatConstructor::RelativeTimeFormatConstructor(Realm& realm) - : NativeFunction(vm().names.RelativeTimeFormat.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.RelativeTimeFormat.as_string(), *realm.intrinsics().function_prototype()) { } @@ -31,7 +31,7 @@ void RelativeTimeFormatConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 17.2.1 Intl.RelativeTimeFormat.prototype, https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_relative_time_format_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_relative_time_format_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -54,7 +54,7 @@ ThrowCompletionOr RelativeTimeFormatConstructor::construct(FunctionObje auto options = vm.argument(1); // 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%RelativeTimeFormat.prototype%", « [[InitializedRelativeTimeFormat]], [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). - auto* relative_time_format = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_relative_time_format_prototype)); + auto* relative_time_format = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_relative_time_format_prototype)); // 3. Return ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options). return TRY(initialize_relative_time_format(vm, *relative_time_format, locales, options)); @@ -138,11 +138,11 @@ ThrowCompletionOr 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, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale))); + auto* number_format = MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, locale))); relative_time_format.set_number_format(static_cast(number_format)); // 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »). - auto* plural_rules = MUST(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, locale))); + auto* plural_rules = MUST(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), js_string(vm, locale))); relative_time_format.set_plural_rules(static_cast(plural_rules)); // 21. Return relativeTimeFormat. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp index 583d0115136..21ab4500e8e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp @@ -12,7 +12,7 @@ namespace JS::Intl { // 17.3 Properties of the Intl.RelativeTimeFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-relativetimeformat-prototype-object RelativeTimeFormatPrototype::RelativeTimeFormatPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -76,7 +76,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options) auto* relative_time_format = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 15, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp index a24ce1a082d..ecba77b752c 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp @@ -24,7 +24,7 @@ SegmentIterator* SegmentIterator::create(Realm& realm, Segmenter& segmenter, Utf // 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects SegmentIterator::SegmentIterator(Realm& realm, Segmenter& segmenter, Utf16View const& string, Segments const& segments) - : Object(*realm.global_object().intl_segment_iterator_prototype()) + : Object(*realm.intrinsics().intl_segment_iterator_prototype()) , m_iterating_segmenter(segmenter) , m_iterated_string(string) , m_segments(segments) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIteratorPrototype.cpp index cdafeeb66e8..9854ee73144 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIteratorPrototype.cpp @@ -14,7 +14,7 @@ namespace JS::Intl { // 18.6.2 The %SegmentIteratorPrototype% Object, https://tc39.es/ecma402/#sec-%segmentiteratorprototype%-object SegmentIteratorPrototype::SegmentIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp index 6bfaa33655e..0323aceb6c9 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.cpp @@ -62,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, realm.global_object().object_prototype()); + auto* result = Object::create(realm, realm.intrinsics().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); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp index e10e8760d0e..1fe7d8b8fa6 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterConstructor.cpp @@ -16,7 +16,7 @@ namespace JS::Intl { // 18.1 The Intl.Segmenter Constructor, https://tc39.es/ecma402/#sec-intl-segmenter-constructor SegmenterConstructor::SegmenterConstructor(Realm& realm) - : NativeFunction(vm().names.Segmenter.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Segmenter.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void SegmenterConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 18.2.1 Intl.Segmenter.prototype, https://tc39.es/ecma402/#sec-intl.segmenter.prototype - define_direct_property(vm.names.prototype, realm.global_object().intl_segmenter_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().intl_segmenter_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; @@ -51,7 +51,7 @@ ThrowCompletionOr SegmenterConstructor::construct(FunctionObject& new_t // 2. Let internalSlotsList be « [[InitializedSegmenter]], [[Locale]], [[SegmenterGranularity]] ». // 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList). - auto* segmenter = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::intl_segmenter_prototype)); + auto* segmenter = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::intl_segmenter_prototype)); // 4. Let requestedLocales be ? CanonicalizeLocaleList(locales). auto requested_locales = TRY(canonicalize_locale_list(vm, locales)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp index a883115b6ba..a0fd1e7bce8 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp @@ -13,7 +13,7 @@ namespace JS::Intl { // 18.3 Properties of the Intl.Segmenter Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-segmenter-prototype-object SegmenterPrototype::SegmenterPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -41,7 +41,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options) auto* segmenter = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, realm.global_object().object_prototype()); + auto* options = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each row of Table 16, except the header row, in table order, do // a. Let p be the Property value of the current row. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp index 4ea60d65659..e3bc76f843e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp @@ -23,7 +23,7 @@ Segments* Segments::create(Realm& realm, Segmenter& segmenter, Utf16String strin // 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects Segments::Segments(Realm& realm, Segmenter& segmenter, Utf16String string) - : Object(*realm.global_object().intl_segments_prototype()) + : Object(*realm.intrinsics().intl_segments_prototype()) , m_segments_segmenter(segmenter) , m_segments_string(move(string)) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp index aa59db68506..aba326ecfb4 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp @@ -13,7 +13,7 @@ namespace JS::Intl { // 18.5.2 The %SegmentsPrototype% Object, https://tc39.es/ecma402/#sec-%segmentsprototype%-object SegmentsPrototype::SegmentsPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp new file mode 100644 index 00000000000..c7ae6642acf --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.cpp @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace JS { + +static void initialize_constructor(VM& vm, PropertyKey const& property_key, Object& constructor, Object* prototype, PropertyAttributes constructor_property_attributes = Attribute::Writable | Attribute::Configurable) +{ + constructor.define_direct_property(vm.names.name, js_string(vm, property_key.as_string()), Attribute::Configurable); + if (prototype) + prototype->define_direct_property(vm.names.constructor, &constructor, constructor_property_attributes); +} + +// 9.3.2 CreateIntrinsics ( realmRec ), https://tc39.es/ecma262/#sec-createintrinsics +Intrinsics* Intrinsics::create(Realm& realm) +{ + auto& vm = realm.vm(); + + // 1. Set realmRec.[[Intrinsics]] to a new Record. + auto* intrinsics = vm.heap().allocate_without_realm(); + realm.set_intrinsics({}, *intrinsics); + + // 2. Set fields of realmRec.[[Intrinsics]] with the values listed in Table 6. + // The field names are the names listed in column one of the table. + // The value of each field is a new object value fully and recursively populated + // with property values as defined by the specification of each object in + // clauses 19 through 28. All object property values are newly created object + // values. All values that are built-in function objects are created by performing + // CreateBuiltinFunction(steps, length, name, slots, realmRec, prototype) + // where steps is the definition of that function provided by this specification, + // name is the initial value of the function's "name" property, length is the + // initial value of the function's "length" property, slots is a list of the + // names, if any, of the function's specified internal slots, and prototype + // is the specified value of the function's [[Prototype]] internal slot. The + // creation of the intrinsics and their properties must be ordered to avoid + // any dependencies upon objects that have not yet been created. + intrinsics->initialize_intrinsics(realm); + + // 3. Perform AddRestrictedFunctionProperties(realmRec.[[Intrinsics]].[[%Function.prototype%]], realmRec). + add_restricted_function_properties(static_cast(*realm.intrinsics().function_prototype()), realm); + + // 4. Return unused. + return intrinsics; +} + +void Intrinsics::initialize_intrinsics(Realm& realm) +{ + auto& vm = this->vm(); + + // These are done first since other prototypes depend on their presence. + m_empty_object_shape = heap().allocate_without_realm(realm); + m_object_prototype = heap().allocate_without_realm(realm); + m_function_prototype = heap().allocate_without_realm(realm); + + m_new_object_shape = heap().allocate_without_realm(realm); + m_new_object_shape->set_prototype_without_transition(m_object_prototype); + + m_new_ordinary_function_prototype_object_shape = heap().allocate_without_realm(realm); + m_new_ordinary_function_prototype_object_shape->set_prototype_without_transition(m_object_prototype); + m_new_ordinary_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable); + + // Normally Heap::allocate() takes care of this, but these are allocated via allocate_without_realm(). + static_cast(m_function_prototype)->initialize(realm); + static_cast(m_object_prototype)->initialize(realm); + +#define __JS_ENUMERATE(ClassName, snake_name) \ + VERIFY(!m_##snake_name##_prototype); \ + m_##snake_name##_prototype = heap().allocate(realm, realm); + JS_ENUMERATE_ITERATOR_PROTOTYPES +#undef __JS_ENUMERATE + + // These must be initialized separately as they have no companion constructor + m_async_from_sync_iterator_prototype = heap().allocate(realm, realm); + m_async_generator_prototype = heap().allocate(realm, realm); + m_generator_prototype = heap().allocate(realm, realm); + m_intl_segments_prototype = heap().allocate(realm, realm); + + // These must be initialized before allocating... + // - AggregateErrorPrototype, which uses ErrorPrototype as its prototype + // - AggregateErrorConstructor, which uses ErrorConstructor as its prototype + // - AsyncFunctionConstructor, which uses FunctionConstructor as its prototype + m_error_prototype = heap().allocate(realm, realm); + m_error_constructor = heap().allocate(realm, realm); + m_function_constructor = heap().allocate(realm, realm); + + // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype + m_proxy_constructor = heap().allocate(realm, realm); + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + /* These are the prototypes allocated earlier, everything else must not yet exist.*/ \ + if constexpr (!IsOneOf) { \ + VERIFY(!m_##snake_name##_prototype); \ + m_##snake_name##_prototype = heap().allocate(realm, realm); \ + } \ + if constexpr (!IsOneOf) { \ + VERIFY(!m_##snake_name##_constructor); \ + m_##snake_name##_constructor = heap().allocate(realm, realm); \ + } + JS_ENUMERATE_BUILTIN_TYPES +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + VERIFY(!m_intl_##snake_name##_constructor); \ + VERIFY(!m_intl_##snake_name##_prototype); \ + m_intl_##snake_name##_prototype = heap().allocate(realm, realm); \ + m_intl_##snake_name##_constructor = heap().allocate(realm, realm); \ + initialize_constructor(vm, vm.names.ClassName, *m_intl_##snake_name##_constructor, m_intl_##snake_name##_prototype); + JS_ENUMERATE_INTL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + VERIFY(!m_temporal_##snake_name##_constructor); \ + VERIFY(!m_temporal_##snake_name##_prototype); \ + m_temporal_##snake_name##_prototype = heap().allocate(realm, realm); \ + m_temporal_##snake_name##_constructor = heap().allocate(realm, realm); \ + initialize_constructor(vm, vm.names.ClassName, *m_temporal_##snake_name##_constructor, m_temporal_##snake_name##_prototype); + JS_ENUMERATE_TEMPORAL_OBJECTS +#undef __JS_ENUMERATE + + // 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror% + m_throw_type_error_function = NativeFunction::create( + realm, [](VM& vm) { + return vm.throw_completion(ErrorType::RestrictedFunctionPropertiesAccess); + }, + 0, "", &realm); + m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0); + m_throw_type_error_function->define_direct_property(vm.names.name, js_string(vm, ""), 0); + MUST(m_throw_type_error_function->internal_prevent_extensions()); + +#define __JS_ENUMERATE(ClassName, snake_name) \ + VERIFY(!m_##snake_name##_object); \ + m_##snake_name##_object = heap().allocate(realm, realm); + JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS +#undef __JS_ENUMERATE + + initialize_constructor(vm, vm.names.AggregateError, *m_aggregate_error_constructor, m_aggregate_error_prototype); + initialize_constructor(vm, vm.names.Array, *m_array_constructor, m_array_prototype); + initialize_constructor(vm, vm.names.ArrayBuffer, *m_array_buffer_constructor, m_array_buffer_prototype); + initialize_constructor(vm, vm.names.BigInt, *m_bigint_constructor, m_bigint_prototype); + initialize_constructor(vm, vm.names.Boolean, *m_boolean_constructor, m_boolean_prototype); + initialize_constructor(vm, vm.names.DataView, *m_data_view_constructor, m_data_view_prototype); + initialize_constructor(vm, vm.names.Date, *m_date_constructor, m_date_prototype); + initialize_constructor(vm, vm.names.Error, *m_error_constructor, m_error_prototype); + initialize_constructor(vm, vm.names.FinalizationRegistry, *m_finalization_registry_constructor, m_finalization_registry_prototype); + initialize_constructor(vm, vm.names.Function, *m_function_constructor, m_function_prototype); + initialize_constructor(vm, vm.names.Map, *m_map_constructor, m_map_prototype); + initialize_constructor(vm, vm.names.Number, *m_number_constructor, m_number_prototype); + initialize_constructor(vm, vm.names.Object, *m_object_constructor, m_object_prototype); + initialize_constructor(vm, vm.names.Promise, *m_promise_constructor, m_promise_prototype); + initialize_constructor(vm, vm.names.Proxy, *m_proxy_constructor, nullptr); + initialize_constructor(vm, vm.names.RegExp, *m_regexp_constructor, m_regexp_prototype); + initialize_constructor(vm, vm.names.Set, *m_set_constructor, m_set_prototype); + initialize_constructor(vm, vm.names.ShadowRealm, *m_shadow_realm_constructor, m_shadow_realm_prototype); + initialize_constructor(vm, vm.names.String, *m_string_constructor, m_string_prototype); + initialize_constructor(vm, vm.names.Symbol, *m_symbol_constructor, m_symbol_prototype); + initialize_constructor(vm, vm.names.TypedArray, *m_typed_array_constructor, m_typed_array_prototype); + initialize_constructor(vm, vm.names.WeakMap, *m_weak_map_constructor, m_weak_map_prototype); + initialize_constructor(vm, vm.names.WeakRef, *m_weak_ref_constructor, m_weak_ref_prototype); + initialize_constructor(vm, vm.names.WeakSet, *m_weak_set_constructor, m_weak_set_prototype); + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + initialize_constructor(vm, vm.names.ClassName, *m_##snake_name##_constructor, m_##snake_name##_prototype); + JS_ENUMERATE_NATIVE_ERRORS + JS_ENUMERATE_TYPED_ARRAYS +#undef __JS_ENUMERATE + + initialize_constructor(vm, vm.names.GeneratorFunction, *m_generator_function_constructor, m_generator_function_prototype, Attribute::Configurable); + initialize_constructor(vm, vm.names.AsyncGeneratorFunction, *m_async_generator_function_constructor, m_async_generator_function_prototype, Attribute::Configurable); + initialize_constructor(vm, vm.names.AsyncFunction, *m_async_function_constructor, m_async_function_prototype, Attribute::Configurable); + + // 27.5.1.1 Generator.prototype.constructor, https://tc39.es/ecma262/#sec-generator.prototype.constructor + m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_prototype, Attribute::Configurable); + + // 27.6.1.1 AsyncGenerator.prototype.constructor, https://tc39.es/ecma262/#sec-asyncgenerator-prototype-constructor + m_async_generator_prototype->define_direct_property(vm.names.constructor, m_async_generator_function_prototype, Attribute::Configurable); + + m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function(); + m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function(); + m_json_parse_function = &m_json_object->get_without_side_effects(vm.names.parse).as_function(); + m_object_prototype_to_string_function = &m_object_prototype->get_without_side_effects(vm.names.toString).as_function(); +} + +void Intrinsics::visit_edges(Visitor& visitor) +{ + visitor.visit(m_empty_object_shape); + visitor.visit(m_new_object_shape); + visitor.visit(m_new_ordinary_function_prototype_object_shape); + visitor.visit(m_proxy_constructor); + visitor.visit(m_async_from_sync_iterator_prototype); + visitor.visit(m_async_generator_prototype); + visitor.visit(m_generator_prototype); + visitor.visit(m_intl_segments_prototype); + visitor.visit(m_array_prototype_values_function); + visitor.visit(m_date_constructor_now_function); + visitor.visit(m_eval_function); + visitor.visit(m_json_parse_function); + visitor.visit(m_object_prototype_to_string_function); + visitor.visit(m_throw_type_error_function); + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + visitor.visit(m_##snake_name##_constructor); \ + visitor.visit(m_##snake_name##_prototype); + JS_ENUMERATE_BUILTIN_TYPES +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + visitor.visit(m_intl_##snake_name##_constructor); \ + visitor.visit(m_intl_##snake_name##_prototype); + JS_ENUMERATE_INTL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + visitor.visit(m_temporal_##snake_name##_constructor); \ + visitor.visit(m_temporal_##snake_name##_prototype); + JS_ENUMERATE_TEMPORAL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name) \ + visitor.visit(m_##snake_name##_object); + JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name) \ + visitor.visit(m_##snake_name##_prototype); + JS_ENUMERATE_ITERATOR_PROTOTYPES +#undef __JS_ENUMERATE +} + +// 10.2.4 AddRestrictedFunctionProperties ( F, realm ), https://tc39.es/ecma262/#sec-addrestrictedfunctionproperties +void add_restricted_function_properties(FunctionObject& function, Realm& realm) +{ + auto& vm = realm.vm(); + + // 1. Assert: realm.[[Intrinsics]].[[%ThrowTypeError%]] exists and has been initialized. + VERIFY(realm.intrinsics().throw_type_error_function()); + + // 2. Let thrower be realm.[[Intrinsics]].[[%ThrowTypeError%]]. + auto* thrower = realm.intrinsics().throw_type_error_function(); + + // 3. Perform ! DefinePropertyOrThrow(F, "caller", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }). + function.define_direct_accessor(vm.names.caller, thrower, thrower, Attribute::Configurable); + + // 4. Perform ! DefinePropertyOrThrow(F, "arguments", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }). + function.define_direct_accessor(vm.names.arguments, thrower, thrower, Attribute::Configurable); + + // 5. Return unused. +} + +} diff --git a/Userland/Libraries/LibJS/Runtime/Intrinsics.h b/Userland/Libraries/LibJS/Runtime/Intrinsics.h new file mode 100644 index 00000000000..2ddaa566d8b --- /dev/null +++ b/Userland/Libraries/LibJS/Runtime/Intrinsics.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace JS { + +class Intrinsics final : public Cell { +public: + // Allow the global object to set intrinsics, ugly but needed for now. + friend class GlobalObject; + + static Intrinsics* create(Realm&); + + Intrinsics() = default; + + Shape* empty_object_shape() { return m_empty_object_shape; } + + Shape* new_object_shape() { return m_new_object_shape; } + Shape* new_ordinary_function_prototype_object_shape() { return m_new_ordinary_function_prototype_object_shape; } + + // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype + ProxyConstructor* proxy_constructor() { return m_proxy_constructor; } + + // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor + Object* async_from_sync_iterator_prototype() { return m_async_from_sync_iterator_prototype; } + Object* async_generator_prototype() { return m_async_generator_prototype; } + Object* generator_prototype() { return m_generator_prototype; } + + // Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%) + Object* async_generator_function_prototype_prototype() { return m_async_generator_prototype; } + // Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%) + Object* generator_function_prototype_prototype() { return m_generator_prototype; } + + // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor + Object* intl_segments_prototype() { return m_intl_segments_prototype; } + + FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; } + FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; } + FunctionObject* eval_function() const { return m_eval_function; } + FunctionObject* json_parse_function() const { return m_json_parse_function; } + FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; } + FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; } + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + ConstructorName* snake_name##_constructor() \ + { \ + return m_##snake_name##_constructor; \ + } \ + Object* snake_name##_prototype() \ + { \ + return m_##snake_name##_prototype; \ + } + JS_ENUMERATE_BUILTIN_TYPES +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + Intl::ConstructorName* intl_##snake_name##_constructor() \ + { \ + return m_intl_##snake_name##_constructor; \ + } \ + Object* intl_##snake_name##_prototype() \ + { \ + return m_intl_##snake_name##_prototype; \ + } + JS_ENUMERATE_INTL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + Temporal::ConstructorName* temporal_##snake_name##_constructor() \ + { \ + return m_temporal_##snake_name##_constructor; \ + } \ + Object* temporal_##snake_name##_prototype() \ + { \ + return m_temporal_##snake_name##_prototype; \ + } + JS_ENUMERATE_TEMPORAL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name) \ + ClassName* snake_name##_object() \ + { \ + return m_##snake_name##_object; \ + } + JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name) \ + Object* snake_name##_prototype() \ + { \ + return m_##snake_name##_prototype; \ + } + JS_ENUMERATE_ITERATOR_PROTOTYPES +#undef __JS_ENUMERATE + +private: + virtual StringView class_name() const override { return "Intrinsics"sv; } + virtual void visit_edges(Visitor&) override; + + void initialize_intrinsics(Realm&); + + Shape* m_empty_object_shape { nullptr }; + Shape* m_new_object_shape { nullptr }; + Shape* m_new_ordinary_function_prototype_object_shape { nullptr }; + + // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype + ProxyConstructor* m_proxy_constructor { nullptr }; + + // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor + Object* m_async_from_sync_iterator_prototype { nullptr }; + Object* m_async_generator_prototype { nullptr }; + Object* m_generator_prototype { nullptr }; + + // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor + Object* m_intl_segments_prototype { nullptr }; + + FunctionObject* m_array_prototype_values_function { nullptr }; + FunctionObject* m_date_constructor_now_function { nullptr }; + FunctionObject* m_eval_function { nullptr }; + FunctionObject* m_json_parse_function { nullptr }; + FunctionObject* m_object_prototype_to_string_function { nullptr }; + FunctionObject* m_throw_type_error_function { nullptr }; + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ + ConstructorName* m_##snake_name##_constructor { nullptr }; \ + Object* m_##snake_name##_prototype { nullptr }; + JS_ENUMERATE_BUILTIN_TYPES +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + Intl::ConstructorName* m_intl_##snake_name##_constructor { nullptr }; \ + Object* m_intl_##snake_name##_prototype { nullptr }; + JS_ENUMERATE_INTL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ + Temporal::ConstructorName* m_temporal_##snake_name##_constructor { nullptr }; \ + Object* m_temporal_##snake_name##_prototype { nullptr }; + JS_ENUMERATE_TEMPORAL_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name) \ + ClassName* m_##snake_name##_object { nullptr }; + JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS +#undef __JS_ENUMERATE + +#define __JS_ENUMERATE(ClassName, snake_name) \ + Object* m_##snake_name##_prototype { nullptr }; + JS_ENUMERATE_ITERATOR_PROTOTYPES +#undef __JS_ENUMERATE +}; + +void add_restricted_function_properties(FunctionObject&, Realm&); + +} diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index c57de9bd7ae..2bdbc5406ef 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -189,7 +189,7 @@ Object* create_iterator_result_object(VM& vm, Value value, bool done) auto& realm = *vm.current_realm(); // 1. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // 2. Perform ! CreateDataPropertyOrThrow(obj, "value", value). MUST(object->create_data_property_or_throw(vm.names.value, value)); diff --git a/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp index 8c8eef569e5..177c7149612 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorPrototype.cpp @@ -12,7 +12,7 @@ namespace JS { // 27.1.2 The %IteratorPrototype% Object, https://tc39.es/ecma262/#sec-%iteratorprototype%-object IteratorPrototype::IteratorPrototype(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index 7f5991ddd36..d4f97646dd7 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -26,7 +26,7 @@ namespace JS { JSONObject::JSONObject(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } @@ -101,7 +101,7 @@ ThrowCompletionOr JSONObject::stringify_impl(VM& vm, Value value, Value state.gap = String::empty(); } - auto* wrapper = Object::create(realm, realm.global_object().object_prototype()); + auto* wrapper = Object::create(realm, realm.intrinsics().object_prototype()); MUST(wrapper->create_data_property_or_throw(String::empty(), value)); return serialize_json_property(vm, state, String::empty(), wrapper); } @@ -400,7 +400,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse) return vm.throw_completion(ErrorType::JsonMalformed); Value unfiltered = parse_json_value(vm, json.value()); if (reviver.is_function()) { - auto* root = Object::create(realm, realm.global_object().object_prototype()); + auto* root = Object::create(realm, realm.intrinsics().object_prototype()); auto root_name = String::empty(); MUST(root->create_data_property_or_throw(root_name, unfiltered)); return internalize_json_property(vm, root, root_name, reviver.as_function()); @@ -430,7 +430,7 @@ Value JSONObject::parse_json_value(VM& vm, JsonValue const& value) Object* JSONObject::parse_json_object(VM& vm, JsonObject const& json_object) { auto& realm = *vm.current_realm(); - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); json_object.for_each_member([&](auto& key, auto& value) { object->define_direct_property(key, parse_json_value(vm, value), default_attributes); }); diff --git a/Userland/Libraries/LibJS/Runtime/Map.cpp b/Userland/Libraries/LibJS/Runtime/Map.cpp index 6c8824bd59b..076d963a97a 100644 --- a/Userland/Libraries/LibJS/Runtime/Map.cpp +++ b/Userland/Libraries/LibJS/Runtime/Map.cpp @@ -10,7 +10,7 @@ namespace JS { Map* Map::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().map_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().map_prototype()); } Map::Map(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp index bc61a2ff9d4..952aee361f7 100644 --- a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { MapConstructor::MapConstructor(Realm& realm) - : NativeFunction(vm().names.Map.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Map.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void MapConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 24.1.2.1 Map.prototype, https://tc39.es/ecma262/#sec-map.prototype - define_direct_property(vm.names.prototype, realm.global_object().map_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().map_prototype(), 0); define_native_accessor(realm, *vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); @@ -43,7 +43,7 @@ ThrowCompletionOr MapConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto* map = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::map_prototype)); + auto* map = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::map_prototype)); if (vm.argument(0).is_nullish()) return map; diff --git a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp index 52cee6fad53..33fb1357ad4 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapIterator.cpp @@ -11,7 +11,7 @@ namespace JS { MapIterator* MapIterator::create(Realm& realm, Map& map, Object::PropertyKind iteration_kind) { - return realm.heap().allocate(realm, map, iteration_kind, *realm.global_object().map_iterator_prototype()); + return realm.heap().allocate(realm, map, iteration_kind, *realm.intrinsics().map_iterator_prototype()); } MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp index d45810aac71..88800c8d036 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp @@ -14,7 +14,7 @@ namespace JS { MapIteratorPrototype::MapIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp index 19dcf8e2f33..0321086adcb 100644 --- a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp @@ -13,7 +13,7 @@ namespace JS { MapPrototype::MapPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.cpp b/Userland/Libraries/LibJS/Runtime/MathObject.cpp index bf212c4b5fe..fef6df733f1 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/MathObject.cpp @@ -16,7 +16,7 @@ namespace JS { MathObject::MathObject(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp b/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp index efab770e2fc..2fda0b0e9c1 100644 --- a/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ModuleNamespaceObject.cpp @@ -11,7 +11,7 @@ namespace JS { ModuleNamespaceObject::ModuleNamespaceObject(Realm& realm, Module* module, Vector exports) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) , m_module(module) , m_exports(move(exports)) { diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index 4f9578c7a67..a8ee8e7883f 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -26,7 +26,7 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Functionglobal_object().function_prototype(); + prototype = realm.value()->intrinsics().function_prototype(); // 3. Let internalSlotsList be a List containing the names of all the internal slots that 10.3 requires for the built-in function object that is about to be created. // 4. Append to internalSlotsList the elements of additionalInternalSlotsList. @@ -53,7 +53,7 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function(VM&)> function) { - return realm.heap().allocate(realm, name, move(function), *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, name, move(function), *realm.intrinsics().function_prototype()); } NativeFunction::NativeFunction(Function(VM&)> native_function, Object* prototype, Realm& realm) @@ -69,7 +69,7 @@ NativeFunction::NativeFunction(Function(VM&)> native_fu NativeFunction::NativeFunction(Object& prototype) : FunctionObject(prototype) - , m_realm(global_object().associated_realm()) + , m_realm(&prototype.shape().realm()) { } @@ -77,14 +77,14 @@ NativeFunction::NativeFunction(FlyString name, Function : FunctionObject(prototype) , m_name(move(name)) , m_native_function(move(native_function)) - , m_realm(global_object().associated_realm()) + , m_realm(&prototype.shape().realm()) { } NativeFunction::NativeFunction(FlyString name, Object& prototype) : FunctionObject(prototype) , m_name(move(name)) - , m_realm(global_object().associated_realm()) + , m_realm(&prototype.shape().realm()) { } diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index b1f6ed14f72..6e61b56c6a4 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -24,7 +24,7 @@ constexpr double const MIN_SAFE_INTEGER_VALUE { -(__builtin_exp2(53) - 1) }; namespace JS { NumberConstructor::NumberConstructor(Realm& realm) - : NativeFunction(vm().names.Number.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Number.as_string(), *realm.intrinsics().function_prototype()) { } @@ -34,16 +34,17 @@ void NumberConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 21.1.2.15 Number.prototype, https://tc39.es/ecma262/#sec-number.prototype - define_direct_property(vm.names.prototype, realm.global_object().number_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().number_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.isFinite, is_finite, 1, attr); define_native_function(realm, vm.names.isInteger, is_integer, 1, attr); define_native_function(realm, vm.names.isNaN, is_nan, 1, attr); define_native_function(realm, vm.names.isSafeInteger, is_safe_integer, 1, attr); - // FIXME: Store these as intrinsics (`parse_int_function()`) instead of getting them from the global object - define_direct_property(vm.names.parseInt, realm.global_object().get_without_side_effects(vm.names.parseInt), attr); - define_direct_property(vm.names.parseFloat, realm.global_object().get_without_side_effects(vm.names.parseFloat), attr); + // NOTE: These are set from the global object as at this point we don't have them allocated yet; + // The native functions are part of the global object itself. + define_direct_property(vm.names.parseInt, js_undefined(), attr); + define_direct_property(vm.names.parseFloat, js_undefined(), attr); define_direct_property(vm.names.EPSILON, Value(EPSILON_VALUE), 0); define_direct_property(vm.names.MAX_VALUE, Value(NumericLimits::max()), 0); define_direct_property(vm.names.MIN_VALUE, Value(NumericLimits::min()), 0); @@ -100,7 +101,7 @@ ThrowCompletionOr NumberConstructor::construct(FunctionObject& new_targ // 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] »). // 5. Set O.[[NumberData]] to n. // 6. Return O. - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::number_prototype, number.as_double())); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::number_prototype, number.as_double())); } // 21.1.2.2 Number.isFinite ( number ), https://tc39.es/ecma262/#sec-number.isfinite diff --git a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp index 750d9a4bad5..8284f91cad7 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberObject.cpp @@ -11,7 +11,7 @@ namespace JS { NumberObject* NumberObject::create(Realm& realm, double value) { - return realm.heap().allocate(realm, value, *realm.global_object().number_prototype()); + return realm.heap().allocate(realm, value, *realm.intrinsics().number_prototype()); } NumberObject::NumberObject(double value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index 1a6b02cf5a2..1e0a8b52120 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -84,7 +84,7 @@ static size_t compute_fraction_digits(double number, int exponent) } NumberPrototype::NumberPrototype(Realm& realm) - : NumberObject(0, *realm.global_object().object_prototype()) + : NumberObject(0, *realm.intrinsics().object_prototype()) { } @@ -327,7 +327,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string) auto number_value = TRY(this_number_value(vm, vm.this_value())); // 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »). - auto* number_format = static_cast(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), locales, options))); + auto* number_format = static_cast(TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), locales, options))); // 3. Return ? FormatNumeric(numberFormat, x). // Note: Our implementation of FormatNumeric does not throw. diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 7eeefde6613..7c1daa32b0e 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -27,9 +27,9 @@ namespace JS { Object* Object::create(Realm& realm, Object* prototype) { if (!prototype) - return realm.heap().allocate(realm, *realm.global_object().empty_object_shape()); - else if (prototype == realm.global_object().object_prototype()) - return realm.heap().allocate(realm, *realm.global_object().new_object_shape()); + return realm.heap().allocate(realm, *realm.intrinsics().empty_object_shape()); + else if (prototype == realm.intrinsics().object_prototype()) + return realm.heap().allocate(realm, *realm.intrinsics().new_object_shape()); else return realm.heap().allocate(realm, *prototype); } @@ -52,14 +52,16 @@ Object::Object(ConstructWithoutPrototypeTag, Realm& realm) Object::Object(Realm& realm, Object* prototype) { - m_shape = realm.global_object().empty_object_shape(); + m_shape = realm.intrinsics().empty_object_shape(); + VERIFY(m_shape); if (prototype != nullptr) set_prototype(prototype); } Object::Object(Object& prototype) { - m_shape = prototype.global_object().empty_object_shape(); + m_shape = prototype.shape().realm().intrinsics().empty_object_shape(); + VERIFY(m_shape); set_prototype(&prototype); } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 9f3ccf6ec5f..ad58242b7aa 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -18,7 +18,7 @@ namespace JS { ObjectConstructor::ObjectConstructor(Realm& realm) - : NativeFunction(vm().names.Object.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Object.as_string(), *realm.intrinsics().function_prototype()) { } @@ -28,7 +28,7 @@ void ObjectConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 20.1.2.19 Object.prototype, https://tc39.es/ecma262/#sec-object.prototype - define_direct_property(vm.names.prototype, realm.global_object().object_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().object_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.defineProperty, define_property, 3, attr); @@ -70,10 +70,10 @@ ThrowCompletionOr ObjectConstructor::construct(FunctionObject& new_targ auto& realm = *vm.current_realm(); if (&new_target != this) - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::object_prototype)); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::object_prototype)); auto value = vm.argument(0); if (value.is_nullish()) - return Object::create(realm, realm.global_object().object_prototype()); + return Object::create(realm, realm.intrinsics().object_prototype()); return value.to_object(vm); } @@ -223,7 +223,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries) auto& realm = *vm.current_realm(); auto iterable = TRY(require_object_coercible(vm, vm.argument(0))); - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); (void)TRY(get_iterator_values(vm, iterable, [&](Value iterator_value) -> Optional { if (!iterator_value.is_object()) @@ -274,7 +274,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) auto own_keys = TRY(object->internal_own_property_keys()); // 3. Let descriptors be OrdinaryObjectCreate(%Object.prototype%). - auto* descriptors = Object::create(realm, realm.global_object().object_prototype()); + auto* descriptors = Object::create(realm, realm.intrinsics().object_prototype()); // 4. For each element key of ownKeys, do for (auto& key : own_keys) { diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index e36b9195eb9..d114b094d7f 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -43,7 +43,7 @@ ThrowCompletionOr promise_resolve(VM& vm, Object& constructor, Value va Promise* Promise::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().promise_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().promise_prototype()); } // 27.2 Promise Objects, https://tc39.es/ecma262/#sec-promise-objects diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index a2ae7a45112..17378521014 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -240,7 +240,7 @@ static ThrowCompletionOr perform_promise_race(VM& vm, Iterator& iterator_ } PromiseConstructor::PromiseConstructor(Realm& realm) - : NativeFunction(vm().names.Promise.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Promise.as_string(), *realm.intrinsics().function_prototype()) { } @@ -250,7 +250,7 @@ void PromiseConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 27.2.4.4 Promise.prototype, https://tc39.es/ecma262/#sec-promise.prototype - define_direct_property(vm.names.prototype, realm.global_object().promise_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().promise_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.all, all, 1, attr); @@ -290,7 +290,7 @@ ThrowCompletionOr PromiseConstructor::construct(FunctionObject& new_tar // 5. Set promise.[[PromiseFulfillReactions]] to a new empty List. // 6. Set promise.[[PromiseRejectReactions]] to a new empty List. // 7. Set promise.[[PromiseIsHandled]] to false. - auto* promise = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::promise_prototype)); + auto* promise = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::promise_prototype)); // 8. Let resolvingFunctions be CreateResolvingFunctions(promise). auto [resolve_function, reject_function] = promise->create_resolving_functions(); diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp index 3a28aa58210..04fb7e45302 100644 --- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp @@ -17,7 +17,7 @@ namespace JS { PromisePrototype::PromisePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -48,7 +48,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then) auto* promise = TRY(typed_this_object(vm)); // 3. Let C be ? SpeciesConstructor(promise, %Promise%). - auto* constructor = TRY(species_constructor(vm, *promise, *realm.global_object().promise_constructor())); + auto* constructor = TRY(species_constructor(vm, *promise, *realm.intrinsics().promise_constructor())); // 4. Let resultCapability be ? NewPromiseCapability(C). auto result_capability = TRY(new_promise_capability(vm, constructor)); @@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) return vm.throw_completion(ErrorType::NotAnObject, promise.to_string_without_side_effects()); // 3. Let C be ? SpeciesConstructor(promise, %Promise%). - auto* constructor = TRY(species_constructor(vm, promise.as_object(), *realm.global_object().promise_constructor())); + auto* constructor = TRY(species_constructor(vm, promise.as_object(), *realm.intrinsics().promise_constructor())); // 4. Assert: IsConstructor(C) is true. VERIFY(constructor); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp index c80b9d7cd6f..2a475629497 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp @@ -57,7 +57,7 @@ void PromiseResolvingElementFunction::visit_edges(Cell::Visitor& visitor) PromiseAllResolveElementFunction* PromiseAllResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype()); } PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) @@ -89,7 +89,7 @@ ThrowCompletionOr PromiseAllResolveElementFunction::resolve_element() PromiseAllSettledResolveElementFunction* PromiseAllSettledResolveElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype()); } PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) @@ -103,7 +103,7 @@ ThrowCompletionOr PromiseAllSettledResolveElementFunction::resolve_elemen auto& realm = *vm.current_realm(); // 9. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled"). MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "fulfilled"sv))); @@ -130,7 +130,7 @@ ThrowCompletionOr PromiseAllSettledResolveElementFunction::resolve_elemen PromiseAllSettledRejectElementFunction* PromiseAllSettledRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, values, capability, remaining_elements, *realm.intrinsics().function_prototype()); } PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(size_t index, PromiseValueList& values, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) @@ -144,7 +144,7 @@ ThrowCompletionOr PromiseAllSettledRejectElementFunction::resolve_element auto& realm = *vm.current_realm(); // 9. Let obj be OrdinaryObjectCreate(%Object.prototype%). - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); // 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected"). MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "rejected"sv))); @@ -171,7 +171,7 @@ ThrowCompletionOr PromiseAllSettledRejectElementFunction::resolve_element PromiseAnyRejectElementFunction* PromiseAnyRejectElementFunction::create(Realm& realm, size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements) { - return realm.heap().allocate(realm, index, errors, capability, remaining_elements, *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, index, errors, capability, remaining_elements, *realm.intrinsics().function_prototype()); } PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, PromiseValueList& errors, PromiseCapability capability, RemainingElements& remaining_elements, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp index 31ee4835e5a..935be968c0c 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp @@ -13,7 +13,7 @@ namespace JS { PromiseResolvingFunction* PromiseResolvingFunction::create(Realm& realm, Promise& promise, AlreadyResolved& already_resolved, FunctionType function) { - return realm.heap().allocate(realm, promise, already_resolved, move(function), *realm.global_object().function_prototype()); + return realm.heap().allocate(realm, promise, already_resolved, move(function), *realm.intrinsics().function_prototype()); } PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyResolved& already_resolved, FunctionType native_function, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp index 74bb413b764..ab958b26f3f 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp @@ -71,7 +71,7 @@ Value from_property_descriptor(VM& vm, Optional const& prope if (!property_descriptor.has_value()) return js_undefined(); - auto* object = Object::create(realm, realm.global_object().object_prototype()); + auto* object = Object::create(realm, realm.intrinsics().object_prototype()); if (property_descriptor->value.has_value()) MUST(object->create_data_property_or_throw(vm.names.value, *property_descriptor->value)); if (property_descriptor->writable.has_value()) diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp index 81926730ab3..6a68131f048 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -25,7 +25,7 @@ static ThrowCompletionOr proxy_create(VM& vm, Value target, Value } ProxyConstructor::ProxyConstructor(Realm& realm) - : NativeFunction(vm().names.Proxy.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Proxy.as_string(), *realm.intrinsics().function_prototype()) { } @@ -87,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable) auto* revoker = NativeFunction::create(realm, move(revoker_closure), 0, ""); // 5. Let result be OrdinaryObjectCreate(%Object.prototype%). - auto* result = Object::create(realm, realm.global_object().object_prototype()); + auto* result = Object::create(realm, realm.intrinsics().object_prototype()); // 6. Perform ! CreateDataPropertyOrThrow(result, "proxy", p). MUST(result->create_data_property_or_throw(vm.names.proxy, proxy)); diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp index 648e00c526e..eef9c96ba4b 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -17,7 +17,7 @@ namespace JS { ProxyObject* ProxyObject::create(Realm& realm, Object& target, Object& handler) { - return realm.heap().allocate(realm, target, handler, *realm.global_object().object_prototype()); + return realm.heap().allocate(realm, target, handler, *realm.intrinsics().object_prototype()); } ProxyObject::ProxyObject(Object& target, Object& handler, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp index ca9e09b4491..03038f3127b 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.cpp +++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp @@ -17,7 +17,18 @@ namespace JS { // 9.3.1 CreateRealm ( ), https://tc39.es/ecma262/#sec-createrealm Realm* Realm::create(VM& vm) { - return vm.heap().allocate_without_realm(); + // 1. Let realmRec be a new Realm Record. + auto* realm = vm.heap().allocate_without_realm(); + + // 2. Perform CreateIntrinsics(realmRec). + Intrinsics::create(*realm); + + // 3. Set realmRec.[[GlobalObject]] to undefined. + // 4. Set realmRec.[[GlobalEnv]] to undefined. + // 5. Set realmRec.[[TemplateMap]] to a new empty List. + + // 6. Return realmRec. + return realm; } // 9.6 InitializeHostDefinedRealm ( ), https://tc39.es/ecma262/#sec-initializehostdefinedrealm @@ -107,6 +118,7 @@ void Realm::set_global_object(GlobalObject* global_object, GlobalObject* this_va void Realm::visit_edges(Visitor& visitor) { + visitor.visit(m_intrinsics); visitor.visit(m_global_object); visitor.visit(m_global_environment); } diff --git a/Userland/Libraries/LibJS/Runtime/Realm.h b/Userland/Libraries/LibJS/Runtime/Realm.h index 9739a096415..8a3a043d0b8 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.h +++ b/Userland/Libraries/LibJS/Runtime/Realm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause @@ -7,10 +7,12 @@ #pragma once +#include #include #include #include #include +#include namespace JS { @@ -33,6 +35,14 @@ public: [[nodiscard]] GlobalObject& global_object() const { return *m_global_object; } [[nodiscard]] GlobalEnvironment& global_environment() const { return *m_global_environment; } + [[nodiscard]] Intrinsics const& intrinsics() const { return *m_intrinsics; } + [[nodiscard]] Intrinsics& intrinsics() { return *m_intrinsics; } + void set_intrinsics(Badge, Intrinsics& intrinsics) + { + VERIFY(!m_intrinsics); + m_intrinsics = &intrinsics; + } + HostDefined* host_defined() { return m_host_defined; } void set_host_defined(OwnPtr host_defined) { m_host_defined = move(host_defined); } @@ -40,6 +50,7 @@ private: virtual StringView class_name() const override { return "Realm"sv; } virtual void visit_edges(Visitor&) override; + Intrinsics* m_intrinsics { nullptr }; // [[Intrinsics]] GlobalObject* m_global_object { nullptr }; // [[GlobalObject]] GlobalEnvironment* m_global_environment { nullptr }; // [[GlobalEnv]] OwnPtr m_host_defined; // [[HostDefined]] diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index dbf23f54197..c6bff072eca 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -118,11 +118,11 @@ ThrowCompletionOr 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 = realm.global_object().string_prototype(); + base_obj = realm.intrinsics().string_prototype(); } else if (m_base_value.is_number()) - base_obj = realm.global_object().number_prototype(); + base_obj = realm.intrinsics().number_prototype(); else if (m_base_value.is_boolean()) - base_obj = realm.global_object().boolean_prototype(); + base_obj = realm.intrinsics().boolean_prototype(); else base_obj = TRY(m_base_value.to_object(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index 8c74732106e..7ac1d6ecc99 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -16,7 +16,7 @@ namespace JS { ReflectObject::ReflectObject(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp index b40387d28db..3acbb1d2b24 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp @@ -12,7 +12,7 @@ namespace JS { RegExpConstructor::RegExpConstructor(Realm& realm) - : NativeFunction(vm().names.RegExp.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.RegExp.as_string(), *realm.intrinsics().function_prototype()) { } @@ -22,7 +22,7 @@ void RegExpConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 22.2.4.1 RegExp.prototype, https://tc39.es/ecma262/#sec-regexp.prototype - define_direct_property(vm.names.prototype, realm.global_object().regexp_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().regexp_prototype(), 0); define_native_accessor(realm, *vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp index 1af4e908c09..192b682dcea 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp @@ -124,12 +124,12 @@ ThrowCompletionOr parse_regex_pattern(VM& vm, StringView pattern, bool u RegExpObject* RegExpObject::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().regexp_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().regexp_prototype()); } RegExpObject* RegExpObject::create(Realm& realm, Regex regex, String pattern, String flags) { - return realm.heap().allocate(realm, move(regex), move(pattern), move(flags), *realm.global_object().regexp_prototype()); + return realm.heap().allocate(realm, move(regex), move(pattern), move(flags), *realm.intrinsics().regexp_prototype()); } RegExpObject::RegExpObject(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 7d1353ba87b..781c64ec42e 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -22,7 +22,7 @@ namespace JS { RegExpPrototype::RegExpPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -418,7 +418,7 @@ size_t advance_string_index(Utf16View const& string, size_t index, bool unicode) /* 2. If R does not have an [[OriginalFlags]] internal slot, then */ \ if (!is(regexp_object)) { \ /* a. If SameValue(R, %RegExp.prototype%) is true, return undefined. */ \ - if (same_value(regexp_object, realm.global_object().regexp_prototype())) \ + if (same_value(regexp_object, realm.intrinsics().regexp_prototype())) \ return js_undefined(); \ /* b. Otherwise, throw a TypeError exception. */ \ return vm.throw_completion(ErrorType::NotAnObjectOfType, "RegExp"); \ @@ -574,7 +574,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all) auto string = TRY(vm.argument(0).to_utf16_string(vm)); // 4. Let C be ? SpeciesConstructor(R, %RegExp%). - auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.global_object().regexp_constructor())); + auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.intrinsics().regexp_constructor())); // 5. Let flags be ? ToString(? Get(R, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); @@ -851,7 +851,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source) // 3. If R does not have an [[OriginalSource]] internal slot, then if (!is(regexp_object)) { // a. If SameValue(R, %RegExp.prototype%) is true, return "(?:)". - if (same_value(regexp_object, realm.global_object().regexp_prototype())) + if (same_value(regexp_object, realm.intrinsics().regexp_prototype())) return js_string(vm, "(?:)"); // b. Otherwise, throw a TypeError exception. @@ -879,7 +879,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split) auto string = TRY(vm.argument(0).to_utf16_string(vm)); // 4. Let C be ? SpeciesConstructor(rx, %RegExp%). - auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.global_object().regexp_constructor())); + auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.intrinsics().regexp_constructor())); // 5. Let flags be ? ToString(? Get(rx, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp index a79b2350b2d..68436ef091d 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp @@ -12,7 +12,7 @@ namespace JS { // 22.2.7.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ), https://tc39.es/ecma262/#sec-createregexpstringiterator RegExpStringIterator* RegExpStringIterator::create(Realm& realm, Object& regexp_object, Utf16String string, bool global, bool unicode) { - return realm.heap().allocate(realm, *realm.global_object().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode); + return realm.heap().allocate(realm, *realm.intrinsics().regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode); } RegExpStringIterator::RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp index bc76b94ec58..f202b759e9f 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp @@ -13,7 +13,7 @@ namespace JS { RegExpStringIteratorPrototype::RegExpStringIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Set.cpp b/Userland/Libraries/LibJS/Runtime/Set.cpp index 9f3b9406550..618d95b6f85 100644 --- a/Userland/Libraries/LibJS/Runtime/Set.cpp +++ b/Userland/Libraries/LibJS/Runtime/Set.cpp @@ -10,12 +10,12 @@ namespace JS { Set* Set::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().set_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().set_prototype()); } Set::Set(Object& prototype) : Object(prototype) - , m_values(*prototype.global_object().map_prototype()) + , m_values(*prototype.shape().realm().intrinsics().map_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp index 4754c4fc545..b3c4d36bbc5 100644 --- a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { SetConstructor::SetConstructor(Realm& realm) - : NativeFunction(vm().names.Set.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Set.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void SetConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 24.2.2.1 Set.prototype, https://tc39.es/ecma262/#sec-set.prototype - define_direct_property(vm.names.prototype, realm.global_object().set_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().set_prototype(), 0); define_native_accessor(realm, *vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); @@ -43,7 +43,7 @@ ThrowCompletionOr SetConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto* set = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::set_prototype)); + auto* set = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::set_prototype)); if (vm.argument(0).is_nullish()) return set; diff --git a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp index 2797ee18333..5fcdb86f8ba 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetIterator.cpp @@ -11,7 +11,7 @@ namespace JS { SetIterator* SetIterator::create(Realm& realm, Set& set, Object::PropertyKind iteration_kind) { - return realm.heap().allocate(realm, set, iteration_kind, *realm.global_object().set_iterator_prototype()); + return realm.heap().allocate(realm, set, iteration_kind, *realm.intrinsics().set_iterator_prototype()); } SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp index 2f976e1a5f2..d93db45b96a 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp @@ -14,7 +14,7 @@ namespace JS { SetIteratorPrototype::SetIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp index 0a9bea3abf9..f1ec8b21a86 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp @@ -13,7 +13,7 @@ namespace JS { SetPrototype::SetPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 0ed2d9a99a3..ff7e6dd6d52 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -212,7 +212,7 @@ ThrowCompletionOr shadow_realm_import_value(VM& vm, String specifier_stri // 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]]. // 2. Let innerCapability be ! NewPromiseCapability(%Promise%). - auto inner_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto inner_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 3. Let runningContext be the running execution context. // 4. If runningContext is not already suspended, suspend runningContext. @@ -267,7 +267,7 @@ ThrowCompletionOr shadow_realm_import_value(VM& vm, String specifier_stri auto* on_fulfilled = NativeFunction::create(realm, move(steps), 1, "", &caller_realm); // 12. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do. // Throw a nicer TypeError forwarding the import error message instead (we know the argument is an Error object). diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp index 82e7f86259a..d0a384ddf0a 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp @@ -12,7 +12,7 @@ namespace JS { // 3.2 The ShadowRealm Constructor, https://tc39.es/proposal-shadowrealm/#sec-shadowrealm-constructor ShadowRealmConstructor::ShadowRealmConstructor(Realm& realm) - : NativeFunction(vm().names.ShadowRealm.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.ShadowRealm.as_string(), *realm.intrinsics().function_prototype()) { } @@ -22,7 +22,7 @@ void ShadowRealmConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 3.3.1 ShadowRealm.prototype, https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype - define_direct_property(vm.names.prototype, realm.global_object().shadow_realm_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().shadow_realm_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); } @@ -59,7 +59,7 @@ ThrowCompletionOr ShadowRealmConstructor::construct(FunctionObject& new // 2. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%ShadowRealm.prototype%", « [[ShadowRealm]], [[ExecutionContext]] »). // 4. Set O.[[ShadowRealm]] to realmRec. // 9. Set O.[[ExecutionContext]] to context. - auto* object = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::shadow_realm_prototype, *realm, move(context))); + auto* object = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::shadow_realm_prototype, *realm, move(context))); // 10. Perform ? SetRealmGlobalObject(realmRec, undefined, undefined). auto* new_global_object = vm.heap().allocate_without_realm(*realm); diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp index ca96c2f7210..7a510e9a71a 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp @@ -12,7 +12,7 @@ namespace JS { // 3.4 Properties of the ShadowRealm Prototype Object, https://tc39.es/proposal-shadowrealm/#sec-properties-of-the-shadowrealm-prototype-object ShadowRealmPrototype::ShadowRealmPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index fa07dcd9cdd..ab4f1982cbc 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -18,7 +18,7 @@ namespace JS { StringConstructor::StringConstructor(Realm& realm) - : NativeFunction(vm().names.String.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.String.as_string(), *realm.intrinsics().function_prototype()) { } @@ -28,7 +28,7 @@ void StringConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 22.1.2.3 String.prototype, https://tc39.es/ecma262/#sec-string.prototype - define_direct_property(vm.names.prototype, realm.global_object().string_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().string_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.raw, raw, 1, attr); @@ -60,7 +60,7 @@ ThrowCompletionOr StringConstructor::construct(FunctionObject& new_targ primitive_string = js_string(vm, ""); else primitive_string = TRY(vm.argument(0).to_primitive_string(vm)); - auto* prototype = TRY(get_prototype_from_constructor(vm, new_target, &GlobalObject::string_prototype)); + auto* prototype = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::string_prototype)); return StringObject::create(realm, *primitive_string, *prototype); } diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp index 0a72b029e6b..abd8e8f62fc 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp @@ -12,7 +12,7 @@ namespace JS { StringIterator* StringIterator::create(Realm& realm, String string) { - return realm.heap().allocate(realm, move(string), *realm.global_object().string_iterator_prototype()); + return realm.heap().allocate(realm, move(string), *realm.intrinsics().string_iterator_prototype()); } StringIterator::StringIterator(String string, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp index 71e056bacbf..72386b10150 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp @@ -14,7 +14,7 @@ namespace JS { StringIteratorPrototype::StringIteratorPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().iterator_prototype()) + : PrototypeObject(*realm.intrinsics().iterator_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index ce10ba34fa6..1d1be6b03aa 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -103,7 +103,7 @@ static Optional string_index_of(Utf16View const& string, Utf16View const } StringPrototype::StringPrototype(Realm& realm) - : StringObject(*js_string(realm.vm(), String::empty()), *realm.global_object().object_prototype()) + : StringObject(*js_string(realm.vm(), String::empty()), *realm.intrinsics().object_prototype()) { } @@ -1088,7 +1088,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare) auto that_value = TRY(vm.argument(0).to_string(vm)); // 4. Let collator be ? Construct(%Collator%, « locales, options »). - auto* collator = TRY(construct(vm, *realm.global_object().intl_collator_constructor(), vm.argument(1), vm.argument(2))); + auto* collator = TRY(construct(vm, *realm.intrinsics().intl_collator_constructor(), vm.argument(1), vm.argument(2))); // 5. Return CompareStrings(collator, S, thatValue). return Intl::compare_strings(static_cast(*collator), Utf8View(string), Utf8View(that_value)); diff --git a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp index 13847b1cb97..8d266a49c8f 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp @@ -11,7 +11,7 @@ namespace JS { SymbolConstructor::SymbolConstructor(Realm& realm) - : NativeFunction(vm().names.Symbol.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Symbol.as_string(), *realm.intrinsics().function_prototype()) { } @@ -21,7 +21,7 @@ void SymbolConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 20.4.2.9 Symbol.prototype, https://tc39.es/ecma262/#sec-symbol.prototype - define_direct_property(vm.names.prototype, realm.global_object().symbol_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().symbol_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.for_, for_, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp index 61344a3b136..5163d3487fa 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolObject.cpp @@ -12,7 +12,7 @@ namespace JS { SymbolObject* SymbolObject::create(Realm& realm, Symbol& primitive_symbol) { - return realm.heap().allocate(realm, primitive_symbol, *realm.global_object().symbol_prototype()); + return realm.heap().allocate(realm, primitive_symbol, *realm.intrinsics().symbol_prototype()); } SymbolObject::SymbolObject(Symbol& symbol, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp index bc7981e1a80..7e9b5748137 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -19,7 +19,7 @@ namespace JS { SymbolPrototype::SymbolPrototype(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index c3987699761..02229cb06b5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -70,11 +70,11 @@ ThrowCompletionOr create_temporal_calendar(VM& vm, String const& iden // 2. If newTarget is not provided, set newTarget to %Temporal.Calendar%. if (!new_target) - new_target = realm.global_object().temporal_calendar_constructor(); + new_target = realm.intrinsics().temporal_calendar_constructor(); // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »). // 4. Set object.[[Identifier]] to identifier. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_calendar_prototype, identifier)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_calendar_prototype, identifier)); // 5. Return object. return object; @@ -947,7 +947,7 @@ ThrowCompletionOr default_merge_calendar_fields(VM& vm, Object const& f auto& realm = *vm.current_realm(); // 1. Let merged be OrdinaryObjectCreate(%Object.prototype%). - auto* merged = Object::create(realm, realm.global_object().object_prototype()); + auto* merged = Object::create(realm, realm.intrinsics().object_prototype()); // 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key). auto fields_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key)); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp index 4f3da005bfc..6dfe1948942 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp @@ -12,7 +12,7 @@ namespace JS::Temporal { // 12.2 The Temporal.Calendar Constructor, https://tc39.es/proposal-temporal/#sec-temporal-calendar-constructor CalendarConstructor::CalendarConstructor(Realm& realm) - : NativeFunction(vm().names.Calendar.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Calendar.as_string(), *realm.intrinsics().function_prototype()) { } @@ -23,7 +23,7 @@ void CalendarConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 12.3.1 Temporal.Calendar.prototype, https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_calendar_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_calendar_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 6e33204687b..422bb7e3b6b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -21,7 +21,7 @@ namespace JS::Temporal { // 12.4 Properties of the Temporal.Calendar Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-calendar-prototype-object CalendarPrototype::CalendarPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp index 99eaff7f98d..e1b89a8a7fc 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp @@ -334,7 +334,7 @@ ThrowCompletionOr create_temporal_duration(VM& vm, double years, doub // 2. If newTarget is not present, set newTarget to %Temporal.Duration%. if (!new_target) - new_target = realm.global_object().temporal_duration_constructor(); + new_target = realm.intrinsics().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)). @@ -347,7 +347,7 @@ ThrowCompletionOr create_temporal_duration(VM& vm, double years, doub // 11. Set object.[[Milliseconds]] to ℝ(𝔽(milliseconds)). // 12. Set object.[[Microseconds]] to ℝ(𝔽(microseconds)). // 13. Set object.[[Nanoseconds]] to ℝ(𝔽(nanoseconds)). - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)); // 14. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp index 0bf97db5858..9604a6eb283 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationConstructor.cpp @@ -15,7 +15,7 @@ namespace JS::Temporal { // 7.1 The Temporal.Duration Constructor, https://tc39.es/proposal-temporal/#sec-temporal-duration-constructor DurationConstructor::DurationConstructor(Realm& realm) - : NativeFunction(vm().names.Duration.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Duration.as_string(), *realm.intrinsics().function_prototype()) { } @@ -26,7 +26,7 @@ void DurationConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 7.2.1 Temporal.Duration.prototype, https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_duration_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_duration_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index f23fc5dae16..f7c91f6c5ac 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -16,7 +16,7 @@ namespace JS::Temporal { // 7.3 Properties of the Temporal.Duration Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-duration-prototype-object DurationPrototype::DurationPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp index dbe4eab60a9..48a12782eb8 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp @@ -61,11 +61,11 @@ ThrowCompletionOr create_temporal_instant(VM& vm, BigInt const& epoch_ // 3. If newTarget is not present, set newTarget to %Temporal.Instant%. if (!new_target) - new_target = realm.global_object().temporal_instant_constructor(); + new_target = realm.intrinsics().temporal_instant_constructor(); // 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »). // 5. Set object.[[Nanoseconds]] to epochNanoseconds. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_instant_prototype, epoch_nanoseconds)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_instant_prototype, epoch_nanoseconds)); // 6. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp index f0d9ba895a8..152ef332e73 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp @@ -14,7 +14,7 @@ namespace JS::Temporal { // 8.1 The Temporal.Instant Constructor, https://tc39.es/proposal-temporal/#sec-temporal-instant-constructor InstantConstructor::InstantConstructor(Realm& realm) - : NativeFunction(vm().names.Instant.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.Instant.as_string(), *realm.intrinsics().function_prototype()) { } @@ -25,7 +25,7 @@ void InstantConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 8.2.1 Temporal.Instant.prototype, https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_instant_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_instant_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 6325b02421e..6b382757bcb 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -20,7 +20,7 @@ namespace JS::Temporal { // 8.3 Properties of the Temporal.Instant Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-instant-prototype-object InstantPrototype::InstantPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp index bac128c0b70..e31a88dc41c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp @@ -21,7 +21,7 @@ namespace JS::Temporal { // 2 The Temporal.Now Object, https://tc39.es/proposal-temporal/#sec-temporal-now-object Now::Now(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index b54133dd201..a3e0f96008f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -67,14 +67,14 @@ ThrowCompletionOr 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 = realm.global_object().temporal_plain_date_constructor(); + new_target = realm.intrinsics().temporal_plain_date_constructor(); // 8. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »). // 9. Set object.[[ISOYear]] to isoYear. // 10. Set object.[[ISOMonth]] to isoMonth. // 11. Set object.[[ISODay]] to isoDay. // 12. Set object.[[Calendar]] to calendar. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar)); return object; } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp index 29153665dea..f4b9c811663 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateConstructor.cpp @@ -16,7 +16,7 @@ namespace JS::Temporal { // 3.1 The Temporal.PlainDate Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaindate-constructor PlainDateConstructor::PlainDateConstructor(Realm& realm) - : NativeFunction(vm().names.PlainDate.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.PlainDate.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void PlainDateConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 3.2.1 Temporal.PlainDate.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_date_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_date_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp index 9ba70eaa678..e2cbd780bfc 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp @@ -21,7 +21,7 @@ namespace JS::Temporal { // 3.3 Properties of the Temporal.PlainDate Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindate-prototype-object PlainDatePrototype::PlainDatePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -326,7 +326,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields) auto* temporal_date = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, realm.global_object().object_prototype()); + auto* fields = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalDate.[[Calendar]]). MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_date->calendar()))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp index b3d611c60a3..173cb5874b8 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp @@ -249,7 +249,7 @@ ThrowCompletionOr 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 = realm.global_object().temporal_plain_date_time_constructor(); + new_target = realm.intrinsics().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. @@ -262,7 +262,7 @@ ThrowCompletionOr create_temporal_date_time(VM& vm, i32 iso_year // 15. Set object.[[ISOMicrosecond]] to microsecond. // 16. Set object.[[ISONanosecond]] to nanosecond. // 17. Set object.[[Calendar]] to calendar. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar)); // 18. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp index 0ce85372d5a..0a3f8c16a57 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimeConstructor.cpp @@ -16,7 +16,7 @@ namespace JS::Temporal { // 5.1 The Temporal.PlainDateTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaindatetime-constructor PlainDateTimeConstructor::PlainDateTimeConstructor(Realm& realm) - : NativeFunction(vm().names.PlainDateTime.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.PlainDateTime.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void PlainDateTimeConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 5.2.1 Temporal.PlainDateTime.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_date_time_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_date_time_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp index 25cac88f60e..93a4a36a90a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp @@ -22,7 +22,7 @@ namespace JS::Temporal { // 5.3 Properties of the Temporal.PlainDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindatetime-prototype-object PlainDateTimePrototype::PlainDateTimePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -735,7 +735,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields) auto* date_time = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, realm.global_object().object_prototype()); + auto* fields = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", dateTime.[[Calendar]]). MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&date_time->calendar()))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp index ecbc4335538..fa3d6dc632b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDay.cpp @@ -159,14 +159,14 @@ ThrowCompletionOr 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 = realm.global_object().temporal_plain_month_day_constructor(); + new_target = realm.intrinsics().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. // 8. Set object.[[ISODay]] to isoDay. // 9. Set object.[[Calendar]] to calendar. // 10. Set object.[[ISOYear]] to referenceISOYear. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar)); // 11. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp index 4cc51a6aa96..125b233d794 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayConstructor.cpp @@ -15,7 +15,7 @@ namespace JS::Temporal { // 10.1 The Temporal.PlainMonthDay Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plainmonthday-constructor PlainMonthDayConstructor::PlainMonthDayConstructor(Realm& realm) - : NativeFunction(vm().names.PlainMonthDay.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.PlainMonthDay.as_string(), *realm.intrinsics().function_prototype()) { } @@ -26,7 +26,7 @@ void PlainMonthDayConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 10.2.1 Temporal.PlainMonthDay.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_month_day_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_month_day_prototype(), 0); define_direct_property(vm.names.length, Value(2), Attribute::Configurable); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp index 2c31946da77..816bf4998e6 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp @@ -16,7 +16,7 @@ namespace JS::Temporal { // 10.3 Properties of the Temporal.PlainMonthDay Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainmonthday-prototype-object PlainMonthDayPrototype::PlainMonthDayPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -260,7 +260,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields) auto* month_day = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, realm.global_object().object_prototype()); + auto* fields = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", monthDay.[[Calendar]]). MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&month_day->calendar()))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp index 78a29922c29..d2f91c34060 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp @@ -320,7 +320,7 @@ ThrowCompletionOr 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 = realm.global_object().temporal_plain_time_constructor(); + new_target = realm.intrinsics().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. @@ -330,7 +330,7 @@ ThrowCompletionOr create_temporal_time(VM& vm, u8 hour, u8 minute, u // 9. Set object.[[ISOMicrosecond]] to microsecond. // 10. Set object.[[ISONanosecond]] to nanosecond. // 11. Set object.[[Calendar]] to ! GetISO8601Calendar(). - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm))); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm))); // 12. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp index 6d156a43a35..01e3c56704c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimeConstructor.cpp @@ -14,7 +14,7 @@ namespace JS::Temporal { // 4.1 The Temporal.PlainTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaintime-constructor PlainTimeConstructor::PlainTimeConstructor(Realm& realm) - : NativeFunction(vm().names.PlainTime.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.PlainTime.as_string(), *realm.intrinsics().function_prototype()) { } @@ -25,7 +25,7 @@ void PlainTimeConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 4.2.1 Temporal.PlainTime.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_time_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_time_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index 7d5f42e2379..215b27c59f5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -21,7 +21,7 @@ namespace JS::Temporal { // 4.3 Properties of the Temporal.PlainTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaintime-prototype-object PlainTimePrototype::PlainTimePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -425,7 +425,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields) auto* temporal_time = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, realm.global_object().object_prototype()); + auto* fields = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalTime.[[Calendar]]). MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_time->calendar()))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp index 82272ceb4ea..c744de030ea 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -200,14 +200,14 @@ ThrowCompletionOr 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 = realm.global_object().temporal_plain_year_month_constructor(); + new_target = realm.intrinsics().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. // 8. Set object.[[ISOMonth]] to isoMonth. // 9. Set object.[[Calendar]] to calendar. // 10. Set object.[[ISODay]] to referenceISODay. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar)); // 11. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp index 72f43002da0..f79f20a9d36 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthConstructor.cpp @@ -16,7 +16,7 @@ namespace JS::Temporal { // 9.1 The Temporal.PlainYearMonth Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plainyearmonth-constructor PlainYearMonthConstructor::PlainYearMonthConstructor(Realm& realm) - : NativeFunction(vm().names.PlainYearMonth.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.PlainYearMonth.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void PlainYearMonthConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 9.2.1 Temporal.PlainYearMonth.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_year_month_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_year_month_prototype(), 0); define_direct_property(vm.names.length, Value(2), Attribute::Configurable); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp index 0f49d70672e..9c12558557d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp @@ -18,7 +18,7 @@ namespace JS::Temporal { // 9.3 Properties of the Temporal.PlainYearMonth Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainyearmonth-prototype-object PlainYearMonthPrototype::PlainYearMonthPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -427,7 +427,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields) auto* year_month = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, realm.global_object().object_prototype()); + auto* fields = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", yearMonth.[[Calendar]]). MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&year_month->calendar()))); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp index 7cfb7622475..d7a8b6cc185 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Temporal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -22,7 +22,7 @@ namespace JS::Temporal { // 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects Temporal::Temporal(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } @@ -37,16 +37,16 @@ void Temporal::initialize(Realm& realm) u8 attr = Attribute::Writable | Attribute::Configurable; define_direct_property(vm.names.Now, heap().allocate(realm, realm), attr); - define_direct_property(vm.names.Calendar, realm.global_object().temporal_calendar_constructor(), attr); - define_direct_property(vm.names.Duration, realm.global_object().temporal_duration_constructor(), attr); - define_direct_property(vm.names.Instant, realm.global_object().temporal_instant_constructor(), attr); - define_direct_property(vm.names.PlainDate, realm.global_object().temporal_plain_date_constructor(), attr); - define_direct_property(vm.names.PlainDateTime, realm.global_object().temporal_plain_date_time_constructor(), attr); - define_direct_property(vm.names.PlainMonthDay, realm.global_object().temporal_plain_month_day_constructor(), attr); - define_direct_property(vm.names.PlainTime, realm.global_object().temporal_plain_time_constructor(), attr); - define_direct_property(vm.names.PlainYearMonth, realm.global_object().temporal_plain_year_month_constructor(), attr); - define_direct_property(vm.names.TimeZone, realm.global_object().temporal_time_zone_constructor(), attr); - define_direct_property(vm.names.ZonedDateTime, realm.global_object().temporal_zoned_date_time_constructor(), attr); + define_direct_property(vm.names.Calendar, realm.intrinsics().temporal_calendar_constructor(), attr); + define_direct_property(vm.names.Duration, realm.intrinsics().temporal_duration_constructor(), attr); + define_direct_property(vm.names.Instant, realm.intrinsics().temporal_instant_constructor(), attr); + define_direct_property(vm.names.PlainDate, realm.intrinsics().temporal_plain_date_constructor(), attr); + define_direct_property(vm.names.PlainDateTime, realm.intrinsics().temporal_plain_date_time_constructor(), attr); + define_direct_property(vm.names.PlainMonthDay, realm.intrinsics().temporal_plain_month_day_constructor(), attr); + define_direct_property(vm.names.PlainTime, realm.intrinsics().temporal_plain_time_constructor(), attr); + define_direct_property(vm.names.PlainYearMonth, realm.intrinsics().temporal_plain_year_month_constructor(), attr); + define_direct_property(vm.names.TimeZone, realm.intrinsics().temporal_time_zone_constructor(), attr); + define_direct_property(vm.names.ZonedDateTime, realm.intrinsics().temporal_zoned_date_time_constructor(), attr); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index 3b7936858ae..1bc1faa1529 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -69,10 +69,10 @@ ThrowCompletionOr create_temporal_time_zone(VM& vm, String const& ide // 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%. if (!new_target) - new_target = realm.global_object().temporal_time_zone_constructor(); + new_target = realm.intrinsics().temporal_time_zone_constructor(); // 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »). - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_time_zone_prototype)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_time_zone_prototype)); // 3. Let offsetNanosecondsResult be Completion(ParseTimeZoneOffsetString(identifier)). auto offset_nanoseconds_result = parse_time_zone_offset_string(vm, identifier); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp index 9ee77b5887b..8ea721b3686 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp @@ -12,7 +12,7 @@ namespace JS::Temporal { // 11.2 The Temporal.TimeZone Constructor, https://tc39.es/proposal-temporal/#sec-temporal-timezone-constructor TimeZoneConstructor::TimeZoneConstructor(Realm& realm) - : NativeFunction(vm().names.TimeZone.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.TimeZone.as_string(), *realm.intrinsics().function_prototype()) { } @@ -23,7 +23,7 @@ void TimeZoneConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 11.3.1 Temporal.TimeZone.prototype, https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_time_zone_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_time_zone_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index c65254bce2a..fc463bfbda9 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -18,7 +18,7 @@ namespace JS::Temporal { // 11.4 Properties of the Temporal.TimeZone Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-timezone-prototype-object TimeZonePrototype::TimeZonePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index eb824f38fe1..1d9efe8b36f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -273,13 +273,13 @@ ThrowCompletionOr create_temporal_zoned_date_time(VM& vm, BigInt // 2. If newTarget is not present, set newTarget to %Temporal.ZonedDateTime%. if (!new_target) - new_target = realm.global_object().temporal_zoned_date_time_constructor(); + new_target = realm.intrinsics().temporal_zoned_date_time_constructor(); // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.ZonedDateTime.prototype%", « [[InitializedTemporalZonedDateTime]], [[Nanoseconds]], [[TimeZone]], [[Calendar]] »). // 4. Set object.[[Nanoseconds]] to epochNanoseconds. // 5. Set object.[[TimeZone]] to timeZone. // 6. Set object.[[Calendar]] to calendar. - auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &GlobalObject::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar)); + auto* object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar)); // 7. Return object. return object; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp index d695455c518..cd1ce2ab5c8 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp @@ -17,7 +17,7 @@ namespace JS::Temporal { // 6.1 The Temporal.ZonedDateTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-zoneddatetime-constructor ZonedDateTimeConstructor::ZonedDateTimeConstructor(Realm& realm) - : NativeFunction(vm().names.ZonedDateTime.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.ZonedDateTime.as_string(), *realm.intrinsics().function_prototype()) { } @@ -28,7 +28,7 @@ void ZonedDateTimeConstructor::initialize(Realm& realm) auto& vm = this->vm(); // 6.2.1 Temporal.ZonedDateTime.prototype, https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype - define_direct_property(vm.names.prototype, realm.global_object().temporal_zoned_date_time_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().temporal_zoned_date_time_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp index e0e8660802a..8cb5157afe4 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp @@ -21,7 +21,7 @@ namespace JS::Temporal { // 6.3 Properties of the Temporal.ZonedDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-zoneddatetime-prototype-object ZonedDateTimePrototype::ZonedDateTimePrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } @@ -1291,7 +1291,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields) auto* zoned_date_time = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, realm.global_object().object_prototype()); + auto* fields = Object::create(realm, realm.intrinsics().object_prototype()); // 4. Let timeZone be zonedDateTime.[[TimeZone]]. auto& time_zone = zoned_date_time->time_zone(); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 35e20e20070..5ea98f0fdcc 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -168,7 +168,7 @@ static ThrowCompletionOr 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, *realm.global_object().array_buffer_constructor(), byte_length.value())); + data = TRY(allocate_array_buffer(vm, *realm.intrinsics().array_buffer_constructor(), byte_length.value())); // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. if (src_data->is_detached()) @@ -240,7 +240,7 @@ static ThrowCompletionOr allocate_typed_array_buffer(VM& vm, TypedArray auto byte_length = element_size * length; // 4. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). - auto* data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length)); + auto* data = TRY(allocate_array_buffer(vm, *realm.intrinsics().array_buffer_constructor(), byte_length)); // 5. Set O.[[ViewedArrayBuffer]] to data. typed_array.set_viewed_array_buffer(data); @@ -346,7 +346,7 @@ ThrowCompletionOr typed_array_create_same_type(VM& vm, TypedArr // 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 = (realm.global_object().*exemplar.intrinsic_constructor())(); + auto* constructor = (realm.intrinsics().*exemplar.intrinsic_constructor())(); // 3. Let result be ? TypedArrayCreate(constructor, argumentList). auto* result = TRY(typed_array_create(vm, *constructor, move(arguments))); @@ -423,137 +423,137 @@ void TypedArrayBase::visit_edges(Visitor& visitor) visitor.visit(m_viewed_array_buffer); } -#define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type) \ - ThrowCompletionOr ClassName::create(Realm& realm, u32 length, FunctionObject& new_target) \ - { \ - auto* prototype = TRY(get_prototype_from_constructor(realm.vm(), new_target, &GlobalObject::snake_name##_prototype)); \ - auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ - return realm.heap().allocate(realm, *prototype, length, *array_buffer); \ - } \ - \ - ThrowCompletionOr ClassName::create(Realm& realm, u32 length) \ - { \ - auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ - return create(realm, length, *array_buffer); \ - } \ - \ - ClassName* ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \ - { \ - return realm.heap().allocate(realm, *realm.global_object().snake_name##_prototype(), length, array_buffer); /* */ \ - } \ - \ - ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \ - : TypedArray(prototype, \ - reinterpret_cast(&GlobalObject::snake_name##_constructor), length, array_buffer) \ - { \ - if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array")) \ - m_content_type = ContentType::BigInt; \ - else \ - m_content_type = ContentType::Number; \ - } \ - \ - ClassName::~ClassName() \ - { \ - } \ - \ - FlyString const& ClassName::element_name() const \ - { \ - return vm().names.ClassName.as_string(); \ - } \ - \ - PrototypeName::PrototypeName(Realm& realm) \ - : Object(*realm.global_object().typed_array_prototype()) \ - { \ - } \ - \ - PrototypeName::~PrototypeName() \ - { \ - } \ - \ - void PrototypeName::initialize(Realm& realm) \ - { \ - auto& vm = this->vm(); \ - Object::initialize(realm); \ - define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ - } \ - \ - ConstructorName::ConstructorName(Realm& realm) \ - : TypedArrayConstructor(vm().names.ClassName.as_string(), *realm.global_object().typed_array_constructor()) \ - { \ - } \ - \ - ConstructorName::~ConstructorName() \ - { \ - } \ - \ - void ConstructorName::initialize(Realm& realm) \ - { \ - auto& vm = this->vm(); \ - NativeFunction::initialize(realm); \ - \ - /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */ \ - define_direct_property(vm.names.prototype, realm.global_object().snake_name##_prototype(), 0); \ - \ - /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */ \ - define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ - \ - define_direct_property(vm.names.length, Value(3), Attribute::Configurable); \ - } \ - \ - /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ - ThrowCompletionOr ConstructorName::call() \ - { \ - auto& vm = this->vm(); \ - return vm.throw_completion(ErrorType::ConstructorWithoutNew, vm.names.ClassName); \ - } \ - \ - /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ - ThrowCompletionOr ConstructorName::construct(FunctionObject& new_target) \ - { \ - auto& vm = this->vm(); \ - auto& realm = *vm.current_realm(); \ - \ - if (vm.argument_count() == 0) \ - return TRY(ClassName::create(realm, 0, new_target)); \ - \ - auto first_argument = vm.argument(0); \ - if (first_argument.is_object()) { \ - auto* typed_array = TRY(ClassName::create(realm, 0, new_target)); \ - if (first_argument.as_object().is_typed_array()) { \ - auto& arg_typed_array = static_cast(first_argument.as_object()); \ - TRY(initialize_typed_array_from_typed_array(vm, *typed_array, arg_typed_array)); \ - } else if (is(first_argument.as_object())) { \ - auto& array_buffer = static_cast(first_argument.as_object()); \ - TRY(initialize_typed_array_from_array_buffer(vm, *typed_array, array_buffer, \ - vm.argument(1), vm.argument(2))); \ - } else { \ - auto iterator = TRY(first_argument.get_method(vm, *vm.well_known_symbol_iterator())); \ - if (iterator) { \ - auto values = TRY(iterable_to_list(vm, first_argument, iterator)); \ - TRY(initialize_typed_array_from_list(vm, *typed_array, values)); \ - } else { \ - TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object())); \ - } \ - } \ - return typed_array; \ - } \ - \ - auto array_length_or_error = first_argument.to_index(vm); \ - if (array_length_or_error.is_error()) { \ - auto error = array_length_or_error.release_error(); \ - if (error.value()->is_object() && is(error.value()->as_object())) { \ - /* Re-throw more specific RangeError */ \ - return vm.throw_completion(ErrorType::InvalidLength, "typed array"); \ - } \ - return error; \ - } \ - auto array_length = array_length_or_error.release_value(); \ - if (array_length > NumericLimits::max() / sizeof(Type)) \ - return vm.throw_completion(ErrorType::InvalidLength, "typed array"); \ - /* FIXME: What is the best/correct behavior here? */ \ - if (Checked::multiplication_would_overflow(array_length, sizeof(Type))) \ - return vm.throw_completion(ErrorType::InvalidLength, "typed array"); \ - return TRY(ClassName::create(realm, array_length, new_target)); \ +#define JS_DEFINE_TYPED_ARRAY(ClassName, snake_name, PrototypeName, ConstructorName, Type) \ + ThrowCompletionOr 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))); \ + return realm.heap().allocate(realm, *prototype, length, *array_buffer); \ + } \ + \ + ThrowCompletionOr ClassName::create(Realm& realm, u32 length) \ + { \ + auto* array_buffer = TRY(ArrayBuffer::create(realm, length * sizeof(UnderlyingBufferDataType))); \ + return create(realm, length, *array_buffer); \ + } \ + \ + ClassName* ClassName::create(Realm& realm, u32 length, ArrayBuffer& array_buffer) \ + { \ + return realm.heap().allocate(realm, *realm.intrinsics().snake_name##_prototype(), length, array_buffer); \ + } \ + \ + ClassName::ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer) \ + : TypedArray(prototype, \ + reinterpret_cast(&Intrinsics::snake_name##_constructor), length, array_buffer) \ + { \ + if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array")) \ + m_content_type = ContentType::BigInt; \ + else \ + m_content_type = ContentType::Number; \ + } \ + \ + ClassName::~ClassName() \ + { \ + } \ + \ + FlyString const& ClassName::element_name() const \ + { \ + return vm().names.ClassName.as_string(); \ + } \ + \ + PrototypeName::PrototypeName(Realm& realm) \ + : Object(*realm.intrinsics().typed_array_prototype()) \ + { \ + } \ + \ + PrototypeName::~PrototypeName() \ + { \ + } \ + \ + void PrototypeName::initialize(Realm& realm) \ + { \ + auto& vm = this->vm(); \ + Object::initialize(realm); \ + define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ + } \ + \ + ConstructorName::ConstructorName(Realm& realm) \ + : TypedArrayConstructor(vm().names.ClassName.as_string(), *realm.intrinsics().typed_array_constructor()) \ + { \ + } \ + \ + ConstructorName::~ConstructorName() \ + { \ + } \ + \ + void ConstructorName::initialize(Realm& realm) \ + { \ + auto& vm = this->vm(); \ + NativeFunction::initialize(realm); \ + \ + /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */ \ + define_direct_property(vm.names.prototype, realm.intrinsics().snake_name##_prototype(), 0); \ + \ + /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */ \ + define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ + \ + define_direct_property(vm.names.length, Value(3), Attribute::Configurable); \ + } \ + \ + /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ + ThrowCompletionOr ConstructorName::call() \ + { \ + auto& vm = this->vm(); \ + return vm.throw_completion(ErrorType::ConstructorWithoutNew, vm.names.ClassName); \ + } \ + \ + /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ + ThrowCompletionOr ConstructorName::construct(FunctionObject& new_target) \ + { \ + auto& vm = this->vm(); \ + auto& realm = *vm.current_realm(); \ + \ + if (vm.argument_count() == 0) \ + return TRY(ClassName::create(realm, 0, new_target)); \ + \ + auto first_argument = vm.argument(0); \ + if (first_argument.is_object()) { \ + auto* typed_array = TRY(ClassName::create(realm, 0, new_target)); \ + if (first_argument.as_object().is_typed_array()) { \ + auto& arg_typed_array = static_cast(first_argument.as_object()); \ + TRY(initialize_typed_array_from_typed_array(vm, *typed_array, arg_typed_array)); \ + } else if (is(first_argument.as_object())) { \ + auto& array_buffer = static_cast(first_argument.as_object()); \ + TRY(initialize_typed_array_from_array_buffer(vm, *typed_array, array_buffer, \ + vm.argument(1), vm.argument(2))); \ + } else { \ + auto iterator = TRY(first_argument.get_method(vm, *vm.well_known_symbol_iterator())); \ + if (iterator) { \ + auto values = TRY(iterable_to_list(vm, first_argument, iterator)); \ + TRY(initialize_typed_array_from_list(vm, *typed_array, values)); \ + } else { \ + TRY(initialize_typed_array_from_array_like(vm, *typed_array, first_argument.as_object())); \ + } \ + } \ + return typed_array; \ + } \ + \ + auto array_length_or_error = first_argument.to_index(vm); \ + if (array_length_or_error.is_error()) { \ + auto error = array_length_or_error.release_error(); \ + if (error.value()->is_object() && is(error.value()->as_object())) { \ + /* Re-throw more specific RangeError */ \ + return vm.throw_completion(ErrorType::InvalidLength, "typed array"); \ + } \ + return error; \ + } \ + auto array_length = array_length_or_error.release_value(); \ + if (array_length > NumericLimits::max() / sizeof(Type)) \ + return vm.throw_completion(ErrorType::InvalidLength, "typed array"); \ + /* FIXME: What is the best/correct behavior here? */ \ + if (Checked::multiplication_would_overflow(array_length, sizeof(Type))) \ + return vm.throw_completion(ErrorType::InvalidLength, "typed array"); \ + return TRY(ClassName::create(realm, array_length, new_target)); \ } #undef __JS_ENUMERATE diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index 6d7da888549..403c809a51d 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -32,7 +32,7 @@ public: Number, }; - using IntrinsicConstructor = TypedArrayConstructor* (GlobalObject::*)(); + using IntrinsicConstructor = TypedArrayConstructor* (Intrinsics::*)(); u32 array_length() const { return m_array_length; } u32 byte_length() const { return m_byte_length; } diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp index 2282b0f3b82..ab711200de8 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp @@ -17,7 +17,7 @@ TypedArrayConstructor::TypedArrayConstructor(FlyString const& name, Object& prot } TypedArrayConstructor::TypedArrayConstructor(Realm& realm) - : NativeFunction(vm().names.TypedArray.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.TypedArray.as_string(), *realm.intrinsics().function_prototype()) { } @@ -27,7 +27,7 @@ void TypedArrayConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 23.2.2.3 %TypedArray%.prototype, https://tc39.es/ecma262/#sec-%typedarray%.prototype - define_direct_property(vm.names.prototype, realm.global_object().typed_array_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().typed_array_prototype(), 0); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(realm, vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index a391a9f45b5..e9b83e07f9f 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -16,7 +16,7 @@ namespace JS { TypedArrayPrototype::TypedArrayPrototype(Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { } @@ -65,7 +65,7 @@ void TypedArrayPrototype::initialize(Realm& realm) define_native_accessor(realm, *vm.well_known_symbol_to_string_tag(), to_string_tag_getter, nullptr, Attribute::Configurable); // 23.2.3.32 %TypedArray%.prototype.toString ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.tostring - define_direct_property(vm.names.toString, realm.global_object().array_prototype()->get_without_side_effects(vm.names.toString), attr); + define_direct_property(vm.names.toString, realm.intrinsics().array_prototype()->get_without_side_effects(vm.names.toString), attr); // 23.2.3.34 %TypedArray%.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype-@@iterator define_direct_property(*vm.well_known_symbol_iterator(), get_without_side_effects(vm.names.values), attr); @@ -146,7 +146,7 @@ static ThrowCompletionOr typed_array_species_create(VM& vm, Typ auto& realm = *vm.current_realm(); // 1. Let defaultConstructor be the intrinsic object listed in column one of Table 72 for exemplar.[[TypedArrayName]]. - auto* default_constructor = (realm.global_object().*exemplar.intrinsic_constructor())(); + auto* default_constructor = (realm.intrinsics().*exemplar.intrinsic_constructor())(); // 2. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). auto* constructor = TRY(species_constructor(vm, exemplar, *default_constructor)); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index bcc591c9934..8a1c09e9063 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -336,7 +336,7 @@ ThrowCompletionOr VM::property_binding_initialization(BindingPattern const VERIFY_NOT_REACHED(); } - auto* rest_object = Object::create(realm, realm.global_object().object_prototype()); + auto* rest_object = Object::create(realm, realm.intrinsics().object_prototype()); VERIFY(rest_object); TRY(rest_object->copy_data_properties(vm, object, seen_names)); diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index cb5650540f4..a4997dc5ad9 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -450,7 +450,7 @@ ThrowCompletionOr Value::to_object(VM& vm) const case BOOLEAN_TAG: return BooleanObject::create(realm, as_bool()); case STRING_TAG: - return StringObject::create(realm, const_cast(as_string()), *realm.global_object().string_prototype()); + return StringObject::create(realm, const_cast(as_string()), *realm.intrinsics().string_prototype()); case SYMBOL_TAG: return SymbolObject::create(realm, const_cast(as_symbol())); case BIGINT_TAG: diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp index 2da2b3f40ef..0169bdf1c19 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp @@ -10,7 +10,7 @@ namespace JS { WeakMap* WeakMap::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().weak_map_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().weak_map_prototype()); } WeakMap::WeakMap(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp index 2ffda9bdc57..73667d24f5f 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { WeakMapConstructor::WeakMapConstructor(Realm& realm) - : NativeFunction(vm().names.WeakMap.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.WeakMap.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void WeakMapConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 24.3.2.1 WeakMap.prototype, https://tc39.es/ecma262/#sec-weakmap.prototype - define_direct_property(vm.names.prototype, realm.global_object().weak_map_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().weak_map_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); } @@ -41,7 +41,7 @@ ThrowCompletionOr WeakMapConstructor::construct(FunctionObject& new_tar { auto& vm = this->vm(); - auto* weak_map = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::weak_map_prototype)); + auto* weak_map = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::weak_map_prototype)); if (vm.argument(0).is_nullish()) return weak_map; diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp index 8f311fcb2d3..08538e9d538 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp @@ -12,7 +12,7 @@ namespace JS { WeakMapPrototype::WeakMapPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp index d3d10a2cb91..023ccbcbd45 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp @@ -10,12 +10,12 @@ namespace JS { WeakRef* WeakRef::create(Realm& realm, Object& value) { - return realm.heap().allocate(realm, value, *realm.global_object().weak_ref_prototype()); + return realm.heap().allocate(realm, value, *realm.intrinsics().weak_ref_prototype()); } WeakRef* WeakRef::create(Realm& realm, Symbol& value) { - return realm.heap().allocate(realm, value, *realm.global_object().weak_ref_prototype()); + return realm.heap().allocate(realm, value, *realm.intrinsics().weak_ref_prototype()); } WeakRef::WeakRef(Object& value, Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp index e4769ab8673..302f291f7a4 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp @@ -13,7 +13,7 @@ namespace JS { WeakRefConstructor::WeakRefConstructor(Realm& realm) - : NativeFunction(vm().names.WeakRef.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.WeakRef.as_string(), *realm.intrinsics().function_prototype()) { } @@ -23,7 +23,7 @@ void WeakRefConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 26.1.2.1 WeakRef.prototype, https://tc39.es/ecma262/#sec-weak-ref.prototype - define_direct_property(vm.names.prototype, realm.global_object().weak_ref_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().weak_ref_prototype(), 0); define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } @@ -45,9 +45,9 @@ ThrowCompletionOr WeakRefConstructor::construct(FunctionObject& new_tar return vm.throw_completion(ErrorType::CannotBeHeldWeakly, target.to_string_without_side_effects()); if (target.is_object()) - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::weak_ref_prototype, target.as_object())); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::weak_ref_prototype, target.as_object())); VERIFY(target.is_symbol()); - return TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::weak_ref_prototype, target.as_symbol())); + return TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::weak_ref_prototype, target.as_symbol())); } } diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp index bd90ec78659..5b7b818407a 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp @@ -10,7 +10,7 @@ namespace JS { WeakRefPrototype::WeakRefPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp index afa0f30a8b4..336a3d1501c 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp @@ -10,7 +10,7 @@ namespace JS { WeakSet* WeakSet::create(Realm& realm) { - return realm.heap().allocate(realm, *realm.global_object().weak_set_prototype()); + return realm.heap().allocate(realm, *realm.intrinsics().weak_set_prototype()); } WeakSet::WeakSet(Object& prototype) diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp index 493e0b27564..146d022228d 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp @@ -14,7 +14,7 @@ namespace JS { WeakSetConstructor::WeakSetConstructor(Realm& realm) - : NativeFunction(vm().names.WeakSet.as_string(), *realm.global_object().function_prototype()) + : NativeFunction(vm().names.WeakSet.as_string(), *realm.intrinsics().function_prototype()) { } @@ -24,7 +24,7 @@ void WeakSetConstructor::initialize(Realm& realm) NativeFunction::initialize(realm); // 24.4.2.1 WeakSet.prototype, https://tc39.es/ecma262/#sec-weakset.prototype - define_direct_property(vm.names.prototype, realm.global_object().weak_set_prototype(), 0); + define_direct_property(vm.names.prototype, realm.intrinsics().weak_set_prototype(), 0); define_direct_property(vm.names.length, Value(0), Attribute::Configurable); } @@ -41,7 +41,7 @@ ThrowCompletionOr WeakSetConstructor::construct(FunctionObject& new_tar { auto& vm = this->vm(); - auto* weak_set = TRY(ordinary_create_from_constructor(vm, new_target, &GlobalObject::weak_set_prototype)); + auto* weak_set = TRY(ordinary_create_from_constructor(vm, new_target, &Intrinsics::weak_set_prototype)); if (vm.argument(0).is_nullish()) return weak_set; diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp index f1c0833b75f..1d536fcb3eb 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp @@ -12,7 +12,7 @@ namespace JS { WeakSetPrototype::WeakSetPrototype(Realm& realm) - : PrototypeObject(*realm.global_object().object_prototype()) + : PrototypeObject(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp index 65356ba0a59..31d020511d0 100644 --- a/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/WrappedFunction.cpp @@ -21,7 +21,7 @@ ThrowCompletionOr WrappedFunction::create(Realm& realm, Realm& // 4. Set wrapped.[[Call]] as described in 2.1. // 5. Set wrapped.[[WrappedTargetFunction]] to Target. // 6. Set wrapped.[[Realm]] to callerRealm. - auto& prototype = *caller_realm.global_object().function_prototype(); + auto& prototype = *caller_realm.intrinsics().function_prototype(); auto* wrapped = vm.heap().allocate(realm, caller_realm, target, prototype); // 7. Let result be CopyNameAndLength(wrapped, Target). diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp index 709de2869c4..bf76e76106b 100644 --- a/Userland/Libraries/LibJS/SyntheticModule.cpp +++ b/Userland/Libraries/LibJS/SyntheticModule.cpp @@ -148,7 +148,7 @@ ThrowCompletionOr> parse_json_module(StringView source_tex auto& vm = realm.vm(); // 1. Let jsonParse be realm's intrinsic object named "%JSON.parse%". - auto* json_parse = realm.global_object().json_parse_function(); + auto* json_parse = realm.intrinsics().json_parse_function(); // 2. Let json be ? Call(jsonParse, undefined, « sourceText »). auto json = TRY(call(vm, *json_parse, js_undefined(), js_string(realm.vm(), source_text))); diff --git a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp index 54ef7887914..775ff6d7739 100644 --- a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp @@ -15,7 +15,7 @@ namespace Web::Bindings { AudioConstructor::AudioConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp b/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp index 55a39552652..97f9c4b8b58 100644 --- a/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp @@ -14,7 +14,7 @@ namespace Web::Bindings { CSSNamespace::CSSNamespace(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/EventListenerWrapper.cpp b/Userland/Libraries/LibWeb/Bindings/EventListenerWrapper.cpp index c161fea5857..ebcc9a890ff 100644 --- a/Userland/Libraries/LibWeb/Bindings/EventListenerWrapper.cpp +++ b/Userland/Libraries/LibWeb/Bindings/EventListenerWrapper.cpp @@ -13,7 +13,7 @@ namespace Web { namespace Bindings { EventListenerWrapper::EventListenerWrapper(JS::Realm& realm, DOM::IDLEventListener& impl) - : Wrapper(*realm.global_object().object_prototype()) + : Wrapper(*realm.intrinsics().object_prototype()) , m_impl(impl) { } diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 7c2810aff66..772daf0f248 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -15,7 +15,7 @@ namespace Web::Bindings { ImageConstructor::ImageConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp index 94aa81905f3..774fbfed70a 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp @@ -12,7 +12,7 @@ namespace Web::Bindings { LocationConstructor::LocationConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h b/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h index cc597d0ac42..52ed45fe8da 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h +++ b/Userland/Libraries/LibWeb/Bindings/LocationPrototype.h @@ -19,7 +19,7 @@ class LocationPrototype final : public JS::Object { public: explicit LocationPrototype(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } }; diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp index 92b897893e4..8a1b13e22f3 100644 --- a/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp @@ -12,7 +12,7 @@ namespace Web::Bindings { NavigatorConstructor::NavigatorConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h b/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h index c94aa13e607..32eb17d619c 100644 --- a/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorPrototype.h @@ -19,7 +19,7 @@ class NavigatorPrototype final : public JS::Object { public: explicit NavigatorPrototype(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } }; diff --git a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp index 8f72bab8161..c4b7930f13f 100644 --- a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp @@ -16,7 +16,7 @@ namespace Web::Bindings { OptionConstructor::OptionConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp index 946aff90072..ef33827f171 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp @@ -12,7 +12,7 @@ namespace Web::Bindings { WindowConstructor::WindowConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp index ca6a07d9174..bcb42d8a04b 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp @@ -15,7 +15,7 @@ namespace Web::Bindings { WebAssemblyInstanceConstructor::WebAssemblyInstanceConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h index 8f409538a3c..36ba30e1d15 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.h @@ -18,7 +18,7 @@ class WebAssemblyInstancePrototype final : public JS::Object { public: explicit WebAssemblyInstancePrototype(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp index ea23f37cbeb..35f38465ea3 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp @@ -13,7 +13,7 @@ namespace Web::Bindings { WebAssemblyMemoryConstructor::WebAssemblyMemoryConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h index ac68af75fd7..c9b8aa03e3b 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.h @@ -20,7 +20,7 @@ class WebAssemblyMemoryPrototype final : public JS::Object { public: explicit WebAssemblyMemoryPrototype(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp index 06969b48a63..71a24e76943 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp @@ -15,7 +15,7 @@ namespace Web::Bindings { WebAssemblyModuleConstructor::WebAssemblyModuleConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModulePrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModulePrototype.h index b2177e2e982..33890534c79 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModulePrototype.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModulePrototype.h @@ -20,7 +20,7 @@ class WebAssemblyModulePrototype final : public JS::Object { public: explicit WebAssemblyModulePrototype(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } }; diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index a5d2ad63b84..5be142435f4 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -26,7 +26,7 @@ namespace Web::Bindings { WebAssemblyObject::WebAssemblyObject(JS::Realm& realm) - : Object(*realm.global_object().object_prototype()) + : Object(*realm.intrinsics().object_prototype()) { s_abstract_machine.enable_instruction_count_limit(); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp index a9a7bef0feb..0698f06be58 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp @@ -15,7 +15,7 @@ namespace Web::Bindings { WebAssemblyTableConstructor::WebAssemblyTableConstructor(JS::Realm& realm) - : NativeFunction(*realm.global_object().function_prototype()) + : NativeFunction(*realm.intrinsics().function_prototype()) { } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h index c3d576f0a9f..d5616de1919 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.h @@ -20,7 +20,7 @@ class WebAssemblyTablePrototype final : public JS::Object { public: explicit WebAssemblyTablePrototype(JS::Realm& realm) - : JS::Object(*realm.global_object().object_prototype()) + : JS::Object(*realm.intrinsics().object_prototype()) { } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index b08020d917e..260eab4e840 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -143,7 +143,7 @@ DOM::ExceptionOr XMLHttpRequest::response() // 3. Let jsonObject be the result of running parse JSON from bytes on this’s received bytes. If that threw an exception, then return null. TextCodec::UTF8Decoder decoder; - auto json_object_result = JS::call(vm, realm.global_object().json_parse_function(), JS::js_undefined(), JS::js_string(vm, decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() }))); + auto json_object_result = JS::call(vm, realm.intrinsics().json_parse_function(), JS::js_undefined(), JS::js_string(vm, decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() }))); if (json_object_result.is_error()) return JS::Value(JS::js_null()); diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index b9f4c187e31..4d51a76b7c8 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1003,8 +1003,11 @@ static void print_value(JS::Value value, HashTable& seen_objects) return print_error(object, seen_objects); auto prototype_or_error = object.internal_get_prototype_of(); - if (prototype_or_error.has_value() && prototype_or_error.value() == object.global_object().error_prototype()) - return print_error(object, seen_objects); + if (prototype_or_error.has_value() && prototype_or_error.value() != nullptr) { + auto& prototype = *prototype_or_error.value(); + if (&prototype == prototype.shape().realm().intrinsics().error_prototype()) + return print_error(object, seen_objects); + } if (is(object)) return print_regexp_object(static_cast(object), seen_objects); @@ -1272,9 +1275,9 @@ static JS::ThrowCompletionOr load_ini_impl(JS::VM& vm) return vm.throw_completion(String::formatted("Failed to open '{}': {}", filename, file->error_string())); auto config_file = MUST(Core::ConfigFile::open(filename, file->fd())); - auto* object = JS::Object::create(realm, realm.global_object().object_prototype()); + auto* object = JS::Object::create(realm, realm.intrinsics().object_prototype()); for (auto const& group : config_file->groups()) { - auto* group_object = JS::Object::create(realm, realm.global_object().object_prototype()); + auto* group_object = JS::Object::create(realm, realm.intrinsics().object_prototype()); for (auto const& key : config_file->keys(group)) { auto entry = config_file->read_entry(group, key); group_object->define_direct_property(key, js_string(vm, move(entry)), JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable);