Make Date methods argument coercion spec compliant (bnoordhuis)

This commit is contained in:
Fabrice Bellard
2023-12-09 12:27:08 +01:00
parent b14d77be5b
commit 26fdf659e3
2 changed files with 10 additions and 35 deletions

View File

@@ -47816,20 +47816,19 @@ static JSValue set_date_field(JSContext *ctx, JSValueConst this_val,
res = get_date_fields(ctx, this_val, fields, is_local, first_field == 0);
if (res < 0)
return JS_EXCEPTION;
// Argument coercion is observable and must be done unconditionally.
n = min_int(argc, end_field - first_field);
for(i = 0; i < n; i++) {
if (JS_ToFloat64(ctx, &a, argv[i]))
return JS_EXCEPTION;
if (!isfinite(a))
res = FALSE;
fields[first_field + i] = trunc(a);
}
if (res && argc > 0) {
n = end_field - first_field;
if (argc < n)
n = argc;
for(i = 0; i < n; i++) {
if (JS_ToFloat64(ctx, &a, argv[i]))
return JS_EXCEPTION;
if (!isfinite(a))
goto done;
fields[first_field + i] = trunc(a);
}
d = set_date_fields(fields, is_local);
}
done:
return JS_SetThisTimeValue(ctx, this_val, d);
}