Skip to content

Commit fced162

Browse files
committed
Reject out-of-range limits in Iterator.prototype.take/drop
test262 now enforces the normative change adding step 7 to both helpers: if numLimit is finite and greater than 2**53 - 1, throw a RangeError after closing the underlying iterator.
1 parent 034097c commit fced162

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

quickjs.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45387,30 +45387,16 @@ static JSValue js_create_iterator_helper(JSContext *ctx, JSValueConst this_val,
4538745387
v = JS_ToNumber(ctx, argv[0]);
4538845388
if (JS_IsException(v))
4538945389
goto fail;
45390-
// Check for Infinity.
45391-
if (JS_ToFloat64(ctx, &dlimit, v)) {
45392-
JS_FreeValue(ctx, v);
45393-
goto fail;
45394-
}
45395-
if (isnan(dlimit)) {
45396-
JS_FreeValue(ctx, v);
45390+
JS_ToFloat64Free(ctx, &dlimit, v);
45391+
if (isnan(dlimit))
4539745392
goto range_error;
45398-
}
45399-
if (!isfinite(dlimit)) {
45400-
JS_FreeValue(ctx, v);
45401-
if (dlimit < 0)
45402-
goto range_error;
45403-
else
45404-
count = MAX_SAFE_INTEGER;
45405-
} else {
45406-
v = JS_ToIntegerFree(ctx, v);
45407-
if (JS_IsException(v))
45408-
goto fail;
45409-
if (JS_ToInt64Free(ctx, &count, v))
45410-
goto fail;
45411-
}
45412-
if (count < 0)
45393+
if (isfinite(dlimit) && dlimit > MAX_SAFE_INTEGER)
45394+
goto range_error;
45395+
dlimit = trunc(dlimit);
45396+
if (dlimit < 0)
4541345397
goto range_error;
45398+
// +Infinity means "no limit"; use MAX_SAFE_INTEGER
45399+
count = isfinite(dlimit) ? (int64_t)dlimit : MAX_SAFE_INTEGER;
4541445400
}
4541545401
break;
4541645402
case JS_ITERATOR_HELPER_KIND_FILTER:

0 commit comments

Comments
 (0)