Title: [189435] trunk/Tools
Revision
189435
Author
[email protected]
Date
2015-09-05 10:33:19 -0700 (Sat, 05 Sep 2015)

Log Message

Web Inspector: Improve prepare-ChangeLog for multiple cases
https://bugs.webkit.org/show_bug.cgi?id=148875

Patch by Joseph Pecoraro <[email protected]> on 2015-09-05
Reviewed by Timothy Hatcher.

* Scripts/prepare-ChangeLog:
(get_function_line_ranges_for_javascript):
- We were ignoring everything inside of an anonymous function _expression_,
  such as (function(){ ... }), which made InjectedScriptSource produce nothing.
  Better handle this by inserting a few tweaks.
- Allow method syntax outside of classes as long as they are at the global level.
- Avoid treating "get" and "set" as getter/setter functions in bad contexts.

* Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests-expected.txt:
* Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests.js:
(Foo.prototype.method1):
(Foo.prototype.method2):
(Foo.prototype.method3.innerFunction):
(Foo.prototype.method3):
(insideGlobalAnonymousFunctionExpression):
(foo.insideGlobalFunctionExpression):
(IssueWithMapGetAndSet.prototype.method1.nestedFunctionInsideMethod1):
(IssueWithMapGetAndSet.prototype.method1):
(IssueWithMapGetAndSet.prototype.method2):
(IssueWithMapGetAndSet.prototype.method3):
(IssueWithMapGetAndSet):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (189434 => 189435)


--- trunk/Tools/ChangeLog	2015-09-05 17:27:22 UTC (rev 189434)
+++ trunk/Tools/ChangeLog	2015-09-05 17:33:19 UTC (rev 189435)
@@ -1,3 +1,32 @@
+2015-09-05  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: Improve prepare-ChangeLog for multiple cases
+        https://bugs.webkit.org/show_bug.cgi?id=148875
+
+        Reviewed by Timothy Hatcher.
+
+        * Scripts/prepare-ChangeLog:
+        (get_function_line_ranges_for_javascript):
+        - We were ignoring everything inside of an anonymous function _expression_,
+          such as (function(){ ... }), which made InjectedScriptSource produce nothing.
+          Better handle this by inserting a few tweaks.
+        - Allow method syntax outside of classes as long as they are at the global level.
+        - Avoid treating "get" and "set" as getter/setter functions in bad contexts.
+
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests-expected.txt:
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests.js:
+        (Foo.prototype.method1):
+        (Foo.prototype.method2):
+        (Foo.prototype.method3.innerFunction):
+        (Foo.prototype.method3):
+        (insideGlobalAnonymousFunctionExpression):
+        (foo.insideGlobalFunctionExpression):
+        (IssueWithMapGetAndSet.prototype.method1.nestedFunctionInsideMethod1):
+        (IssueWithMapGetAndSet.prototype.method1):
+        (IssueWithMapGetAndSet.prototype.method2):
+        (IssueWithMapGetAndSet.prototype.method3):
+        (IssueWithMapGetAndSet):
+
 2015-09-05  Yusuke Suzuki  <[email protected]>
 
         [ES6] Enable ES6 Module in JSC shell by default

Modified: trunk/Tools/Scripts/prepare-ChangeLog (189434 => 189435)


--- trunk/Tools/Scripts/prepare-ChangeLog	2015-09-05 17:27:22 UTC (rev 189434)
+++ trunk/Tools/Scripts/prepare-ChangeLog	2015-09-05 17:33:19 UTC (rev 189435)
@@ -1286,8 +1286,7 @@
 #    }
 #
 # A method name is the word immediately before parenthesis, with an open
-# curly brace immediately following closing parenthesis. For simplification
-# we only parse for methods inside of a class. And for a class _expression_
+# curly brace immediately following closing parenthesis. For a class _expression_
 # we take the assignment identifier instead of the class name for namespacing.
 #
 #    namespace.Foo = class DoesNotMatter extends Bar {
@@ -1301,6 +1300,13 @@
 #        method() {} // (ClassName.prototype.method)
 #    }
 #
+# Methods may exist in object literals, outside of classes.
+#
+#   Foo.prototype = {
+#       method() {}, // (Foo.prototype.method)
+#       otherMethod() {} // (Foo.prototype.otherMethod)
+#   }
+#
 # Comment handling is simple-minded but will work for all but pathological cases.
 #
 # Result is a list of triples: [ start_line, end_line, function_name ].
@@ -1322,7 +1328,9 @@
     my $inQuotedText = "";
     my $inExtends = 0;
     my $inMethod = 0;
+    my $inAnonymousFunctionParameters = 0;
     my $parenthesesDepth = 0;
+    my $globalParenthesesDepth = 0;
     my $bracesDepth = 0;
 
     my $classJustSeen = 0;
@@ -1333,6 +1341,8 @@
     my $assignmentJustSeen = 0;
     my $staticOrContructorSeen = 0;
 
+    my $currentToken = "";
+    my $lastToken = "";
     my $possibleMethodName = "";
     my $word = "";
 
@@ -1370,23 +1380,32 @@
         }
 
         # Find function names.
-        while (m-(\w+|[(){}=:;,])-g) {
+        while (m-(\w+|[(){}=:;,.])-g) {
             # Skip everything until "{" after extends.
             if ($inExtends) {
                 next if $1 ne '{';
                 $inExtends = 0;
             }
 
+            $lastToken = $currentToken;
+            $currentToken = $1;
+
             # Open parenthesis.
             if ($1 eq '(') {
                 $parenthesesDepth++;
+                $globalParenthesesDepth++ if $currentParsingMode[$#currentParsingMode] eq "global";
                 $possibleMethodName = join('.', @currentIdentifiers);
+                $inAnonymousFunctionParameters = 1 if $functionJustSeen;
+                $functionJustSeen = 0;
                 next;
             }
 
             # Close parenthesis.
             if ($1 eq ')') {
                 $parenthesesDepth--;
+                $globalParenthesesDepth-- if $currentParsingMode[$#currentParsingMode] eq "global";
+                @currentIdentifiers = () if $inAnonymousFunctionParameters;
+                $inAnonymousFunctionParameters = 0;
                 $parenthesisJustSeen = 1;
                 next;
             }
@@ -1394,10 +1413,16 @@
             # Open brace.
             if ($1 eq '{') {
                 my $methodName = "";
+                my $mode = $currentParsingMode[$#currentParsingMode];
 
                 # Method.
-                if ($currentParsingMode[$#currentParsingMode] eq 'class' and $parenthesisJustSeen and ($staticOrContructorSeen or $possibleMethodName)) {
-                    $methodName = join('.', $staticOrContructorSeen ? "" : "prototype", $possibleMethodName);
+                if (($mode eq 'class' or $mode eq 'global') and $parenthesisJustSeen and ($staticOrContructorSeen or $possibleMethodName)) {
+                    if ($mode eq 'class') {
+                        $methodName = join('.', $staticOrContructorSeen ? "" : "prototype", $possibleMethodName);
+                    } else {
+                        $methodName = $possibleMethodName;
+                    }
+
                     $methodName =~ s/\.{2,}/\./g; # Removes consecutive periods.
                     $methodName =~ s/\.$//; # Remove trailing period.
 
@@ -1433,6 +1458,8 @@
                     my $currentName = pop(@currentFunctionNames);
                     my $start = pop(@currentFunctionStartLines);
 
+                    $currentName =~ s/^\.//g; # Removes leading periods.
+
                     push(@ranges, [$start, $., $currentName]);
                 }
 
@@ -1442,6 +1469,11 @@
                 next;
             }
 
+            # Dot.
+            if ($1 eq '.') {
+                next;
+            }
+
             # Semicolon or comma.
             if ($1 eq ';' or $1 eq ',') {
                 @currentIdentifiers = ();
@@ -1479,12 +1511,14 @@
 
             # Getter prefix.
             if ($1 eq 'get') {
+                next if $lastToken eq '.'; # Avoid map.get(...).
                 $getterJustSeen = 1;
                 next;
             }
 
             # Setter prefix.
             if ($1 eq 'set') {
+                next if $lastToken eq '.'; # Avoid map.set(...).
                 $setterJustSeen = 1;
                 next;
             }
@@ -1501,7 +1535,7 @@
                 next;
             }
 
-            next if $parenthesesDepth;
+            next if $parenthesesDepth > $globalParenthesesDepth;
 
             # Word.
             $word = $1;

Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests-expected.txt (189434 => 189435)


--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests-expected.txt	2015-09-05 17:27:22 UTC (rev 189434)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests-expected.txt	2015-09-05 17:33:19 UTC (rev 189435)
@@ -201,6 +201,66 @@
       175,
       192,
       'namespace.MyClass'
+    ],
+    [
+      '195',
+      '195',
+      'Foo.prototype.method1'
+    ],
+    [
+      '198',
+      '199',
+      'Foo.prototype.method2'
+    ],
+    [
+      '203',
+      '205',
+      'Foo.prototype.method3.innerFunction'
+    ],
+    [
+      '202',
+      '207',
+      'Foo.prototype.method3'
+    ],
+    [
+      '211',
+      '213',
+      'insideGlobalAnonymousFunctionExpression'
+    ],
+    [
+      '217',
+      '219',
+      'foo.insideGlobalFunctionExpression'
+    ],
+    [
+      '216',
+      '220',
+      'foo'
+    ],
+    [
+      '227',
+      '227',
+      'IssueWithMapGetAndSet.prototype.method1.nestedFunctionInsideMethod1'
+    ],
+    [
+      '224',
+      '229',
+      'IssueWithMapGetAndSet.prototype.method1'
+    ],
+    [
+      '232',
+      '234',
+      'IssueWithMapGetAndSet.prototype.method2'
+    ],
+    [
+      '237',
+      '238',
+      'IssueWithMapGetAndSet.prototype.method3'
+    ],
+    [
+      '222',
+      '239',
+      'IssueWithMapGetAndSet'
     ]
   ]
 }

Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests.js (189434 => 189435)


--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests.js	2015-09-05 17:27:22 UTC (rev 189434)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/_javascript__unittests.js	2015-09-05 17:33:19 UTC (rev 189435)
@@ -190,3 +190,50 @@
 
     get getter() { }
 }
+
+Foo.prototype = {
+    method1() { },
+
+    method2(a)
+    {
+    },
+
+    method3(a, b)
+    {
+        function innerFunction() {
+            // ...
+        }
+        return innerFunction();
+    }
+};
+
+(function(asdf) {
+    function insideGlobalAnonymousFunctionExpression(obj)
+    {
+    }
+})();
+
+(function foo(asdf) {
+    function insideGlobalFunctionExpression(obj)
+    {
+    }
+})();
+
+class IssueWithMapGetAndSet {
+    method1()
+    {
+        this.map.set(a, b);
+        let object = {property: value};
+        function nestedFunctionInsideMethod1(){}
+        this._callingSomething();
+    }
+
+    method2()
+    {
+        this.map.get(a);
+    }
+
+    method3()
+    {
+    }
+};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to