mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:27:43 +00:00
LibWeb: Make IdleDeadline GC-allocated
This commit is contained in:
parent
8f2a711132
commit
915a240944
5 changed files with 22 additions and 22 deletions
|
@ -449,7 +449,6 @@ class URLSearchParamsIterator;
|
|||
|
||||
namespace Web::Bindings {
|
||||
class DOMExceptionWrapper;
|
||||
class IdleDeadlineWrapper;
|
||||
class IntersectionObserverWrapper;
|
||||
class LocationObject;
|
||||
class OptionConstructor;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <LibWeb/Bindings/EventTargetPrototype.h>
|
||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Bindings/IDLAbstractOperations.h>
|
||||
#include <LibWeb/Bindings/IdleDeadlineWrapper.h>
|
||||
#include <LibWeb/Bindings/LocationObject.h>
|
||||
#include <LibWeb/Bindings/NavigatorObject.h>
|
||||
#include <LibWeb/Bindings/Replaceable.h>
|
||||
|
@ -63,18 +62,18 @@ void run_animation_frame_callbacks(DOM::Document& document, double)
|
|||
|
||||
class IdleCallback : public RefCounted<IdleCallback> {
|
||||
public:
|
||||
explicit IdleCallback(Function<JS::Completion(NonnullRefPtr<RequestIdleCallback::IdleDeadline>)> handler, u32 handle)
|
||||
explicit IdleCallback(Function<JS::Completion(JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline>)> handler, u32 handle)
|
||||
: m_handler(move(handler))
|
||||
, m_handle(handle)
|
||||
{
|
||||
}
|
||||
~IdleCallback() = default;
|
||||
|
||||
JS::Completion invoke(NonnullRefPtr<RequestIdleCallback::IdleDeadline> deadline) { return m_handler(move(deadline)); }
|
||||
JS::Completion invoke(JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline> deadline) { return m_handler(deadline); }
|
||||
u32 handle() const { return m_handle; }
|
||||
|
||||
private:
|
||||
Function<JS::Completion(NonnullRefPtr<RequestIdleCallback::IdleDeadline>)> m_handler;
|
||||
Function<JS::Completion(JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline>)> m_handler;
|
||||
u32 m_handle { 0 };
|
||||
};
|
||||
|
||||
|
@ -666,7 +665,7 @@ void Window::invoke_idle_callbacks()
|
|||
// 1. Pop the top callback from window's list of runnable idle callbacks.
|
||||
auto callback = m_runnable_idle_callbacks.take_first();
|
||||
// 2. Let deadlineArg be a new IdleDeadline whose [get deadline time algorithm] is getDeadline.
|
||||
auto deadline_arg = RequestIdleCallback::IdleDeadline::create();
|
||||
auto deadline_arg = RequestIdleCallback::IdleDeadline::create(*this);
|
||||
// 3. Call callback with deadlineArg as its argument. If an uncaught runtime script error occurs, then report the exception.
|
||||
auto result = callback->invoke(deadline_arg);
|
||||
if (result.is_error())
|
||||
|
@ -689,7 +688,7 @@ u32 Window::request_idle_callback_impl(Bindings::CallbackType& callback)
|
|||
// 3. Let handle be the current value of window's idle callback identifier.
|
||||
auto handle = window.m_idle_callback_identifier;
|
||||
// 4. Push callback to the end of window's list of idle request callbacks, associated with handle.
|
||||
auto handler = [callback = JS::make_handle(callback)](NonnullRefPtr<RequestIdleCallback::IdleDeadline> deadline) -> JS::Completion {
|
||||
auto handler = [callback = JS::make_handle(callback)](JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline> deadline) -> JS::Completion {
|
||||
auto& realm = callback->callback.shape().realm();
|
||||
auto* wrapped_deadline = Bindings::wrap(realm, *deadline);
|
||||
return Bindings::IDL::invoke_callback(const_cast<Bindings::CallbackType&>(*callback), {}, JS::Value(wrapped_deadline));
|
||||
|
|
|
@ -6,18 +6,21 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/RequestIdleCallback/IdleDeadline.h>
|
||||
|
||||
namespace Web::RequestIdleCallback {
|
||||
|
||||
NonnullRefPtr<IdleDeadline> IdleDeadline::create(bool did_timeout)
|
||||
JS::NonnullGCPtr<IdleDeadline> IdleDeadline::create(HTML::Window& window, bool did_timeout)
|
||||
{
|
||||
return adopt_ref(*new IdleDeadline(did_timeout));
|
||||
return *window.heap().allocate<IdleDeadline>(window.realm(), window, did_timeout);
|
||||
}
|
||||
|
||||
IdleDeadline::IdleDeadline(bool did_timeout)
|
||||
: m_did_timeout(did_timeout)
|
||||
IdleDeadline::IdleDeadline(HTML::Window& window, bool did_timeout)
|
||||
: PlatformObject(window.realm())
|
||||
, m_did_timeout(did_timeout)
|
||||
{
|
||||
set_prototype(&window.cached_web_prototype("IdleDeadline"));
|
||||
}
|
||||
|
||||
IdleDeadline::~IdleDeadline() = default;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -8,27 +8,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
|
||||
namespace Web::RequestIdleCallback {
|
||||
|
||||
class IdleDeadline final
|
||||
: public RefCounted<IdleDeadline>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::IdleDeadlineWrapper;
|
||||
using AllowOwnPtr = TrueType;
|
||||
class IdleDeadline final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(IdleDeadline, Bindings::PlatformObject);
|
||||
|
||||
static NonnullRefPtr<IdleDeadline> create(bool did_timeout = false);
|
||||
public:
|
||||
static JS::NonnullGCPtr<IdleDeadline> create(HTML::Window&, bool did_timeout = false);
|
||||
virtual ~IdleDeadline() override;
|
||||
|
||||
double time_remaining() const;
|
||||
bool did_timeout() const { return m_did_timeout; }
|
||||
|
||||
private:
|
||||
IdleDeadline(bool did_timeout);
|
||||
IdleDeadline(HTML::Window&, bool did_timeout);
|
||||
|
||||
bool m_did_timeout { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(IdleDeadline, Web::RequestIdleCallback)
|
||||
|
|
|
@ -157,7 +157,7 @@ libweb_js_wrapper(HTML/WorkerNavigator)
|
|||
libweb_js_wrapper(HighResolutionTime/Performance NO_INSTANCE)
|
||||
libweb_js_wrapper(IntersectionObserver/IntersectionObserver)
|
||||
libweb_js_wrapper(NavigationTiming/PerformanceTiming NO_INSTANCE)
|
||||
libweb_js_wrapper(RequestIdleCallback/IdleDeadline)
|
||||
libweb_js_wrapper(RequestIdleCallback/IdleDeadline NO_INSTANCE)
|
||||
libweb_js_wrapper(ResizeObserver/ResizeObserver)
|
||||
libweb_js_wrapper(SVG/SVGAnimatedLength NO_INSTANCE)
|
||||
libweb_js_wrapper(SVG/SVGClipPathElement NO_INSTANCE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue