diff options
author | Linus Groh <mail@linusgroh.de> | 2022-12-15 19:59:47 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-16 09:59:56 +0100 |
commit | 107e06a396e6c42b1dce4bf032ae356941ac4a48 (patch) | |
tree | 7d3d7cff0f45bba476f19316a65bedd2c696d11e /Userland/Libraries | |
parent | 4c732abed52535071d9b47d0e70dcda63fe28e42 (diff) | |
download | serenity-107e06a396e6c42b1dce4bf032ae356941ac4a48.zip |
LibJS: Convert new_declarative_environment() to NonnullGCPtr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/AbstractOperations.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp | 2 |
6 files changed, 16 insertions, 16 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 96048aade4..f783b1e5ae 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -242,7 +242,7 @@ Completion BlockStatement::execute(Interpreter& interpreter) const // Optimization: We only need a new lexical environment if there are any lexical declarations. :^) if (has_lexical_declarations()) { old_environment = vm.running_execution_context().lexical_environment; - auto* block_environment = new_declarative_environment(*old_environment); + auto block_environment = new_declarative_environment(*old_environment); block_declaration_instantiation(interpreter, block_environment); vm.running_execution_context().lexical_environment = block_environment; } else { @@ -308,7 +308,7 @@ Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& auto has_own_name = !name().is_empty(); auto const& used_name = has_own_name ? name() : given_name; - auto* environment = interpreter.lexical_environment(); + auto environment = NonnullGCPtr { *interpreter.lexical_environment() }; if (has_own_name) { VERIFY(environment); environment = new_declarative_environment(*environment); @@ -768,7 +768,7 @@ Completion ForStatement::loop_evaluation(Interpreter& interpreter, Vector<FlyStr if (m_init) { if (is<VariableDeclaration>(*m_init) && static_cast<VariableDeclaration const&>(*m_init).declaration_kind() != DeclarationKind::Var) { - auto* loop_environment = new_declarative_environment(*old_environment); + auto loop_environment = new_declarative_environment(*old_environment); auto& declaration = static_cast<VariableDeclaration const&>(*m_init); declaration.for_each_bound_name([&](auto const& name) { if (declaration.declaration_kind() == DeclarationKind::Const) { @@ -900,7 +900,7 @@ struct ForInOfHeadState { auto& vm = interpreter.vm(); Optional<Reference> lhs_reference; - Environment* iteration_environment = nullptr; + GCPtr<Environment> iteration_environment; // g. If lhsKind is either assignment or varBinding, then if (lhs_kind == Assignment || lhs_kind == VarBinding) { @@ -1841,7 +1841,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::class_definition_e auto* environment = vm.lexical_environment(); VERIFY(environment); - auto* class_environment = new_declarative_environment(*environment); + auto class_environment = new_declarative_environment(*environment); // We might not set the lexical environment but we always want to restore it eventually. ArmedScopeGuard restore_environment = [&] { @@ -3842,7 +3842,7 @@ Completion TryStatement::execute(Interpreter& interpreter) const auto* old_environment = vm.running_execution_context().lexical_environment; // 2. Let catchEnv be NewDeclarativeEnvironment(oldEnv). - auto* catch_environment = new_declarative_environment(*old_environment); + auto catch_environment = new_declarative_environment(*old_environment); m_handler->parameter().visit( [&](FlyString const& parameter) { @@ -4160,7 +4160,7 @@ Completion SwitchStatement::execute_impl(Interpreter& interpreter) const // Optimization: Avoid creating a lexical environment if there are no lexical declarations. if (has_lexical_declarations()) { // 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). - auto* block_environment = new_declarative_environment(*old_environment); + auto block_environment = new_declarative_environment(*old_environment); // 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). block_declaration_instantiation(interpreter, block_environment); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index ea3f6673cb..3ba225cad4 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -414,7 +414,7 @@ ThrowCompletionOr<void> DeleteVariable::execute_impl(Bytecode::Interpreter& inte ThrowCompletionOr<void> CreateEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const { auto make_and_swap_envs = [&](auto*& old_environment) { - Environment* environment = new_declarative_environment(*old_environment); + Environment* environment = new_declarative_environment(*old_environment).ptr(); swap(old_environment, environment); return environment; }; diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index b57869c9f9..072727c739 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -383,7 +383,7 @@ ThrowCompletionOr<Object*> get_prototype_from_constructor(VM& vm, FunctionObject } // 9.1.2.2 NewDeclarativeEnvironment ( E ), https://tc39.es/ecma262/#sec-newdeclarativeenvironment -DeclarativeEnvironment* new_declarative_environment(Environment& environment) +NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment& environment) { auto& heap = environment.heap(); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 29e638818c..b9bc01661a 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -19,7 +19,7 @@ namespace JS { -DeclarativeEnvironment* new_declarative_environment(Environment&); +NonnullGCPtr<DeclarativeEnvironment> new_declarative_environment(Environment&); ObjectEnvironment* new_object_environment(Object&, bool is_with_environment, Environment*); FunctionEnvironment* new_function_environment(ECMAScriptFunctionObject&, Object* new_target); PrivateEnvironment* new_private_environment(VM& vm, PrivateEnvironment* outer); diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 413f40bd25..9f1a7089bc 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -391,7 +391,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia arguments_object_needed = false; } - Environment* environment; + GCPtr<Environment> environment; if (is_strict_mode() || !has_parameter_expressions) { environment = callee_context.lexical_environment; @@ -477,7 +477,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia })); } - Environment* var_environment; + GCPtr<Environment> var_environment; HashTable<FlyString> instantiated_var_names; if (scope_body) @@ -531,7 +531,7 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia }); } - Environment* lex_environment; + GCPtr<Environment> lex_environment; // 30. If strict is false, then if (!is_strict_mode()) { @@ -578,9 +578,9 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia } if (is<DeclarativeEnvironment>(*lex_environment)) - static_cast<DeclarativeEnvironment*>(lex_environment)->shrink_to_fit(); + static_cast<DeclarativeEnvironment*>(lex_environment.ptr())->shrink_to_fit(); if (is<DeclarativeEnvironment>(*var_environment)) - static_cast<DeclarativeEnvironment*>(var_environment)->shrink_to_fit(); + static_cast<DeclarativeEnvironment*>(var_environment.ptr())->shrink_to_fit(); return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp index 05c9e0035e..55599256d4 100644 --- a/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp +++ b/Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp @@ -127,7 +127,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex // NOTE: This would be unused due to step 11 and is omitted for that reason. // 5. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]). - Environment* lexical_environment = new_declarative_environment(eval_realm.global_environment()); + Environment* lexical_environment = new_declarative_environment(eval_realm.global_environment()).ptr(); // 6. Let varEnv be evalRealm.[[GlobalEnv]]. Environment* variable_environment = &eval_realm.global_environment(); |