From d43159c0046b70e2a4600bd6ed560eef0ee18f64 Mon Sep 17 00:00:00 2001 From: Giora Guttsait Date: Sat, 22 Jan 2022 21:47:42 +0200 Subject: [PATCH 1/3] lib: throw error in structuedClone when no arguments are passed --- lib/internal/structured_clone.js | 10 +++++++++- test/parallel/test-structuredClone-global.js | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/internal/structured_clone.js b/lib/internal/structured_clone.js index 2ee9517284ab6e..523d462076eb8a 100644 --- a/lib/internal/structured_clone.js +++ b/lib/internal/structured_clone.js @@ -1,5 +1,9 @@ 'use strict'; +const { + codes: { ERR_MISSING_ARGS }, +} = require('internal/errors'); + const { MessageChannel, receiveMessageOnPort, @@ -7,6 +11,10 @@ const { let channel; function structuredClone(value, options = undefined) { + if (arguments.length === 0) { + throw new ERR_MISSING_ARGS('input'); + } + // TODO: Improve this with a more efficient solution that avoids // instantiating a MessageChannel channel ??= new MessageChannel(); @@ -17,5 +25,5 @@ function structuredClone(value, options = undefined) { } module.exports = { - structuredClone + structuredClone, }; diff --git a/test/parallel/test-structuredClone-global.js b/test/parallel/test-structuredClone-global.js index ae6120c04e0005..b640f532681894 100644 --- a/test/parallel/test-structuredClone-global.js +++ b/test/parallel/test-structuredClone-global.js @@ -5,10 +5,12 @@ require('../common'); const { - structuredClone: _structuredClone + structuredClone: _structuredClone, } = require('internal/structured_clone'); + const { - strictEqual + strictEqual, + throws, } = require('assert'); strictEqual(globalThis.structuredClone, _structuredClone); @@ -17,3 +19,5 @@ strictEqual(globalThis.structuredClone, undefined); // Restore the value for the known globals check. structuredClone = _structuredClone; + +throws(() => _structuredClone(), /TypeError/); From e8d0d9c07466a620ebd76d50b889a0c16c9a3a49 Mon Sep 17 00:00:00 2001 From: Giora Guttsait Date: Sat, 22 Jan 2022 23:18:57 +0200 Subject: [PATCH 2/3] Update lib/internal/structured_clone.js copy-pasta is strong Co-authored-by: Mohammed Keyvanzadeh --- lib/internal/structured_clone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/structured_clone.js b/lib/internal/structured_clone.js index 523d462076eb8a..0392232badf9fc 100644 --- a/lib/internal/structured_clone.js +++ b/lib/internal/structured_clone.js @@ -12,7 +12,7 @@ const { let channel; function structuredClone(value, options = undefined) { if (arguments.length === 0) { - throw new ERR_MISSING_ARGS('input'); + throw new ERR_MISSING_ARGS('value'); } // TODO: Improve this with a more efficient solution that avoids From 309f2f809e84362efc22977d3a115c05ac89f29c Mon Sep 17 00:00:00 2001 From: Giora Guttsait Date: Sun, 23 Jan 2022 11:49:23 +0200 Subject: [PATCH 3/3] Update test/parallel/test-structuredClone-global.js Co-authored-by: Mestery --- test/parallel/test-structuredClone-global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-structuredClone-global.js b/test/parallel/test-structuredClone-global.js index b640f532681894..95dab1e8e8963b 100644 --- a/test/parallel/test-structuredClone-global.js +++ b/test/parallel/test-structuredClone-global.js @@ -20,4 +20,4 @@ strictEqual(globalThis.structuredClone, undefined); // Restore the value for the known globals check. structuredClone = _structuredClone; -throws(() => _structuredClone(), /TypeError/); +throws(() => _structuredClone(), /ERR_MISSING_ARGS/);