test262/test/language/expressions
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
..
addition Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
array Rebuild generated tests 2022-11-30 16:04:02 -08:00
arrow-function Use verifyProperty in language/expressions tests 2023-09-13 16:05:40 +02:00
assignment Add additional tests for tc39/ecma262#3307. 2024-04-22 12:36:07 -07:00
assignmenttargettype Add tests for Source Phase Imports (#3980) 2024-06-27 14:58:04 +02:00
async-arrow-function Remove 'AsyncArrowFunction' test 2024-07-04 11:03:23 +02:00
async-function Generated tests for refactoring (IIFE/async function).then(\$DONE, \$DONE); to use asyncTest 2023-02-21 11:04:09 -08:00
async-generator Generated tests for refactoring (IIFE/async function).then(\$DONE, \$DONE); to use asyncTest 2023-02-21 11:04:09 -08:00
await Refactor simple cases of (IIFE/async function).then(\$DONE, \$DONE); to use asyncTest 2023-02-21 11:04:09 -08:00
bitwise-and chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
bitwise-not chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
bitwise-or chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
bitwise-xor chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
call Rebuild generated tests 2022-11-30 16:04:02 -08:00
class Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
coalesce Fix failure phase in coalesce tests (#2415) 2019-11-11 14:38:26 -05:00
comma chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
compound-assignment Add `Array.prototype.includes` and `exponentiation` features (#3799) 2023-03-23 10:51:08 +01:00
concatenation chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
conditional chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
delete Remove unused functions 2021-10-05 16:24:16 -04:00
division Correct typo to improve coverage 2021-09-16 16:34:28 -04:00
does-not-equals chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
dynamic-import Add tests for Source Phase Imports (#3980) 2024-06-27 14:58:04 +02:00
equals chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
exponentiation Add `Array.prototype.includes` and `exponentiation` features (#3799) 2023-03-23 10:51:08 +01:00
function Use verifyProperty in language/expressions tests 2023-09-13 16:05:40 +02:00
generators Use verifyProperty in language/expressions tests 2023-09-13 16:05:40 +02:00
greater-than chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
greater-than-or-equal chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
grouping chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
import.meta Update "info" field (#2941) 2021-01-28 16:03:01 -08:00
in Add various private field and private method tests 2021-08-04 15:06:38 -04:00
instanceof chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
left-shift chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
less-than chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
less-than-or-equal chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
logical-and chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
logical-assignment Fix tests for private reference with logical assignment 2022-02-21 15:38:59 -05:00
logical-not chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
logical-or chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
member-expression Add additional tests for tc39/ecma262#3307. 2024-04-22 12:36:07 -07:00
modulus chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
multiplication chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
new Rebuild generated tests 2022-11-30 16:04:02 -08:00
new.target Refactor simple cases of (IIFE/async function).then(\$DONE, \$DONE); to use asyncTest 2023-02-21 11:04:09 -08:00
object Use verifyProperty in language/expressions tests 2023-09-13 16:05:40 +02:00
optional-chaining Refactor simple cases of (IIFE/async function).then(\$DONE, \$DONE); to use asyncTest 2023-02-21 11:04:09 -08:00
postfix-decrement Test for assignment with target wrapped in two sets of parentheses 2023-11-21 09:51:03 -05:00
postfix-increment Test for assignment with target wrapped in two sets of parentheses 2023-11-21 09:51:03 -05:00
prefix-decrement Delete trailing space after `|` 2023-06-29 14:08:47 +02:00
prefix-increment Fix copyright 2023-05-18 11:19:31 -07:00
property-accessors tools: enforce restriction on YAML negative key 2022-01-10 13:50:38 -05:00
relational chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
right-shift chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
strict-does-not-equals chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
strict-equals chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
subtraction chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
super Rebuild generated tests 2022-11-30 16:04:02 -08:00
tagged-template Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
template-literal Move some AnnexB tests per proposed spec change 2021-05-21 13:06:41 -04:00
this chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
typeof Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
unary-minus chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
unary-plus Test that "infinity" is not recognized as numeric 2022-04-04 16:56:40 -04:00
unsigned-right-shift chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
void chore: migrate $ERROR -> throw new Test262Error in test/language/e* (#3098) 2021-07-28 13:48:39 -07:00
yield Add yield* tests 2020-06-03 13:25:03 -04:00
tco-pos.js Fix esid: static-semantics-hasproductionintailposition => sec-static-semantics-hascallintailposition 2018-01-10 15:44:56 -05:00