Serenity Operating System
at master 38 lines 772 B view raw
1/* 2 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibWeb/DOM/Document.h> 8#include <LibWeb/HTML/EventLoop/Task.h> 9 10namespace Web::HTML { 11 12Task::Task(Source source, DOM::Document const* document, JS::SafeFunction<void()> steps) 13 : m_source(source) 14 , m_steps(move(steps)) 15 , m_document(JS::make_handle(document)) 16{ 17} 18 19Task::~Task() = default; 20 21void Task::execute() 22{ 23 m_steps(); 24} 25 26// https://html.spec.whatwg.org/#concept-task-runnable 27bool Task::is_runnable() const 28{ 29 // A task is runnable if its document is either null or fully active. 30 return !m_document.ptr() || m_document->is_fully_active(); 31} 32 33DOM::Document const* Task::document() const 34{ 35 return m_document.ptr(); 36} 37 38}