2021-09-14 20:51:16 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021-2023, Andreas Kling <andreas@ladybird.org>
|
2022-01-18 19:29:17 +01:00
|
|
|
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
|
2021-09-14 20:51:16 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-18 19:29:17 +01:00
|
|
|
#include <LibJS/CyclicModule.h>
|
2021-09-14 20:51:16 +02:00
|
|
|
#include <LibJS/Forward.h>
|
2022-11-23 11:41:19 +01:00
|
|
|
#include <LibJS/Runtime/ExecutionContext.h>
|
2021-09-14 20:51:16 +02:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
// 16.2.1.6 Source Text Module Records, https://tc39.es/ecma262/#sec-source-text-module-records
|
2022-01-18 19:29:17 +01:00
|
|
|
class SourceTextModule final : public CyclicModule {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(SourceTextModule, CyclicModule);
|
|
|
|
GC_DECLARE_ALLOCATOR(SourceTextModule);
|
2022-09-05 14:31:25 +02:00
|
|
|
|
2021-09-14 20:51:16 +02:00
|
|
|
public:
|
2024-06-16 10:38:35 +02:00
|
|
|
virtual ~SourceTextModule() override;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
static Result<GC::Ref<SourceTextModule>, Vector<ParserError>> parse(StringView source_text, Realm&, StringView filename = {}, Script::HostDefined* host_defined = nullptr);
|
2021-09-14 20:51:16 +02:00
|
|
|
|
2022-01-16 13:16:04 +01:00
|
|
|
Program const& parse_node() const { return *m_ecmascript_code; }
|
|
|
|
|
2023-01-08 19:23:00 -05:00
|
|
|
virtual ThrowCompletionOr<Vector<DeprecatedFlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set) override;
|
|
|
|
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, DeprecatedFlyString const& export_name, Vector<ResolvedBinding> resolve_set = {}) override;
|
2022-01-18 19:29:17 +01:00
|
|
|
|
2022-09-05 14:31:25 +02:00
|
|
|
Object* import_meta() { return m_import_meta; }
|
2023-07-11 23:07:12 -04:00
|
|
|
void set_import_meta(Badge<VM>, Object* import_meta) { m_import_meta = import_meta; }
|
2022-01-18 19:29:17 +01:00
|
|
|
|
|
|
|
protected:
|
2022-05-02 20:54:39 +02:00
|
|
|
virtual ThrowCompletionOr<void> initialize_environment(VM& vm) override;
|
2024-11-15 04:01:23 +13:00
|
|
|
virtual ThrowCompletionOr<void> execute_module(VM& vm, GC::Ptr<PromiseCapability> capability) override;
|
2022-01-18 19:29:17 +01:00
|
|
|
|
|
|
|
private:
|
2022-10-02 21:18:33 +02:00
|
|
|
SourceTextModule(Realm&, StringView filename, Script::HostDefined* host_defined, bool has_top_level_await, NonnullRefPtr<Program> body, Vector<ModuleRequest> requested_modules,
|
2022-01-18 19:29:17 +01:00
|
|
|
Vector<ImportEntry> import_entries, Vector<ExportEntry> local_export_entries,
|
|
|
|
Vector<ExportEntry> indirect_export_entries, Vector<ExportEntry> star_export_entries,
|
2023-02-19 22:07:52 +01:00
|
|
|
RefPtr<ExportStatement const> default_export);
|
2022-01-18 19:29:17 +01:00
|
|
|
|
2022-09-05 14:31:25 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2023-11-27 16:45:45 +01:00
|
|
|
NonnullRefPtr<Program> m_ecmascript_code; // [[ECMAScriptCode]]
|
|
|
|
NonnullOwnPtr<ExecutionContext> m_execution_context; // [[Context]]
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<Object> m_import_meta; // [[ImportMeta]]
|
2023-11-27 16:45:45 +01:00
|
|
|
Vector<ImportEntry> m_import_entries; // [[ImportEntries]]
|
|
|
|
Vector<ExportEntry> m_local_export_entries; // [[LocalExportEntries]]
|
|
|
|
Vector<ExportEntry> m_indirect_export_entries; // [[IndirectExportEntries]]
|
|
|
|
Vector<ExportEntry> m_star_export_entries; // [[StarExportEntries]]
|
2022-01-18 19:29:17 +01:00
|
|
|
|
2023-02-19 22:07:52 +01:00
|
|
|
RefPtr<ExportStatement const> m_default_export; // Note: Not from the spec
|
2021-09-14 20:51:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|