/* * Copyright (c) 2021, Andreas Kling * Copyright (c) 2022, David Tuin * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace JS { // 16.2.1.6 Source Text Module Records, https://tc39.es/ecma262/#sec-source-text-module-records class SourceTextModule final : public CyclicModule { JS_CELL(SourceTextModule, CyclicModule); public: static Result, Vector> parse(StringView source_text, Realm&, StringView filename = {}, Script::HostDefined* host_defined = nullptr); Program const& parse_node() const { return *m_ecmascript_code; } virtual ThrowCompletionOr> get_exported_names(VM& vm, Vector export_star_set) override; virtual ThrowCompletionOr resolve_export(VM& vm, DeprecatedFlyString const& export_name, Vector resolve_set = {}) override; Object* import_meta() { return m_import_meta; } void set_import_meta(Badge, Object* import_meta) { m_import_meta = import_meta; } protected: virtual ThrowCompletionOr initialize_environment(VM& vm) override; virtual ThrowCompletionOr execute_module(VM& vm, GCPtr capability) override; private: SourceTextModule(Realm&, StringView filename, Script::HostDefined* host_defined, bool has_top_level_await, NonnullRefPtr body, Vector requested_modules, Vector import_entries, Vector local_export_entries, Vector indirect_export_entries, Vector star_export_entries, RefPtr default_export); virtual void visit_edges(Cell::Visitor&) override; NonnullRefPtr m_ecmascript_code; // [[ECMAScriptCode]] ExecutionContext m_execution_context; // [[Context]] GCPtr m_import_meta; // [[ImportMeta]] Vector m_import_entries; // [[ImportEntries]] Vector m_local_export_entries; // [[LocalExportEntries]] Vector m_indirect_export_entries; // [[IndirectExportEntries]] Vector m_star_export_entries; // [[StarExportEntries]] RefPtr m_default_export; // Note: Not from the spec }; }