@@ -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+
5323953254static 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 }
5347253482has_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 */
0 commit comments