test262/test/built-ins/Number
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
..
MAX_VALUE Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
MIN_VALUE Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
NEGATIVE_INFINITY Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
POSITIVE_INFINITY Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
isFinite remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
isInteger remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
isNaN remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
isSafeInteger remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
parseFloat remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
parseInt 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.7.3-1.js Replace runTestCase with assert helpers [test/built-ins/Number] 2015-08-06 18:26:38 +02:00
15.7.3-2.js built-ins/Number/*: make all indentation consistent (depth & character) (#1436) 2018-02-15 15:11:50 -05:00
15.7.4-1.js built-ins/Number/*: make all indentation consistent (depth & character) (#1436) 2018-02-15 15:11:50 -05:00
EPSILON.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
MAX_SAFE_INTEGER.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
MIN_SAFE_INTEGER.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
NaN.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
S8.12.8_A3.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S8.12.8_A4.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.1_A1_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A2_U180E.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
S9.3.1_A3_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A3_T1_U180E.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
S9.3.1_A3_T2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A3_T2_U180E.js built-ins/Number/*: make all indentation consistent (depth & character) (#1436) 2018-02-15 15:11:50 -05:00
S9.3.1_A4_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A4_T2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A5_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A5_T2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A5_T3.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A6_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A6_T2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A7.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A8.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A9.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A10.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A11.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A12.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A13.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A14.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A15.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A16.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A17.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A18.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A19.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A20.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A21.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A22.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A23.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A24.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A25.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A26.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A27.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A28.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A29.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A30.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A31.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3.1_A32.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3_A1_T1.js Improve assertions comparing values to NaN (#690) 2016-07-01 11:22:55 -07:00
S9.3_A2_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3_A3_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3_A4.1_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3_A4.2_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S9.3_A5_T1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.1.1_A1.js Test that "infinity" is not recognized as numeric 2022-04-04 16:56:40 -04:00
S15.7.1.1_A2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.2.1_A1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.2.1_A2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.2.1_A3.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.2.1_A4.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A1.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A2.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A3.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A4.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A5.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A6.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A7.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.3_A8.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T01.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T02.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T03.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T04.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T05.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T06.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
S15.7.5_A1_T07.js Transform legacy format to harness assertions: test/built-ins/N*/**/*.js 2021-09-02 11:34:34 -07:00
bigint-conversion.js Add `Array.prototype.includes` and `exponentiation` features (#3799) 2023-03-23 10:51:08 +01:00
is-a-constructor.js Standardize built-in constructor testing 2020-10-06 12:01:34 -04:00
parseFloat.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
parseInt.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
prop-desc.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
proto-from-ctor-realm.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
return-abrupt-tonumber-value-symbol.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
return-abrupt-tonumber-value.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
string-binary-literal-invalid.js Add more ToNumber tests for invalid binary and octal literals 2018-01-05 12:48:57 -05:00
string-binary-literal.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
string-hex-literal-invalid.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:50:00 -05:00
string-numeric-separator-literal-bil-bd-nsl-bd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-bil-bd-nsl-bds.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-bil-bds-nsl-bd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-bil-bds-nsl-bds.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dd-dot-dd-ep-sign-minus-dd-nsl-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dd-dot-dd-ep-sign-minus-dds-nsl-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dd-dot-dd-ep-sign-plus-dd-nsl-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dd-dot-dd-ep-sign-plus-dds-nsl-dd.js built-ins/Number/*: make all indentation consistent (depth & character) (#1436) 2018-02-15 15:11:50 -05:00
string-numeric-separator-literal-dd-nsl-dd-one-of.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dds-dot-dd-nsl-dd-ep-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dds-nsl-dd.js Fix yaml consistency 2018-03-06 14:36:02 -05:00
string-numeric-separator-literal-dot-dd-nsl-dd-ep.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dot-dd-nsl-dds-ep.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dot-dds-nsl-dd-ep.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-dot-dds-nsl-dds-ep.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-hil-hd-nsl-hd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-hil-hd-nsl-hds.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-hil-hds-nsl-hd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-hil-hds-nsl-hds.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-hil-od-nsl-od-one-of.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-nzd-nsl-dd-one-of.js built-ins/Number/*: make all indentation consistent (depth & character) (#1436) 2018-02-15 15:11:50 -05:00
string-numeric-separator-literal-nzd-nsl-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-nzd-nsl-dds.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-oil-od-nsl-od-one-of.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-oil-od-nsl-od.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-oil-od-nsl-ods.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-oil-ods-nsl-od.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-oil-ods-nsl-ods.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-sign-minus-dds-nsl-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-numeric-separator-literal-sign-plus-dds-nsl-dd.js Fix ToNumber operations 2018-02-08 11:13:54 -05:00
string-octal-literal-invald.js Add more ToNumber tests for invalid binary and octal literals 2018-01-05 12:48:57 -05:00
string-octal-literal.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00