Avoid variable/type shadowing in blink/dom
In an effort to reduce or even ban variable shadowing, this renames
a variable to avoid such shadowing. I'm interested in prohibiting
shadowing because I think it might prevent potential jumbo problems.
The exact warnings this avoids are:
third_party/blink/renderer/core/dom/element.cc:3940:35: error: declaration shadows a local variable [-Werror,-Wshadow]
else if (const Attribute* attribute =
^
third_party/blink/renderer/core/dom/element.cc:3938:30: note: previous declaration is here
if (const Attribute* attribute = attributes.Find(xml_names::kLangAttr))
^
third_party/blink/renderer/core/dom/node.cc:2113:17: error: declaration shadows a local variable [-Werror,-Wshadow]
const Node* node = chain[index - 1];
^
third_party/blink/renderer/core/dom/node.cc:2107:15: note: previous declaration is here
const Node* node = this;
^
third_party/blink/renderer/core/dom/range.cc:529:36: error: declaration shadows a type alias in namespace 'blink' [-Werror,-Wshadow]
typedef HeapVector<Member<Node>> NodeVector;
^
third_party/blink/renderer/core/dom/container_node.h:84:7: note: previous declaration is here
using NodeVector = HeapVector<Member<Node>, kInitialNodeVectorSize>;
^
third_party/blink/renderer/core/dom/range.cc:750:36: error: declaration shadows a type alias in namespace 'blink' [-Werror,-Wshadow]
typedef HeapVector<Member<Node>> NodeVector;
^
third_party/blink/renderer/core/dom/container_node.h:84:7: note: previous declaration is here
using NodeVector = HeapVector<Member<Node>, kInitialNodeVectorSize>;
^
Bug: 925310
Change-Id: I8bc037dd1cf54baf5f6fe1ed93b1ead391313e8a
Reviewed-on: https://chromium-review.googlesource.com/c/1478876
Reviewed-by: Fredrik Söderquist <fs@opera.com>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Auto-Submit: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#634659}diff --git a/third_party/blink/renderer/core/dom/element.cc b/third_party/blink/renderer/core/dom/element.cc
index 2c19cf3..30e68d0 100644
--- a/third_party/blink/renderer/core/dom/element.cc
+++ b/third_party/blink/renderer/core/dom/element.cc
@@ -3939,11 +3939,14 @@
if (const ElementData* element_data = ToElement(n)->GetElementData()) {
AttributeCollection attributes = element_data->Attributes();
// Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7
- if (const Attribute* attribute = attributes.Find(xml_names::kLangAttr))
+ if (const Attribute* attribute =
+ attributes.Find(xml_names::kLangAttr)) {
value = attribute->Value();
- else if (const Attribute* attribute =
- attributes.Find(html_names::kLangAttr))
- value = attribute->Value();
+ } else {
+ attribute = attributes.Find(html_names::kLangAttr);
+ if (attribute)
+ value = attribute->Value();
+ }
}
} else if (auto* document = DynamicTo<Document>(n)) {
// checking the MIME content-language
diff --git a/third_party/blink/renderer/core/dom/node.cc b/third_party/blink/renderer/core/dom/node.cc
index 50815259..75454d94 100644
--- a/third_party/blink/renderer/core/dom/node.cc
+++ b/third_party/blink/renderer/core/dom/node.cc
@@ -2105,10 +2105,10 @@
void Node::PrintNodePathTo(std::ostream& stream) const {
HeapVector<Member<const Node>, 16> chain;
- const Node* node = this;
- while (node->ParentOrShadowHostNode()) {
- chain.push_back(node);
- node = node->ParentOrShadowHostNode();
+ const Node* parent_node = this;
+ while (parent_node->ParentOrShadowHostNode()) {
+ chain.push_back(parent_node);
+ parent_node = parent_node->ParentOrShadowHostNode();
}
for (unsigned index = chain.size(); index > 0; --index) {
const Node* node = chain[index - 1];
diff --git a/third_party/blink/renderer/core/dom/range.cc b/third_party/blink/renderer/core/dom/range.cc
index e2f86e3c..963e3c44 100644
--- a/third_party/blink/renderer/core/dom/range.cc
+++ b/third_party/blink/renderer/core/dom/range.cc
@@ -526,8 +526,6 @@
DocumentFragment* Range::ProcessContents(ActionType action,
ExceptionState& exception_state) {
- typedef HeapVector<Member<Node>> NodeVector;
-
DocumentFragment* fragment = nullptr;
if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS)
fragment = DocumentFragment::Create(*owner_document_.Get());
@@ -705,7 +703,7 @@
}
Node* n = container->firstChild();
- HeapVector<Member<Node>> nodes;
+ NodeVector nodes;
for (unsigned i = start_offset; n && i; i--)
n = n->nextSibling();
for (unsigned i = start_offset; n && i < end_offset;
@@ -720,7 +718,7 @@
}
void Range::ProcessNodes(ActionType action,
- HeapVector<Member<Node>>& nodes,
+ NodeVector& nodes,
Node* old_container,
Node* new_container,
ExceptionState& exception_state) {
@@ -747,8 +745,6 @@
Node* cloned_container,
Node* common_root,
ExceptionState& exception_state) {
- typedef HeapVector<Member<Node>> NodeVector;
-
NodeVector ancestors;
for (Node& runner : NodeTraversal::AncestorsOf(*container)) {
if (runner == common_root)
diff --git a/third_party/blink/renderer/core/dom/range.h b/third_party/blink/renderer/core/dom/range.h
index e25d568..0cc5e36 100644
--- a/third_party/blink/renderer/core/dom/range.h
+++ b/third_party/blink/renderer/core/dom/range.h
@@ -194,7 +194,7 @@
unsigned end_offset,
ExceptionState&);
static void ProcessNodes(ActionType,
- HeapVector<Member<Node>>&,
+ NodeVector&,
Node* old_container,
Node* new_container,
ExceptionState&);