Merge pull request #1002 from leobalter/async-async

Add early error cases for `async async` in property definitions
This commit is contained in:
Leo Balter 2017-05-01 12:34:00 -04:00 committed by GitHub
commit d23063c7aa
7 changed files with 96 additions and 1 deletions

View File

@ -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

View File

@ -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}`);
};

View File

@ -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");

View File

@ -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');
});

View File

@ -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;');

View File

@ -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');

View File

@ -0,0 +1,33 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
async is not a valid prefix of an identifier reference
esid: sec-object-initializer
info: |
PropertyDefinition:
IdentifierReference
CoverInitializedName
PropertyName : AssignmentExpression
MethodDefinition
MethodDefinition:
PropertyName ( UniqueFormalParameters ) { FunctionBody }
AsyncMethod
AsyncMethod:
async [no LineTerminator here] PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody }
VariableDeclaration : BindingPattern Initializer
1. Let rhs be the result of evaluating Initializer.
2. Let rval be GetValue(rhs).
3. ReturnIfAbrupt(rval).
4. Return the result of performing BindingInitialization for
BindingPattern passing rval and undefined as arguments.
negative:
phase: early
type: SyntaxError
---*/
({async async});