diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-09-05 13:08:37 +0300 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2021-10-09 11:44:53 +0300 |
commit | 08ffbd115e5170274f3c0bea602378903fd03173 (patch) | |
tree | d70a374a90b2e1c7462b9f42627c0075c3fac307 /src/module_wrap.cc | |
parent | 879ff775d039aa9b1becd548a99a7e19937521f5 (diff) |
vm: add support for import assertions in dynamic imports
PR-URL: https://github.com/nodejs/node/pull/40249
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r-- | src/module_wrap.cc | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc index f3ea419df1e..aeb0d2cb373 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -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(); @@ -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, @@ -602,9 +610,13 @@ static MaybeLocal<Promise> ImportModuleDynamically( UNREACHABLE(); } + Local<Object> assertions = + createImportAssertionContainer(env, isolate, import_assertions); + Local<Value> import_args[] = { object, Local<Value>(specifier), + assertions, }; Local<Value> result; |