Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2085)

Unified Diff: test/mjsunit/harmony/block-function-sloppy.js

Issue 1234433002: [es6] Sloppy functions in block (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Don't report errors Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/harmony/block-function-sloppy.js
diff --git a/test/mjsunit/harmony/block-function-sloppy.js b/test/mjsunit/harmony/block-function-sloppy.js
new file mode 100644
index 0000000000000000000000000000000000000000..a26b6b41847efc6700dc5ff2a269cd9f703cb166
--- /dev/null
+++ b/test/mjsunit/harmony/block-function-sloppy.js
@@ -0,0 +1,226 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-sloppy --no-legacy-const
+
+
+(function TestHoistingToBlock() {
+ assertEquals(undefined, f);
+ {
+ assertEquals(1, f());
+ function f() { return 1; }
+ assertEquals(1, f());
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestOnlyOneFunction() {
+ var outer, inner;
+ {
+ function f() { return 1; }
+ inner = f;
+ }
+ outer = f;
+ assertEquals(inner, outer);
+})();
+
+
+(function TestNoInitIf() {
+ assertEquals(undefined, f);
+ if (false) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitIf() {
+ assertEquals(undefined, f);
+ if (true) {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitElse() {
+ assertEquals(undefined, f);
+ if (true) {
+ } else {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitElse() {
+ assertEquals(undefined, f);
+ if (false) {
+ } else {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitWhile() {
+ assertEquals(undefined, f);
+ while (false) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitWhile() {
+ assertEquals(undefined, f);
+ while (true) {
+ function f() { return 1; }
+ break;
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitFor() {
+ assertEquals(undefined, f);
+ for (; false; ) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitFor() {
+ assertEquals(undefined, f);
+ for (; true; ) {
+ function f() { return 1; }
+ break
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitForLet() {
+ assertEquals(undefined, f);
+ for (let x; false; ) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitForLet() {
+ assertEquals(undefined, f);
+ for (let x = 0; x < 1; x++) {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitForIn() {
+ assertEquals(undefined, f);
+ for (var k in {}) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitForIn() {
+ assertEquals(undefined, f);
+ for (var k in {a: 1}) {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitForInLet() {
+ assertEquals(undefined, f);
+ for (let k in {}) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitForInLet() {
+ assertEquals(undefined, f);
+ for (let k in {a: 1}) {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitForOf() {
+ assertEquals(undefined, f);
+ for (var v of []) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestNoInitForOf() {
+ assertEquals(undefined, f);
+ for (var v of [0]) {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoInitForOfLet() {
+ assertEquals(undefined, f);
+ for (let v of []) {
+ function f() { return 1; }
+ }
+ assertEquals(undefined, f);
+})();
+
+
+(function TestInitForOfLet() {
+ assertEquals(undefined, f);
+ for (let v of [0]) {
+ function f() { return 1; }
+ }
+ assertEquals(1, f());
+})();
+
+
+(function TestNoVarBindingInCaseOfEarlyError() {
+ let f = 1;
+ assertEquals(1, f);
+ {
+ assertEquals(2, f());
+ function f() { return 2; }
+ assertEquals(2, f());
+ }
+ assertEquals(1, f);
+})();
+
+
+(function TestCorrectError() {
+ var ex;
+ try {
+ eval(`
+ function f() {
+ let x = 1;
+ {
+ function x() {}
+ }
+ let y = 2;
+ let y = 3;
+ }
+ f();
+ `);
+ } catch (e) {
+ ex = e;
+ }
+ assertEquals("Identifier 'y' has already been declared", ex.message);
+})();

Powered by Google App Engine
This is Rietveld 408576698