Script.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/URL.h>
  8. #include <LibJS/Heap/Cell.h>
  9. #include <LibJS/Script.h>
  10. #include <LibWeb/Forward.h>
  11. namespace Web::HTML {
  12. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script
  13. class Script
  14. : public JS::Cell
  15. , public JS::Script::HostDefined {
  16. JS_CELL(Script, JS::Cell);
  17. public:
  18. virtual ~Script() override;
  19. AK::URL const& base_url() const { return m_base_url; }
  20. DeprecatedString const& filename() const { return m_filename; }
  21. EnvironmentSettingsObject& settings_object() { return m_settings_object; }
  22. [[nodiscard]] JS::Value error_to_rethrow() const { return m_error_to_rethrow; }
  23. void set_error_to_rethrow(JS::Value value) { m_error_to_rethrow = value; }
  24. [[nodiscard]] JS::Value parse_error() const { return m_parse_error; }
  25. void set_parse_error(JS::Value value) { m_parse_error = value; }
  26. protected:
  27. Script(AK::URL base_url, DeprecatedString filename, EnvironmentSettingsObject& environment_settings_object);
  28. virtual void visit_edges(Visitor&) override;
  29. private:
  30. virtual void visit_host_defined_self(JS::Cell::Visitor&) override;
  31. AK::URL m_base_url;
  32. DeprecatedString m_filename;
  33. JS::NonnullGCPtr<EnvironmentSettingsObject> m_settings_object;
  34. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error
  35. JS::Value m_parse_error;
  36. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-error-to-rethrow
  37. JS::Value m_error_to_rethrow;
  38. };
  39. }