Task.cpp 772 B

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