453 Commits

Author SHA1 Message Date
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
Chengzhong Wu
8a2229cde8
Add tests for Source Phase Imports (#3980) 2024-06-27 14:58:04 +02:00
Nicolò Ribaudo
41515e87e5 Use import-attributes flag in new generated tests 2023-10-26 18:21:19 -07:00
Nicolò Ribaudo
06f6ae960a Copy all import assertions tests as a basis for import attributes tests 2023-10-26 18:21:19 -07:00
Daniel Minor
ca9fa92dc3 Fixup template files 2023-10-05 10:23:12 -07:00
Nicolò Ribaudo
7ef1833109 Move all tests using import assertions to files named as such 2023-07-17 16:32:25 +02:00
Huáng Jùnliàng
a3880a460a update decorator member expr private id test cases 2023-03-29 12:54:37 -07:00
José Julián Espina
4a6439e4a7
Add Array.prototype.includes and exponentiation features (#3799) 2023-03-23 10:51:08 +01:00
Cam Tenny
4d9d5c570d Refactor simple cases of (IIFE/async function).then(\$DONE, \$DONE); to use asyncTest 2023-02-21 11:04:09 -08:00
Huáng Jùnliàng
58b3321dba remove invalid element decorator yield reference tests 2023-01-03 12:33:04 -08:00
Philip Chimento
db39fee915 Fix name conflict in path of decorators test template
This test template shared the same "path" as its sibling,
cls-decl-decorators-valid-syntax.template. That meant that these two
templates would race to generate the same test files with different
contents.

This prefixes the generated tests for class element decorators (as opposed
to class decorators) with "class-element-".
2022-11-30 16:04:02 -08:00
Philip Chimento
1d5e560ca7 Fix typo 2022-11-30 16:04:02 -08:00
Philip Chimento
d87a7da6e1 Replace Object.hasOwnProperty.call with Object.prototype.hasOwnProperty.call
While we're at it, use assert() instead of assert.sameValue() for brevity,
if we are not specifically testing that the return value of hasOwnProperty
is the value true or false; and add more informative assertion messages to
help with debugging.

In some cases, the Object.hasOwnProperty.call could be replaced with
verifyProperty(), if the property descriptor was also being verified at
the same time.

This fixes some tests that were faulty to begin with: a common mistake was
Object.hasOwnProperty(obj, prop) which is probably going to return false
when that's not what you want.

The only instances left of `Object.hasOwnProperty` are one regression test
in implementation-contributed which I can't tell if it was intentionally
needed to trigger the regression, and a few instances of
`Object.hasOwnProperty('prototype')` which would defeat the purpose to
convert into `Object.prototype.hasOwnProperty.call(Object, 'prototype')`
form.

Closes: #3524
2022-11-30 16:04:02 -08:00
legendecas
ee521159d5 Fix decorator tests 2022-06-23 15:17:43 -04:00
Youssef Soliman
79c4496559 Fixed spelling error identifer -> identifier. 2022-06-21 10:14:17 +02:00
Huáng Jùnliàng
79e3bc5176
add noStrict flag to yield-as-binding-id cases (#3551) 2022-06-09 09:01:21 +02:00
legendecas
6f8e0f67ca Decorators: add initial tests on class 2022-05-18 09:49:49 -04:00
Philip Chimento
615a2eb9a1 Fix tests for private reference with logical assignment
There were three things wrong with the 'and', 'or', and 'nullish' tests
that I added as part of #2940:

1. They were in the wrong folder (should be
   expressions/logical-assignment, not expressions/compound-assignment)
2. The tests for ||= and ??= on readonly accessor properties were
   incorrect. These assignments would short-circuit if the getter
   returned 1 as it previously did, so PutValue would not throw.
3. The tests for ||= and ??= on private methods were invalid, as a
   method always evaluates to true in a boolean context, and is not
   nullish, so these would always short-circuit.

I've removed the invalid private method cases, fixed the readonly
accessor cases, and added new templates to test the short-circuit
behaviour as well as the non-short-circuit behaviour.

Closes: #3413
2022-02-21 15:38:59 -05:00
Philip Chimento
1b1097dbf6 Add tests for compound assignment to private reference
This tests compound assignment, with each compound assignment operator,
to each kind of private reference (private field, private accessor
property with getter and setter, private accessor property with only
getter, and private method). The latter two cannot be assigned to and
therefore throw.

Closes: #2940
2022-02-16 09:56:59 -05:00
dnalborczyk
0659f8d952 Update eval-script-code-host-resolves-module-code.case 2021-10-22 09:00:00 -04:00
Mike Pennisi
8d420cef41 Remove unused functions 2021-10-13 14:18:32 -04:00
Mike Pennisi
891b7915bd Remove superfluous EmptyStatement 2021-10-05 16:28:06 -04:00
Mike Pennisi
a6834093aa Improve coverage by invoking functions as intended
Some tests which include function declarations designed to verify
behavior do not reference those functions. Insert the references
necessary for those functions to serve their intended purpose.
2021-10-05 16:22:56 -04:00
rwaldron
e6b47d7738 chore: update src/**/*.case to use assert.compareArray wherever applicable 2021-10-01 16:38:56 -04:00
Mike Pennisi
d9ddf80479 Revert "Merge pull request #3219 from tc39/rwaldron/migrate-comparearray"
This reverts commit b690cb67be9b487eb10156c03e2c00869e88cc9d, reversing
changes made to 50dd431dffe5cf86e9064a652d6b01dbbe542cf0. This is
necessary because the reverted changeset reduced coverage by an unknown
extent.
2021-10-01 10:18:47 -04:00
rwaldron
d7414a8d8e chore: update src/**/*.case to use assert.compareArray wherever applicable 2021-09-24 11:21:44 -04:00
rwaldron
85a54852e6 refactor: remove function syntax boundary from AssignmentTargetType templates 2021-08-19 11:52:48 -04:00
rwaldron
4bdba71130 chore: migrate $ERROR -> throw new Test262Error in src/* 2021-07-22 10:56:15 -04:00
Richard Gibson
d9a20dfe34 Add a maintenance file for src/insignificant-input-elements 2021-07-16 09:49:17 -04:00
Richard Gibson
3a69fc75d9 Add a test case for each WhiteSpace/LineTerminator character 2021-07-16 09:49:17 -04:00
Richard Gibson
5b1cfdd2b0 Add template for whitespace-after-regular-expression-literal tests 2021-07-16 09:49:17 -04:00
Mike Pennisi
18834b2e19 Add tests for import assertions 2021-05-14 11:04:29 -04:00
Mike Pennisi
b9bc25096b Apply logical-assignment-operators feature flag 2021-04-20 09:53:57 -04:00
Caio Lima
f81c2f5422 Adding test case for super access from class field defined as arrow function 2021-01-18 09:41:23 -05:00
Rick Waldron
602c828805 Coverage: read-only function expression name. Closes gh-2896 2020-11-18 16:30:13 -05:00
Rick Waldron
a563e3a3f8 Remove template that is generating duplicate tests 2020-10-29 13:48:50 -04:00
Rick Waldron
0e77b43c9b Split up indirect and direct eval cases 2020-10-14 14:20:46 -04:00
Rick Waldron
bab4da88e3 Remove erroneous test templates and generated files 2020-10-14 14:20:46 -04:00
Rick Waldron
0a84a4f176 Forbidden Extensions: revised to check property existence 2020-10-14 14:01:01 -04:00
Rick Waldron
a6d38ffe9a Correction: add explicit language re: application of Forbidden Extensions, bullet 1 2020-10-07 16:43:31 -04:00
Rick Waldron
97e051114a Separate cases 2020-10-05 10:53:43 -04:00
Rick Waldron
74a4152703 Coverage: lexical arguments, new.target, in async arrow functions. Fixes gh-1737 2020-10-05 10:53:43 -04:00
Rick Waldron
a7fcbb37b9 Fix: add flags to src/computed-property-names/evaluation/class-*-fields*. Fixes gh-2834 2020-09-30 11:51:44 -04:00
devsnek
2fade3db47 Update WeakRef.case 2020-09-29 18:00:55 -04:00
Rick Waldron
d65346149e Coverage: computed property names from yield expression
# Conflicts:
#	src/computed-property-names/evaluation/yield-expression.template
2020-09-25 16:12:12 -04:00
Rick Waldron
bba4fbc259 Coverage: globalThis[Symbol.unscopables]. Fixes gh-1750 2020-09-25 15:54:49 -04:00
Rick Waldron
4853f6d363 Make test async 2020-09-25 14:42:12 -04:00
Rick Waldron
2aff8eb9a4 Coverage: computed property names from await expression 2020-09-25 14:42:12 -04:00
Rick Waldron
4375480990 Coverage: computed property names that evaluate to null. Fixes gh-1734 2020-09-25 13:30:10 -04:00
Rick Waldron
ac19f339e7 Fix: poisoned next function in "IteratorClose is called when reference evaluation produces a "return" completion". Fixes gh-670 2020-09-25 13:15:33 -04:00