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
|
|
|
|
|
|
Libraries: Clean up UTF-16 source text paths
Store parser errors, source range filenames, source code filenames,
module source, and Rust parser errors as UTF-16 where they flow back
into JavaScript-visible strings. Keep byte-oriented source buffers
byte-backed.
Remove temporary PrimitiveString, ByteString, and UTF-8 detours from
JSON, RegExp, module debug logging, print formatting, and tests.
2026-06-21 14:03:19 -03:00
|
|
|
#include <AK/Utf16String.h>
|
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
|
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; }
|
Libraries: Clean up UTF-16 source text paths
Store parser errors, source range filenames, source code filenames,
module source, and Rust parser errors as UTF-16 where they flow back
into JavaScript-visible strings. Keep byte-oriented source buffers
byte-backed.
Remove temporary PrimitiveString, ByteString, and UTF-8 detours from
JSON, RegExp, module debug logging, print formatting, and tests.
2026-06-21 14:03:19 -03:00
|
|
|
Utf16String const& display_filename() const { return m_display_filename; }
|
2021-09-09 13:03:01 -03:00
|
|
|
|
2024-10-25 00:27:26 -03:00
|
|
|
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:
|
2026-04-03 13:12:46 -03:00
|
|
|
Script(Optional<URL::URL> base_url, ByteString filename, EnvironmentSettingsObject&);
|
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;
|
Libraries: Clean up UTF-16 source text paths
Store parser errors, source range filenames, source code filenames,
module source, and Rust parser errors as UTF-16 where they flow back
into JavaScript-visible strings. Keep byte-oriented source buffers
byte-backed.
Remove temporary PrimitiveString, ByteString, and UTF-8 detours from
JSON, RegExp, module debug logging, print formatting, and tests.
2026-06-21 14:03:19 -03:00
|
|
|
Utf16String m_display_filename;
|
2026-04-03 13:12:46 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/webappapis.html#settings-object
|
|
|
|
|
// An environment settings object, containing various settings that are shared with other scripts in the same context.
|
|
|
|
|
GC::Ref<EnvironmentSettingsObject> m_settings;
|
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(); }
|