Home | History | Annotate | Download | only in regress
      1 // Copyright 2016 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 
      6 // In sloppy mode we allow function redeclarations within blocks for webcompat.
      7 (function() {
      8   assertEquals(undefined, f);  // Annex B
      9   if (true) {
     10     assertEquals(2, f());
     11     function f() { return 1 }
     12     assertEquals(2, f());
     13     function f() { return 2 }
     14     assertEquals(2, f());
     15   }
     16   assertEquals(2, f());  // Annex B
     17 })();
     18 
     19 // Should still fail in strict mode
     20 assertThrows(`
     21   (function() {
     22     "use strict";
     23     if (true) {
     24       function f() { return 1 }
     25       function f() { return 2 }
     26     }
     27   })();
     28 `, SyntaxError);
     29 
     30 // Conflicts between let and function still throw
     31 assertThrows(`
     32   (function() {
     33     if (true) {
     34       let f;
     35       function f() { return 2 }
     36     }
     37   })();
     38 `, SyntaxError);
     39 
     40 assertThrows(`
     41   (function() {
     42     if (true) {
     43       function f() { return 2 }
     44       let f;
     45     }
     46   })();
     47 `, SyntaxError);
     48 
     49 // Conflicts between const and function still throw
     50 assertThrows(`
     51   (function() {
     52     if (true) {
     53       const f;
     54       function f() { return 2 }
     55     }
     56   })();
     57 `, SyntaxError);
     58 
     59 assertThrows(`
     60   (function() {
     61     if (true) {
     62       function f() { return 2 }
     63       const f;
     64     }
     65   })();
     66 `, SyntaxError);
     67 
     68 // Annex B redefinition semantics still apply with more blocks
     69 (function() {
     70   assertEquals(undefined, f);  // Annex B
     71   if (true) {
     72     assertEquals(undefined, f);
     73     { function f() { return 1 } }
     74     assertEquals(1, f());
     75     { function f() { return 2 } }
     76     assertEquals(2, f());
     77   }
     78   assertEquals(2, f());  // Annex B
     79 })();
     80