]> git.kaiwu.me - quickjs.git/commitdiff
Reject out-of-range limits in Iterator.prototype.take/drop
authorFabrice Bellard <fabrice@bellard.org>
Sat, 26 Sep 2026 13:01:46 +0000 (15:01 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 26 Sep 2026 13:01:46 +0000 (15:01 +0200)
quickjs.c
test262_errors.txt

index eb93ac5cc3406f6fc89fae3016707fdcd7c168f9..adfed759a0ceb0e863e9ac3381c03eaa3fdd6633 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -44090,32 +44090,20 @@ static JSValue js_create_iterator_helper(JSContext *ctx, JSValueConst this_val,
     case JS_ITERATOR_HELPER_KIND_DROP:
     case JS_ITERATOR_HELPER_KIND_TAKE:
         {
-            JSValue v;
             double dlimit;
-            v = JS_ToNumber(ctx, argv[0]);
-            if (JS_IsException(v))
-                goto fail;
-            // Check for Infinity.
-            if (JS_ToFloat64(ctx, &dlimit, v)) {
-                JS_FreeValue(ctx, v);
+            if (JS_ToFloat64(ctx, &dlimit, argv[0]))
                 goto fail;
-            }
-            if (isnan(dlimit)) {
-                JS_FreeValue(ctx, v);
+            if (isnan(dlimit))
                 goto range_error;
-            }
-            if (!isfinite(dlimit)) {
-                JS_FreeValue(ctx, v);
-                if (dlimit < 0)
+            if (dlimit < INT64_MIN) {
+                count = INT64_MIN;
+            } else if (dlimit > MAX_SAFE_INTEGER) {
+                if (isfinite(dlimit))
                     goto range_error;
                 else
                     count = MAX_SAFE_INTEGER;
             } else {
-                v = JS_ToIntegerFree(ctx, v);
-                if (JS_IsException(v))
-                    goto fail;
-                if (JS_ToInt64Free(ctx, &count, v))
-                    goto fail;
+                count = (int64_t)dlimit;
             }
             if (count < 0)
                 goto range_error;
index 8ee4c2b5cffaa9023fc6a95b12dd1f3de9d68e57..6f59bcac9632261740c807280b50ffdbdf5f3fb5 100644 (file)
@@ -5,18 +5,6 @@ test262/test/annexB/language/expressions/assignmenttargettype/callexpression-in-
 test262/test/annexB/language/expressions/assignmenttargettype/callexpression-in-prefix-update.js:27: SyntaxError: invalid increment/decrement operand
 test262/test/annexB/language/expressions/assignmenttargettype/callexpression.js:33: SyntaxError: invalid assignment left-hand side
 test262/test/annexB/language/expressions/assignmenttargettype/cover-callexpression-and-asyncarrowhead.js:20: SyntaxError: invalid assignment left-hand side
-test262/test/built-ins/Iterator/prototype/drop/argument-effect-order.js:27: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/drop/argument-effect-order.js:27: strict mode: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/drop/argument-validation-failure-closes-underlying.js:18: Test262Error: Expected a RangeError but got a Test262Error
-test262/test/built-ins/Iterator/prototype/drop/argument-validation-failure-closes-underlying.js:18: strict mode: Test262Error: Expected a RangeError but got a Test262Error
-test262/test/built-ins/Iterator/prototype/drop/limit-rangeerror.js:29: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/drop/limit-rangeerror.js:29: strict mode: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/take/argument-effect-order.js:44: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/take/argument-effect-order.js:44: strict mode: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/take/argument-validation-failure-closes-underlying.js:18: Test262Error: Expected a RangeError but got a Test262Error
-test262/test/built-ins/Iterator/prototype/take/argument-validation-failure-closes-underlying.js:18: strict mode: Test262Error: Expected a RangeError but got a Test262Error
-test262/test/built-ins/Iterator/prototype/take/limit-rangeerror.js:29: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
-test262/test/built-ins/Iterator/prototype/take/limit-rangeerror.js:29: strict mode: Test262Error: Expected a RangeError to be thrown but no exception was thrown at all
 test262/test/built-ins/Promise/try/avoids-wrap-for-subclass.js:10: Test262Error: Expected SameValue(«[object Promise]», «[object Promise]») to be true
 test262/test/built-ins/Promise/try/avoids-wrap-for-subclass.js:10: strict mode: Test262Error: Expected SameValue(«[object Promise]», «[object Promise]») to be true
 test262/test/built-ins/Promise/try/avoids-wrap.js:10: Test262Error: Expected SameValue(«[object Promise]», «[object Promise]») to be true