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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 v8::Handle<v8::Script> script = Compile( | 355 v8::Handle<v8::Script> script = Compile( |
356 "function createMyObj() {\n" | 356 "function createMyObj() {\n" |
357 " var obj = {};\n" | 357 " var obj = {};\n" |
358 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" | 358 " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" |
359 " return obj;\n" | 359 " return obj;\n" |
360 "}"); | 360 "}"); |
361 // Can't infer the function name statically. | 361 // Can't infer the function name statically. |
362 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); | 362 CheckFunctionName(script, "return 1", "obj.(anonymous function)"); |
363 } | 363 } |
| 364 |
| 365 |
| 366 TEST(GlobalAssignmentAndCall) { |
| 367 InitializeVM(); |
| 368 v8::HandleScope scope; |
| 369 |
| 370 v8::Handle<v8::Script> script = Compile( |
| 371 "var Foo = function() {\n" |
| 372 " return 1;\n" |
| 373 "}();\n" |
| 374 "var Baz = Bar = function() {\n" |
| 375 " return 2;\n" |
| 376 "}"); |
| 377 // The inferred name is empty, because this is an assignment of a result. |
| 378 CheckFunctionName(script, "return 1", ""); |
| 379 // See MultipleAssignments test. |
| 380 CheckFunctionName(script, "return 2", "Bar"); |
| 381 } |
| 382 |
| 383 |
| 384 TEST(AssignmentAndCall) { |
| 385 InitializeVM(); |
| 386 v8::HandleScope scope; |
| 387 |
| 388 v8::Handle<v8::Script> script = Compile( |
| 389 "(function Enclosing() {\n" |
| 390 " var Foo;\n" |
| 391 " Foo = function() {\n" |
| 392 " return 1;\n" |
| 393 " }();\n" |
| 394 " var Baz = Bar = function() {\n" |
| 395 " return 2;\n" |
| 396 " }\n" |
| 397 "})();"); |
| 398 // The inferred name is empty, because this is an assignment of a result. |
| 399 CheckFunctionName(script, "return 1", ""); |
| 400 // See MultipleAssignments test. |
| 401 CheckFunctionName(script, "return 2", "Enclosing.Bar"); |
| 402 } |
OLD | NEW |