ladybird/Userland/Libraries/LibJS/Script.h
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

51 lines
1.4 KiB
C++

/*
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibJS/Heap/Handle.h>
#include <LibJS/ParserError.h>
#include <LibJS/Runtime/Realm.h>
namespace JS {
// 16.1.4 Script Records, https://tc39.es/ecma262/#sec-script-records
class Script final : public Cell {
JS_CELL(Script, Cell);
public:
struct HostDefined {
virtual ~HostDefined() = default;
virtual void visit_host_defined_self(Cell::Visitor&) = 0;
};
virtual ~Script() override;
static Result<NonnullGCPtr<Script>, Vector<ParserError>> parse(StringView source_text, Realm&, StringView filename = {}, HostDefined* = nullptr, size_t line_number_offset = 1);
Realm& realm() { return *m_realm; }
Program const& parse_node() const { return *m_parse_node; }
HostDefined* host_defined() const { return m_host_defined; }
StringView filename() const { return m_filename; }
private:
Script(Realm&, StringView filename, NonnullRefPtr<Program>, HostDefined* = nullptr);
virtual void visit_edges(Cell::Visitor&) override;
GCPtr<Realm> m_realm; // [[Realm]]
NonnullRefPtr<Program> m_parse_node; // [[ECMAScriptCode]]
// Needed for potential lookups of modules.
DeprecatedString m_filename;
HostDefined* m_host_defined { nullptr }; // [[HostDefined]]
};
}