Skip to content

Commit

Permalink
fix handling of sparse arrays in structuredClone, close #1156
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 14, 2022
1 parent 0f12121 commit 06c316b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
- Added Samsung Internet 19.0 compat data mapping
- Added Quest Browser 24.0 compat data mapping
- Fixed the first version in the Chromium-based Edge compat data mapping
- Fixed handling of sparse arrays in `structuredClone`, [#1156](https://github.com/zloirock/core-js/issues/1156)
- `{ Map, WeakMap }.prototype.emplace` became stricter [by the spec draft](https://tc39.es/proposal-upsert/)
- Fixed a theoretically possible future conflict of polyfills definitions in the pure version
- 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)
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js/modules/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var IS_DENO = require('../internals/engine-is-deno');
var IS_NODE = require('../internals/engine-is-node');

var Object = global.Object;
var Array = global.Array;
var Date = global.Date;
var Error = global.Error;
var EvalError = global.EvalError;
Expand Down Expand Up @@ -153,7 +154,7 @@ var structuredCloneInternal = function (value, map) {

switch (type) {
case 'Array':
cloned = [];
cloned = Array(lengthOfArrayLike(value));
deep = true;
break;
case 'Object':
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ QUnit.module('structuredClone', () => {
const arrays = [
[],
[1, 2, 3],
Array(1),
assign(
['foo', 'bar'],
{ 10: true, 11: false, 20: 123, 21: 456, 30: null }),
Expand Down
1 change: 1 addition & 0 deletions tests/unit-pure/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ QUnit.module('structuredClone', () => {
const arrays = [
[],
[1, 2, 3],
Array(1),
assign(
['foo', 'bar'],
{ 10: true, 11: false, 20: 123, 21: 456, 30: null }),
Expand Down

0 comments on commit 06c316b

Please sign in to comment.