mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 01:07:44 +00:00
LibJS+LibWeb: Reduce use of GlobalObject as an intermediary
- Prefer VM::current_realm() over GlobalObject::associated_realm() - Prefer VM::heap() over GlobalObject::heap() - Prefer Cell::vm() over Cell::global_object() - Prefer Wrapper::vm() over Wrapper::global_object() - Inline Realm::global_object() calls used to access intrinsics as they will later perform a direct lookup without going through the global object
This commit is contained in:
parent
e3895e6c80
commit
b345a0acca
58 changed files with 157 additions and 231 deletions
|
@ -288,9 +288,8 @@ Completion FunctionExpression::execute(Interpreter& interpreter) const
|
|||
// 15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression, https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
|
||||
Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& interpreter, FlyString given_name) const
|
||||
{
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
if (given_name.is_empty())
|
||||
given_name = "";
|
||||
|
@ -426,8 +425,8 @@ Completion CallExpression::throw_type_error_for_callee(Interpreter& interpreter,
|
|||
Completion CallExpression::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto callee_reference = TRY(m_callee->to_reference(interpreter));
|
||||
|
||||
|
@ -443,7 +442,7 @@ Completion CallExpression::execute(Interpreter& interpreter) const
|
|||
|
||||
auto& function = callee.as_function();
|
||||
|
||||
if (&function == global_object.eval_function()
|
||||
if (&function == realm.global_object().eval_function()
|
||||
&& callee_reference.is_environment_reference()
|
||||
&& callee_reference.name().is_string()
|
||||
&& callee_reference.name().as_string() == vm.names.eval.as_string()) {
|
||||
|
@ -594,8 +593,7 @@ Completion IfStatement::execute(Interpreter& interpreter) const
|
|||
Completion WithStatement::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = global_object.vm();
|
||||
auto& vm = interpreter.vm();
|
||||
|
||||
// 1. Let value be the result of evaluating Expression.
|
||||
auto value = TRY(m_object->execute(interpreter)).release_value();
|
||||
|
@ -1664,8 +1662,8 @@ private:
|
|||
// 15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classfielddefinitionevaluation
|
||||
ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation(Interpreter& interpreter, Object& target) const
|
||||
{
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto property_key_or_private_name = TRY(class_key_to_property_name(interpreter, *m_key));
|
||||
Handle<ECMAScriptFunctionObject> initializer {};
|
||||
|
@ -1713,8 +1711,8 @@ Optional<FlyString> ClassMethod::private_bound_identifier() const
|
|||
// 15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classstaticblockdefinitionevaluation
|
||||
ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_evaluation(Interpreter& interpreter, Object& home_object) const
|
||||
{
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let lex be the running execution context's LexicalEnvironment.
|
||||
auto* lexical_environment = interpreter.vm().running_execution_context().lexical_environment;
|
||||
|
@ -1807,9 +1805,8 @@ Completion ClassDeclaration::execute(Interpreter& interpreter) const
|
|||
// 15.7.14 Runtime Semantics: ClassDefinitionEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation
|
||||
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_evaluation(Interpreter& interpreter, FlyString const& binding_name, FlyString const& class_name) const
|
||||
{
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* environment = vm.lexical_environment();
|
||||
VERIFY(environment);
|
||||
|
@ -3035,12 +3032,11 @@ Completion ObjectProperty::execute(Interpreter& interpreter) const
|
|||
Completion ObjectExpression::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let obj be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// 2. Perform ? PropertyDefinitionEvaluation of PropertyDefinitionList with argument obj.
|
||||
for (auto& property : m_properties) {
|
||||
|
@ -3252,8 +3248,8 @@ void MetaProperty::dump(int indent) const
|
|||
Completion MetaProperty::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// NewTarget : new . target
|
||||
if (m_type == MetaProperty::Type::NewTarget) {
|
||||
|
@ -3328,9 +3324,8 @@ void ImportCall::dump(int indent) const
|
|||
Completion ImportCall::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 2.1.1.1 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-assertions/#sec-evaluate-import-call
|
||||
// 1. Let referencingScriptOrModule be GetActiveScriptOrModule().
|
||||
|
@ -3352,7 +3347,7 @@ Completion ImportCall::execute(Interpreter& interpreter) const
|
|||
// Note: options_value is undefined by default.
|
||||
|
||||
// 6. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
||||
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||
|
||||
// 7. Let specifierString be Completion(ToString(specifier)).
|
||||
// 8. IfAbruptRejectPromise(specifierString, promiseCapability).
|
||||
|
@ -3501,8 +3496,8 @@ void RegExpLiteral::dump(int indent) const
|
|||
Completion RegExpLiteral::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let pattern be CodePointsToString(BodyText of RegularExpressionLiteral).
|
||||
auto pattern = this->pattern();
|
||||
|
@ -3532,9 +3527,8 @@ void ArrayExpression::dump(int indent) const
|
|||
Completion ArrayExpression::execute(Interpreter& interpreter) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let array be ! ArrayCreate(0).
|
||||
auto* array = MUST(Array::create(realm, 0));
|
||||
|
@ -3651,9 +3645,10 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter) const
|
|||
// 13.2.8.3 GetTemplateObject ( templateLiteral ), https://tc39.es/ecma262/#sec-gettemplateobject
|
||||
ThrowCompletionOr<Value> TaggedTemplateLiteral::get_template_object(Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
||||
// 1. Let realm be the current Realm Record.
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 2. Let templateRegistry be realm.[[TemplateMap]].
|
||||
// 3. For each element e of templateRegistry, do
|
||||
|
@ -4518,9 +4513,8 @@ bool ImportStatement::has_bound_name(FlyString const& name) const
|
|||
void ScopeNode::block_declaration_instantiation(Interpreter& interpreter, Environment* environment) const
|
||||
{
|
||||
// See also B.3.2.6 Changes to BlockDeclarationInstantiation, https://tc39.es/ecma262/#sec-web-compat-blockdeclarationinstantiation
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
VERIFY(environment);
|
||||
auto* private_environment = vm.running_execution_context().private_environment;
|
||||
|
@ -4548,9 +4542,8 @@ void ScopeNode::block_declaration_instantiation(Interpreter& interpreter, Enviro
|
|||
// 16.1.7 GlobalDeclarationInstantiation ( script, env ), https://tc39.es/ecma262/#sec-globaldeclarationinstantiation
|
||||
ThrowCompletionOr<void> Program::global_declaration_instantiation(Interpreter& interpreter, GlobalEnvironment& global_environment) const
|
||||
{
|
||||
auto& global_object = interpreter.global_object();
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let lexNames be the LexicallyDeclaredNames of script.
|
||||
// 2. Let varNames be the VarDeclaredNames of script.
|
||||
|
|
|
@ -237,7 +237,10 @@ ThrowCompletionOr<void> NewString::execute_impl(Bytecode::Interpreter& interpret
|
|||
|
||||
ThrowCompletionOr<void> NewObject::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.accumulator() = Object::create(interpreter.realm(), interpreter.global_object().object_prototype());
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
interpreter.accumulator() = Object::create(realm, realm.global_object().object_prototype());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -255,9 +258,11 @@ ThrowCompletionOr<void> NewRegExp::execute_impl(Bytecode::Interpreter& interpret
|
|||
ThrowCompletionOr<void> CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* from_object = TRY(interpreter.reg(m_from_object).to_object(vm));
|
||||
|
||||
auto* to_object = Object::create(interpreter.realm(), interpreter.global_object().object_prototype());
|
||||
auto* to_object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
HashTable<Value, ValueTraits> excluded_names;
|
||||
for (size_t i = 0; i < m_excluded_names_count; ++i)
|
||||
|
|
|
@ -500,7 +500,6 @@ VM& ConsoleClient::vm()
|
|||
// 2.1. Logger(logLevel, args), https://console.spec.whatwg.org/#logger
|
||||
ThrowCompletionOr<Value> ConsoleClient::logger(Console::LogLevel log_level, MarkedVector<Value> const& args)
|
||||
{
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. If args is empty, return.
|
||||
|
@ -515,7 +514,7 @@ ThrowCompletionOr<Value> ConsoleClient::logger(Console::LogLevel log_level, Mark
|
|||
|
||||
// 4. If rest is empty, perform Printer(logLevel, « first ») and return.
|
||||
if (rest_size == 0) {
|
||||
MarkedVector<Value> first_as_vector { global_object.heap() };
|
||||
MarkedVector<Value> first_as_vector { vm.heap() };
|
||||
first_as_vector.append(first);
|
||||
return printer(log_level, move(first_as_vector));
|
||||
}
|
||||
|
|
|
@ -197,11 +197,11 @@ ThrowCompletionOr<Promise*> CyclicModule::evaluate(VM& vm)
|
|||
// 5. Let stack be a new empty List.
|
||||
Vector<Module*> stack;
|
||||
|
||||
auto& global_object = realm().global_object();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 6. Let capability be ! NewPromiseCapability(%Promise%).
|
||||
// 7. Set module.[[TopLevelCapability]] to capability.
|
||||
m_top_level_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
||||
m_top_level_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||
|
||||
// 8. Let result be Completion(InnerModuleEvaluation(module, stack, 0)).
|
||||
auto result = inner_module_evaluation(vm, stack, 0);
|
||||
|
@ -433,8 +433,7 @@ ThrowCompletionOr<void> CyclicModule::execute_module(VM&, Optional<PromiseCapabi
|
|||
// 16.2.1.5.2.2 ExecuteAsyncModule ( module ), https://tc39.es/ecma262/#sec-execute-async-module
|
||||
void CyclicModule::execute_async_module(VM& vm)
|
||||
{
|
||||
auto& global_object = realm().global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] executing async module {}", filename());
|
||||
// 1. Assert: module.[[Status]] is evaluating or evaluating-async.
|
||||
|
@ -443,7 +442,7 @@ void CyclicModule::execute_async_module(VM& vm)
|
|||
VERIFY(m_has_top_level_await);
|
||||
|
||||
// 3. Let capability be ! NewPromiseCapability(%Promise%).
|
||||
auto capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
||||
auto capability = MUST(new_promise_capability(vm, realm.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) -> ThrowCompletionOr<Value> {
|
||||
|
|
|
@ -22,10 +22,10 @@ namespace JS {
|
|||
|
||||
NonnullOwnPtr<Interpreter> Interpreter::create_with_existing_realm(Realm& realm)
|
||||
{
|
||||
auto& global_object = realm.global_object();
|
||||
DeferGC defer_gc(global_object.heap());
|
||||
auto interpreter = adopt_own(*new Interpreter(global_object.vm()));
|
||||
interpreter->m_global_object = make_handle(&global_object);
|
||||
auto& vm = realm.vm();
|
||||
DeferGC defer_gc(vm.heap());
|
||||
auto interpreter = adopt_own(*new Interpreter(vm));
|
||||
interpreter->m_global_object = make_handle(&realm.global_object());
|
||||
interpreter->m_realm = make_handle(&realm);
|
||||
return interpreter;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ ThrowCompletionOr<Value> AggregateErrorConstructor::call()
|
|||
ThrowCompletionOr<Object*> AggregateErrorConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* aggregate_error = TRY(ordinary_create_from_constructor<AggregateError>(vm, new_target, &GlobalObject::aggregate_error_prototype));
|
||||
|
||||
|
|
|
@ -50,8 +50,7 @@ ThrowCompletionOr<Value> ArrayConstructor::call()
|
|||
ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &GlobalObject::array_prototype));
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ void AsyncFromSyncIteratorPrototype::initialize(Realm& realm)
|
|||
static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, PromiseCapability& promise_capability)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. NOTE: Because promiseCapability is derived from the intrinsic %Promise%, the calls to promiseCapability.[[Reject]] entailed by the use IfAbruptRejectPromise below are guaranteed not to throw.
|
||||
// 2. Let done be Completion(IteratorComplete(result)).
|
||||
|
@ -47,7 +46,7 @@ static Object* async_from_sync_iterator_continuation(VM& vm, Object& result, Pro
|
|||
|
||||
// 6. Let valueWrapper be PromiseResolve(%Promise%, value).
|
||||
// 7. IfAbruptRejectPromise(valueWrapper, promiseCapability).
|
||||
auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *global_object.promise_constructor(), value));
|
||||
auto value_wrapper = TRY_OR_MUST_REJECT(vm, promise_capability, promise_resolve(vm, *realm.global_object().promise_constructor(), value));
|
||||
|
||||
// 8. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called:
|
||||
auto unwrap = [done](VM& vm) -> ThrowCompletionOr<Value> {
|
||||
|
|
|
@ -986,8 +986,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_json)
|
|||
static ThrowCompletionOr<Intl::DateTimeFormat*> construct_date_time_format(VM& vm, Value locales, Value options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
auto* date_time_format = TRY(construct(vm, *global_object.intl_date_time_format_constructor(), locales, options));
|
||||
auto* date_time_format = TRY(construct(vm, *realm.global_object().intl_date_time_format_constructor(), locales, options));
|
||||
return static_cast<Intl::DateTimeFormat*>(date_time_format);
|
||||
}
|
||||
|
||||
|
|
|
@ -318,8 +318,7 @@ void ECMAScriptFunctionObject::make_method(Object& home_object)
|
|||
ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantiation(Interpreter* interpreter)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto& callee_context = vm.running_execution_context();
|
||||
|
||||
|
@ -780,8 +779,7 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi
|
|||
Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto* bytecode_interpreter = Bytecode::Interpreter::current();
|
||||
|
||||
if (m_kind == FunctionKind::AsyncGenerator)
|
||||
|
@ -865,7 +863,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
|||
// AsyncFunctionBody : FunctionBody
|
||||
else if (m_kind == FunctionKind::Async) {
|
||||
// 1. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
auto promise_capability = MUST(new_promise_capability(vm, global_object.promise_constructor()));
|
||||
auto promise_capability = MUST(new_promise_capability(vm, realm.global_object().promise_constructor()));
|
||||
|
||||
// 2. Let declResult be Completion(FunctionDeclarationInstantiation(functionObject, argumentsList)).
|
||||
auto declaration_result = function_declaration_instantiation(ast_interpreter);
|
||||
|
|
|
@ -247,7 +247,7 @@ ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(FlyString c
|
|||
|
||||
// 1. Let ObjRec be envRec.[[ObjectRecord]].
|
||||
// 2. Let globalObject be ObjRec.[[BindingObject]].
|
||||
auto& global_object = verify_cast<GlobalObject>(m_object_record->binding_object());
|
||||
auto& global_object = m_object_record->binding_object();
|
||||
|
||||
// 3. Let hasProperty be ? HasOwnProperty(globalObject, N).
|
||||
auto has_property = TRY(global_object.has_own_property(name));
|
||||
|
|
|
@ -532,7 +532,6 @@ static Optional<StringView> resolve_day_period(StringView locale, StringView cal
|
|||
ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, DateTimeFormat& date_time_format, Vector<PatternPartition> pattern_parts, double time, Unicode::CalendarPattern const* range_format_options)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let x be TimeClip(x).
|
||||
time = time_clip(time);
|
||||
|
@ -546,7 +545,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
|
|||
auto const& data_locale = date_time_format.data_locale();
|
||||
|
||||
auto construct_number_format = [&](auto* options) -> ThrowCompletionOr<NumberFormat*> {
|
||||
auto* number_format = TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, locale), options));
|
||||
auto* number_format = TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale), options));
|
||||
return static_cast<NumberFormat*>(number_format);
|
||||
};
|
||||
|
||||
|
@ -849,7 +848,6 @@ ThrowCompletionOr<String> format_date_time(VM& vm, DateTimeFormat& date_time_for
|
|||
ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date_time_format, double time)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let parts be ? PartitionDateTimePattern(dateTimeFormat, x).
|
||||
auto parts = TRY(partition_date_time_pattern(vm, date_time_format, time));
|
||||
|
@ -863,7 +861,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
|
|||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||
|
@ -1164,7 +1162,6 @@ ThrowCompletionOr<String> format_date_time_range(VM& vm, DateTimeFormat& date_ti
|
|||
ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat& date_time_format, double start, double end)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, x, y).
|
||||
auto parts = TRY(partition_date_time_range_pattern(vm, date_time_format, start, end));
|
||||
|
@ -1178,7 +1175,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
|
|||
// 4. For each Record { [[Type]], [[Value]], [[Source]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be OrdinaryObjectCreate(%ObjectPrototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||
|
|
|
@ -36,8 +36,8 @@ void DateTimeFormatFunction::initialize(Realm& realm)
|
|||
|
||||
ThrowCompletionOr<Value> DateTimeFormatFunction::call()
|
||||
{
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = global_object.vm();
|
||||
auto& vm = this->vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
auto date = vm.argument(0);
|
||||
|
||||
|
@ -49,7 +49,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
|
|||
// 3. If date is not provided or is undefined, then
|
||||
if (date.is_undefined()) {
|
||||
// a. Let x be ! Call(%Date.now%, undefined).
|
||||
date_value = MUST(JS::call(vm, global_object.date_constructor_now_function(), js_undefined())).as_double();
|
||||
date_value = MUST(JS::call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double();
|
||||
}
|
||||
// 4. Else,
|
||||
else {
|
||||
|
|
|
@ -307,7 +307,6 @@ static String convert_number_format_pattern_to_duration_format_template(Unicode:
|
|||
ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM& vm, DurationFormat const& duration_format, Temporal::DurationRecord const& duration)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let result be a new empty List.
|
||||
Vector<PatternPartition> result;
|
||||
|
@ -403,7 +402,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
}
|
||||
|
||||
// o. Let nf be ? Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
|
||||
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
|
||||
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
|
||||
|
||||
// FIXME: durationFormat.[[NumberFormat]] is not a thing, the spec likely means 'nf' in this case
|
||||
// p. Let num be ! FormatNumeric(durationFormat.[[NumberFormat]], value).
|
||||
|
@ -432,7 +431,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
// t. Else,
|
||||
else {
|
||||
// i. Let pr be ? Construct(%PluralRules%, « durationFormat.[[Locale]] »).
|
||||
auto* plural_rules = TRY(construct(vm, *global_object.intl_plural_rules_constructor(), js_string(vm, duration_format.locale())));
|
||||
auto* plural_rules = TRY(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, duration_format.locale())));
|
||||
|
||||
// ii. Let prv be ! ResolvePlural(pr, value).
|
||||
auto plurality = resolve_plural(static_cast<PluralRules&>(*plural_rules), value);
|
||||
|
@ -480,7 +479,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
}
|
||||
|
||||
// 3. Let lf be ? Construct(%ListFormat%, « durationFormat.[[Locale]] »).
|
||||
auto* list_format = static_cast<Intl::ListFormat*>(TRY(construct(vm, *global_object.intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
|
||||
auto* list_format = static_cast<Intl::ListFormat*>(TRY(construct(vm, *realm.global_object().intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
|
||||
|
||||
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
|
||||
// so we try to hack something together from it that looks mostly right
|
||||
|
|
|
@ -204,7 +204,6 @@ String format_list(ListFormat const& list_format, Vector<String> const& list)
|
|||
Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String> const& list)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
|
||||
auto parts = create_parts_from_list(list_format, list);
|
||||
|
@ -218,7 +217,7 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String
|
|||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||
|
|
|
@ -908,7 +908,6 @@ String format_numeric(VM& vm, NumberFormat& number_format, MathematicalValue num
|
|||
Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, MathematicalValue number)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let parts be ? PartitionNumberPattern(numberFormat, x).
|
||||
// Note: Our implementation of PartitionNumberPattern does not throw.
|
||||
|
@ -923,7 +922,7 @@ Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, Mathematical
|
|||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||
|
@ -1825,7 +1824,6 @@ ThrowCompletionOr<String> format_numeric_range(VM& vm, NumberFormat& number_form
|
|||
ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& number_format, MathematicalValue start, MathematicalValue end)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let parts be ? PartitionNumberRangePattern(numberFormat, x, y).
|
||||
auto parts = TRY(partition_number_range_pattern(vm, number_format, move(start), move(end)));
|
||||
|
@ -1839,7 +1837,7 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
|
|||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||
|
|
|
@ -244,7 +244,6 @@ ThrowCompletionOr<String> format_relative_time(VM& vm, RelativeTimeFormat& relat
|
|||
ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeFormat& relative_time_format, double value, StringView unit)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit).
|
||||
auto parts = TRY(partition_relative_time_pattern(vm, relative_time_format, value, unit));
|
||||
|
@ -258,7 +257,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
|
|||
// 4. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
|
||||
|
|
|
@ -79,7 +79,6 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatConstructor::supported_locales_of)
|
|||
ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, RelativeTimeFormat& relative_time_format, Value locales_value, Value options_value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
|
||||
|
@ -139,11 +138,11 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
|
|||
relative_time_format.set_numeric(numeric.as_string().string());
|
||||
|
||||
// 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »).
|
||||
auto* number_format = MUST(construct(vm, *global_object.intl_number_format_constructor(), js_string(vm, locale)));
|
||||
auto* number_format = MUST(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale)));
|
||||
relative_time_format.set_number_format(static_cast<NumberFormat*>(number_format));
|
||||
|
||||
// 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
|
||||
auto* plural_rules = MUST(construct(vm, *global_object.intl_plural_rules_constructor(), js_string(vm, locale)));
|
||||
auto* plural_rules = MUST(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, locale)));
|
||||
relative_time_format.set_plural_rules(static_cast<PluralRules*>(plural_rules));
|
||||
|
||||
// 21. Return relativeTimeFormat.
|
||||
|
|
|
@ -48,7 +48,6 @@ StringView Segmenter::segmenter_granularity_string() const
|
|||
Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View const& string, double start_index, double end_index)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let len be the length of string.
|
||||
auto length = string.length_in_code_units();
|
||||
|
@ -63,7 +62,7 @@ Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View
|
|||
VERIFY(start_index < end_index);
|
||||
|
||||
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* result = Object::create(realm, global_object.object_prototype());
|
||||
auto* result = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// 6. Let segment be the substring of string from startIndex to endIndex.
|
||||
auto segment = string.substring_view(start_index, end_index - start_index);
|
||||
|
|
|
@ -187,10 +187,9 @@ Completion async_iterator_close(VM& vm, Iterator const& iterator_record, Complet
|
|||
Object* create_iterator_result_object(VM& vm, Value value, bool done)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let obj be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// 2. Perform ! CreateDataPropertyOrThrow(obj, "value", value).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, value));
|
||||
|
|
|
@ -46,7 +46,6 @@ void JSONObject::initialize(Realm& realm)
|
|||
ThrowCompletionOr<String> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
StringifyState state;
|
||||
|
||||
|
@ -102,7 +101,7 @@ ThrowCompletionOr<String> JSONObject::stringify_impl(VM& vm, Value value, Value
|
|||
state.gap = String::empty();
|
||||
}
|
||||
|
||||
auto* wrapper = Object::create(realm, global_object.object_prototype());
|
||||
auto* wrapper = Object::create(realm, realm.global_object().object_prototype());
|
||||
MUST(wrapper->create_data_property_or_throw(String::empty(), value));
|
||||
return serialize_json_property(vm, state, String::empty(), wrapper);
|
||||
}
|
||||
|
|
|
@ -369,9 +369,8 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
|
|||
// NOTE: This has been flattened for readability, so some `else` branches in the
|
||||
// spec text have been replaced with `continue`s in the loop below.
|
||||
|
||||
auto& global_object = this->global_object();
|
||||
auto& vm = this->vm();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let ownKeys be ? O.[[OwnPropertyKeys]]().
|
||||
auto own_keys = TRY(internal_own_property_keys());
|
||||
|
|
|
@ -67,14 +67,13 @@ ThrowCompletionOr<Value> ObjectConstructor::call()
|
|||
ThrowCompletionOr<Object*> ObjectConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
if (&new_target != this)
|
||||
return TRY(ordinary_create_from_constructor<Object>(vm, new_target, &GlobalObject::object_prototype));
|
||||
auto value = vm.argument(0);
|
||||
if (value.is_nullish())
|
||||
return Object::create(realm, global_object.object_prototype());
|
||||
return Object::create(realm, realm.global_object().object_prototype());
|
||||
return value.to_object(vm);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
|
|||
dbgln_if(PROMISE_DEBUG, "[Promise @ {} / create_resolving_functions()]", this);
|
||||
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. Let alreadyResolved be the Record { [[Value]]: false }.
|
||||
auto* already_resolved = vm.heap().allocate_without_realm<AlreadyResolved>();
|
||||
|
|
|
@ -68,8 +68,7 @@ PromiseAllResolveElementFunction::PromiseAllResolveElementFunction(size_t index,
|
|||
ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 8. Set values[index] to x.
|
||||
m_values.values()[m_index] = vm.argument(0);
|
||||
|
@ -101,11 +100,10 @@ PromiseAllSettledResolveElementFunction::PromiseAllSettledResolveElementFunction
|
|||
ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_element()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 9. Let obj be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled").
|
||||
MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "fulfilled"sv)));
|
||||
|
@ -143,11 +141,10 @@ PromiseAllSettledRejectElementFunction::PromiseAllSettledRejectElementFunction(s
|
|||
ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 9. Let obj be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(realm, global_object.object_prototype());
|
||||
auto* object = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected").
|
||||
MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "rejected"sv)));
|
||||
|
@ -185,8 +182,7 @@ PromiseAnyRejectElementFunction::PromiseAnyRejectElementFunction(size_t index, P
|
|||
ThrowCompletionOr<Value> PromiseAnyRejectElementFunction::resolve_element()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 8. Set errors[index] to x.
|
||||
m_values.values()[m_index] = vm.argument(0);
|
||||
|
|
|
@ -743,8 +743,7 @@ ThrowCompletionOr<MarkedVector<Value>> ProxyObject::internal_own_property_keys()
|
|||
ThrowCompletionOr<Value> ProxyObject::internal_call(Value this_argument, MarkedVector<Value> arguments_list)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// A Proxy exotic object only has a [[Call]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Call]] internal method.
|
||||
// TODO: We should be able to turn this into a VERIFY(), this must be checked at the call site.
|
||||
|
@ -792,8 +791,7 @@ bool ProxyObject::has_constructor() const
|
|||
ThrowCompletionOr<Object*> ProxyObject::internal_construct(MarkedVector<Value> arguments_list, FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// A Proxy exotic object only has a [[Construct]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Construct]] internal method.
|
||||
// TODO: We should be able to turn this into a VERIFY(), this must be checked at the call site.
|
||||
|
|
|
@ -86,7 +86,6 @@ Completion Reference::throw_reference_error(VM& vm) const
|
|||
ThrowCompletionOr<Value> Reference::get_value(VM& vm) const
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. ReturnIfAbrupt(V).
|
||||
// 2. If V is not a Reference Record, return V.
|
||||
|
@ -119,11 +118,11 @@ ThrowCompletionOr<Value> Reference::get_value(VM& vm) const
|
|||
auto string_value = m_base_value.as_string().get(vm, m_name);
|
||||
if (string_value.has_value())
|
||||
return *string_value;
|
||||
base_obj = global_object.string_prototype();
|
||||
base_obj = realm.global_object().string_prototype();
|
||||
} else if (m_base_value.is_number())
|
||||
base_obj = global_object.number_prototype();
|
||||
base_obj = realm.global_object().number_prototype();
|
||||
else if (m_base_value.is_boolean())
|
||||
base_obj = global_object.boolean_prototype();
|
||||
base_obj = realm.global_object().boolean_prototype();
|
||||
else
|
||||
base_obj = TRY(m_base_value.to_object(vm));
|
||||
|
||||
|
|
|
@ -53,8 +53,7 @@ ThrowCompletionOr<Value> StringConstructor::call()
|
|||
ThrowCompletionOr<Object*> StringConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
PrimitiveString* primitive_string;
|
||||
if (!vm.argument_count())
|
||||
|
|
|
@ -64,14 +64,13 @@ Span<StringView const> available_calendars()
|
|||
ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, String const& identifier, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: IsBuiltinCalendar(identifier) is true.
|
||||
VERIFY(is_builtin_calendar(identifier));
|
||||
|
||||
// 2. If newTarget is not provided, set newTarget to %Temporal.Calendar%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_calendar_constructor();
|
||||
new_target = realm.global_object().temporal_calendar_constructor();
|
||||
|
||||
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
|
||||
// 4. Set object.[[Identifier]] to identifier.
|
||||
|
@ -886,10 +885,9 @@ u8 iso_day(Object& temporal_object)
|
|||
ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& fields, Object const& additional_fields)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* merged = Object::create(realm, global_object.object_prototype());
|
||||
auto* merged = Object::create(realm, realm.global_object().object_prototype());
|
||||
|
||||
// 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key).
|
||||
auto fields_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key));
|
||||
|
|
|
@ -327,7 +327,6 @@ ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(VM&
|
|||
ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If ! IsValidDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds))
|
||||
|
@ -335,7 +334,7 @@ ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, doub
|
|||
|
||||
// 2. If newTarget is not present, set newTarget to %Temporal.Duration%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_duration_constructor();
|
||||
new_target = realm.global_object().temporal_duration_constructor();
|
||||
|
||||
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Duration.prototype%", « [[InitializedTemporalDuration]], [[Years]], [[Months]], [[Weeks]], [[Days]], [[Hours]], [[Minutes]], [[Seconds]], [[Milliseconds]], [[Microseconds]], [[Nanoseconds]] »).
|
||||
// 4. Set object.[[Years]] to ℝ(𝔽(years)).
|
||||
|
|
|
@ -53,7 +53,6 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds)
|
|||
ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_nanoseconds, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: Type(epochNanoseconds) is BigInt.
|
||||
|
||||
|
@ -62,7 +61,7 @@ ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_
|
|||
|
||||
// 3. If newTarget is not present, set newTarget to %Temporal.Instant%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_instant_constructor();
|
||||
new_target = realm.global_object().temporal_instant_constructor();
|
||||
|
||||
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »).
|
||||
// 5. Set object.[[Nanoseconds]] to epochNanoseconds.
|
||||
|
|
|
@ -51,7 +51,6 @@ ISODateRecord create_iso_date_record(i32 year, u8 month, u8 day)
|
|||
ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: isoYear is an integer.
|
||||
// 2. Assert: isoMonth is an integer.
|
||||
|
@ -68,7 +67,7 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_
|
|||
|
||||
// 7. If newTarget is not present, set newTarget to %Temporal.PlainDate%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_plain_date_constructor();
|
||||
new_target = realm.global_object().temporal_plain_date_constructor();
|
||||
|
||||
// 8. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »).
|
||||
// 9. Set object.[[ISOYear]] to isoYear.
|
||||
|
|
|
@ -228,7 +228,6 @@ ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute
|
|||
ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, and nanosecond are integers.
|
||||
// 2. Assert: Type(calendar) is Object.
|
||||
|
@ -249,7 +248,7 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
|
|||
|
||||
// 6. If newTarget is not present, set newTarget to %Temporal.PlainDateTime%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_plain_date_time_constructor();
|
||||
new_target = realm.global_object().temporal_plain_date_time_constructor();
|
||||
|
||||
// 7. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDateTime.prototype%", « [[InitializedTemporalDateTime]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
|
||||
// 8. Set object.[[ISOYear]] to isoYear.
|
||||
|
|
|
@ -145,7 +145,6 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(VM& vm, Value item, Obje
|
|||
ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month, u8 iso_day, Object& calendar, i32 reference_iso_year, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: isoMonth, isoDay, and referenceISOYear are integers.
|
||||
// 2. Assert: Type(calendar) is Object.
|
||||
|
@ -160,7 +159,7 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
|
|||
|
||||
// 5. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_plain_month_day_constructor();
|
||||
new_target = realm.global_object().temporal_plain_month_day_constructor();
|
||||
|
||||
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]], [[ISOMonth]], [[ISODay]], [[ISOYear]], [[Calendar]] »).
|
||||
// 7. Set object.[[ISOMonth]] to isoMonth.
|
||||
|
|
|
@ -311,7 +311,6 @@ TemporalTime constrain_time(double hour, double minute, double second, double mi
|
|||
ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: hour, minute, second, millisecond, microsecond and nanosecond are integers.
|
||||
|
||||
|
@ -321,7 +320,7 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u
|
|||
|
||||
// 3. If newTarget is not present, set newTarget to %Temporal.PlainTime%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_plain_time_constructor();
|
||||
new_target = realm.global_object().temporal_plain_time_constructor();
|
||||
|
||||
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
|
||||
// 5. Set object.[[ISOHour]] to hour.
|
||||
|
|
|
@ -186,7 +186,6 @@ ISOYearMonth balance_iso_year_month(double year, double month)
|
|||
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: isoYear, isoMonth, and referenceISODay are integers.
|
||||
// 2. Assert: Type(calendar) is Object.
|
||||
|
@ -201,7 +200,7 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye
|
|||
|
||||
// 5. If newTarget is not present, set newTarget to %Temporal.PlainYearMonth%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_plain_year_month_constructor();
|
||||
new_target = realm.global_object().temporal_plain_year_month_constructor();
|
||||
|
||||
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainYearMonth.prototype%", « [[InitializedTemporalYearMonth]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »).
|
||||
// 7. Set object.[[ISOYear]] to isoYear.
|
||||
|
|
|
@ -66,11 +66,10 @@ String default_time_zone()
|
|||
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, String const& identifier, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_time_zone_constructor();
|
||||
new_target = realm.global_object().temporal_time_zone_constructor();
|
||||
|
||||
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
|
||||
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(vm, *new_target, &GlobalObject::temporal_time_zone_prototype));
|
||||
|
|
|
@ -268,14 +268,13 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true.
|
||||
VERIFY(is_valid_epoch_nanoseconds(epoch_nanoseconds));
|
||||
|
||||
// 2. If newTarget is not present, set newTarget to %Temporal.ZonedDateTime%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_zoned_date_time_constructor();
|
||||
new_target = realm.global_object().temporal_zoned_date_time_constructor();
|
||||
|
||||
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.ZonedDateTime.prototype%", « [[InitializedTemporalZonedDateTime]], [[Nanoseconds]], [[TimeZone]], [[Calendar]] »).
|
||||
// 4. Set object.[[Nanoseconds]] to epochNanoseconds.
|
||||
|
|
|
@ -129,7 +129,6 @@ template<typename T>
|
|||
static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(VM& vm, TypedArray<T>& dest_array, TypedArrayBase& src_array)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let srcData be srcArray.[[ViewedArrayBuffer]].
|
||||
auto* src_data = src_array.viewed_array_buffer();
|
||||
|
@ -169,7 +168,7 @@ static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(VM& vm, T
|
|||
// 11. Else,
|
||||
else {
|
||||
// a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||
data = TRY(allocate_array_buffer(vm, *global_object.array_buffer_constructor(), byte_length.value()));
|
||||
data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length.value()));
|
||||
|
||||
// b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
|
||||
if (src_data->is_detached())
|
||||
|
@ -225,7 +224,6 @@ template<typename T>
|
|||
static ThrowCompletionOr<void> allocate_typed_array_buffer(VM& vm, TypedArray<T>& typed_array, size_t length)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// Enforce 2GB "Excessive Length" limit
|
||||
if (length > NumericLimits<i32>::max() / sizeof(T))
|
||||
|
@ -242,7 +240,7 @@ static ThrowCompletionOr<void> allocate_typed_array_buffer(VM& vm, TypedArray<T>
|
|||
auto byte_length = element_size * length;
|
||||
|
||||
// 4. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength).
|
||||
auto* data = TRY(allocate_array_buffer(vm, *global_object.array_buffer_constructor(), byte_length));
|
||||
auto* data = TRY(allocate_array_buffer(vm, *realm.global_object().array_buffer_constructor(), byte_length));
|
||||
|
||||
// 5. Set O.[[ViewedArrayBuffer]] to data.
|
||||
typed_array.set_viewed_array_buffer(data);
|
||||
|
@ -345,11 +343,10 @@ ThrowCompletionOr<TypedArrayBase*> typed_array_create(VM& vm, FunctionObject& co
|
|||
ThrowCompletionOr<TypedArrayBase*> typed_array_create_same_type(VM& vm, TypedArrayBase const& exemplar, MarkedVector<Value> arguments)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: exemplar is an Object that has [[TypedArrayName]] and [[ContentType]] internal slots.
|
||||
// 2. Let constructor be the intrinsic object listed in column one of Table 63 (points to Table 72) for exemplar.[[TypedArrayName]].
|
||||
auto* constructor = (global_object.*exemplar.intrinsic_constructor())();
|
||||
auto* constructor = (realm.global_object().*exemplar.intrinsic_constructor())();
|
||||
|
||||
// 3. Let result be ? TypedArrayCreate(constructor, argumentList).
|
||||
auto* result = TRY(typed_array_create(vm, *constructor, move(arguments)));
|
||||
|
@ -514,8 +511,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
|
|||
ThrowCompletionOr<Object*> ConstructorName::construct(FunctionObject& new_target) \
|
||||
{ \
|
||||
auto& vm = this->vm(); \
|
||||
auto& global_object = this->global_object(); \
|
||||
auto& realm = *global_object.associated_realm(); \
|
||||
auto& realm = *vm.current_realm(); \
|
||||
\
|
||||
if (vm.argument_count() == 0) \
|
||||
return TRY(ClassName::create(realm, 0, new_target)); \
|
||||
|
|
|
@ -144,10 +144,9 @@ static ThrowCompletionOr<void> for_each_item_from_last(VM& vm, String const& nam
|
|||
static ThrowCompletionOr<TypedArrayBase*> typed_array_species_create(VM& vm, TypedArrayBase const& exemplar, MarkedVector<Value> arguments)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let defaultConstructor be the intrinsic object listed in column one of Table 72 for exemplar.[[TypedArrayName]].
|
||||
auto* default_constructor = (global_object.*exemplar.intrinsic_constructor())();
|
||||
auto* default_constructor = (realm.global_object().*exemplar.intrinsic_constructor())();
|
||||
|
||||
// 2. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
|
||||
auto* constructor = TRY(species_constructor(vm, exemplar, *default_constructor));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue