Skip to content

Commit 4f12ebe

Browse files
committed
structuredClone should throw an error if no arguments passed
1 parent 336eae4 commit 4f12ebe

File tree

6 files changed

+14
-5
lines changed

6 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22
##### Unreleased
33
- Detects and replaces broken third-party `Function#bind` polyfills, uses only native `Function#bind` in the internals
4+
- `structuredClone` should throw an error if no arguments passed
45

56
##### 3.20.2 - 2022.01.02
67
- Added a fix of [a V8 ~ Chrome 36- `Object.{ defineProperty, defineProperties }` bug](https://bugs.chromium.org/p/v8/issues/detail?id=3334), [Babel issue](https://github.com/babel/babel/issues/14056)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var global = require('../internals/global');
2+
3+
var TypeError = global.TypeError;
4+
5+
module.exports = function (passed, required) {
6+
if (passed < required) throw TypeError('Not enough arguments');
7+
return passed;
8+
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var hasOwn = require('../internals/has-own-property');
1616
var createProperty = require('../internals/create-property');
1717
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
1818
var lengthOfArrayLike = require('../internals/length-of-array-like');
19+
var validateArgumentsLength = require('../internals/validate-arguments-length');
1920
var regExpFlags = require('../internals/regexp-flags');
2021
var ERROR_STACK_INSTALLABLE = require('../internals/error-stack-installable');
2122

@@ -447,7 +448,7 @@ var tryToTransfer = function (rawTransfer, map) {
447448

448449
$({ global: true, enumerable: true, sham: !PROPER_TRANSFER, forced: FORCED_REPLACEMENT }, {
449450
structuredClone: function structuredClone(value /* , { transfer } */) {
450-
var options = arguments.length > 1 ? anObject(arguments[1]) : undefined;
451+
var options = validateArgumentsLength(arguments.length, 1) > 1 ? anObject(arguments[1]) : undefined;
451452
var transfer = options ? options.transfer : undefined;
452453
var map;
453454

packages/core-js/modules/web.url-search-params.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var create = require('../internals/object-create');
2424
var createPropertyDescriptor = require('../internals/create-property-descriptor');
2525
var getIterator = require('../internals/get-iterator');
2626
var getIteratorMethod = require('../internals/get-iterator-method');
27+
var validateArgumentsLength = require('../internals/validate-arguments-length');
2728
var wellKnownSymbol = require('../internals/well-known-symbol');
2829
var arraySort = require('../internals/array-sort');
2930

@@ -99,10 +100,6 @@ var serialize = function (it) {
99100
return replace(encodeURIComponent(it), find, replacer);
100101
};
101102

102-
var validateArgumentsLength = function (passed, required) {
103-
if (passed < required) throw TypeError('Not enough arguments');
104-
};
105-
106103
var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params, kind) {
107104
setInternalState(this, {
108105
type: URL_SEARCH_PARAMS_ITERATOR,

tests/pure/web.structured-clone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ QUnit.module('structuredClone', () => {
2020
assert.isFunction(structuredClone, 'structuredClone is a function');
2121
assert.name(structuredClone, 'structuredClone');
2222
assert.arity(structuredClone, 1);
23+
assert.throws(() => structuredClone(), 'throws without arguments');
2324
});
2425

2526
function cloneTest(value, verifyFunc) {

tests/tests/web.structured-clone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ QUnit.module('structuredClone', () => {
1212
assert.name(structuredClone, 'structuredClone');
1313
assert.arity(structuredClone, 1);
1414
if (!NODE) assert.looksNative(structuredClone);
15+
assert.throws(() => structuredClone(), 'throws without arguments');
1516
});
1617

1718
function cloneTest(value, verifyFunc) {

0 commit comments

Comments
 (0)