|
|
@@ -26,17 +26,20 @@ using v8::Array; |
|
|
using v8::ArrayBufferView; |
|
|
using v8::Context; |
|
|
using v8::EscapableHandleScope; |
|
|
using v8::FixedArray; |
|
|
using v8::Function; |
|
|
using v8::FunctionCallbackInfo; |
|
|
using v8::FunctionTemplate; |
|
|
using v8::HandleScope; |
|
|
using v8::Int32; |
|
|
using v8::Integer; |
|
|
using v8::IntegrityLevel; |
|
|
using v8::Isolate; |
|
|
using v8::Local; |
|
|
using v8::MaybeLocal; |
|
|
using v8::MicrotaskQueue; |
|
|
using v8::Module; |
|
|
using v8::ModuleRequest; |
|
|
using v8::Number; |
|
|
using v8::Object; |
|
|
using v8::PrimitiveArray; |
|
|
@@ -128,8 +131,8 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { |
|
|
context = contextify_context->context(); |
|
|
} |
|
|
|
|
|
Local<Integer> line_offset; |
|
|
Local<Integer> column_offset; |
|
|
int line_offset = 0; |
|
|
int column_offset = 0; |
|
|
|
|
|
bool synthetic = args[2]->IsArray(); |
|
|
if (synthetic) { |
|
|
@@ -139,9 +142,9 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { |
|
|
// new ModuleWrap(url, context, source, lineOffset, columOffset, cachedData) |
|
|
CHECK(args[2]->IsString()); |
|
|
CHECK(args[3]->IsNumber()); |
|
|
line_offset = args[3].As<Integer>(); |
|
|
line_offset = args[3].As<Int32>()->Value(); |
|
|
CHECK(args[4]->IsNumber()); |
|
|
column_offset = args[4].As<Integer>(); |
|
|
column_offset = args[4].As<Int32>()->Value(); |
|
|
} |
|
|
|
|
|
Local<PrimitiveArray> host_defined_options = |
|
|
@@ -185,14 +188,14 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { |
|
|
|
|
|
Local<String> source_text = args[2].As<String>(); |
|
|
ScriptOrigin origin(url, |
|
|
line_offset, // line offset |
|
|
column_offset, // column offset |
|
|
True(isolate), // is cross origin |
|
|
Local<Integer>(), // script id |
|
|
line_offset, |
|
|
column_offset, |
|
|
true, // is cross origin |
|
|
-1, // script id |
|
|
Local<Value>(), // source map URL |
|
|
False(isolate), // is opaque (?) |
|
|
False(isolate), // is WASM |
|
|
True(isolate), // is ES Module |
|
|
false, // is opaque (?) |
|
|
false, // is WASM |
|
|
true, // is ES Module |
|
|
host_defined_options); |
|
|
ScriptCompiler::Source source(source_text, origin, cached_data); |
|
|
ScriptCompiler::CompileOptions options; |
|
|
@@ -270,12 +273,15 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { |
|
|
Local<Context> mod_context = obj->context(); |
|
|
Local<Module> module = obj->module_.Get(isolate); |
|
|
|
|
|
const int module_requests_length = module->GetModuleRequestsLength(); |
|
|
Local<FixedArray> module_requests = module->GetModuleRequests(); |
|
|
const int module_requests_length = module_requests->Length(); |
|
|
MaybeStackBuffer<Local<Value>, 16> promises(module_requests_length); |
|
|
|
|
|
// call the dependency resolve callbacks |
|
|
for (int i = 0; i < module_requests_length; i++) { |
|
|
Local<String> specifier = module->GetModuleRequest(i); |
|
|
Local<ModuleRequest> module_request = |
|
|
module_requests->Get(env->context(), i).As<ModuleRequest>(); |
|
|
Local<String> specifier = module_request->GetSpecifier(); |
|
|
Utf8Value specifier_utf8(env->isolate(), specifier); |
|
|
std::string specifier_std(*specifier_utf8, specifier_utf8.length()); |
|
|
|
|
|
@@ -311,7 +317,7 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) { |
|
|
Local<Context> context = obj->context(); |
|
|
Local<Module> module = obj->module_.Get(isolate); |
|
|
TryCatchScope try_catch(env); |
|
|
USE(module->InstantiateModule(context, ResolveCallback)); |
|
|
USE(module->InstantiateModule(context, ResolveModuleCallback)); |
|
|
|
|
|
// clear resolve cache on instantiate |
|
|
obj->resolve_cache_.clear(); |
|
|
@@ -453,12 +459,16 @@ void ModuleWrap::GetStaticDependencySpecifiers( |
|
|
|
|
|
Local<Module> module = obj->module_.Get(env->isolate()); |
|
|
|
|
|
int count = module->GetModuleRequestsLength(); |
|
|
Local<FixedArray> module_requests = module->GetModuleRequests(); |
|
|
int count = module_requests->Length(); |
|
|
|
|
|
MaybeStackBuffer<Local<Value>, 16> specifiers(count); |
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
specifiers[i] = module->GetModuleRequest(i); |
|
|
for (int i = 0; i < count; i++) { |
|
|
Local<ModuleRequest> module_request = |
|
|
module_requests->Get(env->context(), i).As<ModuleRequest>(); |
|
|
specifiers[i] = module_request->GetSpecifier(); |
|
|
} |
|
|
|
|
|
args.GetReturnValue().Set( |
|
|
Array::New(env->isolate(), specifiers.out(), count)); |
|
|
@@ -473,9 +483,11 @@ void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) { |
|
|
args.GetReturnValue().Set(module->GetException()); |
|
|
} |
|
|
|
|
|
MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context, |
|
|
Local<String> specifier, |
|
|
Local<Module> referrer) { |
|
|
MaybeLocal<Module> ModuleWrap::ResolveModuleCallback( |
|
|
Local<Context> context, |
|
|
Local<String> specifier, |
|
|
Local<FixedArray> import_assertions, |
|
|
Local<Module> referrer) { |
|
|
Environment* env = Environment::GetCurrent(context); |
|
|
if (env == nullptr) { |
|
|
Isolate* isolate = context->GetIsolate(); |
|
|
@@ -524,14 +536,14 @@ static MaybeLocal<Promise> ImportModuleDynamically( |
|
|
Local<Context> context, |
|
|
Local<ScriptOrModule> referrer, |
|
|
Local<String> specifier) { |
|
|
Isolate* iso = context->GetIsolate(); |
|
|
Isolate* isolate = context->GetIsolate(); |
|
|
Environment* env = Environment::GetCurrent(context); |
|
|
if (env == nullptr) { |
|
|
THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(iso); |
|
|
THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate); |
|
|
return MaybeLocal<Promise>(); |
|
|
} |
|
|
|
|
|
EscapableHandleScope handle_scope(iso); |
|
|
EscapableHandleScope handle_scope(isolate); |
|
|
|
|
|
Local<Function> import_callback = |
|
|
env->host_import_module_dynamically_callback(); |
|
|
@@ -550,11 +562,11 @@ static MaybeLocal<Promise> ImportModuleDynamically( |
|
|
|
|
|
Local<Value> object; |
|
|
|
|
|
int type = options->Get(iso, HostDefinedOptions::kType) |
|
|
int type = options->Get(isolate, HostDefinedOptions::kType) |
|
|
.As<Number>() |
|
|
->Int32Value(context) |
|
|
.ToChecked(); |
|
|
uint32_t id = options->Get(iso, HostDefinedOptions::kID) |
|
|
uint32_t id = options->Get(isolate, HostDefinedOptions::kID) |
|
|
.As<Number>() |
|
|
->Uint32Value(context) |
|
|
.ToChecked(); |
|
|
@@ -580,7 +592,7 @@ static MaybeLocal<Promise> ImportModuleDynamically( |
|
|
Local<Value> result; |
|
|
if (import_callback->Call( |
|
|
context, |
|
|
Undefined(iso), |
|
|
Undefined(isolate), |
|
|
arraysize(import_args), |
|
|
import_args).ToLocal(&result)) { |
|
|
CHECK(result->IsPromise()); |
|
|
@@ -592,16 +604,16 @@ static MaybeLocal<Promise> ImportModuleDynamically( |
|
|
|
|
|
void ModuleWrap::SetImportModuleDynamicallyCallback( |
|
|
const FunctionCallbackInfo<Value>& args) { |
|
|
Isolate* iso = args.GetIsolate(); |
|
|
Isolate* isolate = args.GetIsolate(); |
|
|
Environment* env = Environment::GetCurrent(args); |
|
|
HandleScope handle_scope(iso); |
|
|
HandleScope handle_scope(isolate); |
|
|
|
|
|
CHECK_EQ(args.Length(), 1); |
|
|
CHECK(args[0]->IsFunction()); |
|
|
Local<Function> import_callback = args[0].As<Function>(); |
|
|
env->set_host_import_module_dynamically_callback(import_callback); |
|
|
|
|
|
iso->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically); |
|
|
isolate->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically); |
|
|
} |
|
|
|
|
|
void ModuleWrap::HostInitializeImportMetaObjectCallback( |
|
|
|