mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:37:44 +00:00
LibJS: Convert Heap::allocate{,_without_realm}() to NonnullGCPtr
This commit is contained in:
parent
2a66fc6cae
commit
22089436ed
161 changed files with 367 additions and 370 deletions
|
@ -19,7 +19,7 @@ JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_radial(JS::Realm& realm,
|
|||
(void)x1;
|
||||
(void)y1;
|
||||
(void)r1;
|
||||
return *realm.heap().allocate<CanvasGradient>(realm, realm, Type::Radial);
|
||||
return realm.heap().allocate<CanvasGradient>(realm, realm, Type::Radial);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_linear(JS::Realm& realm, double x0, double y0, double x1, double y1)
|
||||
|
@ -28,7 +28,7 @@ JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_linear(JS::Realm& realm,
|
|||
(void)y0;
|
||||
(void)x1;
|
||||
(void)y1;
|
||||
return *realm.heap().allocate<CanvasGradient>(realm, realm, Type::Linear);
|
||||
return realm.heap().allocate<CanvasGradient>(realm, realm, Type::Linear);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_conic(JS::Realm& realm, double start_angle, double x, double y)
|
||||
|
@ -36,7 +36,7 @@ JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_conic(JS::Realm& realm,
|
|||
(void)start_angle;
|
||||
(void)x;
|
||||
(void)y;
|
||||
return *realm.heap().allocate<CanvasGradient>(realm, realm, Type::Conic);
|
||||
return realm.heap().allocate<CanvasGradient>(realm, realm, Type::Conic);
|
||||
}
|
||||
|
||||
CanvasGradient::CanvasGradient(JS::Realm& realm, Type type)
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<CanvasRenderingContext2D> CanvasRenderingContext2D::create(JS::Realm& realm, HTMLCanvasElement& element)
|
||||
{
|
||||
return *realm.heap().allocate<CanvasRenderingContext2D>(realm, realm, element);
|
||||
return realm.heap().allocate<CanvasRenderingContext2D>(realm, realm, element);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2D::CanvasRenderingContext2D(JS::Realm& realm, HTMLCanvasElement& element)
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Web::HTML {
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMParser>> DOMParser::construct_impl(JS::Realm& realm)
|
||||
{
|
||||
return JS::NonnullGCPtr(*realm.heap().allocate<DOMParser>(realm, realm));
|
||||
return realm.heap().allocate<DOMParser>(realm, realm);
|
||||
}
|
||||
|
||||
DOMParser::DOMParser(JS::Realm& realm)
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Web::HTML {
|
|||
JS::NonnullGCPtr<DOMStringMap> DOMStringMap::create(DOM::Element& element)
|
||||
{
|
||||
auto& realm = element.realm();
|
||||
return *realm.heap().allocate<DOMStringMap>(realm, element);
|
||||
return realm.heap().allocate<DOMStringMap>(realm, element);
|
||||
}
|
||||
|
||||
DOMStringMap::DOMStringMap(DOM::Element& element)
|
||||
|
|
|
@ -376,7 +376,7 @@ void HTMLInputElement::create_shadow_tree_if_needed()
|
|||
break;
|
||||
}
|
||||
|
||||
auto* shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this);
|
||||
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this);
|
||||
auto initial_value = m_value;
|
||||
if (initial_value.is_null())
|
||||
initial_value = DeprecatedString::empty();
|
||||
|
@ -390,8 +390,8 @@ void HTMLInputElement::create_shadow_tree_if_needed()
|
|||
m_text_node->set_is_password_input({}, true);
|
||||
|
||||
MUST(element->append_child(*m_text_node));
|
||||
MUST(shadow_root->append_child(move(element)));
|
||||
set_shadow_root(move(shadow_root));
|
||||
MUST(shadow_root->append_child(element));
|
||||
set_shadow_root(shadow_root);
|
||||
}
|
||||
|
||||
void HTMLInputElement::did_receive_focus()
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
|
||||
{
|
||||
return *root.heap().allocate<HTMLOptionsCollection>(root.realm(), root, move(filter));
|
||||
return root.heap().allocate<HTMLOptionsCollection>(root.realm(), root, move(filter));
|
||||
}
|
||||
|
||||
HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<History> History::create(JS::Realm& realm, DOM::Document& document)
|
||||
{
|
||||
return *realm.heap().allocate<History>(realm, realm, document);
|
||||
return realm.heap().allocate<History>(realm, realm, document);
|
||||
}
|
||||
|
||||
History::History(JS::Realm& realm, DOM::Document& document)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<MessageChannel> MessageChannel::construct_impl(JS::Realm& realm)
|
||||
{
|
||||
return *realm.heap().allocate<MessageChannel>(realm, realm);
|
||||
return realm.heap().allocate<MessageChannel>(realm, realm);
|
||||
}
|
||||
|
||||
MessageChannel::MessageChannel(JS::Realm& realm)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<MessagePort> MessagePort::create(JS::Realm& realm)
|
||||
{
|
||||
return *realm.heap().allocate<MessagePort>(realm, realm);
|
||||
return realm.heap().allocate<MessagePort>(realm, realm);
|
||||
}
|
||||
|
||||
MessagePort::MessagePort(JS::Realm& realm)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<Navigator> Navigator::create(JS::Realm& realm)
|
||||
{
|
||||
return *realm.heap().allocate<Navigator>(realm, realm);
|
||||
return realm.heap().allocate<Navigator>(realm, realm);
|
||||
}
|
||||
|
||||
Navigator::Navigator(JS::Realm& realm)
|
||||
|
|
|
@ -759,7 +759,7 @@ AnythingElse:
|
|||
void HTMLParser::insert_comment(HTMLToken& token)
|
||||
{
|
||||
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
|
||||
adjusted_insertion_location.parent->insert_before(*realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()), adjusted_insertion_location.insert_before_sibling);
|
||||
adjusted_insertion_location.parent->insert_before(realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment()), adjusted_insertion_location.insert_before_sibling);
|
||||
}
|
||||
|
||||
void HTMLParser::handle_in_head(HTMLToken& token)
|
||||
|
@ -1071,7 +1071,7 @@ void HTMLParser::handle_after_body(HTMLToken& token)
|
|||
|
||||
if (token.is_comment()) {
|
||||
auto& insertion_location = m_stack_of_open_elements.first();
|
||||
MUST(insertion_location.append_child(*realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment())));
|
||||
MUST(insertion_location.append_child(realm().heap().allocate<DOM::Comment>(realm(), document(), token.comment())));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3181,8 +3181,8 @@ void HTMLParser::handle_after_frameset(HTMLToken& token)
|
|||
void HTMLParser::handle_after_after_frameset(HTMLToken& token)
|
||||
{
|
||||
if (token.is_comment()) {
|
||||
auto* comment = document().heap().allocate<DOM::Comment>(document().realm(), document(), token.comment());
|
||||
MUST(document().append_child(*comment));
|
||||
auto comment = document().heap().allocate<DOM::Comment>(document().realm(), document(), token.comment());
|
||||
MUST(document().append_child(comment));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3540,21 +3540,21 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
|
|||
|
||||
JS::NonnullGCPtr<HTMLParser> HTMLParser::create_for_scripting(DOM::Document& document)
|
||||
{
|
||||
return *document.heap().allocate_without_realm<HTMLParser>(document);
|
||||
return document.heap().allocate_without_realm<HTMLParser>(document);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<HTMLParser> HTMLParser::create_with_uncertain_encoding(DOM::Document& document, ByteBuffer const& input)
|
||||
{
|
||||
if (document.has_encoding())
|
||||
return *document.heap().allocate_without_realm<HTMLParser>(document, input, document.encoding().value());
|
||||
return document.heap().allocate_without_realm<HTMLParser>(document, input, document.encoding().value());
|
||||
auto encoding = run_encoding_sniffing_algorithm(document, input);
|
||||
dbgln_if(HTML_PARSER_DEBUG, "The encoding sniffing algorithm returned encoding '{}'", encoding);
|
||||
return *document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
|
||||
return document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<HTMLParser> HTMLParser::create(DOM::Document& document, StringView input, DeprecatedString const& encoding)
|
||||
{
|
||||
return *document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
|
||||
return document.heap().allocate_without_realm<HTMLParser>(document, input, encoding);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-serialisation-algorithm
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<Path2D> Path2D::construct_impl(JS::Realm& realm, Optional<Variant<JS::Handle<Path2D>, DeprecatedString>> const& path)
|
||||
{
|
||||
return *realm.heap().allocate<Path2D>(realm, realm, path);
|
||||
return realm.heap().allocate<Path2D>(realm, realm, path);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d
|
||||
|
|
|
@ -60,14 +60,14 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(DeprecatedString filename,
|
|||
script->m_error_to_rethrow = parse_error;
|
||||
|
||||
// 2. Return script.
|
||||
return JS::NonnullGCPtr(*script);
|
||||
return script;
|
||||
}
|
||||
|
||||
// 12. Set script's record to result.
|
||||
script->m_script_record = *result.release_value();
|
||||
|
||||
// 13. Return script.
|
||||
return JS::NonnullGCPtr(*script);
|
||||
return script;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
|
||||
|
|
|
@ -38,7 +38,7 @@ JS::GCPtr<JavaScriptModuleScript> JavaScriptModuleScript::create(DeprecatedStrin
|
|||
auto& realm = settings_object.realm();
|
||||
|
||||
// 2. Let script be a new module script that this algorithm will subsequently initialize.
|
||||
auto* script = realm.heap().allocate<JavaScriptModuleScript>(realm, move(base_url), filename, settings_object);
|
||||
auto script = realm.heap().allocate<JavaScriptModuleScript>(realm, move(base_url), filename, settings_object);
|
||||
|
||||
// 3. Set script's settings object to settings.
|
||||
// NOTE: This was already done when constructing.
|
||||
|
|
|
@ -38,7 +38,7 @@ void WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, Nonnull
|
|||
|
||||
// 3. Let settings object be a new environment settings object whose algorithms are defined as follows:
|
||||
// NOTE: See the functions defined for this class.
|
||||
auto* settings_object = realm->heap().allocate<WindowEnvironmentSettingsObject>(*realm, window, move(execution_context));
|
||||
auto settings_object = realm->heap().allocate<WindowEnvironmentSettingsObject>(*realm, window, move(execution_context));
|
||||
|
||||
// 4. If reservedEnvironment is non-null, then:
|
||||
if (reserved_environment.has_value()) {
|
||||
|
@ -71,8 +71,8 @@ void WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, Nonnull
|
|||
|
||||
// 7. Set realm's [[HostDefined]] field to settings object.
|
||||
// Non-Standard: We store the ESO next to the web intrinsics in a custom HostDefined object
|
||||
auto* intrinsics = realm->heap().allocate<Bindings::Intrinsics>(*realm, *realm);
|
||||
auto host_defined = make<Bindings::HostDefined>(*settings_object, *intrinsics);
|
||||
auto intrinsics = realm->heap().allocate<Bindings::Intrinsics>(*realm, *realm);
|
||||
auto host_defined = make<Bindings::HostDefined>(settings_object, intrinsics);
|
||||
realm->set_host_defined(move(host_defined));
|
||||
|
||||
// Non-Standard: We cannot fully initialize window object until *after* the we set up
|
||||
|
|
|
@ -30,14 +30,14 @@ public:
|
|||
auto settings_object = realm->heap().allocate<WorkerEnvironmentSettingsObject>(*realm, move(execution_context));
|
||||
settings_object->target_browsing_context = nullptr;
|
||||
|
||||
auto* intrinsics = realm->heap().allocate<Bindings::Intrinsics>(*realm, *realm);
|
||||
auto host_defined = make<Bindings::HostDefined>(*settings_object, *intrinsics);
|
||||
auto intrinsics = realm->heap().allocate<Bindings::Intrinsics>(*realm, *realm);
|
||||
auto host_defined = make<Bindings::HostDefined>(settings_object, intrinsics);
|
||||
realm->set_host_defined(move(host_defined));
|
||||
|
||||
// FIXME: Shared workers should use the shared worker method
|
||||
Bindings::add_dedicated_worker_exposed_interfaces(realm->global_object(), *realm);
|
||||
|
||||
return *settings_object;
|
||||
return settings_object;
|
||||
}
|
||||
|
||||
virtual ~WorkerEnvironmentSettingsObject() override = default;
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<Storage> Storage::create(JS::Realm& realm)
|
||||
{
|
||||
return *realm.heap().allocate<Storage>(realm, realm);
|
||||
return realm.heap().allocate<Storage>(realm, realm);
|
||||
}
|
||||
|
||||
Storage::Storage(JS::Realm& realm)
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<TextMetrics> TextMetrics::create(JS::Realm& realm)
|
||||
{
|
||||
return *realm.heap().allocate<TextMetrics>(realm, realm);
|
||||
return realm.heap().allocate<TextMetrics>(realm, realm);
|
||||
}
|
||||
|
||||
TextMetrics::TextMetrics(JS::Realm& realm)
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<Timer> Timer::create(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
||||
{
|
||||
return *window.heap().allocate_without_realm<Timer>(window, milliseconds, move(callback), id);
|
||||
return window.heap().allocate_without_realm<Timer>(window, milliseconds, move(callback), id);
|
||||
}
|
||||
|
||||
Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
|
||||
|
|
|
@ -86,7 +86,7 @@ private:
|
|||
|
||||
JS::NonnullGCPtr<Window> Window::create(JS::Realm& realm)
|
||||
{
|
||||
return *realm.heap().allocate<Window>(realm, realm);
|
||||
return realm.heap().allocate<Window>(realm, realm);
|
||||
}
|
||||
|
||||
Window::Window(JS::Realm& realm)
|
||||
|
@ -1340,7 +1340,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::request_animation_frame)
|
|||
auto* callback_object = TRY(vm.argument(0).to_object(vm));
|
||||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
auto* callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
|
||||
auto callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
|
||||
return JS::Value(impl->request_animation_frame_impl(*callback));
|
||||
}
|
||||
|
||||
|
@ -1363,7 +1363,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::queue_microtask)
|
|||
if (!callback_object->is_function())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
|
||||
auto* callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
|
||||
auto callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
|
||||
|
||||
impl->queue_microtask_impl(*callback);
|
||||
return JS::js_undefined();
|
||||
|
@ -1379,7 +1379,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::request_idle_callback)
|
|||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunctionNoParam);
|
||||
// FIXME: accept options object
|
||||
|
||||
auto* callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
|
||||
auto callback = vm.heap().allocate_without_realm<WebIDL::CallbackType>(*callback_object, HTML::incumbent_settings_object());
|
||||
|
||||
return JS::Value(impl->request_idle_callback_impl(*callback));
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> Worker::create(FlyString const& sc
|
|||
worker->run_a_worker(url, outside_settings, *outside_port, options);
|
||||
|
||||
// 10. Return worker
|
||||
return JS::NonnullGCPtr(*worker);
|
||||
return worker;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#run-a-worker
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::HTML {
|
|||
|
||||
JS::NonnullGCPtr<WorkerNavigator> WorkerNavigator::create(WorkerGlobalScope& global_scope)
|
||||
{
|
||||
return *global_scope.heap().allocate<WorkerNavigator>(global_scope.realm(), global_scope);
|
||||
return global_scope.heap().allocate<WorkerNavigator>(global_scope.realm(), global_scope);
|
||||
}
|
||||
|
||||
WorkerNavigator::WorkerNavigator(WorkerGlobalScope& global_scope)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue