Skip to content

Commit 06c316b

Browse files
committed
fix handling of sparse arrays in structuredClone, close #1156
1 parent 0f12121 commit 06c316b

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
- Added Samsung Internet 19.0 compat data mapping
7575
- Added Quest Browser 24.0 compat data mapping
7676
- Fixed the first version in the Chromium-based Edge compat data mapping
77+
- Fixed handling of sparse arrays in `structuredClone`, [#1156](https://github.com/zloirock/core-js/issues/1156)
7778
- `{ Map, WeakMap }.prototype.emplace` became stricter [by the spec draft](https://tc39.es/proposal-upsert/)
7879
- Fixed a theoretically possible future conflict of polyfills definitions in the pure version
7980
- Added pure version of the `Number` constructor, [#1154](https://github.com/zloirock/core-js/issues/1154), [#1155](https://github.com/zloirock/core-js/issues/1155), thanks [@trosos](https://github.com/trosos)

packages/core-js/modules/web.structured-clone.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var IS_DENO = require('../internals/engine-is-deno');
2828
var IS_NODE = require('../internals/engine-is-node');
2929

3030
var Object = global.Object;
31+
var Array = global.Array;
3132
var Date = global.Date;
3233
var Error = global.Error;
3334
var EvalError = global.EvalError;
@@ -153,7 +154,7 @@ var structuredCloneInternal = function (value, map) {
153154

154155
switch (type) {
155156
case 'Array':
156-
cloned = [];
157+
cloned = Array(lengthOfArrayLike(value));
157158
deep = true;
158159
break;
159160
case 'Object':

tests/unit-global/web.structured-clone.js

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ QUnit.module('structuredClone', () => {
239239
const arrays = [
240240
[],
241241
[1, 2, 3],
242+
Array(1),
242243
assign(
243244
['foo', 'bar'],
244245
{ 10: true, 11: false, 20: 123, 21: 456, 30: null }),

tests/unit-pure/web.structured-clone.js

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ QUnit.module('structuredClone', () => {
247247
const arrays = [
248248
[],
249249
[1, 2, 3],
250+
Array(1),
250251
assign(
251252
['foo', 'bar'],
252253
{ 10: true, 11: false, 20: 123, 21: 456, 30: null }),

0 commit comments

Comments
 (0)