Skip to content

Commit 055016f

Browse files
committed
fixup! lib: refactor internal webidl converters
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 713e897 commit 055016f

2 files changed

Lines changed: 5 additions & 38 deletions

File tree

lib/internal/webidl.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
NumberMAX_SAFE_INTEGER,
2222
NumberMIN_SAFE_INTEGER,
2323
ObjectPrototypeIsPrototypeOf,
24+
SafeArrayIterator,
2425
SafeSet,
2526
String,
2627
SymbolIterator,
@@ -357,10 +358,10 @@ function convertToInt(
357358
if (integer === V) {
358359
return V === 0 ? 0 : V;
359360
}
360-
if (options === kEmptyObject || options.enforceRange || !options.clamp) {
361-
return integer === 0 ? 0 : integer;
361+
if (options !== kEmptyObject && options.clamp) {
362+
return evenRound(V);
362363
}
363-
return evenRound(V);
364+
return integer === 0 ? 0 : integer;
364365
}
365366
if (options !== kEmptyObject && options.enforceRange) {
366367
// Keep [EnforceRange] ahead of [Clamp] without falling through to
@@ -604,7 +605,7 @@ function requiredArguments(length, required, options = kEmptyObject) {
604605
* @returns {Converter}
605606
*/
606607
function createEnumConverter(name, values) {
607-
const E = new SafeSet(values);
608+
const E = new SafeSet(new SafeArrayIterator(values));
608609

609610
return function(V, options = kEmptyObject) {
610611
// Web IDL enumeration step 1: convert V with ToString.

test/parallel/test-internal-webidl-converttoint.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -267,40 +267,6 @@ assert.throws(() => convertToInt(256, 8, 'unsigned', {
267267
code: 'ERR_OUT_OF_RANGE',
268268
});
269269

270-
{
271-
const calls = [];
272-
const options = {
273-
get enforceRange() {
274-
calls.push('enforceRange');
275-
return true;
276-
},
277-
get clamp() {
278-
calls.push('clamp');
279-
return true;
280-
},
281-
};
282-
283-
assert.strictEqual(convertToInt(1.5, 8, 'unsigned', options), 1);
284-
assert.deepStrictEqual(calls, ['enforceRange']);
285-
}
286-
287-
{
288-
const calls = [];
289-
const options = {
290-
get enforceRange() {
291-
calls.push('enforceRange');
292-
return true;
293-
},
294-
get clamp() {
295-
calls.push('clamp');
296-
return true;
297-
},
298-
};
299-
300-
assert.strictEqual(convertToInt(255.5, 8, 'unsigned', options), 255);
301-
assert.deepStrictEqual(calls, ['enforceRange']);
302-
}
303-
304270
{
305271
const calls = [];
306272
const options = {

0 commit comments

Comments
 (0)