Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: throw error in structuedClone when no arguments are passed
  • Loading branch information
gioragutt committed Jan 22, 2022
commit d43159c0046b70e2a4600bd6ed560eef0ee18f64
10 changes: 9 additions & 1 deletion lib/internal/structured_clone.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use strict';

const {
codes: { ERR_MISSING_ARGS },
} = require('internal/errors');

const {
MessageChannel,
receiveMessageOnPort,
} = require('internal/worker/io');

let channel;
function structuredClone(value, options = undefined) {
if (arguments.length === 0) {
throw new ERR_MISSING_ARGS('input');
Comment thread
gioragutt marked this conversation as resolved.
Outdated
}

// TODO: Improve this with a more efficient solution that avoids
// instantiating a MessageChannel
channel ??= new MessageChannel();
Expand All @@ -17,5 +25,5 @@ function structuredClone(value, options = undefined) {
}

module.exports = {
structuredClone
structuredClone,
};
8 changes: 6 additions & 2 deletions test/parallel/test-structuredClone-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -17,3 +19,5 @@ strictEqual(globalThis.structuredClone, undefined);

// Restore the value for the known globals check.
structuredClone = _structuredClone;

throws(() => _structuredClone(), /TypeError/);
Comment thread
gioragutt marked this conversation as resolved.
Outdated