| OLD | NEW | 
|    1 // Copyright 2011 the V8 project authors. All rights reserved. |    1 // Copyright 2011 the V8 project authors. All rights reserved. | 
|    2 // Redistribution and use in source and binary forms, with or without |    2 // Redistribution and use in source and binary forms, with or without | 
|    3 // modification, are permitted provided that the following conditions are |    3 // modification, are permitted provided that the following conditions are | 
|    4 // met: |    4 // met: | 
|    5 // |    5 // | 
|    6 //     * Redistributions of source code must retain the above copyright |    6 //     * Redistributions of source code must retain the above copyright | 
|    7 //       notice, this list of conditions and the following disclaimer. |    7 //       notice, this list of conditions and the following disclaimer. | 
|    8 //     * Redistributions in binary form must reproduce the above |    8 //     * Redistributions in binary form must reproduce the above | 
|    9 //       copyright notice, this list of conditions and the following |    9 //       copyright notice, this list of conditions and the following | 
|   10 //       disclaimer in the documentation and/or other materials provided |   10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|   26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |   26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|   27  |   27  | 
|   28 // Test let declarations in various settings. |   28 // Test let declarations in various settings. | 
|   29  |   29  | 
|   30 "use strict"; |   30 "use strict"; | 
|   31  |   31  | 
|   32 // Global |   32 // Global | 
|   33 let x; |   33 let x; | 
|   34 let y = 2; |   34 let y = 2; | 
|   35 const z = 4; |   35 const z = 4; | 
 |   36 class c { static foo() { return 1; } } | 
|   36  |   37  | 
|   37 // Block local |   38 // Block local | 
|   38 { |   39 { | 
|   39   let y; |   40   let y; | 
|   40   let x = 3; |   41   let x = 3; | 
|   41   const z = 5; |   42   const z = 5; | 
 |   43   class c { static foo() { return 2; } } | 
|   42 } |   44 } | 
|   43  |   45  | 
|   44 assertEquals(undefined, x); |   46 assertEquals(undefined, x); | 
|   45 assertEquals(2,y); |   47 assertEquals(2,y); | 
|   46 assertEquals(4,z); |   48 assertEquals(4,z); | 
 |   49 assertEquals(1, c.foo()); | 
|   47  |   50  | 
|   48 if (true) { |   51 if (true) { | 
|   49   let y; |   52   let y; | 
|   50   assertEquals(undefined, y); |   53   assertEquals(undefined, y); | 
|   51 } |   54 } | 
|   52  |   55  | 
|   53 // Invalid declarations are early errors in harmony mode and thus should trigger |   56 // Invalid declarations are early errors in harmony mode and thus should trigger | 
|   54 // an exception in eval code during parsing, before even compiling or executing |   57 // an exception in eval code during parsing, before even compiling or executing | 
|   55 // the code. Thus the generated function is not called here. |   58 // the code. Thus the generated function is not called here. | 
|   56 function TestLocalThrows(str, expect) { |   59 function TestLocalThrows(str, expect) { | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   99 // Test var declarations in statement positions. |  102 // Test var declarations in statement positions. | 
|  100 TestLocalDoesNotThrow("if (true) var x;"); |  103 TestLocalDoesNotThrow("if (true) var x;"); | 
|  101 TestLocalDoesNotThrow("if (true) {} else var x;"); |  104 TestLocalDoesNotThrow("if (true) {} else var x;"); | 
|  102 TestLocalDoesNotThrow("do var x; while (false)"); |  105 TestLocalDoesNotThrow("do var x; while (false)"); | 
|  103 TestLocalDoesNotThrow("while (false) var x;"); |  106 TestLocalDoesNotThrow("while (false) var x;"); | 
|  104 TestLocalDoesNotThrow("label: var x;"); |  107 TestLocalDoesNotThrow("label: var x;"); | 
|  105 TestLocalDoesNotThrow("for (;false;) var x;"); |  108 TestLocalDoesNotThrow("for (;false;) var x;"); | 
|  106 TestLocalDoesNotThrow("switch (true) { case true: var x; }"); |  109 TestLocalDoesNotThrow("switch (true) { case true: var x; }"); | 
|  107 TestLocalDoesNotThrow("switch (true) { default: var x; }"); |  110 TestLocalDoesNotThrow("switch (true) { default: var x; }"); | 
|  108  |  111  | 
 |  112 // Test class declarations with initialisers in statement positions. | 
 |  113 TestLocalThrows("if (true) class x { };", SyntaxError); | 
 |  114 TestLocalThrows("if (true) {} else class x { };", SyntaxError); | 
 |  115 TestLocalThrows("do class x { }; while (false)", SyntaxError); | 
 |  116 TestLocalThrows("while (false) class x { };", SyntaxError); | 
 |  117 TestLocalThrows("label: class x { };", SyntaxError); | 
 |  118 TestLocalThrows("for (;false;) class x { };", SyntaxError); | 
 |  119 TestLocalDoesNotThrow("switch (true) { case true: class x { }; }"); | 
 |  120 TestLocalDoesNotThrow("switch (true) { default: class x { }; }"); | 
 |  121  | 
|  109 // Test that redeclarations of functions are only allowed in outermost scope. |  122 // Test that redeclarations of functions are only allowed in outermost scope. | 
|  110 TestLocalThrows("{ let f; var f; }"); |  123 TestLocalThrows("{ let f; var f; }"); | 
|  111 TestLocalThrows("{ var f; let f; }"); |  124 TestLocalThrows("{ var f; let f; }"); | 
|  112 TestLocalThrows("{ function f() {} let f; }"); |  125 TestLocalThrows("{ function f() {} let f; }"); | 
|  113 TestLocalThrows("{ let f; function f() {} }"); |  126 TestLocalThrows("{ let f; function f() {} }"); | 
|  114 TestLocalThrows("{ function f() {} var f; }"); |  127 TestLocalThrows("{ function f() {} var f; }"); | 
|  115 TestLocalThrows("{ var f; function f() {} }"); |  128 TestLocalThrows("{ var f; function f() {} }"); | 
 |  129 TestLocalThrows("{ function f() {} class f {} }"); | 
 |  130 TestLocalThrows("{ class f {}; function f() {} }"); | 
|  116 TestLocalThrows("{ function f() {} function f() {} }"); |  131 TestLocalThrows("{ function f() {} function f() {} }"); | 
|  117 TestLocalThrows("function f() {} let f;"); |  132 TestLocalThrows("function f() {} let f;"); | 
|  118 TestLocalThrows("let f; function f() {}"); |  133 TestLocalThrows("let f; function f() {}"); | 
 |  134 TestLocalThrows("function f() {} class f {}"); | 
 |  135 TestLocalThrows("class f {}; function f() {}"); | 
|  119 TestLocalDoesNotThrow("function arg() {}"); |  136 TestLocalDoesNotThrow("function arg() {}"); | 
|  120 TestLocalDoesNotThrow("function f() {} var f;"); |  137 TestLocalDoesNotThrow("function f() {} var f;"); | 
|  121 TestLocalDoesNotThrow("var f; function f() {}"); |  138 TestLocalDoesNotThrow("var f; function f() {}"); | 
|  122 TestLocalDoesNotThrow("function f() {} function f() {}"); |  139 TestLocalDoesNotThrow("function f() {} function f() {}"); | 
|  123  |  140  | 
|  124 function g(f) { |  141 function g(f) { | 
|  125   function f() { return 1 } |  142   function f() { return 1 } | 
|  126   return f() |  143   return f() | 
|  127 } |  144 } | 
|  128 assertEquals(1, g(function() { return 2 })) |  145 assertEquals(1, g(function() { return 2 })) | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  148  |  165  | 
|  149 // Test function declarations in statement position in strict mode. |  166 // Test function declarations in statement position in strict mode. | 
|  150 TestLocalThrows("function f() { if (true) function g() {} }", SyntaxError); |  167 TestLocalThrows("function f() { if (true) function g() {} }", SyntaxError); | 
|  151 TestLocalThrows("function f() { if (true) {} else function g() {} }", SyntaxErro
     r); |  168 TestLocalThrows("function f() { if (true) {} else function g() {} }", SyntaxErro
     r); | 
|  152 TestLocalThrows("function f() { do function g() {} while (false) }", SyntaxError
     ); |  169 TestLocalThrows("function f() { do function g() {} while (false) }", SyntaxError
     ); | 
|  153 TestLocalThrows("function f() { while (false) function g() {} }", SyntaxError); |  170 TestLocalThrows("function f() { while (false) function g() {} }", SyntaxError); | 
|  154 TestLocalThrows("function f() { label: function g() {} }", SyntaxError); |  171 TestLocalThrows("function f() { label: function g() {} }", SyntaxError); | 
|  155 TestLocalThrows("function f() { for (;false;) function g() {} }", SyntaxError); |  172 TestLocalThrows("function f() { for (;false;) function g() {} }", SyntaxError); | 
|  156 TestLocalDoesNotThrow("function f() { switch (true) { case true: function g() {}
      } }"); |  173 TestLocalDoesNotThrow("function f() { switch (true) { case true: function g() {}
      } }"); | 
|  157 TestLocalDoesNotThrow("function f() { switch (true) { default: function g() {} }
      }"); |  174 TestLocalDoesNotThrow("function f() { switch (true) { default: function g() {} }
      }"); | 
| OLD | NEW |