OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --strong-mode --harmony_rest_parameters --harmony_arrow_functions --ha
rmony_classes --harmony_computed-property_names | 5 // Flags: --strong-mode --harmony_rest_parameters --harmony_arrow_functions --ha
rmony_classes --harmony_computed-property_names |
6 | 6 |
7 // Note that it's essential for these tests that the reference is inside dead | 7 // Note that it's essential for these tests that the reference is inside dead |
8 // code (because we already produce ReferenceErrors for run-time unresolved | 8 // code (because we already produce ReferenceErrors for run-time unresolved |
9 // variables and don't want to confuse those with strong mode errors). But the | 9 // variables and don't want to confuse those with strong mode errors). But the |
10 // errors should *not* be inside lazy, unexecuted functions, since lazy parsing | 10 // errors should *not* be inside lazy, unexecuted functions, since lazy parsing |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 (function DeclarationAfterUse() { | 28 (function DeclarationAfterUse() { |
29 // Note that these tests only test cases where the declaration is found but is | 29 // Note that these tests only test cases where the declaration is found but is |
30 // after the use. In particular, we cannot yet detect cases where the use can | 30 // after the use. In particular, we cannot yet detect cases where the use can |
31 // possibly bind to a global variable. | 31 // possibly bind to a global variable. |
32 assertThrowsHelper("x; let x = 0;"); | 32 assertThrowsHelper("x; let x = 0;"); |
33 assertThrowsHelper("function f() { x; let x = 0; }"); | 33 assertThrowsHelper("function f() { x; let x = 0; }"); |
34 assertThrowsHelper("function f() { x; } let x = 0;"); | 34 assertThrowsHelper("function f() { x; } let x = 0;"); |
35 | 35 |
| 36 assertThrowsHelper("x; const x = 0;"); |
| 37 assertThrowsHelper("function f() { x; const x = 0; }"); |
| 38 assertThrowsHelper("function f() { x; } const x = 0;"); |
| 39 |
36 // These tests needs to be done a bit more manually, since var is not allowed | 40 // These tests needs to be done a bit more manually, since var is not allowed |
37 // in strong mode: | 41 // in strong mode: |
38 assertThrows( | 42 assertThrows( |
39 `(function outer() { | 43 `(function outer() { |
40 function f() { 'use strong'; if (false) { x; } } var x = 0; f(); | 44 function f() { 'use strong'; if (false) { x; } } var x = 0; f(); |
41 })()`, | 45 })()`, |
42 ReferenceError); | 46 ReferenceError); |
43 assertDoesNotThrow( | 47 assertDoesNotThrow( |
44 "(function outer() {\n" + | 48 "(function outer() {\n" + |
45 " function f() { if (false) { x; } } var x = 0; f(); \n" + | 49 " function f() { if (false) { x; } } var x = 0; f(); \n" + |
(...skipping 25 matching lines...) Expand all Loading... |
71 assertThrowsHelper("for (const x = x; ; ) { }"); | 75 assertThrowsHelper("for (const x = x; ; ) { }"); |
72 assertThrowsHelper("for (let x = y, y; ; ) { }"); | 76 assertThrowsHelper("for (let x = y, y; ; ) { }"); |
73 assertThrowsHelper("for (const x = y, y = 0; ; ) { }"); | 77 assertThrowsHelper("for (const x = y, y = 0; ; ) { }"); |
74 | 78 |
75 // Computed property names | 79 // Computed property names |
76 assertThrowsHelper("let o = { 'a': 'b', [o.a]: 'c'};"); | 80 assertThrowsHelper("let o = { 'a': 'b', [o.a]: 'c'};"); |
77 })(); | 81 })(); |
78 | 82 |
79 | 83 |
80 (function DeclarationAfterUseInClasses() { | 84 (function DeclarationAfterUseInClasses() { |
| 85 // Referring to a variable declared later |
| 86 assertThrowsHelper("class C { m() { x; } } let x = 0;"); |
| 87 assertThrowsHelper("class C { static m() { x; } } let x = 0;"); |
| 88 assertThrowsHelper("class C { [x]() { } } let x = 0;"); |
| 89 |
| 90 assertThrowsHelper("class C { m() { x; } } const x = 0;"); |
| 91 assertThrowsHelper("class C { static m() { x; } } const x = 0;"); |
| 92 assertThrowsHelper("class C { [x]() { } } const x = 0;"); |
| 93 |
| 94 // Referring to the class name. |
81 assertThrowsHelper("class C extends C { }"); | 95 assertThrowsHelper("class C extends C { }"); |
82 assertThrowsHelper("let C = class C2 extends C { }"); | 96 assertThrowsHelper("let C = class C2 extends C { }"); |
83 assertThrowsHelper("let C = class C2 extends C2 { }"); | 97 assertThrowsHelper("let C = class C2 extends C2 { }"); |
84 | 98 |
85 assertThrowsHelper("let C = class C2 { constructor() { C; } }"); | 99 assertThrowsHelper("let C = class C2 { constructor() { C; } }"); |
86 assertThrowsHelper("let C = class C2 { method() { C; } }"); | 100 assertThrowsHelper("let C = class C2 { method() { C; } }"); |
87 assertThrowsHelper("let C = class C2 { *generator_method() { C; } }"); | 101 assertThrowsHelper("let C = class C2 { *generator_method() { C; } }"); |
88 | 102 |
89 assertThrowsHelper( | 103 assertThrowsHelper( |
90 `let C = class C2 { | 104 `let C = class C2 { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 249 } |
236 return new CInner(); | 250 return new CInner(); |
237 } | 251 } |
238 } | 252 } |
239 (new COuter()).m().n(); | 253 (new COuter()).m().n(); |
240 | 254 |
241 // Making sure the check which is supposed to prevent "object literal inside | 255 // Making sure the check which is supposed to prevent "object literal inside |
242 // computed property name references the class name" is not too generic: | 256 // computed property name references the class name" is not too generic: |
243 class C14 { m() { let obj = { n() { C14 } }; obj.n(); } }; (new C14()).m(); | 257 class C14 { m() { let obj = { n() { C14 } }; obj.n(); } }; (new C14()).m(); |
244 })(); | 258 })(); |
OLD | NEW |