@@ -253,6 +253,21 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
253
253
args.GetReturnValue ().Set (that);
254
254
}
255
255
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
+
256
271
void ModuleWrap::Link (const FunctionCallbackInfo<Value>& args) {
257
272
Environment* env = Environment::GetCurrent (args);
258
273
Isolate* isolate = args.GetIsolate ();
@@ -288,14 +303,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
288
303
289
304
Local<FixedArray> raw_assertions = module_request->GetImportAssertions ();
290
305
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);
299
307
300
308
Local<Value> argv[] = {
301
309
specifier,
@@ -603,14 +611,7 @@ static MaybeLocal<Promise> ImportModuleDynamically(
603
611
}
604
612
605
613
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);
614
615
615
616
Local<Value> import_args[] = {
616
617
object,
0 commit comments