Skip to content

Commit

Permalink
src: readiterable entries may be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Oct 25, 2023
1 parent c3a41d8 commit 4ab7c8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,11 @@ static Maybe<bool> ReadIterable(Environment* env,
entries.push_back(val);
}

transfer_list.AllocateSufficientStorage(entries.size());
std::copy(entries.begin(), entries.end(), &transfer_list[0]);
if (!entries.empty()) {
transfer_list.AllocateSufficientStorage(entries.size());
std::copy(entries.begin(), entries.end(), &transfer_list[0]);
}

return Just(true);
}

Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-messagechannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const common = require('../common');

// See: https://github.com/nodejs/node/issues/49940
(async () => {
new MessageChannel().port1.postMessage({}, {
transfer: {
*[Symbol.iterator]() {}
}
});
})().then(common.mustCall());
11 changes: 11 additions & 0 deletions test/parallel/test-structuredClone-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ assert.strictEqual(structuredClone(undefined, null), undefined);
// Transfer can be null or undefined.
assert.strictEqual(structuredClone(undefined, { transfer: null }), undefined);
assert.strictEqual(structuredClone(undefined, { }), undefined);

{
// See: https://github.com/nodejs/node/issues/49940
const cloned = structuredClone({}, {
transfer: {
*[Symbol.iterator]() {}
}
});

assert.strictEqual(cloned, {});

Check failure on line 27 in test/parallel/test-structuredClone-global.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- node:assert:125 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Values have same structure but are not reference-equal: {} at Object.<anonymous> (/Users/runner/work/node/node/test/parallel/test-structuredClone-global.js:27:10) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { generatedMessage: true, code: 'ERR_ASSERTION', actual: {}, expected: {}, operator: 'strictEqual' } Node.js v22.0.0-pre Command: out/Release/node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /Users/runner/work/node/node/test/parallel/test-structuredClone-global.js
}

0 comments on commit 4ab7c8a

Please sign in to comment.