Skip to content

Commit b7ecb0a

Browse files
KhafraDevUlisesGascon
authored andcommitted
src: readiterable entries may be empty
fixup PR-URL: #50398 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
1 parent 7a661d7 commit b7ecb0a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/node_messaging.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,11 @@ static Maybe<bool> ReadIterable(Environment* env,
994994
entries.push_back(val);
995995
}
996996

997-
transfer_list.AllocateSufficientStorage(entries.size());
998-
std::copy(entries.begin(), entries.end(), &transfer_list[0]);
997+
if (!entries.empty()) {
998+
transfer_list.AllocateSufficientStorage(entries.size());
999+
std::copy(entries.begin(), entries.end(), &transfer_list[0]);
1000+
}
1001+
9991002
return Just(true);
10001003
}
10011004

test/parallel/test-messagechannel.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
// See: https://github.com/nodejs/node/issues/49940
6+
(async () => {
7+
new MessageChannel().port1.postMessage({}, {
8+
transfer: {
9+
*[Symbol.iterator]() {}
10+
}
11+
});
12+
})().then(common.mustCall());

test/parallel/test-structuredClone-global.js

+11
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ assert.strictEqual(structuredClone(undefined, null), undefined);
1515
// Transfer can be null or undefined.
1616
assert.strictEqual(structuredClone(undefined, { transfer: null }), undefined);
1717
assert.strictEqual(structuredClone(undefined, { }), undefined);
18+
19+
{
20+
// See: https://github.com/nodejs/node/issues/49940
21+
const cloned = structuredClone({}, {
22+
transfer: {
23+
*[Symbol.iterator]() {}
24+
}
25+
});
26+
27+
assert.deepStrictEqual(cloned, {});
28+
}

0 commit comments

Comments
 (0)