diff options
Diffstat (limited to 'Userland/Libraries')
46 files changed, 173 insertions, 207 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 48e96c6fa5..6eabb15219 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -526,14 +526,14 @@ Completion YieldExpression::execute(Interpreter&) const Completion AwaitExpression::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); + auto& vm = interpreter.vm(); // 1. Let exprRef be the result of evaluating UnaryExpression. // 2. Let value be ? GetValue(exprRef). auto value = TRY(m_argument->execute(interpreter)).release_value(); // 3. Return ? Await(value). - return await(global_object, value); + return await(vm, value); } // 14.10.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-return-statement-runtime-semantics-evaluation @@ -883,7 +883,6 @@ struct ForInOfHeadState { { VERIFY(!next_value.is_empty()); - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); Optional<Reference> lhs_reference; @@ -935,7 +934,7 @@ struct ForInOfHeadState { // j. Else, if (lhs_kind == Assignment) { VERIFY(pattern_lhs); - return interpreter.vm().destructuring_assignment_evaluation(*pattern_lhs, next_value, global_object); + return interpreter.vm().destructuring_assignment_evaluation(*pattern_lhs, next_value); } VERIFY(expression_lhs && is<VariableDeclaration>(*expression_lhs)); auto& for_declaration = static_cast<VariableDeclaration const&>(*expression_lhs); @@ -944,7 +943,7 @@ struct ForInOfHeadState { // At this point iteration_environment is undefined if lhs_kind == VarBinding which means this does both // branch j.ii and j.iii because ForBindingInitialization is just a forwarding call to BindingInitialization. - return interpreter.vm().binding_initialization(binding_pattern, next_value, iteration_environment, global_object); + return interpreter.vm().binding_initialization(binding_pattern, next_value, iteration_environment); } }; @@ -1165,7 +1164,6 @@ Completion ForAwaitOfStatement::execute(Interpreter& interpreter) const Completion ForAwaitOfStatement::loop_evaluation(Interpreter& interpreter, Vector<FlyString> const& label_set) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); // 14.7.5.6 ForIn/OfHeadEvaluation ( uninitializedBoundNames, expr, iterationKind ), https://tc39.es/ecma262/#sec-runtime-semantics-forinofheadevaluation @@ -1197,7 +1195,7 @@ Completion ForAwaitOfStatement::loop_evaluation(Interpreter& interpreter, Vector auto next_result = TRY(call(vm, iterator.next_method, iterator.iterator)); // b. If iteratorKind is async, set nextResult to ? Await(nextResult). - next_result = TRY(await(global_object, next_result)); + next_result = TRY(await(vm, next_result)); // c. If Type(nextResult) is not Object, throw a TypeError exception. if (!next_result.is_object()) @@ -2597,7 +2595,6 @@ void ThisExpression::dump(int indent) const Completion AssignmentExpression::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); if (m_op == AssignmentOp::Assignment) { @@ -2615,7 +2612,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter) const if (lhs->is_identifier()) { // i. Let rval be ? NamedEvaluation of AssignmentExpression with argument lref.[[ReferencedName]]. auto& identifier_name = static_cast<Identifier const&>(*lhs).string(); - rhs_result = TRY(interpreter.vm().named_evaluation_if_anonymous_function(m_rhs, identifier_name)); + rhs_result = TRY(vm.named_evaluation_if_anonymous_function(m_rhs, identifier_name)); } // d. Else, else { @@ -2637,7 +2634,7 @@ Completion AssignmentExpression::execute(Interpreter& interpreter) const auto rhs_result = TRY(m_rhs->execute(interpreter)).release_value(); // 5. Perform ? DestructuringAssignmentEvaluation of assignmentPattern with argument rval. - TRY(interpreter.vm().destructuring_assignment_evaluation(pattern, rhs_result, global_object)); + TRY(vm.destructuring_assignment_evaluation(pattern, rhs_result)); // 6. Return rval. return rhs_result; @@ -2910,7 +2907,6 @@ void UpdateExpression::dump(int indent) const Completion VariableDeclaration::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); for (auto& declarator : m_declarations) { @@ -2931,7 +2927,7 @@ Completion VariableDeclaration::execute(Interpreter& interpreter) const Environment* environment = m_declaration_kind == DeclarationKind::Var ? nullptr : interpreter.lexical_environment(); - return vm.binding_initialization(pattern, initializer_result, environment, global_object); + return vm.binding_initialization(pattern, initializer_result, environment); })); } else if (m_declaration_kind != DeclarationKind::Var) { VERIFY(declarator.target().has<NonnullRefPtr<Identifier>>()); @@ -3781,7 +3777,6 @@ void ThrowStatement::dump(int indent) const Completion TryStatement::execute(Interpreter& interpreter) const { InterpreterNodeScope node_scope { interpreter, *this }; - auto& global_object = interpreter.global_object(); auto& vm = interpreter.vm(); // 14.15.2 Runtime Semantics: CatchClauseEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-catchclauseevaluation @@ -3815,7 +3810,7 @@ Completion TryStatement::execute(Interpreter& interpreter) const return catch_environment->initialize_binding(vm, parameter, thrown_value); }, [&](NonnullRefPtr<BindingPattern> const& pattern) { - return vm.binding_initialization(pattern, thrown_value, catch_environment, global_object); + return vm.binding_initialization(pattern, thrown_value, catch_environment); }); // 6. If status is an abrupt completion, then diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp index f881241b9f..b3b7f022af 100644 --- a/Userland/Libraries/LibJS/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Interpreter.cpp @@ -45,9 +45,6 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record) // 1. Let globalEnv be scriptRecord.[[Realm]].[[GlobalEnv]]. auto& global_environment = script_record.realm().global_environment(); - // NOTE: This isn't in the spec but we require it. - auto& global_object = script_record.realm().global_object(); - // 2. Let scriptContext be a new ECMAScript code execution context. ExecutionContext script_context(vm.heap()); @@ -74,7 +71,7 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record) // FIXME: 9. Suspend the currently running execution context. // 10. Push scriptContext onto the execution context stack; scriptContext is now the running execution context. - TRY(vm.push_execution_context(script_context, global_object)); + TRY(vm.push_execution_context(script_context, {})); // 11. Let script be scriptRecord.[[ECMAScriptCode]]. auto& script = script_record.parse_node(); diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h index 0fc673cee8..1dea3c4efa 100644 --- a/Userland/Libraries/LibJS/Parser.h +++ b/Userland/Libraries/LibJS/Parser.h @@ -219,7 +219,7 @@ public: }; // Needs to mess with m_state, and we're not going to expose a non-const getter for that :^) - friend ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic_function(GlobalObject&, FunctionObject&, FunctionObject*, FunctionKind, MarkedVector<Value> const&); + friend ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic_function(VM&, FunctionObject&, FunctionObject*, FunctionKind, MarkedVector<Value> const&); private: friend class ScopePusher; diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index da468842ab..f729ca1f2a 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -663,7 +663,7 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller, eval_context.is_strict_mode = strict_eval; // 27. Push evalContext onto the execution context stack; evalContext is now the running execution context. - TRY(vm.push_execution_context(eval_context, eval_realm.global_object())); + TRY(vm.push_execution_context(eval_context, {})); // NOTE: We use a ScopeGuard to automatically pop the execution context when any of the `TRY`s below return a throw completion. ScopeGuard pop_guard = [&] { diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp index 0b81ff5c40..e4778ffaa9 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp @@ -38,7 +38,6 @@ ThrowCompletionOr<Value> AsyncFunctionConstructor::call() ThrowCompletionOr<Object*> AsyncFunctionConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); // 1. Let C be the active function object. auto* constructor = vm.active_function_object(); @@ -47,7 +46,7 @@ ThrowCompletionOr<Object*> AsyncFunctionConstructor::construct(FunctionObject& n auto& args = vm.running_execution_context().arguments; // 3. Return CreateDynamicFunction(C, NewTarget, async, args). - return TRY(FunctionConstructor::create_dynamic_function(global_object, *constructor, &new_target, FunctionKind::Async, args)); + return TRY(FunctionConstructor::create_dynamic_function(vm, *constructor, &new_target, FunctionKind::Async, args)); } } diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp index 2684294b0b..97dc69c3eb 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp @@ -15,28 +15,28 @@ namespace JS { ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(Realm& realm, GeneratorObject* generator_object) { auto wrapper = realm.heap().allocate<AsyncFunctionDriverWrapper>(realm, realm, generator_object); - return wrapper->react_to_async_task_completion(realm.vm(), realm.global_object(), js_undefined(), true); + return wrapper->react_to_async_task_completion(realm.vm(), js_undefined(), true); } 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& global_object) { - return react_to_async_task_completion(vm, global_object, vm.argument(0), true); + , m_on_fulfillment(NativeFunction::create(realm, "async.on_fulfillment"sv, [this](VM& vm, GlobalObject&) { + 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& global_object) { - return react_to_async_task_completion(vm, global_object, vm.argument(0), false); + , m_on_rejection(NativeFunction::create(realm, "async.on_rejection"sv, [this](VM& vm, GlobalObject&) { + return react_to_async_task_completion(vm, vm.argument(0), false); })) { } -ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_completion(VM& vm, GlobalObject& global_object, Value value, bool is_successful) +ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::react_to_async_task_completion(VM& vm, Value value, bool is_successful) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto generator_result = is_successful - ? m_generator_object->next_impl(vm, global_object, value, {}) - : m_generator_object->next_impl(vm, global_object, {}, value); + ? m_generator_object->next_impl(vm, value, {}) + : m_generator_object->next_impl(vm, {}, value); if (generator_result.is_throw_completion()) { VERIFY(generator_result.throw_completion().type() == Completion::Type::Throw); diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h index 4942ed2e31..40f92034a5 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h @@ -24,7 +24,7 @@ public: virtual ~AsyncFunctionDriverWrapper() override = default; void visit_edges(Cell::Visitor&) override; - ThrowCompletionOr<Value> react_to_async_task_completion(VM&, GlobalObject&, Value, bool is_successful); + ThrowCompletionOr<Value> react_to_async_task_completion(VM&, Value, bool is_successful); private: GeneratorObject* m_generator_object { nullptr }; diff --git a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp index e3e49e2dd6..bb83045693 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp @@ -39,7 +39,6 @@ ThrowCompletionOr<Value> AsyncGeneratorFunctionConstructor::call() ThrowCompletionOr<Object*> AsyncGeneratorFunctionConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); // 1. Let C be the active function object. auto* constructor = vm.active_function_object(); @@ -48,7 +47,7 @@ ThrowCompletionOr<Object*> AsyncGeneratorFunctionConstructor::construct(Function auto& args = vm.running_execution_context().arguments; // 3. Return ? CreateDynamicFunction(C, NewTarget, asyncGenerator, args). - return TRY(FunctionConstructor::create_dynamic_function(global_object, *constructor, &new_target, FunctionKind::AsyncGenerator, args)); + return TRY(FunctionConstructor::create_dynamic_function(vm, *constructor, &new_target, FunctionKind::AsyncGenerator, args)); } } diff --git a/Userland/Libraries/LibJS/Runtime/BigInt.cpp b/Userland/Libraries/LibJS/Runtime/BigInt.cpp index fdb830de96..5d351c80fa 100644 --- a/Userland/Libraries/LibJS/Runtime/BigInt.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigInt.cpp @@ -28,10 +28,9 @@ BigInt* js_bigint(VM& vm, Crypto::SignedBigInteger big_integer) } // 21.2.1.1.1 NumberToBigInt ( number ), https://tc39.es/ecma262/#sec-numbertobigint -ThrowCompletionOr<BigInt*> number_to_bigint(GlobalObject& global_object, Value number) +ThrowCompletionOr<BigInt*> number_to_bigint(VM& vm, Value number) { VERIFY(number.is_number()); - auto& vm = global_object.vm(); // 1. If IsIntegralNumber(number) is false, throw a RangeError exception. if (!number.is_integral_number()) diff --git a/Userland/Libraries/LibJS/Runtime/BigInt.h b/Userland/Libraries/LibJS/Runtime/BigInt.h index 9290c554f2..41cf1f0b00 100644 --- a/Userland/Libraries/LibJS/Runtime/BigInt.h +++ b/Userland/Libraries/LibJS/Runtime/BigInt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -28,6 +28,6 @@ private: BigInt* js_bigint(Heap&, Crypto::SignedBigInteger); BigInt* js_bigint(VM&, Crypto::SignedBigInteger); -ThrowCompletionOr<BigInt*> number_to_bigint(GlobalObject&, Value); +ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value); } diff --git a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp index 1f581fc4eb..9359a92afd 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp @@ -41,7 +41,6 @@ void BigIntConstructor::initialize(Realm& realm) ThrowCompletionOr<Value> BigIntConstructor::call() { auto& vm = this->vm(); - auto& global_object = this->global_object(); auto value = vm.argument(0); @@ -50,7 +49,7 @@ ThrowCompletionOr<Value> BigIntConstructor::call() // 3. If Type(prim) is Number, return ? NumberToBigInt(prim). if (primitive.is_number()) - return TRY(number_to_bigint(global_object, primitive)); + return TRY(number_to_bigint(vm, primitive)); // 4. Otherwise, return ? ToBigInt(prim). return TRY(primitive.to_bigint(vm)); diff --git a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp index baf880dde1..d27c958ba8 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -36,20 +36,19 @@ void BigIntPrototype::initialize(Realm& realm) } // thisBigIntValue ( value ), https://tc39.es/ecma262/#thisbigintvalue -static ThrowCompletionOr<BigInt*> this_bigint_value(GlobalObject& global_object, Value value) +static ThrowCompletionOr<BigInt*> this_bigint_value(VM& vm, Value value) { if (value.is_bigint()) return &value.as_bigint(); if (value.is_object() && is<BigIntObject>(value.as_object())) return &static_cast<BigIntObject&>(value.as_object()).bigint(); - auto& vm = global_object.vm(); return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "BigInt"); } // 21.2.3.3 BigInt.prototype.toString ( [ radix ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string) { - auto* bigint = TRY(this_bigint_value(global_object, vm.this_value())); + auto* bigint = TRY(this_bigint_value(vm, vm.this_value())); double radix = 10; if (!vm.argument(0).is_undefined()) { radix = TRY(vm.argument(0).to_integer_or_infinity(vm)); @@ -67,7 +66,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) auto options = vm.argument(1); // 1. Let x be ? thisBigIntValue(this value). - auto* bigint = TRY(this_bigint_value(global_object, vm.this_value())); + auto* bigint = TRY(this_bigint_value(vm, vm.this_value())); // 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »). auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), locales, options))); @@ -80,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string) // 21.2.3.4 BigInt.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-bigint.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::value_of) { - return TRY(this_bigint_value(global_object, vm.this_value())); + return TRY(this_bigint_value(vm, vm.this_value())); } } diff --git a/Userland/Libraries/LibJS/Runtime/Completion.cpp b/Userland/Libraries/LibJS/Runtime/Completion.cpp index dd6b19f848..0414f6c0a8 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.cpp +++ b/Userland/Libraries/LibJS/Runtime/Completion.cpp @@ -29,16 +29,15 @@ Completion::Completion(ThrowCompletionOr<Value> const& throw_completion_or_value } // 6.2.3.1 Await, https://tc39.es/ecma262/#await -ThrowCompletionOr<Value> await(GlobalObject& global_object, Value value) +ThrowCompletionOr<Value> await(VM& vm, Value value) { - auto& vm = global_object.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let asyncContext be the running execution context. // NOTE: This is not needed, as we don't suspend anything. // 2. Let promise be ? PromiseResolve(%Promise%, value). - auto* promise_object = TRY(promise_resolve(vm, *global_object.promise_constructor(), value)); + auto* promise_object = TRY(promise_resolve(vm, *realm.global_object().promise_constructor(), value)); Optional<bool> success; Value result; diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index fb3b377b5b..abc90d64ec 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -293,7 +293,7 @@ public: using ThrowCompletionOr<Empty>::ThrowCompletionOr; }; -ThrowCompletionOr<Value> await(GlobalObject&, Value); +ThrowCompletionOr<Value> await(VM&, Value); // 6.2.3.2 NormalCompletion ( value ), https://tc39.es/ecma262/#sec-normalcompletion inline Completion normal_completion(Optional<Value> value) diff --git a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp index 8b64a5bdf8..9346e50ffb 100644 --- a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp @@ -52,9 +52,8 @@ void DataViewPrototype::initialize(Realm& realm) // 25.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ), https://tc39.es/ecma262/#sec-getviewvalue template<typename T> -static ThrowCompletionOr<Value> get_view_value(GlobalObject& global_object, Value request_index, Value is_little_endian) +static ThrowCompletionOr<Value> get_view_value(VM& vm, Value request_index, Value is_little_endian) { - auto& vm = global_object.vm(); auto* view = TRY(DataViewPrototype::typed_this_value(vm)); auto get_index = TRY(request_index.to_index(vm)); auto little_endian = is_little_endian.to_boolean(); @@ -82,9 +81,8 @@ static ThrowCompletionOr<Value> get_view_value(GlobalObject& global_object, Valu // 25.3.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value ), https://tc39.es/ecma262/#sec-setviewvalue template<typename T> -static ThrowCompletionOr<Value> set_view_value(GlobalObject& global_object, Value request_index, Value is_little_endian, Value value) +static ThrowCompletionOr<Value> set_view_value(VM& vm, Value request_index, Value is_little_endian, Value value) { - auto& vm = global_object.vm(); auto* view = TRY(DataViewPrototype::typed_this_value(vm)); auto get_index = TRY(request_index.to_index(vm)); @@ -122,112 +120,112 @@ static ThrowCompletionOr<Value> set_view_value(GlobalObject& global_object, Valu // 25.3.4.5 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getbigint64 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_big_int_64) { - return get_view_value<i64>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<i64>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.6 DataView.prototype.getBigUint64 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getbiguint64 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_big_uint_64) { - return get_view_value<u64>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<u64>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.7 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getfloat32 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_float_32) { - return get_view_value<float>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<float>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.8 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getfloat64 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_float_64) { - return get_view_value<double>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<double>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.9 DataView.prototype.getInt8 ( byteOffset ), https://tc39.es/ecma262/#sec-dataview.prototype.getint8 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_int_8) { - return get_view_value<i8>(global_object, vm.argument(0), Value(true)); + return get_view_value<i8>(vm, vm.argument(0), Value(true)); } // 25.3.4.10 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getint16 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_int_16) { - return get_view_value<i16>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<i16>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.11 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getint32 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_int_32) { - return get_view_value<i32>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<i32>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.12 DataView.prototype.getUint8 ( byteOffset ), https://tc39.es/ecma262/#sec-dataview.prototype.getuint8 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_uint_8) { - return get_view_value<u8>(global_object, vm.argument(0), Value(true)); + return get_view_value<u8>(vm, vm.argument(0), Value(true)); } // 25.3.4.13 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getuint16 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_uint_16) { - return get_view_value<u16>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<u16>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.14 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.getuint32 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::get_uint_32) { - return get_view_value<u32>(global_object, vm.argument(0), vm.argument(1)); + return get_view_value<u32>(vm, vm.argument(0), vm.argument(1)); } // 25.3.4.15 DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] ), https://tc39.es/ecma262/#sec-dataview.prototype.setbigint64 JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_big_int_64) { - return set_view_value<i64>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<i64>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_big_uint_64) { - return set_view_value<u64>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<u64>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_float_32) { - return set_view_value<float>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<float>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_float_64) { - return set_view_value<double>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<double>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_int_8) { - return set_view_value<i8>(global_object, vm.argument(0), Value(true), vm.argument(1)); + return set_view_value<i8>(vm, vm.argument(0), Value(true), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_int_16) { - return set_view_value<i16>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<i16>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_int_32) { - return set_view_value<i32>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<i32>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_uint_8) { - return set_view_value<u8>(global_object, vm.argument(0), Value(true), vm.argument(1)); + return set_view_value<u8>(vm, vm.argument(0), Value(true), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_uint_16) { - return set_view_value<u16>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<u16>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_uint_32) { - return set_view_value<u32>(global_object, vm.argument(0), vm.argument(2), vm.argument(1)); + return set_view_value<u32>(vm, vm.argument(0), vm.argument(2), vm.argument(1)); } // 25.3.4.1 get DataView.prototype.buffer, https://tc39.es/ecma262/#sec-get-dataview.prototype.buffer diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index e7271a8e3d..93207b3aa3 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -16,7 +16,7 @@ class Date final : public Object { public: static Date* create(Realm&, double date_value); - static Date* now(GlobalObject&); + static Date* now(VM&); Date(double date_value, Object& prototype); virtual ~Date() override = default; diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index d907e740e8..7003833b87 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -1177,7 +1177,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant) auto t = TRY(this_time_value(vm, vm.this_value())); // 2. Let ns be ? NumberToBigInt(t) × ℤ(10^6). - auto* ns = TRY(number_to_bigint(global_object, Value(t))); + auto* ns = TRY(number_to_bigint(vm, Value(t))); ns = js_bigint(vm, ns->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 })); // 3. Return ! CreateTemporalInstant(ns). diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 0baca4fc9c..ca099d783c 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -467,7 +467,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia return reference.initialize_referenced_binding(vm, argument_value); } else if (IsSame<NonnullRefPtr<BindingPattern> const&, decltype(param)>) { // Here the difference from hasDuplicates is important - return vm.binding_initialization(param, argument_value, used_environment, global_object); + return vm.binding_initialization(param, argument_value, used_environment); } })); } @@ -627,7 +627,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::prepare_for_ordinary_call(Exec // FIXME: We don't have this concept yet. // 12. Push calleeContext onto the execution context stack; calleeContext is now the running execution context. - TRY(vm.push_execution_context(callee_context, global_object())); + TRY(vm.push_execution_context(callee_context, {})); // 13. NOTE: Any exception objects produced after this point are associated with calleeRealm. // 14. Return calleeContext. @@ -719,7 +719,6 @@ void ECMAScriptFunctionObject::async_function_start(PromiseCapability const& pro void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, PromiseCapability const& promise_capability, ExecutionContext& async_context) { auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); // 1. Assert: promiseCapability is a PromiseCapability Record. @@ -760,7 +759,7 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi }); // 4. Push asyncContext onto the execution context stack; asyncContext is now the running execution context. - auto push_result = vm.push_execution_context(async_context, global_object); + auto push_result = vm.push_execution_context(async_context, {}); if (push_result.is_error()) return; diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 0af377610d..8fde5b20f8 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -36,12 +36,10 @@ void FunctionConstructor::initialize(Realm& realm) } // 20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, args ), https://tc39.es/ecma262/#sec-createdynamicfunction -ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic_function(GlobalObject& global_object, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args) +ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic_function(VM& vm, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args) { - auto& vm = global_object.vm(); - // 1. Let currentRealm be the current Realm Record. - auto& current_realm = *vm.running_execution_context().realm; + auto& current_realm = *vm.current_realm(); // 2. Perform ? HostEnsureCanCompileStrings(currentRealm). TRY(vm.host_ensure_can_compile_strings(current_realm)); @@ -234,7 +232,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic // 30. If kind is generator, then if (kind == FunctionKind::Generator) { // a. Let prototype be OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%). - prototype = Object::create(realm, global_object.generator_function_prototype_prototype()); + prototype = Object::create(realm, realm.global_object().generator_function_prototype_prototype()); // b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }). function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); @@ -242,7 +240,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic // 31. Else if kind is asyncGenerator, then else if (kind == FunctionKind::AsyncGenerator) { // a. Let prototype be OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%). - prototype = Object::create(realm, global_object.async_generator_function_prototype_prototype()); + prototype = Object::create(realm, realm.global_object().async_generator_function_prototype_prototype()); // b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }). function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); @@ -250,7 +248,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic // 32. Else if kind is normal, perform MakeConstructor(F). else if (kind == FunctionKind::Normal) { // FIXME: Implement MakeConstructor - prototype = Object::create(realm, global_object.object_prototype()); + prototype = Object::create(realm, realm.global_object().object_prototype()); prototype->define_direct_property(vm.names.constructor, function, Attribute::Writable | Attribute::Configurable); function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); } @@ -271,7 +269,6 @@ ThrowCompletionOr<Value> FunctionConstructor::call() ThrowCompletionOr<Object*> FunctionConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); // 1. Let C be the active function object. auto* constructor = vm.active_function_object(); @@ -280,7 +277,7 @@ ThrowCompletionOr<Object*> FunctionConstructor::construct(FunctionObject& new_ta auto& args = vm.running_execution_context().arguments; // 3. Return ? CreateDynamicFunction(C, NewTarget, normal, args). - return TRY(create_dynamic_function(global_object, *constructor, &new_target, FunctionKind::Normal, args)); + return TRY(create_dynamic_function(vm, *constructor, &new_target, FunctionKind::Normal, args)); } } diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.h b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.h index 7e8ea448c1..54907c8bcb 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.h +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,7 +15,7 @@ class FunctionConstructor final : public NativeFunction { JS_OBJECT(FunctionConstructor, NativeFunction); public: - static ThrowCompletionOr<ECMAScriptFunctionObject*> create_dynamic_function(GlobalObject& global_object, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args); + static ThrowCompletionOr<ECMAScriptFunctionObject*> create_dynamic_function(VM&, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args); explicit FunctionConstructor(Realm&); virtual void initialize(Realm&) override; diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp index d8bf1dca88..5c73f3e394 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp @@ -37,7 +37,6 @@ ThrowCompletionOr<Value> GeneratorFunctionConstructor::call() ThrowCompletionOr<Object*> GeneratorFunctionConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); // 1. Let C be the active function object. auto* constructor = vm.active_function_object(); @@ -46,7 +45,7 @@ ThrowCompletionOr<Object*> GeneratorFunctionConstructor::construct(FunctionObjec auto& args = vm.running_execution_context().arguments; // 3. Return ? CreateDynamicFunction(C, NewTarget, generator, args). - return TRY(FunctionConstructor::create_dynamic_function(global_object, *constructor, &new_target, FunctionKind::Generator, args)); + return TRY(FunctionConstructor::create_dynamic_function(vm, *constructor, &new_target, FunctionKind::Generator, args)); } } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index 6b8530bd83..80712ab0c7 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -51,9 +51,9 @@ void GeneratorObject::visit_edges(Cell::Visitor& visitor) visitor.visit(m_previous_value); } -ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global_object, Optional<Value> next_argument, Optional<Value> value_to_throw) +ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, Optional<Value> next_argument, Optional<Value> value_to_throw) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); auto bytecode_interpreter = Bytecode::Interpreter::current(); VERIFY(bytecode_interpreter); @@ -73,7 +73,7 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global auto previous_generated_value = TRY(generated_value(m_previous_value)); - auto result = Object::create(realm, global_object.object_prototype()); + auto result = Object::create(realm, realm.global_object().object_prototype()); result->define_direct_property("value", previous_generated_value, default_attributes); if (m_done) { @@ -95,7 +95,7 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global VERIFY(!m_generating_function->bytecode_executable()->basic_blocks.find_if([next_block](auto& block) { return block == next_block; }).is_end()); // Temporarily switch to the captured execution context - TRY(vm.push_execution_context(m_execution_context, global_object)); + TRY(vm.push_execution_context(m_execution_context, {})); // Pretend that 'yield' returned the passed value, or threw if (value_to_throw.has_value()) { diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h index 963367d274..9432f87805 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h @@ -22,7 +22,7 @@ public: virtual ~GeneratorObject() override = default; void visit_edges(Cell::Visitor&) override; - ThrowCompletionOr<Value> next_impl(VM&, GlobalObject&, Optional<Value> next_argument, Optional<Value> value_to_throw); + ThrowCompletionOr<Value> next_impl(VM&, Optional<Value> next_argument, Optional<Value> value_to_throw); void set_done() { m_done = true; } private: diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp index 3aaecb2775..e398123e64 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp @@ -31,7 +31,7 @@ void GeneratorPrototype::initialize(Realm& realm) JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::next) { auto* generator_object = TRY(typed_this_object(vm)); - return generator_object->next_impl(vm, global_object, vm.argument(0), {}); + return generator_object->next_impl(vm, vm.argument(0), {}); } // 27.5.1.3 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.return @@ -39,14 +39,14 @@ JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::return_) { auto* generator_object = TRY(typed_this_object(vm)); generator_object->set_done(); - return generator_object->next_impl(vm, global_object, {}, {}); + return generator_object->next_impl(vm, {}, {}); } // 27.5.1.4 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.throw JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::throw_) { auto* generator_object = TRY(typed_this_object(vm)); - return generator_object->next_impl(vm, global_object, {}, vm.argument(0)); + return generator_object->next_impl(vm, {}, vm.argument(0)); } } diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 928c5cc6dc..97d6afafc2 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -498,9 +498,8 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval) } // 19.2.6.1.1 Encode ( string, unescapedSet ), https://tc39.es/ecma262/#sec-encode -static ThrowCompletionOr<String> encode(GlobalObject& global_object, String const& string, StringView unescaped_set) +static ThrowCompletionOr<String> encode(VM& vm, String const& string, StringView unescaped_set) { - auto& vm = global_object.vm(); auto utf16_string = Utf16String(string); // 1. Let strLen be the length of string. @@ -554,7 +553,7 @@ static ThrowCompletionOr<String> encode(GlobalObject& global_object, String cons } // 19.2.6.1.2 Decode ( string, reservedSet ), https://tc39.es/ecma262/#sec-decode -static ThrowCompletionOr<String> decode(GlobalObject& global_object, String const& string, StringView reserved_set) +static ThrowCompletionOr<String> decode(VM& vm, String const& string, StringView reserved_set) { StringBuilder decoded_builder; auto code_point_start_offset = 0u; @@ -563,22 +562,22 @@ static ThrowCompletionOr<String> decode(GlobalObject& global_object, String cons auto code_unit = string[k]; if (code_unit != '%') { if (expected_continuation_bytes > 0) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); decoded_builder.append(code_unit); continue; } if (k + 2 >= string.length()) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); auto first_digit = decode_hex_digit(string[k + 1]); if (first_digit >= 16) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); auto second_digit = decode_hex_digit(string[k + 2]); if (second_digit >= 16) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); u8 decoded_code_unit = (first_digit << 4) | second_digit; k += 2; @@ -586,7 +585,7 @@ static ThrowCompletionOr<String> decode(GlobalObject& global_object, String cons decoded_builder.append(decoded_code_unit); expected_continuation_bytes--; if (expected_continuation_bytes == 0 && !Utf8View(decoded_builder.string_view().substring_view(code_point_start_offset)).validate()) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); continue; } @@ -600,14 +599,14 @@ static ThrowCompletionOr<String> decode(GlobalObject& global_object, String cons auto leading_ones = count_leading_zeroes_safe(static_cast<u8>(~decoded_code_unit)); if (leading_ones == 1 || leading_ones > 4) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); code_point_start_offset = decoded_builder.length(); decoded_builder.append(decoded_code_unit); expected_continuation_bytes = leading_ones - 1; } if (expected_continuation_bytes > 0) - return global_object.vm().throw_completion<URIError>(ErrorType::URIMalformed); + return vm.throw_completion<URIError>(ErrorType::URIMalformed); return decoded_builder.build(); } @@ -615,7 +614,7 @@ static ThrowCompletionOr<String> decode(GlobalObject& global_object, String cons JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri) { auto uri_string = TRY(vm.argument(0).to_string(vm)); - auto encoded = TRY(encode(global_object, uri_string, ";/?:@&=+$,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()#"sv)); + auto encoded = TRY(encode(vm, uri_string, ";/?:@&=+$,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()#"sv)); return js_string(vm, move(encoded)); } @@ -623,7 +622,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri) JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri) { auto uri_string = TRY(vm.argument(0).to_string(vm)); - auto decoded = TRY(decode(global_object, uri_string, ";/?:@&=+$,#"sv)); + auto decoded = TRY(decode(vm, uri_string, ";/?:@&=+$,#"sv)); return js_string(vm, move(decoded)); } @@ -631,7 +630,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri) JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component) { auto uri_string = TRY(vm.argument(0).to_string(vm)); - auto encoded = TRY(encode(global_object, uri_string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"sv)); + auto encoded = TRY(encode(vm, uri_string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"sv)); return js_string(vm, move(encoded)); } @@ -639,7 +638,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component) JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component) { auto uri_string = TRY(vm.argument(0).to_string(vm)); - auto decoded = TRY(decode(global_object, uri_string, ""sv)); + auto decoded = TRY(decode(vm, uri_string, ""sv)); return js_string(vm, move(decoded)); } diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 9061363211..9de508fb0a 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -125,9 +125,6 @@ ThrowCompletionOr<Object*> iterator_step(VM& vm, Iterator const& iterator_record // NOTE: These only differ in that async awaits the inner value after the call. static Completion iterator_close_impl(VM& vm, Iterator const& iterator_record, Completion completion, IteratorHint iterator_hint) { - auto& realm = *vm.current_realm(); - auto& global_object = realm.global_object(); - // 1. Assert: Type(iteratorRecord.[[Iterator]]) is Object. // 2. Let iterator be iteratorRecord.[[Iterator]]. @@ -154,7 +151,7 @@ static Completion iterator_close_impl(VM& vm, Iterator const& iterator_record, C // Note: If this is AsyncIteratorClose perform one extra step. if (iterator_hint == IteratorHint::Async && !inner_result.is_error()) { // d. If innerResult.[[Type]] is normal, set innerResult to Completion(Await(innerResult.[[Value]])). - inner_result = await(global_object, inner_result.value()); + inner_result = await(vm, inner_result.value()); } } diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index 64ec73c833..b6334f590f 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -96,7 +96,6 @@ NativeFunction::NativeFunction(FlyString name, Object& prototype) ThrowCompletionOr<Value> NativeFunction::internal_call(Value this_argument, MarkedVector<Value> arguments_list) { auto& vm = this->vm(); - auto& global_object = this->global_object(); // 1. Let callerContext be the running execution context. auto& caller_context = vm.running_execution_context(); @@ -148,7 +147,7 @@ ThrowCompletionOr<Value> NativeFunction::internal_call(Value this_argument, Mark // </8.> -------------------------------------------------------------------------- // 9. Push calleeContext onto the execution context stack; calleeContext is now the running execution context. - TRY(vm.push_execution_context(callee_context, global_object)); + TRY(vm.push_execution_context(callee_context, {})); // 10. Let result be the Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. thisArgument is the this value, argumentsList provides the named parameters, and the NewTarget value is undefined. auto result = call(); @@ -164,7 +163,6 @@ ThrowCompletionOr<Value> NativeFunction::internal_call(Value this_argument, Mark ThrowCompletionOr<Object*> NativeFunction::internal_construct(MarkedVector<Value> arguments_list, FunctionObject& new_target) { auto& vm = this->vm(); - auto& global_object = this->global_object(); // 1. Let callerContext be the running execution context. auto& caller_context = vm.running_execution_context(); @@ -212,7 +210,7 @@ ThrowCompletionOr<Object*> NativeFunction::internal_construct(MarkedVector<Value // </8.> -------------------------------------------------------------------------- // 9. Push calleeContext onto the execution context stack; calleeContext is now the running execution context. - TRY(vm.push_execution_context(callee_context, global_object)); + TRY(vm.push_execution_context(callee_context, {})); // 10. Let result be the Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. The this value is uninitialized, argumentsList provides the named parameters, and newTarget provides the NewTarget value. auto result = construct(new_target); diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index 367812762e..9a56419f29 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -57,10 +57,8 @@ void NumberConstructor::initialize(Realm& realm) } // Most of 21.1.1.1 Number ( value ) factored into a separate function for sharing between call() and construct(). -static ThrowCompletionOr<Value> get_value_from_constructor_argument(GlobalObject& global_object) +static ThrowCompletionOr<Value> get_value_from_constructor_argument(VM& vm) { - auto& vm = global_object.vm(); - Value number; if (vm.argument_count() > 0) { auto primitive = TRY(vm.argument(0).to_numeric(vm)); @@ -80,16 +78,15 @@ static ThrowCompletionOr<Value> get_value_from_constructor_argument(GlobalObject // 21.1.1.1 Number ( value ), https://tc39.es/ecma262/#sec-number-constructor-number-value ThrowCompletionOr<Value> NumberConstructor::call() { - return get_value_from_constructor_argument(global_object()); + return get_value_from_constructor_argument(vm()); } // 21.1.1.1 Number ( value ), https://tc39.es/ecma262/#sec-number-constructor-number-value ThrowCompletionOr<Object*> NumberConstructor::construct(FunctionObject& new_target) { - auto& global_object = this->global_object(); auto& vm = this->vm(); - auto number = TRY(get_value_from_constructor_argument(global_object)); + auto number = TRY(get_value_from_constructor_argument(vm)); return TRY(ordinary_create_from_constructor<NumberObject>(vm, new_target, &GlobalObject::number_prototype, number.as_double())); } diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index 826c4b8189..d93e1a9302 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -102,7 +102,7 @@ void NumberPrototype::initialize(Realm& realm) } // thisNumberValue ( value ), https://tc39.es/ecma262/#thisnumbervalue -static ThrowCompletionOr<Value> this_number_value(GlobalObject& global_object, Value value) +static ThrowCompletionOr<Value> this_number_value(VM& vm, Value value) { // 1. If Type(value) is Number, return value. if (value.is_number()) @@ -116,8 +116,6 @@ static ThrowCompletionOr<Value> this_number_value(GlobalObject& global_object, V return Value(static_cast<NumberObject&>(value.as_object()).number()); } - auto& vm = global_object.vm(); - // 3. Throw a TypeError exception. return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Number"); } @@ -128,7 +126,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_exponential) auto fraction_digits_value = vm.argument(0); // 1. Let x be ? thisNumberValue(this value). - auto number_value = TRY(this_number_value(global_object, vm.this_value())); + auto number_value = TRY(this_number_value(vm, vm.this_value())); // 2. Let f be ? ToIntegerOrInfinity(fractionDigits). auto fraction_digits = TRY(fraction_digits_value.to_integer_or_infinity(vm)); @@ -247,7 +245,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_exponential) JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed) { // 1. Let x be ? thisNumberValue(this value). - auto number_value = TRY(this_number_value(global_object, vm.this_value())); + auto number_value = TRY(this_number_value(vm, vm.this_value())); // 2. Let f be ? ToIntegerOrInfinity(fractionDigits). // 3. Assert: If fractionDigits is undefined, then f is 0. @@ -324,7 +322,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string) auto options = vm.argument(1); // 1. Let x be ? thisNumberValue(this value). - auto number_value = TRY(this_number_value(global_object, vm.this_value())); + auto number_value = TRY(this_number_value(vm, vm.this_value())); // 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »). auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), locales, options))); @@ -341,7 +339,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision) auto precision_value = vm.argument(0); // 1. Let x be ? thisNumberValue(this value). - auto number_value = TRY(this_number_value(global_object, vm.this_value())); + auto number_value = TRY(this_number_value(vm, vm.this_value())); // 2. If precision is undefined, return ! ToString(x). if (precision_value.is_undefined()) @@ -471,7 +469,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision) JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) { // 1. Let x be ? thisNumberValue(this value). - auto number_value = TRY(this_number_value(global_object, vm.this_value())); + auto number_value = TRY(this_number_value(vm, vm.this_value())); double radix_mv; @@ -553,7 +551,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string) JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::value_of) { // 1. Return ? thisNumberValue(this value). - return this_number_value(global_object, vm.this_value()); + return this_number_value(vm, vm.this_value()); } } diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 484dd676c1..ec791986de 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1133,7 +1133,6 @@ void Object::define_native_function(PropertyKey const& property_key, Function<Th // 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties ThrowCompletionOr<Object*> Object::define_properties(Value properties) { - auto& global_object = this->global_object(); auto& vm = this->vm(); // 1. Let props be ? ToObject(Properties). @@ -1163,7 +1162,7 @@ ThrowCompletionOr<Object*> Object::define_properties(Value properties) auto descriptor_object = TRY(props->get(property_key)); // ii. Let desc be ? ToPropertyDescriptor(descObj). - auto descriptor = TRY(to_property_descriptor(global_object, descriptor_object)); + auto descriptor = TRY(to_property_descriptor(vm, descriptor_object)); // iii. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors. descriptors.append({ property_key, descriptor }); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 270a55cc4a..07eee4ea89 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -84,10 +84,8 @@ enum class GetOwnPropertyKeysType { }; // 20.1.2.11.1 GetOwnPropertyKeys ( O, type ), https://tc39.es/ecma262/#sec-getownpropertykeys -static ThrowCompletionOr<MarkedVector<Value>> get_own_property_keys(GlobalObject& global_object, Value value, GetOwnPropertyKeysType type) +static ThrowCompletionOr<MarkedVector<Value>> get_own_property_keys(VM& vm, Value value, GetOwnPropertyKeysType type) { - auto& vm = global_object.vm(); - // 1. Let obj be ? ToObject(O). auto* object = TRY(value.to_object(vm)); @@ -116,7 +114,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) auto& realm = *global_object.associated_realm(); // 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, string)). - return Array::create_from(realm, TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::String))); + return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::String))); } // 20.1.2.11 Object.getOwnPropertySymbols ( O ), https://tc39.es/ecma262/#sec-object.getownpropertysymbols @@ -125,7 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_symbols) auto& realm = *global_object.associated_realm(); // 1. Return CreateArrayFromList(? GetOwnPropertyKeys(O, symbol)). - return Array::create_from(realm, TRY(get_own_property_keys(global_object, vm.argument(0), GetOwnPropertyKeysType::Symbol))); + return Array::create_from(realm, TRY(get_own_property_keys(vm, vm.argument(0), GetOwnPropertyKeysType::Symbol))); } // 20.1.2.12 Object.getPrototypeOf ( O ), https://tc39.es/ecma262/#sec-object.getprototypeof @@ -262,7 +260,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptor) auto* object = TRY(vm.argument(0).to_object(vm)); auto key = TRY(vm.argument(1).to_property_key(vm)); auto descriptor = TRY(object->internal_get_own_property(key)); - return from_property_descriptor(global_object, descriptor); + return from_property_descriptor(vm, descriptor); } // 20.1.2.9 Object.getOwnPropertyDescriptors ( O ), https://tc39.es/ecma262/#sec-object.getownpropertydescriptors @@ -287,7 +285,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_descriptors) auto desc = TRY(object->internal_get_own_property(property_key)); // b. Let descriptor be FromPropertyDescriptor(desc). - auto descriptor = from_property_descriptor(global_object, desc); + auto descriptor = from_property_descriptor(vm, desc); // c. If descriptor is not undefined, perform ! CreateDataPropertyOrThrow(descriptors, key, descriptor). if (!descriptor.is_undefined()) @@ -304,7 +302,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::define_property) if (!vm.argument(0).is_object()) return vm.throw_completion<TypeError>(ErrorType::NotAnObject, vm.argument(0).to_string_without_side_effects()); auto key = TRY(vm.argument(1).to_property_key(vm)); - auto descriptor = TRY(to_property_descriptor(global_object, vm.argument(2))); + auto descriptor = TRY(to_property_descriptor(vm, vm.argument(2))); TRY(vm.argument(0).as_object().define_property_or_throw(key, descriptor)); return vm.argument(0); } diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp index f90276ceb4..59412eb99a 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp @@ -87,12 +87,12 @@ Utf16View PrimitiveString::utf16_string_view() const return utf16_string().view(); } -Optional<Value> PrimitiveString::get(GlobalObject& global_object, PropertyKey const& property_key) const +Optional<Value> PrimitiveString::get(VM& vm, PropertyKey const& property_key) const { if (property_key.is_symbol()) return {}; if (property_key.is_string()) { - if (property_key.as_string() == global_object.vm().names.length.as_string()) { + if (property_key.as_string() == vm.names.length.as_string()) { auto length = utf16_string().length_in_code_units(); return Value(static_cast<double>(length)); } @@ -104,7 +104,7 @@ Optional<Value> PrimitiveString::get(GlobalObject& global_object, PropertyKey co auto length = str.length_in_code_units(); if (length <= index.as_index()) return {}; - return js_string(vm(), str.substring_view(index.as_index(), 1)); + return js_string(vm, str.substring_view(index.as_index(), 1)); } PrimitiveString* js_string(Heap& heap, Utf16View const& view) diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.h b/Userland/Libraries/LibJS/Runtime/PrimitiveString.h index 889bb1132d..38300c4b3a 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.h +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.h @@ -34,7 +34,7 @@ public: Utf16View utf16_string_view() const; bool has_utf16_string() const { return m_has_utf16_string; } - Optional<Value> get(GlobalObject&, PropertyKey const&) const; + Optional<Value> get(VM&, PropertyKey const&) const; private: virtual StringView class_name() const override { return "PrimitiveString"sv; } diff --git a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp index b471116277..74bb413b76 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.cpp @@ -65,13 +65,13 @@ bool PropertyDescriptor::is_generic_descriptor() const } // 6.2.5.4 FromPropertyDescriptor ( Desc ), https://tc39.es/ecma262/#sec-frompropertydescriptor -Value from_property_descriptor(GlobalObject& global_object, Optional<PropertyDescriptor> const& property_descriptor) +Value from_property_descriptor(VM& vm, Optional<PropertyDescriptor> const& property_descriptor) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); + if (!property_descriptor.has_value()) return js_undefined(); - auto& vm = global_object.vm(); - auto* object = Object::create(realm, global_object.object_prototype()); + auto* object = Object::create(realm, realm.global_object().object_prototype()); if (property_descriptor->value.has_value()) MUST(object->create_data_property_or_throw(vm.names.value, *property_descriptor->value)); if (property_descriptor->writable.has_value()) @@ -88,10 +88,8 @@ Value from_property_descriptor(GlobalObject& global_object, Optional<PropertyDes } // 6.2.5.5 ToPropertyDescriptor ( Obj ), https://tc39.es/ecma262/#sec-topropertydescriptor -ThrowCompletionOr<PropertyDescriptor> to_property_descriptor(GlobalObject& global_object, Value argument) +ThrowCompletionOr<PropertyDescriptor> to_property_descriptor(VM& vm, Value argument) { - auto& vm = global_object.vm(); - // 1. If Type(Obj) is not Object, throw a TypeError exception. if (!argument.is_object()) return vm.throw_completion<TypeError>(ErrorType::NotAnObject, argument.to_string_without_side_effects()); diff --git a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.h b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.h index 048ef7cd99..2f9bfcb3b0 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.h +++ b/Userland/Libraries/LibJS/Runtime/PropertyDescriptor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,8 +14,8 @@ namespace JS { // 6.2.5 The Property Descriptor Specification Type, https://tc39.es/ecma262/#sec-property-descriptor-specification-type -Value from_property_descriptor(GlobalObject&, Optional<PropertyDescriptor> const&); -ThrowCompletionOr<PropertyDescriptor> to_property_descriptor(GlobalObject&, Value); +Value from_property_descriptor(VM&, Optional<PropertyDescriptor> const&); +ThrowCompletionOr<PropertyDescriptor> to_property_descriptor(VM&, Value); class PropertyDescriptor { public: diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp index 3a7ba4fe00..16d4651a3b 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -14,10 +14,9 @@ namespace JS { // 10.5.14 ProxyCreate ( target, handler ), https://tc39.es/ecma262/#sec-proxycreate -static ThrowCompletionOr<ProxyObject*> proxy_create(GlobalObject& global_object, Value target, Value handler) +static ThrowCompletionOr<ProxyObject*> proxy_create(VM& vm, Value target, Value handler) { - auto& vm = global_object.vm(); - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); if (!target.is_object()) return vm.throw_completion<TypeError>(ErrorType::ProxyConstructorBadType, "target", target.to_string_without_side_effects()); if (!handler.is_object()) @@ -51,16 +50,16 @@ ThrowCompletionOr<Value> ProxyConstructor::call() ThrowCompletionOr<Object*> ProxyConstructor::construct(FunctionObject&) { auto& vm = this->vm(); - return TRY(proxy_create(global_object(), vm.argument(0), vm.argument(1))); + return TRY(proxy_create(vm, vm.argument(0), vm.argument(1))); } // 28.2.2.1 Proxy.revocable ( target, handler ), https://tc39.es/ecma262/#sec-proxy.revocable JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable) { - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // 1. Let p be ? ProxyCreate(target, handler). - auto* proxy = TRY(proxy_create(global_object, vm.argument(0), vm.argument(1))); + 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<Value> { diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp index 757a785855..9ccfbd548b 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -217,7 +217,6 @@ ThrowCompletionOr<bool> ProxyObject::internal_prevent_extensions() ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_property(PropertyKey const& property_key) const { auto& vm = this->vm(); - auto& global_object = this->global_object(); VERIFY(property_key.is_valid()); @@ -274,7 +273,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr auto extensible_target = TRY(m_target.is_extensible()); // 12. Let resultDesc be ? ToPropertyDescriptor(trapResultObj). - auto result_desc = TRY(to_property_descriptor(global_object, trap_result)); + auto result_desc = TRY(to_property_descriptor(vm, trap_result)); // 13. Perform CompletePropertyDescriptor(resultDesc). result_desc.complete(); @@ -309,7 +308,6 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyKey const& property_key, PropertyDescriptor const& property_descriptor) { auto& vm = this->vm(); - auto& global_object = this->global_object(); VERIFY(property_key.is_valid()); @@ -332,7 +330,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyKey co } // 7. Let descObj be FromPropertyDescriptor(Desc). - auto descriptor_object = from_property_descriptor(global_object, property_descriptor); + auto descriptor_object = from_property_descriptor(vm, property_descriptor); // 8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P, descObj »)). auto trap_result = TRY(call(vm, *trap, &m_handler, &m_target, property_key_to_value(vm, property_key), descriptor_object)).to_boolean(); diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index a5d1c107b6..d94148398c 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -116,7 +116,7 @@ ThrowCompletionOr<Value> Reference::get_value(VM& vm) const // OPTIMIZATION: For various primitives we can avoid actually creating a new object for them. Object* base_obj = nullptr; if (m_base_value.is_string()) { - auto string_value = m_base_value.as_string().get(global_object, m_name); + auto string_value = m_base_value.as_string().get(vm, m_name); if (string_value.has_value()) return *string_value; base_obj = global_object.string_prototype(); diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index e2eb72203a..128c052534 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -102,7 +102,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::define_property) auto key = TRY(property_key.to_property_key(vm)); // 3. Let desc be ? ToPropertyDescriptor(attributes). - auto descriptor = TRY(to_property_descriptor(global_object, attributes)); + auto descriptor = TRY(to_property_descriptor(vm, attributes)); // 4. Return ? target.[[DefineOwnProperty]](key, desc). return Value(TRY(target.as_object().internal_define_own_property(key, descriptor))); @@ -166,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor) auto descriptor = TRY(target.as_object().internal_get_own_property(key)); // 4. Return FromPropertyDescriptor(desc). - return from_property_descriptor(global_object, descriptor); + return from_property_descriptor(vm, descriptor); } // 28.1.7 Reflect.getPrototypeOf ( target ), https://tc39.es/ecma262/#sec-reflect.getprototypeof diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 8c6bceabcb..8864b1167e 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -161,7 +161,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex eval_context.is_strict_mode = strict_eval; // 15. Push evalContext onto the execution context stack; evalContext is now the running execution context. - TRY(vm.push_execution_context(eval_context, eval_realm.global_object())); + TRY(vm.push_execution_context(eval_context, {})); // 16. Let result be Completion(EvalDeclarationInstantiation(body, varEnv, lexEnv, null, strictEval)). auto eval_result = eval_declaration_instantiation(vm, program, variable_environment, lexical_environment, nullptr, strict_eval); @@ -204,6 +204,9 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex // 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context) { + // FIXME: evalRealm isn't being used anywhere in this AO (spec issue) + (void)eval_realm; + auto& realm = *vm.current_realm(); // 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]]. @@ -216,7 +219,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_stri // NOTE: We don't support this concept yet. // 5. Push evalContext onto the execution context stack; evalContext is now the running execution context. - TRY(vm.push_execution_context(eval_context, eval_realm.global_object())); + TRY(vm.push_execution_context(eval_context, {})); // 6. Perform HostImportModuleDynamically(null, specifierString, innerCapability). vm.host_import_module_dynamically(Empty {}, ModuleRequest { move(specifier_string) }, inner_capability); diff --git a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp index 2ee9f50447..cefa0f4671 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -38,20 +38,19 @@ void SymbolPrototype::initialize(Realm& realm) } // thisSymbolValue ( value ), https://tc39.es/ecma262/#thissymbolvalue -static ThrowCompletionOr<Symbol*> this_symbol_value(GlobalObject& global_object, Value value) +static ThrowCompletionOr<Symbol*> this_symbol_value(VM& vm, Value value) { if (value.is_symbol()) return &value.as_symbol(); if (value.is_object() && is<SymbolObject>(value.as_object())) return &static_cast<SymbolObject&>(value.as_object()).primitive_symbol(); - auto& vm = global_object.vm(); return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Symbol"); } // 20.4.3.2 get Symbol.prototype.description, https://tc39.es/ecma262/#sec-symbol.prototype.description JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::description_getter) { - auto* symbol = TRY(this_symbol_value(global_object, vm.this_value())); + auto* symbol = TRY(this_symbol_value(vm, vm.this_value())); auto& description = symbol->raw_description(); if (!description.has_value()) return js_undefined(); @@ -61,21 +60,21 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::description_getter) // 20.4.3.3 Symbol.prototype.toString ( ), https://tc39.es/ecma262/#sec-symbol.prototype.tostring JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string) { - auto* symbol = TRY(this_symbol_value(global_object, vm.this_value())); + auto* symbol = TRY(this_symbol_value(vm, vm.this_value())); return js_string(vm, symbol->to_string()); } // 20.4.3.4 Symbol.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-symbol.prototype.valueof JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::value_of) { - return TRY(this_symbol_value(global_object, vm.this_value())); + return TRY(this_symbol_value(vm, vm.this_value())); } // 20.4.3.5 Symbol.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::symbol_to_primitive) { // The hint argument is ignored. - return TRY(this_symbol_value(global_object, vm.this_value())); + return TRY(this_symbol_value(vm, vm.this_value())); } } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp index b2f5cc1508..da7f0f86df 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantConstructor.cpp @@ -86,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_seconds) auto epoch_seconds_value = TRY(vm.argument(0).to_number(vm)); // 2. Set epochSeconds to ? NumberToBigInt(epochSeconds). - auto* epoch_seconds = TRY(number_to_bigint(global_object, epoch_seconds_value)); + auto* epoch_seconds = TRY(number_to_bigint(vm, epoch_seconds_value)); // 3. Let epochNanoseconds be epochSeconds × 10^9ℤ. auto* epoch_nanoseconds = js_bigint(vm, epoch_seconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000'000 })); @@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_milliseconds) auto epoch_milliseconds_value = TRY(vm.argument(0).to_number(vm)); // 2. Set epochMilliseconds to ? NumberToBigInt(epochMilliseconds). - auto* epoch_milliseconds = TRY(number_to_bigint(global_object, epoch_milliseconds_value)); + auto* epoch_milliseconds = TRY(number_to_bigint(vm, epoch_milliseconds_value)); // 3. Let epochNanoseconds be epochMilliseconds × 10^6ℤ. auto* epoch_nanoseconds = js_bigint(vm, epoch_milliseconds->big_integer().multiplied_by(Crypto::UnsignedBigInteger { 1'000'000 })); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index e13dd25cf6..1464b5d040 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -255,16 +255,16 @@ ThrowCompletionOr<Value> VM::named_evaluation_if_anonymous_function(ASTNode cons } // 13.15.5.2 Runtime Semantics: DestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-destructuringassignmentevaluation -ThrowCompletionOr<void> VM::destructuring_assignment_evaluation(NonnullRefPtr<BindingPattern> const& target, Value value, GlobalObject& global_object) +ThrowCompletionOr<void> VM::destructuring_assignment_evaluation(NonnullRefPtr<BindingPattern> const& target, Value value) { // Note: DestructuringAssignmentEvaluation is just like BindingInitialization without an environment // And it allows member expressions. We thus trust the parser to disallow member expressions // in any non assignment binding and just call BindingInitialization with a nullptr environment - return binding_initialization(target, value, nullptr, global_object); + return binding_initialization(target, value, nullptr); } // 8.5.2 Runtime Semantics: BindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-bindinginitialization -ThrowCompletionOr<void> VM::binding_initialization(FlyString const& target, Value value, Environment* environment, GlobalObject&) +ThrowCompletionOr<void> VM::binding_initialization(FlyString const& target, Value value, Environment* environment) { // 1. Let name be StringValue of Identifier. // 2. Return ? InitializeBoundName(name, value, environment). @@ -272,7 +272,7 @@ ThrowCompletionOr<void> VM::binding_initialization(FlyString const& target, Valu } // 8.5.2 Runtime Semantics: BindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-bindinginitialization -ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern> const& target, Value value, Environment* environment, GlobalObject& global_object) +ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern> const& target, Value value, Environment* environment) { auto& vm = *this; @@ -285,7 +285,7 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern> // BindingInitialization of ObjectBindingPattern // 1. Perform ? PropertyBindingInitialization of BindingPropertyList with arguments value and environment. - TRY(property_binding_initialization(*target, value, environment, global_object)); + TRY(property_binding_initialization(*target, value, environment)); // 2. Return unused. return {}; @@ -296,7 +296,7 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern> auto iterator_record = TRY(get_iterator(vm, value)); // 2. Let result be Completion(IteratorBindingInitialization of ArrayBindingPattern with arguments iteratorRecord and environment). - auto result = iterator_binding_initialization(*target, iterator_record, environment, global_object); + auto result = iterator_binding_initialization(*target, iterator_record, environment); // 3. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iteratorRecord, result). if (!iterator_record.done) { @@ -314,10 +314,11 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern> // 13.15.5.3 Runtime Semantics: PropertyDestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-propertydestructuringassignmentevaluation // 14.3.3.1 Runtime Semantics: PropertyBindingInitialization, https://tc39.es/ecma262/#sec-destructuring-binding-patterns-runtime-semantics-propertybindinginitialization -ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject& global_object) +ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment) { auto& vm = *this; - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); + auto* object = TRY(value.to_object(vm)); HashTable<PropertyKey> seen_names; @@ -335,7 +336,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const VERIFY_NOT_REACHED(); } - auto* rest_object = Object::create(realm, global_object.object_prototype()); + auto* rest_object = Object::create(realm, realm.global_object().object_prototype()); VERIFY(rest_object); TRY(rest_object->copy_data_properties(vm, object, seen_names)); @@ -393,7 +394,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const } if (auto* binding_ptr = property.alias.get_pointer<NonnullRefPtr<BindingPattern>>()) { - TRY(binding_initialization(*binding_ptr, value_to_assign, environment, global_object)); + TRY(binding_initialization(*binding_ptr, value_to_assign, environment)); } else { VERIFY(reference_to_assign_to.has_value()); if (!environment) @@ -408,10 +409,10 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const // 13.15.5.5 Runtime Semantics: IteratorDestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-iteratordestructuringassignmentevaluation // 8.5.3 Runtime Semantics: IteratorBindingInitialization, https://tc39.es/ecma262/#sec-runtime-semantics-iteratorbindinginitialization -ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const& binding, Iterator& iterator_record, Environment* environment, GlobalObject& global_object) +ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const& binding, Iterator& iterator_record, Environment* environment) { auto& vm = *this; - auto& realm = *global_object.associated_realm(); + auto& realm = *vm.current_realm(); // FIXME: this method is nearly identical to destructuring assignment! for (size_t i = 0; i < binding.entries.size(); i++) { @@ -530,7 +531,7 @@ ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const } if (auto* binding_ptr = entry.alias.get_pointer<NonnullRefPtr<BindingPattern>>()) { - TRY(binding_initialization(*binding_ptr, value, environment, global_object)); + TRY(binding_initialization(*binding_ptr, value, environment)); } else if (!entry.alias.has<Empty>()) { VERIFY(assignment_target.has_value()); if (!environment) diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 94c603b182..b32d708e46 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -93,7 +93,10 @@ public: m_execution_context_stack.append(&context); } - ThrowCompletionOr<void> push_execution_context(ExecutionContext& context, GlobalObject&) + // TODO: Rename this function instead of providing a second argument, now that the global object is no longer passed in. + struct CheckStackSpaceLimitTag { }; + + ThrowCompletionOr<void> push_execution_context(ExecutionContext& context, CheckStackSpaceLimitTag) { // Ensure we got some stack space left, so the next function call doesn't kill us. if (did_reach_stack_space_limit()) @@ -203,9 +206,9 @@ public: CustomData* custom_data() { return m_custom_data; } - ThrowCompletionOr<void> destructuring_assignment_evaluation(NonnullRefPtr<BindingPattern> const& target, Value value, GlobalObject& global_object); - ThrowCompletionOr<void> binding_initialization(FlyString const& target, Value value, Environment* environment, GlobalObject&); - ThrowCompletionOr<void> binding_initialization(NonnullRefPtr<BindingPattern> const& target, Value value, Environment* environment, GlobalObject& global_object); + ThrowCompletionOr<void> destructuring_assignment_evaluation(NonnullRefPtr<BindingPattern> const& target, Value value); + ThrowCompletionOr<void> binding_initialization(FlyString const& target, Value value, Environment* environment); + ThrowCompletionOr<void> binding_initialization(NonnullRefPtr<BindingPattern> const& target, Value value, Environment* environment); ThrowCompletionOr<Value> named_evaluation_if_anonymous_function(ASTNode const& expression, FlyString const& name); @@ -239,8 +242,8 @@ public: private: explicit VM(OwnPtr<CustomData>); - ThrowCompletionOr<void> property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment, GlobalObject&); - ThrowCompletionOr<void> iterator_binding_initialization(BindingPattern const& binding, Iterator& iterator_record, Environment* environment, GlobalObject&); + ThrowCompletionOr<void> property_binding_initialization(BindingPattern const& binding, Value value, Environment* environment); + ThrowCompletionOr<void> iterator_binding_initialization(BindingPattern const& binding, Iterator& iterator_record, Environment* environment); ThrowCompletionOr<NonnullRefPtr<Module>> resolve_imported_module(ScriptOrModule referencing_script_or_module, ModuleRequest const& module_request); ThrowCompletionOr<void> link_and_eval_module(Module& module); diff --git a/Userland/Libraries/LibJS/SourceTextModule.cpp b/Userland/Libraries/LibJS/SourceTextModule.cpp index bb15ecb8c6..f2509a1f4f 100644 --- a/Userland/Libraries/LibJS/SourceTextModule.cpp +++ b/Userland/Libraries/LibJS/SourceTextModule.cpp @@ -402,7 +402,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm) // Note: We're already working on that one. // 17. Push moduleContext onto the execution context stack; moduleContext is now the running execution context. - TRY(vm.push_execution_context(m_execution_context, realm().global_object())); + TRY(vm.push_execution_context(m_execution_context, {})); // 18. Let code be module.[[ECMAScriptCode]]. @@ -655,7 +655,7 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, Optional<Promis // a. Assert: capability is not present. VERIFY(!capability.has_value()); // b. Push moduleContext onto the execution context stack; moduleContext is now the running execution context. - TRY(vm.push_execution_context(module_context, realm().global_object())); + TRY(vm.push_execution_context(module_context, {})); // c. Let result be the result of evaluating module.[[ECMAScriptCode]]. auto result = m_ecmascript_code->execute(vm.interpreter()); diff --git a/Userland/Libraries/LibJS/SyntheticModule.cpp b/Userland/Libraries/LibJS/SyntheticModule.cpp index 39021d444f..709de2869c 100644 --- a/Userland/Libraries/LibJS/SyntheticModule.cpp +++ b/Userland/Libraries/LibJS/SyntheticModule.cpp @@ -95,7 +95,7 @@ ThrowCompletionOr<Promise*> SyntheticModule::evaluate(VM& vm) module_context.lexical_environment = environment(); // 8. Push moduleContext on to the execution context stack; moduleContext is now the running execution context. - TRY(vm.push_execution_context(module_context, realm().global_object())); + TRY(vm.push_execution_context(module_context, {})); // 9. Let result be the result of performing module.[[EvaluationSteps]](module). auto result = m_evaluation_steps(*this); |