From 407b8964ce559671a004d2693ca45b67fefe59ea Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Thu, 7 Jan 2016 12:15:24 -0500 Subject: [PATCH] Add tests for ES2015 completion reform In order to facilitate proper tail calls, ES2015 modified the completion value of a number of statements. These tests use `eval` to verify the new values. --- .../statements/do-while/cptn-abrupt-empty.js | 21 +++++ .../statements/do-while/cptn-normal.js | 23 ++++++ .../for-in/cptn-decl-abrupt-empty.js | 41 ++++++++++ .../statements/for-in/cptn-decl-itr.js | 31 +++++++ .../statements/for-in/cptn-decl-skip-itr.js | 25 ++++++ .../statements/for-in/cptn-decl-zero-itr.js | 27 ++++++ .../for-in/cptn-expr-abrupt-empty.js | 41 ++++++++++ .../statements/for-in/cptn-expr-itr.js | 31 +++++++ .../statements/for-in/cptn-expr-skip-itr.js | 25 ++++++ .../statements/for-in/cptn-expr-zero-itr.js | 27 ++++++ .../for-of/cptn-decl-abrupt-empty.js | 42 ++++++++++ .../statements/for-of/cptn-decl-itr.js | 32 ++++++++ .../statements/for-of/cptn-decl-no-itr.js | 29 +++++++ .../for-of/cptn-expr-abrupt-empty.js | 43 ++++++++++ .../statements/for-of/cptn-expr-itr.js | 33 ++++++++ .../statements/for-of/cptn-expr-no-itr.js | 30 +++++++ .../statements/for/cptn-decl-abrupt-empty.js | 45 ++++++++++ .../statements/for/cptn-decl-expr-iter.js | 32 ++++++++ .../statements/for/cptn-decl-expr-no-iter.js | 28 +++++++ .../statements/for/cptn-expr-abrupt-empty.js | 59 +++++++++++++ .../statements/for/cptn-expr-expr-iter.js | 35 ++++++++ .../statements/for/cptn-expr-expr-no-iter.js | 30 +++++++ .../if/cptn-else-false-abrupt-empty.js | 46 +++++++++++ .../statements/if/cptn-else-false-nrml.js | 23 ++++++ .../if/cptn-else-true-abrupt-empty.js | 42 ++++++++++ .../statements/if/cptn-else-true-nrml.js | 23 ++++++ .../statements/if/cptn-no-else-false.js | 15 ++++ .../if/cptn-no-else-true-abrupt-empty.js | 31 +++++++ .../statements/if/cptn-no-else-true-nrml.js | 22 +++++ .../statements/switch/cptn-a-abrupt-empty.js | 56 +++++++++++++ .../switch/cptn-a-fall-thru-abrupt-empty.js | 65 +++++++++++++++ .../switch/cptn-a-fall-thru-nrml.js | 66 +++++++++++++++ .../statements/switch/cptn-abrupt-empty.js | 24 ++++++ .../statements/switch/cptn-b-abrupt-empty.js | 64 +++++++++++++++ .../switch/cptn-b-fall-thru-abrupt-empty.js | 80 ++++++++++++++++++ .../switch/cptn-b-fall-thru-nrml.js | 65 +++++++++++++++ .../statements/switch/cptn-b-final.js | 78 ++++++++++++++++++ .../switch/cptn-dflt-abrupt-empty.js | 49 +++++++++++ .../switch/cptn-dflt-b-abrupt-empty.js | 66 +++++++++++++++ .../cptn-dflt-b-fall-thru-abrupt-empty.js | 82 +++++++++++++++++++ .../switch/cptn-dflt-b-fall-thru-nrml.js | 67 +++++++++++++++ .../statements/switch/cptn-dflt-b-final.js | 80 ++++++++++++++++++ .../cptn-dflt-fall-thru-abrupt-empty.js | 69 ++++++++++++++++ .../switch/cptn-dflt-fall-thru-nrml.js | 57 +++++++++++++ .../statements/switch/cptn-dflt-final.js | 68 +++++++++++++++ .../switch/cptn-no-dflt-match-abrupt-empty.js | 53 ++++++++++++ ...tn-no-dflt-match-fall-thru-abrupt-empty.js | 65 +++++++++++++++ .../cptn-no-dflt-match-fall-thru-nrml.js | 49 +++++++++++ .../switch/cptn-no-dflt-match-final.js | 70 ++++++++++++++++ .../switch/cptn-no-dflt-no-match.js | 42 ++++++++++ test/language/statements/try/cptn-catch.js | 30 +++++++ .../statements/try/cptn-finally-from-catch.js | 43 ++++++++++ .../statements/try/cptn-finally-skip-catch.js | 30 +++++++ .../statements/try/cptn-finally-wo-catch.js | 22 +++++ test/language/statements/try/cptn-try.js | 23 ++++++ .../statements/while/cptn-abrupt-empty.js | 30 +++++++ test/language/statements/while/cptn-iter.js | 23 ++++++ .../language/statements/while/cptn-no-iter.js | 19 +++++ .../statements/with/cptn-abrupt-empty.js | 30 +++++++ test/language/statements/with/cptn-nrml.js | 19 +++++ 60 files changed, 2516 insertions(+) create mode 100644 test/language/statements/do-while/cptn-abrupt-empty.js create mode 100644 test/language/statements/do-while/cptn-normal.js create mode 100644 test/language/statements/for-in/cptn-decl-abrupt-empty.js create mode 100644 test/language/statements/for-in/cptn-decl-itr.js create mode 100644 test/language/statements/for-in/cptn-decl-skip-itr.js create mode 100644 test/language/statements/for-in/cptn-decl-zero-itr.js create mode 100644 test/language/statements/for-in/cptn-expr-abrupt-empty.js create mode 100644 test/language/statements/for-in/cptn-expr-itr.js create mode 100644 test/language/statements/for-in/cptn-expr-skip-itr.js create mode 100644 test/language/statements/for-in/cptn-expr-zero-itr.js create mode 100644 test/language/statements/for-of/cptn-decl-abrupt-empty.js create mode 100644 test/language/statements/for-of/cptn-decl-itr.js create mode 100644 test/language/statements/for-of/cptn-decl-no-itr.js create mode 100644 test/language/statements/for-of/cptn-expr-abrupt-empty.js create mode 100644 test/language/statements/for-of/cptn-expr-itr.js create mode 100644 test/language/statements/for-of/cptn-expr-no-itr.js create mode 100644 test/language/statements/for/cptn-decl-abrupt-empty.js create mode 100644 test/language/statements/for/cptn-decl-expr-iter.js create mode 100644 test/language/statements/for/cptn-decl-expr-no-iter.js create mode 100644 test/language/statements/for/cptn-expr-abrupt-empty.js create mode 100644 test/language/statements/for/cptn-expr-expr-iter.js create mode 100644 test/language/statements/for/cptn-expr-expr-no-iter.js create mode 100644 test/language/statements/if/cptn-else-false-abrupt-empty.js create mode 100644 test/language/statements/if/cptn-else-false-nrml.js create mode 100644 test/language/statements/if/cptn-else-true-abrupt-empty.js create mode 100644 test/language/statements/if/cptn-else-true-nrml.js create mode 100644 test/language/statements/if/cptn-no-else-false.js create mode 100644 test/language/statements/if/cptn-no-else-true-abrupt-empty.js create mode 100644 test/language/statements/if/cptn-no-else-true-nrml.js create mode 100644 test/language/statements/switch/cptn-a-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-a-fall-thru-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-a-fall-thru-nrml.js create mode 100644 test/language/statements/switch/cptn-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-b-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-b-fall-thru-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-b-fall-thru-nrml.js create mode 100644 test/language/statements/switch/cptn-b-final.js create mode 100644 test/language/statements/switch/cptn-dflt-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-dflt-b-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-dflt-b-fall-thru-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-dflt-b-fall-thru-nrml.js create mode 100644 test/language/statements/switch/cptn-dflt-b-final.js create mode 100644 test/language/statements/switch/cptn-dflt-fall-thru-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-dflt-fall-thru-nrml.js create mode 100644 test/language/statements/switch/cptn-dflt-final.js create mode 100644 test/language/statements/switch/cptn-no-dflt-match-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-no-dflt-match-fall-thru-abrupt-empty.js create mode 100644 test/language/statements/switch/cptn-no-dflt-match-fall-thru-nrml.js create mode 100644 test/language/statements/switch/cptn-no-dflt-match-final.js create mode 100644 test/language/statements/switch/cptn-no-dflt-no-match.js create mode 100644 test/language/statements/try/cptn-catch.js create mode 100644 test/language/statements/try/cptn-finally-from-catch.js create mode 100644 test/language/statements/try/cptn-finally-skip-catch.js create mode 100644 test/language/statements/try/cptn-finally-wo-catch.js create mode 100644 test/language/statements/try/cptn-try.js create mode 100644 test/language/statements/while/cptn-abrupt-empty.js create mode 100644 test/language/statements/while/cptn-iter.js create mode 100644 test/language/statements/while/cptn-no-iter.js create mode 100644 test/language/statements/with/cptn-abrupt-empty.js create mode 100644 test/language/statements/with/cptn-nrml.js diff --git a/test/language/statements/do-while/cptn-abrupt-empty.js b/test/language/statements/do-while/cptn-abrupt-empty.js new file mode 100644 index 0000000000..329f85b584 --- /dev/null +++ b/test/language/statements/do-while/cptn-abrupt-empty.js @@ -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. +/*--- +es6id: 13.7.2.6 +description: > + Completion value when iteration completes due to an empty abrupt completion +info: > + IterationStatement : do Statement while ( Expression ) ; + + 1. Let V = undefined. + 2. Repeat + a. Let stmt be the result of evaluating Statement. + b. If LoopContinues(stmt, labelSet) is false, return + Completion(UpdateEmpty(stmt, V)). +---*/ + +assert.sameValue(eval('1; do { break; } while (false)'), undefined); +assert.sameValue(eval('2; do { 3; break; } while (false)'), 3); + +assert.sameValue(eval('4; do { continue; } while (false)'), undefined); +assert.sameValue(eval('5; do { 6; continue; } while (false)'), 6); diff --git a/test/language/statements/do-while/cptn-normal.js b/test/language/statements/do-while/cptn-normal.js new file mode 100644 index 0000000000..317d3e7a36 --- /dev/null +++ b/test/language/statements/do-while/cptn-normal.js @@ -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. +/*--- +es6id: 13.7.2.6 +description: > + Completion value when iteration completes due to expression value +info: > + IterationStatement : do Statement while ( Expression ) ; + + 1. Let V = undefined. + 2. Repeat + a. Let stmt be the result of evaluating Statement. + b. If LoopContinues(stmt, labelSet) is false, return + Completion(UpdateEmpty(stmt, V)). + c. If stmt.[[value]] is not empty, let V = stmt.[[value]]. + d. Let exprRef be the result of evaluating Expression. + e. Let exprValue be GetValue(exprRef). + f. ReturnIfAbrupt(exprValue). + g. If ToBoolean(exprValue) is false, return NormalCompletion(V). +---*/ + +assert.sameValue(eval('1; do { } while (false)'), undefined); +assert.sameValue(eval('2; do { 3; } while (false)'), 3); diff --git a/test/language/statements/for-in/cptn-decl-abrupt-empty.js b/test/language/statements/for-in/cptn-decl-abrupt-empty.js new file mode 100644 index 0000000000..093911205c --- /dev/null +++ b/test/language/statements/for-in/cptn-decl-abrupt-empty.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and iteration is cancelled +info: > + IterationStatement : for ( var ForBinding in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + m. If LoopContinues(result, labelSet) is false, return + IteratorClose(iterator, UpdateEmpty(result, V)). +---*/ + +assert.sameValue(eval('1; for (var a in { x: 0 }) { break; }'), undefined); +assert.sameValue(eval('2; for (var b in { x: 0 }) { 3; break; }'), 3); + +assert.sameValue( + eval('4; outer: do { for (var a in { x: 0 }) { continue outer; } } while (false)'), + undefined +); +assert.sameValue( + eval('5; outer: do { for (var b in { x: 0 }) { 6; continue outer; } } while (false)'), + 6 +); diff --git a/test/language/statements/for-in/cptn-decl-itr.js b/test/language/statements/for-in/cptn-decl-itr.js new file mode 100644 index 0000000000..f2feb563a4 --- /dev/null +++ b/test/language/statements/for-in/cptn-decl-itr.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and iteration occurs +info: > + IterationStatement : for ( var ForBinding in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + n. If result.[[value]] is not empty, let V be result.[[value]]. +---*/ + +assert.sameValue(eval('1; for (var a in { x: 0 }) { }'), undefined); +assert.sameValue(eval('2; for (var b in { x: 0 }) { 3; }'), 3); diff --git a/test/language/statements/for-in/cptn-decl-skip-itr.js b/test/language/statements/for-in/cptn-decl-skip-itr.js new file mode 100644 index 0000000000..7bfc01e71d --- /dev/null +++ b/test/language/statements/for-in/cptn-decl-skip-itr.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and iteration is skipped +info: > + IterationStatement : for ( var ForBinding in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + + 13.7.5.12 Runtime Semantics: ForIn/OfHeadEvaluation + + [...] + 7. If iterationKind is enumerate, then + a. If exprValue.[[value]] is null or undefined, then + i. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: + empty}. +---*/ + +assert.sameValue(eval('1; for (var a in undefined) { }'), undefined); +assert.sameValue(eval('2; for (var b in undefined) { 3; }'), undefined); +assert.sameValue(eval('4; for (var c in null) { }'), undefined); +assert.sameValue(eval('5; for (var d in null) { 6; }'), undefined); diff --git a/test/language/statements/for-in/cptn-decl-zero-itr.js b/test/language/statements/for-in/cptn-decl-zero-itr.js new file mode 100644 index 0000000000..bed1bf9f3e --- /dev/null +++ b/test/language/statements/for-in/cptn-decl-zero-itr.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and no iteration occurs +info: > + IterationStatement : for ( var ForBinding in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). +---*/ + +assert.sameValue(eval('1; for (var a in {}) { }'), undefined); +assert.sameValue(eval('2; for (var b in {}) { 3; }'), undefined); diff --git a/test/language/statements/for-in/cptn-expr-abrupt-empty.js b/test/language/statements/for-in/cptn-expr-abrupt-empty.js new file mode 100644 index 0000000000..7e9846ce66 --- /dev/null +++ b/test/language/statements/for-in/cptn-expr-abrupt-empty.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and iteration is cancelled +info: > + IterationStatement : for ( LeftHandSideExpression in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + m. If LoopContinues(result, labelSet) is false, return + IteratorClose(iterator, UpdateEmpty(result, V)). +---*/ + +assert.sameValue(eval('var a; 1; for (a in { x: 0 }) { break; }'), undefined); +assert.sameValue(eval('var b; 2; for (b in { x: 0 }) { 3; break; }'), 3); + +assert.sameValue( + eval('var a; 4; outer: do { for (a in { x: 0 }) { continue outer; } } while (false)'), + undefined +); +assert.sameValue( + eval('var b; 5; outer: do { for (b in { x: 0 }) { 6; continue outer; } } while (false)'), + 6 +); diff --git a/test/language/statements/for-in/cptn-expr-itr.js b/test/language/statements/for-in/cptn-expr-itr.js new file mode 100644 index 0000000000..4955da0b2f --- /dev/null +++ b/test/language/statements/for-in/cptn-expr-itr.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and iteration occurs +info: > + IterationStatement : for ( LeftHandSideExpression in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + n. If result.[[value]] is not empty, let V be result.[[value]]. +---*/ + +assert.sameValue(eval('var a; 1; for (a in { x: 0 }) { }'), undefined); +assert.sameValue(eval('var b; 2; for (b in { x: 0 }) { 3; }'), 3); diff --git a/test/language/statements/for-in/cptn-expr-skip-itr.js b/test/language/statements/for-in/cptn-expr-skip-itr.js new file mode 100644 index 0000000000..e6b6a85e9a --- /dev/null +++ b/test/language/statements/for-in/cptn-expr-skip-itr.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and iteration is skipped +info: > + IterationStatement : for ( LeftHandSideExpression in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + + 13.7.5.12 Runtime Semantics: ForIn/OfHeadEvaluation + + [...] + 7. If iterationKind is enumerate, then + a. If exprValue.[[value]] is null or undefined, then + i. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: + empty}. +---*/ + +assert.sameValue(eval('var a; 1; for (a in undefined) { }'), undefined); +assert.sameValue(eval('var b; 2; for (b in undefined) { 3; }'), undefined); +assert.sameValue(eval('var c; 4; for (c in null) { }'), undefined); +assert.sameValue(eval('var d; 5; for (d in null) { 6; }'), undefined); diff --git a/test/language/statements/for-in/cptn-expr-zero-itr.js b/test/language/statements/for-in/cptn-expr-zero-itr.js new file mode 100644 index 0000000000..983fca27e1 --- /dev/null +++ b/test/language/statements/for-in/cptn-expr-zero-itr.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and no iteration occurs +info: > + IterationStatement : for ( LeftHandSideExpression in Expression ) Statement + + 1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). +---*/ + +assert.sameValue(eval('var a; 1; for (a in {}) { }'), undefined); +assert.sameValue(eval('var b; 2; for (b in {}) { 3; }'), undefined); diff --git a/test/language/statements/for-of/cptn-decl-abrupt-empty.js b/test/language/statements/for-of/cptn-decl-abrupt-empty.js new file mode 100644 index 0000000000..e81a40d3c7 --- /dev/null +++ b/test/language/statements/for-of/cptn-decl-abrupt-empty.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and iteration is cancelled +info: > + IterationStatement : for ( var ForBinding of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », + AssignmentExpression, iterate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + m. If LoopContinues(result, labelSet) is false, return + IteratorClose(iterator, UpdateEmpty(result, V)). +---*/ + +assert.sameValue(eval('1; for (var a of [0]) { break; }'), undefined); +assert.sameValue(eval('2; for (var b of [0]) { 3; break; }'), 3); + +assert.sameValue( + eval('4; outer: do { for (var a of [0]) { continue outer; } } while (false)'), + undefined +); +assert.sameValue( + eval('5; outer: do { for (var b of [0]) { 6; continue outer; } } while (false)'), + 6 +); diff --git a/test/language/statements/for-of/cptn-decl-itr.js b/test/language/statements/for-of/cptn-decl-itr.js new file mode 100644 index 0000000000..a68bc2d157 --- /dev/null +++ b/test/language/statements/for-of/cptn-decl-itr.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and iteration occurs +info: > + IterationStatement : for ( var ForBinding of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », + AssignmentExpression, iterate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + n. If result.[[value]] is not empty, let V be result.[[value]]. +---*/ + +assert.sameValue(eval('1; for (var a of [0]) { }'), undefined); +assert.sameValue(eval('2; for (var b of [0]) { 3; }'), 3); diff --git a/test/language/statements/for-of/cptn-decl-no-itr.js b/test/language/statements/for-of/cptn-decl-no-itr.js new file mode 100644 index 0000000000..da1ddd13c2 --- /dev/null +++ b/test/language/statements/for-of/cptn-decl-no-itr.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has a declaration and no iteration occurs +info: > + IterationStatement : for ( var ForBinding of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », + AssignmentExpression, iterate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, + varBinding, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). +---*/ + + +assert.sameValue(eval('1; for (var a of []) { }'), undefined); +assert.sameValue(eval('2; for (var b of []) { 3; }'), undefined); diff --git a/test/language/statements/for-of/cptn-expr-abrupt-empty.js b/test/language/statements/for-of/cptn-expr-abrupt-empty.js new file mode 100644 index 0000000000..85d276f949 --- /dev/null +++ b/test/language/statements/for-of/cptn-expr-abrupt-empty.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and iteration is cancelled +info: > + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », + AssignmentExpression, iterate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + m. If LoopContinues(result, labelSet) is false, return + IteratorClose(iterator, UpdateEmpty(result, V)). +---*/ + +assert.sameValue(eval('var a; 1; for (a of [0]) { break; }'), undefined); +assert.sameValue(eval('var b; 2; for (b of [0]) { 3; break; }'), 3); + +assert.sameValue( + eval('var a; 4; outer: do { for (a of [0]) { continue outer; } } while (false)'), + undefined +); +assert.sameValue( + eval('var b; 5; outer: do { for (b of [0]) { 6; continue outer; } } while (false)'), + 6 +); diff --git a/test/language/statements/for-of/cptn-expr-itr.js b/test/language/statements/for-of/cptn-expr-itr.js new file mode 100644 index 0000000000..0af69cef1d --- /dev/null +++ b/test/language/statements/for-of/cptn-expr-itr.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and iteration occurs +info: > + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », + AssignmentExpression, iterate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). + [...] + k. Let result be the result of evaluating stmt. + [...] + n. If result.[[value]] is not empty, let V be result.[[value]]. +---*/ + +assert.sameValue(eval('var a; 1; for (a of [0]) { }'), undefined); +assert.sameValue(eval('var b; 2; for (b of [0]) { 3; }'), 3); diff --git a/test/language/statements/for-of/cptn-expr-no-itr.js b/test/language/statements/for-of/cptn-expr-no-itr.js new file mode 100644 index 0000000000..dcd3e013f7 --- /dev/null +++ b/test/language/statements/for-of/cptn-expr-no-itr.js @@ -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. +/*--- +es6id: 13.7.5.11 +description: > + Completion value when head has no declaration and no iteration occurs +info: > + IterationStatement : + for ( LeftHandSideExpression of AssignmentExpression ) Statement + + 1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », + AssignmentExpression, iterate). + 2. ReturnIfAbrupt(keyResult). + 3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, + keyResult, assignment, labelSet). + + 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation + + [...] + 2. Let V = undefined. + [...] + 5. Repeat + a. Let nextResult be IteratorStep(iterator). + b. ReturnIfAbrupt(nextResult). + c. If nextResult is false, return NormalCompletion(V). +---*/ + + +assert.sameValue(eval('var a; 1; for (a of []) { }'), undefined); +assert.sameValue(eval('var b; 2; for (b of []) { 3; }'), undefined); diff --git a/test/language/statements/for/cptn-decl-abrupt-empty.js b/test/language/statements/for/cptn-decl-abrupt-empty.js new file mode 100644 index 0000000000..e3830d5681 --- /dev/null +++ b/test/language/statements/for/cptn-decl-abrupt-empty.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.4.7 +description: > + Completion value when head has a declaration but no "test" expression +info: > + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(varDcl). + 3. Return ForBodyEvaluation(the first Expression, the second Expression, + Statement, « », labelSet). + + 13.7.4.8 Runtime Semantics: ForBodyEvaluation + 1. Let V = undefined. + [...] + 4. Repeat + a. If test is not [empty], then + [...] + b. Let result be the result of evaluating stmt. + c. If LoopContinues(result, labelSet) is false, return + Completion(UpdateEmpty(result, V)). + + 13.9.3 Runtime Semantics: Evaluation + + BreakStatement : break ; + + 1. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: empty}. +---*/ + +assert.sameValue(eval('1; for (var run = true; ; ) { break; }'), undefined); +assert.sameValue( + eval('2; for (var first = true; ; ) { if (!first) { break; } first = false; 3; }'), + 3, + 'Updating an empty completion from a prior iteration.' +); + +assert.sameValue(eval('4; outer: do { for (var run = true; ; ) { continue outer; } } while (false)'), undefined); +assert.sameValue( + eval('5; outer: do { for (var first = true; ; ) { if (!first) { continue outer; } first = false; 6; } } while (false)'), + 6, + 'Updating an empty completion from a prior iteration.' +); diff --git a/test/language/statements/for/cptn-decl-expr-iter.js b/test/language/statements/for/cptn-decl-expr-iter.js new file mode 100644 index 0000000000..48b3fbb6f9 --- /dev/null +++ b/test/language/statements/for/cptn-decl-expr-iter.js @@ -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. +/*--- +es6id: 13.7.4.7 +description: > + Completion value when head has a declaration and a "test" expression and iteration occurs +info: > + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(varDcl). + 3. Return ForBodyEvaluation(the first Expression, the second Expression, + Statement, « », labelSet). + + 13.7.4.8 Runtime Semantics: ForBodyEvaluation + 1. Let V = undefined. + [...] + 4. Repeat + a. If test is not [empty], then + i. Let testRef be the result of evaluating test. + ii. Let testValue be GetValue(testRef). + iii. ReturnIfAbrupt(testValue). + iv. If ToBoolean(testValue) is false, return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; for (var runA = true; runA; runA = false) { }'), undefined +); +assert.sameValue( + eval('2; for (var runB = true; runB; runB = false) { 3; }'), 3 +); diff --git a/test/language/statements/for/cptn-decl-expr-no-iter.js b/test/language/statements/for/cptn-decl-expr-no-iter.js new file mode 100644 index 0000000000..c14c12f68c --- /dev/null +++ b/test/language/statements/for/cptn-decl-expr-no-iter.js @@ -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. +/*--- +es6id: 13.7.4.7 +description: > + Completion value when head has a declaration and a "test" expression and no iteration occurs +info: > + IterationStatement : + for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement + + 1. Let varDcl be the result of evaluating VariableDeclarationList. + 2. ReturnIfAbrupt(varDcl). + 3. Return ForBodyEvaluation(the first Expression, the second Expression, + Statement, « », labelSet). + + 13.7.4.8 Runtime Semantics: ForBodyEvaluation + 1. Let V = undefined. + [...] + 4. Repeat + a. If test is not [empty], then + i. Let testRef be the result of evaluating test. + ii. Let testValue be GetValue(testRef). + iii. ReturnIfAbrupt(testValue). + iv. If ToBoolean(testValue) is false, return NormalCompletion(V). +---*/ + +assert.sameValue(eval('1; for (var run = false; run; ) { }'), undefined); +assert.sameValue(eval('2; for (var run = false; run; ) { 3; }'), undefined); diff --git a/test/language/statements/for/cptn-expr-abrupt-empty.js b/test/language/statements/for/cptn-expr-abrupt-empty.js new file mode 100644 index 0000000000..b51cc62f79 --- /dev/null +++ b/test/language/statements/for/cptn-expr-abrupt-empty.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.4.7 +description: > + Completion value when head has no declaration and no "test" expression +info: > + IterationStatement : + for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement + + 1. If the first Expression is present, then + a. Let exprRef be the result of evaluating the first Expression. + b. Let exprValue be GetValue(exprRef). + c. ReturnIfAbrupt(exprValue). + 2. Return ForBodyEvaluation(the second Expression, the third Expression, + Statement, « », labelSet). + + 13.7.4.8 Runtime Semantics: ForBodyEvaluation + 1. Let V = undefined. + [...] + 4. Repeat + a. If test is not [empty], then + [...] + b. Let result be the result of evaluating stmt. + c. If LoopContinues(result, labelSet) is false, return + Completion(UpdateEmpty(result, V)). + + 13.9.3 Runtime Semantics: Evaluation + + BreakStatement : break ; + + 1. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: empty}. +---*/ + +assert.sameValue(eval('1; for ( ; ; ) { break; }'), undefined); +assert.sameValue(eval('2; for ( ; ; ) { 3; break; }'), 3); +assert.sameValue( + eval('var first = true; 4; for ( ; ; ) { if (!first) { 5; break; } first = false; }'), + 5, + 'Updating an empty completion from a prior iteration.' +); +assert.sameValue( + eval('var first = true; 6; for ( ; ; ) { if (!first) { break; } first = false; 7; }'), + 7, + 'Updating an empty completion from a prior iteration.' +); + +assert.sameValue(eval('8; outer: do { for ( ; ; ) { continue outer; } } while (false)'), undefined); +assert.sameValue(eval('9; outer: do { for ( ; ; ) { 10; continue outer; } } while (false)'), 10); +assert.sameValue( + eval('var first = true; 11; outer: do { for ( ; ; ) { if (!first) { 12; continue outer; } first = false; } } while (false)'), + 12, + 'Updating an empty completion from a prior iteration.' +); +assert.sameValue( + eval('var first = true; 13; outer: do { for ( ; ; ) { if (!first) { continue outer; } first = false; 14; } } while (false)'), + 14, + 'Updating an empty completion from a prior iteration.' +); diff --git a/test/language/statements/for/cptn-expr-expr-iter.js b/test/language/statements/for/cptn-expr-expr-iter.js new file mode 100644 index 0000000000..9dc98a6f36 --- /dev/null +++ b/test/language/statements/for/cptn-expr-expr-iter.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.7.4.7 +description: > + Completion value when head has no declaration and a "test" expression and + iteration occurs +info: > + IterationStatement : + for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement + + 1. If the first Expression is present, then + a. Let exprRef be the result of evaluating the first Expression. + b. Let exprValue be GetValue(exprRef). + c. ReturnIfAbrupt(exprValue). + 2. Return ForBodyEvaluation(the second Expression, the third Expression, + Statement, « », labelSet). + + 13.7.4.8 Runtime Semantics: ForBodyEvaluation + 1. Let V = undefined. + [...] + 4. Repeat + a. If test is not [empty], then + i. Let testRef be the result of evaluating test. + ii. Let testValue be GetValue(testRef). + iii. ReturnIfAbrupt(testValue). + iv. If ToBoolean(testValue) is false, return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('var runA; 1; for (runA = true; runA; runA = false) { }'), undefined +); +assert.sameValue( + eval('var runB; 2; for (runB = true; runB; runB = false) { 3; }'), 3 +); diff --git a/test/language/statements/for/cptn-expr-expr-no-iter.js b/test/language/statements/for/cptn-expr-expr-no-iter.js new file mode 100644 index 0000000000..1dc8001217 --- /dev/null +++ b/test/language/statements/for/cptn-expr-expr-no-iter.js @@ -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. +/*--- +es6id: 13.7.4.7 +description: > + Completion value when head has no declaration and a "test" expression and no iteration occurs +info: > + IterationStatement : + for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement + + 1. If the first Expression is present, then + a. Let exprRef be the result of evaluating the first Expression. + b. Let exprValue be GetValue(exprRef). + c. ReturnIfAbrupt(exprValue). + 2. Return ForBodyEvaluation(the second Expression, the third Expression, + Statement, « », labelSet). + + 13.7.4.8 Runtime Semantics: ForBodyEvaluation + 1. Let V = undefined. + [...] + 4. Repeat + a. If test is not [empty], then + i. Let testRef be the result of evaluating test. + ii. Let testValue be GetValue(testRef). + iii. ReturnIfAbrupt(testValue). + iv. If ToBoolean(testValue) is false, return NormalCompletion(V). +---*/ + +assert.sameValue(eval('1; for ( ; false; ) { }'), undefined); +assert.sameValue(eval('2; for ( ; false; ) { 3; }'), undefined); diff --git a/test/language/statements/if/cptn-else-false-abrupt-empty.js b/test/language/statements/if/cptn-else-false-abrupt-empty.js new file mode 100644 index 0000000000..6fb94344a7 --- /dev/null +++ b/test/language/statements/if/cptn-else-false-abrupt-empty.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.6.7 +description: + Completion value when expression is false with an `else` clause and body + returns an empty abrupt completion +info: > + IfStatement : if ( Expression ) Statement else Statement + + 4. If exprValue is true, then + [...] + 5. Else, + a. Let stmtCompletion be the result of evaluating the second Statement. + 6. ReturnIfAbrupt(stmtCompletion). + 7. If stmtCompletion.[[value]] is not empty, return stmtCompletion. + 8. Return NormalCompletion(undefined). +---*/ + +assert.sameValue( + eval('1; do { if (false) { } else { break; } } while (false)'), undefined +); +assert.sameValue( + eval('2; do { 3; if (false) { } else { break; } } while (false)'), 3 +); +assert.sameValue( + eval('4; do { if (false) { 5; } else { break; } } while (false)'), undefined +); +assert.sameValue( + eval('6; do { 7; if (false) { 8; } else { break; } } while (false)'), 7 +); + +assert.sameValue( + eval('9; do { if (false) { } else { continue; } } while (false)'), undefined +); +assert.sameValue( + eval('10; do { 11; if (false) { } else { continue; } } while (false)'), 11 +); +assert.sameValue( + eval('12; do { if (false) { 13; } else { continue; } } while (false)'), + undefined +); +assert.sameValue( + eval('14; do { 15; if (false) { 16; } else { continue; } } while (false)'), + 15 +); diff --git a/test/language/statements/if/cptn-else-false-nrml.js b/test/language/statements/if/cptn-else-false-nrml.js new file mode 100644 index 0000000000..90ce477937 --- /dev/null +++ b/test/language/statements/if/cptn-else-false-nrml.js @@ -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. +/*--- +es6id: 13.6.7 +description: > + Completion value when expression is false with an `else` clause and body + returns a normal completion +info: > + IfStatement : if ( Expression ) Statement else Statement + + 4. If exprValue is true, then + [...] + 5. Else, + a. Let stmtCompletion be the result of evaluating the second Statement. + 6. ReturnIfAbrupt(stmtCompletion). + 7. If stmtCompletion.[[value]] is not empty, return stmtCompletion. + 8. Return NormalCompletion(undefined). +---*/ + +assert.sameValue(eval('1; if (false) { } else { }'), undefined); +assert.sameValue(eval('2; if (false) { } else { 3; }'), 3); +assert.sameValue(eval('4; if (false) { 5; } else { }'), undefined); +assert.sameValue(eval('6; if (false) { 7; } else { 8; }'), 8); diff --git a/test/language/statements/if/cptn-else-true-abrupt-empty.js b/test/language/statements/if/cptn-else-true-abrupt-empty.js new file mode 100644 index 0000000000..7c26d250c4 --- /dev/null +++ b/test/language/statements/if/cptn-else-true-abrupt-empty.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.6.7 +description: > + Completion value when expression is true with an `else` clause and body + returns an abrupt completion +info: > + IfStatement : if ( Expression ) Statement else Statement + + 4. If exprValue is true, then + a. Let stmtCompletion be the result of evaluating the first Statement. + 5. Else, + [...] + 6. ReturnIfAbrupt(stmtCompletion). +---*/ + +assert.sameValue( + eval('1; do { if (true) { break; } else { } } while (false)'), undefined +); +assert.sameValue( + eval('2; do { 3; if (true) { break; } else { } } while (false)'), 3 +); +assert.sameValue( + eval('4; do { if (true) { break; } else { 5; } } while (false)'), undefined +); +assert.sameValue( + eval('6; do { 7; if (true) { break; } else { 8; } } while (false)'), 7 +); + +assert.sameValue( + eval('1; do { if (true) { continue; } else { } } while (false)'), undefined +); +assert.sameValue( + eval('2; do { 3; if (true) { continue; } else { } } while (false)'), 3 +); +assert.sameValue( + eval('4; do { if (true) { continue; } else { 5; } } while (false)'), undefined +); +assert.sameValue( + eval('6; do { 7; if (true) { continue; } else { 8; } } while (false)'), 7 +); diff --git a/test/language/statements/if/cptn-else-true-nrml.js b/test/language/statements/if/cptn-else-true-nrml.js new file mode 100644 index 0000000000..9361464c36 --- /dev/null +++ b/test/language/statements/if/cptn-else-true-nrml.js @@ -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. +/*--- +es6id: 13.6.7 +description: > + Completion value when expression is true with an `else` clause and body + returns a normal completion +info: > + IfStatement : if ( Expression ) Statement else Statement + + 4. If exprValue is true, then + a. Let stmtCompletion be the result of evaluating the first Statement. + 5. Else, + [...] + 6. ReturnIfAbrupt(stmtCompletion). + 7. If stmtCompletion.[[value]] is not empty, return stmtCompletion. + 8. Return NormalCompletion(undefined). +---*/ + +assert.sameValue(eval('1; if (true) { } else { }'), undefined); +assert.sameValue(eval('2; if (true) { 3; } else { }'), 3); +assert.sameValue(eval('4; if (true) { } else { 5; }'), undefined); +assert.sameValue(eval('6; if (true) { 7; } else { 8; }'), 7); diff --git a/test/language/statements/if/cptn-no-else-false.js b/test/language/statements/if/cptn-no-else-false.js new file mode 100644 index 0000000000..b8b877f1f7 --- /dev/null +++ b/test/language/statements/if/cptn-no-else-false.js @@ -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. +/*--- +es6id: 13.6.7 +description: Completion value when expression is false without an `else` clause +info: > + IfStatement : if ( Expression ) Statement + + [...] + 4. If exprValue is false, then + a. Return NormalCompletion(undefined). +---*/ + +assert.sameValue(eval('1; if (false) { }'), undefined); +assert.sameValue(eval('2; if (false) { 3; }'), undefined); diff --git a/test/language/statements/if/cptn-no-else-true-abrupt-empty.js b/test/language/statements/if/cptn-no-else-true-abrupt-empty.js new file mode 100644 index 0000000000..9d8471d0e8 --- /dev/null +++ b/test/language/statements/if/cptn-no-else-true-abrupt-empty.js @@ -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. +/*--- +es6id: 13.6.7 +description: > + Completion value when expression is true without an `else` clause and body + returns an empty abrupt completion +info: > + IfStatement : if ( Expression ) Statement + + [...] + 4. If exprValue is false, then + [...] + 5. Else, + a. Let stmtCompletion be the result of evaluating Statement. + b. ReturnIfAbrupt(stmtCompletion). +---*/ + +assert.sameValue( + eval('1; do { 2; if (true) { 3; break; } 4; } while (false)'), 3 +); +assert.sameValue( + eval('5; do { 6; if (true) { break; } 7; } while (false)'), 6 +); + +assert.sameValue( + eval('8; do { 9; if (true) { 10; continue; } 11; } while (false)'), 10 +); +assert.sameValue( + eval('12; do { 13; if (true) { continue; } 14; } while (false)'), 13 +); diff --git a/test/language/statements/if/cptn-no-else-true-nrml.js b/test/language/statements/if/cptn-no-else-true-nrml.js new file mode 100644 index 0000000000..47722221e4 --- /dev/null +++ b/test/language/statements/if/cptn-no-else-true-nrml.js @@ -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. +/*--- +es6id: 13.6.7 +description: > + Completion value when expression is true without an `else` clause and body + returns a normal completion. +info: > + IfStatement : if ( Expression ) Statement + + [...] + 4. If exprValue is false, then + [...] + 5. Else, + a. Let stmtCompletion be the result of evaluating Statement. + b. ReturnIfAbrupt(stmtCompletion). + c. If stmtCompletion.[[value]] is not empty, return stmtCompletion. + d. Return NormalCompletion(undefined). +---*/ + +assert.sameValue(eval('1; if (true) { }'), undefined); +assert.sameValue(eval('2; if (true) { 3; }'), 3); diff --git a/test/language/statements/switch/cptn-a-abrupt-empty.js b/test/language/statements/switch/cptn-a-abrupt-empty.js new file mode 100644 index 0000000000..2112d9734c --- /dev/null +++ b/test/language/statements/switch/cptn-a-abrupt-empty.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when the matching case is exited via an empty abrupt + completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + a. If found is false, then + i. Let clauseSelector be the result of CaseSelectorEvaluation of C. + ii. If clauseSelector is an abrupt completion, then + 1. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + 2. Else, return Completion(clauseSelector). + iii. Let found be the result of performing Strict Equality Comparison + input === clauseSelector.[[value]]. + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, + V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": break; default: }'), undefined +); +assert.sameValue( + eval('2; switch ("a") { case "a": { 3; break; } default: }'), 3 +); + +assert.sameValue( + eval('4; do { switch ("a") { case "a": continue; default: } } while (false)'), + undefined +); +assert.sameValue( + eval('5; do { switch ("a") { case "a": { 6; continue; } default: } } while (false)'), + 6 +); diff --git a/test/language/statements/switch/cptn-a-fall-thru-abrupt-empty.js b/test/language/statements/switch/cptn-a-fall-thru-abrupt-empty.js new file mode 100644 index 0000000000..32b7160ff7 --- /dev/null +++ b/test/language/statements/switch/cptn-a-fall-thru-abrupt-empty.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with an empty abrupt completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + a. If found is false, then + [...] + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, + V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": 2; case "b": 3; break; default: }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { case "a": case "b": 5; break; default: }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { case "a": 7; case "b": break; default: }'), + 7, + 'Empty value does not replace previous non-empty value' +); + +assert.sameValue( + eval('8; do { switch ("a") { case "a": 9; case "b": 10; continue; default: } } while (false)'), + 10, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('11; do { switch ("a") { case "a": case "b": 12; continue; default: } } while (false)'), + 12, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('13; do { switch ("a") { case "a": 14; case "b": continue; default: } } while (false)'), + 14, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-a-fall-thru-nrml.js b/test/language/statements/switch/cptn-a-fall-thru-nrml.js new file mode 100644 index 0000000000..8656dbfbcb --- /dev/null +++ b/test/language/statements/switch/cptn-a-fall-thru-nrml.js @@ -0,0 +1,66 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with a normal completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + a. If found is false, then + i. Let clauseSelector be the result of CaseSelectorEvaluation of C. + ii. If clauseSelector is an abrupt completion, then + [...] + iii. Let found be the result of performing Strict Equality Comparison + input === clauseSelector.[[value]]. + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + [...] + [...] + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 12. Repeat for each CaseClause C in B (NOTE this is another complete + iteration of the second CaseClauses) + [...] + 13. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": 2; default: 3; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { case "a": default: 5; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { case "a": 7; default: }'), + 7, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-abrupt-empty.js b/test/language/statements/switch/cptn-abrupt-empty.js new file mode 100644 index 0000000000..1d36b19d80 --- /dev/null +++ b/test/language/statements/switch/cptn-abrupt-empty.js @@ -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. +/*--- +es6id: 13.12.11 +description: > + Completion value when case block is empty +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { } + + 1. Return NormalCompletion(undefined). +---*/ + +assert.sameValue(eval('1; switch(null) {}'), undefined); diff --git a/test/language/statements/switch/cptn-b-abrupt-empty.js b/test/language/statements/switch/cptn-b-abrupt-empty.js new file mode 100644 index 0000000000..ff90ea74ad --- /dev/null +++ b/test/language/statements/switch/cptn-b-abrupt-empty.js @@ -0,0 +1,64 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when the matching case is exited via an empty abrupt + completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + 2. If clauseSelector is an abrupt completion, then + a. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + b. Else, return Completion(clauseSelector). + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + 1. Let R be the result of evaluating CaseClause C. + 2. If R.[[value]] is not empty, let V = R.[[value]]. + 3. If R is an abrupt completion, return + Completion(UpdateEmpty(R, V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "a": break; }'), undefined +); +assert.sameValue( + eval('2; switch ("a") { default: case "a": { 3; break; } }'), 3 +); + +assert.sameValue( + eval('4; do { switch ("a") { default: case "a": continue; } } while (false)'), + undefined +); +assert.sameValue( + eval('5; do { switch ("a") { default: case "a": { 6; continue; } } } while (false)'), + 6 +); diff --git a/test/language/statements/switch/cptn-b-fall-thru-abrupt-empty.js b/test/language/statements/switch/cptn-b-fall-thru-abrupt-empty.js new file mode 100644 index 0000000000..4cb7c5e74f --- /dev/null +++ b/test/language/statements/switch/cptn-b-fall-thru-abrupt-empty.js @@ -0,0 +1,80 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with an empty abrupt completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + 2. If clauseSelector is an abrupt completion, then + a. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + b. Else, return Completion(clauseSelector). + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + 1. Let R be the result of evaluating CaseClause C. + 2. If R.[[value]] is not empty, let V = R.[[value]]. + 3. If R is an abrupt completion, return + Completion(UpdateEmpty(R, V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "a": 2; case "b": 3; break; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { default: case "a": case "b": 5; break; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { default: case "a": 7; case "b": break; }'), + 7, + 'Empty value does not replace previous non-empty value' +); + +assert.sameValue( + eval('8; do { switch ("a") { default: case "a": 9; case "b": 10; continue; } } while (false)'), + 10, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('11; do { switch ("a") { default: case "a": case "b": 12; continue; } } while (false)'), + 12, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('13; do { switch ("a") { default: case "a": 14; case "b": continue; } } while (false)'), + 14, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-b-fall-thru-nrml.js b/test/language/statements/switch/cptn-b-fall-thru-nrml.js new file mode 100644 index 0000000000..7a32793ba4 --- /dev/null +++ b/test/language/statements/switch/cptn-b-fall-thru-nrml.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with a normal completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + 2. If clauseSelector is an abrupt completion, then + a. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + b. Else, return Completion(clauseSelector). + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + 1. Let R be the result of evaluating CaseClause C. + 2. If R.[[value]] is not empty, let V = R.[[value]]. + 3. If R is an abrupt completion, return + Completion(UpdateEmpty(R, V)). + 8. If foundInB is true, return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "a": 2; case "b": 3; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { default: case "a": case "b": 5; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { default: case "a": 7; case "b": }'), + 7, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-b-final.js b/test/language/statements/switch/cptn-b-final.js new file mode 100644 index 0000000000..8ebd9cd72c --- /dev/null +++ b/test/language/statements/switch/cptn-b-final.js @@ -0,0 +1,78 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: Completion value when the final case matches +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + 2. If clauseSelector is an abrupt completion, then + a. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + b. Else, return Completion(clauseSelector). + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + 1. Let R be the result of evaluating CaseClause C. + 2. If R.[[value]] is not empty, let V = R.[[value]]. + 3. If R is an abrupt completion, return + Completion(UpdateEmpty(R, V)). + 8. If foundInB is true, return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "a": }'), + undefined, + 'empty StatementList (lone case)' +); +assert.sameValue( + eval('2; switch ("a") { default: case "a": 3; }'), + 3, + 'non-empy StatementList (lone case)' +); +assert.sameValue( + eval('4; switch ("b") { default: case "a": case "b": }'), + undefined, + 'empty StatementList (following an empty case)' +); +assert.sameValue( + eval('5; switch ("b") { default: case "a": case "b": 6; }'), + 6, + 'non-empty StatementList (following an empty case)' +); +assert.sameValue( + eval('7; switch ("b") { default: case "a": 8; case "b": }'), + undefined, + 'empty StatementList (following a non-empty case)' +); +assert.sameValue( + eval('9; switch ("b") { default: case "a": 10; case "b": 11; }'), + 11, + 'non-empty StatementList (following a non-empty case)' +); diff --git a/test/language/statements/switch/cptn-dflt-abrupt-empty.js b/test/language/statements/switch/cptn-dflt-abrupt-empty.js new file mode 100644 index 0000000000..2b6f817794 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-abrupt-empty.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when the default case is exited via an empty abrupt + completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). +---*/ + +assert.sameValue(eval('1; switch ("a") { default: break; }'), undefined); +assert.sameValue(eval('2; switch ("a") { default: { 3; break; } }'), 3); + +assert.sameValue( + eval('4; do { switch ("a") { default: { continue; } } } while (false)'), + undefined +); +assert.sameValue( + eval('5; do { switch ("a") { default: { 6; continue; } } } while (false)'), + 6 +); diff --git a/test/language/statements/switch/cptn-dflt-b-abrupt-empty.js b/test/language/statements/switch/cptn-dflt-b-abrupt-empty.js new file mode 100644 index 0000000000..748bf34c43 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-b-abrupt-empty.js @@ -0,0 +1,66 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when the matching case is exited via an empty abrupt + completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + [...] + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 12. Repeat for each CaseClause C in B (NOTE this is another complete + iteration of the second CaseClauses) + a. Let R be the result of evaluating CaseClause C. + b. If R.[[value]] is not empty, let V = R.[[value]]. + c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "b": break; }'), undefined +); +assert.sameValue( + eval('2; switch ("a") { default: case "b": { 3; break; } }'), 3 +); + +assert.sameValue( + eval('4; do { switch ("a") { default: case "b": continue; } } while (false)'), + undefined +); +assert.sameValue( + eval('5; do { switch ("a") { default: case "b": { 6; continue; } } } while (false)'), + 6 +); diff --git a/test/language/statements/switch/cptn-dflt-b-fall-thru-abrupt-empty.js b/test/language/statements/switch/cptn-dflt-b-fall-thru-abrupt-empty.js new file mode 100644 index 0000000000..eb76a565c6 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-b-fall-thru-abrupt-empty.js @@ -0,0 +1,82 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with an empty abrupt completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + [...] + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 12. Repeat for each CaseClause C in B (NOTE this is another complete + iteration of the second CaseClauses) + a. Let R be the result of evaluating CaseClause C. + b. If R.[[value]] is not empty, let V = R.[[value]]. + c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "b": 2; case "c": 3; break; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { default: case "b": case "c": 5; break; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { default: case "b": 7; case "c": break; }'), + 7, + 'Empty value does not replace previous non-empty value' +); + +assert.sameValue( + eval('8; do { switch ("a") { default: case "b": 9; case "c": 10; continue; } } while (false)'), + 10, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('11; do { switch ("a") { default: case "b": case "c": 12; continue; } } while (false)'), + 12, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('13; do { switch ("a") { default: case "b": 14; case "c": continue; } } while (false)'), + 14, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-dflt-b-fall-thru-nrml.js b/test/language/statements/switch/cptn-dflt-b-fall-thru-nrml.js new file mode 100644 index 0000000000..bfc97d5a02 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-b-fall-thru-nrml.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with a normal completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + [...] + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 12. Repeat for each CaseClause C in B (NOTE this is another complete + iteration of the second CaseClauses) + a. Let R be the result of evaluating CaseClause C. + b. If R.[[value]] is not empty, let V = R.[[value]]. + c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 13. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "b": 2; case "c": 3; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { default: case "b": case "c": 5; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { default: case "b": 7; case "c": }'), + 7, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-dflt-b-final.js b/test/language/statements/switch/cptn-dflt-b-final.js new file mode 100644 index 0000000000..13130b3e93 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-b-final.js @@ -0,0 +1,80 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: Completion value when the final case matches +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + i. If foundInB is false, then + 1. Let clauseSelector be the result of CaseSelectorEvaluation of + C. + [...] + 3. Let foundInB be the result of performing Strict Equality + Comparison input === clauseSelector.[[value]]. + ii. If foundInB is true, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 12. Repeat for each CaseClause C in B (NOTE this is another complete + iteration of the second CaseClauses) + a. Let R be the result of evaluating CaseClause C. + b. If R.[[value]] is not empty, let V = R.[[value]]. + c. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 13. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: case "b": }'), + undefined, + 'empty StatementList (lone case)' +); +assert.sameValue( + eval('2; switch ("a") { default: case "b": 3; }'), + 3, + 'non-empy StatementList (lone case)' +); +assert.sameValue( + eval('4; switch ("a") { default: case "b": case "c": }'), + undefined, + 'empty StatementList (following an empty case)' +); +assert.sameValue( + eval('5; switch ("a") { default: case "b": case "c": 6; }'), + 6, + 'non-empty StatementList (following an empty case)' +); +assert.sameValue( + eval('7; switch ("a") { default: case "b": 8; case "c": }'), + 8, + 'empty StatementList (following a non-empty case)' +); +assert.sameValue( + eval('9; switch ("a") { default: case "b": 10; case "c": 11; }'), + 11, + 'non-empty StatementList (following a non-empty case)' +); diff --git a/test/language/statements/switch/cptn-dflt-fall-thru-abrupt-empty.js b/test/language/statements/switch/cptn-dflt-fall-thru-abrupt-empty.js new file mode 100644 index 0000000000..00b7cc2fe6 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-fall-thru-abrupt-empty.js @@ -0,0 +1,69 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with an empty abrupt completion in the default case +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": 2; default: 3; break; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { case "a": default: 5; break; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { case "a": 7; default: break; }'), + 7, + 'Empty value does not replace previous non-empty value' +); + +assert.sameValue( + eval('8; do { switch ("a") { case "a": 9; default: 10; continue; } } while (false)'), + 10, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('11; do { switch ("a") { case "a": default: 12; continue; } } while (false)'), + 12, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('13; do { switch ("a") { case "a": 14; default: continue; } } while (false)'), + 14, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-dflt-fall-thru-nrml.js b/test/language/statements/switch/cptn-dflt-fall-thru-nrml.js new file mode 100644 index 0000000000..b8dc7d6299 --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-fall-thru-nrml.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with a normal completion in the default case +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + 11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)). + 12. Repeat for each CaseClause C in B (NOTE this is another complete + iteration of the second CaseClauses) + [...] + 13. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": 2; default: 3; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { case "a": default: 5; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { case "a": 7; default: }'), + 7, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-dflt-final.js b/test/language/statements/switch/cptn-dflt-final.js new file mode 100644 index 0000000000..0dc6eb54aa --- /dev/null +++ b/test/language/statements/switch/cptn-dflt-final.js @@ -0,0 +1,68 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: Completion value when the default case matches and is final +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the list of CaseClause items in the first CaseClauses, in + source text order. If the first CaseClauses is not present A is « ». + 3. Let found be false. + 4. Repeat for each CaseClause C in A + [...] + 5. Let foundInB be false. + 6. Let B be the List containing the CaseClause items in the second + CaseClauses, in source text order. If the second CaseClauses is not + present B is « ». + 7. If found is false, then + a. Repeat for each CaseClause C in B + [...] + 8. If foundInB is true, return NormalCompletion(V). + 9. Let R be the result of evaluating DefaultClause. + 10. If R.[[value]] is not empty, let V = R.[[value]]. + [...] + 13. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { default: }'), + undefined, + 'empty StatementList (lone case)' +); +assert.sameValue( + eval('2; switch ("a") { default: 3; }'), + 3, + 'non-empy StatementList (lone case)' +); +assert.sameValue( + eval('4; switch ("b") { case "a": default: }'), + undefined, + 'empty StatementList (following an empty case)' +); +assert.sameValue( + eval('5; switch ("b") { case "a": default: 6; }'), + 6, + 'non-empty StatementList (following an empty case)' +); +assert.sameValue( + eval('7; switch ("b") { case "a": 8; default: }'), + undefined, + 'empty StatementList (following a non-empty case)' +); +assert.sameValue( + eval('9; switch ("b") { case "a": 10; default: 11; }'), + 11, + 'non-empty StatementList (following a non-empty case)' +); diff --git a/test/language/statements/switch/cptn-no-dflt-match-abrupt-empty.js b/test/language/statements/switch/cptn-no-dflt-match-abrupt-empty.js new file mode 100644 index 0000000000..fc63f20714 --- /dev/null +++ b/test/language/statements/switch/cptn-no-dflt-match-abrupt-empty.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when the matching case is exited via an empty abrupt + completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the List of CaseClause items in CaseClauses, in source text + order. + 3. Let found be false. + 4. Repeat for each CaseClause C in A, + a. If found is false, then + i. Let clauseSelector be the result of CaseSelectorEvaluation of C. + ii. If clauseSelector is an abrupt completion, then + 1. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + 2. Else, return Completion(clauseSelector). + iii. Let found be the result of performing Strict Equality Comparison + input === clauseSelector.[[value]]. + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, + V)). +---*/ + +assert.sameValue(eval('1; switch ("a") { case "a": break; }'), undefined); +assert.sameValue(eval('2; switch ("a") { case "a": { 3; break; } }'), 3); + +assert.sameValue( + eval('4; do { switch ("a") { case "a": continue; } } while (false)'), + undefined +); +assert.sameValue( + eval('5; do { switch ("a") { case "a": { 6; continue; } } } while (false)'), + 6 +); diff --git a/test/language/statements/switch/cptn-no-dflt-match-fall-thru-abrupt-empty.js b/test/language/statements/switch/cptn-no-dflt-match-fall-thru-abrupt-empty.js new file mode 100644 index 0000000000..37bb2d4f07 --- /dev/null +++ b/test/language/statements/switch/cptn-no-dflt-match-fall-thru-abrupt-empty.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with an empty abrupt completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the List of CaseClause items in CaseClauses, in source text + order. + 3. Let found be false. + 4. Repeat for each CaseClause C in A, + a. If found is false, then + [...] + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, + V)). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": 2; case "b": 3; break; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { case "a": case "b": 5; break; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { case "a": 7; case "b": break; }'), + 7, + 'Empty value does not replace previous non-empty value' +); + +assert.sameValue( + eval('8; do { switch ("a") { case "a": 9; case "b": 10; continue; } } while (false)'), + 10, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('11; do { switch ("a") { case "a": case "b": 12; continue; } } while (false)'), + 12, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('13; do { switch ("a") { case "a": 14; case "b": continue; } } while (false)'), + 14, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-no-dflt-match-fall-thru-nrml.js b/test/language/statements/switch/cptn-no-dflt-match-fall-thru-nrml.js new file mode 100644 index 0000000000..935ac16ad1 --- /dev/null +++ b/test/language/statements/switch/cptn-no-dflt-match-fall-thru-nrml.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: > + Completion value when execution continues through multiple cases and ends + with a normal completion +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the List of CaseClause items in CaseClauses, in source text + order. + 3. Let found be false. + 4. Repeat for each CaseClause C in A, + a. If found is false, then + [...] + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + [...] + 5. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": 2; case "b": 3; }'), + 3, + 'Non-empty value replaces previous non-empty value' +); +assert.sameValue( + eval('4; switch ("a") { case "a": case "b": 5; }'), + 5, + 'Non-empty value replaces empty value' +); +assert.sameValue( + eval('6; switch ("a") { case "a": 7; case "b": }'), + 7, + 'Empty value does not replace previous non-empty value' +); diff --git a/test/language/statements/switch/cptn-no-dflt-match-final.js b/test/language/statements/switch/cptn-no-dflt-match-final.js new file mode 100644 index 0000000000..750addc876 --- /dev/null +++ b/test/language/statements/switch/cptn-no-dflt-match-final.js @@ -0,0 +1,70 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: Completion value when only the final case matches +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the List of CaseClause items in CaseClauses, in source text + order. + 3. Let found be false. + 4. Repeat for each CaseClause C in A, + a. If found is false, then + i. Let clauseSelector be the result of CaseSelectorEvaluation of C. + ii. If clauseSelector is an abrupt completion, then + 1. If clauseSelector.[[value]] is empty, return + Completion{[[type]]: clauseSelector.[[type]], [[value]]: + undefined, [[target]]: clauseSelector.[[target]]}. + 2. Else, return Completion(clauseSelector). + iii. Let found be the result of performing Strict Equality Comparison + input === clauseSelector.[[value]]. + b. If found is true, then + i. Let R be the result of evaluating C. + ii. If R.[[value]] is not empty, let V = R.[[value]]. + iii. If R is an abrupt completion, return Completion(UpdateEmpty(R, + V)). + 5. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case "a": }'), + undefined, + 'empty StatementList (lone case)' +); +assert.sameValue( + eval('2; switch ("a") { case "a": 3; }'), + 3, + 'non-empy StatementList (lone case)' +); +assert.sameValue( + eval('4; switch ("b") { case "a": case "b": }'), + undefined, + 'empty StatementList (following an empty case)' +); +assert.sameValue( + eval('5; switch ("b") { case "a": case "b": 6; }'), + 6, + 'non-empty StatementList (following an empty case)' +); +assert.sameValue( + eval('7; switch ("b") { case "a": 8; case "b": }'), + undefined, + 'empty StatementList (following a non-empty case)' +); +assert.sameValue( + eval('9; switch ("b") { case "a": 10; case "b": 11; }'), + 11, + 'non-empty StatementList (following a non-empty case)' +); diff --git a/test/language/statements/switch/cptn-no-dflt-no-match.js b/test/language/statements/switch/cptn-no-dflt-no-match.js new file mode 100644 index 0000000000..1ffe1804f1 --- /dev/null +++ b/test/language/statements/switch/cptn-no-dflt-no-match.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.12.11 +description: Completion value when no cases match +info: > + SwitchStatement : switch ( Expression ) CaseBlock + + [...] + 8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + 9. Set the running execution context’s LexicalEnvironment to oldEnv. + 10. Return R. + + 13.12.9 Runtime Semantics: CaseBlockEvaluation + + CaseBlock : { CaseClauses } + + 1. Let V = undefined. + 2. Let A be the List of CaseClause items in CaseClauses, in source text + order. + 3. Let found be false. + 4. Repeat for each CaseClause C in A, + a. If found is false, then + i. Let clauseSelector be the result of CaseSelectorEvaluation of C. + ii. If clauseSelector is an abrupt completion, then + [...] + iii. Let found be the result of performing Strict Equality Comparison + input === clauseSelector.[[value]]. + b. If found is true, then + [...] + 5. Return NormalCompletion(V). +---*/ + +assert.sameValue( + eval('1; switch ("a") { case null: }'), undefined, 'empty StatementList' +); +assert.sameValue( + eval('2; switch ("a") { case null: 3; }'), + undefined, + 'non-empty StatementList' +); diff --git a/test/language/statements/try/cptn-catch.js b/test/language/statements/try/cptn-catch.js new file mode 100644 index 0000000000..bb6a3adcdc --- /dev/null +++ b/test/language/statements/try/cptn-catch.js @@ -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. +/*--- +es6id: 13.15.8 +description: Completion value from `catch` clause of a try..catch statement +info: > + TryStatement : try Block Catch + + 1. Let B be the result of evaluating Block. + 2. If B.[[type]] is throw, then + a. Let C be CatchClauseEvaluation of Catch with parameter B.[[value]]. + 3. Else B.[[type]] is not throw, + [...] + 4. If C.[[type]] is return, or C.[[type]] is throw, return Completion(C). + 5. If C.[[value]] is not empty, return Completion(C). + 6. Return Completion{[[type]]: C.[[type]], [[value]]: undefined, + [[target]]: C.[[target]]}. + + 13.15.7 Runtime Semantics: CatchClauseEvaluation + + Catch : catch ( CatchParameter ) Block + + [...] + 7. Let B be the result of evaluating Block. + 8. Set the running execution context’s LexicalEnvironment to oldEnv. + 9. Return Completion(B). +---*/ + +assert.sameValue(eval('1; try { throw null; } catch (err) { }'), undefined); +assert.sameValue(eval('2; try { throw null; } catch (err) { 3; }'), 3); diff --git a/test/language/statements/try/cptn-finally-from-catch.js b/test/language/statements/try/cptn-finally-from-catch.js new file mode 100644 index 0000000000..d5b0a48017 --- /dev/null +++ b/test/language/statements/try/cptn-finally-from-catch.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.15.8 +description: > + Completion value from `finally` clause of a try..catch..finally statement + (following execution of `catch` block) +info: > + TryStatement : try Block Catch Finally + + 1. Let B be the result of evaluating Block. + 2. If B.[[type]] is throw, then + a. Let C be CatchClauseEvaluation of Catch with parameter B.[[value]]. + [...] + 4. Let F be the result of evaluating Finally. + 5. If F.[[type]] is normal, let F be C. + 6. If F.[[type]] is return, or F.[[type]] is throw, return Completion(F). + 7. If F.[[value]] is not empty, return NormalCompletion(F.[[value]]). + 8. Return Completion{[[type]]: F.[[type]], [[value]]: undefined, + [[target]]: F.[[target]]}. + + 13.15.7 Runtime Semantics: CatchClauseEvaluation + + Catch : catch ( CatchParameter ) Block + + [...] + 7. Let B be the result of evaluating Block. + 8. Set the running execution context’s LexicalEnvironment to oldEnv. + 9. Return Completion(B). +---*/ + +assert.sameValue( + eval('1; try { throw null; } catch (err) { } finally { }'), undefined +); +assert.sameValue( + eval('2; try { throw null; } catch (err) { 3; } finally { }'), 3 +); +assert.sameValue( + eval('4; try { throw null; } catch (err) { } finally { 5; }'), undefined +); +assert.sameValue( + eval('6; try { throw null; } catch (err) { 7; } finally { 8; }'), 7 +); diff --git a/test/language/statements/try/cptn-finally-skip-catch.js b/test/language/statements/try/cptn-finally-skip-catch.js new file mode 100644 index 0000000000..00d21834ce --- /dev/null +++ b/test/language/statements/try/cptn-finally-skip-catch.js @@ -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. +/*--- +es6id: 13.15.8 +description: > + Completion value from `finally` clause of a try..catch..finally statement + (when `catch` block is not executed) +info: > + TryStatement : try Block Catch Finally + + 1. Let B be the result of evaluating Block. + 2. If B.[[type]] is throw, then + [...] + 3. Else B.[[type]] is not throw, let C be B. + 4. Let F be the result of evaluating Finally. + 5. If F.[[type]] is normal, let F be C. + 6. If F.[[type]] is return, or F.[[type]] is throw, return Completion(F). + 7. If F.[[value]] is not empty, return NormalCompletion(F.[[value]]). + 8. Return Completion{[[type]]: F.[[type]], [[value]]: undefined, + [[target]]: F.[[target]]}. +---*/ + +assert.sameValue(eval('1; try { } catch (err) { } finally { }'), undefined); +assert.sameValue(eval('2; try { } catch (err) { 3; } finally { }'), undefined); +assert.sameValue(eval('4; try { } catch (err) { } finally { 5; }'), undefined); +assert.sameValue(eval('6; try { } catch (err) { 7; } finally { 8; }'), undefined); +assert.sameValue(eval('9; try { 10; } catch (err) { } finally { }'), 10); +assert.sameValue(eval('11; try { 12; } catch (err) { 13; } finally { }'), 12); +assert.sameValue(eval('14; try { 15; } catch (err) { } finally { 16; }'), 15); +assert.sameValue(eval('17; try { 18; } catch (err) { 19; } finally { 20; }'), 18); diff --git a/test/language/statements/try/cptn-finally-wo-catch.js b/test/language/statements/try/cptn-finally-wo-catch.js new file mode 100644 index 0000000000..9b311be9f1 --- /dev/null +++ b/test/language/statements/try/cptn-finally-wo-catch.js @@ -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. +/*--- +es6id: 13.15.8 +description: Completion value from `finally` clause of a try..finally statement +info: > + TryStatement : try Block Finally + + 1. Let B be the result of evaluating Block. + 2. Let F be the result of evaluating Finally. + 3. If F.[[type]] is normal, let F be B. + 4. If F.[[type]] is return, or F.[[type]] is throw, return Completion(F). + 5. If F.[[value]] is not empty, return Completion(F). + 6. Return Completion{[[type]]: F.[[type]], [[value]]: undefined, + [[target]]: F.[[target]]}. +---*/ + + +assert.sameValue(eval('1; try { } finally { }'), undefined); +assert.sameValue(eval('2; try { 3; } finally { }'), 3); +assert.sameValue(eval('4; try { } finally { 5; }'), undefined); +assert.sameValue(eval('6; try { 7; } finally { 8; }'), 7); diff --git a/test/language/statements/try/cptn-try.js b/test/language/statements/try/cptn-try.js new file mode 100644 index 0000000000..05a8f51cfd --- /dev/null +++ b/test/language/statements/try/cptn-try.js @@ -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. +/*--- +es6id: 13.15.8 +description: Completion value from `try` clause of a try..catch statement +info: > + TryStatement : try Block Catch + + 1. Let B be the result of evaluating Block. + 2. If B.[[type]] is throw, then + [...] + 3. Else B.[[type]] is not throw, + a. Let C be B. + 4. If C.[[type]] is return, or C.[[type]] is throw, return Completion(C). + 5. If C.[[value]] is not empty, return Completion(C). + 6. Return Completion{[[type]]: C.[[type]], [[value]]: undefined, + [[target]]: C.[[target]]}. +---*/ + +assert.sameValue(eval('1; try { } catch (err) { }'), undefined); +assert.sameValue(eval('2; try { 3; } catch (err) { }'), 3); +assert.sameValue(eval('4; try { } catch (err) { 5; }'), undefined); +assert.sameValue(eval('6; try { 7; } catch (err) { 8; }'), 7); diff --git a/test/language/statements/while/cptn-abrupt-empty.js b/test/language/statements/while/cptn-abrupt-empty.js new file mode 100644 index 0000000000..cbbaa2e8e0 --- /dev/null +++ b/test/language/statements/while/cptn-abrupt-empty.js @@ -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. +/*--- +es6id: 13.7.3.6 +description: > + Completion value when iteration completes due to an empty abrupt completion +info: > + IterationStatement : while ( Expression ) Statement + + 1. Let V = undefined. + 2. Repeat + a. Let exprRef be the result of evaluating Expression. + b. Let exprValue be GetValue(exprRef). + c. ReturnIfAbrupt(exprValue). + d. If ToBoolean(exprValue) is false, return NormalCompletion(V). + e. Let stmt be the result of evaluating Statement. + f. If LoopContinues (stmt, labelSet) is false, return + Completion(UpdateEmpty(stmt, V)). +---*/ + +assert.sameValue(eval('1; while (true) { break; }'), undefined); +assert.sameValue(eval('2; while (true) { 3; break; }'), 3); + +assert.sameValue( + eval('4; outer: do { while (true) { continue outer; } } while (false)'), + undefined +); +assert.sameValue( + eval('5; outer: do { while (true) { 6; continue outer; } } while (false)'), 6 +); diff --git a/test/language/statements/while/cptn-iter.js b/test/language/statements/while/cptn-iter.js new file mode 100644 index 0000000000..9e615de94b --- /dev/null +++ b/test/language/statements/while/cptn-iter.js @@ -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. +/*--- +es6id: 13.7.3.6 +description: > + Completion value when iteration completes due to expression value +info: > + IterationStatement : while ( Expression ) Statement + + 1. Let V = undefined. + 2. Repeat + a. Let exprRef be the result of evaluating Expression. + b. Let exprValue be GetValue(exprRef). + c. ReturnIfAbrupt(exprValue). + d. If ToBoolean(exprValue) is false, return NormalCompletion(V). + e. Let stmt be the result of evaluating Statement. + f. If LoopContinues (stmt, labelSet) is false, return + Completion(UpdateEmpty(stmt, V)). + g. If stmt.[[value]] is not empty, let V = stmt.[[value]]. +---*/ + +assert.sameValue(eval('var count1 = 2; 1; while (count1 -= 1) { }'), undefined); +assert.sameValue(eval('var count2 = 2; 2; while (count2 -= 1) { 3; }'), 3); diff --git a/test/language/statements/while/cptn-no-iter.js b/test/language/statements/while/cptn-no-iter.js new file mode 100644 index 0000000000..e81bd7b64e --- /dev/null +++ b/test/language/statements/while/cptn-no-iter.js @@ -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. +/*--- +es6id: 13.7.3.6 +description: > + Completion value when no iteration occurs +info: > + IterationStatement : while ( Expression ) Statement + + 1. Let V = undefined. + 2. Repeat + a. Let exprRef be the result of evaluating Expression. + b. Let exprValue be GetValue(exprRef). + c. ReturnIfAbrupt(exprValue). + d. If ToBoolean(exprValue) is false, return NormalCompletion(V). +---*/ + +assert.sameValue(eval('1; while (false) { }'), undefined); +assert.sameValue(eval('2; while (false) { 3; }'), undefined); diff --git a/test/language/statements/with/cptn-abrupt-empty.js b/test/language/statements/with/cptn-abrupt-empty.js new file mode 100644 index 0000000000..739884f0db --- /dev/null +++ b/test/language/statements/with/cptn-abrupt-empty.js @@ -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. +/*--- +es6id: 13.11.7 +description: > + Statement completion value when body returns an empty abrupt completion +info: > + WithStatement : with ( Expression ) Statement + + [...] + 8. Let C be the result of evaluating Statement. + 9. Set the running execution context’s Lexical Environment to oldEnv. + 10. If C.[[type]] is normal and C.[[value]] is empty, return + NormalCompletion(undefined). +flags: [noStrict] +---*/ + +assert.sameValue( + eval('1; do { 2; with({}) { 3; break; } 4; } while (false);'), 3 +); +assert.sameValue( + eval('5; do { 6; with({}) { break; } 7; } while (false);'), 6 +); + +assert.sameValue( + eval('8; do { 9; with({}) { 10; continue; } 11; } while (false)'), 10 +); +assert.sameValue( + eval('12; do { 13; with({}) { continue; } 14; } while (false)'), 13 +); diff --git a/test/language/statements/with/cptn-nrml.js b/test/language/statements/with/cptn-nrml.js new file mode 100644 index 0000000000..e2a540fa82 --- /dev/null +++ b/test/language/statements/with/cptn-nrml.js @@ -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. +/*--- +es6id: 13.11.7 +description: Statement completion value when body returns a normal completion +info: > + WithStatement : with ( Expression ) Statement + + [...] + 8. Let C be the result of evaluating Statement. + 9. Set the running execution context’s Lexical Environment to oldEnv. + 10. If C.[[type]] is normal and C.[[value]] is empty, return + NormalCompletion(undefined). + 11. Return Completion(C). +flags: [noStrict] +---*/ + +assert.sameValue(eval('1; with({}) { }'), undefined); +assert.sameValue(eval('2; with({}) { 3; }'), 3);