LibJS+LibWeb: Use realm.create<T> instead of heap.allocate<T>

The main motivation behind this is to remove JS specifics of the Realm
from the implementation of the Heap.

As a side effect of this change, this is a bit nicer to read than the
previous approach, and in my opinion, also makes it a little more clear
that this method is specific to a JavaScript Realm.
This commit is contained in:
Shannon Booth 2024-11-14 05:50:17 +13:00 committed by Tim Flynn
commit 9b79a686eb
Notes: github-actions[bot] 2024-11-13 21:52:48 +00:00
326 changed files with 697 additions and 714 deletions

View file

@ -28,7 +28,7 @@ JS_DEFINE_ALLOCATOR(Animation);
JS::NonnullGCPtr<Animation> Animation::create(JS::Realm& realm, JS::GCPtr<AnimationEffect> effect, Optional<JS::GCPtr<AnimationTimeline>> timeline)
{
// 1. Let animation be a new Animation object.
auto animation = realm.heap().allocate<Animation>(realm, realm);
auto animation = realm.create<Animation>(realm);
// 2. Run the procedure to set the timeline of an animation on animation passing timeline as the new timeline or, if
// a timeline argument is missing, passing the default document timeline of the Document associated with the

View file

@ -14,7 +14,7 @@ JS_DEFINE_ALLOCATOR(AnimationPlaybackEvent);
JS::NonnullGCPtr<AnimationPlaybackEvent> AnimationPlaybackEvent::create(JS::Realm& realm, FlyString const& type, AnimationPlaybackEventInit const& event_init)
{
return realm.heap().allocate<AnimationPlaybackEvent>(realm, realm, type, event_init);
return realm.create<AnimationPlaybackEvent>(realm, type, event_init);
}
// https://www.w3.org/TR/web-animations-1/#dom-animationplaybackevent-animationplaybackevent

View file

@ -19,7 +19,7 @@ JS_DEFINE_ALLOCATOR(DocumentTimeline);
JS::NonnullGCPtr<DocumentTimeline> DocumentTimeline::create(JS::Realm& realm, DOM::Document& document, HighResolutionTime::DOMHighResTimeStamp origin_time)
{
auto timeline = realm.heap().allocate<DocumentTimeline>(realm, realm, document, origin_time);
auto timeline = realm.create<DocumentTimeline>(realm, document, origin_time);
auto current_time = document.last_animation_frame_timestamp();
if (!current_time.has_value()) {
// The document hasn't processed an animation frame yet, so just use the exact current time

View file

@ -648,7 +648,7 @@ int KeyframeEffect::composite_order(JS::NonnullGCPtr<KeyframeEffect> a, JS::Nonn
JS::NonnullGCPtr<KeyframeEffect> KeyframeEffect::create(JS::Realm& realm)
{
return realm.heap().allocate<KeyframeEffect>(realm, realm);
return realm.create<KeyframeEffect>(realm);
}
// https://www.w3.org/TR/web-animations-1/#dom-keyframeeffect-keyframeeffect
@ -658,10 +658,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyframeEffect>> KeyframeEffect::construct_
Optional<JS::Handle<JS::Object>> const& keyframes,
Variant<double, KeyframeEffectOptions> options)
{
auto& vm = realm.vm();
// 1. Create a new KeyframeEffect object, effect.
auto effect = vm.heap().allocate<KeyframeEffect>(realm, realm);
auto effect = realm.create<KeyframeEffect>(realm);
// 2. Set the target element of effect to target.
effect->set_target(target);
@ -721,10 +719,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyframeEffect>> KeyframeEffect::construct_
// https://www.w3.org/TR/web-animations-1/#dom-keyframeeffect-keyframeeffect-source
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyframeEffect>> KeyframeEffect::construct_impl(JS::Realm& realm, JS::NonnullGCPtr<KeyframeEffect> source)
{
auto& vm = realm.vm();
// 1. Create a new KeyframeEffect object, effect.
auto effect = vm.heap().allocate<KeyframeEffect>(realm, realm);
auto effect = realm.create<KeyframeEffect>(realm);
// 2. Set the following properties of effect using the corresponding values of source: