forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-module.cc
More file actions
63 lines (54 loc) Β· 2.17 KB
/
runtime-module.cc
File metadata and controls
63 lines (54 loc) Β· 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/execution/arguments-inl.h"
#include "src/objects/js-promise.h"
#include "src/objects/source-text-module.h"
namespace v8 {
namespace internal {
RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
HandleScope scope(isolate);
DCHECK_LE(3, args.length());
DCHECK_GE(4, args.length());
DirectHandle<JSFunction> function = args.at<JSFunction>(0);
Handle<Object> specifier = args.at(1);
ModuleImportPhase phase =
static_cast<ModuleImportPhase>(args.smi_value_at(2));
MaybeDirectHandle<Object> import_options;
if (args.length() == 4) {
import_options = args.at<Object>(3);
}
DirectHandle<Script> referrer_script(
Cast<Script>(function->shared()->script())->GetEvalOrigin(), isolate);
RETURN_RESULT_OR_FAILURE(
isolate, isolate->RunHostImportModuleDynamicallyCallback(
referrer_script, specifier, phase, import_options));
}
RUNTIME_FUNCTION(Runtime_GetModuleNamespace) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
int module_request = args.smi_value_at(0);
DirectHandle<SourceTextModule> module(isolate->context()->module(), isolate);
return *SourceTextModule::GetModuleNamespace(isolate, module, module_request);
}
RUNTIME_FUNCTION(Runtime_GetImportMetaObject) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
DirectHandle<SourceTextModule> module(isolate->context()->module(), isolate);
RETURN_RESULT_OR_FAILURE(isolate,
SourceTextModule::GetImportMeta(isolate, module));
}
RUNTIME_FUNCTION(Runtime_GetModuleNamespaceExport) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
DirectHandle<JSModuleNamespace> module_namespace =
args.at<JSModuleNamespace>(0);
Handle<String> name = args.at<String>(1);
if (!module_namespace->HasExport(isolate, name)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewReferenceError(MessageTemplate::kNotDefined, name));
}
RETURN_RESULT_OR_FAILURE(isolate, module_namespace->GetExport(isolate, name));
}
} // namespace internal
} // namespace v8