GeezerVison is showing github.com — src: iterate on import attributes array correctly · nodejs/node@eacf4ba
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/module_wrap.cc +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -255,10 +255,14 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) { | 255 | 255 | } | 256 | 256 |
| 257 | 257 | static Local<Object> createImportAttributesContainer( | 258 | | - Realm* realm, Isolate* isolate, Local<FixedArray> raw_attributes) { | | 258 | + Realm* realm, | | 259 | + Isolate* isolate, | | 260 | + Local<FixedArray> raw_attributes, | | 261 | + const int elements_per_attribute) { | | 262 | + CHECK_EQ(raw_attributes->Length() % elements_per_attribute, 0); | 259 | 263 | Local<Object> attributes = | 260 | 264 | Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0); | 261 | | - for (int i = 0; i < raw_attributes->Length(); i += 3) { | | 265 | + for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) { | 262 | 266 | attributes | 263 | 267 | ->Set(realm->context(), | 264 | 268 | raw_attributes->Get(realm->context(), i).As<String>(), | @@ -304,7 +308,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { | 304 | 308 |
| 305 | 309 | Local<FixedArray> raw_attributes = module_request->GetImportAssertions(); | 306 | 310 | Local<Object> attributes = | 307 | | - createImportAttributesContainer(realm, isolate, raw_attributes); | | 311 | + createImportAttributesContainer(realm, isolate, raw_attributes, 3); | 308 | 312 |
| 309 | 313 | Local<Value> argv[] = { | 310 | 314 | specifier, | @@ -588,7 +592,7 @@ static MaybeLocal<Promise> ImportModuleDynamically( | 588 | 592 | } | 589 | 593 |
| 590 | 594 | Local<Object> attributes = | 591 | | - createImportAttributesContainer(realm, isolate, import_attributes); | | 595 | + createImportAttributesContainer(realm, isolate, import_attributes, 2); | 592 | 596 |
| 593 | 597 | Local<Value> import_args[] = { | 594 | 598 | id, | |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-attributes-errors.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,11 @@ async function test() { | 26 | 26 | { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } | 27 | 27 | ); | 28 | 28 |
| | 29 | + await rejects( | | 30 | + import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }), | | 31 | + { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } | | 32 | + ); | | 33 | + | 29 | 34 | await rejects( | 30 | 35 | import(jsModuleDataUrl, { with: { type: 'unsupported' } }), | 31 | 36 | { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } | |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-attributes-errors.mjs +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,11 @@ await rejects( | 21 | 21 | { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } | 22 | 22 | ); | 23 | 23 |
| | 24 | +await rejects( | | 25 | + import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }), | | 26 | + { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } | | 27 | +); | | 28 | + | 24 | 29 | await rejects( | 25 | 30 | import(import.meta.url, { with: { type: 'unsupported' } }), | 26 | 31 | { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } | |
|