mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
LibJS: Replace GlobalObject with VM in Reference AOs [Part 6/19]
This commit is contained in:
parent
275a7a0c0a
commit
ae9e031f56
10 changed files with 88 additions and 77 deletions
|
@ -229,7 +229,7 @@ ThrowCompletionOr<void> initialize_bound_name(GlobalObject& global_object, FlySt
|
|||
auto lhs = TRY(vm.resolve_binding(name));
|
||||
|
||||
// b. Return ? PutValue(lhs, value).
|
||||
return TRY(lhs.put_value(global_object, value));
|
||||
return TRY(lhs.put_value(vm, value));
|
||||
}
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
|
@ -463,9 +463,9 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
|||
Reference reference = TRY(vm.resolve_binding(param, used_environment));
|
||||
// Here the difference from hasDuplicates is important
|
||||
if (has_duplicates)
|
||||
return reference.put_value(global_object, argument_value);
|
||||
return reference.put_value(vm, argument_value);
|
||||
else
|
||||
return reference.initialize_referenced_binding(global_object, argument_value);
|
||||
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);
|
||||
|
|
|
@ -13,10 +13,8 @@
|
|||
namespace JS {
|
||||
|
||||
// 6.2.4.6 PutValue ( V, W ), https://tc39.es/ecma262/#sec-putvalue
|
||||
ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value value)
|
||||
ThrowCompletionOr<void> Reference::put_value(VM& vm, Value value)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. ReturnIfAbrupt(V).
|
||||
// 2. ReturnIfAbrupt(W).
|
||||
|
||||
|
@ -28,9 +26,11 @@ ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value
|
|||
if (is_unresolvable()) {
|
||||
// a. If V.[[Strict]] is true, throw a ReferenceError exception.
|
||||
if (m_strict)
|
||||
return throw_reference_error(global_object);
|
||||
return throw_reference_error(vm);
|
||||
|
||||
// b. Let globalObj be GetGlobalObject().
|
||||
auto& global_object = vm.get_global_object();
|
||||
|
||||
// c. Perform ? Set(globalObj, V.[[ReferencedName]], W, false).
|
||||
TRY(global_object.set(m_name, value, Object::ShouldThrowExceptions::No));
|
||||
|
||||
|
@ -74,9 +74,8 @@ ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value
|
|||
return m_base_environment->set_mutable_binding(vm, m_name.as_string(), value, m_strict);
|
||||
}
|
||||
|
||||
Completion Reference::throw_reference_error(GlobalObject& global_object) const
|
||||
Completion Reference::throw_reference_error(VM& vm) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
if (!m_name.is_valid())
|
||||
return vm.throw_completion<ReferenceError>(ErrorType::ReferenceUnresolvable);
|
||||
else
|
||||
|
@ -84,16 +83,17 @@ Completion Reference::throw_reference_error(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 6.2.4.5 GetValue ( V ), https://tc39.es/ecma262/#sec-getvalue
|
||||
ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<Value> Reference::get_value(VM& vm) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. ReturnIfAbrupt(V).
|
||||
// 2. If V is not a Reference Record, return V.
|
||||
|
||||
// 3. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
if (!is_valid_reference() || is_unresolvable())
|
||||
return throw_reference_error(global_object);
|
||||
return throw_reference_error(vm);
|
||||
|
||||
// 4. If IsPropertyReference(V) is true, then
|
||||
if (is_property_reference()) {
|
||||
|
@ -145,7 +145,7 @@ ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
|
|||
}
|
||||
|
||||
// 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation
|
||||
ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
|
||||
ThrowCompletionOr<bool> Reference::delete_(VM& vm)
|
||||
{
|
||||
// 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation
|
||||
// UnaryExpression : delete UnaryExpression
|
||||
|
@ -163,8 +163,6 @@ ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
|
|||
return true;
|
||||
}
|
||||
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 5. If IsPropertyReference(ref) is true, then
|
||||
if (is_property_reference()) {
|
||||
// a. Assert: IsPrivateReference(ref) is false.
|
||||
|
@ -235,10 +233,8 @@ String Reference::to_string() const
|
|||
}
|
||||
|
||||
// 6.2.4.8 InitializeReferencedBinding ( V, W ), https://tc39.es/ecma262/#sec-object.prototype.hasownproperty
|
||||
ThrowCompletionOr<void> Reference::initialize_referenced_binding(GlobalObject& global_object, Value value) const
|
||||
ThrowCompletionOr<void> Reference::initialize_referenced_binding(VM& vm, Value value) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
VERIFY(!is_unresolvable());
|
||||
VERIFY(m_base_type == BaseType::Environment);
|
||||
return m_base_environment->initialize_binding(vm, m_name.as_string(), value);
|
||||
|
|
|
@ -121,11 +121,11 @@ public:
|
|||
return m_base_type == BaseType::Environment;
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> initialize_referenced_binding(GlobalObject& global_object, Value value) const;
|
||||
ThrowCompletionOr<void> initialize_referenced_binding(VM&, Value value) const;
|
||||
|
||||
ThrowCompletionOr<void> put_value(GlobalObject&, Value);
|
||||
ThrowCompletionOr<Value> get_value(GlobalObject&) const;
|
||||
ThrowCompletionOr<bool> delete_(GlobalObject&);
|
||||
ThrowCompletionOr<void> put_value(VM&, Value);
|
||||
ThrowCompletionOr<Value> get_value(VM&) const;
|
||||
ThrowCompletionOr<bool> delete_(VM&);
|
||||
|
||||
String to_string() const;
|
||||
|
||||
|
@ -134,7 +134,7 @@ public:
|
|||
Optional<EnvironmentCoordinate> environment_coordinate() const { return m_environment_coordinate; }
|
||||
|
||||
private:
|
||||
Completion throw_reference_error(GlobalObject&) const;
|
||||
Completion throw_reference_error(VM&) const;
|
||||
|
||||
BaseType m_base_type { BaseType::Unresolvable };
|
||||
union {
|
||||
|
|
|
@ -338,9 +338,9 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
|
||||
TRY(rest_object->copy_data_properties(vm, object, seen_names));
|
||||
if (!environment)
|
||||
return assignment_target.put_value(global_object, rest_object);
|
||||
return assignment_target.put_value(vm, rest_object);
|
||||
else
|
||||
return assignment_target.initialize_referenced_binding(global_object, rest_object);
|
||||
return assignment_target.initialize_referenced_binding(vm, rest_object);
|
||||
}
|
||||
|
||||
auto name = TRY(property.name.visit(
|
||||
|
@ -366,9 +366,9 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
}
|
||||
|
||||
if (!environment)
|
||||
TRY(reference.put_value(global_object, value_to_assign));
|
||||
TRY(reference.put_value(vm, value_to_assign));
|
||||
else
|
||||
TRY(reference.initialize_referenced_binding(global_object, value_to_assign));
|
||||
TRY(reference.initialize_referenced_binding(vm, value_to_assign));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -395,9 +395,9 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
} else {
|
||||
VERIFY(reference_to_assign_to.has_value());
|
||||
if (!environment)
|
||||
TRY(reference_to_assign_to->put_value(global_object, value_to_assign));
|
||||
TRY(reference_to_assign_to->put_value(vm, value_to_assign));
|
||||
else
|
||||
TRY(reference_to_assign_to->initialize_referenced_binding(global_object, value_to_assign));
|
||||
TRY(reference_to_assign_to->initialize_referenced_binding(vm, value_to_assign));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,6 +408,7 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
// 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)
|
||||
{
|
||||
auto& vm = *this;
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// FIXME: this method is nearly identical to destructuring assignment!
|
||||
|
@ -531,9 +532,9 @@ ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const
|
|||
} else if (!entry.alias.has<Empty>()) {
|
||||
VERIFY(assignment_target.has_value());
|
||||
if (!environment)
|
||||
TRY(assignment_target->put_value(global_object, value));
|
||||
TRY(assignment_target->put_value(vm, value));
|
||||
else
|
||||
TRY(assignment_target->initialize_referenced_binding(global_object, value));
|
||||
TRY(assignment_target->initialize_referenced_binding(vm, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -639,6 +640,16 @@ Value VM::get_new_target()
|
|||
return verify_cast<FunctionEnvironment>(env).new_target();
|
||||
}
|
||||
|
||||
// 9.4.5 GetGlobalObject ( ), https://tc39.es/ecma262/#sec-getglobalobject
|
||||
GlobalObject& VM::get_global_object()
|
||||
{
|
||||
// 1. Let currentRealm be the current Realm Record.
|
||||
auto& current_realm = *this->current_realm();
|
||||
|
||||
// 2. Return currentRealm.[[GlobalObject]].
|
||||
return current_realm.global_object();
|
||||
}
|
||||
|
||||
bool VM::in_strict_mode() const
|
||||
{
|
||||
if (execution_context_stack().is_empty())
|
||||
|
|
|
@ -183,6 +183,8 @@ public:
|
|||
|
||||
Value get_new_target();
|
||||
|
||||
GlobalObject& get_global_object();
|
||||
|
||||
CommonPropertyNames names;
|
||||
|
||||
void run_queued_promise_jobs();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue