Skip to content

Commit

Permalink
fixup! vm: add support for import assertions in dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Oct 5, 2021
1 parent 085b12c commit adf6993
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(that);
}

static Local<Object> createImportAssertionContainer(Environment* env,
Isolate* isolate, Local<FixedArray> raw_assertions) {
Local<Object> assertions =
Object::New(isolate, v8::Null(env->isolate()), nullptr, nullptr, 0);
for (int i = 0; i < raw_assertions->Length(); i += 3) {
assertions
->Set(env->context(),
raw_assertions->Get(env->context(), i).As<String>(),
raw_assertions->Get(env->context(), i + 1).As<Value>())
.ToChecked();
}

return assertions;
}

void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = args.GetIsolate();
Expand Down Expand Up @@ -288,14 +303,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {

Local<FixedArray> raw_assertions = module_request->GetImportAssertions();
Local<Object> assertions =
Object::New(isolate, v8::Null(env->isolate()), nullptr, nullptr, 0);
for (int i = 0; i < raw_assertions->Length(); i += 3) {
assertions
->Set(env->context(),
raw_assertions->Get(env->context(), i).As<String>(),
raw_assertions->Get(env->context(), i + 1).As<Value>())
.ToChecked();
}
createImportAssertionContainer(env, isolate, raw_assertions);

Local<Value> argv[] = {
specifier,
Expand Down Expand Up @@ -603,14 +611,7 @@ static MaybeLocal<Promise> ImportModuleDynamically(
}

Local<Object> assertions =
Object::New(isolate, v8::Null(env->isolate()), nullptr, nullptr, 0);
for (int i = 0; i < import_assertions->Length(); i += 2) {
assertions
->Set(env->context(),
Local<String>::Cast(import_assertions->Get(env->context(), i)),
Local<Value>::Cast(import_assertions->Get(env->context(), i + 1)))
.ToChecked();
}
createImportAssertionContainer(env, isolate, import_assertions);

Local<Value> import_args[] = {
object,
Expand Down

0 comments on commit adf6993

Please sign in to comment.