mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 13:34:38 +02:00
Add tests for TryStatement binding restrictions (#577)
This changeset includes tests for early errors and those generated dynamically by eval. It also accounts for relevant AnnexB extensions.
This commit is contained in:
parent
88f390d189
commit
38329a7038
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-variablestatements-in-catch-blocks
|
||||||
|
es6id: B3.5
|
||||||
|
description: Re-declaration of catch parameter
|
||||||
|
info: >
|
||||||
|
[...]
|
||||||
|
|
||||||
|
This modified behaviour also applies to var and function declarations
|
||||||
|
introduced by direct evals contained within the Block of a Catch clause.
|
||||||
|
This change is accomplished by modify the algorithm of 18.2.1.2 as follows:
|
||||||
|
|
||||||
|
Step 5.d.ii.2.a.i is replaced by:
|
||||||
|
|
||||||
|
i. If thisEnvRec is not the Environment Record for a Catch clause, throw a
|
||||||
|
SyntaxError exception.
|
||||||
|
ii. If name is bound by any syntactic form other than a
|
||||||
|
FunctionDeclaration, a VariableStatement, the VariableDeclarationList
|
||||||
|
of a for statement, or the ForBinding of a for-in statement, throw a
|
||||||
|
SyntaxError exception.
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw null;
|
||||||
|
} catch (err) {
|
||||||
|
eval('function err() {}');
|
||||||
|
eval('var err;');
|
||||||
|
eval('for (var err; false; ) {}');
|
||||||
|
eval('for (var err in []) {}');
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-variablestatements-in-catch-blocks
|
||||||
|
es6id: B3.5
|
||||||
|
description: Re-declaration of catch parameter (for-in statement)
|
||||||
|
info: >
|
||||||
|
It is a Syntax Error if any element of the BoundNames of CatchParameter
|
||||||
|
also occurs in the VarDeclaredNames of Block, unless that element is only
|
||||||
|
bound by a VariableStatement or the VariableDeclarationList of a for
|
||||||
|
statement, or the ForBinding of a for-in statement.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var before, during, after;
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw 'exception';
|
||||||
|
} catch (err) {
|
||||||
|
before = err;
|
||||||
|
for (var err in { propertyName: null }) {
|
||||||
|
during = err;
|
||||||
|
}
|
||||||
|
after = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(before, 'exception');
|
||||||
|
assert.sameValue(during, 'propertyName', 'during loop body evaluation');
|
||||||
|
assert.sameValue(after, 'propertyName', 'after loop body evaluation');
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-variablestatements-in-catch-blocks
|
||||||
|
es6id: B3.5
|
||||||
|
description: Re-declaration of catch parameter (for-in statement)
|
||||||
|
info: >
|
||||||
|
It is a Syntax Error if any element of the BoundNames of CatchParameter
|
||||||
|
also occurs in the VarDeclaredNames of Block, unless that element is only
|
||||||
|
bound by a VariableStatement or the VariableDeclarationList of a for
|
||||||
|
statement, or the ForBinding of a for-in statement.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var before, during, after;
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw 'exception';
|
||||||
|
} catch (err) {
|
||||||
|
before = err;
|
||||||
|
for (var err = 'loop initializer'; err !== 'increment'; err = 'increment') {
|
||||||
|
during = err;
|
||||||
|
}
|
||||||
|
after = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.sameValue(before, 'exception');
|
||||||
|
assert.sameValue(during, 'loop initializer');
|
||||||
|
assert.sameValue(after, 'increment');
|
@ -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.
|
||||||
|
/*---
|
||||||
|
esid: sec-evaldeclarationinstantiation
|
||||||
|
es6id: 18.2.1.2
|
||||||
|
description: Variable collision with lexical binding in lower scope
|
||||||
|
info: >
|
||||||
|
Annex B extensions permit re-declarations from FunctionDeclaration,
|
||||||
|
VariableStatement, the VariableDeclarationList of a for statement, and the
|
||||||
|
ForBinding of a for-in statement. Bindings from the ForBinding of a for-of
|
||||||
|
statement are restricted regardless of the application of Annex B.
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
try {
|
||||||
|
throw null;
|
||||||
|
} catch (err) {
|
||||||
|
eval('for (var err of []) {}');
|
||||||
|
}
|
||||||
|
});
|
14
test/language/statements/try/early-catch-duplicates.js
Normal file
14
test/language/statements/try/early-catch-duplicates.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-try-statement-static-semantics-early-errors
|
||||||
|
es6id: 13.15.1
|
||||||
|
description: >
|
||||||
|
It is a Syntax Error if BoundNames of CatchParameter contains any duplicate
|
||||||
|
elements.
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
|
||||||
|
$ERROR('This code should not be executed.');
|
||||||
|
|
||||||
|
try { } catch ([x, x]) {}
|
15
test/language/statements/try/early-catch-lex.js
Normal file
15
test/language/statements/try/early-catch-lex.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-try-statement-static-semantics-early-errors
|
||||||
|
es6id: 13.15.1
|
||||||
|
description: >
|
||||||
|
It is a Syntax Error if any element of the BoundNames of CatchParameter
|
||||||
|
also occurs in the LexicallyDeclaredNames of Block.
|
||||||
|
negative: SyntaxError
|
||||||
|
features: [let]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
$ERROR('This code should not be executed.');
|
||||||
|
|
||||||
|
try { } catch (x) { let x; }
|
19
test/language/statements/try/early-catch-var.js
Normal file
19
test/language/statements/try/early-catch-var.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-try-statement-static-semantics-early-errors
|
||||||
|
es6id: 13.15.1
|
||||||
|
description: >
|
||||||
|
It is a Syntax Error if any element of the BoundNames of CatchParameter
|
||||||
|
also occurs in the VarDeclaredNames of Block.
|
||||||
|
info: >
|
||||||
|
Annex B extensions permit re-declarations from VariableStatement, the
|
||||||
|
VariableDeclarationList of a for statement, and the ForBinding of a for-of
|
||||||
|
statement. Bindings from the ForBinding of a for-in statement are
|
||||||
|
restricted regardless of the application of Annex B.
|
||||||
|
negative: SyntaxError
|
||||||
|
---*/
|
||||||
|
|
||||||
|
$ERROR('This code should not be executed.');
|
||||||
|
|
||||||
|
try { } catch (x) { for (var x of []) {} }
|
Loading…
x
Reference in New Issue
Block a user