<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189435] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189435">189435</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-09-05 10:33:19 -0700 (Sat, 05 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Improve prepare-ChangeLog for multiple cases
https://bugs.webkit.org/show_bug.cgi?id=148875

Patch by Joseph Pecoraro &lt;pecoraro@apple.com&gt; 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 &quot;get&quot; and &quot;set&quot; 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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptsprepareChangeLog">trunk/Tools/Scripts/prepare-ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitperlprepareChangeLog_unittestresourcesjavascript_unittestsexpectedtxt">trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/javascript_unittests-expected.txt</a></li>
<li><a href="#trunkToolsScriptswebkitperlprepareChangeLog_unittestresourcesjavascript_unittestsjs">trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/javascript_unittests.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (189434 => 189435)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-09-05 17:27:22 UTC (rev 189434)
+++ trunk/Tools/ChangeLog        2015-09-05 17:33:19 UTC (rev 189435)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2015-09-05  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        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 &quot;get&quot; and &quot;set&quot; 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):
+
</ins><span class="cx"> 2015-09-05  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [ES6] Enable ES6 Module in JSC shell by default
</span></span></pre></div>
<a id="trunkToolsScriptsprepareChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/prepare-ChangeLog (189434 => 189435)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1286,8 +1286,7 @@
</span><span class="cx"> #    }
</span><span class="cx"> #
</span><span class="cx"> # A method name is the word immediately before parenthesis, with an open
</span><del>-# curly brace immediately following closing parenthesis. For simplification
-# we only parse for methods inside of a class. And for a class expression
</del><ins>+# curly brace immediately following closing parenthesis. For a class expression
</ins><span class="cx"> # we take the assignment identifier instead of the class name for namespacing.
</span><span class="cx"> #
</span><span class="cx"> #    namespace.Foo = class DoesNotMatter extends Bar {
</span><span class="lines">@@ -1301,6 +1300,13 @@
</span><span class="cx"> #        method() {} // (ClassName.prototype.method)
</span><span class="cx"> #    }
</span><span class="cx"> #
</span><ins>+# Methods may exist in object literals, outside of classes.
+#
+#   Foo.prototype = {
+#       method() {}, // (Foo.prototype.method)
+#       otherMethod() {} // (Foo.prototype.otherMethod)
+#   }
+#
</ins><span class="cx"> # Comment handling is simple-minded but will work for all but pathological cases.
</span><span class="cx"> #
</span><span class="cx"> # Result is a list of triples: [ start_line, end_line, function_name ].
</span><span class="lines">@@ -1322,7 +1328,9 @@
</span><span class="cx">     my $inQuotedText = &quot;&quot;;
</span><span class="cx">     my $inExtends = 0;
</span><span class="cx">     my $inMethod = 0;
</span><ins>+    my $inAnonymousFunctionParameters = 0;
</ins><span class="cx">     my $parenthesesDepth = 0;
</span><ins>+    my $globalParenthesesDepth = 0;
</ins><span class="cx">     my $bracesDepth = 0;
</span><span class="cx"> 
</span><span class="cx">     my $classJustSeen = 0;
</span><span class="lines">@@ -1333,6 +1341,8 @@
</span><span class="cx">     my $assignmentJustSeen = 0;
</span><span class="cx">     my $staticOrContructorSeen = 0;
</span><span class="cx"> 
</span><ins>+    my $currentToken = &quot;&quot;;
+    my $lastToken = &quot;&quot;;
</ins><span class="cx">     my $possibleMethodName = &quot;&quot;;
</span><span class="cx">     my $word = &quot;&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -1370,23 +1380,32 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         # Find function names.
</span><del>-        while (m-(\w+|[(){}=:;,])-g) {
</del><ins>+        while (m-(\w+|[(){}=:;,.])-g) {
</ins><span class="cx">             # Skip everything until &quot;{&quot; after extends.
</span><span class="cx">             if ($inExtends) {
</span><span class="cx">                 next if $1 ne '{';
</span><span class="cx">                 $inExtends = 0;
</span><span class="cx">             }
</span><span class="cx"> 
</span><ins>+            $lastToken = $currentToken;
+            $currentToken = $1;
+
</ins><span class="cx">             # Open parenthesis.
</span><span class="cx">             if ($1 eq '(') {
</span><span class="cx">                 $parenthesesDepth++;
</span><ins>+                $globalParenthesesDepth++ if $currentParsingMode[$#currentParsingMode] eq &quot;global&quot;;
</ins><span class="cx">                 $possibleMethodName = join('.', @currentIdentifiers);
</span><ins>+                $inAnonymousFunctionParameters = 1 if $functionJustSeen;
+                $functionJustSeen = 0;
</ins><span class="cx">                 next;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             # Close parenthesis.
</span><span class="cx">             if ($1 eq ')') {
</span><span class="cx">                 $parenthesesDepth--;
</span><ins>+                $globalParenthesesDepth-- if $currentParsingMode[$#currentParsingMode] eq &quot;global&quot;;
+                @currentIdentifiers = () if $inAnonymousFunctionParameters;
+                $inAnonymousFunctionParameters = 0;
</ins><span class="cx">                 $parenthesisJustSeen = 1;
</span><span class="cx">                 next;
</span><span class="cx">             }
</span><span class="lines">@@ -1394,10 +1413,16 @@
</span><span class="cx">             # Open brace.
</span><span class="cx">             if ($1 eq '{') {
</span><span class="cx">                 my $methodName = &quot;&quot;;
</span><ins>+                my $mode = $currentParsingMode[$#currentParsingMode];
</ins><span class="cx"> 
</span><span class="cx">                 # Method.
</span><del>-                if ($currentParsingMode[$#currentParsingMode] eq 'class' and $parenthesisJustSeen and ($staticOrContructorSeen or $possibleMethodName)) {
-                    $methodName = join('.', $staticOrContructorSeen ? &quot;&quot; : &quot;prototype&quot;, $possibleMethodName);
</del><ins>+                if (($mode eq 'class' or $mode eq 'global') and $parenthesisJustSeen and ($staticOrContructorSeen or $possibleMethodName)) {
+                    if ($mode eq 'class') {
+                        $methodName = join('.', $staticOrContructorSeen ? &quot;&quot; : &quot;prototype&quot;, $possibleMethodName);
+                    } else {
+                        $methodName = $possibleMethodName;
+                    }
+
</ins><span class="cx">                     $methodName =~ s/\.{2,}/\./g; # Removes consecutive periods.
</span><span class="cx">                     $methodName =~ s/\.$//; # Remove trailing period.
</span><span class="cx"> 
</span><span class="lines">@@ -1433,6 +1458,8 @@
</span><span class="cx">                     my $currentName = pop(@currentFunctionNames);
</span><span class="cx">                     my $start = pop(@currentFunctionStartLines);
</span><span class="cx"> 
</span><ins>+                    $currentName =~ s/^\.//g; # Removes leading periods.
+
</ins><span class="cx">                     push(@ranges, [$start, $., $currentName]);
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -1442,6 +1469,11 @@
</span><span class="cx">                 next;
</span><span class="cx">             }
</span><span class="cx"> 
</span><ins>+            # Dot.
+            if ($1 eq '.') {
+                next;
+            }
+
</ins><span class="cx">             # Semicolon or comma.
</span><span class="cx">             if ($1 eq ';' or $1 eq ',') {
</span><span class="cx">                 @currentIdentifiers = ();
</span><span class="lines">@@ -1479,12 +1511,14 @@
</span><span class="cx"> 
</span><span class="cx">             # Getter prefix.
</span><span class="cx">             if ($1 eq 'get') {
</span><ins>+                next if $lastToken eq '.'; # Avoid map.get(...).
</ins><span class="cx">                 $getterJustSeen = 1;
</span><span class="cx">                 next;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             # Setter prefix.
</span><span class="cx">             if ($1 eq 'set') {
</span><ins>+                next if $lastToken eq '.'; # Avoid map.set(...).
</ins><span class="cx">                 $setterJustSeen = 1;
</span><span class="cx">                 next;
</span><span class="cx">             }
</span><span class="lines">@@ -1501,7 +1535,7 @@
</span><span class="cx">                 next;
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            next if $parenthesesDepth;
</del><ins>+            next if $parenthesesDepth &gt; $globalParenthesesDepth;
</ins><span class="cx"> 
</span><span class="cx">             # Word.
</span><span class="cx">             $word = $1;
</span></span></pre></div>
<a id="trunkToolsScriptswebkitperlprepareChangeLog_unittestresourcesjavascript_unittestsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/javascript_unittests-expected.txt (189434 => 189435)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -201,6 +201,66 @@
</span><span class="cx">       175,
</span><span class="cx">       192,
</span><span class="cx">       'namespace.MyClass'
</span><ins>+    ],
+    [
+      '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'
</ins><span class="cx">     ]
</span><span class="cx">   ]
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsScriptswebkitperlprepareChangeLog_unittestresourcesjavascript_unittestsjs"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/javascript_unittests.js (189434 => 189435)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -190,3 +190,50 @@
</span><span class="cx"> 
</span><span class="cx">     get getter() { }
</span><span class="cx"> }
</span><ins>+
+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()
+    {
+    }
+};
</ins></span></pre>
</div>
</div>

</body>
</html>