Add syntax tests for declaration restrictions

Assert that declarations are not permitted in positions reserved for
statements only.
This commit is contained in:
Mike Pennisi 2016-03-10 19:35:14 -05:00
parent 007d3b1eb7
commit 021ed85d97
55 changed files with 596 additions and 2 deletions

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-do-while-statement
es6id: 13.7.2
negative: SyntaxError
---*/
do class C {} while (false)

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-do-while-statement
es6id: 13.7.2
negative: SyntaxError
---*/
do const x = null; while (false)

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-do-while-statement
es6id: 13.7.2
negative: SyntaxError
---*/
do function f() {} while (false)

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-do-while-statement
es6id: 13.7.2
negative: SyntaxError
---*/
do function* g() {} while (false)

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-do-while-statement
es6id: 13.7.2
negative: SyntaxError
---*/
do let x; while (false)

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x in {}) class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x in {}) const y = null;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Function declaration not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x in {}) function f() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x in {}) function* g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x in {}) let y;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x of []) class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x of []) const y = null;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Function declaration not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x of []) function f() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x of []) function* g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
negative: SyntaxError
---*/
for (var x of []) let y;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-for-statement
es6id: 13.7.4
negative: SyntaxError
---*/
for ( ; false; ) class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-for-statement
es6id: 13.7.4
negative: SyntaxError
---*/
for ( ; false; ) const x = null;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Function declaration not allowed in statement position
esid: sec-for-statement
es6id: 13.7.4
negative: SyntaxError
---*/
for ( ; false; ) function f() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-for-statement
es6id: 13.7.4
negative: SyntaxError
---*/
for ( ; false; ) function* g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-for-statement
es6id: 13.7.4
negative: SyntaxError
---*/
for ( ; false; ) let x;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) class C {} else class D {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) class C {} else ;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) const x = null; else const y = null;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) const x = null; else ;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) const x = null;

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AnnexB extension not honored in strict mode (IfStatement with a declaration in both statement positions in the global scope)
esid: sec-if-statement
es6id: 13.6
flags: [onlyStrict]
negative: SyntaxError
info: >
The following rules for IfStatement augment those in 13.6:
IfStatement[Yield, Return]:
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
The above rules are only applied when parsing code that is not strict mode code.
---*/
if (true) function f() {} else function _f() {}

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AnnexB extension not honored in strict mode (IfStatement with a declaration in the first statement position in the global scope)
esid: sec-if-statement
es6id: 13.6
flags: [onlyStrict]
negative: SyntaxError
info: >
The following rules for IfStatement augment those in 13.6:
IfStatement[Yield, Return]:
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
The above rules are only applied when parsing code that is not strict mode code.
---*/
if (true) function f() {} else ;

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AnnexB extension not honored in strict mode (IfStatement without an else clause in the global scope)
esid: sec-if-statement
es6id: 13.6
flags: [onlyStrict]
negative: SyntaxError
info: >
The following rules for IfStatement augment those in 13.6:
IfStatement[Yield, Return]:
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
The above rules are only applied when parsing code that is not strict mode code.
---*/
if (true) function f() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) function* g() { } else function* _g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) function* g() { } else ;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) function* g() { }

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) let x; else let y;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) let x; else ;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (true) let x;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (false) ; else class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (false) ; else const x = null;

View File

@ -0,0 +1,25 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: AnnexB extension not honored in strict mode (IfStatement with a declaration in the second statement position in the global scope)
esid: sec-if-statement
es6id: 13.6
flags: [onlyStrict]
negative: SyntaxError
info: >
The following rules for IfStatement augment those in 13.6:
IfStatement[Yield, Return]:
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
B.3.3.2 Changes to GlobalDeclarationInstantiation
1. 1. Let strict be IsStrict of script
2. If strict is *false*, then
[...]
---*/
if (false) ; else function f() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (false) ; else function* g() { }

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-if-statement
es6id: 13.6
negative: SyntaxError
---*/
if (false) ; else let x;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-labelled-statements
es6id: 13.13
negative: SyntaxError
---*/
label: class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-labelled-statements
es6id: 13.13
negative: SyntaxError
---*/
label: const x = null;

View File

@ -1,12 +1,13 @@
// Copyright (C) 2011 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.1
esid: sec-labelled-statements
es6id: 13.13
description: >
function declarations in statement position in strict mode:
label: Statement
flags: [onlyStrict]
negative: SyntaxError
---*/
label: function g() {}
label: function g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-labelled-statements
es6id: 13.13
negative: SyntaxError
---*/
label: function* g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-labelled-statements
es6id: 13.13
negative: SyntaxError
---*/
label: let x;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-while-statement
es6id: 13.7.3
negative: SyntaxError
---*/
while (false) class C {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-while-statement
es6id: 13.7.3
negative: SyntaxError
---*/
while (false) const x = null;

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Function declaration not allowed in statement position
esid: sec-while-statement
es6id: 13.7.3
negative: SyntaxError
---*/
while (false) function f() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-while-statement
es6id: 13.7.3
negative: SyntaxError
---*/
while (false) function* g() {}

View File

@ -0,0 +1,10 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-while-statement
es6id: 13.7.3
negative: SyntaxError
---*/
while (false) let x;

View File

@ -0,0 +1,11 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Class declaration not allowed in statement position
esid: sec-with-statement
es6id: 13.11
flags: [noStrict]
negative: SyntaxError
---*/
with ({}) class C {}

View File

@ -0,0 +1,11 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (const) not allowed in statement position
esid: sec-with-statement
es6id: 13.11
flags: [noStrict]
negative: SyntaxError
---*/
with ({}) const x = null;

View File

@ -0,0 +1,11 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Function declaration not allowed in statement position
esid: sec-with-statement
es6id: 13.11
flags: [noStrict]
negative: SyntaxError
---*/
with ({}) function f() {}

View File

@ -0,0 +1,11 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Generator declaration not allowed in statement position
esid: sec-with-statement
es6id: 13.11
flags: [noStrict]
negative: SyntaxError
---*/
with ({}) function* g() {}

View File

@ -0,0 +1,11 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Lexical declaration (let) not allowed in statement position
esid: sec-with-statement
es6id: 13.11
flags: [noStrict]
negative: SyntaxError
---*/
with ({}) let x;