From 8a1abdca8777cf4df3a27d12f0f623937c85dde6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 17 Jul 2023 23:05:21 -0700 Subject: [PATCH] [patch] throw on negative set sizes per https://github.com/tc39/proposal-set-methods/pull/88 --- aos/GetSetRecord.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/aos/GetSetRecord.js b/aos/GetSetRecord.js index 6acb138..fcb063b 100644 --- a/aos/GetSetRecord.js +++ b/aos/GetSetRecord.js @@ -2,6 +2,7 @@ var GetIntrinsic = require('get-intrinsic'); +var $RangeError = GetIntrinsic('%RangeError%'); var $TypeError = GetIntrinsic('%TypeError%'); var Get = require('es-abstract/2023/Get'); @@ -32,15 +33,19 @@ module.exports = function GetSetRecord(obj) { var intSize = ToIntegerOrInfinity(numSize); // step 6 - var has = Get(obj, 'has'); // step 7 + if (intSize < 0) { + throw new $RangeError('set size must be non-negative'); // step 7 + } + + var has = Get(obj, 'has'); // step 8 if (!IsCallable(has)) { - throw new $TypeError('has is not a function'); // step 8 + throw new $TypeError('has is not a function'); // step 9 } - var keys = Get(obj, 'keys'); // step 9 + var keys = Get(obj, 'keys'); // step 10 if (!IsCallable(keys)) { - throw new $TypeError('keys is not a function'); // step 10 + throw new $TypeError('keys is not a function'); // step 11 } /* globals StopIteration: false */ if (isSet(obj) && typeof StopIteration === 'object') { @@ -50,5 +55,5 @@ module.exports = function GetSetRecord(obj) { }; } - return { '[[Set]]': obj, '[[Size]]': intSize, '[[Has]]': has, '[[Keys]]': keys }; // step 11 + return { '[[Set]]': obj, '[[Size]]': intSize, '[[Has]]': has, '[[Keys]]': keys }; // step 12 };