Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,14 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
}

static Local<Object> createImportAttributesContainer(
Realm* realm, Isolate* isolate, Local<FixedArray> raw_attributes) {
Realm* realm,
Isolate* isolate,
Local<FixedArray> raw_attributes,
const int elements_per_attribute) {
CHECK_EQ(raw_attributes->Length() % elements_per_attribute, 0);
Local<Object> attributes =
Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
for (int i = 0; i < raw_attributes->Length(); i += 3) {
for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) {
attributes
->Set(realm->context(),
raw_attributes->Get(realm->context(), i).As<String>(),
Expand Down Expand Up @@ -304,7 +308,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {

Local<FixedArray> raw_attributes = module_request->GetImportAssertions();
Local<Object> attributes =
createImportAttributesContainer(realm, isolate, raw_attributes);
createImportAttributesContainer(realm, isolate, raw_attributes, 3);

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

Local<Object> attributes =
createImportAttributesContainer(realm, isolate, import_attributes);
createImportAttributesContainer(realm, isolate, import_attributes, 2);

Local<Value> import_args[] = {
id,
Expand Down
5 changes: 5 additions & 0 deletions test/es-module/test-esm-import-attributes-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ async function test() {
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
);

await rejects(
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
);

await rejects(
import(jsModuleDataUrl, { with: { type: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
Expand Down
5 changes: 5 additions & 0 deletions test/es-module/test-esm-import-attributes-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ await rejects(
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
);

await rejects(
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
);

await rejects(
import(import.meta.url, { with: { type: 'unsupported' } }),
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
Expand Down