test262/test/built-ins/Date
Peter Hoddie e4f4abdcb2
Compatibility with Hardened JavaScript (#4088)
This PR proposes changes to existing test262 tests to allow them to pass under Hardened JavaScript (see Secure ECMAScript proposal and Hardened JavaScript). Moddable uses Hardened JavaScript for JavaScript runtimes on resource constrained embedded devices, including those targeted by ECMA-419.

The changes fall into four groups:

1. Replace use of new Date() with new Date(1970). Scripts running inside a Compartment cannot retrieve the current time, so new Date() throws but new Date(1970) succeeds. Very few tests need the current time, but instead simply need a Date instance.
2. Use Object.defineProperty instead of setting existing built-in properties directly, such as toString and toValue. In Hardened JavaScript, prototypes of built-in objects are frozen. Consequently, setting properties of an instance that exist on the prototype throw (Hardened JavaScript is always in strict mode).
3. Eliminate use of Math.random(). Scripts running inside a Compartment cannot generate random numbers. One test identified so far uses Math.random() in a way that can easily be replaced with a counter.
4. Narrow the scope of exception tests. Consider the following

assert.throws(TypeError, () => {
  var s1 = new Date();
  s1.toString = Boolean.prototype.toString;
  s1.toString();
});

This test passes, but only because new Date() fails by throwing a TypeError. If the invocation of the Date constructor is resolved by (1) above, then the assignment to toString fails as per (2) above. The script should be modified as below to ensure that assert.throws only tests the intended statement, s1.toString(). The modified script tests the intended functionality and passes under Hardened JavaScript

var s1 = new Date(1970);
Object.defineProperty(s1, "toString", {
  value: Boolean.prototype.toString
});
assert.throws(TypeError, () => {
  s1.toString();
});

This is an initial PR to begin the process of adapting test262 for use with Hardened JavaScript. Further changes are expected, with the vast majority likely to fall into the four groups described above.

Thank you to gibson042, kriskowal, and erights for their advice on this work.
2024-07-04 08:19:23 -07:00
..
UTC remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
now remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
parse remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
prototype Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
15.9.1.15-1.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.2.1_A1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.2.1_A2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A1_T1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A1_T2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A1_T3.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A1_T4.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A1_T5.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A1_T6.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A2_T1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A2_T2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A2_T3.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A2_T4.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A2_T5.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A2_T6.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T1.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T1.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T2.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T2.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T3.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T3.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T4.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T4.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T5.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T5.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T6.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A3_T6.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T0.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T3.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T4.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T5.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A4_T6.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A5_T1.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.3.1_A5_T2.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.3.1_A5_T3.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.3.1_A5_T4.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.3.1_A5_T5.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.3.1_A5_T6.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S15.9.3.1_A6_T1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A6_T2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A6_T3.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A6_T4.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.1_A6_T5.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.2_A1_T1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.2_A2_T1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.2_A3_T1.1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.3.2_A3_T1.2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.4_A1.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.4_A2.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.4_A3.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.4_A4.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
S15.9.4_A5.js Transform legacy format to harness assertions 2021-09-02 11:21:25 -07:00
TimeClip_negative_zero.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
coercion-errors.js Revert "js-beautify: make all indentation consistent (depth & character) (#1409)" (#1412) 2018-02-09 12:09:47 -05:00
coercion-order.js Revert "js-beautify: make all indentation consistent (depth & character) (#1409)" (#1412) 2018-02-09 12:09:47 -05:00
construct_with_date.js chore: migrate $ERROR -> throw new Test262Error in test/built-ins/Date (#3079) 2021-07-21 14:14:06 -07:00
is-a-constructor.js Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
name.js rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
prop-desc.js Improve coverage: ctor props of the global object 2019-09-27 15:39:10 -04:00
proto-from-ctor-realm-one.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
proto-from-ctor-realm-two.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
proto-from-ctor-realm-zero.js Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
subclassing.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-get-symbol-to-prim-err.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-symbol-to-prim-err.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-symbol-to-prim-invocation.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-symbol-to-prim-return-obj.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-symbol-to-prim-return-prim.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-to-primitive-call-err.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-to-primitive-call.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-to-primitive-get-meth-err.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-to-primitive-result-faulty.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-to-primitive-result-non-string-prim.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
value-to-primitive-result-string.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
year-zero.js Test ISO strings with extended year -000000 2022-04-25 11:34:52 -04:00