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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 " }();\n" | 393 " }();\n" |
394 " var Baz = Bar = function() {\n" | 394 " var Baz = Bar = function() {\n" |
395 " return 2;\n" | 395 " return 2;\n" |
396 " }\n" | 396 " }\n" |
397 "})();"); | 397 "})();"); |
398 // The inferred name is empty, because this is an assignment of a result. | 398 // The inferred name is empty, because this is an assignment of a result. |
399 CheckFunctionName(script, "return 1", ""); | 399 CheckFunctionName(script, "return 1", ""); |
400 // See MultipleAssignments test. | 400 // See MultipleAssignments test. |
401 CheckFunctionName(script, "return 2", "Enclosing.Bar"); | 401 CheckFunctionName(script, "return 2", "Enclosing.Bar"); |
402 } | 402 } |
| 403 |
| 404 |
| 405 TEST(MethodAssignmentInAnonymousFunctionCall) { |
| 406 InitializeVM(); |
| 407 v8::HandleScope scope; |
| 408 |
| 409 v8::Handle<v8::Script> script = Compile( |
| 410 "(function () {\n" |
| 411 " var EventSource = function () { };\n" |
| 412 " EventSource.prototype.addListener = function () {\n" |
| 413 " return 2012;\n" |
| 414 " };\n" |
| 415 " this.PublicEventSource = EventSource;\n" |
| 416 "})();"); |
| 417 CheckFunctionName(script, "return 2012", "EventSource.addListener"); |
| 418 } |
| 419 |
| 420 |
| 421 TEST(ReturnAnonymousFunction) { |
| 422 InitializeVM(); |
| 423 v8::HandleScope scope; |
| 424 |
| 425 v8::Handle<v8::Script> script = Compile( |
| 426 "(function() {\n" |
| 427 " function wrapCode() {\n" |
| 428 " return function () {\n" |
| 429 " return 2012;\n" |
| 430 " };\n" |
| 431 " };\n" |
| 432 " var foo = 10;\n" |
| 433 " function f() {\n" |
| 434 " return wrapCode();\n" |
| 435 " }\n" |
| 436 " this.ref = f;\n" |
| 437 "})()"); |
| 438 script->Run(); |
| 439 CheckFunctionName(script, "return 2012", ""); |
| 440 } |
OLD | NEW |