/* * Copyright (c) 2022, David Tuin * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace JS { // 1.2 Synthetic Module Records, https://tc39.es/proposal-json-modules/#sec-synthetic-module-records class SyntheticModule final : public Module { public: using EvaluationFunction = Function(SyntheticModule&)>; SyntheticModule(Vector export_names, EvaluationFunction evaluation_steps, Realm& realm, StringView filename); static NonnullRefPtr create_default_export_synthetic_module(Value default_export, Realm& realm, StringView filename); ThrowCompletionOr set_synthetic_module_export(FlyString const& export_name, Value export_value); virtual ThrowCompletionOr link(VM& vm) override; virtual ThrowCompletionOr evaluate(VM& vm) override; virtual ThrowCompletionOr> get_exported_names(VM& vm, Vector export_star_set) override; virtual ThrowCompletionOr resolve_export(VM& vm, FlyString const& export_name, Vector resolve_set) override; private: Vector m_export_names; // [[ExportNames]] EvaluationFunction m_evaluation_steps; // [[EvaluationSteps]] }; ThrowCompletionOr> parse_json_module(StringView source_text, Realm& realm, StringView filename); }