Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: src/compiler/js-call-reducer.cc

Issue 2763533002: [WIP] JSForInLowering and JSForInHasOwnProperty.
Patch Set: Hack around the issue with indices not being available always. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/js-call-reducer.h ('k') | src/compiler/js-for-in-lowering.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-call-reducer.cc
diff --git a/src/compiler/js-call-reducer.cc b/src/compiler/js-call-reducer.cc
index 21148b3d20d6351d82cbbc3913745762129b52b1..47b60e447e7098fbec28f1dbc25fd1ce59b6f91b 100644
--- a/src/compiler/js-call-reducer.cc
+++ b/src/compiler/js-call-reducer.cc
@@ -303,6 +303,37 @@ JSCallReducer::HolderLookup JSCallReducer::LookupHolder(
return kHolderNotFound;
}
+// ES6 section 19.1.3.2 Object.prototype.hasOwnProperty
+Reduction JSCallReducer::ReduceObjectPrototypeHasOwnProperty(Node* node) {
+ DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
+ CallParameters const& params = CallParametersOf(node->op());
+ if (params.arity() != 3) return NoChange();
+ Node* receiver = NodeProperties::GetValueInput(node, 1);
+ Node* name = NodeProperties::GetValueInput(node, 2);
+
+ // We can optimize a call to Object.prototype.hasOwnProperty if it's being
+ // used inside a for..in, so for code like this:
+ //
+ // for (name in receiver) {
+ // if (receiver.hasOwnProperty(name)) {
+ // ...
+ // }
+ // }
+ if (name->opcode() == IrOpcode::kJSForInNext) {
+ Node* object = NodeProperties::GetValueInput(name, 0);
+ Node* enumerator = NodeProperties::GetValueInput(name, 2);
+ if (object == receiver || (object->opcode() == IrOpcode::kJSToObject &&
+ object->InputAt(0) == receiver)) {
+ node->ReplaceInput(1, object);
+ node->InsertInput(graph()->zone(), 3, enumerator);
+ NodeProperties::ChangeOp(node, javascript()->ForInHasOwnProperty());
+ return Changed(node);
+ }
+ }
+
+ return NoChange();
+}
+
// ES6 section B.2.2.1.1 get Object.prototype.__proto__
Reduction JSCallReducer::ReduceObjectPrototypeGetProto(Node* node) {
DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
@@ -533,6 +564,8 @@ Reduction JSCallReducer::ReduceJSCall(Node* node) {
return ReduceFunctionPrototypeHasInstance(node);
case Builtins::kNumberConstructor:
return ReduceNumberConstructor(node);
+ case Builtins::kObjectHasOwnProperty:
+ return ReduceObjectPrototypeHasOwnProperty(node);
case Builtins::kObjectPrototypeGetProto:
return ReduceObjectPrototypeGetProto(node);
default:
« no previous file with comments | « src/compiler/js-call-reducer.h ('k') | src/compiler/js-for-in-lowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698