From b465f46e009164b5d2659f216b9307efee187222 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 22 Aug 2022 11:48:08 +0100 Subject: [PATCH] LibJS: Remove GlobalObject parameter from native functions --- .../LibWeb/WrapperGenerator/IDLGenerators.cpp | 4 +-- Tests/LibWasm/test-wasm.cpp | 4 +-- .../Spreadsheet/JSIntegration.cpp | 10 +++--- Userland/Libraries/LibJS/Bytecode/Op.cpp | 4 +-- Userland/Libraries/LibJS/CyclicModule.cpp | 4 +-- Userland/Libraries/LibJS/Forward.h | 4 +-- .../LibJS/Runtime/AbstractOperations.cpp | 4 +-- .../LibJS/Runtime/ArrayBufferPrototype.cpp | 4 ++- .../LibJS/Runtime/ArrayConstructor.cpp | 4 +-- .../LibJS/Runtime/ArrayIteratorPrototype.cpp | 2 +- .../LibJS/Runtime/ArrayPrototype.cpp | 24 +++++++------ .../AsyncFromSyncIteratorPrototype.cpp | 14 ++++---- .../Runtime/AsyncFunctionDriverWrapper.cpp | 4 +-- .../LibJS/Runtime/BigIntPrototype.cpp | 4 ++- .../Libraries/LibJS/Runtime/Completion.cpp | 4 +-- .../Libraries/LibJS/Runtime/ConsoleObject.cpp | 34 +++++++++---------- .../LibJS/Runtime/DateConstructor.cpp | 5 ++- .../Libraries/LibJS/Runtime/DatePrototype.cpp | 2 +- .../Runtime/ECMAScriptFunctionObject.cpp | 2 +- .../LibJS/Runtime/FunctionPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/GlobalObject.cpp | 2 +- .../LibJS/Runtime/Intl/CollatorPrototype.cpp | 6 ++-- .../Runtime/Intl/DateTimeFormatPrototype.cpp | 10 +++--- .../Runtime/Intl/DisplayNamesPrototype.cpp | 4 +-- .../Runtime/Intl/DurationFormatPrototype.cpp | 8 ++--- .../Libraries/LibJS/Runtime/Intl/Intl.cpp | 4 +-- .../Runtime/Intl/ListFormatPrototype.cpp | 4 +-- .../LibJS/Runtime/Intl/LocalePrototype.cpp | 12 +++---- .../Runtime/Intl/NumberFormatPrototype.cpp | 6 ++-- .../Runtime/Intl/PluralRulesPrototype.cpp | 4 +-- .../Intl/RelativeTimeFormatPrototype.cpp | 4 +-- .../LibJS/Runtime/Intl/SegmenterPrototype.cpp | 6 ++-- .../LibJS/Runtime/Intl/SegmentsPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/JSONObject.cpp | 4 +-- .../LibJS/Runtime/MapIteratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/MapPrototype.cpp | 6 ++-- .../Libraries/LibJS/Runtime/MathObject.cpp | 4 +-- .../LibJS/Runtime/NativeFunction.cpp | 10 +++--- .../Libraries/LibJS/Runtime/NativeFunction.h | 10 +++--- .../LibJS/Runtime/NumberPrototype.cpp | 4 ++- Userland/Libraries/LibJS/Runtime/Object.cpp | 4 +-- Userland/Libraries/LibJS/Runtime/Object.h | 4 +-- .../LibJS/Runtime/ObjectConstructor.cpp | 20 +++++------ Userland/Libraries/LibJS/Runtime/Promise.cpp | 6 ++-- .../LibJS/Runtime/PromisePrototype.cpp | 20 ++++++----- .../LibJS/Runtime/PromiseReaction.cpp | 2 +- .../Runtime/PromiseResolvingFunction.cpp | 4 +-- .../LibJS/Runtime/PromiseResolvingFunction.h | 4 +-- .../LibJS/Runtime/ProxyConstructor.cpp | 4 +-- .../Libraries/LibJS/Runtime/ReflectObject.cpp | 2 +- .../LibJS/Runtime/RegExpPrototype.cpp | 17 ++++++---- .../LibJS/Runtime/SetIteratorPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/SetPrototype.cpp | 4 +-- .../Libraries/LibJS/Runtime/ShadowRealm.cpp | 4 +-- .../LibJS/Runtime/StringPrototype.cpp | 8 +++-- .../LibJS/Runtime/SymbolConstructor.cpp | 2 +- .../Runtime/Temporal/CalendarPrototype.cpp | 2 +- .../Runtime/Temporal/DurationPrototype.cpp | 4 +-- .../Runtime/Temporal/InstantPrototype.cpp | 2 +- .../Runtime/Temporal/PlainDatePrototype.cpp | 4 +-- .../Temporal/PlainDateTimePrototype.cpp | 6 ++-- .../Temporal/PlainMonthDayPrototype.cpp | 6 ++-- .../Runtime/Temporal/PlainTimePrototype.cpp | 6 ++-- .../Temporal/PlainYearMonthPrototype.cpp | 6 ++-- .../Runtime/Temporal/TimeZonePrototype.cpp | 2 +- .../Temporal/ZonedDateTimePrototype.cpp | 6 ++-- .../LibJS/Runtime/TypedArrayPrototype.cpp | 6 ++-- Userland/Libraries/LibJS/Runtime/VM.cpp | 8 ++--- .../Libraries/LibTest/JavaScriptTestRunner.h | 6 ++-- .../CrossOriginAbstractOperations.cpp | 6 ++-- .../LibWeb/Bindings/LocationObject.cpp | 6 ++++ .../LibWeb/Bindings/WindowObject.cpp | 2 +- Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Worker.cpp | 2 +- .../WebAssemblyMemoryPrototype.cpp | 2 +- .../LibWeb/WebAssembly/WebAssemblyObject.cpp | 8 ++--- Userland/Utilities/js.cpp | 5 +-- 77 files changed, 240 insertions(+), 215 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 4f27362ea68..d99200f575e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -1788,12 +1788,12 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@) if (arguments_match_check.is_empty()) { function_generator.append(R"~~~( - return @function.name:snakecase@@overload_suffix@(vm, global_object); + return @function.name:snakecase@@overload_suffix@(vm); )~~~"); } else { function_generator.append(R"~~~( if (@arguments_match_check@) - return @function.name:snakecase@@overload_suffix@(vm, global_object); + return @function.name:snakecase@@overload_suffix@(vm); )~~~"); } diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 300d0f84f00..5a99fdc4fdf 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -14,7 +14,7 @@ TEST_ROOT("Userland/Libraries/LibWasm/Tests"); TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto filename = TRY(vm.argument(0).to_string(vm)); auto file = Core::Stream::File::open(filename, Core::Stream::OpenMode::Read); if (file.is_error()) @@ -100,7 +100,7 @@ HashMap WebAssemblyModule::s_spec_test_na TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* object = TRY(vm.argument(0).to_object(vm)); if (!is(object)) return vm.throw_completion("Expected a Uint8Array argument to parse_webassembly_module"); diff --git a/Userland/Applications/Spreadsheet/JSIntegration.cpp b/Userland/Applications/Spreadsheet/JSIntegration.cpp index dabd7e50c4f..601ae8fcef5 100644 --- a/Userland/Applications/Spreadsheet/JSIntegration.cpp +++ b/Userland/Applications/Spreadsheet/JSIntegration.cpp @@ -177,7 +177,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_name) return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "SheetGlobalObject"); auto sheet_object = static_cast(this_object); - return JS::js_string(global_object.heap(), sheet_object->m_sheet.name()); + return JS::js_string(vm, sheet_object->m_sheet.name()); } JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents) @@ -240,7 +240,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents) JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* this_object = TRY(vm.this_value().to_object(vm)); @@ -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, global_object.object_prototype()); + auto object = JS::Object::create(realm, realm.global_object().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); @@ -267,7 +267,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name) JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); if (vm.argument_count() != 0) return vm.throw_completion("Expected no arguments to current_cell_position()"); @@ -284,7 +284,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position) auto position = current_cell->position(); - auto object = JS::Object::create(realm, global_object.object_prototype()); + auto object = JS::Object::create(realm, realm.global_object().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); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 2a41865bc0d..267bb43f249 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -718,8 +718,8 @@ ThrowCompletionOr GetObjectPropertyIterator::execute_impl(Bytecode::Interp .iterator = object, .next_method = NativeFunction::create( interpreter.realm(), - [seen_items = HashTable(), items = move(properties)](VM& vm, GlobalObject& global_object) mutable -> ThrowCompletionOr { - auto& realm = *global_object.associated_realm(); + [seen_items = HashTable(), items = move(properties)](VM& vm) mutable -> ThrowCompletionOr { + auto& realm = *vm.current_realm(); auto iterated_object_value = vm.this_value(); if (!iterated_object_value.is_object()) return vm.throw_completion("Invalid state for GetObjectPropertyIterator.next"); diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp index bc04cd42d15..029ada98577 100644 --- a/Userland/Libraries/LibJS/CyclicModule.cpp +++ b/Userland/Libraries/LibJS/CyclicModule.cpp @@ -446,7 +446,7 @@ void CyclicModule::execute_async_module(VM& vm) auto capability = MUST(new_promise_capability(vm, global_object.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, GlobalObject&) -> ThrowCompletionOr { + auto fulfilled_closure = [&](VM& vm) -> ThrowCompletionOr { // a. Perform AsyncModuleExecutionFulfilled(module). async_module_execution_fulfilled(vm); @@ -458,7 +458,7 @@ void CyclicModule::execute_async_module(VM& vm) auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, ""); // 6. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures module and performs the following steps when called: - auto rejected_closure = [&](VM& vm, GlobalObject&) -> ThrowCompletionOr { + auto rejected_closure = [&](VM& vm) -> ThrowCompletionOr { auto error = vm.argument(0); // a. Perform AsyncModuleExecutionRejected(module, error). diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h index 4b4b7869d25..072f529d945 100644 --- a/Userland/Libraries/LibJS/Forward.h +++ b/Userland/Libraries/LibJS/Forward.h @@ -9,10 +9,10 @@ #include #define JS_DECLARE_NATIVE_FUNCTION(name) \ - static JS::ThrowCompletionOr name(JS::VM&, JS::GlobalObject&) + static JS::ThrowCompletionOr name(JS::VM&) #define JS_DEFINE_NATIVE_FUNCTION(name) \ - JS::ThrowCompletionOr name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object) + JS::ThrowCompletionOr name([[maybe_unused]] JS::VM& vm) // NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately. #define JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \ diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index f729ca1f2a6..b912fae44cc 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -1118,10 +1118,10 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector< // 3. Perform ! map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]: false, [[Configurable]]: true }). object->parameter_map().define_native_accessor( PropertyKey { index }, - [&environment, name](VM& vm, GlobalObject&) -> ThrowCompletionOr { + [&environment, name](VM& vm) -> ThrowCompletionOr { return MUST(environment.get_binding_value(vm, name, false)); }, - [&environment, name](VM& vm, GlobalObject&) { + [&environment, name](VM& vm) { MUST(environment.set_mutable_binding(vm, name, vm.argument(0), false)); return js_undefined(); }, diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp index b181770e098..23d8021d3a8 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp @@ -34,6 +34,8 @@ void ArrayBufferPrototype::initialize(Realm& realm) // 25.1.5.3 ArrayBuffer.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice) { + auto& realm = *vm.current_realm(); + // 1. Let O be the this value. // 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). auto* array_buffer_object = TRY(typed_this_value(vm)); @@ -80,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, *global_object.array_buffer_constructor())); + auto* constructor = TRY(species_constructor(vm, *array_buffer_object, *realm.global_object().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 e9d650426f0..c06637492ce 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -85,7 +85,7 @@ ThrowCompletionOr ArrayConstructor::construct(FunctionObject& new_targe // 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto constructor = vm.this_value(); FunctionObject* map_fn = nullptr; @@ -177,7 +177,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array) // 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto this_value = vm.this_value(); Object* array; if (this_value.is_constructor()) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index c51442e95ac..2b179c49e07 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -34,7 +34,7 @@ void ArrayIteratorPrototype::initialize(Realm& realm) // FIXME: This seems to be CreateArrayIterator (https://tc39.es/ecma262/#sec-createarrayiterator) instead of %ArrayIteratorPrototype%.next. JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* iterator = TRY(typed_this_value(vm)); auto target_array = iterator->array(); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index c7e5047bbf0..1218fcd1756 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -189,7 +189,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat) return TRY(val.is_array(vm)); }; - auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &global_object, &n](Value arg) -> ThrowCompletionOr { + auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &n](Value arg) -> ThrowCompletionOr { auto spreadable = TRY(is_concat_spreadable(arg)); if (spreadable) { VERIFY(arg.is_object()); @@ -295,7 +295,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within) // 23.1.3.5 Array.prototype.entries ( ), https://tc39.es/ecma262/#sec-array.prototype.entries JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* this_object = TRY(vm.this_value().to_object(vm)); @@ -753,7 +753,7 @@ static void add_value_to_keyed_group(VM& vm, GroupsType& groups, KeyType key, Va // 2.1 Array.prototype.group ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.group JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto callback_function = vm.argument(0); auto this_arg = vm.argument(1); @@ -809,7 +809,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group) // 2.2 Array.prototype.groupToMap ( callbackfn [ , thisArg ] ), https://tc39.es/proposal-array-grouping/#sec-array.prototype.grouptomap JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_to_map) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto callback_function = vm.argument(0); auto this_arg = vm.argument(1); @@ -1018,7 +1018,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join) // 23.1.3.19 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* this_object = TRY(vm.this_value().to_object(vm)); @@ -1749,7 +1749,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string) // 1.1.1.4 Array.prototype.toReversed ( ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let O be ? ToObject(this value). auto* object = TRY(vm.this_value().to_object(vm)); @@ -1785,7 +1785,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_reversed) // 1.1.1.5 Array.prototype.toSorted ( comparefn ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto comparefn = vm.argument(0); @@ -1827,7 +1827,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_sorted) // 1.1.1.6 Array.prototype.toSpliced ( start, deleteCount, ...items ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto start = vm.argument(0); auto delete_count = vm.argument(1); @@ -1958,6 +1958,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_spliced) // 23.1.3.33 Array.prototype.toString ( ), https://tc39.es/ecma262/#sec-array.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string) { + auto& realm = *vm.current_realm(); + // 1. Let array be ? ToObject(this value). auto* array = TRY(vm.this_value().to_object(vm)); @@ -1966,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 = global_object.object_prototype_to_string_function(); + func = realm.global_object().object_prototype_to_string_function(); // 4. Return ? Call(func, array). return TRY(call(vm, func.as_function(), array)); @@ -2007,7 +2009,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift) // 23.1.3.35 Array.prototype.values ( ), https://tc39.es/ecma262/#sec-array.prototype.values JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* this_object = TRY(vm.this_value().to_object(vm)); @@ -2017,7 +2019,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values) // 1.1.1.7 Array.prototype.with ( index, value ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::with) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto index = vm.argument(0); auto value = vm.argument(1); diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp index 53c3a5b692c..fc886df38e2 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp @@ -50,7 +50,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *global_object.promise_constructor(), value)); // 8. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called: - auto unwrap = [done](VM& vm, GlobalObject&) -> ThrowCompletionOr { + auto unwrap = [done](VM& vm) -> ThrowCompletionOr { // a. Return CreateIterResultObject(value, done). return create_iterator_result_object(vm, vm.argument(0), done); }; @@ -69,12 +69,14 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro // 27.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next) { + auto& realm = *vm.current_realm(); + // 1. Let O be the this value. // 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot. auto* this_object = MUST(typed_this_object(vm)); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. auto& sync_iterator_record = this_object->sync_iterator_record(); @@ -95,14 +97,14 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next) // 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.return JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let O be the this value. // 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot. auto* this_object = MUST(typed_this_object(vm)); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); // 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. auto* sync_iterator = this_object->sync_iterator_record().iterator; @@ -148,14 +150,14 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_) // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.throw JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let O be the this value. // 2. Assert: O is an Object that has a [[SyncIteratorRecord]] internal slot. auto* this_object = MUST(typed_this_object(vm)); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor())); + auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor())); // 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. auto* sync_iterator = this_object->sync_iterator_record().iterator; diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp index 97dc69c3ebb..f398e8a1339 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp @@ -21,10 +21,10 @@ ThrowCompletionOr AsyncFunctionDriverWrapper::create(Realm& realm, Genera AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object) : Promise(*realm.global_object().promise_prototype()) , m_generator_object(generator_object) - , m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm, GlobalObject&) { + , m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm) { return react_to_async_task_completion(vm, vm.argument(0), true); })) - , m_on_rejection(NativeFunction::create(realm, "async.on_rejection"sv, [this](VM& vm, GlobalObject&) { + , m_on_rejection(NativeFunction::create(realm, "async.on_rejection"sv, [this](VM& vm) { return react_to_async_task_completion(vm, vm.argument(0), false); })) { diff --git a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp index d27c958ba82..1e75e493f5a 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -62,6 +62,8 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) // 19.3.1 BigInt.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-bigint.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) { + auto& realm = *vm.current_realm(); + auto locales = vm.argument(0); auto options = vm.argument(1); @@ -69,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, *global_object.intl_number_format_constructor(), locales, options))); + auto* number_format = static_cast(TRY(construct(vm, *realm.global_object().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/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp index 0414f6c0a81..eaa75d21102 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.cpp +++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp @@ -42,7 +42,7 @@ ThrowCompletionOr await(VM& vm, Value value) Optional success; Value result; // 3. Let fulfilledClosure be a new Abstract Closure with parameters (value) that captures asyncContext and performs the following steps when called: - auto fulfilled_closure = [&success, &result](VM& vm, GlobalObject&) -> ThrowCompletionOr { + auto fulfilled_closure = [&success, &result](VM& vm) -> ThrowCompletionOr { // a. Let prevContext be the running execution context. // b. Suspend prevContext. // FIXME: We don't have this concept yet. @@ -66,7 +66,7 @@ ThrowCompletionOr await(VM& vm, Value value) auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 1, ""); // 5. Let rejectedClosure be a new Abstract Closure with parameters (reason) that captures asyncContext and performs the following steps when called: - auto rejected_closure = [&success, &result](VM& vm, GlobalObject&) -> ThrowCompletionOr { + auto rejected_closure = [&success, &result](VM& vm) -> ThrowCompletionOr { // a. Let prevContext be the running execution context. // b. Suspend prevContext. // FIXME: We don't have this concept yet. diff --git a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp index ad4067eab56..ffa78e123b7 100644 --- a/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling - * Copyright (c) 2020-2021, Linus Groh + * Copyright (c) 2020-2022, Linus Groh * Copyright (c) 2020, Emanuele Torre * * SPDX-License-Identifier: BSD-2-Clause @@ -43,97 +43,97 @@ void ConsoleObject::initialize(Realm& realm) // 1.1.6. log(...data), https://console.spec.whatwg.org/#log JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::log) { - return global_object.console().log(); + return vm.current_realm()->global_object().console().log(); } // 1.1.3. debug(...data), https://console.spec.whatwg.org/#debug JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::debug) { - return global_object.console().debug(); + return vm.current_realm()->global_object().console().debug(); } // 1.1.5. info(...data), https://console.spec.whatwg.org/#info JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::info) { - return global_object.console().info(); + return vm.current_realm()->global_object().console().info(); } // 1.1.9. warn(...data), https://console.spec.whatwg.org/#warn JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::warn) { - return global_object.console().warn(); + return vm.current_realm()->global_object().console().warn(); } // 1.1.4. error(...data), https://console.spec.whatwg.org/#error JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::error) { - return global_object.console().error(); + return vm.current_realm()->global_object().console().error(); } // 1.1.8. trace(...data), https://console.spec.whatwg.org/#trace JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::trace) { - return global_object.console().trace(); + return vm.current_realm()->global_object().console().trace(); } // 1.2.1. count(label), https://console.spec.whatwg.org/#count JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count) { - return global_object.console().count(); + return vm.current_realm()->global_object().console().count(); } // 1.2.2. countReset(label), https://console.spec.whatwg.org/#countreset JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::count_reset) { - return global_object.console().count_reset(); + return vm.current_realm()->global_object().console().count_reset(); } // 1.1.2. clear(), https://console.spec.whatwg.org/#clear JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear) { - return global_object.console().clear(); + return vm.current_realm()->global_object().console().clear(); } // 1.1.1. assert(condition, ...data), https://console.spec.whatwg.org/#assert JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::assert_) { - return global_object.console().assert_(); + return vm.current_realm()->global_object().console().assert_(); } // 1.3.1. group(...data), https://console.spec.whatwg.org/#group JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group) { - return global_object.console().group(); + return vm.current_realm()->global_object().console().group(); } // 1.3.2. groupCollapsed(...data), https://console.spec.whatwg.org/#groupcollapsed JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_collapsed) { - return global_object.console().group_collapsed(); + return vm.current_realm()->global_object().console().group_collapsed(); } // 1.3.3. groupEnd(), https://console.spec.whatwg.org/#groupend JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::group_end) { - return global_object.console().group_end(); + return vm.current_realm()->global_object().console().group_end(); } // 1.4.1. time(label), https://console.spec.whatwg.org/#time JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time) { - return global_object.console().time(); + return vm.current_realm()->global_object().console().time(); } // 1.4.2. timeLog(label, ...data), https://console.spec.whatwg.org/#timelog JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_log) { - return global_object.console().time_log(); + return vm.current_realm()->global_object().console().time_log(); } // 1.4.3. timeEnd(label), https://console.spec.whatwg.org/#timeend JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::time_end) { - return global_object.console().time_end(); + return vm.current_realm()->global_object().console().time_end(); } } diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index 3222ef78fea..7fd53f18105 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -198,7 +198,6 @@ ThrowCompletionOr DateConstructor::call() ThrowCompletionOr DateConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); double date_value; @@ -249,7 +248,7 @@ ThrowCompletionOr DateConstructor::construct(FunctionObject& new_target // c. Let m be ? ToNumber(values[1]). auto month = TRY(vm.argument(1).to_number(vm)).as_double(); - auto arg_or = [&vm, &global_object](size_t i, double fallback) -> ThrowCompletionOr { + auto arg_or = [&vm](size_t i, double fallback) -> ThrowCompletionOr { return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback; }; @@ -312,7 +311,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse) // 21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ), https://tc39.es/ecma262/#sec-date.utc JS_DEFINE_NATIVE_FUNCTION(DateConstructor::utc) { - auto arg_or = [&vm, &global_object](size_t i, double fallback) -> ThrowCompletionOr { + auto arg_or = [&vm](size_t i, double fallback) -> ThrowCompletionOr { return vm.argument_count() > i ? TRY(vm.argument(i).to_number(vm)).as_double() : fallback; }; diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 7003833b87e..ffabb25ac08 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -1318,7 +1318,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::set_year) JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_gmt_string) { // NOTE: The toUTCString method is preferred. The toGMTString method is provided principally for compatibility with old code. - return to_utc_string(vm, global_object); + return to_utc_string(vm); } } diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index ca099d783c1..8874d385a91 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -726,7 +726,7 @@ void async_block_start(VM& vm, NonnullRefPtr const& async_body, Promi auto& running_context = vm.running_execution_context(); // 3. Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution context the following steps will be performed: - auto* execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm, auto&) -> ThrowCompletionOr { + auto* execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm) -> ThrowCompletionOr { // a. Let result be the result of evaluating asyncBody. auto result = async_body->execute(vm.interpreter()); diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 496b7b25a39..c009def7e40 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -82,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply) // 3.1.2.1 Function.prototype.bind ( thisArg, ...args ), https://tc39.es/proposal-shadowrealm/#sec-function.prototype.bind JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto this_argument = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 97d6afafc2c..d0ca61d56ea 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -226,7 +226,7 @@ void GlobalObject::initialize_global_object() // 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror% m_throw_type_error_function = NativeFunction::create( - realm, [](VM& vm, GlobalObject&) { + realm, [](VM& vm) { return vm.throw_completion(ErrorType::RestrictedFunctionPropertiesAccess); }, 0, "", &realm); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp index e5b06190a8d..02bc8856c43 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp @@ -34,7 +34,7 @@ void CollatorPrototype::initialize(Realm& realm) // 10.3.3 get Intl.Collator.prototype.compare, https://tc39.es/ecma402/#sec-intl.collator.prototype.compare JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let collator be the this value. // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). @@ -57,14 +57,14 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter) // 10.3.4 Intl.Collator.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let collator be the this value. // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). auto* collator = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/DateTimeFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp index 32a4d45e93a..a1354504e28 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatPrototype.cpp @@ -40,7 +40,7 @@ void DateTimeFormatPrototype::initialize(Realm& realm) // 11.3.3 get Intl.DateTimeFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.format JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let dtf be the this value. // 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then @@ -65,6 +65,8 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format) // 11.3.4 Intl.DateTimeFormat.prototype.formatToParts ( date ), https://tc39.es/ecma402/#sec-Intl.DateTimeFormat.prototype.formatToParts JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts) { + auto& realm = *vm.current_realm(); + auto date = vm.argument(0); // 1. Let dtf be the this value. @@ -76,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, global_object.date_constructor_now_function(), js_undefined())).as_double(); + date_value = MUST(call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double(); } // 4. Else, else { @@ -144,7 +146,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts) // 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let dtf be the this value. // 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then @@ -153,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, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp index 99d99d9c798..c6f8f5e1f23 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp @@ -124,14 +124,14 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of) // 12.3.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let displayNames be this value. // 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]). auto* display_names = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp index 0e4eb6df144..4a4e503b44e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp @@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format) // 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let df be this value. // 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]). @@ -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, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); // b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]). MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type))); @@ -110,14 +110,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts) // 1.4.5 Intl.DurationFormat.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.resolvedOptions JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let df be the this value. // 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]). auto* duration_format = TRY(typed_this_object(vm)); // 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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 d372e183b1b..e99001aa632 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp @@ -61,7 +61,7 @@ void Intl::initialize(Realm& realm) // 8.3.1 Intl.getCanonicalLocales ( locales ), https://tc39.es/ecma402/#sec-intl.getcanonicallocales JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto locales = vm.argument(0); @@ -109,7 +109,7 @@ static Vector available_time_zones() // 2.2.2 Intl.supportedValuesOf ( key ), https://tc39.es/proposal-intl-enumeration/#sec-intl.supportedvaluesof JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let key be ? ToString(key). auto key = TRY(vm.argument(0).to_string(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp index 204cc07ec91..94fe068d90f 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp @@ -69,14 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts) // 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let lf be the this value. // 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]). auto* list_format = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/LocalePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp index be1e4ed8add..a0fe4479ab0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp @@ -55,7 +55,7 @@ void LocalePrototype::initialize(Realm& realm) // 14.3.3 Intl.Locale.prototype.maximize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.maximize JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). @@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize) // 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). @@ -251,14 +251,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::time_zones) // 1.4.21 get Intl.Locale.prototype.textInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.textInfo JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). auto* locale_object = TRY(typed_this_object(vm)); // 3. Let info be ! ObjectCreate(%Object.prototype%). - auto* info = Object::create(realm, global_object.object_prototype()); + auto* info = Object::create(realm, realm.global_object().object_prototype()); // 4. Let dir be ! CharacterDirectionOfLocale(loc). auto direction = character_direction_of_locale(*locale_object); @@ -273,14 +273,14 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info) // 1.4.22 get Intl.Locale.prototype.weekInfo, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.weekInfo JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). [[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm)); // 3. Let info be ! ObjectCreate(%Object.prototype%). - auto* info = Object::create(realm, global_object.object_prototype()); + auto* info = Object::create(realm, realm.global_object().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/NumberFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp index 6470fc4bc04..2486888d557 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp @@ -40,7 +40,7 @@ void NumberFormatPrototype::initialize(Realm& realm) // 15.3.3 get Intl.NumberFormat.prototype.format, https://tc39.es/ecma402/#sec-intl.numberformat.prototype.format JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let nf be the this value. // 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then @@ -136,7 +136,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts) // 15.3.5 Intl.NumberFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let nf be the this value. // 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then @@ -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, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/PluralRulesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp index 289a7a19c34..e4ec32fd689 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/PluralRulesPrototype.cpp @@ -79,14 +79,14 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range) // 1.4.5 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let pr be the this value. // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). auto* plural_rules = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/RelativeTimeFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp index b321c3a2436..0ca5450c96e 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormatPrototype.cpp @@ -69,14 +69,14 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts) // 17.3.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let relativeTimeFormat be the this value. // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). auto* relative_time_format = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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/SegmenterPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp index ecd9bc65e02..c1cf4e05548 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp @@ -34,14 +34,14 @@ void SegmenterPrototype::initialize(Realm& realm) // 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.resolvedoptions JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let segmenter be the this value. // 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]). auto* segmenter = TRY(typed_this_object(vm)); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%). - auto* options = Object::create(realm, global_object.object_prototype()); + auto* options = Object::create(realm, realm.global_object().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. @@ -58,7 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options) // 18.3.3 Intl.Segmenter.prototype.segment ( string ), https://tc39.es/ecma402/#sec-intl.segmenter.prototype.segment JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let segmenter be the this value. // 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]). diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp index 15a5426cbba..b5fa596b453 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp @@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::containing) // 18.5.2.2 %SegmentsPrototype% [ @@iterator ] ( ), https://tc39.es/ecma402/#sec-%segmentsprototype%-@@iterator JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let segments be the this value. // 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]). diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index 8d646bdaffa..cbe259c3a11 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -391,7 +391,7 @@ String JSONObject::quote_json_string(String string) // 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto string = TRY(vm.argument(0).to_string(vm)); auto reviver = vm.argument(1); @@ -401,7 +401,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, global_object.object_prototype()); + auto* root = Object::create(realm, realm.global_object().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()); diff --git a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp index be182342dfc..55a4f77539d 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp @@ -30,7 +30,7 @@ void MapIteratorPrototype::initialize(Realm& realm) // 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* map_iterator = TRY(typed_this_value(vm)); if (map_iterator->done()) diff --git a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp index f93c370cc26..9d736acf06f 100644 --- a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp @@ -57,7 +57,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::delete_) // 24.1.3.4 Map.prototype.entries ( ), https://tc39.es/ecma262/#sec-map.prototype.entries JS_DEFINE_NATIVE_FUNCTION(MapPrototype::entries) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* map = TRY(typed_this_object(vm)); @@ -96,7 +96,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::has) // 24.1.3.8 Map.prototype.keys ( ), https://tc39.es/ecma262/#sec-map.prototype.keys JS_DEFINE_NATIVE_FUNCTION(MapPrototype::keys) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* map = TRY(typed_this_object(vm)); @@ -117,7 +117,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::set) // 24.1.3.11 Map.prototype.values ( ), https://tc39.es/ecma262/#sec-map.prototype.values JS_DEFINE_NATIVE_FUNCTION(MapPrototype::values) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* map = TRY(typed_this_object(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.cpp b/Userland/Libraries/LibJS/Runtime/MathObject.cpp index 5d5dc4c4ed4..64cae951323 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/MathObject.cpp @@ -176,8 +176,8 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc) if (number.is_nan()) return js_nan(); if (number.as_double() < 0) - return MathObject::ceil(vm, global_object); - return MathObject::floor(vm, global_object); + return MathObject::ceil(vm); + return MathObject::floor(vm); } // 21.3.2.30 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index b6334f590f3..4f9578c7a67 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -16,7 +16,7 @@ namespace JS { // 10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] ), https://tc39.es/ecma262/#sec-createbuiltinfunction // NOTE: This doesn't consider additionalInternalSlotsList, which is rarely used, and can either be implemented using only the `function` lambda, or needs a NativeFunction subclass. -NativeFunction* NativeFunction::create(Realm& allocating_realm, Function(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional realm, Optional prototype, Optional const& prefix) +NativeFunction* NativeFunction::create(Realm& allocating_realm, Function(VM&)> behaviour, i32 length, PropertyKey const& name, Optional realm, Optional prototype, Optional const& prefix) { auto& vm = allocating_realm.vm(); @@ -51,12 +51,12 @@ NativeFunction* NativeFunction::create(Realm& allocating_realm, Function(VM&, GlobalObject&)> function) +NativeFunction* NativeFunction::create(Realm& realm, FlyString const& name, Function(VM&)> function) { return realm.heap().allocate(realm, name, move(function), *realm.global_object().function_prototype()); } -NativeFunction::NativeFunction(Function(VM&, GlobalObject&)> native_function, Object* prototype, Realm& realm) +NativeFunction::NativeFunction(Function(VM&)> native_function, Object* prototype, Realm& realm) : FunctionObject(realm, prototype) , m_native_function(move(native_function)) , m_realm(&realm) @@ -73,7 +73,7 @@ NativeFunction::NativeFunction(Object& prototype) { } -NativeFunction::NativeFunction(FlyString name, Function(VM&, GlobalObject&)> native_function, Object& prototype) +NativeFunction::NativeFunction(FlyString name, Function(VM&)> native_function, Object& prototype) : FunctionObject(prototype) , m_name(move(name)) , m_native_function(move(native_function)) @@ -224,7 +224,7 @@ ThrowCompletionOr NativeFunction::internal_construct(MarkedVector NativeFunction::call() { - return m_native_function(vm(), global_object()); + return m_native_function(vm()); } ThrowCompletionOr NativeFunction::construct(FunctionObject&) diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.h b/Userland/Libraries/LibJS/Runtime/NativeFunction.h index 05ac7f567c6..a96517f7ed4 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.h @@ -20,11 +20,11 @@ class NativeFunction : public FunctionObject { JS_OBJECT(NativeFunction, FunctionObject); public: - static NativeFunction* create(Realm&, Function(VM&, GlobalObject&)> behaviour, i32 length, PropertyKey const& name, Optional = {}, Optional prototype = {}, Optional const& prefix = {}); - static NativeFunction* create(Realm&, FlyString const& name, Function(VM&, GlobalObject&)>); + static NativeFunction* create(Realm&, Function(VM&)> behaviour, i32 length, PropertyKey const& name, Optional = {}, Optional prototype = {}, Optional const& prefix = {}); + static NativeFunction* create(Realm&, FlyString const& name, Function(VM&)>); - NativeFunction(Function(VM&, GlobalObject&)>, Object* prototype, Realm& realm); - NativeFunction(FlyString name, Function(VM&, GlobalObject&)>, Object& prototype); + NativeFunction(Function(VM&)>, Object* prototype, Realm& realm); + NativeFunction(FlyString name, Function(VM&)>, Object& prototype); virtual void initialize(Realm&) override { } virtual ~NativeFunction() override = default; @@ -53,7 +53,7 @@ private: FlyString m_name; Optional m_initial_name; // [[InitialName]] - Function(VM&, GlobalObject&)> m_native_function; + Function(VM&)> m_native_function; Realm* m_realm { nullptr }; }; diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index d93e1a93029..763047c19fb 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -318,6 +318,8 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed) // 19.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-number.prototype.tolocalestring JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string) { + auto& realm = *vm.current_realm(); + auto locales = vm.argument(0); auto options = vm.argument(1); @@ -325,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, *global_object.intl_number_format_constructor(), locales, options))); + auto* number_format = static_cast(TRY(construct(vm, *realm.global_object().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 ec791986de6..396e79c4d6d 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1073,7 +1073,7 @@ void Object::set_prototype(Object* new_prototype) m_shape = shape.create_prototype_transition(new_prototype); } -void Object::define_native_accessor(PropertyKey const& property_key, Function(VM&, GlobalObject&)> getter, Function(VM&, GlobalObject&)> setter, PropertyAttributes attribute) +void Object::define_native_accessor(PropertyKey const& property_key, Function(VM&)> getter, Function(VM&)> setter, PropertyAttributes attribute) { auto& realm = *global_object().associated_realm(); FunctionObject* getter_function = nullptr; @@ -1123,7 +1123,7 @@ Value Object::get_without_side_effects(PropertyKey const& property_key) const return {}; } -void Object::define_native_function(PropertyKey const& property_key, Function(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute) +void Object::define_native_function(PropertyKey const& property_key, Function(VM&)> native_function, i32 length, PropertyAttributes attribute) { auto& realm = *global_object().associated_realm(); auto* function = NativeFunction::create(realm, move(native_function), length, property_key, &realm); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 3388760a085..fa29bbe48bb 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -157,8 +157,8 @@ public: void define_direct_property(PropertyKey const& property_key, Value value, PropertyAttributes attributes) { storage_set(property_key, { value, attributes }); }; void define_direct_accessor(PropertyKey const&, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes); - void define_native_function(PropertyKey const&, Function(VM&, GlobalObject&)>, i32 length, PropertyAttributes attributes); - void define_native_accessor(PropertyKey const&, Function(VM&, GlobalObject&)> getter, Function(VM&, GlobalObject&)> setter, PropertyAttributes attributes); + void define_native_function(PropertyKey const&, Function(VM&)>, i32 length, PropertyAttributes attributes); + void define_native_accessor(PropertyKey const&, Function(VM&)> getter, Function(VM&)> setter, PropertyAttributes attributes); virtual bool is_function() const { return false; } virtual bool is_typed_array() const { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 07eee4ea892..66936bc157f 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -111,7 +111,7 @@ static ThrowCompletionOr> get_own_property_keys(VM& vm, Valu // 20.1.2.10 Object.getOwnPropertyNames ( O ), https://tc39.es/ecma262/#sec-object.getownpropertynames JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, string)). return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::String))); @@ -120,7 +120,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) // 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, symbol)). return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::Symbol))); @@ -221,10 +221,10 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::freeze) // 20.1.2.7 Object.fromEntries ( iterable ), https://tc39.es/ecma262/#sec-object.fromentries JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto iterable = TRY(require_object_coercible(vm, vm.argument(0))); - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); (void)TRY(get_iterator_values(vm, iterable, [&](Value iterator_value) -> Optional { if (!iterator_value.is_object()) @@ -266,7 +266,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) // 20.1.2.9 Object.getOwnPropertyDescriptors ( O ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptors JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let obj be ? ToObject(O). auto* object = TRY(vm.argument(0).to_object(vm)); @@ -275,7 +275,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, global_object.object_prototype()); + auto* descriptors = Object::create(realm, realm.global_object().object_prototype()); // 4. For each element key of ownKeys, do for (auto& key : own_keys) { @@ -330,7 +330,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is) // 20.1.2.18 Object.keys ( O ), https://tc39.es/ecma262/#sec-object.keys JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* object = TRY(vm.argument(0).to_object(vm)); auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Key)); @@ -340,7 +340,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) // 20.1.2.23 Object.values ( O ), https://tc39.es/ecma262/#sec-object.values JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* object = TRY(vm.argument(0).to_object(vm)); auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::Value)); @@ -350,7 +350,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) // 20.1.2.5 Object.entries ( O ), https://tc39.es/ecma262/#sec-object.entries JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* object = TRY(vm.argument(0).to_object(vm)); auto name_list = TRY(object->enumerable_own_property_names(PropertyKind::KeyAndValue)); @@ -360,7 +360,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) // 20.1.2.2 Object.create ( O, Properties ), https://tc39.es/ecma262/#sec-object.create JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::create) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto proto = vm.argument(0); auto properties = vm.argument(1); diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index 96b51c7ab11..c80f0df565d 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -71,10 +71,10 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() // 6. Set resolve.[[AlreadyResolved]] to alreadyResolved. // 27.2.1.3.2 Promise Resolve Functions, https://tc39.es/ecma262/#sec-promise-resolve-functions - auto* resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& global_object, auto& promise, auto& already_resolved) { + auto* resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& promise, auto& already_resolved) { dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Resolve function was called", &promise); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto resolution = vm.argument(0); @@ -166,7 +166,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() // 11. Set reject.[[AlreadyResolved]] to alreadyResolved. // 27.2.1.3.1 Promise Reject Functions, https://tc39.es/ecma262/#sec-promise-reject-functions - auto* reject_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto&, auto& promise, auto& already_resolved) { + auto* reject_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& promise, auto& already_resolved) { dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Reject function was called", &promise); auto reason = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp index 12119cda934..3bff025998c 100644 --- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp @@ -38,6 +38,8 @@ void PromisePrototype::initialize(Realm& realm) // 27.2.5.4 Promise.prototype.then ( onFulfilled, onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.then JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then) { + auto& realm = *vm.current_realm(); + auto on_fulfilled = vm.argument(0); auto on_rejected = vm.argument(1); @@ -46,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, *global_object.promise_constructor())); + auto* constructor = TRY(species_constructor(vm, *promise, *realm.global_object().promise_constructor())); // 4. Let resultCapability be ? NewPromiseCapability(C). auto result_capability = TRY(new_promise_capability(vm, constructor)); @@ -70,7 +72,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::catch_) // 27.2.5.3 Promise.prototype.finally ( onFinally ), https://tc39.es/ecma262/#sec-promise.prototype.finally JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto on_finally = vm.argument(0); @@ -82,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(), *global_object.promise_constructor())); + auto* constructor = TRY(species_constructor(vm, promise.as_object(), *realm.global_object().promise_constructor())); // 4. Assert: IsConstructor(C) is true. VERIFY(constructor); @@ -101,8 +103,8 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) // 6. Else, else { // a. Let thenFinallyClosure be a new Abstract Closure with parameters (value) that captures onFinally and C and performs the following steps when called: - auto then_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr { - auto& realm = *global_object.associated_realm(); + auto then_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm) -> ThrowCompletionOr { + auto& realm = *vm.current_realm(); auto& constructor = const_cast(*constructor_handle.cell()); auto& on_finally = const_cast(*on_finally_handle.cell()); auto value = vm.argument(0); @@ -114,7 +116,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) auto* promise = TRY(promise_resolve(vm, constructor, result)); // iii. Let returnValue be a new Abstract Closure with no parameters that captures value and performs the following steps when called: - auto return_value = [value_handle = make_handle(value)](auto&, auto&) -> ThrowCompletionOr { + auto return_value = [value_handle = make_handle(value)](auto&) -> ThrowCompletionOr { // 1. Return value. return value_handle.value(); }; @@ -130,8 +132,8 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) then_finally = NativeFunction::create(realm, move(then_finally_closure), 1, ""); // c. Let catchFinallyClosure be a new Abstract Closure with parameters (reason) that captures onFinally and C and performs the following steps when called: - auto catch_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> ThrowCompletionOr { - auto& realm = *global_object.associated_realm(); + auto catch_finally_closure = [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm) -> ThrowCompletionOr { + auto& realm = *vm.current_realm(); auto& constructor = const_cast(*constructor_handle.cell()); auto& on_finally = const_cast(*on_finally_handle.cell()); auto reason = vm.argument(0); @@ -143,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) auto* promise = TRY(promise_resolve(vm, constructor, result)); // iii. Let throwReason be a new Abstract Closure with no parameters that captures reason and performs the following steps when called: - auto throw_reason = [reason_handle = make_handle(reason)](auto&, auto&) -> ThrowCompletionOr { + auto throw_reason = [reason_handle = make_handle(reason)](auto&) -> ThrowCompletionOr { // 1. Return ThrowCompletion(reason). return throw_completion(reason_handle.value()); }; diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp index 0239f632665..f81d1a0118c 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp @@ -31,7 +31,7 @@ ThrowCompletionOr new_promise_capability(VM& vm, Value constr } promise_capability_functions; // 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures promiseCapability and performs the following steps when called: - auto executor_closure = [&promise_capability_functions](auto& vm, auto&) -> ThrowCompletionOr { + auto executor_closure = [&promise_capability_functions](auto& vm) -> ThrowCompletionOr { auto resolve = vm.argument(0); auto reject = vm.argument(1); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp index 546e7f3ed88..31ee4835e5a 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -32,7 +32,7 @@ void PromiseResolvingFunction::initialize(Realm& realm) ThrowCompletionOr PromiseResolvingFunction::call() { - return m_native_function(vm(), global_object(), m_promise, m_already_resolved); + return m_native_function(vm(), m_promise, m_already_resolved); } void PromiseResolvingFunction::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h index fede9b09b5a..f89a30054fe 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh + * Copyright (c) 2021-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -26,7 +26,7 @@ class PromiseResolvingFunction final : public NativeFunction { JS_OBJECT(PromiseResolvingFunction, NativeFunction); public: - using FunctionType = Function(VM&, GlobalObject&, Promise&, AlreadyResolved&)>; + using FunctionType = Function(VM&, Promise&, AlreadyResolved&)>; static PromiseResolvingFunction* create(Realm&, Promise&, AlreadyResolved&, FunctionType); diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp index 16d4651a3bb..772ab46ed7a 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable) auto* proxy = TRY(proxy_create(vm, vm.argument(0), vm.argument(1))); // 2. Let revokerClosure be a new Abstract Closure with no parameters that captures nothing and performs the following steps when called: - auto revoker_closure = [proxy_handle = make_handle(proxy)](auto&, auto&) -> ThrowCompletionOr { + auto revoker_closure = [proxy_handle = make_handle(proxy)](auto&) -> ThrowCompletionOr { // a. Let F be the active function object. // b. Let p be F.[[RevocableProxy]]. @@ -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, global_object.object_prototype()); + auto* result = Object::create(realm, realm.global_object().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/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index 128c0525345..cbe5cfc6296 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -215,7 +215,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::is_extensible) // 28.1.10 Reflect.ownKeys ( target ), https://tc39.es/ecma262/#sec-reflect.ownkeys JS_DEFINE_NATIVE_FUNCTION(ReflectObject::own_keys) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto target = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index cb5ff1e21d3..fba131b0fcb 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -412,12 +412,13 @@ size_t advance_string_index(Utf16View const& string, size_t index, bool unicode) #define __JS_ENUMERATE(flagName, flag_name, flag_char) \ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flag_name) \ { \ + auto& realm = *vm.current_realm(); \ /* 1. If Type(R) is not Object, throw a TypeError exception. */ \ auto* regexp_object = TRY(this_object(vm)); \ /* 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, global_object.regexp_prototype())) \ + if (same_value(regexp_object, realm.global_object().regexp_prototype())) \ return js_undefined(); \ /* b. Otherwise, throw a TypeError exception. */ \ return vm.throw_completion(ErrorType::NotAnObjectOfType, "RegExp"); \ @@ -487,7 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags) // With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp.prototype-%2540%2540match JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let rx be the this value. // 2. If Type(rx) is not Object, throw a TypeError exception. @@ -566,7 +567,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) // With changes from https://arai-a.github.io/ecma262-compare/?pr=2418&id=sec-regexp-prototype-matchall JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. @@ -576,7 +577,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, *global_object.regexp_constructor())); + auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.global_object().regexp_constructor())); // 5. Let flags be ? ToString(? Get(R, "flags")). auto flags_value = TRY(regexp_object->get(vm.names.flags)); @@ -842,6 +843,8 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_search) // 22.2.5.13 get RegExp.prototype.source, https://tc39.es/ecma262/#sec-get-regexp.prototype.source JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source) { + auto& realm = *vm.current_realm(); + // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. auto* regexp_object = TRY(this_object(vm)); @@ -849,7 +852,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, global_object.regexp_prototype())) + if (same_value(regexp_object, realm.global_object().regexp_prototype())) return js_string(vm, "(?:)"); // b. Otherwise, throw a TypeError exception. @@ -866,7 +869,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source) // 22.2.5.14 RegExp.prototype [ @@split ] ( string, limit ), https://tc39.es/ecma262/#sec-regexp.prototype-@@split JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let rx be the this value. // 2. If Type(rx) is not Object, throw a TypeError exception. @@ -876,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, *global_object.regexp_constructor())); + auto* constructor = TRY(species_constructor(vm, *regexp_object, *realm.global_object().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/SetIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp index 2ef658f0dc5..a64146300a5 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp @@ -32,7 +32,7 @@ void SetIteratorPrototype::initialize(Realm& realm) // 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* set_iterator = TRY(typed_this_value(vm)); if (set_iterator->done()) diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp index 160f9f62550..1502e98529b 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp @@ -70,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_) // 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* set = TRY(typed_this_object(vm)); @@ -99,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has) // 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* set = TRY(typed_this_object(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 8864b1167e3..0ed2d9a99a3 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -232,7 +232,7 @@ ThrowCompletionOr shadow_realm_import_value(VM& vm, String specifier_stri // NOTE: We don't support this concept yet. // 9. Let steps be the steps of an ExportGetter function as described below. - auto steps = [string = move(export_name_string)](auto& vm, auto&) -> ThrowCompletionOr { + auto steps = [string = move(export_name_string)](auto& vm) -> ThrowCompletionOr { // 1. Assert: exports is a module namespace exotic object. VERIFY(vm.argument(0).is_object()); auto& exports = vm.argument(0).as_object(); @@ -271,7 +271,7 @@ ThrowCompletionOr shadow_realm_import_value(VM& vm, String specifier_stri // 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). - auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm, auto&) -> ThrowCompletionOr { + auto* throw_type_error = NativeFunction::create(realm, {}, [](auto& vm) -> ThrowCompletionOr { return vm.template throw_completion(vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string()); }); diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index aef1fc67367..9e919f0f2bc 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -648,7 +648,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice) // 22.1.3.22 String.prototype.split ( separator, limit ), https://tc39.es/ecma262/#sec-string.prototype.split JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto object = TRY(require_object_coercible(vm, vm.this_value())); @@ -771,7 +771,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at) // 22.1.3.34 String.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-string.prototype-@@iterator JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto this_object = TRY(require_object_coercible(vm, vm.this_value())); auto string = TRY(this_object.to_string(vm)); @@ -1076,6 +1076,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::sup) // 19.1.1 String.prototype.localeCompare ( that [ , locales [ , options ] ] ), https://tc39.es/ecma402/#sup-String.prototype.localeCompare JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare) { + auto& realm = *vm.current_realm(); + // 1. Let O be ? RequireObjectCoercible(this value). auto object = TRY(require_object_coercible(vm, vm.this_value())); @@ -1086,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, *global_object.intl_collator_constructor(), vm.argument(1), vm.argument(2))); + auto* collator = TRY(construct(vm, *realm.global_object().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 049ba708f7c..eed3c8e16c7 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp @@ -54,7 +54,7 @@ ThrowCompletionOr SymbolConstructor::construct(FunctionObject&) JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::for_) { auto description = TRY(vm.argument(0).to_string(vm)); - return global_object.vm().get_global_symbol(description); + return vm.get_global_symbol(description); } // 20.4.2.6 Symbol.keyFor ( sym ), https://tc39.es/ecma262/#sec-symbol.keyfor diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 7b2394584e2..cf826752fff 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -501,7 +501,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::in_leap_year) // NOTE: This is the minimum fields implementation for engines without ECMA-402. JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto fields = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index 149f36791de..9c34d4b6d18 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -322,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::subtract) // 7.3.20 Temporal.Duration.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.round JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). @@ -446,7 +446,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round) // 7.3.21 Temporal.Duration.prototype.total ( totalOf ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.total JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 91fb1637401..fb70f618616 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -175,7 +175,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::since) // 8.3.11 Temporal.Instant.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.round JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::round) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let instant be the this value. // 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp index 81a87bea6fe..a08cbaf67cb 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDatePrototype.cpp @@ -319,14 +319,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_month_day) // 3.3.18 Temporal.PlainDate.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.getisofields JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let temporalDate be the this value. // 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]). auto* temporal_date = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, global_object.object_prototype()); + auto* fields = Object::create(realm, realm.global_object().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/PlainDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp index b7c4181442f..30a47383914 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTimePrototype.cpp @@ -517,7 +517,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::since) // 5.3.30 Temporal.PlainDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.round JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::round) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let dateTime be the this value. // 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]). @@ -728,14 +728,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_time) // 5.3.41 Temporal.PlainDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.getisofields JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let dateTime be the this value. // 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]). auto* date_time = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, global_object.object_prototype()); + auto* fields = Object::create(realm, realm.global_object().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/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp index 15ea5be926c..aa996c5f208 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp @@ -202,7 +202,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::value_of) // 10.3.12 Temporal.PlainMonthDay.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.toplaindate JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto item = vm.argument(0); @@ -253,14 +253,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date) // 10.3.13 Temporal.PlainMonthDay.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.getisofields JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let monthDay be the this value. // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]). auto* month_day = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, global_object.object_prototype()); + auto* fields = Object::create(realm, realm.global_object().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/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index 2859756bb6b..34e154dc126 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -265,7 +265,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::since) // 4.3.15 Temporal.PlainTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.round JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). @@ -418,14 +418,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_zoned_date_time) // 4.3.19 Temporal.PlainTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.getisofields JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let temporalTime be the this value. // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]). auto* temporal_time = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, global_object.object_prototype()); + auto* fields = Object::create(realm, realm.global_object().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/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp index fe5bf5526e6..abdeb27a7d4 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp @@ -369,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::value_of) // 9.3.21 Temporal.PlainYearMonth.prototype.toPlainDate ( item ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.toplaindate JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto item = vm.argument(0); @@ -420,14 +420,14 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date) // 9.3.22 Temporal.PlainYearMonth.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.getisofields JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let yearMonth be the this value. // 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]). auto* year_month = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, global_object.object_prototype()); + auto* fields = Object::create(realm, realm.global_object().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/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp index bebaf3a67cb..64ae66263f5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp @@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_instant_for) // 11.4.8 Temporal.TimeZone.prototype.getPossibleInstantsFor ( dateTime ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getpossibleinstantsfor JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let timeZone be the this value. // 2. Perform ? RequireInternalSlot(timeZone, [[InitializedTemporalTimezone]]). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp index f55e8871d20..f4d9113ce4f 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp @@ -951,7 +951,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::since) // 6.3.39 Temporal.ZonedDateTime.prototype.round ( roundTo ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.round JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let zonedDateTime be the this value. // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]). @@ -1284,14 +1284,14 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_month_day) // 6.3.52 Temporal.ZonedDateTime.prototype.getISOFields ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.getisofields JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let zonedDateTime be the this value. // 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]). auto* zoned_date_time = TRY(typed_this_object(vm)); // 3. Let fields be OrdinaryObjectCreate(%Object.prototype%). - auto* fields = Object::create(realm, global_object.object_prototype()); + auto* fields = Object::create(realm, realm.global_object().object_prototype()); // 4. Let timeZone be zonedDateTime.[[TimeZone]]. auto& time_zone = zoned_date_time->time_zone(); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 12be9dc9405..48389d04c1d 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -386,7 +386,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::copy_within) // 23.2.3.7 %TypedArray%.prototype.entries ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.entries JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::entries) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* typed_array = TRY(validate_typed_array_from_this(vm)); return ArrayIterator::create(realm, typed_array, Object::PropertyKind::KeyAndValue); @@ -688,7 +688,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::join) // 23.2.3.19 %TypedArray%.prototype.keys ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.keys JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::keys) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* typed_array = TRY(validate_typed_array_from_this(vm)); return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Key); @@ -1622,7 +1622,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::with) // 23.2.3.33 %TypedArray%.prototype.values ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.values JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::values) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* typed_array = TRY(typed_array_from_this(vm)); return ArrayIterator::create(realm, typed_array, Object::PropertyKind::Value); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 1464b5d0400..bcc591c9934 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -83,10 +83,10 @@ VM::VM(OwnPtr custom_data) promise->reject(Error::create(realm, ErrorType::DynamicImportNotAllowed.message())); promise->perform_then( - NativeFunction::create(realm, "", [](auto&, auto&) -> ThrowCompletionOr { + NativeFunction::create(realm, "", [](auto&) -> ThrowCompletionOr { VERIFY_NOT_REACHED(); }), - NativeFunction::create(realm, "", [reject = make_handle(promise_capability.reject)](auto& vm, auto&) -> ThrowCompletionOr { + NativeFunction::create(realm, "", [reject = make_handle(promise_capability.reject)](auto& vm) -> ThrowCompletionOr { auto error = vm.argument(0); // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »). @@ -1037,7 +1037,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu auto& realm = *current_realm(); // 1. Let fulfilledClosure be a new Abstract Closure with parameters (result) that captures referencingScriptOrModule, specifier, and promiseCapability and performs the following steps when called: - auto fulfilled_closure = [referencing_script_or_module, module_request = move(module_request), resolve_function = make_handle(promise_capability.resolve), reject_function = make_handle(promise_capability.reject)](VM& vm, GlobalObject&) -> ThrowCompletionOr { + auto fulfilled_closure = [referencing_script_or_module, module_request = move(module_request), resolve_function = make_handle(promise_capability.resolve), reject_function = make_handle(promise_capability.reject)](VM& vm) -> ThrowCompletionOr { auto result = vm.argument(0); // a. Assert: result is undefined. VERIFY(result.is_undefined()); @@ -1069,7 +1069,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu auto* on_fulfilled = NativeFunction::create(realm, move(fulfilled_closure), 0, ""); // 3. Let rejectedClosure be a new Abstract Closure with parameters (error) that captures promiseCapability and performs the following steps when called: - auto rejected_closure = [rejected_function = make_handle(promise_capability.reject)](VM& vm, GlobalObject&) -> ThrowCompletionOr { + auto rejected_closure = [rejected_function = make_handle(promise_capability.reject)](VM& vm) -> ThrowCompletionOr { auto error = vm.argument(0); // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »). MUST(call(vm, rejected_function.cell(), js_undefined(), error)); diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 9cb62ddb475..31d326dd577 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -130,7 +130,7 @@ extern bool g_collect_on_every_allocation; extern bool g_run_bytecode; extern String g_currently_running_test; struct FunctionWithLength { - JS::ThrowCompletionOr (*function)(JS::VM&, JS::GlobalObject&); + JS::ThrowCompletionOr (*function)(JS::VM&); size_t length { 0 }; }; extern HashMap s_exposed_global_functions; @@ -206,8 +206,8 @@ inline void TestRunnerGlobalObject::initialize_global_object() define_direct_property("global", this, JS::Attribute::Enumerable); for (auto& entry : s_exposed_global_functions) { define_native_function( - entry.key, [fn = entry.value.function](auto& vm, auto& global_object) { - return fn(vm, global_object); + entry.key, [fn = entry.value.function](auto& vm) { + return fn(vm); }, entry.value.length, JS::default_attributes); } diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp index 84a7f0d4529..b880ba1db5f 100644 --- a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp @@ -126,7 +126,7 @@ Optional cross_origin_get_own_property_helper(Variantis_function()) { value = JS::NativeFunction::create( - realm, [function = JS::make_handle(*value)](auto& vm, auto&) { + realm, [function = JS::make_handle(*value)](auto& vm) { return JS::call(vm, function.value(), JS::js_undefined()); }, 0, ""); @@ -143,7 +143,7 @@ Optional cross_origin_get_own_property_helper(Variantget)](auto& vm, auto&) { + realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto& vm) { return JS::call(vm, getter.cell(), object_ptr); }, 0, ""); @@ -155,7 +155,7 @@ Optional cross_origin_get_own_property_helper(Variantset)](auto& vm, auto&) { + realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto& vm) { return JS::call(vm, setter.cell(), object_ptr); }, 0, ""); diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 9c970a5f528..33415ebe24c 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -95,6 +95,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) // https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2 JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) { + auto& realm = *vm.current_realm(); + auto& global_object = realm.global_object(); auto& window = static_cast(global_object); // FIXME: 1. If this's relevant Document is null, then return. @@ -218,6 +220,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter) // https://html.spec.whatwg.org/multipage/history.html#dom-location-reload JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) { + auto& realm = *vm.current_realm(); + auto& global_object = realm.global_object(); auto& window = static_cast(global_object); window.impl().did_call_location_reload({}); return JS::js_undefined(); @@ -226,6 +230,8 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) // https://html.spec.whatwg.org/multipage/history.html#dom-location-replace JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace) { + auto& realm = *vm.current_realm(); + auto& global_object = realm.global_object(); auto& window = static_cast(global_object); auto url = TRY(vm.argument(0).to_string(vm)); // FIXME: This needs spec compliance work. diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index 8863983ef16..cef091c1e4b 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -626,7 +626,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll) // https://www.w3.org/TR/cssom-view/#dom-window-scrollby JS_DEFINE_NATIVE_FUNCTION(WindowObject::scroll_by) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* impl = TRY(impl_from(vm)); if (!impl->page()) diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp index 4d3352c18e7..ab622f323f3 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp @@ -524,7 +524,7 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl // document.body.remove(); // location.reload(); // The body element is no longer in the DOM and there is no variable holding onto it. However, the onunload handler is still called, meaning the callback keeps the body element alive. - auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm, auto&) mutable -> JS::ThrowCompletionOr { + auto callback_function = JS::NativeFunction::create(realm, "", [event_target = NonnullRefPtr(*this), name](JS::VM& vm) mutable -> JS::ThrowCompletionOr { // The event dispatcher should only call this with one argument. VERIFY(vm.argument_count() == 1); diff --git a/Userland/Libraries/LibWeb/HTML/Worker.cpp b/Userland/Libraries/LibWeb/HTML/Worker.cpp index 970b4719446..73a66c2a78b 100644 --- a/Userland/Libraries/LibWeb/HTML/Worker.cpp +++ b/Userland/Libraries/LibWeb/HTML/Worker.cpp @@ -122,7 +122,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti // FIXME: This should be done with IDL u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable; m_worker_scope->define_native_function( - "postMessage", [this](auto& vm, auto&) { + "postMessage", [this](auto& vm) { // This is the implementation of the function that the spawned worked calls // https://html.spec.whatwg.org/multipage/workers.html#dom-dedicatedworkerglobalscope-postmessage diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp index 56a2ef7f5cd..cce83551d81 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp @@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow) JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto* this_object = TRY(vm.this_value().to_object(vm)); if (!is(this_object)) diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index e25a1d996a5..0e10b1c78f9 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -154,7 +154,7 @@ JS::ThrowCompletionOr parse_module(JS::VM& vm, JS::Object* buffer_object JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // FIXME: This shouldn't block! auto buffer_or_error = vm.argument(0).to_object(vm); @@ -317,7 +317,7 @@ JS::ThrowCompletionOr WebAssemblyObject::instantiate_module(JS::VM& vm, JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // FIXME: This shouldn't block! auto buffer_or_error = vm.argument(0).to_object(vm); @@ -449,8 +449,8 @@ JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress add auto function = JS::NativeFunction::create( realm, name, - [address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr { - auto& realm = *global_object.associated_realm(); + [address, type = type.release_value()](JS::VM& vm) -> JS::ThrowCompletionOr { + auto& realm = *vm.current_realm(); Vector values; values.ensure_capacity(type.parameters().size()); diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index f59fc2e4b34..2639206c84d 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1311,10 +1311,11 @@ void ReplObject::initialize_global_object() define_native_accessor( "_", - [](JS::VM&, JS::GlobalObject&) { + [](JS::VM&) { return g_last_value.value(); }, - [](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr { + [](JS::VM& vm) -> JS::ThrowCompletionOr { + auto& global_object = vm.get_global_object(); VERIFY(is(global_object)); outln("Disable writing last value to '_'");