1// Copyright 2015 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Test for conflicting variable bindings. 6 7// Flags: --harmony-sloppy --harmony-sloppy-function 8 9function AssertEqualsStrictAndSloppy(value, code) { 10 assertEquals(value, eval("(function() {" + code + "})()")); 11 assertEquals(value, eval("(function() { 'use strict'; " + code + "})()")); 12 assertEquals(value, eval("(function() { var x = 0; {" + code + "} })()")); 13 assertEquals(value, eval("(function() { 'use strict'; var x = 0; {" 14 + code + "} })()")); 15} 16 17function AssertThrowsStrictAndSloppy(code, error) { 18 assertThrows("(function() {" + code + "})()", error); 19 assertThrows("(function() { 'use strict'; " + code + "})()", error); 20 assertThrows("(function() { var x = 0; { " + code + "} })()", error); 21 assertThrows("(function() { 'use strict'; var x = 0; {" + code + "} })()", 22 error); 23} 24 25(function TestClassTDZ() { 26 AssertEqualsStrictAndSloppy( 27 "x", "function f() { return x; }; class x { }; return f().name;"); 28 AssertEqualsStrictAndSloppy 29 ("x", "class x { }; function f() { return x; }; return f().name;"); 30 AssertEqualsStrictAndSloppy( 31 "x", "class x { }; var result = f().name; " + 32 "function f() { return x; }; return result;"); 33 AssertThrowsStrictAndSloppy( 34 "function f() { return x; }; f(); class x { };", ReferenceError); 35 AssertThrowsStrictAndSloppy( 36 "f(); function f() { return x; }; class x { };", ReferenceError); 37 AssertThrowsStrictAndSloppy( 38 "f(); class x { }; function f() { return x; };", ReferenceError); 39 AssertThrowsStrictAndSloppy( 40 "var x = 1; { f(); class x { }; function f() { return x; }; }", 41 ReferenceError); 42 AssertThrowsStrictAndSloppy("x = 3; class x { };", ReferenceError) 43})(); 44 45(function TestClassNameConflict() { 46 AssertThrowsStrictAndSloppy("class x { }; var x;", SyntaxError); 47 AssertThrowsStrictAndSloppy("var x; class x { };", SyntaxError); 48 AssertThrowsStrictAndSloppy("class x { }; function x() { };", SyntaxError); 49 AssertThrowsStrictAndSloppy("function x() { }; class x { };", SyntaxError); 50 AssertThrowsStrictAndSloppy("class x { }; for (var x = 0; false;) { };", 51 SyntaxError); 52 AssertThrowsStrictAndSloppy("for (var x = 0; false;) { }; class x { };", 53 SyntaxError); 54})(); 55 56(function TestClassMutableBinding() { 57 AssertEqualsStrictAndSloppy( 58 "x3", "class x { }; var y = x.name; x = 3; return y + x;") 59})(); 60