forked from v8/v8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-module.cc
More file actions
75 lines (61 loc) · 2.49 KB
/
Copy pathruntime-module.cc
File metadata and controls
75 lines (61 loc) · 2.49 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
64
65
66
67
68
69
70
71
72
73
74
75
// 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/runtime/runtime-utils.h"
#include "src/arguments.h"
#include "src/counters.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, specifier, 1);
Handle<JSPromise> promise = isolate->factory()->NewJSPromise();
Handle<String> specifier_str;
MaybeHandle<String> maybe_specifier = Object::ToString(isolate, specifier);
if (!maybe_specifier.ToHandle(&specifier_str)) {
DCHECK(isolate->has_pending_exception());
Handle<Object> reason(isolate->pending_exception(), isolate);
isolate->clear_pending_exception();
Handle<Object> argv[] = {promise, reason,
isolate->factory()->ToBoolean(false)};
RETURN_FAILURE_ON_EXCEPTION(
isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
isolate->factory()->undefined_value(),
arraysize(argv), argv))
return *promise;
}
DCHECK(!isolate->has_pending_exception());
Handle<Script> script(Script::cast(function->shared()->script()));
Handle<String> source_url(String::cast(script->name()));
isolate->RunHostImportModuleDynamicallyCallback(source_url, specifier_str,
promise);
return *promise;
}
RUNTIME_FUNCTION(Runtime_GetModuleNamespace) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_SMI_ARG_CHECKED(module_request, 0);
Handle<Module> module(isolate->context()->module());
return *Module::GetModuleNamespace(module, module_request);
}
RUNTIME_FUNCTION(Runtime_LoadModuleVariable) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_SMI_ARG_CHECKED(index, 0);
Handle<Module> module(isolate->context()->module());
return *Module::LoadVariable(module, index);
}
RUNTIME_FUNCTION(Runtime_StoreModuleVariable) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_SMI_ARG_CHECKED(index, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
Handle<Module> module(isolate->context()->module());
Module::StoreVariable(module, index, value);
return isolate->heap()->undefined_value();
}
} // namespace internal
} // namespace v8