Skip to content

Commit 7fb994c

Browse files
author
Fabrice Bellard
committed
fixed argument evaluation order in Date constructor and Date.UTC()
1 parent 0d4cd2d commit 7fb994c

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ Test262o: 0/11262 errors, 463 excluded
6363
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
6464

6565
Test262:
66-
Result: 67/83149 errors, 1645 excluded, 5538 skipped
66+
Result: 63/83149 errors, 1645 excluded, 5538 skipped

quickjs.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53236,6 +53236,21 @@ static double set_date_fields(double fields[minimum_length(7)], int is_local) {
5323653236
return time_clip(tv);
5323753237
}
5323853238

53239+
static double set_date_fields_checked(double fields[minimum_length(7)], int is_local)
53240+
{
53241+
int i;
53242+
double a;
53243+
for(i = 0; i < 7; i++) {
53244+
a = fields[i];
53245+
if (!isfinite(a))
53246+
return NAN;
53247+
fields[i] = trunc(a);
53248+
if (i == 0 && fields[0] >= 0 && fields[0] < 100)
53249+
fields[0] += 1900;
53250+
}
53251+
return set_date_fields(fields, is_local);
53252+
}
53253+
5323953254
static JSValue get_date_field(JSContext *ctx, JSValueConst this_val,
5324053255
int argc, JSValueConst *argv, int magic)
5324153256
{
@@ -53421,7 +53436,7 @@ static JSValue js_date_constructor(JSContext *ctx, JSValueConst new_target,
5342153436
// Date(y, mon, d, h, m, s, ms)
5342253437
JSValue rv;
5342353438
int i, n;
53424-
double a, val;
53439+
double val;
5342553440

5342653441
if (JS_IsUndefined(new_target)) {
5342753442
/* invoked as function */
@@ -53459,15 +53474,10 @@ static JSValue js_date_constructor(JSContext *ctx, JSValueConst new_target,
5345953474
if (n > 7)
5346053475
n = 7;
5346153476
for(i = 0; i < n; i++) {
53462-
if (JS_ToFloat64(ctx, &a, argv[i]))
53477+
if (JS_ToFloat64(ctx, &fields[i], argv[i]))
5346353478
return JS_EXCEPTION;
53464-
if (!isfinite(a))
53465-
break;
53466-
fields[i] = trunc(a);
53467-
if (i == 0 && fields[0] >= 0 && fields[0] < 100)
53468-
fields[0] += 1900;
5346953479
}
53470-
val = (i == n) ? set_date_fields(fields, 1) : NAN;
53480+
val = set_date_fields_checked(fields, 1);
5347153481
}
5347253482
has_val:
5347353483
#if 0
@@ -53497,23 +53507,17 @@ static JSValue js_Date_UTC(JSContext *ctx, JSValueConst this_val,
5349753507
// UTC(y, mon, d, h, m, s, ms)
5349853508
double fields[] = { 0, 0, 1, 0, 0, 0, 0 };
5349953509
int i, n;
53500-
double a;
5350153510

5350253511
n = argc;
5350353512
if (n == 0)
5350453513
return JS_NAN;
5350553514
if (n > 7)
5350653515
n = 7;
5350753516
for(i = 0; i < n; i++) {
53508-
if (JS_ToFloat64(ctx, &a, argv[i]))
53517+
if (JS_ToFloat64(ctx, &fields[i], argv[i]))
5350953518
return JS_EXCEPTION;
53510-
if (!isfinite(a))
53511-
return JS_NAN;
53512-
fields[i] = trunc(a);
53513-
if (i == 0 && fields[0] >= 0 && fields[0] < 100)
53514-
fields[0] += 1900;
5351553519
}
53516-
return JS_NewFloat64(ctx, set_date_fields(fields, 0));
53520+
return JS_NewFloat64(ctx, set_date_fields_checked(fields, 0));
5351753521
}
5351853522

5351953523
/* Date string parsing */

test262_errors.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ test262/test/annexB/language/expressions/assignmenttargettype/callexpression.js:
77
test262/test/annexB/language/expressions/assignmenttargettype/cover-callexpression-and-asyncarrowhead.js:20: SyntaxError: invalid assignment left-hand side
88
test262/test/language/identifier-resolution/assign-to-global-undefined.js:20: strict mode: expected error
99
test262/test/language/module-code/top-level-await/rejection-order.js:20: TypeError: $DONE() not called
10-
test262/test/staging/sm/Date/UTC-convert-all-arguments.js:13: Test262Error: index 1: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
11-
test262/test/staging/sm/Date/UTC-convert-all-arguments.js:13: strict mode: Test262Error: index 1: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
12-
test262/test/staging/sm/Date/constructor-convert-all-arguments.js:13: Test262Error: index undefined: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
13-
test262/test/staging/sm/Date/constructor-convert-all-arguments.js:13: strict mode: Test262Error: index undefined: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
1410
test262/test/staging/sm/Date/two-digit-years.js:26: Test262Error: Expected SameValue(«915177600000», «NaN») to be true
1511
test262/test/staging/sm/Date/two-digit-years.js:26: strict mode: Test262Error: Expected SameValue(«915177600000», «NaN») to be true
1612
test262/test/staging/sm/Function/arguments-parameter-shadowing.js:14: Test262Error: Expected SameValue(«true», «false») to be true

0 commit comments

Comments
 (0)