LCOV - code coverage report
Current view: top level - test/cctest - test-func-name-inference.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 211 223 94.6 %
Date: 2019-04-17 Functions: 31 33 93.9 %

          Line data    Source code
       1             : // Copyright 2011 the V8 project authors. All rights reserved.
       2             : // Redistribution and use in source and binary forms, with or without
       3             : // modification, are permitted provided that the following conditions are
       4             : // met:
       5             : //
       6             : //     * Redistributions of source code must retain the above copyright
       7             : //       notice, this list of conditions and the following disclaimer.
       8             : //     * Redistributions in binary form must reproduce the above
       9             : //       copyright notice, this list of conditions and the following
      10             : //       disclaimer in the documentation and/or other materials provided
      11             : //       with the distribution.
      12             : //     * Neither the name of Google Inc. nor the names of its
      13             : //       contributors may be used to endorse or promote products derived
      14             : //       from this software without specific prior written permission.
      15             : //
      16             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      17             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      18             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      19             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      20             : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      21             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      22             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      26             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             : 
      28             : #include <memory>
      29             : 
      30             : #include "src/v8.h"
      31             : 
      32             : #include "src/api-inl.h"
      33             : #include "src/debug/debug.h"
      34             : #include "src/objects-inl.h"
      35             : #include "src/string-search.h"
      36             : #include "test/cctest/cctest.h"
      37             : 
      38             : 
      39             : using ::v8::internal::CStrVector;
      40             : using ::v8::internal::Factory;
      41             : using ::v8::internal::Handle;
      42             : using ::v8::internal::Heap;
      43             : using ::v8::internal::JSFunction;
      44             : using ::v8::internal::Runtime;
      45             : using ::v8::internal::SharedFunctionInfo;
      46             : using ::v8::internal::Vector;
      47             : 
      48             : 
      49         265 : static void CheckFunctionName(v8::Local<v8::Script> script,
      50             :                               const char* func_pos_src,
      51             :                               const char* ref_inferred_name) {
      52             :   i::Isolate* isolate = CcTest::i_isolate();
      53             : 
      54             :   // Get script source.
      55             :   Handle<i::Object> obj = v8::Utils::OpenHandle(*script);
      56             :   Handle<SharedFunctionInfo> shared_function;
      57         265 :   if (obj->IsSharedFunctionInfo()) {
      58             :     shared_function =
      59             :         Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj), isolate);
      60             :   } else {
      61             :     shared_function =
      62             :         Handle<SharedFunctionInfo>(JSFunction::cast(*obj)->shared(), isolate);
      63             :   }
      64             :   Handle<i::Script> i_script(i::Script::cast(shared_function->script()),
      65         530 :                              isolate);
      66         265 :   CHECK(i_script->source()->IsString());
      67             :   Handle<i::String> script_src(i::String::cast(i_script->source()), isolate);
      68             : 
      69             :   // Find the position of a given func source substring in the source.
      70             :   int func_pos;
      71             :   {
      72             :     i::DisallowHeapAllocation no_gc;
      73         265 :     Vector<const uint8_t> func_pos_str = i::OneByteVector(func_pos_src);
      74         265 :     i::String::FlatContent script_content = script_src->GetFlatContent(no_gc);
      75             :     func_pos = SearchString(isolate, script_content.ToOneByteVector(),
      76         265 :                             func_pos_str, 0);
      77             :   }
      78         265 :   CHECK_NE(0, func_pos);
      79             : 
      80             :   // Obtain SharedFunctionInfo for the function.
      81             :   Handle<SharedFunctionInfo> shared_func_info =
      82             :       Handle<SharedFunctionInfo>::cast(
      83         265 :           isolate->debug()->FindSharedFunctionInfoInScript(i_script, func_pos));
      84             : 
      85             :   // Verify inferred function name.
      86             :   std::unique_ptr<char[]> inferred_name =
      87         265 :       shared_func_info->inferred_name()->ToCString();
      88             :   i::PrintF("expected: %s, found: %s\n", ref_inferred_name,
      89         265 :             inferred_name.get());
      90         265 :   CHECK_EQ(0, strcmp(ref_inferred_name, inferred_name.get()));
      91         265 : }
      92             : 
      93             : 
      94         135 : static v8::Local<v8::Script> Compile(v8::Isolate* isolate, const char* src) {
      95         135 :   return v8::Script::Compile(
      96             :              isolate->GetCurrentContext(),
      97         135 :              v8::String::NewFromUtf8(isolate, src, v8::NewStringType::kNormal)
      98         135 :                  .ToLocalChecked())
      99         135 :       .ToLocalChecked();
     100             : }
     101             : 
     102             : 
     103       26644 : TEST(GlobalProperty) {
     104           5 :   CcTest::InitializeVM();
     105          10 :   v8::HandleScope scope(CcTest::isolate());
     106             : 
     107             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     108             :                                          "fun1 = function() { return 1; }\n"
     109           5 :                                          "fun2 = function() { return 2; }\n");
     110           5 :   CheckFunctionName(script, "return 1", "fun1");
     111           5 :   CheckFunctionName(script, "return 2", "fun2");
     112           5 : }
     113             : 
     114             : 
     115       26644 : TEST(GlobalVar) {
     116           5 :   CcTest::InitializeVM();
     117          10 :   v8::HandleScope scope(CcTest::isolate());
     118             : 
     119             :   v8::Local<v8::Script> script =
     120             :       Compile(CcTest::isolate(),
     121             :               "var fun1 = function() { return 1; }\n"
     122           5 :               "var fun2 = function() { return 2; }\n");
     123           5 :   CheckFunctionName(script, "return 1", "fun1");
     124           5 :   CheckFunctionName(script, "return 2", "fun2");
     125           5 : }
     126             : 
     127             : 
     128       26644 : TEST(LocalVar) {
     129           5 :   CcTest::InitializeVM();
     130          10 :   v8::HandleScope scope(CcTest::isolate());
     131             : 
     132             :   v8::Local<v8::Script> script =
     133             :       Compile(CcTest::isolate(),
     134             :               "function outer() {\n"
     135             :               "  var fun1 = function() { return 1; }\n"
     136             :               "  var fun2 = function() { return 2; }\n"
     137           5 :               "}");
     138           5 :   CheckFunctionName(script, "return 1", "fun1");
     139           5 :   CheckFunctionName(script, "return 2", "fun2");
     140           5 : }
     141             : 
     142       26644 : TEST(ObjectProperty) {
     143           5 :   CcTest::InitializeVM();
     144          10 :   v8::HandleScope scope(CcTest::isolate());
     145             : 
     146             :   v8::Local<v8::Script> script =
     147             :       Compile(CcTest::isolate(),
     148             :               "var obj = {\n"
     149             :               "  fun1: function() { return 1; },\n"
     150             :               "  fun2: class { constructor() { return 2; } }\n"
     151           5 :               "}");
     152           5 :   CheckFunctionName(script, "return 1", "obj.fun1");
     153           5 :   CheckFunctionName(script, "return 2", "obj.fun2");
     154           5 : }
     155             : 
     156       26644 : TEST(InConstructor) {
     157           5 :   CcTest::InitializeVM();
     158          10 :   v8::HandleScope scope(CcTest::isolate());
     159             : 
     160             :   v8::Local<v8::Script> script =
     161             :       Compile(CcTest::isolate(),
     162             :               "function MyClass() {\n"
     163             :               "  this.method1 = function() { return 1; }\n"
     164             :               "  this.method2 = function() { return 2; }\n"
     165           5 :               "}");
     166           5 :   CheckFunctionName(script, "return 1", "MyClass.method1");
     167           5 :   CheckFunctionName(script, "return 2", "MyClass.method2");
     168           5 : }
     169             : 
     170             : 
     171       26644 : TEST(Factory) {
     172           5 :   CcTest::InitializeVM();
     173          10 :   v8::HandleScope scope(CcTest::isolate());
     174             : 
     175             :   v8::Local<v8::Script> script =
     176             :       Compile(CcTest::isolate(),
     177             :               "function createMyObj() {\n"
     178             :               "  var obj = {};\n"
     179             :               "  obj.method1 = function() { return 1; }\n"
     180             :               "  obj.method2 = function() { return 2; }\n"
     181             :               "  return obj;\n"
     182           5 :               "}");
     183           5 :   CheckFunctionName(script, "return 1", "obj.method1");
     184           5 :   CheckFunctionName(script, "return 2", "obj.method2");
     185           5 : }
     186             : 
     187             : 
     188       26644 : TEST(Static) {
     189           5 :   CcTest::InitializeVM();
     190          10 :   v8::HandleScope scope(CcTest::isolate());
     191             : 
     192             :   v8::Local<v8::Script> script =
     193             :       Compile(CcTest::isolate(),
     194             :               "function MyClass() {}\n"
     195             :               "MyClass.static1 = function() { return 1; }\n"
     196             :               "MyClass.static2 = function() { return 2; }\n"
     197             :               "MyClass.MyInnerClass = {}\n"
     198             :               "MyClass.MyInnerClass.static3 = function() { return 3; }\n"
     199           5 :               "MyClass.MyInnerClass.static4 = function() { return 4; }");
     200           5 :   CheckFunctionName(script, "return 1", "MyClass.static1");
     201           5 :   CheckFunctionName(script, "return 2", "MyClass.static2");
     202           5 :   CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.static3");
     203           5 :   CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.static4");
     204           5 : }
     205             : 
     206             : 
     207       26644 : TEST(Prototype) {
     208           5 :   CcTest::InitializeVM();
     209          10 :   v8::HandleScope scope(CcTest::isolate());
     210             : 
     211             :   v8::Local<v8::Script> script = Compile(
     212             :       CcTest::isolate(),
     213             :       "function MyClass() {}\n"
     214             :       "MyClass.prototype.method1 = function() { return 1; }\n"
     215             :       "MyClass.prototype.method2 = function() { return 2; }\n"
     216             :       "MyClass.MyInnerClass = function() {}\n"
     217             :       "MyClass.MyInnerClass.prototype.method3 = function() { return 3; }\n"
     218           5 :       "MyClass.MyInnerClass.prototype.method4 = function() { return 4; }");
     219           5 :   CheckFunctionName(script, "return 1", "MyClass.method1");
     220           5 :   CheckFunctionName(script, "return 2", "MyClass.method2");
     221           5 :   CheckFunctionName(script, "return 3", "MyClass.MyInnerClass.method3");
     222           5 :   CheckFunctionName(script, "return 4", "MyClass.MyInnerClass.method4");
     223           5 : }
     224             : 
     225             : 
     226       26644 : TEST(ObjectLiteral) {
     227           5 :   CcTest::InitializeVM();
     228          10 :   v8::HandleScope scope(CcTest::isolate());
     229             : 
     230             :   v8::Local<v8::Script> script =
     231             :       Compile(CcTest::isolate(),
     232             :               "function MyClass() {}\n"
     233             :               "MyClass.prototype = {\n"
     234             :               "  method1: function() { return 1; },\n"
     235           5 :               "  method2: function() { return 2; } }");
     236           5 :   CheckFunctionName(script, "return 1", "MyClass.method1");
     237           5 :   CheckFunctionName(script, "return 2", "MyClass.method2");
     238           5 : }
     239             : 
     240             : 
     241       26639 : TEST(UpperCaseClass) {
     242           0 :   CcTest::InitializeVM();
     243           0 :   v8::HandleScope scope(CcTest::isolate());
     244             : 
     245             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     246             :                                          "'use strict';\n"
     247             :                                          "class MyClass {\n"
     248             :                                          "  constructor() {\n"
     249             :                                          "    this.value = 1;\n"
     250             :                                          "  }\n"
     251             :                                          "  method() {\n"
     252             :                                          "    this.value = 2;\n"
     253             :                                          "  }\n"
     254           0 :                                          "}");
     255           0 :   CheckFunctionName(script, "this.value = 1", "MyClass");
     256           0 :   CheckFunctionName(script, "this.value = 2", "MyClass.method");
     257           0 : }
     258             : 
     259             : 
     260       26639 : TEST(LowerCaseClass) {
     261           0 :   CcTest::InitializeVM();
     262           0 :   v8::HandleScope scope(CcTest::isolate());
     263             : 
     264             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     265             :                                          "'use strict';\n"
     266             :                                          "class myclass {\n"
     267             :                                          "  constructor() {\n"
     268             :                                          "    this.value = 1;\n"
     269             :                                          "  }\n"
     270             :                                          "  method() {\n"
     271             :                                          "    this.value = 2;\n"
     272             :                                          "  }\n"
     273           0 :                                          "}");
     274           0 :   CheckFunctionName(script, "this.value = 1", "myclass");
     275           0 :   CheckFunctionName(script, "this.value = 2", "myclass.method");
     276           0 : }
     277             : 
     278             : 
     279       26644 : TEST(AsParameter) {
     280           5 :   CcTest::InitializeVM();
     281          10 :   v8::HandleScope scope(CcTest::isolate());
     282             : 
     283             :   v8::Local<v8::Script> script = Compile(
     284             :       CcTest::isolate(),
     285             :       "function f1(a) { return a(); }\n"
     286             :       "function f2(a, b) { return a() + b(); }\n"
     287             :       "var result1 = f1(function() { return 1; })\n"
     288           5 :       "var result2 = f2(function() { return 2; }, function() { return 3; })");
     289             :   // Can't infer names here.
     290           5 :   CheckFunctionName(script, "return 1", "");
     291           5 :   CheckFunctionName(script, "return 2", "");
     292           5 :   CheckFunctionName(script, "return 3", "");
     293           5 : }
     294             : 
     295             : 
     296       26644 : TEST(MultipleFuncsConditional) {
     297           5 :   CcTest::InitializeVM();
     298          10 :   v8::HandleScope scope(CcTest::isolate());
     299             : 
     300             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     301             :                                          "var x = 0;\n"
     302             :                                          "fun1 = x ?\n"
     303             :                                          "    function() { return 1; } :\n"
     304           5 :                                          "    function() { return 2; }");
     305           5 :   CheckFunctionName(script, "return 1", "fun1");
     306           5 :   CheckFunctionName(script, "return 2", "fun1");
     307           5 : }
     308             : 
     309             : 
     310       26644 : TEST(MultipleFuncsInLiteral) {
     311           5 :   CcTest::InitializeVM();
     312          10 :   v8::HandleScope scope(CcTest::isolate());
     313             : 
     314             :   v8::Local<v8::Script> script =
     315             :       Compile(CcTest::isolate(),
     316             :               "var x = 0;\n"
     317             :               "function MyClass() {}\n"
     318             :               "MyClass.prototype = {\n"
     319             :               "  method1: x ? function() { return 1; } :\n"
     320           5 :               "               function() { return 2; } }");
     321           5 :   CheckFunctionName(script, "return 1", "MyClass.method1");
     322           5 :   CheckFunctionName(script, "return 2", "MyClass.method1");
     323           5 : }
     324             : 
     325             : 
     326       26644 : TEST(AnonymousInAnonymousClosure1) {
     327           5 :   CcTest::InitializeVM();
     328          10 :   v8::HandleScope scope(CcTest::isolate());
     329             : 
     330             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     331             :                                          "(function() {\n"
     332             :                                          "  (function() {\n"
     333             :                                          "      var a = 1;\n"
     334             :                                          "      return;\n"
     335             :                                          "  })();\n"
     336             :                                          "  var b = function() {\n"
     337             :                                          "      var c = 1;\n"
     338             :                                          "      return;\n"
     339             :                                          "  };\n"
     340           5 :                                          "})();");
     341           5 :   CheckFunctionName(script, "return", "");
     342           5 : }
     343             : 
     344             : 
     345       26644 : TEST(AnonymousInAnonymousClosure2) {
     346           5 :   CcTest::InitializeVM();
     347          10 :   v8::HandleScope scope(CcTest::isolate());
     348             : 
     349             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     350             :                                          "(function() {\n"
     351             :                                          "  (function() {\n"
     352             :                                          "      var a = 1;\n"
     353             :                                          "      return;\n"
     354             :                                          "  })();\n"
     355             :                                          "  var c = 1;\n"
     356           5 :                                          "})();");
     357           5 :   CheckFunctionName(script, "return", "");
     358           5 : }
     359             : 
     360             : 
     361       26644 : TEST(NamedInAnonymousClosure) {
     362           5 :   CcTest::InitializeVM();
     363          10 :   v8::HandleScope scope(CcTest::isolate());
     364             : 
     365             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     366             :                                          "var foo = function() {\n"
     367             :                                          "  (function named() {\n"
     368             :                                          "      var a = 1;\n"
     369             :                                          "  })();\n"
     370             :                                          "  var c = 1;\n"
     371             :                                          "  return;\n"
     372           5 :                                          "};");
     373           5 :   CheckFunctionName(script, "return", "foo");
     374           5 : }
     375             : 
     376             : 
     377             : // See http://code.google.com/p/v8/issues/detail?id=380
     378       26644 : TEST(Issue380) {
     379           5 :   CcTest::InitializeVM();
     380          10 :   v8::HandleScope scope(CcTest::isolate());
     381             : 
     382             :   v8::Local<v8::Script> script =
     383             :       Compile(CcTest::isolate(),
     384             :               "function a() {\n"
     385             :               "var result = function(p,a,c,k,e,d)"
     386             :               "{return p}(\"if blah blah\",62,1976,\'a|b\'.split(\'|\'),0,{})\n"
     387           5 :               "}");
     388           5 :   CheckFunctionName(script, "return p", "");
     389           5 : }
     390             : 
     391             : 
     392       26644 : TEST(MultipleAssignments) {
     393           5 :   CcTest::InitializeVM();
     394          10 :   v8::HandleScope scope(CcTest::isolate());
     395             : 
     396             :   v8::Local<v8::Script> script =
     397             :       Compile(CcTest::isolate(),
     398             :               "var fun1 = fun2 = function () { return 1; }\n"
     399             :               "var bar1 = bar2 = bar3 = function () { return 2; }\n"
     400             :               "foo1 = foo2 = function () { return 3; }\n"
     401           5 :               "baz1 = baz2 = baz3 = function () { return 4; }");
     402           5 :   CheckFunctionName(script, "return 1", "fun2");
     403           5 :   CheckFunctionName(script, "return 2", "bar3");
     404           5 :   CheckFunctionName(script, "return 3", "foo2");
     405           5 :   CheckFunctionName(script, "return 4", "baz3");
     406           5 : }
     407             : 
     408             : 
     409       26644 : TEST(AsConstructorParameter) {
     410           5 :   CcTest::InitializeVM();
     411          10 :   v8::HandleScope scope(CcTest::isolate());
     412             : 
     413             :   v8::Local<v8::Script> script = Compile(
     414             :       CcTest::isolate(),
     415             :       "function Foo() {}\n"
     416             :       "var foo = new Foo(function() { return 1; })\n"
     417           5 :       "var bar = new Foo(function() { return 2; }, function() { return 3; })");
     418           5 :   CheckFunctionName(script, "return 1", "");
     419           5 :   CheckFunctionName(script, "return 2", "");
     420           5 :   CheckFunctionName(script, "return 3", "");
     421           5 : }
     422             : 
     423             : 
     424       26644 : TEST(FactoryHashmap) {
     425           5 :   CcTest::InitializeVM();
     426          10 :   v8::HandleScope scope(CcTest::isolate());
     427             : 
     428             :   v8::Local<v8::Script> script =
     429             :       Compile(CcTest::isolate(),
     430             :               "function createMyObj() {\n"
     431             :               "  var obj = {};\n"
     432             :               "  obj[\"method1\"] = function() { return 1; }\n"
     433             :               "  obj[\"method2\"] = function() { return 2; }\n"
     434             :               "  return obj;\n"
     435           5 :               "}");
     436           5 :   CheckFunctionName(script, "return 1", "obj.method1");
     437           5 :   CheckFunctionName(script, "return 2", "obj.method2");
     438           5 : }
     439             : 
     440             : 
     441       26644 : TEST(FactoryHashmapVariable) {
     442           5 :   CcTest::InitializeVM();
     443          10 :   v8::HandleScope scope(CcTest::isolate());
     444             : 
     445             :   v8::Local<v8::Script> script =
     446             :       Compile(CcTest::isolate(),
     447             :               "function createMyObj() {\n"
     448             :               "  var obj = {};\n"
     449             :               "  var methodName = \"method1\";\n"
     450             :               "  obj[methodName] = function() { return 1; }\n"
     451             :               "  methodName = \"method2\";\n"
     452             :               "  obj[methodName] = function() { return 2; }\n"
     453             :               "  return obj;\n"
     454           5 :               "}");
     455             :   // Can't infer function names statically.
     456           5 :   CheckFunctionName(script, "return 1", "obj.<computed>");
     457           5 :   CheckFunctionName(script, "return 2", "obj.<computed>");
     458           5 : }
     459             : 
     460             : 
     461       26644 : TEST(FactoryHashmapConditional) {
     462           5 :   CcTest::InitializeVM();
     463          10 :   v8::HandleScope scope(CcTest::isolate());
     464             : 
     465             :   v8::Local<v8::Script> script = Compile(
     466             :       CcTest::isolate(),
     467             :       "function createMyObj() {\n"
     468             :       "  var obj = {};\n"
     469             :       "  obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n"
     470             :       "  return obj;\n"
     471           5 :       "}");
     472             :   // Can't infer the function name statically.
     473           5 :   CheckFunctionName(script, "return 1", "obj.<computed>");
     474           5 : }
     475             : 
     476             : 
     477       26644 : TEST(GlobalAssignmentAndCall) {
     478           5 :   CcTest::InitializeVM();
     479          10 :   v8::HandleScope scope(CcTest::isolate());
     480             : 
     481             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     482             :                                          "var Foo = function() {\n"
     483             :                                          "  return 1;\n"
     484             :                                          "}();\n"
     485             :                                          "var Baz = Bar = function() {\n"
     486             :                                          "  return 2;\n"
     487           5 :                                          "}");
     488             :   // The inferred name is empty, because this is an assignment of a result.
     489           5 :   CheckFunctionName(script, "return 1", "");
     490             :   // See MultipleAssignments test.
     491           5 :   CheckFunctionName(script, "return 2", "Bar");
     492           5 : }
     493             : 
     494             : 
     495       26644 : TEST(AssignmentAndCall) {
     496           5 :   CcTest::InitializeVM();
     497          10 :   v8::HandleScope scope(CcTest::isolate());
     498             : 
     499             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     500             :                                          "(function Enclosing() {\n"
     501             :                                          "  var Foo;\n"
     502             :                                          "  Foo = function() {\n"
     503             :                                          "    return 1;\n"
     504             :                                          "  }();\n"
     505             :                                          "  var Baz = Bar = function() {\n"
     506             :                                          "    return 2;\n"
     507             :                                          "  }\n"
     508           5 :                                          "})();");
     509             :   // The inferred name is empty, because this is an assignment of a result.
     510           5 :   CheckFunctionName(script, "return 1", "");
     511             :   // See MultipleAssignments test.
     512             :   // TODO(2276): Lazy compiling the enclosing outer closure would yield
     513             :   // in "Enclosing.Bar" being the inferred name here.
     514           5 :   CheckFunctionName(script, "return 2", "Bar");
     515           5 : }
     516             : 
     517             : 
     518       26644 : TEST(MethodAssignmentInAnonymousFunctionCall) {
     519           5 :   CcTest::InitializeVM();
     520          10 :   v8::HandleScope scope(CcTest::isolate());
     521             : 
     522             :   v8::Local<v8::Script> script =
     523             :       Compile(CcTest::isolate(),
     524             :               "(function () {\n"
     525             :               "    var EventSource = function () { };\n"
     526             :               "    EventSource.prototype.addListener = function () {\n"
     527             :               "        return 2012;\n"
     528             :               "    };\n"
     529             :               "    this.PublicEventSource = EventSource;\n"
     530           5 :               "})();");
     531           5 :   CheckFunctionName(script, "return 2012", "EventSource.addListener");
     532           5 : }
     533             : 
     534             : 
     535       26644 : TEST(ReturnAnonymousFunction) {
     536           5 :   CcTest::InitializeVM();
     537          10 :   v8::HandleScope scope(CcTest::isolate());
     538             : 
     539             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     540             :                                          "(function() {\n"
     541             :                                          "  function wrapCode() {\n"
     542             :                                          "    return function () {\n"
     543             :                                          "      return 2012;\n"
     544             :                                          "    };\n"
     545             :                                          "  };\n"
     546             :                                          "  var foo = 10;\n"
     547             :                                          "  function f() {\n"
     548             :                                          "    return wrapCode();\n"
     549             :                                          "  }\n"
     550             :                                          "  this.ref = f;\n"
     551           5 :                                          "})()");
     552          10 :   script->Run(CcTest::isolate()->GetCurrentContext()).ToLocalChecked();
     553           5 :   CheckFunctionName(script, "return 2012", "");
     554           5 : }
     555             : 
     556       26644 : TEST(IgnoreExtendsClause) {
     557           5 :   CcTest::InitializeVM();
     558          10 :   v8::HandleScope scope(CcTest::isolate());
     559             : 
     560             :   v8::Local<v8::Script> script =
     561             :       Compile(CcTest::isolate(),
     562             :               "(function() {\n"
     563             :               "  var foo = {};\n"
     564             :               "  foo.C = class {}\n"
     565             :               "  class D extends foo.C {}\n"
     566             :               "  foo.bar = function() { return 1; };\n"
     567           5 :               "})()");
     568          10 :   script->Run(CcTest::isolate()->GetCurrentContext()).ToLocalChecked();
     569           5 :   CheckFunctionName(script, "return 1", "foo.bar");
     570           5 : }
     571             : 
     572       26644 : TEST(ParameterAndArrow) {
     573           5 :   CcTest::InitializeVM();
     574          10 :   v8::HandleScope scope(CcTest::isolate());
     575             : 
     576             :   v8::Local<v8::Script> script = Compile(CcTest::isolate(),
     577             :                                          "(function(param) {\n"
     578             :                                          "  (() => { return 2017 })();\n"
     579           5 :                                          "})()");
     580          10 :   script->Run(CcTest::isolate()->GetCurrentContext()).ToLocalChecked();
     581           5 :   CheckFunctionName(script, "return 2017", "");
     582       79922 : }

Generated by: LCOV version 1.10