@@ -37468,7 +37468,7 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
37468
37468
if (js_get_length64(ctx, &len, obj))
37469
37469
goto exception;
37470
37470
37471
- res = FALSE ;
37471
+ res = TRUE ;
37472
37472
if (len > 0) {
37473
37473
n = 0;
37474
37474
if (argc > 1) {
@@ -37479,7 +37479,6 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
37479
37479
for (; n < count; n++) {
37480
37480
if (js_strict_eq2(ctx, js_dup(argv[0]), js_dup(arrp[n]),
37481
37481
JS_EQ_SAME_VALUE_ZERO)) {
37482
- res = TRUE;
37483
37482
goto done;
37484
37483
}
37485
37484
}
@@ -37490,11 +37489,11 @@ static JSValue js_array_includes(JSContext *ctx, JSValue this_val,
37490
37489
goto exception;
37491
37490
if (js_strict_eq2(ctx, js_dup(argv[0]), val,
37492
37491
JS_EQ_SAME_VALUE_ZERO)) {
37493
- res = TRUE;
37494
- break;
37492
+ goto done;
37495
37493
}
37496
37494
}
37497
37495
}
37496
+ res = FALSE;
37498
37497
done:
37499
37498
JS_FreeValue(ctx, obj);
37500
37499
return js_bool(res);
@@ -37508,15 +37507,14 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValue this_val,
37508
37507
int argc, JSValue *argv)
37509
37508
{
37510
37509
JSValue obj, val;
37511
- int64_t len, n, res ;
37510
+ int64_t len, n;
37512
37511
JSValue *arrp;
37513
37512
uint32_t count;
37514
37513
37515
37514
obj = JS_ToObject(ctx, this_val);
37516
37515
if (js_get_length64(ctx, &len, obj))
37517
37516
goto exception;
37518
37517
37519
- res = -1;
37520
37518
if (len > 0) {
37521
37519
n = 0;
37522
37520
if (argc > 1) {
@@ -37527,7 +37525,6 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValue this_val,
37527
37525
for (; n < count; n++) {
37528
37526
if (js_strict_eq2(ctx, js_dup(argv[0]), js_dup(arrp[n]),
37529
37527
JS_EQ_STRICT)) {
37530
- res = n;
37531
37528
goto done;
37532
37529
}
37533
37530
}
@@ -37538,15 +37535,15 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValue this_val,
37538
37535
goto exception;
37539
37536
if (present) {
37540
37537
if (js_strict_eq2(ctx, js_dup(argv[0]), val, JS_EQ_STRICT)) {
37541
- res = n;
37542
- break;
37538
+ goto done;
37543
37539
}
37544
37540
}
37545
37541
}
37546
37542
}
37543
+ n = -1;
37547
37544
done:
37548
37545
JS_FreeValue(ctx, obj);
37549
- return JS_NewInt64(ctx, res );
37546
+ return JS_NewInt64(ctx, n );
37550
37547
37551
37548
exception:
37552
37549
JS_FreeValue(ctx, obj);
@@ -37557,35 +37554,43 @@ static JSValue js_array_lastIndexOf(JSContext *ctx, JSValue this_val,
37557
37554
int argc, JSValue *argv)
37558
37555
{
37559
37556
JSValue obj, val;
37560
- int64_t len, n, res;
37561
- int present;
37557
+ int64_t len, n;
37558
+ JSValue *arrp;
37559
+ uint32_t count;
37562
37560
37563
37561
obj = JS_ToObject(ctx, this_val);
37564
37562
if (js_get_length64(ctx, &len, obj))
37565
37563
goto exception;
37566
37564
37567
- res = -1;
37568
37565
if (len > 0) {
37569
37566
n = len - 1;
37570
37567
if (argc > 1) {
37571
37568
if (JS_ToInt64Clamp(ctx, &n, argv[1], -1, len - 1, len))
37572
37569
goto exception;
37573
37570
}
37574
- /* XXX: should special case fast arrays */
37571
+ if (js_get_fast_array(ctx, obj, &arrp, &count) && count == len) {
37572
+ for (; n >= 0; n--) {
37573
+ if (js_strict_eq2(ctx, js_dup(argv[0]), js_dup(arrp[n]),
37574
+ JS_EQ_STRICT)) {
37575
+ goto done;
37576
+ }
37577
+ }
37578
+ }
37575
37579
for (; n >= 0; n--) {
37576
- present = JS_TryGetPropertyInt64(ctx, obj, n, &val);
37580
+ int present = JS_TryGetPropertyInt64(ctx, obj, n, &val);
37577
37581
if (present < 0)
37578
37582
goto exception;
37579
37583
if (present) {
37580
37584
if (js_strict_eq2(ctx, js_dup(argv[0]), val, JS_EQ_STRICT)) {
37581
- res = n;
37582
- break;
37585
+ goto done;
37583
37586
}
37584
37587
}
37585
37588
}
37586
37589
}
37590
+ n = -1;
37591
+ done:
37587
37592
JS_FreeValue(ctx, obj);
37588
- return JS_NewInt64(ctx, res );
37593
+ return JS_NewInt64(ctx, n );
37589
37594
37590
37595
exception:
37591
37596
JS_FreeValue(ctx, obj);
0 commit comments