2021-09-09 13:03:01 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2021-2023, Andreas Kling <andreas@ladybird.org>
|
2021-09-09 13:03:01 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-09-05 09:32:33 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2022-10-02 18:17:33 -03:00
|
|
|
#include <LibJS/Script.h>
|
2024-03-18 00:22:27 -03:00
|
|
|
#include <LibURL/URL.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2022-06-27 15:50:40 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2021-09-09 13:03:01 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script
|
2024-10-25 00:27:26 -03:00
|
|
|
// https://whatpr.org/html/9893/webappapis.html#concept-script
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API Script
|
2022-10-02 18:17:33 -03:00
|
|
|
: public JS::Cell
|
|
|
|
|
, public JS::Script::HostDefined {
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_CELL(Script, JS::Cell);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(Script);
|
2022-09-05 09:32:33 -03:00
|
|
|
|
2021-09-09 13:03:01 -03:00
|
|
|
public:
|
2022-09-05 09:32:33 -03:00
|
|
|
virtual ~Script() override;
|
2021-09-09 13:03:01 -03:00
|
|
|
|
2025-02-15 23:53:04 -03:00
|
|
|
Optional<URL::URL> const& base_url() const { return m_base_url; }
|
2023-12-16 11:19:34 -03:00
|
|
|
ByteString const& filename() const { return m_filename; }
|
2021-09-09 13:03:01 -03:00
|
|
|
|
2024-10-25 00:27:26 -03:00
|
|
|
JS::Realm& realm() { return m_realm; }
|
|
|
|
|
EnvironmentSettingsObject& settings_object();
|
2022-06-27 15:50:40 -03:00
|
|
|
|
2023-05-18 14:05:56 -03:00
|
|
|
[[nodiscard]] JS::Value error_to_rethrow() const { return m_error_to_rethrow; }
|
|
|
|
|
void set_error_to_rethrow(JS::Value value) { m_error_to_rethrow = value; }
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] JS::Value parse_error() const { return m_parse_error; }
|
|
|
|
|
void set_parse_error(JS::Value value) { m_parse_error = value; }
|
|
|
|
|
|
2021-09-09 13:03:01 -03:00
|
|
|
protected:
|
2025-02-15 23:53:04 -03:00
|
|
|
Script(Optional<URL::URL> base_url, ByteString filename, JS::Realm&);
|
2021-09-09 13:03:01 -03:00
|
|
|
|
2023-05-18 14:05:56 -03:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
|
|
2021-09-09 13:03:01 -03:00
|
|
|
private:
|
2025-04-18 05:23:02 -03:00
|
|
|
virtual bool is_script() const final { return true; }
|
2022-10-02 18:17:33 -03:00
|
|
|
virtual void visit_host_defined_self(JS::Cell::Visitor&) override;
|
|
|
|
|
|
2025-02-15 23:53:04 -03:00
|
|
|
Optional<URL::URL> m_base_url;
|
2023-12-16 11:19:34 -03:00
|
|
|
ByteString m_filename;
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<JS::Realm> m_realm;
|
2023-05-18 14:05:56 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error
|
|
|
|
|
JS::Value m_parse_error;
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-error-to-rethrow
|
|
|
|
|
JS::Value m_error_to_rethrow;
|
2021-09-09 13:03:01 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2025-04-18 05:23:02 -03:00
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool JS::Script::HostDefined::fast_is<Web::HTML::Script>() const { return is_script(); }
|