test262/test/built-ins/Object
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
..
assign remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
create Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
defineProperties Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
defineProperty Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
entries remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
freeze Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
fromEntries remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
getOwnPropertyDescriptor remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
getOwnPropertyDescriptors remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
getOwnPropertyNames remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
getOwnPropertySymbols remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
getPrototypeOf Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
groupBy Fix groupBy string test keys to be insertion order 2024-04-11 16:56:41 -07:00
hasOwn remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
internals/DefineOwnProperty Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
is remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
isExtensible remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
isFrozen remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
isSealed remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
keys Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
preventExtensions Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
prototype Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
seal Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
setPrototypeOf remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
values remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
S9.9_A3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S9.9_A4.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S9.9_A5.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S9.9_A6.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A1_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A1_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A1_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A1_T4.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A1_T5.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T4.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T5.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T6.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T7.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T8.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T9.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T10.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T11.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T12.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T13.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A2_T14.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A3_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A3_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.1.1_A3_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A1_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A1_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A1_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A1_T4.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A1_T5.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A2_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A2_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A2_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A2_T5.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A2_T6.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A2_T7.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A3_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A3_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A3_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A4_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A4_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A4_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A5_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A5_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A5_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A5_T4.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A6_T1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A6_T2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.2.1_A6_T3.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.3_A1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.3_A2.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
S15.2.3_A3.js Replace Object.hasOwnProperty.call with Object.prototype.hasOwnProperty.call 2022-11-30 16:04:02 -08:00
S15.2_A1.js Transform legacy format to harness assertions: test/built-ins/O*/**/*.js 2021-09-02 11:34:27 -07:00
bigint.js add BigInt tests 2017-08-24 15:58:14 -04:00
is-a-constructor.js Standardize built-in constructor testing 2020-10-06 12:01:34 -04:00
prop-desc.js Update built-ins/Object to use verifyProperty 2024-02-28 17:01:01 -08:00
property-order.js Set function `length` and `name` in `CreateBuiltinFunction` 2021-01-29 09:45:20 -05:00
proto-from-ctor-realm.js Add "proto-from-ctor-realm" tests for Intl constructors (#2334) 2019-09-11 17:22:21 -03:00
subclass-object-arg.js fix built-ins/Object/subclass-object-arg (#2200) 2019-06-19 15:48:53 -04:00
symbol_object-returns-fresh-symbol.js Add missing Symbol features flags 2017-09-07 15:51:13 -04:00