Merge pull request #715 from bocoup/audit2016-section-13

Improve coverage for section 13, "Statements and Declarations"
This commit is contained in:
Tom Care 2016-07-12 13:51:15 -07:00 committed by GitHub
commit 163fae3e68
35 changed files with 545 additions and 6 deletions

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.
/*---
esid: sec-let-and-const-declarations-runtime-semantics-evaluation
es6id: 13.3.1.4
description: Returns an empty completion
info: |
LexicalDeclaration : LetOrConst BindingList ;
1. Let next be the result of evaluating BindingList.
2. ReturnIfAbrupt(next).
3. Return NormalCompletion(empty).
---*/
assert.sameValue(
eval('const test262id1 = 1;'), undefined, 'Single declaration'
);
assert.sameValue(
eval('const test262id2 = 2, test262id3 = 3;'),
undefined,
'Multiple declarations'
);
assert.sameValue(eval('4; const test262id5 = 5;'), 4);
assert.sameValue(eval('6; let test262id7 = 7, test262id8 = 8;'), 6);

View File

@ -0,0 +1,13 @@
// 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-empty-statement-runtime-semantics-evaluation
es6id: 13.4.1
description: Returns an empty completion
info: |
1. Return NormalCompletion(empty).
---*/
assert.sameValue(eval(';'), undefined);
assert.sameValue(eval('2;;'), 2);
assert.sameValue(eval('3;;;'), 3);

View File

@ -0,0 +1,31 @@
// 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-iteration-statements
es6id: 13.7
description: >
The token sequence `let [`is interpreted as the beginning of a destructuring
binding pattern
info: |
Syntax
IterationStatement[Yield, Return]:
for ( [lookahead { let [ } ] LeftHandSideExpression[?Yield] in
Expression[+In, ?Yield] ) Statement[?Yield, ?Return]
for ( ForDeclaration[?Yield] in Expression[+In, ?Yield] )
Statement[?Yield, ?Return]
---*/
var obj = Object.create(null);
var value;
obj.key = 1;
for ( let[x] in obj ) {
value = x;
}
assert.sameValue(typeof x, 'undefined', 'binding is block-scoped');
assert.sameValue(value, 'k');

View File

@ -1,15 +1,28 @@
// 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.6.4.13
esid: sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset
es6id: 13.7.5.13
description: >
let ForDeclaration: creates a fresh binding per iteration
---*/
let s = '';
for (let x of [1, 2, 3]) {
s += x;
var fns = {};
var obj = Object.create(null);
obj.a = 1;
obj.b = 1;
obj.c = 1;
for (let x in obj) {
// Store function objects as properties of an object so that their return
// value may be verified regardless of the for-in statement's enumeration
// order.
fns[x] = function() { return x; };
}
assert.sameValue(s, '123', "The value of `s` is `'123'`");
assert.sameValue(typeof fns.a, 'function', 'property definition: "a"');
assert.sameValue(fns.a(), 'a');
assert.sameValue(typeof fns.b, 'function', 'property definition: "b"');
assert.sameValue(fns.b(), 'b');
assert.sameValue(typeof fns.c, 'function', 'property definition: "c"');
assert.sameValue(fns.c(), 'c');

View File

@ -0,0 +1,38 @@
// 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-iteration-statements
es6id: 13.7
description: >
The `let` token is interpreted as an Identifier when it is not followed by a
`[` token
info: |
Syntax
IterationStatement[Yield, Return]:
for ( [lookahead { let [ } ] LeftHandSideExpression[?Yield] in
Expression[+In, ?Yield] ) Statement[?Yield, ?Return]
for ( ForDeclaration[?Yield] in Expression[+In, ?Yield] )
Statement[?Yield, ?Return]
flags: [noStrict]
---*/
var obj = Object.create(null);
var let, value;
obj.key = 1;
for ( let in obj ) ;
assert.sameValue(let, 'key', 'IdentifierReference');
Object.defineProperty(Array.prototype, '1', {
set: function(param) {
value = param;
}
});
for ( [let][1] in obj ) ;
assert.sameValue(value, 'key', 'MemberExpression');

View File

@ -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-for-in-and-for-of-statements
es6id: 13.7.5
description: >
The token sequence `let [`is interpreted as the beginning of a destructuring
binding pattern
info: |
Syntax
IterationStatement[Yield, Return]:
for ( [lookahead let]LeftHandSideExpression[?Yield] of
AssignmentExpression[+In, ?Yield] ) Statement[?Yield, ?Return]
for ( ForDeclaration[?Yield] of AssignmentExpression[+In, ?Yield] )
Statement[?Yield, ?Return]
---*/
var value;
for ( let[x] of [[34]] ) {
value = x;
}
assert.sameValue(typeof x, 'undefined', 'binding is block-scoped');
assert.sameValue(value, 34);

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.
/*---
esid: sec-for-in-and-for-of-statements
es6id: 13.7.5
description: >
The `let` token is disallowed when not followed by a `[` token
info: |
Syntax
IterationStatement[Yield, Return]:
for ( [lookahead let]LeftHandSideExpression[?Yield] of
AssignmentExpression[+In, ?Yield] ) Statement[?Yield, ?Return]
for ( ForDeclaration[?Yield] of AssignmentExpression[+In, ?Yield] )
Statement[?Yield, ?Return]
negative: SyntaxError
---*/
for ( let of [] ) ;

View File

@ -0,0 +1,30 @@
// 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-iteration-statements
es6id: 13.7
description: >
The token sequence `let [`is interpreted as the beginning of a destructuring
binding pattern
info: |
Syntax
IterationStatement[Yield, Return]:
for ( [lookahead { let [ } ] Expression[~In, ?Yield]opt ;
Expression[+In, ?Yield]opt ; Expression[+In, ?Yield]opt )
Statement[?Yield, ?Return]
for ( LexicalDeclaration[~In, ?Yield] Expression[+In, ?Yield]opt ;
Expression[+In, ?Yield]opt) Statement[?Yield, ?Return]
---*/
var value;
for ( let[x] = [23]; ; ) {
value = x;
break;
}
assert.sameValue(typeof x, 'undefined', 'binding is block-scoped');
assert.sameValue(value, 23);

View File

@ -0,0 +1,41 @@
// 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-iteration-statements
es6id: 13.7
description: >
The `let` token is interpreted as an Identifier when it is not followed by a
`[` token
info: |
Syntax
IterationStatement[Yield, Return]:
for ( [lookahead { let [ } ] Expression[~In, ?Yield]opt ;
Expression[+In, ?Yield]opt ; Expression[+In, ?Yield]opt )
Statement[?Yield, ?Return]
for ( LexicalDeclaration[~In, ?Yield] Expression[+In, ?Yield]opt ;
Expression[+In, ?Yield]opt) Statement[?Yield, ?Return]
flags: [noStrict]
---*/
var let;
let = 1;
for ( let; ; )
break;
assert.sameValue(let, 1, 'IdentifierReference');
let = 2;
for ( let = 3; ; )
break;
assert.sameValue(let, 3, 'AssignmentExpression');
let = 4;
for ( [let][0]; ; )
break;
assert.sameValue(let, 4, 'MemberExpression');

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.
/*---
esid: sec-if-statement-static-semantics-early-errors
es6id: 13.6.1
description: >
A labelled function declaration is never permitted in the first of two
Statement positions
info: |
IfStatement :
if ( Expression ) Statement else Statement
if ( Expression ) Statement
- It is a Syntax Error if IsLabelledFunction(Statement) is true.
NOTE It is only necessary to apply this rule if the extension specified in
B.3.2 is implemented.
In the absence of Annex B.3.2, a SyntaxError should be produced due to the
labelled function declaration itself.
negative: SyntaxError
---*/
if (false) label1: label2: function test262() {} else ;

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.
/*---
esid: sec-if-statement-static-semantics-early-errors
es6id: 13.6.1
description: >
A labelled function declaration is never permitted in the sole Statement
position
info: |
IfStatement :
if ( Expression ) Statement else Statement
if ( Expression ) Statement
- It is a Syntax Error if IsLabelledFunction(Statement) is true.
NOTE It is only necessary to apply this rule if the extension specified in
B.3.2 is implemented.
In the absence of Annex B.3.2, a SyntaxError should be produced due to the
labelled function declaration itself.
negative: SyntaxError
---*/
if (false) label1: label2: function test262() {}

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.
/*---
esid: sec-if-statement-static-semantics-early-errors
es6id: 13.6.1
description: >
A labelled function declaration is never permitted in the second of two
Statement positions
info: |
IfStatement :
if ( Expression ) Statement else Statement
if ( Expression ) Statement
- It is a Syntax Error if IsLabelledFunction(Statement) is true.
NOTE It is only necessary to apply this rule if the extension specified in
B.3.2 is implemented.
In the absence of Annex B.3.2, a SyntaxError should be produced due to the
labelled function declaration itself.
negative: SyntaxError
---*/
if (true) ; else label1: label2: function test262() {}

View File

@ -0,0 +1,23 @@
// 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-labelled-statements-static-semantics-containsundefinedcontinuetarget
es6id: 13.13.4
description: Does not modify `iterationSet`
info: |
With arguments iterationSet and labelSet.
LabelledStatement : LabelIdentifier : LabelledItem
1. Let label be the StringValue of LabelIdentifier.
2. Let newLabelSet be a copy of labelSet with label appended.
3. Return ContainsUndefinedContinueTarget of LabelledItem with arguments
iterationSet and newLabelSet. negative: SyntaxError
negative: SyntaxError
---*/
do {
test262: {
continue test262;
}
} while (false)

View 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-labelled-statements-runtime-semantics-labelledevaluation
es6id: 13.13.14
description: Completion value when LabelledItem returns a "break" completion
info: |
LabelledStatement : LabelIdentifier : LabelledItem
1. Let label be the StringValue of LabelIdentifier.
2. Append label as an element of labelSet.
3. Let stmtResult be LabelledEvaluation of LabelledItem with argument
labelSet.
4. If stmtResult.[[Type]] is break and SameValue(stmtResult.[[Target]],
label) is true, then
a. Let stmtResult be NormalCompletion(stmtResult.[[Value]]).
---*/
assert.sameValue(eval('test262id: { 5; break test262id; 9; }'), 5);

View File

@ -0,0 +1,20 @@
// 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-labelled-statements-runtime-semantics-labelledevaluation
es6id: 13.13.14
description: Completion value when LabelledItem returns normally
info: |
LabelledStatement : LabelIdentifier : LabelledItem
1. Let label be the StringValue of LabelIdentifier.
2. Append label as an element of labelSet.
3. Let stmtResult be LabelledEvaluation of LabelledItem with argument
labelSet.
4. If stmtResult.[[Type]] is break and SameValue(stmtResult.[[Target]],
label) is true, then
[...]
5. Return Completion(stmtResult).
---*/
assert.sameValue(eval('test262id: 2;'), 2);

View File

@ -0,0 +1,37 @@
// 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-let-and-const-declarations-runtime-semantics-evaluation
es6id: 13.3.1.4
description: Returns an empty completion
info: |
LexicalDeclaration : LetOrConst BindingList ;
1. Let next be the result of evaluating BindingList.
2. ReturnIfAbrupt(next).
3. Return NormalCompletion(empty).
---*/
assert.sameValue(
eval('let test262id1;'), undefined, 'Single declaration without initializer'
);
assert.sameValue(
eval('let test262id2 = 2;'),
undefined,
'Single declaration bearing initializer'
);
assert.sameValue(
eval('let test262id3 = 3, test262id4;'),
undefined,
'Multiple declarations, final without initializer'
);
assert.sameValue(
eval('let test262id5, test262id6 = 6;'),
undefined,
'Multiple declarations, final bearing initializer'
);
assert.sameValue(eval('7; let test262id8;'), 7);
assert.sameValue(eval('9; let test262id10 = 10;'), 9);
assert.sameValue(eval('11; let test262id12 = 12, test262id13;'), 11);
assert.sameValue(eval('14; let test262id15, test262id16 = 16;'), 14);

View File

@ -0,0 +1,20 @@
// 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-switch-statement-static-semantics-early-errors
es6id: 13.12.1
description: Syntax error from duplicate lexical variables
info: >
It is a Syntax Error if the LexicallyDeclaredNames of CaseBlock contains any
duplicate entries.
negative: SyntaxError
features: [let, const]
---*/
switch (0) {
case 1:
let test262id;
break;
default:
const test262id = null;
}

View File

@ -0,0 +1,22 @@
// 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-switch-statement-static-semantics-early-errors
es6id: 13.12.1
description: >
Syntax error from collisions between lexical variables and var-declarared
variables
info: >
It is a Syntax Error if any element of the LexicallyDeclaredNames of
CaseClauses also occurs in the VarDeclaredNames of CaseClauses.
negative: SyntaxError
features: [let]
---*/
switch (0) {
case 1:
var test262id;
break;
default:
let test262id;
}

View File

@ -0,0 +1,24 @@
// 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-variable-statement-runtime-semantics-evaluation
es6id: 13.3.2.4
description: Binding is resolve prior to evaluation of Initializer
info: |
VariableDeclaration : BindingIdentifier Initializer
1. Let bindingId be StringValue of BindingIdentifier.
2. Let lhs be ? ResolveBinding(bindingId).
3. Let rhs be the result of evaluating Initializer.
[...]
flags: [noStrict]
---*/
var obj = { test262id: 1 };
with (obj) {
var test262id = delete obj.test262id;
}
assert.sameValue(obj.test262id, true);
assert.sameValue(test262id, undefined);

View File

@ -0,0 +1,37 @@
// 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-variable-statement-runtime-semantics-evaluation
es6id: 13.3.2.4
description: Returns an empty completion
info: |
VariableStatement : var VariableDeclarationList ;
1. Let next be the result of evaluating VariableDeclarationList.
2. ReturnIfAbrupt(next).
3. Return NormalCompletion(empty).
---*/
assert.sameValue(
eval('var test262id1;'), undefined, 'Single declaration without initializer'
);
assert.sameValue(
eval('var test262id2 = 2;'),
undefined,
'Single declaration bearing initializer'
);
assert.sameValue(
eval('var test262id3 = 3, test262id4;'),
undefined,
'Multiple declarations, final without initializer'
);
assert.sameValue(
eval('var test262id5, test262id6 = 6;'),
undefined,
'Multiple declarations, final bearing initializer'
);
assert.sameValue(eval('7; var test262id8;'), 7);
assert.sameValue(eval('9; var test262id10 = 10;'), 9);
assert.sameValue(eval('11; var test262id12 = 12, test262id13;'), 11);
assert.sameValue(eval('14; var test262id15, test262id16 = 16;'), 14);

View File

@ -0,0 +1,22 @@
// 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-with-statement-static-semantics-early-errors
es6id: 13.11.1
description:
A labelled function declaration is never permitted in the Statement position
info: |
WithStatementa: with ( Expression ) Statement
[...]
- It is a Syntax Error if IsLabelledFunction(Statement) is true.
NOTE It is only necessary to apply the second rule if the extension specified
in B.3.2 is implemented.
In the absence of Annex B.3.2, a SyntaxError should be produced due to the
labelled function declaration itself.
negative: SyntaxError
---*/
with ({}) label1: label2: function test262() {}