1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:47:35 +00:00

LibWeb: Implement setTimeout/setInterval with ESO according to the spec

Our setInterval implementation currently crashes on DuckDuckGo when it's
invoked with a string argument. In this path, we were creating a native
function to evaluate and execute that string. That evaluation was always
returning a Completion, but NativeFunction expects ThrowCompletionOr.
The conversion from Completion to ThrowCompletionOr would fail a VERIFY
because that conversion is only valid if the Completion is an error; but
we would trigger this conversion even on success.

This change re-implements setTimeout & setInterval in direct accordance
with the spec. So we avoid making that NativeFunction altogether, and
DDG can progress past its invocation to the timer. With this change, we
also have other features we did not previously support, such as passing
any number of arguments to the timers. This does not implement handling
of nesting levels yet.
This commit is contained in:
Timothy Flynn 2022-03-04 10:41:12 -05:00 committed by Andreas Kling
parent 8156ec5da8
commit 18b9d02edd
6 changed files with 184 additions and 138 deletions

View file

@ -8,15 +8,20 @@
#pragma once
#include <AK/TypeCasts.h>
#include <AK/Variant.h>
#include <AK/Weakable.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibWeb/Bindings/CallbackType.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/GlobalEventHandlers.h>
namespace Web {
namespace Bindings {
// https://html.spec.whatwg.org/#timerhandler
using TimerHandler = Variant<CallbackType, String>;
class WindowObject
: public JS::GlobalObject
, public Weakable<WindowObject> {