diff --git a/CHANGELOG.md b/CHANGELOG.md index 158a87f95528..44100689c975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/core-js/modules/web.structured-clone.js b/packages/core-js/modules/web.structured-clone.js index 68ffaab0e144..c6e0227fed2c 100644 --- a/packages/core-js/modules/web.structured-clone.js +++ b/packages/core-js/modules/web.structured-clone.js @@ -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; diff --git a/tests/pure/web.structured-clone.js b/tests/pure/web.structured-clone.js index 57b95615db33..487b6898775c 100644 --- a/tests/pure/web.structured-clone.js +++ b/tests/pure/web.structured-clone.js @@ -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) { diff --git a/tests/tests/web.structured-clone.js b/tests/tests/web.structured-clone.js index 7b634ad3da1e..b4c91156d22d 100644 --- a/tests/tests/web.structured-clone.js +++ b/tests/tests/web.structured-clone.js @@ -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) {