diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2023-12-09 12:27:08 +0100 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2023-12-09 12:27:08 +0100 |
commit | 26fdf659e379a29afb47f1fd46e709b3576645fd (patch) | |
tree | c739b3fd4fad315413104f0741fa69935878af58 /quickjs.c | |
parent | b14d77be5b993fea6000d78a7e83c41f465b9611 (diff) | |
download | quickjs-26fdf659e379a29afb47f1fd46e709b3576645fd.tar.gz quickjs-26fdf659e379a29afb47f1fd46e709b3576645fd.zip |
Make Date methods argument coercion spec compliant (bnoordhuis)
Diffstat (limited to 'quickjs.c')
-rw-r--r-- | quickjs.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -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); } |