2022-01-27 13:51:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, David Tuin <davidot@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibJS/Module.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
// 1.2 Synthetic Module Records, https://tc39.es/proposal-json-modules/#sec-synthetic-module-records
|
|
|
|
class SyntheticModule final : public Module {
|
2022-09-05 12:31:25 +00:00
|
|
|
JS_CELL(SyntheticModule, Module);
|
2023-11-19 08:45:05 +00:00
|
|
|
JS_DECLARE_ALLOCATOR(SyntheticModule);
|
2022-09-05 12:31:25 +00:00
|
|
|
|
2022-01-27 13:51:21 +00:00
|
|
|
public:
|
|
|
|
using EvaluationFunction = Function<ThrowCompletionOr<void>(SyntheticModule&)>;
|
|
|
|
|
2022-09-05 12:31:25 +00:00
|
|
|
static NonnullGCPtr<SyntheticModule> create_default_export_synthetic_module(Value default_export, Realm& realm, StringView filename);
|
2022-01-27 13:51:21 +00:00
|
|
|
|
2023-01-09 00:23:00 +00:00
|
|
|
ThrowCompletionOr<void> set_synthetic_module_export(DeprecatedFlyString const& export_name, Value export_value);
|
2022-01-27 13:51:21 +00:00
|
|
|
|
|
|
|
virtual ThrowCompletionOr<void> link(VM& vm) override;
|
|
|
|
virtual ThrowCompletionOr<Promise*> evaluate(VM& vm) override;
|
2023-01-09 00:23:00 +00: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-27 13:51:21 +00:00
|
|
|
|
|
|
|
private:
|
2023-01-09 00:23:00 +00:00
|
|
|
SyntheticModule(Vector<DeprecatedFlyString> export_names, EvaluationFunction evaluation_steps, Realm& realm, StringView filename);
|
2022-09-05 12:31:25 +00:00
|
|
|
|
2023-01-09 00:23:00 +00:00
|
|
|
Vector<DeprecatedFlyString> m_export_names; // [[ExportNames]]
|
|
|
|
EvaluationFunction m_evaluation_steps; // [[EvaluationSteps]]
|
2022-01-27 13:51:21 +00:00
|
|
|
};
|
|
|
|
|
2022-09-05 12:31:25 +00:00
|
|
|
ThrowCompletionOr<NonnullGCPtr<Module>> parse_json_module(StringView source_text, Realm& realm, StringView filename);
|
2022-01-27 13:51:21 +00:00
|
|
|
|
|
|
|
}
|