mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
LibJS: Convert get_this_environment() to NonnullGCPtr
This commit is contained in:
parent
c132064ee9
commit
e785c66f91
Notes:
sideshowbarker
2024-07-17 04:09:56 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/e785c66f91 Pull-request: https://github.com/SerenityOS/serenity/pull/16521
@ -513,7 +513,7 @@ Completion SuperCall::execute(Interpreter& interpreter) const
|
||||
auto result = TRY(construct(vm, static_cast<FunctionObject&>(*func), move(arg_list), &new_target.as_function()));
|
||||
|
||||
// 7. Let thisER be GetThisEnvironment().
|
||||
auto& this_er = verify_cast<FunctionEnvironment>(get_this_environment(vm));
|
||||
auto& this_er = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
|
||||
|
||||
// 8. Perform ? thisER.BindThisValue(result).
|
||||
TRY(this_er.bind_this_value(vm, result));
|
||||
@ -1430,10 +1430,10 @@ ThrowCompletionOr<Reference> MemberExpression::to_reference(Interpreter& interpr
|
||||
// https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
|
||||
if (is<SuperExpression>(object())) {
|
||||
// 1. Let env be GetThisEnvironment().
|
||||
auto& environment = get_this_environment(vm);
|
||||
auto environment = get_this_environment(vm);
|
||||
|
||||
// 2. Let actualThis be ? env.GetThisBinding().
|
||||
auto actual_this = TRY(environment.get_this_binding(vm));
|
||||
auto actual_this = TRY(environment->get_this_binding(vm));
|
||||
|
||||
PropertyKey property_key;
|
||||
|
||||
|
@ -682,7 +682,7 @@ ThrowCompletionOr<void> SuperCall::execute_impl(Bytecode::Interpreter& interpret
|
||||
auto result = TRY(construct(vm, static_cast<FunctionObject&>(*func), move(arg_list), &new_target.as_function()));
|
||||
|
||||
// 7. Let thisER be GetThisEnvironment().
|
||||
auto& this_environment = verify_cast<FunctionEnvironment>(get_this_environment(vm));
|
||||
auto& this_environment = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
|
||||
|
||||
// 8. Perform ? thisER.BindThisValue(result).
|
||||
TRY(this_environment.bind_this_value(vm, result));
|
||||
|
@ -443,7 +443,7 @@ NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironm
|
||||
}
|
||||
|
||||
// 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment
|
||||
Environment& get_this_environment(VM& vm)
|
||||
NonnullGCPtr<Environment> get_this_environment(VM& vm)
|
||||
{
|
||||
// 1. Let env be the running execution context's LexicalEnvironment.
|
||||
// 2. Repeat,
|
||||
@ -483,12 +483,12 @@ bool can_be_held_weakly(Value value)
|
||||
Object* get_super_constructor(VM& vm)
|
||||
{
|
||||
// 1. Let envRec be GetThisEnvironment().
|
||||
auto& env = get_this_environment(vm);
|
||||
auto env = get_this_environment(vm);
|
||||
|
||||
// 2. Assert: envRec is a function Environment Record.
|
||||
// 3. Let activeFunction be envRec.[[FunctionObject]].
|
||||
// 4. Assert: activeFunction is an ECMAScript function object.
|
||||
auto& active_function = verify_cast<FunctionEnvironment>(env).function_object();
|
||||
auto& active_function = verify_cast<FunctionEnvironment>(*env).function_object();
|
||||
|
||||
// 5. Let superConstructor be ! activeFunction.[[GetPrototypeOf]]().
|
||||
auto* super_constructor = MUST(active_function.internal_get_prototype_of());
|
||||
@ -501,7 +501,7 @@ Object* get_super_constructor(VM& vm)
|
||||
ThrowCompletionOr<Reference> make_super_property_reference(VM& vm, Value actual_this, PropertyKey const& property_key, bool strict)
|
||||
{
|
||||
// 1. Let env be GetThisEnvironment().
|
||||
auto& env = verify_cast<FunctionEnvironment>(get_this_environment(vm));
|
||||
auto& env = verify_cast<FunctionEnvironment>(*get_this_environment(vm));
|
||||
|
||||
// 2. Assert: env.HasSuperBinding() is true.
|
||||
VERIFY(env.has_super_binding());
|
||||
@ -548,11 +548,11 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
|
||||
// 10. If direct is true, then
|
||||
if (direct == EvalMode::Direct) {
|
||||
// a. Let thisEnvRec be GetThisEnvironment().
|
||||
auto& this_environment_record = get_this_environment(vm);
|
||||
auto this_environment_record = get_this_environment(vm);
|
||||
|
||||
// b. If thisEnvRec is a function Environment Record, then
|
||||
if (is<FunctionEnvironment>(this_environment_record)) {
|
||||
auto& this_function_environment_record = static_cast<FunctionEnvironment&>(this_environment_record);
|
||||
if (is<FunctionEnvironment>(*this_environment_record)) {
|
||||
auto& this_function_environment_record = static_cast<FunctionEnvironment&>(*this_environment_record);
|
||||
|
||||
// i. Let F be thisEnvRec.[[FunctionObject]].
|
||||
auto& function = this_function_environment_record.function_object();
|
||||
|
@ -23,7 +23,7 @@ NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment&);
|
||||
NonnullGCPtr<ObjectEnvironment> new_object_environment(Object&, bool is_with_environment, Environment*);
|
||||
NonnullGCPtr<FunctionEnvironment> new_function_environment(ECMAScriptFunctionObject&, Object* new_target);
|
||||
NonnullGCPtr<PrivateEnvironment> new_private_environment(VM& vm, PrivateEnvironment* outer);
|
||||
Environment& get_this_environment(VM&);
|
||||
NonnullGCPtr<Environment> get_this_environment(VM&);
|
||||
bool can_be_held_weakly(Value);
|
||||
Object* get_super_constructor(VM&);
|
||||
ThrowCompletionOr<Reference> make_super_property_reference(VM&, Value actual_this, PropertyKey const&, bool strict);
|
||||
|
@ -603,21 +603,21 @@ ThrowCompletionOr<Value> VM::resolve_this_binding()
|
||||
auto& vm = *this;
|
||||
|
||||
// 1. Let envRec be GetThisEnvironment().
|
||||
auto& environment = get_this_environment(vm);
|
||||
auto environment = get_this_environment(vm);
|
||||
|
||||
// 2. Return ? envRec.GetThisBinding().
|
||||
return TRY(environment.get_this_binding(vm));
|
||||
return TRY(environment->get_this_binding(vm));
|
||||
}
|
||||
|
||||
// 9.4.5 GetNewTarget ( ), https://tc39.es/ecma262/#sec-getnewtarget
|
||||
Value VM::get_new_target()
|
||||
{
|
||||
// 1. Let envRec be GetThisEnvironment().
|
||||
auto& env = get_this_environment(*this);
|
||||
auto env = get_this_environment(*this);
|
||||
|
||||
// 2. Assert: envRec has a [[NewTarget]] field.
|
||||
// 3. Return envRec.[[NewTarget]].
|
||||
return verify_cast<FunctionEnvironment>(env).new_target();
|
||||
return verify_cast<FunctionEnvironment>(*env).new_target();
|
||||
}
|
||||
|
||||
// 9.4.5 GetGlobalObject ( ), https://tc39.es/ecma262/#sec-getglobalobject
|
||||
|
Loading…
Reference in New Issue
Block a user