<!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>[200859] trunk</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/200859">200859</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-05-13 09:16:51 -0700 (Fri, 13 May 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Protector Ref/RefPtrs should have a specified naming style.
https://bugs.webkit.org/show_bug.cgi?id=157591

Reviewed by Darin Adler.

Tools:

* Scripts/webkitpy/style/checkers/cpp.py:
(check_identifier_name_in_declaration):
(CppChecker):
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_names):

Websites/webkit.org:

* code-style.md:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpystylecheckerscpppy">trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py</a></li>
<li><a href="#trunkToolsScriptswebkitpystylecheckerscpp_unittestpy">trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py</a></li>
<li><a href="#trunkWebsiteswebkitorgChangeLog">trunk/Websites/webkit.org/ChangeLog</a></li>
<li><a href="#trunkWebsiteswebkitorgcodestylemd">trunk/Websites/webkit.org/code-style.md</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (200858 => 200859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-05-13 16:06:03 UTC (rev 200858)
+++ trunk/Tools/ChangeLog        2016-05-13 16:16:51 UTC (rev 200859)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-05-13  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Protector Ref/RefPtrs should have a specified naming style.
+        https://bugs.webkit.org/show_bug.cgi?id=157591
+
+        Reviewed by Darin Adler.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_identifier_name_in_declaration):
+        (CppChecker):
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_names):
+
</ins><span class="cx"> 2016-05-12  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove ENABLE(ES6_ARROWFUNCTION_SYNTAX) guards
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpystylecheckerscpppy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (200858 => 200859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py        2016-05-13 16:06:03 UTC (rev 200858)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py        2016-05-13 16:16:51 UTC (rev 200859)
</span><span class="lines">@@ -3291,6 +3291,21 @@
</span><span class="cx">     if match(r'\s*(return|delete)\b', line):
</span><span class="cx">         return
</span><span class="cx"> 
</span><ins>+    # Make sure Ref/RefPtrs used as protectors are named correctly, and do this before we start stripping things off the input.
+    ref_regexp = r'^\s*Ref(Ptr)?&lt;([\w_]|::)+&gt; (?P&lt;protector_name&gt;[\w_]+)\((\*|&amp;)*(m_)?(?P&lt;protected_name&gt;[\w_]+)\);'
+    ref_check = match(ref_regexp, line)
+    if ref_check:
+        protector_name = ref_check.group('protector_name')
+        protected_name = ref_check.group('protected_name')
+        cap_protected_name = protected_name[0].upper() + protected_name[1:]
+        expected_protector_name = 'protected' + cap_protected_name
+        if protected_name == 'this' and protector_name != 'protectedThis':
+            error(line_number, 'readability/naming/protected', 4, &quot;\'&quot; + protector_name + &quot;\' is incorrectly named. It should be named \'protectedThis\'.&quot;)
+        elif protector_name == expected_protector_name or protector_name == 'protector':
+            return
+        else:
+            error(line_number, 'readability/naming/protected', 4, &quot;\'&quot; + protector_name + &quot;\' is incorrectly named. It should be named \'protector\' or \'&quot; + expected_protector_name + &quot;\'.&quot;)
+
</ins><span class="cx">     # Basically, a declaration is a type name followed by whitespaces
</span><span class="cx">     # followed by an identifier. The type name can be complicated
</span><span class="cx">     # due to type adjectives and templates. We remove them first to
</span><span class="lines">@@ -3846,6 +3861,7 @@
</span><span class="cx">         'readability/multiline_string',
</span><span class="cx">         'readability/parameter_name',
</span><span class="cx">         'readability/naming',
</span><ins>+        'readability/naming/protected',
</ins><span class="cx">         'readability/naming/underscores',
</span><span class="cx">         'readability/null',
</span><span class="cx">         'readability/streams',
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpystylecheckerscpp_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (200858 => 200859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py        2016-05-13 16:06:03 UTC (rev 200858)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py        2016-05-13 16:16:51 UTC (rev 200859)
</span><span class="lines">@@ -5179,6 +5179,52 @@
</span><span class="cx">         self.assert_lint('unsigned _fillRule : 1;',
</span><span class="cx">                          '_fillRule' + name_underscore_error_message)
</span><span class="cx"> 
</span><ins>+        # Valid protector RefPtr/Ref variable names.
+        self.assert_lint('RefPtr&lt;Node&gt; protectedThis(this);', '')
+        self.assert_lint('Ref&lt;Node&gt; protectedThis(*this);', '')
+        self.assert_lint('RefPtr&lt;Node&gt; protectedNode(node);', '')
+        self.assert_lint('RefPtr&lt;Node&gt; protectedNode(&amp;node);', '')
+        self.assert_lint('RefPtr&lt;Node&gt; protector(node);', '')
+        self.assert_lint('RefPtr&lt;Node&gt; protector(&amp;node);', '')
+        self.assert_lint('Ref&lt;Node&gt; protectedNode(node);', '')
+        self.assert_lint('Ref&lt;Node&gt; protectedNode(*node);', '')
+        self.assert_lint('Ref&lt;Node&gt; protector(node);', '')
+        self.assert_lint('Ref&lt;Node&gt; protector(*node);', '')
+        self.assert_lint('RefPtr&lt;Node&gt; protectedOtherNode(otherNode);', '')
+        self.assert_lint('RefPtr&lt;Node&gt; protectedOtherNode(&amp;otherNode);', '')
+        self.assert_lint('Ref&lt;Node&gt; protectedOtherNode(otherNode);', '')
+        self.assert_lint('Ref&lt;Node&gt; protectedOtherNode(*otherNode);', '')
+        self.assert_lint('RefPtr&lt;Widget&gt; protectedWidget(m_widget);', '')
+        self.assert_lint('RefPtr&lt;Widget&gt; protectedWidget(&amp;m_widget);', '')
+        self.assert_lint('Ref&lt;Widget&gt; protectedWidget(m_widget);', '')
+        self.assert_lint('Ref&lt;Widget&gt; protectedWidget(*m_widget);', '')
+        self.assert_lint('RefPtr&lt;Widget&gt; protector(m_widget);', '')
+        self.assert_lint('RefPtr&lt;Widget&gt; protector(&amp;m_widget);', '')
+        self.assert_lint('Ref&lt;Widget&gt; protector(m_widget);', '')
+        self.assert_lint('Ref&lt;Widget&gt; protector(*m_widget);', '')
+        self.assert_lint('RefPtr&lt;SomeNamespace::Node&gt; protectedThis(this);', '')
+        self.assert_lint('RefPtr&lt;SomeClass::InternalClass::Node&gt; protectedThis(this);', '')
+
+        # Invalid protector RefPtr/Ref variable names.
+        self.assert_lint('RefPtr&lt;Node&gt; protector(this);', &quot;'protector' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; protector(*this);', &quot;'protector' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('RefPtr&lt;Node&gt; self(this);', &quot;'self' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; self(*this);', &quot;'self' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('RefPtr&lt;Node&gt; protectedThis(node);', &quot;'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('RefPtr&lt;Node&gt; protectedThis(&amp;node);', &quot;'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; protectedThis(node);', &quot;'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; protectedThis(*node);', &quot;'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('RefPtr&lt;Node&gt; protectedNode(otherNode);', &quot;'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('RefPtr&lt;Node&gt; protectedNode(&amp;otherNode);', &quot;'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; protectedNode(otherNode);', &quot;'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; protectedNode(*otherNode);', &quot;'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('RefPtr&lt;Node&gt; nodeRef(node);', &quot;'nodeRef' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]&quot;)
+        self.assert_lint('Ref&lt;Node&gt; nodeRef(*node);', &quot;'nodeRef' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]&quot;)
+
+        # Lines that look like a protector variable declaration but aren't.
+        self.assert_lint('static RefPtr&lt;Widget&gt; doSomethingWith(widget);', '')
+        self.assert_lint('RefPtr&lt;Widget&gt; create();', '')
+
</ins><span class="cx">     def test_parameter_names(self):
</span><span class="cx">         # Leave meaningless variable names out of function declarations.
</span><span class="cx">         meaningless_variable_name_error_message = 'The parameter name &quot;%s&quot; adds no information, so it should be removed.  [readability/parameter_name] [5]'
</span></span></pre></div>
<a id="trunkWebsiteswebkitorgChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Websites/webkit.org/ChangeLog (200858 => 200859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/webkit.org/ChangeLog        2016-05-13 16:06:03 UTC (rev 200858)
+++ trunk/Websites/webkit.org/ChangeLog        2016-05-13 16:16:51 UTC (rev 200859)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2016-05-13  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Protector Ref/RefPtrs should have a specified naming style.
+        https://bugs.webkit.org/show_bug.cgi?id=157591
+
+        Reviewed by Darin Adler.
+
+        * code-style.md:
+
</ins><span class="cx"> 2016-04-26  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove hard-wraps from the feature policy markdown so it renders full width on the site.
</span></span></pre></div>
<a id="trunkWebsiteswebkitorgcodestylemd"></a>
<div class="modfile"><h4>Modified: trunk/Websites/webkit.org/code-style.md (200858 => 200859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/webkit.org/code-style.md        2016-05-13 16:06:03 UTC (rev 200858)
+++ trunk/Websites/webkit.org/code-style.md        2016-05-13 16:16:51 UTC (rev 200859)
</span><span class="lines">@@ -713,6 +713,42 @@
</span><span class="cx"> #define _HTML_DOCUMENT_H_
</span><span class="cx"> ```
</span><span class="cx"> 
</span><ins>+[](#names-protectors-this) Ref and RefPtr objects meant to protect `this` from deletion should be named &quot;protectedThis&quot;.
+
+###### Right:
+
+```cpp
+RefPtr&lt;Node&gt; protectedThis(this);
+Ref&lt;Element&gt; protectedThis(*this);
+```
+
+###### Wrong:
+
+```cpp
+RefPtr&lt;Node&gt; protector(this);
+RefPtr&lt;Widget&gt; self(this);
+Ref&lt;Element&gt; elementRef(*this);
+```
+
+[](#names-protectors) Ref and RefPtr objects meant to protect variables other than `this` from deletion should be named either &quot;protector&quot;, or &quot;protected&quot; combined with the capitalized form of the variable name.
+
+###### Right:
+
+```cpp
+RefPtr&lt;Element&gt; protector(&amp;element);
+RefPtr&lt;Node&gt; protectedNode(node);
+RefPtr&lt;Widget&gt; protectedMainWidget(m_mainWidget);
+```
+
+###### Wrong:
+
+```cpp
+RefPtr&lt;Node&gt; nodeRef(&amp;rootNode);
+Ref&lt;Element&gt; protect(*element);
+RefPtr&lt;Widget&gt; protected(widget);
+RefPtr&lt;Node&gt; protectorNode(node);
+```
+
</ins><span class="cx"> ### Other Punctuation
</span><span class="cx"> 
</span><span class="cx"> [](#punctuation-member-init) Constructors for C++ classes should initialize all of their members using C++ initializer syntax. Each member (and superclass) should be indented on a separate line, with the colon or comma preceding the member on that line.
</span></span></pre>
</div>
</div>

</body>
</html>