OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/js-call-reducer.h" | 5 #include "src/compiler/js-call-reducer.h" |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 Handle<JSObject> prototype(JSObject::cast(object_map->prototype())); | 296 Handle<JSObject> prototype(JSObject::cast(object_map->prototype())); |
297 object_map = handle(prototype->map()); | 297 object_map = handle(prototype->map()); |
298 if (expected_receiver_type->IsTemplateFor(*object_map)) { | 298 if (expected_receiver_type->IsTemplateFor(*object_map)) { |
299 *holder = prototype; | 299 *holder = prototype; |
300 return kHolderFound; | 300 return kHolderFound; |
301 } | 301 } |
302 } | 302 } |
303 return kHolderNotFound; | 303 return kHolderNotFound; |
304 } | 304 } |
305 | 305 |
| 306 // ES6 section 19.1.3.2 Object.prototype.hasOwnProperty |
| 307 Reduction JSCallReducer::ReduceObjectPrototypeHasOwnProperty(Node* node) { |
| 308 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); |
| 309 CallParameters const& params = CallParametersOf(node->op()); |
| 310 if (params.arity() != 3) return NoChange(); |
| 311 Node* receiver = NodeProperties::GetValueInput(node, 1); |
| 312 Node* name = NodeProperties::GetValueInput(node, 2); |
| 313 |
| 314 // We can optimize a call to Object.prototype.hasOwnProperty if it's being |
| 315 // used inside a for..in, so for code like this: |
| 316 // |
| 317 // for (name in receiver) { |
| 318 // if (receiver.hasOwnProperty(name)) { |
| 319 // ... |
| 320 // } |
| 321 // } |
| 322 if (name->opcode() == IrOpcode::kJSForInNext) { |
| 323 Node* object = NodeProperties::GetValueInput(name, 0); |
| 324 Node* enumerator = NodeProperties::GetValueInput(name, 2); |
| 325 if (object == receiver || (object->opcode() == IrOpcode::kJSToObject && |
| 326 object->InputAt(0) == receiver)) { |
| 327 node->ReplaceInput(1, object); |
| 328 node->InsertInput(graph()->zone(), 3, enumerator); |
| 329 NodeProperties::ChangeOp(node, javascript()->ForInHasOwnProperty()); |
| 330 return Changed(node); |
| 331 } |
| 332 } |
| 333 |
| 334 return NoChange(); |
| 335 } |
| 336 |
306 // ES6 section B.2.2.1.1 get Object.prototype.__proto__ | 337 // ES6 section B.2.2.1.1 get Object.prototype.__proto__ |
307 Reduction JSCallReducer::ReduceObjectPrototypeGetProto(Node* node) { | 338 Reduction JSCallReducer::ReduceObjectPrototypeGetProto(Node* node) { |
308 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); | 339 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); |
309 Node* receiver = NodeProperties::GetValueInput(node, 1); | 340 Node* receiver = NodeProperties::GetValueInput(node, 1); |
310 Node* effect = NodeProperties::GetEffectInput(node); | 341 Node* effect = NodeProperties::GetEffectInput(node); |
311 | 342 |
312 // Try to determine the {receiver} map. | 343 // Try to determine the {receiver} map. |
313 ZoneHandleSet<Map> receiver_maps; | 344 ZoneHandleSet<Map> receiver_maps; |
314 if (NodeProperties::InferReceiverMaps(receiver, effect, &receiver_maps)) { | 345 if (NodeProperties::InferReceiverMaps(receiver, effect, &receiver_maps)) { |
315 Handle<Map> candidate_map( | 346 Handle<Map> candidate_map( |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // Check for known builtin functions. | 557 // Check for known builtin functions. |
527 switch (shared->code()->builtin_index()) { | 558 switch (shared->code()->builtin_index()) { |
528 case Builtins::kFunctionPrototypeApply: | 559 case Builtins::kFunctionPrototypeApply: |
529 return ReduceFunctionPrototypeApply(node); | 560 return ReduceFunctionPrototypeApply(node); |
530 case Builtins::kFunctionPrototypeCall: | 561 case Builtins::kFunctionPrototypeCall: |
531 return ReduceFunctionPrototypeCall(node); | 562 return ReduceFunctionPrototypeCall(node); |
532 case Builtins::kFunctionPrototypeHasInstance: | 563 case Builtins::kFunctionPrototypeHasInstance: |
533 return ReduceFunctionPrototypeHasInstance(node); | 564 return ReduceFunctionPrototypeHasInstance(node); |
534 case Builtins::kNumberConstructor: | 565 case Builtins::kNumberConstructor: |
535 return ReduceNumberConstructor(node); | 566 return ReduceNumberConstructor(node); |
| 567 case Builtins::kObjectHasOwnProperty: |
| 568 return ReduceObjectPrototypeHasOwnProperty(node); |
536 case Builtins::kObjectPrototypeGetProto: | 569 case Builtins::kObjectPrototypeGetProto: |
537 return ReduceObjectPrototypeGetProto(node); | 570 return ReduceObjectPrototypeGetProto(node); |
538 default: | 571 default: |
539 break; | 572 break; |
540 } | 573 } |
541 | 574 |
542 // Check for the Array constructor. | 575 // Check for the Array constructor. |
543 if (*function == function->native_context()->array_function()) { | 576 if (*function == function->native_context()->array_function()) { |
544 return ReduceArrayConstructor(node); | 577 return ReduceArrayConstructor(node); |
545 } | 578 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 return jsgraph()->javascript(); | 839 return jsgraph()->javascript(); |
807 } | 840 } |
808 | 841 |
809 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { | 842 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { |
810 return jsgraph()->simplified(); | 843 return jsgraph()->simplified(); |
811 } | 844 } |
812 | 845 |
813 } // namespace compiler | 846 } // namespace compiler |
814 } // namespace internal | 847 } // namespace internal |
815 } // namespace v8 | 848 } // namespace v8 |
OLD | NEW |