Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: test/cctest/test-func-name-inference.cc

Issue 83343002: Remove usage of deprecated APIs from cctests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-deoptimization.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 SharedFunctionInfo::cast(shared_func_info_ptr)); 87 SharedFunctionInfo::cast(shared_func_info_ptr));
88 88
89 // Verify inferred function name. 89 // Verify inferred function name.
90 SmartArrayPointer<char> inferred_name = 90 SmartArrayPointer<char> inferred_name =
91 shared_func_info->inferred_name()->ToCString(); 91 shared_func_info->inferred_name()->ToCString();
92 CHECK_EQ(ref_inferred_name, *inferred_name); 92 CHECK_EQ(ref_inferred_name, *inferred_name);
93 #endif // ENABLE_DEBUGGER_SUPPORT 93 #endif // ENABLE_DEBUGGER_SUPPORT
94 } 94 }
95 95
96 96
97 static v8::Handle<v8::Script> Compile(const char* src) { 97 static v8::Handle<v8::Script> Compile(v8::Isolate* isolate, const char* src) {
98 return v8::Script::Compile(v8::String::New(src)); 98 return v8::Script::Compile(v8::String::NewFromUtf8(isolate, src));
99 } 99 }
100 100
101 101
102 TEST(GlobalProperty) { 102 TEST(GlobalProperty) {
103 CcTest::InitializeVM(); 103 CcTest::InitializeVM();
104 v8::HandleScope scope(CcTest::isolate()); 104 v8::HandleScope scope(CcTest::isolate());
105 105
106 v8::Handle<v8::Script> script = Compile( 106 v8::Handle<v8::Script> script = Compile(
107 CcTest::isolate(),
107 "fun1 = function() { return 1; }\n" 108 "fun1 = function() { return 1; }\n"
108 "fun2 = function() { return 2; }\n"); 109 "fun2 = function() { return 2; }\n");
109 CheckFunctionName(script, "return 1", "fun1"); 110 CheckFunctionName(script, "return 1", "fun1");
110 CheckFunctionName(script, "return 2", "fun2"); 111 CheckFunctionName(script, "return 2", "fun2");
111 } 112 }
112 113
113 114
114 TEST(GlobalVar) { 115 TEST(GlobalVar) {
115 CcTest::InitializeVM(); 116 CcTest::InitializeVM();
116 v8::HandleScope scope(CcTest::isolate()); 117 v8::HandleScope scope(CcTest::isolate());
117 118
118 v8::Handle<v8::Script> script = Compile( 119 v8::Handle<v8::Script> script = Compile(
120 CcTest::isolate(),
119 "var fun1 = function() { return 1; }\n" 121 "var fun1 = function() { return 1; }\n"
120 "var fun2 = function() { return 2; }\n"); 122 "var fun2 = function() { return 2; }\n");
121 CheckFunctionName(script, "return 1", "fun1"); 123 CheckFunctionName(script, "return 1", "fun1");
122 CheckFunctionName(script, "return 2", "fun2"); 124 CheckFunctionName(script, "return 2", "fun2");
123 } 125 }
124 126
125 127
126 TEST(LocalVar) { 128 TEST(LocalVar) {
127 CcTest::InitializeVM(); 129 CcTest::InitializeVM();
128 v8::HandleScope scope(CcTest::isolate()); 130 v8::HandleScope scope(CcTest::isolate());
129 131
130 v8::Handle<v8::Script> script = Compile( 132 v8::Handle<v8::Script> script = Compile(
133 CcTest::isolate(),
131 "function outer() {\n" 134 "function outer() {\n"
132 " var fun1 = function() { return 1; }\n" 135 " var fun1 = function() { return 1; }\n"
133 " var fun2 = function() { return 2; }\n" 136 " var fun2 = function() { return 2; }\n"
134 "}"); 137 "}");
135 CheckFunctionName(script, "return 1", "fun1"); 138 CheckFunctionName(script, "return 1", "fun1");
136 CheckFunctionName(script, "return 2", "fun2"); 139 CheckFunctionName(script, "return 2", "fun2");
137 } 140 }
138 141
139 142
140 TEST(InConstructor) { 143 TEST(InConstructor) {
141 CcTest::InitializeVM(); 144 CcTest::InitializeVM();
142 v8::HandleScope scope(CcTest::isolate()); 145 v8::HandleScope scope(CcTest::isolate());
143 146
144 v8::Handle<v8::Script> script = Compile( 147 v8::Handle<v8::Script> script = Compile(
148 CcTest::isolate(),
145 "function MyClass() {\n" 149 "function MyClass() {\n"
146 " this.method1 = function() { return 1; }\n" 150 " this.method1 = function() { return 1; }\n"
147 " this.method2 = function() { return 2; }\n" 151 " this.method2 = function() { return 2; }\n"
148 "}"); 152 "}");
149 CheckFunctionName(script, "return 1", "MyClass.method1"); 153 CheckFunctionName(script, "return 1", "MyClass.method1");
150 CheckFunctionName(script, "return 2", "MyClass.method2"); 154 CheckFunctionName(script, "return 2", "MyClass.method2");
151 } 155 }
152 156
153 157
154 TEST(Factory) { 158 TEST(Factory) {
155 CcTest::InitializeVM(); 159 CcTest::InitializeVM();
156 v8::HandleScope scope(CcTest::isolate()); 160 v8::HandleScope scope(CcTest::isolate());
157 161
158 v8::Handle<v8::Script> script = Compile( 162 v8::Handle<v8::Script> script = Compile(
163 CcTest::isolate(),
159 "function createMyObj() {\n" 164 "function createMyObj() {\n"
160 " var obj = {};\n" 165 " var obj = {};\n"
161 " obj.method1 = function() { return 1; }\n" 166 " obj.method1 = function() { return 1; }\n"
162 " obj.method2 = function() { return 2; }\n" 167 " obj.method2 = function() { return 2; }\n"
163 " return obj;\n" 168 " return obj;\n"
164 "}"); 169 "}");
165 CheckFunctionName(script, "return 1", "obj.method1"); 170 CheckFunctionName(script, "return 1", "obj.method1");
166 CheckFunctionName(script, "return 2", "obj.method2"); 171 CheckFunctionName(script, "return 2", "obj.method2");
167 } 172 }
168 173
169 174
170 TEST(Static) { 175 TEST(Static) {
171 CcTest::InitializeVM(); 176 CcTest::InitializeVM();
172 v8::HandleScope scope(CcTest::isolate()); 177 v8::HandleScope scope(CcTest::isolate());
173 178
174 v8::Handle<v8::Script> script = Compile( 179 v8::Handle<v8::Script> script = Compile(
180 CcTest::isolate(),
175 "function MyClass() {}\n" 181 "function MyClass() {}\n"
176 "MyClass.static1 = function() { return 1; }\n" 182 "MyClass.static1 = function() { return 1; }\n"
177 "MyClass.static2 = function() { return 2; }\n" 183 "MyClass.static2 = function() { return 2; }\n"
178 "MyClass.MyInnerClass = {}\n" 184 "MyClass.MyInnerClass = {}\n"
179 "MyClass.MyInnerClass.static3 = function() { return 3; }\n" 185 "MyClass.MyInnerClass.static3 = function() { return 3; }\n"
180 "MyClass.MyInnerClass.static4 = function() { return 4; }"); 186 "MyClass.MyInnerClass.static4 = function() { return 4; }");
181 CheckFunctionName(script, "return 1", "MyClass.static1"); 187 CheckFunctionName(script, "return 1", "MyClass.static1");
182 CheckFunctionName(script, "return 2", "MyClass.static2"); 188 CheckFunctionName(script, "return 2", "MyClass.static2");
183 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3"); 189 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3");
184 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4"); 190 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4");
185 } 191 }
186 192
187 193
188 TEST(Prototype) { 194 TEST(Prototype) {
189 CcTest::InitializeVM(); 195 CcTest::InitializeVM();
190 v8::HandleScope scope(CcTest::isolate()); 196 v8::HandleScope scope(CcTest::isolate());
191 197
192 v8::Handle<v8::Script> script = Compile( 198 v8::Handle<v8::Script> script = Compile(
199 CcTest::isolate(),
193 "function MyClass() {}\n" 200 "function MyClass() {}\n"
194 "MyClass.prototype.method1 = function() { return 1; }\n" 201 "MyClass.prototype.method1 = function() { return 1; }\n"
195 "MyClass.prototype.method2 = function() { return 2; }\n" 202 "MyClass.prototype.method2 = function() { return 2; }\n"
196 "MyClass.MyInnerClass = function() {}\n" 203 "MyClass.MyInnerClass = function() {}\n"
197 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n" 204 "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n"
198 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }"); 205 "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }");
199 CheckFunctionName(script, "return 1", "MyClass.method1"); 206 CheckFunctionName(script, "return 1", "MyClass.method1");
200 CheckFunctionName(script, "return 2", "MyClass.method2"); 207 CheckFunctionName(script, "return 2", "MyClass.method2");
201 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3"); 208 CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3");
202 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4"); 209 CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4");
203 } 210 }
204 211
205 212
206 TEST(ObjectLiteral) { 213 TEST(ObjectLiteral) {
207 CcTest::InitializeVM(); 214 CcTest::InitializeVM();
208 v8::HandleScope scope(CcTest::isolate()); 215 v8::HandleScope scope(CcTest::isolate());
209 216
210 v8::Handle<v8::Script> script = Compile( 217 v8::Handle<v8::Script> script = Compile(
218 CcTest::isolate(),
211 "function MyClass() {}\n" 219 "function MyClass() {}\n"
212 "MyClass.prototype = {\n" 220 "MyClass.prototype = {\n"
213 " method1: function() { return 1; },\n" 221 " method1: function() { return 1; },\n"
214 " method2: function() { return 2; } }"); 222 " method2: function() { return 2; } }");
215 CheckFunctionName(script, "return 1", "MyClass.method1"); 223 CheckFunctionName(script, "return 1", "MyClass.method1");
216 CheckFunctionName(script, "return 2", "MyClass.method2"); 224 CheckFunctionName(script, "return 2", "MyClass.method2");
217 } 225 }
218 226
219 227
220 TEST(AsParameter) { 228 TEST(AsParameter) {
221 CcTest::InitializeVM(); 229 CcTest::InitializeVM();
222 v8::HandleScope scope(CcTest::isolate()); 230 v8::HandleScope scope(CcTest::isolate());
223 231
224 v8::Handle<v8::Script> script = Compile( 232 v8::Handle<v8::Script> script = Compile(
233 CcTest::isolate(),
225 "function f1(a) { return a(); }\n" 234 "function f1(a) { return a(); }\n"
226 "function f2(a, b) { return a() + b(); }\n" 235 "function f2(a, b) { return a() + b(); }\n"
227 "var result1 = f1(function() { return 1; })\n" 236 "var result1 = f1(function() { return 1; })\n"
228 "var result2 = f2(function() { return 2; }, function() { return 3; })"); 237 "var result2 = f2(function() { return 2; }, function() { return 3; })");
229 // Can't infer names here. 238 // Can't infer names here.
230 CheckFunctionName(script, "return 1", ""); 239 CheckFunctionName(script, "return 1", "");
231 CheckFunctionName(script, "return 2", ""); 240 CheckFunctionName(script, "return 2", "");
232 CheckFunctionName(script, "return 3", ""); 241 CheckFunctionName(script, "return 3", "");
233 } 242 }
234 243
235 244
236 TEST(MultipleFuncsConditional) { 245 TEST(MultipleFuncsConditional) {
237 CcTest::InitializeVM(); 246 CcTest::InitializeVM();
238 v8::HandleScope scope(CcTest::isolate()); 247 v8::HandleScope scope(CcTest::isolate());
239 248
240 v8::Handle<v8::Script> script = Compile( 249 v8::Handle<v8::Script> script = Compile(
250 CcTest::isolate(),
241 "fun1 = 0 ?\n" 251 "fun1 = 0 ?\n"
242 " function() { return 1; } :\n" 252 " function() { return 1; } :\n"
243 " function() { return 2; }"); 253 " function() { return 2; }");
244 CheckFunctionName(script, "return 1", "fun1"); 254 CheckFunctionName(script, "return 1", "fun1");
245 CheckFunctionName(script, "return 2", "fun1"); 255 CheckFunctionName(script, "return 2", "fun1");
246 } 256 }
247 257
248 258
249 TEST(MultipleFuncsInLiteral) { 259 TEST(MultipleFuncsInLiteral) {
250 CcTest::InitializeVM(); 260 CcTest::InitializeVM();
251 v8::HandleScope scope(CcTest::isolate()); 261 v8::HandleScope scope(CcTest::isolate());
252 262
253 v8::Handle<v8::Script> script = Compile( 263 v8::Handle<v8::Script> script = Compile(
264 CcTest::isolate(),
254 "function MyClass() {}\n" 265 "function MyClass() {}\n"
255 "MyClass.prototype = {\n" 266 "MyClass.prototype = {\n"
256 " method1: 0 ? function() { return 1; } :\n" 267 " method1: 0 ? function() { return 1; } :\n"
257 " function() { return 2; } }"); 268 " function() { return 2; } }");
258 CheckFunctionName(script, "return 1", "MyClass.method1"); 269 CheckFunctionName(script, "return 1", "MyClass.method1");
259 CheckFunctionName(script, "return 2", "MyClass.method1"); 270 CheckFunctionName(script, "return 2", "MyClass.method1");
260 } 271 }
261 272
262 273
263 TEST(AnonymousInAnonymousClosure1) { 274 TEST(AnonymousInAnonymousClosure1) {
264 CcTest::InitializeVM(); 275 CcTest::InitializeVM();
265 v8::HandleScope scope(CcTest::isolate()); 276 v8::HandleScope scope(CcTest::isolate());
266 277
267 v8::Handle<v8::Script> script = Compile( 278 v8::Handle<v8::Script> script = Compile(
279 CcTest::isolate(),
268 "(function() {\n" 280 "(function() {\n"
269 " (function() {\n" 281 " (function() {\n"
270 " var a = 1;\n" 282 " var a = 1;\n"
271 " return;\n" 283 " return;\n"
272 " })();\n" 284 " })();\n"
273 " var b = function() {\n" 285 " var b = function() {\n"
274 " var c = 1;\n" 286 " var c = 1;\n"
275 " return;\n" 287 " return;\n"
276 " };\n" 288 " };\n"
277 "})();"); 289 "})();");
278 CheckFunctionName(script, "return", ""); 290 CheckFunctionName(script, "return", "");
279 } 291 }
280 292
281 293
282 TEST(AnonymousInAnonymousClosure2) { 294 TEST(AnonymousInAnonymousClosure2) {
283 CcTest::InitializeVM(); 295 CcTest::InitializeVM();
284 v8::HandleScope scope(CcTest::isolate()); 296 v8::HandleScope scope(CcTest::isolate());
285 297
286 v8::Handle<v8::Script> script = Compile( 298 v8::Handle<v8::Script> script = Compile(
299 CcTest::isolate(),
287 "(function() {\n" 300 "(function() {\n"
288 " (function() {\n" 301 " (function() {\n"
289 " var a = 1;\n" 302 " var a = 1;\n"
290 " return;\n" 303 " return;\n"
291 " })();\n" 304 " })();\n"
292 " var c = 1;\n" 305 " var c = 1;\n"
293 "})();"); 306 "})();");
294 CheckFunctionName(script, "return", ""); 307 CheckFunctionName(script, "return", "");
295 } 308 }
296 309
297 310
298 TEST(NamedInAnonymousClosure) { 311 TEST(NamedInAnonymousClosure) {
299 CcTest::InitializeVM(); 312 CcTest::InitializeVM();
300 v8::HandleScope scope(CcTest::isolate()); 313 v8::HandleScope scope(CcTest::isolate());
301 314
302 v8::Handle<v8::Script> script = Compile( 315 v8::Handle<v8::Script> script = Compile(
316 CcTest::isolate(),
303 "var foo = function() {\n" 317 "var foo = function() {\n"
304 " (function named() {\n" 318 " (function named() {\n"
305 " var a = 1;\n" 319 " var a = 1;\n"
306 " })();\n" 320 " })();\n"
307 " var c = 1;\n" 321 " var c = 1;\n"
308 " return;\n" 322 " return;\n"
309 "};"); 323 "};");
310 CheckFunctionName(script, "return", "foo"); 324 CheckFunctionName(script, "return", "foo");
311 } 325 }
312 326
313 327
314 // See http://code.google.com/p/v8/issues/detail?id=380 328 // See http://code.google.com/p/v8/issues/detail?id=380
315 TEST(Issue380) { 329 TEST(Issue380) {
316 CcTest::InitializeVM(); 330 CcTest::InitializeVM();
317 v8::HandleScope scope(CcTest::isolate()); 331 v8::HandleScope scope(CcTest::isolate());
318 332
319 v8::Handle<v8::Script> script = Compile( 333 v8::Handle<v8::Script> script = Compile(
334 CcTest::isolate(),
320 "function a() {\n" 335 "function a() {\n"
321 "var result = function(p,a,c,k,e,d)" 336 "var result = function(p,a,c,k,e,d)"
322 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n" 337 "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
323 "}"); 338 "}");
324 CheckFunctionName(script, "return p", ""); 339 CheckFunctionName(script, "return p", "");
325 } 340 }
326 341
327 342
328 TEST(MultipleAssignments) { 343 TEST(MultipleAssignments) {
329 CcTest::InitializeVM(); 344 CcTest::InitializeVM();
330 v8::HandleScope scope(CcTest::isolate()); 345 v8::HandleScope scope(CcTest::isolate());
331 346
332 v8::Handle<v8::Script> script = Compile( 347 v8::Handle<v8::Script> script = Compile(
348 CcTest::isolate(),
333 "var fun1 = fun2 = function () { return 1; }\n" 349 "var fun1 = fun2 = function () { return 1; }\n"
334 "var bar1 = bar2 = bar3 = function () { return 2; }\n" 350 "var bar1 = bar2 = bar3 = function () { return 2; }\n"
335 "foo1 = foo2 = function () { return 3; }\n" 351 "foo1 = foo2 = function () { return 3; }\n"
336 "baz1 = baz2 = baz3 = function () { return 4; }"); 352 "baz1 = baz2 = baz3 = function () { return 4; }");
337 CheckFunctionName(script, "return 1", "fun2"); 353 CheckFunctionName(script, "return 1", "fun2");
338 CheckFunctionName(script, "return 2", "bar3"); 354 CheckFunctionName(script, "return 2", "bar3");
339 CheckFunctionName(script, "return 3", "foo2"); 355 CheckFunctionName(script, "return 3", "foo2");
340 CheckFunctionName(script, "return 4", "baz3"); 356 CheckFunctionName(script, "return 4", "baz3");
341 } 357 }
342 358
343 359
344 TEST(AsConstructorParameter) { 360 TEST(AsConstructorParameter) {
345 CcTest::InitializeVM(); 361 CcTest::InitializeVM();
346 v8::HandleScope scope(CcTest::isolate()); 362 v8::HandleScope scope(CcTest::isolate());
347 363
348 v8::Handle<v8::Script> script = Compile( 364 v8::Handle<v8::Script> script = Compile(
365 CcTest::isolate(),
349 "function Foo() {}\n" 366 "function Foo() {}\n"
350 "var foo = new Foo(function() { return 1; })\n" 367 "var foo = new Foo(function() { return 1; })\n"
351 "var bar = new Foo(function() { return 2; }, function() { return 3; })"); 368 "var bar = new Foo(function() { return 2; }, function() { return 3; })");
352 CheckFunctionName(script, "return 1", ""); 369 CheckFunctionName(script, "return 1", "");
353 CheckFunctionName(script, "return 2", ""); 370 CheckFunctionName(script, "return 2", "");
354 CheckFunctionName(script, "return 3", ""); 371 CheckFunctionName(script, "return 3", "");
355 } 372 }
356 373
357 374
358 TEST(FactoryHashmap) { 375 TEST(FactoryHashmap) {
359 CcTest::InitializeVM(); 376 CcTest::InitializeVM();
360 v8::HandleScope scope(CcTest::isolate()); 377 v8::HandleScope scope(CcTest::isolate());
361 378
362 v8::Handle<v8::Script> script = Compile( 379 v8::Handle<v8::Script> script = Compile(
380 CcTest::isolate(),
363 "function createMyObj() {\n" 381 "function createMyObj() {\n"
364 " var obj = {};\n" 382 " var obj = {};\n"
365 " obj[\"method1\"] = function() { return 1; }\n" 383 " obj[\"method1\"] = function() { return 1; }\n"
366 " obj[\"method2\"] = function() { return 2; }\n" 384 " obj[\"method2\"] = function() { return 2; }\n"
367 " return obj;\n" 385 " return obj;\n"
368 "}"); 386 "}");
369 CheckFunctionName(script, "return 1", "obj.method1"); 387 CheckFunctionName(script, "return 1", "obj.method1");
370 CheckFunctionName(script, "return 2", "obj.method2"); 388 CheckFunctionName(script, "return 2", "obj.method2");
371 } 389 }
372 390
373 391
374 TEST(FactoryHashmapVariable) { 392 TEST(FactoryHashmapVariable) {
375 CcTest::InitializeVM(); 393 CcTest::InitializeVM();
376 v8::HandleScope scope(CcTest::isolate()); 394 v8::HandleScope scope(CcTest::isolate());
377 395
378 v8::Handle<v8::Script> script = Compile( 396 v8::Handle<v8::Script> script = Compile(
397 CcTest::isolate(),
379 "function createMyObj() {\n" 398 "function createMyObj() {\n"
380 " var obj = {};\n" 399 " var obj = {};\n"
381 " var methodName = \"method1\";\n" 400 " var methodName = \"method1\";\n"
382 " obj[methodName] = function() { return 1; }\n" 401 " obj[methodName] = function() { return 1; }\n"
383 " methodName = \"method2\";\n" 402 " methodName = \"method2\";\n"
384 " obj[methodName] = function() { return 2; }\n" 403 " obj[methodName] = function() { return 2; }\n"
385 " return obj;\n" 404 " return obj;\n"
386 "}"); 405 "}");
387 // Can't infer function names statically. 406 // Can't infer function names statically.
388 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); 407 CheckFunctionName(script, "return 1", "obj.(anonymous function)");
389 CheckFunctionName(script, "return 2", "obj.(anonymous function)"); 408 CheckFunctionName(script, "return 2", "obj.(anonymous function)");
390 } 409 }
391 410
392 411
393 TEST(FactoryHashmapConditional) { 412 TEST(FactoryHashmapConditional) {
394 CcTest::InitializeVM(); 413 CcTest::InitializeVM();
395 v8::HandleScope scope(CcTest::isolate()); 414 v8::HandleScope scope(CcTest::isolate());
396 415
397 v8::Handle<v8::Script> script = Compile( 416 v8::Handle<v8::Script> script = Compile(
417 CcTest::isolate(),
398 "function createMyObj() {\n" 418 "function createMyObj() {\n"
399 " var obj = {};\n" 419 " var obj = {};\n"
400 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" 420 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n"
401 " return obj;\n" 421 " return obj;\n"
402 "}"); 422 "}");
403 // Can't infer the function name statically. 423 // Can't infer the function name statically.
404 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); 424 CheckFunctionName(script, "return 1", "obj.(anonymous function)");
405 } 425 }
406 426
407 427
408 TEST(GlobalAssignmentAndCall) { 428 TEST(GlobalAssignmentAndCall) {
409 CcTest::InitializeVM(); 429 CcTest::InitializeVM();
410 v8::HandleScope scope(CcTest::isolate()); 430 v8::HandleScope scope(CcTest::isolate());
411 431
412 v8::Handle<v8::Script> script = Compile( 432 v8::Handle<v8::Script> script = Compile(
433 CcTest::isolate(),
413 "var Foo = function() {\n" 434 "var Foo = function() {\n"
414 " return 1;\n" 435 " return 1;\n"
415 "}();\n" 436 "}();\n"
416 "var Baz = Bar = function() {\n" 437 "var Baz = Bar = function() {\n"
417 " return 2;\n" 438 " return 2;\n"
418 "}"); 439 "}");
419 // The inferred name is empty, because this is an assignment of a result. 440 // The inferred name is empty, because this is an assignment of a result.
420 CheckFunctionName(script, "return 1", ""); 441 CheckFunctionName(script, "return 1", "");
421 // See MultipleAssignments test. 442 // See MultipleAssignments test.
422 CheckFunctionName(script, "return 2", "Bar"); 443 CheckFunctionName(script, "return 2", "Bar");
423 } 444 }
424 445
425 446
426 TEST(AssignmentAndCall) { 447 TEST(AssignmentAndCall) {
427 CcTest::InitializeVM(); 448 CcTest::InitializeVM();
428 v8::HandleScope scope(CcTest::isolate()); 449 v8::HandleScope scope(CcTest::isolate());
429 450
430 v8::Handle<v8::Script> script = Compile( 451 v8::Handle<v8::Script> script = Compile(
452 CcTest::isolate(),
431 "(function Enclosing() {\n" 453 "(function Enclosing() {\n"
432 " var Foo;\n" 454 " var Foo;\n"
433 " Foo = function() {\n" 455 " Foo = function() {\n"
434 " return 1;\n" 456 " return 1;\n"
435 " }();\n" 457 " }();\n"
436 " var Baz = Bar = function() {\n" 458 " var Baz = Bar = function() {\n"
437 " return 2;\n" 459 " return 2;\n"
438 " }\n" 460 " }\n"
439 "})();"); 461 "})();");
440 // The inferred name is empty, because this is an assignment of a result. 462 // The inferred name is empty, because this is an assignment of a result.
441 CheckFunctionName(script, "return 1", ""); 463 CheckFunctionName(script, "return 1", "");
442 // See MultipleAssignments test. 464 // See MultipleAssignments test.
443 // TODO(2276): Lazy compiling the enclosing outer closure would yield 465 // TODO(2276): Lazy compiling the enclosing outer closure would yield
444 // in "Enclosing.Bar" being the inferred name here. 466 // in "Enclosing.Bar" being the inferred name here.
445 CheckFunctionName(script, "return 2", "Bar"); 467 CheckFunctionName(script, "return 2", "Bar");
446 } 468 }
447 469
448 470
449 TEST(MethodAssignmentInAnonymousFunctionCall) { 471 TEST(MethodAssignmentInAnonymousFunctionCall) {
450 CcTest::InitializeVM(); 472 CcTest::InitializeVM();
451 v8::HandleScope scope(CcTest::isolate()); 473 v8::HandleScope scope(CcTest::isolate());
452 474
453 v8::Handle<v8::Script> script = Compile( 475 v8::Handle<v8::Script> script = Compile(
476 CcTest::isolate(),
454 "(function () {\n" 477 "(function () {\n"
455 " var EventSource = function () { };\n" 478 " var EventSource = function () { };\n"
456 " EventSource.prototype.addListener = function () {\n" 479 " EventSource.prototype.addListener = function () {\n"
457 " return 2012;\n" 480 " return 2012;\n"
458 " };\n" 481 " };\n"
459 " this.PublicEventSource = EventSource;\n" 482 " this.PublicEventSource = EventSource;\n"
460 "})();"); 483 "})();");
461 CheckFunctionName(script, "return 2012", "EventSource.addListener"); 484 CheckFunctionName(script, "return 2012", "EventSource.addListener");
462 } 485 }
463 486
464 487
465 TEST(ReturnAnonymousFunction) { 488 TEST(ReturnAnonymousFunction) {
466 CcTest::InitializeVM(); 489 CcTest::InitializeVM();
467 v8::HandleScope scope(CcTest::isolate()); 490 v8::HandleScope scope(CcTest::isolate());
468 491
469 v8::Handle<v8::Script> script = Compile( 492 v8::Handle<v8::Script> script = Compile(
493 CcTest::isolate(),
470 "(function() {\n" 494 "(function() {\n"
471 " function wrapCode() {\n" 495 " function wrapCode() {\n"
472 " return function () {\n" 496 " return function () {\n"
473 " return 2012;\n" 497 " return 2012;\n"
474 " };\n" 498 " };\n"
475 " };\n" 499 " };\n"
476 " var foo = 10;\n" 500 " var foo = 10;\n"
477 " function f() {\n" 501 " function f() {\n"
478 " return wrapCode();\n" 502 " return wrapCode();\n"
479 " }\n" 503 " }\n"
480 " this.ref = f;\n" 504 " this.ref = f;\n"
481 "})()"); 505 "})()");
482 script->Run(); 506 script->Run();
483 CheckFunctionName(script, "return 2012", ""); 507 CheckFunctionName(script, "return 2012", "");
484 } 508 }
OLDNEW
« no previous file with comments | « test/cctest/test-deoptimization.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698