test262/test/built-ins/Promise
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
..
Symbol.species rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
all Compatibility with Hardened JavaScript (#4088) 2024-07-04 08:19:23 -07:00
allSettled remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
any remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
prototype remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
race add Promise.try tests 2024-05-01 15:27:31 -07:00
reject remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
resolve remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
try Add missing `return` statement to `throwsAsync` callback 2024-05-18 11:30:57 -04:00
withResolvers add Promise.try tests 2024-05-01 15:27:31 -07:00
constructor.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00
create-resolving-functions-reject.js remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
create-resolving-functions-resolve.js remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
exception-after-resolve-in-executor.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
exception-after-resolve-in-thenable-job.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
exec-args.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
executor-call-context-sloppy.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00
executor-call-context-strict.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00
executor-function-extensible.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
executor-function-length.js rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
executor-function-name.js Assign "name" property to all anonymous functions (#2299) 2019-08-15 10:58:40 -04:00
executor-function-not-a-constructor.js remove some auto-generated error messages in "assert.throws" tests 2024-03-25 12:09:10 +01:00
executor-function-property-order.js Set function `length` and `name` in `CreateBuiltinFunction` 2021-01-29 09:45:20 -05:00
executor-function-prototype.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
executor-not-callable.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00
get-prototype-abrupt-executor-not-callable.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00
get-prototype-abrupt.js Fix description of Promise constructor test (#2174) 2019-05-22 17:57:45 -04:00
is-a-constructor.js Standardize built-in constructor testing 2020-10-06 12:01:34 -04:00
length.js rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
name.js rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
promise.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00
property-order.js Set function `length` and `name` in `CreateBuiltinFunction` 2021-01-29 09:45:20 -05:00
proto-from-ctor-realm.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
reject-function-extensible.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
reject-function-length.js rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
reject-function-name.js Assign "name" property to all anonymous functions (#2299) 2019-08-15 10:58:40 -04:00
reject-function-nonconstructor.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-function-property-order.js Set function `length` and `name` in `CreateBuiltinFunction` 2021-01-29 09:45:20 -05:00
reject-function-prototype.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
reject-ignored-via-abrupt.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-ignored-via-fn-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-ignored-via-fn-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-via-abrupt-queue.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-via-abrupt.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-via-fn-deferred-queue.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-via-fn-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-via-fn-immed-queue.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
reject-via-fn-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-function-extensible.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
resolve-function-length.js rewrite tests to use verifyProperty 2024-03-25 12:05:06 +01:00
resolve-function-name.js Assign "name" property to all anonymous functions (#2299) 2019-08-15 10:58:40 -04:00
resolve-function-nonconstructor.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-function-property-order.js Set function `length` and `name` in `CreateBuiltinFunction` 2021-01-29 09:45:20 -05:00
resolve-function-prototype.js Frontmatter: fixup "info: >" to "info: |" 2018-01-05 12:27:59 -05:00
resolve-ignored-via-fn-deferred.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
resolve-ignored-via-fn-immed.js Remove duplicated es[56]id if esid is present 2019-08-05 10:54:37 -04:00
resolve-non-obj-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-non-obj-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-non-thenable-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-non-thenable-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-poisoned-then-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-poisoned-then-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-prms-cstm-then-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-prms-cstm-then-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-self.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-thenable-deferred.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
resolve-thenable-immed.js built-ins/Promise/*: make all indentation consistent (depth & character) (#1433) 2018-02-15 15:11:21 -05:00
undefined-newtarget.js Improve Promise constructor coverage (#2158) 2019-05-22 17:33:09 -04:00