summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-22 21:20:40 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-22 21:20:40 +0100
commit6f235ad93f48107d48607f7315ff1372915144f0 (patch)
treeffb171b7897e80af3fc4ad56ec9f2e3c53331276 /Libraries/LibWeb
parent39045bfde82be80052eda5e9502b43b22ef3eb9e (diff)
downloadserenity-6f235ad93f48107d48607f7315ff1372915144f0.zip
LibWeb: Implement cancelAnimationFrame()
These functions (rAF and cAF) should eventually stop using raw ID's from GUI::DisplayLink as their identifiers. That's a FIXME for now. :^)
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 4f7498c2ec..058c702d29 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -373,6 +373,7 @@ JS::Interpreter& Document::interpreter()
ASSERT(arguments[0].is_object());
ASSERT(arguments[0].as_object()->is_function());
auto callback = make_handle(const_cast<JS::Object*>(arguments[0].as_object()));
+ // FIXME: Don't hand out raw DisplayLink ID's to JavaScript!
i32 link_id = GUI::DisplayLink::register_callback([this, callback](i32 link_id) {
const_cast<JS::Function*>(static_cast<const JS::Function*>(callback.cell()))->call(*m_interpreter, {});
GUI::DisplayLink::unregister_callback(link_id);
@@ -380,6 +381,14 @@ JS::Interpreter& Document::interpreter()
return JS::Value(link_id);
});
+ m_interpreter->global_object().put_native_function("cancelAnimationFrame", [](JS::Object*, const Vector<JS::Value>& arguments) -> JS::Value {
+ if (arguments.size() < 1)
+ return JS::js_undefined();
+ // FIXME: We should not be passing untrusted numbers to DisplayLink::unregistered_callback()!
+ GUI::DisplayLink::unregister_callback(arguments[0].to_i32());
+ return JS::js_undefined();
+ });
+
m_interpreter->global_object().put_native_property(
"document",
[this](JS::Object*) {