test262/test/built-ins/Object/preventExtensions
Peter Hoddie e4f4abdcb2
Compatibility with Hardened JavaScript ()
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
..
15.2.3.10-0-1.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-0-2.js Replace runTestCase with assert helpers [test/built-ins/Object/{freeze, preventExtensions, seal}] 2015-08-11 17:51:16 +02:00
15.2.3.10-1-1.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-1-2.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-1-3.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-1-4.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-1.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-2-1.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-2.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-1.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-2.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-3.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-4.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-5-1.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-5.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-6.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-7.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-8.js Compatibility with Hardened JavaScript () 2024-07-04 08:19:23 -07:00
15.2.3.10-3-9.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-10.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-11.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-12.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-13.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-14.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-15.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-16.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-17.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-18.js Compatibility with Hardened JavaScript () 2024-07-04 08:19:23 -07:00
15.2.3.10-3-19.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-20.js Remove links to hg.ecmascript.org 2015-07-17 17:43:09 +02:00
15.2.3.10-3-21.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-22.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-23.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
15.2.3.10-3-24.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
abrupt-completion.js Add Object.{freeze,preventExtensions,seal} abrupt completion tests () 2020-01-14 11:31:45 -05:00
name.js Update built-ins/Object to use verifyProperty 2024-02-28 17:01:01 -08:00
not-a-constructor.js remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
symbol-object-contains-symbol-properties-non-strict.js Add missing Symbol features flags 2017-09-07 15:51:13 -04:00
symbol-object-contains-symbol-properties-strict.js built-ins/Object/*: make all indentation consistent (depth & character) () 2018-02-15 15:33:45 -05:00
throws-when-false.js fix delete test, add error tests, fix lint () 2019-12-21 16:57:41 -05:00