Skip to content

Commit 7c9cf46

Browse files
authored
Make Date methods argument coercion spec compliant (#104)
1 parent 7aabea9 commit 7c9cf46

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

quickjs.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -45895,20 +45895,20 @@ static JSValue set_date_field(JSContext *ctx, JSValueConst this_val,
4589545895
res = get_date_fields(ctx, this_val, fields, is_local, first_field == 0);
4589645896
if (res < 0)
4589745897
return JS_EXCEPTION;
45898-
if (res && argc > 0) {
45899-
n = end_field - first_field;
45900-
if (argc < n)
45901-
n = argc;
45902-
for(i = 0; i < n; i++) {
45903-
if (JS_ToFloat64(ctx, &a, argv[i]))
45904-
return JS_EXCEPTION;
45905-
if (!isfinite(a))
45906-
goto done;
45907-
fields[first_field + i] = trunc(a);
45908-
}
45909-
d = set_date_fields(fields, is_local);
45898+
45899+
// Argument coercion is observable and must be done unconditionally.
45900+
n = min_int(argc, end_field - first_field);
45901+
for(i = 0; i < n; i++) {
45902+
if (JS_ToFloat64(ctx, &a, argv[i]))
45903+
return JS_EXCEPTION;
45904+
if (!isfinite(a))
45905+
res = FALSE;
45906+
fields[first_field + i] = trunc(a);
4591045907
}
45911-
done:
45908+
45909+
if (res && argc > 0)
45910+
d = set_date_fields(fields, is_local);
45911+
4591245912
return JS_SetThisTimeValue(ctx, this_val, d);
4591345913
}
4591445914

test262_errors.txt

-24
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-brok
55
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js:34: strict mode: TypeError: $DONE() not called
66
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js:39: TypeError: $DONE() not called
77
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js:39: strict mode: TypeError: $DONE() not called
8-
test262/test/built-ins/Date/prototype/setDate/arg-coercion-order.js:28: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
9-
test262/test/built-ins/Date/prototype/setDate/arg-coercion-order.js:28: strict mode: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
10-
test262/test/built-ins/Date/prototype/setHours/arg-coercion-order.js:57: Test262Error: Expected [] and [valueOf hour, valueOf min, valueOf sec, valueOf ms] to have the same contents.
11-
test262/test/built-ins/Date/prototype/setHours/arg-coercion-order.js:57: strict mode: Test262Error: Expected [] and [valueOf hour, valueOf min, valueOf sec, valueOf ms] to have the same contents.
12-
test262/test/built-ins/Date/prototype/setMilliseconds/arg-coercion-order.js:28: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
13-
test262/test/built-ins/Date/prototype/setMilliseconds/arg-coercion-order.js:28: strict mode: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
14-
test262/test/built-ins/Date/prototype/setMinutes/arg-coercion-order.js:49: Test262Error: Expected [] and [valueOf min, valueOf sec, valueOf ms] to have the same contents.
15-
test262/test/built-ins/Date/prototype/setMinutes/arg-coercion-order.js:49: strict mode: Test262Error: Expected [] and [valueOf min, valueOf sec, valueOf ms] to have the same contents.
16-
test262/test/built-ins/Date/prototype/setMonth/arg-coercion-order.js:41: Test262Error: Expected [] and [valueOf month, valueOf date] to have the same contents.
17-
test262/test/built-ins/Date/prototype/setMonth/arg-coercion-order.js:41: strict mode: Test262Error: Expected [] and [valueOf month, valueOf date] to have the same contents.
18-
test262/test/built-ins/Date/prototype/setSeconds/arg-coercion-order.js:41: Test262Error: Expected [] and [valueOf sec, valueOf ms] to have the same contents.
19-
test262/test/built-ins/Date/prototype/setSeconds/arg-coercion-order.js:41: strict mode: Test262Error: Expected [] and [valueOf sec, valueOf ms] to have the same contents.
20-
test262/test/built-ins/Date/prototype/setUTCDate/arg-coercion-order.js:25: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
21-
test262/test/built-ins/Date/prototype/setUTCDate/arg-coercion-order.js:25: strict mode: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
22-
test262/test/built-ins/Date/prototype/setUTCHours/arg-coercion-order.js:50: Test262Error: Expected [] and [valueOf hour, valueOf min, valueOf sec, valueOf ms] to have the same contents.
23-
test262/test/built-ins/Date/prototype/setUTCHours/arg-coercion-order.js:50: strict mode: Test262Error: Expected [] and [valueOf hour, valueOf min, valueOf sec, valueOf ms] to have the same contents.
24-
test262/test/built-ins/Date/prototype/setUTCMilliseconds/arg-coercion-order.js:26: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
25-
test262/test/built-ins/Date/prototype/setUTCMilliseconds/arg-coercion-order.js:26: strict mode: Test262Error: ToNumber invoked exactly once Expected SameValue(«0», «1») to be true
26-
test262/test/built-ins/Date/prototype/setUTCMinutes/arg-coercion-order.js:42: Test262Error: Expected [] and [valueOf min, valueOf sec, valueOf ms] to have the same contents.
27-
test262/test/built-ins/Date/prototype/setUTCMinutes/arg-coercion-order.js:42: strict mode: Test262Error: Expected [] and [valueOf min, valueOf sec, valueOf ms] to have the same contents.
28-
test262/test/built-ins/Date/prototype/setUTCMonth/arg-coercion-order.js:34: Test262Error: Expected [] and [valueOf month, valueOf date] to have the same contents.
29-
test262/test/built-ins/Date/prototype/setUTCMonth/arg-coercion-order.js:34: strict mode: Test262Error: Expected [] and [valueOf month, valueOf date] to have the same contents.
30-
test262/test/built-ins/Date/prototype/setUTCSeconds/arg-coercion-order.js:34: Test262Error: Expected [] and [valueOf sec, valueOf ms] to have the same contents.
31-
test262/test/built-ins/Date/prototype/setUTCSeconds/arg-coercion-order.js:34: strict mode: Test262Error: Expected [] and [valueOf sec, valueOf ms] to have the same contents.
328
test262/test/built-ins/Function/internals/Construct/derived-this-uninitialized-realm.js:20: Test262Error: Expected a ReferenceError but got a different error constructor with the same name
339
test262/test/built-ins/Function/internals/Construct/derived-this-uninitialized-realm.js:20: strict mode: Test262Error: Expected a ReferenceError but got a different error constructor with the same name
3410
test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: Test262Error: Expected [a, abc] and [a, undefined] to have the same contents. ? quantifier

0 commit comments

Comments
 (0)