Script.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <LibJS/Heap/Cell.h>
  8. #include <LibJS/Script.h>
  9. #include <LibURL/URL.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. JS_DECLARE_ALLOCATOR(Script);
  18. public:
  19. virtual ~Script() override;
  20. URL::URL const& base_url() const { return m_base_url; }
  21. ByteString const& filename() const { return m_filename; }
  22. EnvironmentSettingsObject& settings_object() { return m_settings_object; }
  23. [[nodiscard]] JS::Value error_to_rethrow() const { return m_error_to_rethrow; }
  24. void set_error_to_rethrow(JS::Value value) { m_error_to_rethrow = value; }
  25. [[nodiscard]] JS::Value parse_error() const { return m_parse_error; }
  26. void set_parse_error(JS::Value value) { m_parse_error = value; }
  27. protected:
  28. Script(URL::URL base_url, ByteString filename, EnvironmentSettingsObject& environment_settings_object);
  29. virtual void visit_edges(Visitor&) override;
  30. private:
  31. virtual void visit_host_defined_self(JS::Cell::Visitor&) override;
  32. URL::URL m_base_url;
  33. ByteString m_filename;
  34. JS::NonnullGCPtr<EnvironmentSettingsObject> m_settings_object;
  35. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error
  36. JS::Value m_parse_error;
  37. // https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-error-to-rethrow
  38. JS::Value m_error_to_rethrow;
  39. };
  40. }