OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 // NOTE: TestGlobal usually only tests the given string in the context | 52 // NOTE: TestGlobal usually only tests the given string in the context |
53 // of a global object in dictionary mode. This is because we use | 53 // of a global object in dictionary mode. This is because we use |
54 // delete to get rid of any added properties. | 54 // delete to get rid of any added properties. |
55 function TestGlobal(s,e) { | 55 function TestGlobal(s,e) { |
56 // Collect the global properties before the call. | 56 // Collect the global properties before the call. |
57 var properties = []; | 57 var properties = []; |
58 for (var key in this) properties.push(key); | 58 for (var key in this) properties.push(key); |
59 // Compute the result. | 59 // Compute the result. |
60 var result; | 60 var result; |
61 try { | 61 try { |
62 var code = s + (e ? "; $$$result=" + e : ""); | 62 var code = s + (e ? "; $$$result=" + e : ""); |
63 if (this.execScript) { | 63 if (this.execScript) { |
64 execScript(code); | 64 execScript(code); |
65 } else { | 65 } else { |
66 this.eval(code); | 66 this.eval(code); |
67 } | 67 } |
68 // Avoid issues if $$$result is not defined by | 68 // Avoid issues if $$$result is not defined by |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 function TestConflict(def0, def1) { | 106 function TestConflict(def0, def1) { |
107 // No eval. | 107 // No eval. |
108 TestAll("TypeError", def0 +'; ' + def1); | 108 TestAll("TypeError", def0 +'; ' + def1); |
109 // Eval everything. | 109 // Eval everything. |
110 TestAll("TypeError", 'eval("' + def0 + '; ' + def1 + '")'); | 110 TestAll("TypeError", 'eval("' + def0 + '; ' + def1 + '")'); |
111 // Eval first definition. | 111 // Eval first definition. |
112 TestAll("TypeError", 'eval("' + def0 +'"); ' + def1); | 112 TestAll("TypeError", 'eval("' + def0 +'"); ' + def1); |
113 // Eval second definition. | 113 // Eval second definition. |
114 TestAll("TypeError", def0 + '; eval("' + def1 + '")'); | 114 TestAll("TypeError", def0 + '; eval("' + def1 + '")'); |
115 // Eval both definitions separately. | 115 // Eval both definitions separately. |
116 TestAll("TypeError", 'eval("' + def0 +'"); eval("' + def1 + '")'); | 116 TestAll("TypeError", 'eval("' + def0 +'"); eval("' + def1 + '")'); |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 // Test conflicting definitions. | 120 // Test conflicting definitions. |
121 TestConflict("const x", "var x"); | 121 TestConflict("const x", "var x"); |
122 TestConflict("const x = 0", "var x"); | 122 TestConflict("const x = 0", "var x"); |
123 TestConflict("const x", "var x = 0"); | 123 TestConflict("const x", "var x = 0"); |
124 TestConflict("const x = 0", "var x = 0"); | 124 TestConflict("const x = 0", "var x = 0"); |
125 | 125 |
126 TestConflict("var x", "const x"); | 126 TestConflict("var x", "const x"); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 // Test that const inside loop behaves correctly. | 212 // Test that const inside loop behaves correctly. |
213 var loop = "for (var i = 0; i < 3; i++) { const x = i; }"; | 213 var loop = "for (var i = 0; i < 3; i++) { const x = i; }"; |
214 TestAll(0, loop, "x"); | 214 TestAll(0, loop, "x"); |
215 TestAll(0, "var a,b,c,d,e,f,g,h; " + loop, "x"); | 215 TestAll(0, "var a,b,c,d,e,f,g,h; " + loop, "x"); |
216 | 216 |
217 | 217 |
218 // Test that const inside with behaves correctly. | 218 // Test that const inside with behaves correctly. |
219 TestAll(87, "with ({x:42}) { const x = 87; }", "x"); | 219 TestAll(87, "with ({x:42}) { const x = 87; }", "x"); |
220 TestAll(undefined, "with ({x:42}) { const x; }", "x"); | 220 TestAll(undefined, "with ({x:42}) { const x; }", "x"); |
OLD | NEW |