mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-29 22:44:25 +03:00
Make Date methods argument coercion spec compliant (bnoordhuis)
This commit is contained in:
21
quickjs.c
21
quickjs.c
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user