Skip to content

Commit 8ab0540

Browse files
gioraguttruyadorno
authored andcommitted
lib: throw error in structuedClone when no arguments are passed
PR-URL: #41651 Fixes: #41450 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 2bba6cd commit 8ab0540

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/internal/structured_clone.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
'use strict';
22

3+
const {
4+
codes: { ERR_MISSING_ARGS },
5+
} = require('internal/errors');
6+
37
const {
48
MessageChannel,
59
receiveMessageOnPort,
610
} = require('internal/worker/io');
711

812
let channel;
913
function structuredClone(value, options = undefined) {
14+
if (arguments.length === 0) {
15+
throw new ERR_MISSING_ARGS('value');
16+
}
17+
1018
// TODO: Improve this with a more efficient solution that avoids
1119
// instantiating a MessageChannel
1220
channel ??= new MessageChannel();
@@ -17,5 +25,5 @@ function structuredClone(value, options = undefined) {
1725
}
1826

1927
module.exports = {
20-
structuredClone
28+
structuredClone,
2129
};

test/parallel/test-structuredClone-global.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
require('../common');
66

77
const {
8-
structuredClone: _structuredClone
8+
structuredClone: _structuredClone,
99
} = require('internal/structured_clone');
10+
1011
const {
11-
strictEqual
12+
strictEqual,
13+
throws,
1214
} = require('assert');
1315

1416
strictEqual(globalThis.structuredClone, _structuredClone);
@@ -17,3 +19,5 @@ strictEqual(globalThis.structuredClone, undefined);
1719

1820
// Restore the value for the known globals check.
1921
structuredClone = _structuredClone;
22+
23+
throws(() => _structuredClone(), /ERR_MISSING_ARGS/);

0 commit comments

Comments
 (0)