From 7c0c1c8f4969abeec1436346f29081b3afbcdeab Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sun, 26 Feb 2023 16:09:02 -0700 Subject: [PATCH] LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr --- .../BindingsGenerator/IDLGenerators.cpp | 4 +- Userland/Libraries/LibJS/AST.cpp | 32 ++-- Userland/Libraries/LibJS/AST.h | 2 +- .../Libraries/LibJS/Bytecode/Interpreter.cpp | 10 +- .../Libraries/LibJS/Bytecode/Interpreter.h | 6 +- Userland/Libraries/LibJS/Bytecode/Op.cpp | 4 +- Userland/Libraries/LibJS/Console.h | 2 +- .../LibJS/Contrib/Test262/$262Object.h | 4 +- .../LibJS/Contrib/Test262/GlobalObject.h | 2 +- Userland/Libraries/LibJS/CyclicModule.cpp | 9 +- Userland/Libraries/LibJS/CyclicModule.h | 22 +-- Userland/Libraries/LibJS/Heap/Handle.h | 2 +- Userland/Libraries/LibJS/Heap/Heap.h | 2 +- Userland/Libraries/LibJS/Heap/HeapBlock.h | 4 +- Userland/Libraries/LibJS/Module.h | 2 +- Userland/Libraries/LibJS/Print.cpp | 2 +- .../LibJS/Runtime/AbstractOperations.cpp | 4 +- Userland/Libraries/LibJS/Runtime/Accessor.h | 4 +- .../LibJS/Runtime/ArgumentsObject.cpp | 2 +- .../Libraries/LibJS/Runtime/ArgumentsObject.h | 4 +- .../AsyncFromSyncIteratorPrototype.cpp | 4 +- .../Libraries/LibJS/Runtime/BigIntObject.cpp | 2 +- .../Libraries/LibJS/Runtime/BigIntObject.h | 2 +- .../Libraries/LibJS/Runtime/BoundFunction.h | 6 +- Userland/Libraries/LibJS/Runtime/DataView.h | 2 +- .../Runtime/ECMAScriptFunctionObject.cpp | 24 +-- .../LibJS/Runtime/ECMAScriptFunctionObject.h | 8 +- .../Libraries/LibJS/Runtime/Environment.h | 2 +- Userland/Libraries/LibJS/Runtime/Error.cpp | 2 +- .../LibJS/Runtime/ExecutionContext.h | 14 +- .../LibJS/Runtime/FinalizationRegistry.h | 4 +- .../LibJS/Runtime/FunctionEnvironment.h | 2 +- .../Libraries/LibJS/Runtime/GeneratorObject.h | 2 +- .../LibJS/Runtime/GlobalEnvironment.h | 8 +- .../Libraries/LibJS/Runtime/Intl/Collator.h | 16 +- .../Runtime/Intl/CollatorCompareFunction.cpp | 2 +- .../Runtime/Intl/CollatorCompareFunction.h | 2 +- .../LibJS/Runtime/Intl/DateTimeFormat.h | 2 +- .../Runtime/Intl/DateTimeFormatFunction.cpp | 2 +- .../Runtime/Intl/DateTimeFormatFunction.h | 2 +- .../LibJS/Runtime/Intl/NumberFormat.h | 2 +- .../Runtime/Intl/NumberFormatFunction.cpp | 2 +- .../LibJS/Runtime/Intl/NumberFormatFunction.h | 2 +- .../LibJS/Runtime/Intl/RelativeTimeFormat.h | 4 +- .../LibJS/Runtime/Intl/SegmentIterator.cpp | 4 +- .../LibJS/Runtime/Intl/SegmentIterator.h | 4 +- .../Libraries/LibJS/Runtime/Intl/Segments.cpp | 2 +- .../Libraries/LibJS/Runtime/Intl/Segments.h | 4 +- .../Libraries/LibJS/Runtime/Intrinsics.cpp | 4 +- Userland/Libraries/LibJS/Runtime/Intrinsics.h | 70 ++++----- Userland/Libraries/LibJS/Runtime/Iterator.h | 6 +- .../LibJS/Runtime/IteratorOperations.cpp | 2 +- Userland/Libraries/LibJS/Runtime/JSONObject.h | 4 +- Userland/Libraries/LibJS/Runtime/Map.h | 20 +-- .../Libraries/LibJS/Runtime/MapIterator.cpp | 2 +- .../Libraries/LibJS/Runtime/MapIterator.h | 2 +- .../LibJS/Runtime/ModuleEnvironment.h | 2 +- .../LibJS/Runtime/ModuleNamespaceObject.cpp | 2 +- .../LibJS/Runtime/ModuleNamespaceObject.h | 2 +- .../LibJS/Runtime/NativeFunction.cpp | 4 +- .../Libraries/LibJS/Runtime/NativeFunction.h | 2 +- Userland/Libraries/LibJS/Runtime/Object.cpp | 6 +- Userland/Libraries/LibJS/Runtime/Object.h | 2 +- .../LibJS/Runtime/ObjectEnvironment.cpp | 24 +-- .../LibJS/Runtime/ObjectEnvironment.h | 4 +- .../Libraries/LibJS/Runtime/PrimitiveString.h | 4 +- .../LibJS/Runtime/PrivateEnvironment.h | 4 +- Userland/Libraries/LibJS/Runtime/Promise.cpp | 8 +- Userland/Libraries/LibJS/Runtime/Promise.h | 14 +- .../LibJS/Runtime/PromiseConstructor.cpp | 4 +- .../Libraries/LibJS/Runtime/PromiseJobs.cpp | 6 +- .../Libraries/LibJS/Runtime/PromiseJobs.h | 2 +- .../PromiseResolvingElementFunctions.cpp | 28 ++-- .../PromiseResolvingElementFunctions.h | 4 +- .../Runtime/PromiseResolvingFunction.cpp | 4 +- .../LibJS/Runtime/PromiseResolvingFunction.h | 4 +- .../LibJS/Runtime/PropertyDescriptor.h | 8 +- .../Libraries/LibJS/Runtime/ProxyObject.cpp | 126 ++++++++-------- .../Libraries/LibJS/Runtime/ProxyObject.h | 6 +- Userland/Libraries/LibJS/Runtime/Realm.h | 8 +- .../Libraries/LibJS/Runtime/Reference.cpp | 2 +- .../LibJS/Runtime/RegExpStringIterator.cpp | 2 +- .../LibJS/Runtime/RegExpStringIterator.h | 2 +- .../Libraries/LibJS/Runtime/SetIterator.cpp | 2 +- .../Libraries/LibJS/Runtime/SetIterator.h | 2 +- .../Libraries/LibJS/Runtime/ShadowRealm.cpp | 4 +- .../Libraries/LibJS/Runtime/ShadowRealm.h | 2 +- Userland/Libraries/LibJS/Runtime/Shape.cpp | 6 +- Userland/Libraries/LibJS/Runtime/Shape.h | 8 +- .../Libraries/LibJS/Runtime/StringObject.cpp | 6 +- .../Libraries/LibJS/Runtime/StringObject.h | 2 +- .../Libraries/LibJS/Runtime/SymbolObject.cpp | 2 +- .../Libraries/LibJS/Runtime/SymbolObject.h | 2 +- .../Runtime/Temporal/AbstractOperations.h | 2 +- .../LibJS/Runtime/Temporal/Instant.cpp | 2 +- .../LibJS/Runtime/Temporal/Instant.h | 2 +- .../LibJS/Runtime/Temporal/PlainDate.cpp | 2 +- .../LibJS/Runtime/Temporal/PlainDate.h | 8 +- .../LibJS/Runtime/Temporal/PlainDateTime.cpp | 2 +- .../LibJS/Runtime/Temporal/PlainDateTime.h | 20 +-- .../LibJS/Runtime/Temporal/PlainMonthDay.cpp | 2 +- .../LibJS/Runtime/Temporal/PlainMonthDay.h | 8 +- .../LibJS/Runtime/Temporal/PlainTime.cpp | 2 +- .../LibJS/Runtime/Temporal/PlainTime.h | 14 +- .../LibJS/Runtime/Temporal/PlainYearMonth.cpp | 2 +- .../LibJS/Runtime/Temporal/PlainYearMonth.h | 8 +- .../LibJS/Runtime/Temporal/ZonedDateTime.cpp | 6 +- .../LibJS/Runtime/Temporal/ZonedDateTime.h | 6 +- Userland/Libraries/LibJS/Runtime/TypedArray.h | 2 +- Userland/Libraries/LibJS/Runtime/VM.cpp | 8 +- Userland/Libraries/LibJS/Runtime/VM.h | 16 +- Userland/Libraries/LibJS/Runtime/WeakMap.h | 6 +- Userland/Libraries/LibJS/Runtime/WeakRef.h | 2 +- .../LibJS/Runtime/WeakRefPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakSet.h | 6 +- .../LibJS/Runtime/WrappedFunction.cpp | 4 +- .../Libraries/LibJS/Runtime/WrappedFunction.h | 8 +- Userland/Libraries/LibJS/SourceTextModule.cpp | 4 +- .../LibWeb/Bindings/MainThreadVM.cpp | 8 +- .../Libraries/LibWeb/Bindings/MainThreadVM.h | 2 +- .../Libraries/LibWeb/CSS/CSSGroupingRule.cpp | 18 +-- .../Libraries/LibWeb/CSS/CSSGroupingRule.h | 4 +- .../Libraries/LibWeb/CSS/CSSMediaRule.cpp | 6 +- Userland/Libraries/LibWeb/CSS/CSSMediaRule.h | 8 +- Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp | 20 +-- Userland/Libraries/LibWeb/CSS/CSSRuleList.h | 17 +-- .../Libraries/LibWeb/CSS/CSSStyleRule.cpp | 4 +- Userland/Libraries/LibWeb/CSS/CSSStyleRule.h | 2 +- .../Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 8 +- Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h | 4 +- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 4 +- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 12 +- Userland/Libraries/LibWeb/CSS/StyleComputer.h | 4 +- Userland/Libraries/LibWeb/CSS/StyleSheet.h | 6 +- .../Libraries/LibWeb/CSS/StyleSheetList.cpp | 10 +- .../Libraries/LibWeb/CSS/StyleSheetList.h | 2 +- .../LibWeb/DOM/AccessibilityTreeNode.cpp | 2 +- .../LibWeb/DOM/AccessibilityTreeNode.h | 4 +- .../Libraries/LibWeb/DOM/DOMImplementation.h | 2 +- Userland/Libraries/LibWeb/DOM/Document.h | 2 +- .../Libraries/LibWeb/DOM/EventDispatcher.cpp | 2 +- Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 8 +- .../Libraries/LibWeb/DOM/MutationObserver.cpp | 6 +- Userland/Libraries/LibWeb/DOM/Node.cpp | 8 +- Userland/Libraries/LibWeb/DOM/Node.h | 2 +- Userland/Libraries/LibWeb/DOM/NodeFilter.cpp | 2 +- Userland/Libraries/LibWeb/DOM/NodeFilter.h | 2 +- .../Libraries/LibWeb/DOM/StaticNodeList.cpp | 2 +- .../Libraries/LibWeb/DOM/StaticNodeList.h | 2 +- .../LibWeb/Fetch/Fetching/Fetching.cpp | 6 +- .../LibWeb/Fetch/HeadersIterator.cpp | 4 +- .../Libraries/LibWeb/Fetch/HeadersIterator.h | 2 +- .../Fetch/Infrastructure/HTTP/Requests.h | 10 +- Userland/Libraries/LibWeb/Fetch/Request.cpp | 4 +- .../LibWeb/HTML/BrowsingContextGroup.h | 2 +- .../LibWeb/HTML/Canvas/CanvasPath.cpp | 6 +- .../Libraries/LibWeb/HTML/Canvas/CanvasPath.h | 2 +- .../HTML/CrossOrigin/AbstractOperations.cpp | 4 +- .../Libraries/LibWeb/HTML/EventHandler.cpp | 2 +- Userland/Libraries/LibWeb/HTML/EventHandler.h | 4 +- .../LibWeb/HTML/EventLoop/EventLoop.cpp | 4 +- .../LibWeb/HTML/EventLoop/EventLoop.h | 4 +- .../LibWeb/HTML/Parser/HTMLTokenizer.h | 3 +- .../LibWeb/HTML/PromiseRejectionEvent.h | 2 +- .../LibWeb/HTML/Scripting/Environments.cpp | 2 +- .../LibWeb/HTML/Scripting/Environments.h | 2 +- .../LibWeb/HTML/Scripting/ModuleMap.h | 2 +- .../Libraries/LibWeb/HTML/Scripting/Script.h | 2 +- .../WindowEnvironmentSettingsObject.cpp | 2 +- .../WorkerEnvironmentSettingsObject.h | 2 +- .../Libraries/LibWeb/HTML/WorkerLocation.cpp | 18 +-- .../Libraries/LibWeb/HTML/WorkerLocation.h | 2 +- .../LibWeb/Layout/BlockFormattingContext.cpp | 2 +- .../LibWeb/Layout/BlockFormattingContext.h | 4 +- .../LibWeb/Layout/FlexFormattingContext.cpp | 130 ++++++++-------- .../LibWeb/Layout/FlexFormattingContext.h | 2 +- .../LibWeb/Layout/FormattingContext.cpp | 2 +- .../LibWeb/Layout/FormattingContext.h | 2 +- .../LibWeb/Layout/GridFormattingContext.cpp | 8 +- .../LibWeb/Layout/GridFormattingContext.h | 4 +- .../LibWeb/Layout/InlineLevelIterator.cpp | 8 +- .../LibWeb/Layout/InlineLevelIterator.h | 10 +- .../Libraries/LibWeb/Layout/LayoutState.h | 6 +- .../LibWeb/Layout/LineBoxFragment.cpp | 2 +- .../Libraries/LibWeb/Layout/LineBoxFragment.h | 3 +- .../LibWeb/Layout/TableFormattingContext.cpp | 26 ++-- .../LibWeb/Layout/TableFormattingContext.h | 4 +- .../Libraries/LibWeb/Layout/TreeBuilder.cpp | 8 +- .../Libraries/LibWeb/Layout/TreeBuilder.h | 2 +- .../Libraries/LibWeb/Loader/FrameLoader.cpp | 4 +- .../Libraries/LibWeb/Loader/FrameLoader.h | 2 +- .../Libraries/LibWeb/Loader/ImageLoader.cpp | 2 +- .../Libraries/LibWeb/Loader/ImageLoader.h | 2 +- .../LibWeb/Page/EditEventHandler.cpp | 12 +- .../Libraries/LibWeb/Page/EditEventHandler.h | 2 +- .../Libraries/LibWeb/Page/EventHandler.cpp | 142 +++++++++--------- Userland/Libraries/LibWeb/Page/EventHandler.h | 2 +- .../LibWeb/Painting/StackingContext.cpp | 42 +++--- .../LibWeb/Painting/StackingContext.h | 4 +- .../ReferrerPolicy/AbstractOperations.cpp | 4 +- .../LibWeb/URL/URLSearchParamsIterator.cpp | 6 +- .../LibWeb/URL/URLSearchParamsIterator.h | 2 +- .../WebAssembly/WebAssemblyInstanceObject.cpp | 6 +- .../WebAssembly/WebAssemblyInstanceObject.h | 2 +- .../LibWeb/WebAssembly/WebAssemblyObject.h | 8 +- .../LibWeb/WebDriver/ExecuteScript.cpp | 2 +- .../LibWeb/WebIDL/AbstractOperations.cpp | 10 +- .../LibWeb/WebIDL/AbstractOperations.h | 18 +-- .../Libraries/LibWeb/WebIDL/CallbackType.cpp | 2 +- .../Libraries/LibWeb/WebIDL/CallbackType.h | 4 +- .../Libraries/LibWeb/XHR/FormDataIterator.cpp | 6 +- .../Libraries/LibWeb/XHR/FormDataIterator.h | 2 +- .../LibWeb/XML/XMLDocumentBuilder.cpp | 36 ++--- .../Libraries/LibWeb/XML/XMLDocumentBuilder.h | 4 +- 214 files changed, 825 insertions(+), 827 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index decc4891d4..a776ff3c9b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1706,12 +1706,12 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString if (!@value@) { @result_expression@ JS::js_null(); } else { - @result_expression@ &@value@->callback; + @result_expression@ @value@->callback; } )~~~"); } else { scoped_generator.append(R"~~~( - @result_expression@ &@value@->callback; + @result_expression@ @value@->callback; )~~~"); } } else if (interface.dictionaries.contains(type.name())) { diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 641f0f8eaa..c17c92d077 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -273,10 +273,10 @@ Completion FunctionDeclaration::execute(Interpreter& interpreter) const // Perform special annexB steps see step 3 of: https://tc39.es/ecma262/#sec-web-compat-functiondeclarationinstantiation // i. Let genv be the running execution context's VariableEnvironment. - auto* variable_environment = interpreter.vm().running_execution_context().variable_environment; + auto variable_environment = interpreter.vm().running_execution_context().variable_environment; // ii. Let benv be the running execution context's LexicalEnvironment. - auto* lexical_environment = interpreter.vm().running_execution_context().lexical_environment; + auto lexical_environment = interpreter.vm().running_execution_context().lexical_environment; // iii. Let fobj be ! benv.GetBindingValue(F, false). auto function_object = MUST(lexical_environment->get_binding_value(vm, name(), false)); @@ -319,7 +319,7 @@ Value FunctionExpression::instantiate_ordinary_function_expression(Interpreter& MUST(environment->create_immutable_binding(vm, name(), false)); } - auto* private_environment = vm.running_execution_context().private_environment; + auto private_environment = vm.running_execution_context().private_environment; auto closure = ECMAScriptFunctionObject::create(realm, used_name, source_text(), body(), parameters(), function_length(), environment, private_environment, kind(), is_strict_mode(), might_need_arguments_object(), contains_direct_call_to_eval(), is_arrow_function()); @@ -622,7 +622,7 @@ Completion WithStatement::execute(Interpreter& interpreter) const auto* object = TRY(value.to_object(vm)); // 3. Let oldEnv be the running execution context's LexicalEnvironment. - auto* old_environment = vm.running_execution_context().lexical_environment; + auto old_environment = vm.running_execution_context().lexical_environment; // 4. Let newEnv be NewObjectEnvironment(obj, true, oldEnv). auto new_environment = new_object_environment(*object, true, old_environment); @@ -1096,7 +1096,7 @@ static ThrowCompletionOr for_in_of_head_execute(Interpreter& i if (new_environment) { // 2.d Set the running execution context's LexicalEnvironment to newEnv. - TemporaryChange scope_change(interpreter.vm().running_execution_context().lexical_environment, new_environment); + TemporaryChange> scope_change(interpreter.vm().running_execution_context().lexical_environment, new_environment); // 3. Let exprRef be the result of evaluating expr. // 5. Let exprValue be ? GetValue(exprRef). @@ -1177,9 +1177,9 @@ Completion ForInStatement::loop_evaluation(Interpreter& interpreter, Vector(vm.running_execution_context().lexical_environment)); + VERIFY(is(*vm.running_execution_context().lexical_environment)); // m. Set result to DisposeResources(iterationEnv, result). - result = dispose_resources(vm, static_cast(vm.running_execution_context().lexical_environment), result); + result = dispose_resources(vm, static_cast(vm.running_execution_context().lexical_environment.ptr()), result); } // n. Set the running execution context's LexicalEnvironment to oldEnv. @@ -1241,8 +1241,8 @@ Completion ForOfStatement::loop_evaluation(Interpreter& interpreter, Vectorexecute(interpreter); if (vm.running_execution_context().lexical_environment != old_environment) { - VERIFY(is(vm.running_execution_context().lexical_environment)); - result = dispose_resources(vm, static_cast(vm.running_execution_context().lexical_environment), result); + VERIFY(is(*vm.running_execution_context().lexical_environment)); + result = dispose_resources(vm, static_cast(vm.running_execution_context().lexical_environment.ptr()), result); } // m. Set the running execution context's LexicalEnvironment to oldEnv. @@ -1378,7 +1378,7 @@ Completion BinaryExpression::execute(Interpreter& interpreter) const auto rhs_result = TRY(m_rhs->execute(interpreter)).release_value(); if (!rhs_result.is_object()) return interpreter.vm().throw_completion(ErrorType::InOperatorWithObject); - auto* private_environment = interpreter.vm().running_execution_context().private_environment; + auto private_environment = interpreter.vm().running_execution_context().private_environment; VERIFY(private_environment); auto private_name = private_environment->resolve_private_identifier(private_identifier); return Value(rhs_result.as_object().private_element_find(private_name) != nullptr); @@ -1661,7 +1661,7 @@ static ThrowCompletionOr class_key_to_property_name(Interprete if (is(key)) { auto& private_identifier = static_cast(key); - auto* private_environment = interpreter.vm().running_execution_context().private_environment; + auto private_environment = interpreter.vm().running_execution_context().private_environment; VERIFY(private_environment); return ClassElementName { private_environment->resolve_private_identifier(private_identifier.string()) }; } @@ -1841,10 +1841,10 @@ ThrowCompletionOr StaticInitializer::class_element_eva 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; + auto lexical_environment = interpreter.vm().running_execution_context().lexical_environment; // 2. Let privateEnv be the running execution context's PrivateEnvironment. - auto* private_environment = interpreter.vm().running_execution_context().private_environment; + auto private_environment = interpreter.vm().running_execution_context().private_environment; // 3. Let sourceText be the empty sequence of Unicode code points. // 4. Let formalParameters be an instance of the production FormalParameters : [empty] . @@ -1946,7 +1946,7 @@ ThrowCompletionOr ClassExpression::class_definition_e if (!binding_name.is_null()) MUST(class_environment->create_immutable_binding(vm, binding_name, true)); - auto* outer_private_environment = vm.running_execution_context().private_environment; + auto outer_private_environment = vm.running_execution_context().private_environment; auto class_private_environment = new_private_environment(vm, outer_private_environment); for (auto const& element : m_elements) { @@ -3976,7 +3976,7 @@ Completion TryStatement::execute(Interpreter& interpreter) const // 14.15.2 Runtime Semantics: CatchClauseEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-catchclauseevaluation auto catch_clause_evaluation = [&](Value thrown_value) { // 1. Let oldEnv be the running execution context's LexicalEnvironment. - auto* old_environment = vm.running_execution_context().lexical_environment; + auto old_environment = vm.running_execution_context().lexical_environment; // 2. Let catchEnv be NewDeclarativeEnvironment(oldEnv). auto catch_environment = new_declarative_environment(*old_environment); @@ -4730,7 +4730,7 @@ void ScopeNode::block_declaration_instantiation(Interpreter& interpreter, Enviro auto& realm = *vm.current_realm(); VERIFY(environment); - auto* private_environment = vm.running_execution_context().private_environment; + auto private_environment = vm.running_execution_context().private_environment; // Note: All the calls here are ! and thus we do not need to TRY this callback. // We use MUST to ensure it does not throw and to avoid discarding the returned ThrowCompletionOr. MUST(for_each_lexically_scoped_declaration([&](Declaration const& declaration) { diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index abb2447c91..0dcd6329d1 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -1863,7 +1863,7 @@ public: private: NonnullRefPtr const m_tag; NonnullRefPtr const m_template_literal; - mutable HashMap> m_cached_values; + mutable HashMap, Handle> m_cached_values; }; class MemberExpression final : public Expression { diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 27cb3fb596..44d21b75bf 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -51,12 +51,12 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e ExecutionContext execution_context(vm().heap()); if (vm().execution_context_stack().is_empty() || !vm().running_execution_context().lexical_environment) { // The "normal" interpreter pushes an execution context without environment so in that case we also want to push one. - execution_context.this_value = &m_realm.global_object(); + execution_context.this_value = &m_realm->global_object(); static DeprecatedFlyString global_execution_context_name = "(*BC* global execution context)"; execution_context.function_name = global_execution_context_name; - execution_context.lexical_environment = &m_realm.global_environment(); - execution_context.variable_environment = &m_realm.global_environment(); - execution_context.realm = &m_realm; + execution_context.lexical_environment = &m_realm->global_environment(); + execution_context.variable_environment = &m_realm->global_environment(); + execution_context.realm = m_realm; execution_context.is_strict_mode = executable.is_strict_mode; vm().push_execution_context(execution_context); pushed_execution_context = true; @@ -67,7 +67,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e if (in_frame) m_register_windows.append(in_frame); else - m_register_windows.append(make(MarkedVector(vm().heap()), MarkedVector(vm().heap()), MarkedVector(vm().heap()), Vector {})); + m_register_windows.append(make(MarkedVector(vm().heap()), MarkedVector>(vm().heap()), MarkedVector>(vm().heap()), Vector {})); registers().resize(executable.number_of_registers); diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.h b/Userland/Libraries/LibJS/Bytecode/Interpreter.h index 45bd02308c..e9346c0db1 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.h +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.h @@ -20,8 +20,8 @@ namespace JS::Bytecode { struct RegisterWindow { MarkedVector registers; - MarkedVector saved_lexical_environments; - MarkedVector saved_variable_environments; + MarkedVector> saved_lexical_environments; + MarkedVector> saved_variable_environments; Vector unwind_contexts; }; @@ -109,7 +109,7 @@ private: static AK::Array, static_cast>(Interpreter::OptimizationLevel::__Count)> s_optimization_pipelines; VM& m_vm; - Realm& m_realm; + NonnullGCPtr m_realm; Vector, RegisterWindow*>> m_register_windows; Optional m_pending_jump; BasicBlock const* m_scheduled_jump { nullptr }; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 2509670419..2b6d179fd7 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -413,8 +413,8 @@ ThrowCompletionOr DeleteVariable::execute_impl(Bytecode::Interpreter& inte ThrowCompletionOr CreateEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const { - auto make_and_swap_envs = [&](auto*& old_environment) { - Environment* environment = new_declarative_environment(*old_environment).ptr(); + auto make_and_swap_envs = [&](auto& old_environment) { + GCPtr environment = new_declarative_environment(*old_environment).ptr(); swap(old_environment, environment); return environment; }; diff --git a/Userland/Libraries/LibJS/Console.h b/Userland/Libraries/LibJS/Console.h index 6394c14e50..1ac8469061 100644 --- a/Userland/Libraries/LibJS/Console.h +++ b/Userland/Libraries/LibJS/Console.h @@ -89,7 +89,7 @@ private: ThrowCompletionOr value_vector_to_string(MarkedVector const&); ThrowCompletionOr format_time_since(Core::ElapsedTimer timer); - Realm& m_realm; + NonnullGCPtr m_realm; ConsoleClient* m_client { nullptr }; HashMap m_counters; diff --git a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.h b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.h index 831d761090..2305b1c899 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.h +++ b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.h @@ -25,8 +25,8 @@ private: virtual void visit_edges(Visitor&) override; - AgentObject* m_agent { nullptr }; - IsHTMLDDA* m_is_htmldda { nullptr }; + GCPtr m_agent; + GCPtr m_is_htmldda; JS_DECLARE_NATIVE_FUNCTION(clear_kept_objects); JS_DECLARE_NATIVE_FUNCTION(create_realm); diff --git a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h index 618fea6a5a..80bbc3eb90 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h +++ b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h @@ -28,7 +28,7 @@ private: virtual void visit_edges(Visitor&) override; - $262Object* m_$262 { nullptr }; + GCPtr<$262Object> m_$262; JS_DECLARE_NATIVE_FUNCTION(print); }; diff --git a/Userland/Libraries/LibJS/CyclicModule.cpp b/Userland/Libraries/LibJS/CyclicModule.cpp index abea38be05..819779e9bf 100644 --- a/Userland/Libraries/LibJS/CyclicModule.cpp +++ b/Userland/Libraries/LibJS/CyclicModule.cpp @@ -25,7 +25,7 @@ void CyclicModule::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_cycle_root); - for (auto* module : m_async_parent_modules) + for (auto module : m_async_parent_modules) visitor.visit(module); } @@ -204,7 +204,7 @@ ThrowCompletionOr CyclicModule::evaluate(VM& vm) VERIFY(m_cycle_root); VERIFY(this != m_cycle_root); VERIFY(m_cycle_root->m_status == ModuleStatus::Linked); - dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] evaluate[{}](vm) deferring to cycle root at {}", this, m_cycle_root); + dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] evaluate[{}](vm) deferring to cycle root at {}", this, m_cycle_root.ptr()); return m_cycle_root->evaluate(vm); } @@ -502,7 +502,7 @@ void CyclicModule::execute_async_module(VM& vm) void CyclicModule::gather_available_ancestors(Vector& exec_list) { // 1. For each Cyclic Module Record m of module.[[AsyncParentModules]], do - for (auto* module : m_async_parent_modules) { + for (auto module : m_async_parent_modules) { // a. If execList does not contain m and m.[[CycleRoot]].[[EvaluationError]] is empty, then if (!exec_list.contains_slow(module) && !module->m_cycle_root->m_evaluation_error.is_error()) { // i. Assert: m.[[Status]] is evaluating-async. @@ -653,8 +653,7 @@ void CyclicModule::async_module_execution_rejected(VM& vm, Value error) m_status = ModuleStatus::Evaluated; // 7. For each Cyclic Module Record m of module.[[AsyncParentModules]], do - for (auto* module : m_async_parent_modules) { - + for (auto module : m_async_parent_modules) { // a. Perform AsyncModuleExecutionRejected(m, error). module->async_module_execution_rejected(vm, error); } diff --git a/Userland/Libraries/LibJS/CyclicModule.h b/Userland/Libraries/LibJS/CyclicModule.h index 93b7a92974..06d2a3f32d 100644 --- a/Userland/Libraries/LibJS/CyclicModule.h +++ b/Userland/Libraries/LibJS/CyclicModule.h @@ -48,17 +48,17 @@ protected: void async_module_execution_fulfilled(VM& vm); void async_module_execution_rejected(VM& vm, Value error); - ModuleStatus m_status { ModuleStatus::Unlinked }; // [[Status]] - ThrowCompletionOr m_evaluation_error; // [[EvaluationError]] - Optional m_dfs_index; // [[DFSIndex]] - Optional m_dfs_ancestor_index; // [[DFSAncestorIndex]] - Vector m_requested_modules; // [[RequestedModules]] - CyclicModule* m_cycle_root { nullptr }; // [[CycleRoot]] - bool m_has_top_level_await { false }; // [[HasTLA]] - bool m_async_evaluation { false }; // [[AsyncEvaluation]] - GCPtr m_top_level_capability; // [[TopLevelCapability]] - Vector m_async_parent_modules; // [[AsyncParentModules]] - Optional m_pending_async_dependencies; // [[PendingAsyncDependencies]] + ModuleStatus m_status { ModuleStatus::Unlinked }; // [[Status]] + ThrowCompletionOr m_evaluation_error; // [[EvaluationError]] + Optional m_dfs_index; // [[DFSIndex]] + Optional m_dfs_ancestor_index; // [[DFSAncestorIndex]] + Vector m_requested_modules; // [[RequestedModules]] + GCPtr m_cycle_root; // [[CycleRoot]] + bool m_has_top_level_await { false }; // [[HasTLA]] + bool m_async_evaluation { false }; // [[AsyncEvaluation]] + GCPtr m_top_level_capability; // [[TopLevelCapability]] + Vector> m_async_parent_modules; // [[AsyncParentModules]] + Optional m_pending_async_dependencies; // [[PendingAsyncDependencies]] }; } diff --git a/Userland/Libraries/LibJS/Heap/Handle.h b/Userland/Libraries/LibJS/Heap/Handle.h index 7d26d4a1a7..d74f2426e8 100644 --- a/Userland/Libraries/LibJS/Heap/Handle.h +++ b/Userland/Libraries/LibJS/Heap/Handle.h @@ -31,7 +31,7 @@ private: friend class Handle; explicit HandleImpl(Cell*); - Cell* m_cell { nullptr }; + GCPtr m_cell; IntrusiveListNode m_list_node; diff --git a/Userland/Libraries/LibJS/Heap/Heap.h b/Userland/Libraries/LibJS/Heap/Heap.h index 3e1c20fefe..d7ac53a1cf 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.h +++ b/Userland/Libraries/LibJS/Heap/Heap.h @@ -113,7 +113,7 @@ private: MarkedVectorBase::List m_marked_vectors; WeakContainer::List m_weak_containers; - Vector m_uprooted_cells; + Vector> m_uprooted_cells; BlockAllocator m_block_allocator; diff --git a/Userland/Libraries/LibJS/Heap/HeapBlock.h b/Userland/Libraries/LibJS/Heap/HeapBlock.h index 8e200c5b22..595e78f5c3 100644 --- a/Userland/Libraries/LibJS/Heap/HeapBlock.h +++ b/Userland/Libraries/LibJS/Heap/HeapBlock.h @@ -99,7 +99,7 @@ private: struct FreelistEntry final : public Cell { JS_CELL(FreelistEntry, Cell); - FreelistEntry* next { nullptr }; + GCPtr next; }; Cell* cell(size_t index) @@ -110,7 +110,7 @@ private: Heap& m_heap; size_t m_cell_size { 0 }; size_t m_next_lazy_freelist_index { 0 }; - FreelistEntry* m_freelist { nullptr }; + GCPtr m_freelist; alignas(Cell) u8 m_storage[]; public: diff --git a/Userland/Libraries/LibJS/Module.h b/Userland/Libraries/LibJS/Module.h index 21ac836366..2e497efb53 100644 --- a/Userland/Libraries/LibJS/Module.h +++ b/Userland/Libraries/LibJS/Module.h @@ -36,7 +36,7 @@ struct ResolvedBinding { } Type type { Null }; - Module* module { nullptr }; + GCPtr module; DeprecatedFlyString export_name; bool is_valid() const diff --git a/Userland/Libraries/LibJS/Print.cpp b/Userland/Libraries/LibJS/Print.cpp index dc0b364550..d789c270fa 100644 --- a/Userland/Libraries/LibJS/Print.cpp +++ b/Userland/Libraries/LibJS/Print.cpp @@ -356,7 +356,7 @@ ErrorOr print_weak_ref(JS::PrintContext& print_context, JS::WeakRef const& { TRY(print_type(print_context, "WeakRef"sv)); TRY(js_out(print_context, " ")); - TRY(print_value(print_context, weak_ref.value().visit([](Empty) -> JS::Value { return JS::js_undefined(); }, [](auto* value) -> JS::Value { return value; }), seen_objects)); + TRY(print_value(print_context, weak_ref.value().visit([](Empty) -> JS::Value { return JS::js_undefined(); }, [](auto value) -> JS::Value { return value; }), seen_objects)); return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 0096735ae4..d52a6edb0d 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -345,8 +345,8 @@ bool validate_and_apply_property_descriptor(Object* object, PropertyKey const& p // i. For each field of Desc, set the corresponding attribute of the property named P of object O to the value of the field. Value value; if (descriptor.is_accessor_descriptor() || (current->is_accessor_descriptor() && !descriptor.is_data_descriptor())) { - auto* getter = descriptor.get.value_or(current->get.value_or(nullptr)); - auto* setter = descriptor.set.value_or(current->set.value_or(nullptr)); + auto getter = descriptor.get.value_or(current->get.value_or(nullptr)); + auto setter = descriptor.set.value_or(current->set.value_or(nullptr)); value = Accessor::create(object->vm(), getter, setter); } else { value = descriptor.value.value_or(current->value.value_or({})); diff --git a/Userland/Libraries/LibJS/Runtime/Accessor.h b/Userland/Libraries/LibJS/Runtime/Accessor.h index 740e53701e..edc001a35c 100644 --- a/Userland/Libraries/LibJS/Runtime/Accessor.h +++ b/Userland/Libraries/LibJS/Runtime/Accessor.h @@ -41,8 +41,8 @@ private: { } - FunctionObject* m_getter { nullptr }; - FunctionObject* m_setter { nullptr }; + GCPtr m_getter; + GCPtr m_setter; }; } diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp index 63d7e0df8c..91f8943959 100644 --- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp @@ -28,7 +28,7 @@ ThrowCompletionOr ArgumentsObject::initialize(Realm& realm) void ArgumentsObject::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(&m_environment); + visitor.visit(m_environment); visitor.visit(m_parameter_map); } diff --git a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h index 4538d1732f..d0e52c34b7 100644 --- a/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h +++ b/Userland/Libraries/LibJS/Runtime/ArgumentsObject.h @@ -35,8 +35,8 @@ private: virtual void visit_edges(Cell::Visitor&) override; - Environment& m_environment; - Object* m_parameter_map { nullptr }; + NonnullGCPtr m_environment; + GCPtr m_parameter_map; }; } diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp index 7ace311002..70092e01f5 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp @@ -108,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_) auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. - auto* sync_iterator = this_object->sync_iterator_record().iterator; + auto sync_iterator = this_object->sync_iterator_record().iterator; // 5. Let return be Completion(GetMethod(syncIterator, "return")). // 6. IfAbruptRejectPromise(return, promiseCapability). @@ -161,7 +161,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_) auto promise_capability = MUST(new_promise_capability(vm, realm.intrinsics().promise_constructor())); // 4. Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. - auto* sync_iterator = this_object->sync_iterator_record().iterator; + auto sync_iterator = this_object->sync_iterator_record().iterator; // 5. Let throw be Completion(GetMethod(syncIterator, "throw")). // 6. IfAbruptRejectPromise(throw, promiseCapability). diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp index 182d2002f1..3c38567ca1 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.cpp @@ -23,7 +23,7 @@ BigIntObject::BigIntObject(BigInt& bigint, Object& prototype) void BigIntObject::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(&m_bigint); + visitor.visit(m_bigint); } } diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.h b/Userland/Libraries/LibJS/Runtime/BigIntObject.h index df7140c14d..3dcf808c63 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntObject.h +++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.h @@ -27,7 +27,7 @@ private: virtual void visit_edges(Visitor&) override; - BigInt& m_bigint; + NonnullGCPtr m_bigint; }; } diff --git a/Userland/Libraries/LibJS/Runtime/BoundFunction.h b/Userland/Libraries/LibJS/Runtime/BoundFunction.h index bf2b251eb8..0e9fbf3675 100644 --- a/Userland/Libraries/LibJS/Runtime/BoundFunction.h +++ b/Userland/Libraries/LibJS/Runtime/BoundFunction.h @@ -35,9 +35,9 @@ private: virtual void visit_edges(Visitor&) override; - FunctionObject* m_bound_target_function { nullptr }; // [[BoundTargetFunction]] - Value m_bound_this; // [[BoundThis]] - Vector m_bound_arguments; // [[BoundArguments]] + GCPtr m_bound_target_function; // [[BoundTargetFunction]] + Value m_bound_this; // [[BoundThis]] + Vector m_bound_arguments; // [[BoundArguments]] DeprecatedFlyString m_name; }; diff --git a/Userland/Libraries/LibJS/Runtime/DataView.h b/Userland/Libraries/LibJS/Runtime/DataView.h index 8955c03d6e..920cd4be2e 100644 --- a/Userland/Libraries/LibJS/Runtime/DataView.h +++ b/Userland/Libraries/LibJS/Runtime/DataView.h @@ -29,7 +29,7 @@ private: virtual void visit_edges(Visitor& visitor) override; - ArrayBuffer* m_viewed_array_buffer { nullptr }; + GCPtr m_viewed_array_buffer; size_t m_byte_length { 0 }; size_t m_byte_offset { 0 }; }; diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 42376b9500..ff8107f9ce 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -247,7 +247,7 @@ ThrowCompletionOr> ECMAScriptFunctionObject::internal_const } // 7. Let constructorEnv be the LexicalEnvironment of calleeContext. - auto* constructor_env = callee_context.lexical_environment; + auto constructor_env = callee_context.lexical_environment; // 8. Let result be Completion(OrdinaryCallEvaluateBody(F, argumentsList)). auto result = ordinary_call_evaluate_body(); @@ -587,7 +587,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia })); } - auto* private_environment = callee_context.private_environment; + auto private_environment = callee_context.private_environment; for (auto& declaration : functions_to_initialize) { auto function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lex_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval()); MUST(var_environment->set_mutable_binding(vm, declaration.name(), function, false)); @@ -621,7 +621,7 @@ ThrowCompletionOr ECMAScriptFunctionObject::prepare_for_ordinary_call(Exec callee_context.function_name = m_name; // 4. Let calleeRealm be F.[[Realm]]. - auto* callee_realm = m_realm; + auto callee_realm = m_realm; // NOTE: This non-standard fallback is needed until we can guarantee that literally // every function has a realm - especially in LibWeb that's sometimes not the case // when a function is created while no JS is running, as we currently need to rely on @@ -674,7 +674,7 @@ void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_ return; // 3. Let calleeRealm be F.[[Realm]]. - auto* callee_realm = m_realm; + auto callee_realm = m_realm; // NOTE: This non-standard fallback is needed until we can guarantee that literally // every function has a realm - especially in LibWeb that's sometimes not the case // when a function is created while no JS is running, as we currently need to rely on @@ -685,7 +685,7 @@ void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_ VERIFY(callee_realm); // 4. Let localEnv be the LexicalEnvironment of calleeContext. - auto* local_env = callee_context.lexical_environment; + auto local_env = callee_context.lexical_environment; Value this_value; @@ -717,7 +717,7 @@ void ECMAScriptFunctionObject::ordinary_call_bind_this(ExecutionContext& callee_ // 7. Assert: localEnv is a function Environment Record. // 8. Assert: The next step never returns an abrupt completion because localEnv.[[ThisBindingStatus]] is not initialized. // 9. Perform ! localEnv.BindThisValue(thisValue). - MUST(verify_cast(local_env)->bind_this_value(vm, this_value)); + MUST(verify_cast(*local_env).bind_this_value(vm, this_value)); // 10. Return unused. } @@ -762,11 +762,11 @@ void async_block_start(VM& vm, NonnullRefPtr const& async_body, vm.pop_execution_context(); // d. Let env be asyncContext's LexicalEnvironment. - auto* env = async_context.lexical_environment; - VERIFY(is(env)); + auto env = async_context.lexical_environment; + VERIFY(is(*env)); // e. Set result to DisposeResources(env, result). - result = dispose_resources(vm, static_cast(env), result); + result = dispose_resources(vm, static_cast(env.ptr()), result); // f. If result.[[Type]] is normal, then if (result.type() == Completion::Type::Normal) { @@ -909,11 +909,11 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body() auto result = m_ecmascript_code->execute(*ast_interpreter); // 3. Let env be the running execution context's LexicalEnvironment. - auto* env = vm.running_execution_context().lexical_environment; - VERIFY(is(env)); + auto env = vm.running_execution_context().lexical_environment; + VERIFY(is(*env)); // 4. Return ? DisposeResources(env, result). - return dispose_resources(vm, static_cast(env), result); + return dispose_resources(vm, static_cast(env.ptr()), result); } // AsyncFunctionBody : FunctionBody else if (m_kind == FunctionKind::Async) { diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h index 978234d852..5030c945ef 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h @@ -112,13 +112,13 @@ private: i32 m_function_length { 0 }; // Internal Slots of ECMAScript Function Objects, https://tc39.es/ecma262/#table-internal-slots-of-ecmascript-function-objects - Environment* m_environment { nullptr }; // [[Environment]] - PrivateEnvironment* m_private_environment { nullptr }; // [[PrivateEnvironment]] + GCPtr m_environment; // [[Environment]] + GCPtr m_private_environment; // [[PrivateEnvironment]] Vector const m_formal_parameters; // [[FormalParameters]] NonnullRefPtr m_ecmascript_code; // [[ECMAScriptCode]] - Realm* m_realm { nullptr }; // [[Realm]] + GCPtr m_realm; // [[Realm]] ScriptOrModule m_script_or_module; // [[ScriptOrModule]] - Object* m_home_object { nullptr }; // [[HomeObject]] + GCPtr m_home_object; // [[HomeObject]] DeprecatedString m_source_text; // [[SourceText]] Vector m_fields; // [[Fields]] Vector m_private_methods; // [[PrivateMethods]] diff --git a/Userland/Libraries/LibJS/Runtime/Environment.h b/Userland/Libraries/LibJS/Runtime/Environment.h index e33fa08b2e..f79dc9f183 100644 --- a/Userland/Libraries/LibJS/Runtime/Environment.h +++ b/Userland/Libraries/LibJS/Runtime/Environment.h @@ -67,7 +67,7 @@ private: bool m_permanently_screwed_by_eval { false }; - Environment* m_outer_environment { nullptr }; + GCPtr m_outer_environment; }; } diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index b793faef7c..33a4ab4a7f 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -65,7 +65,7 @@ void Error::populate_stack() auto& vm = this->vm(); m_traceback.ensure_capacity(vm.execution_context_stack().size()); for (ssize_t i = vm.execution_context_stack().size() - 1; i >= 0; i--) { - auto* context = vm.execution_context_stack()[i]; + auto context = vm.execution_context_stack()[i]; auto function_name = context->function_name; if (function_name.is_empty()) function_name = ""sv; diff --git a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h index aea4986160..180a91c12b 100644 --- a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h +++ b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h @@ -32,15 +32,15 @@ private: explicit ExecutionContext(MarkedVector existing_arguments); public: - FunctionObject* function { nullptr }; // [[Function]] - Realm* realm { nullptr }; // [[Realm]] - ScriptOrModule script_or_module; // [[ScriptOrModule]] - Environment* lexical_environment { nullptr }; // [[LexicalEnvironment]] - Environment* variable_environment { nullptr }; // [[VariableEnvironment]] - PrivateEnvironment* private_environment { nullptr }; // [[PrivateEnvironment]] + GCPtr function; // [[Function]] + GCPtr realm; // [[Realm]] + ScriptOrModule script_or_module; // [[ScriptOrModule]] + GCPtr lexical_environment; // [[LexicalEnvironment]] + GCPtr variable_environment; // [[VariableEnvironment]] + GCPtr private_environment; // [[PrivateEnvironment]] // Non-standard: This points at something that owns this ExecutionContext, in case it needs to be protected from GC. - Cell* context_owner { nullptr }; + GCPtr context_owner; ASTNode const* current_node { nullptr }; DeprecatedFlyString function_name; diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h index 792738e399..53fc1c1638 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h @@ -46,9 +46,9 @@ private: JobCallback m_cleanup_callback; struct FinalizationRecord { - Cell* target { nullptr }; + GCPtr target; Value held_value; - Cell* unregister_token { nullptr }; + GCPtr unregister_token; }; SinglyLinkedList m_records; }; diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h index ee6968703c..4baab41344 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h @@ -52,7 +52,7 @@ private: Value m_this_value; // [[ThisValue]] ThisBindingStatus m_this_binding_status { ThisBindingStatus::Uninitialized }; // [[ThisBindingStatus]] - ECMAScriptFunctionObject* m_function_object { nullptr }; // [[FunctionObject]] + GCPtr m_function_object; // [[FunctionObject]] Value m_new_target { js_undefined() }; // [[NewTarget]] }; diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h index 4d0b1ab145..7686de296d 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h @@ -38,7 +38,7 @@ private: ThrowCompletionOr execute(VM&, JS::Completion const& completion); ExecutionContext m_execution_context; - ECMAScriptFunctionObject* m_generating_function { nullptr }; + GCPtr m_generating_function; Value m_previous_value; Optional m_frame; GeneratorState m_generator_state { GeneratorState::SuspendedStart }; diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h index 1bae539f6c..39d5cef37c 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h @@ -43,10 +43,10 @@ private: virtual bool is_global_environment() const override { return true; } virtual void visit_edges(Visitor&) override; - ObjectEnvironment* m_object_record { nullptr }; // [[ObjectRecord]] - Object* m_global_this_value { nullptr }; // [[GlobalThisValue]] - DeclarativeEnvironment* m_declarative_record { nullptr }; // [[DeclarativeRecord]] - Vector m_var_names; // [[VarNames]] + GCPtr m_object_record; // [[ObjectRecord]] + GCPtr m_global_this_value; // [[GlobalThisValue]] + GCPtr m_declarative_record; // [[DeclarativeRecord]] + Vector m_var_names; // [[VarNames]] }; template<> diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Collator.h b/Userland/Libraries/LibJS/Runtime/Intl/Collator.h index bd319bc801..1a1d090e21 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/Collator.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/Collator.h @@ -77,14 +77,14 @@ private: virtual void visit_edges(Visitor&) override; - String m_locale; // [[Locale]] - Usage m_usage { Usage::Sort }; // [[Usage]] - Sensitivity m_sensitivity { Sensitivity::Variant }; // [[Sensitivity]] - CaseFirst m_case_first { CaseFirst::False }; // [[CaseFirst]] - String m_collation; // [[Collation]] - bool m_ignore_punctuation { false }; // [[IgnorePunctuation]] - bool m_numeric { false }; // [[Numeric]] - CollatorCompareFunction* m_bound_compare { nullptr }; // [[BoundCompare]] + String m_locale; // [[Locale]] + Usage m_usage { Usage::Sort }; // [[Usage]] + Sensitivity m_sensitivity { Sensitivity::Variant }; // [[Sensitivity]] + CaseFirst m_case_first { CaseFirst::False }; // [[CaseFirst]] + String m_collation; // [[Collation]] + bool m_ignore_punctuation { false }; // [[IgnorePunctuation]] + bool m_numeric { false }; // [[Numeric]] + GCPtr m_bound_compare; // [[BoundCompare]] }; } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp index 1282b39208..a14b0f9fd2 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp @@ -71,7 +71,7 @@ ThrowCompletionOr CollatorCompareFunction::call() void CollatorCompareFunction::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(&m_collator); + visitor.visit(m_collator); } } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h index 944f448233..5d39576983 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h @@ -26,7 +26,7 @@ private: virtual void visit_edges(Visitor&) override; - Collator& m_collator; // [[Collator]] + NonnullGCPtr m_collator; // [[Collator]] }; double compare_strings(Collator&, Utf8View const& x, Utf8View const& y); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h index d994c4ff74..42b5fbd441 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.h @@ -142,7 +142,7 @@ private: Optional