Skip to content

Commit

Permalink
allow null and undefined as the second argument of `structuredClo…
Browse files Browse the repository at this point in the history
…ne`, close #1056
  • Loading branch information
zloirock committed Mar 14, 2022
1 parent fb58217 commit 887850a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- `null` and `undefined` allowed as the second argument of `structuredClone`, [#1056](https://github.com/zloirock/core-js/issues/1056)
- Updated Electron 18.0 compat data mapping

##### 3.21.1 - 2022.02.17
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ var tryToTransfer = function (rawTransfer, map) {

$({ global: true, enumerable: true, sham: !PROPER_TRANSFER, forced: FORCED_REPLACEMENT }, {
structuredClone: function structuredClone(value /* , { transfer } */) {
var options = validateArgumentsLength(arguments.length, 1) > 1 ? anObject(arguments[1]) : undefined;
var options = validateArgumentsLength(arguments.length, 1) > 1 && arguments[1] != null ? anObject(arguments[1]) : undefined;
var transfer = options ? options.transfer : undefined;
var map;

Expand Down
2 changes: 2 additions & 0 deletions tests/pure/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ QUnit.module('structuredClone', () => {
assert.name(structuredClone, 'structuredClone');
assert.arity(structuredClone, 1);
assert.throws(() => structuredClone(), 'throws without arguments');
assert.same(structuredClone(1, null), 1, 'null as options');
assert.same(structuredClone(1, undefined), 1, 'undefined as options');
});

function cloneTest(value, verifyFunc) {
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/web.structured-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ QUnit.module('structuredClone', () => {
assert.arity(structuredClone, 1);
if (!NODE) assert.looksNative(structuredClone);
assert.throws(() => structuredClone(), 'throws without arguments');
assert.same(structuredClone(1, null), 1, 'null as options');
assert.same(structuredClone(1, undefined), 1, 'undefined as options');
});

function cloneTest(value, verifyFunc) {
Expand Down

0 comments on commit 887850a

Please sign in to comment.