diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-05 19:04:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-06 08:26:26 +0200 |
commit | 6e5c9970bf00dbec7b41db2030f6b613fd2a373f (patch) | |
tree | d379448919ffb545744f2cdccde5f4904cc44522 /Libraries/LibWeb | |
parent | 003741db1c3aa80ab84d7b10a867c02b7eb9a5c0 (diff) | |
download | serenity-6e5c9970bf00dbec7b41db2030f6b613fd2a373f.zip |
LibWeb: Allow window.setTimeout() with no interval
If no interval is specified, it will be treated as 0 and the callback
function will be called on the next event loop iteration.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/Bindings/WindowObject.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp index ff6aab0a72..5bd017a228 100644 --- a/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -104,14 +104,19 @@ JS::Value WindowObject::set_timeout(JS::Interpreter& interpreter) if (!impl) return {}; auto& arguments = interpreter.call_frame().arguments; - if (arguments.size() < 2) + if (arguments.size() < 1) return {}; auto* callback_object = arguments[0].to_object(interpreter.heap()); if (!callback_object) return {}; if (!callback_object->is_function()) return interpreter.throw_exception<JS::Error>("TypeError", "Not a function"); - impl->set_timeout(*static_cast<JS::Function*>(callback_object), arguments[1].to_i32()); + + i32 interval = 0; + if (interpreter.argument_count() >= 2) + interval = arguments[1].to_i32(); + + impl->set_timeout(*static_cast<JS::Function*>(callback_object), interval); return {}; } |