diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2023-12-09 12:26:37 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-09 22:26:51 +0100 |
commit | 4dcbf01dacb43c9d9a3b66463e8846e74b1341a4 (patch) | |
tree | 7b9d346b55cad07080b2868735ef6d3ba770d8d1 /lib/quickjs/quickjs.c | |
parent | 09bab6ef85710f93850c7e8fc34f6cb13829ac8b (diff) | |
download | chawan-4dcbf01dacb43c9d9a3b66463e8846e74b1341a4.tar.gz |
fixed negative zero date
Diffstat (limited to 'lib/quickjs/quickjs.c')
-rw-r--r-- | lib/quickjs/quickjs.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c index ffc4977f..b3f0b539 100644 --- a/lib/quickjs/quickjs.c +++ b/lib/quickjs/quickjs.c @@ -48034,20 +48034,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); } @@ -48318,8 +48317,11 @@ static int string_get_signed_digits(JSString *sp, int *pp, int64_t *pval) { p++; res = string_get_digits(sp, &p, pval); - if (res == 0 && sgn == '-') + if (res == 0 && sgn == '-') { + if (*pval == 0) + return -1; // reject negative zero *pval = -*pval; + } *pp = p; return res; } |