GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: iterate on import attributes array correctly · nodejs/node@b2b4132

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • module_wrap.cc
  • test/es-module
    • test-esm-import-attributes-errors.js
    • test-esm-import-attributes-errors.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/module_wrap.cc‎

Copy file name to clipboardExpand all lines: src/module_wrap.cc
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,14 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
254254
}
255255

256256
static Local<Object> createImportAttributesContainer(
257-
Realm* realm, Isolate* isolate, Local<FixedArray> raw_attributes) {
257+
Realm* realm,
258+
Isolate* isolate,
259+
Local<FixedArray> raw_attributes,
260+
const int elements_per_attribute) {
261+
CHECK_EQ(raw_attributes->Length() % elements_per_attribute, 0);
258262
Local<Object> attributes =
259263
Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
260-
for (int i = 0; i < raw_attributes->Length(); i += 3) {
264+
for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) {
261265
attributes
262266
->Set(realm->context(),
263267
raw_attributes->Get(realm->context(), i).As<String>(),
@@ -303,7 +307,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
303307

304308
Local<FixedArray> raw_attributes = module_request->GetImportAssertions();
305309
Local<Object> attributes =
306-
createImportAttributesContainer(realm, isolate, raw_attributes);
310+
createImportAttributesContainer(realm, isolate, raw_attributes, 3);
307311

308312
Local<Value> argv[] = {
309313
specifier,
@@ -587,7 +591,7 @@ static MaybeLocal<Promise> ImportModuleDynamically(
587591
}
588592

589593
Local<Object> attributes =
590-
createImportAttributesContainer(realm, isolate, import_attributes);
594+
createImportAttributesContainer(realm, isolate, import_attributes, 2);
591595

592596
Local<Value> import_args[] = {
593597
id,
Collapse file

‎test/es-module/test-esm-import-attributes-errors.js‎

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 numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ async function test() {
2626
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
2727
);
2828

29+
await rejects(
30+
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
31+
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
32+
);
33+
2934
await rejects(
3035
import(jsModuleDataUrl, { with: { type: 'unsupported' } }),
3136
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
Collapse file

‎test/es-module/test-esm-import-attributes-errors.mjs‎

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 numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ await rejects(
2121
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
2222
);
2323

24+
await rejects(
25+
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
26+
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
27+
);
28+
2429
await rejects(
2530
import(import.meta.url, { with: { type: 'unsupported' } }),
2631
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.