@@ -253,6 +253,21 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
253253 args.GetReturnValue ().Set (that);
254254}
255255
256+ static Local<Object> createImportAssertionContainer (Environment* env,
257+ Isolate* isolate, Local<FixedArray> raw_assertions) {
258+ Local<Object> assertions =
259+ Object::New (isolate, v8::Null (env->isolate ()), nullptr , nullptr , 0 );
260+ for (int i = 0 ; i < raw_assertions->Length (); i += 3 ) {
261+ assertions
262+ ->Set (env->context (),
263+ raw_assertions->Get (env->context (), i).As <String>(),
264+ raw_assertions->Get (env->context (), i + 1 ).As <Value>())
265+ .ToChecked ();
266+ }
267+
268+ return assertions;
269+ }
270+
256271void ModuleWrap::Link (const FunctionCallbackInfo<Value>& args) {
257272 Environment* env = Environment::GetCurrent (args);
258273 Isolate* isolate = args.GetIsolate ();
@@ -288,14 +303,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
288303
289304 Local<FixedArray> raw_assertions = module_request->GetImportAssertions ();
290305 Local<Object> assertions =
291- Object::New (isolate, v8::Null (env->isolate ()), nullptr , nullptr , 0 );
292- for (int i = 0 ; i < raw_assertions->Length (); i += 3 ) {
293- assertions
294- ->Set (env->context (),
295- raw_assertions->Get (env->context (), i).As <String>(),
296- raw_assertions->Get (env->context (), i + 1 ).As <Value>())
297- .ToChecked ();
298- }
306+ createImportAssertionContainer (env, isolate, raw_assertions);
299307
300308 Local<Value> argv[] = {
301309 specifier,
@@ -603,14 +611,7 @@ static MaybeLocal<Promise> ImportModuleDynamically(
603611 }
604612
605613 Local<Object> assertions =
606- Object::New (isolate, v8::Null (env->isolate ()), nullptr , nullptr , 0 );
607- for (int i = 0 ; i < import_assertions->Length (); i += 2 ) {
608- assertions
609- ->Set (env->context (),
610- Local<String>::Cast (import_assertions->Get (env->context (), i)),
611- Local<Value>::Cast (import_assertions->Get (env->context (), i + 1 )))
612- .ToChecked ();
613- }
614+ createImportAssertionContainer (env, isolate, import_assertions);
614615
615616 Local<Value> import_args[] = {
616617 object,
0 commit comments