OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 "true", | 134 "true", |
135 "try", | 135 "try", |
136 "typeof", | 136 "typeof", |
137 "var", | 137 "var", |
138 "void", | 138 "void", |
139 "while", | 139 "while", |
140 "with", | 140 "with", |
141 ]; | 141 ]; |
142 | 142 |
143 function testKeywordProperty(keyword) { | 143 function testKeywordProperty(keyword) { |
| 144 var exception = false; |
144 try { | 145 try { |
145 // Sanity check that what we get is a keyword. | 146 // Sanity check that what we get is a keyword. |
146 eval("var " + keyword + " = 42;"); | 147 eval("var " + keyword + " = 42;"); |
147 assertUnreachable("Not a keyword: " + keyword); | 148 } catch (e) { |
148 } catch (e) { } | 149 exception = true; |
| 150 } |
| 151 assertTrue(exception); |
149 | 152 |
150 // Simple property, read and write. | 153 // Simple property, read and write. |
151 var x = eval("({" + keyword + ": 42})"); | 154 var x = eval("({" + keyword + ": 42})"); |
152 assertEquals(42, x[keyword]); | 155 assertEquals(42, x[keyword]); |
153 assertEquals(42, eval("x." + keyword)); | 156 assertEquals(42, eval("x." + keyword)); |
154 eval("x." + keyword + " = 37"); | 157 eval("x." + keyword + " = 37"); |
155 assertEquals(37, x[keyword]); | 158 assertEquals(37, x[keyword]); |
156 assertEquals(37, eval("x." + keyword)); | 159 assertEquals(37, eval("x." + keyword)); |
157 | 160 |
158 // Getter/setter property, read and write. | 161 // Getter/setter property, read and write. |
(...skipping 21 matching lines...) Expand all Loading... |
180 // Function property, constructed. | 183 // Function property, constructed. |
181 function construct() { this.constructed = true; } | 184 function construct() { this.constructed = true; } |
182 var v = eval("({" + keyword + ": construct})"); | 185 var v = eval("({" + keyword + ": construct})"); |
183 var vo = eval("new v." + keyword + "()"); | 186 var vo = eval("new v." + keyword + "()"); |
184 assertTrue(vo instanceof construct); | 187 assertTrue(vo instanceof construct); |
185 assertTrue(vo.constructed); | 188 assertTrue(vo.constructed); |
186 } | 189 } |
187 | 190 |
188 for (var i = 0; i < keywords.length; i++) { | 191 for (var i = 0; i < keywords.length; i++) { |
189 testKeywordProperty(keywords[i]); | 192 testKeywordProperty(keywords[i]); |
190 } | 193 } |
OLD | NEW |