mirror of https://github.com/tc39/test262.git
e4f4abdcb2
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. |
||
---|---|---|
.. | ||
builtin-objects | ||
binding.js | ||
builtins.js | ||
class-definition-evaluation-empty-constructor-heritage-present.js | ||
class-definition-null-proto-contains-return-override.js | ||
class-definition-null-proto-missing-return-override.js | ||
class-definition-null-proto-super.js | ||
class-definition-null-proto-this.js | ||
class-definition-null-proto.js | ||
class-definition-parent-proto-null.js | ||
default-constructor-2.js | ||
default-constructor-spread-override.js | ||
default-constructor.js | ||
derived-class-return-override-catch-finally-arrow.js | ||
derived-class-return-override-catch-finally.js | ||
derived-class-return-override-catch-super-arrow.js | ||
derived-class-return-override-catch-super.js | ||
derived-class-return-override-catch.js | ||
derived-class-return-override-finally-super-arrow.js | ||
derived-class-return-override-finally-super.js | ||
derived-class-return-override-for-of-arrow.js | ||
derived-class-return-override-for-of.js | ||
derived-class-return-override-with-boolean.js | ||
derived-class-return-override-with-empty.js | ||
derived-class-return-override-with-null.js | ||
derived-class-return-override-with-number.js | ||
derived-class-return-override-with-object.js | ||
derived-class-return-override-with-string.js | ||
derived-class-return-override-with-symbol.js | ||
derived-class-return-override-with-this.js | ||
derived-class-return-override-with-undefined.js | ||
superclass-arrow-function.js | ||
superclass-async-function.js | ||
superclass-async-generator-function.js | ||
superclass-bound-function.js | ||
superclass-generator-function.js | ||
superclass-prototype-setter-constructor.js | ||
superclass-prototype-setter-method-override.js | ||
superclass-static-method-override.js |