summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md3
-rw-r--r--harness/assert.js7
-rw-r--r--test/harness/assert-throws-early-incorrect-ctor.js20
-rw-r--r--test/harness/assert-throws-early-not-early.js16
-rw-r--r--test/harness/assert-throws-early-referenceerror.js9
-rw-r--r--test/harness/assert-throws-early-syntaxerror.js9
6 files changed, 63 insertions, 1 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8e007afc1..d7e0aeec2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -159,7 +159,8 @@ $DONE(arg) | see Writing Asynchronous Tests, below
assert(value, message) | throw a new Test262Error instance if the specified value is not strictly equal to the JavaScript `true` value; accepts an optional string message for use in creating the error
assert.sameValue(actual, expected, message) | throw a new Test262Error instance if the first two arguments are not [the same value](https://tc39.github.io/ecma262/#sec-samevalue); accepts an optional string message for use in creating the error
assert.notSameValue(actual, unexpected, message) | throw a new Test262Error instance if the first two arguments are [the same value](https://tc39.github.io/ecma262/#sec-samevalue); accepts an optional string message for use in creating the error
-assert.throws(expectedErrorConstructor, fn) | throw a new Test262Error instance if the provided function does not throw an error, or if the constructor of the value thrown does not match the provided constructor
+assert.throws(expectedErrorConstructor, fn, message) | throw a new Test262Error instance if the provided function does not throw an error, or if the constructor of the value thrown does not match the provided constructor
+assert.throws.early(expectedErrorConstructor, fn) | throw a new Test262Error instance if the provided function does not throw an early error, or if the constructor of the value thrown does not match the provided constructor. This assertion catches only errors that will be parsed through `Function(code)`.
```
/// error class
diff --git a/harness/assert.js b/harness/assert.js
index 545b965f2..1bd3d31fd 100644
--- a/harness/assert.js
+++ b/harness/assert.js
@@ -79,3 +79,10 @@ assert.throws = function (expectedErrorConstructor, func, message) {
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
$ERROR(message);
};
+
+assert.throws.early = function(err, code) {
+ let wrappedCode = `function wrapperFn() { ${code} }`;
+ let ieval = eval;
+
+ assert.throws(err, () => { Function(wrappedCode); }, `Function: ${code}`);
+};
diff --git a/test/harness/assert-throws-early-incorrect-ctor.js b/test/harness/assert-throws-early-incorrect-ctor.js
new file mode 100644
index 000000000..c291c930a
--- /dev/null
+++ b/test/harness/assert-throws-early-incorrect-ctor.js
@@ -0,0 +1,20 @@
+// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: >
+ Functions that throw values whose constructor does not match the specified
+ constructor do not satisfy the assertion.
+---*/
+
+// monkeypatch the API
+$ERROR = function $ERROR(message) {
+ throw new Test262Error(message);
+};
+
+assert.throws(Test262Error, () => {
+ assert.throws.early(SyntaxError, "1 = 1;");
+}, "'1=1' is a ReferenceError");
+assert.throws(Test262Error, () => {
+ assert.throws.early(ReferenceError, "var;");
+}, "'var;' is a SyntaxError");
diff --git a/test/harness/assert-throws-early-not-early.js b/test/harness/assert-throws-early-not-early.js
new file mode 100644
index 000000000..b9774492d
--- /dev/null
+++ b/test/harness/assert-throws-early-not-early.js
@@ -0,0 +1,16 @@
+// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: >
+ The assertion fails when the code does not parse with an early error
+---*/
+
+// monkeypatch the API
+$ERROR = function $ERROR(message) {
+ throw new Test262Error(message);
+};
+
+assert.throws(Test262Error, () => {
+ assert.throws.early(ReferenceError, 'x = 1');
+});
diff --git a/test/harness/assert-throws-early-referenceerror.js b/test/harness/assert-throws-early-referenceerror.js
new file mode 100644
index 000000000..fbb667f1c
--- /dev/null
+++ b/test/harness/assert-throws-early-referenceerror.js
@@ -0,0 +1,9 @@
+// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: >
+ The assertion pass when the code parses with an early ReferenceError
+---*/
+
+assert.throws.early(ReferenceError, '1 = 1;');
diff --git a/test/harness/assert-throws-early-syntaxerror.js b/test/harness/assert-throws-early-syntaxerror.js
new file mode 100644
index 000000000..0e047d0f0
--- /dev/null
+++ b/test/harness/assert-throws-early-syntaxerror.js
@@ -0,0 +1,9 @@
+// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: >
+ The assertion pass when the code parses with an early SyntaxError
+---*/
+
+assert.throws.early(SyntaxError, 'let let');