From adf69938100fad70d43683e493f9fc20be49e65c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 5 Oct 2021 19:30:23 +0200 Subject: [PATCH] fixup! vm: add support for import assertions in dynamic imports --- src/module_wrap.cc | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 1e7fb959a6ea8e..aeb0d2cb37313b 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -253,6 +253,21 @@ void ModuleWrap::New(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(that); } +static Local createImportAssertionContainer(Environment* env, + Isolate* isolate, Local raw_assertions) { + Local 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(), + raw_assertions->Get(env->context(), i + 1).As()) + .ToChecked(); + } + + return assertions; +} + void ModuleWrap::Link(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = args.GetIsolate(); @@ -288,14 +303,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo& args) { Local raw_assertions = module_request->GetImportAssertions(); Local 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(), - raw_assertions->Get(env->context(), i + 1).As()) - .ToChecked(); - } + createImportAssertionContainer(env, isolate, raw_assertions); Local argv[] = { specifier, @@ -603,14 +611,7 @@ static MaybeLocal ImportModuleDynamically( } Local 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::Cast(import_assertions->Get(env->context(), i)), - Local::Cast(import_assertions->Get(env->context(), i + 1))) - .ToChecked(); - } + createImportAssertionContainer(env, isolate, import_assertions); Local import_args[] = { object,