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

Side by Side Diff: src/compiler/js-typed-lowering.cc

Issue 1420093005: [turbofan] Sanitize typing rules for function calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler/node-properties.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/code-factory.h" 5 #include "src/code-factory.h"
6 #include "src/compiler/access-builder.h" 6 #include "src/compiler/access-builder.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/js-typed-lowering.h" 8 #include "src/compiler/js-typed-lowering.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/node-matchers.h" 10 #include "src/compiler/node-matchers.h"
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } 1379 }
1380 1380
1381 return NoChange(); 1381 return NoChange();
1382 } 1382 }
1383 1383
1384 1384
1385 Reduction JSTypedLowering::ReduceJSCallFunction(Node* node) { 1385 Reduction JSTypedLowering::ReduceJSCallFunction(Node* node) {
1386 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); 1386 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode());
1387 CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); 1387 CallFunctionParameters const& p = CallFunctionParametersOf(node->op());
1388 int const arity = static_cast<int>(p.arity() - 2); 1388 int const arity = static_cast<int>(p.arity() - 2);
1389 Node* const function = NodeProperties::GetValueInput(node, 0); 1389 Node* target = NodeProperties::GetValueInput(node, 0);
1390 Type* const function_type = NodeProperties::GetType(function); 1390 Type* target_type = NodeProperties::GetType(target);
1391 Node* const receiver = NodeProperties::GetValueInput(node, 1); 1391 Node* receiver = NodeProperties::GetValueInput(node, 1);
1392 Type* const receiver_type = NodeProperties::GetType(receiver); 1392 Type* receiver_type = NodeProperties::GetType(receiver);
1393 Node* const effect = NodeProperties::GetEffectInput(node);
1394 Node* const control = NodeProperties::GetControlInput(node);
1395 1393
1396 // Check that {function} is actually a JSFunction with the correct arity. 1394 // Check if {target} is a known JSFunction.
1397 if (function_type->IsFunction() && 1395 if (target_type->IsConstant() &&
1398 function_type->AsFunction()->Arity() == arity) { 1396 target_type->AsConstant()->Value()->IsJSFunction()) {
1399 // Check that the {receiver} doesn't need to be wrapped. 1397 Handle<JSFunction> function =
1400 if (receiver_type->Is(Type::ReceiverOrUndefined())) { 1398 Handle<JSFunction>::cast(target_type->AsConstant()->Value());
1401 Node* const context = graph()->NewNode( 1399 Handle<SharedFunctionInfo> shared(function->shared(), isolate());
1402 simplified()->LoadField(AccessBuilder::ForJSFunctionContext()), 1400 if (shared->internal_formal_parameter_count() == arity) {
1403 function, effect, control); 1401 // Check if we need to wrap the {receiver}.
1402 if (is_sloppy(shared->language_mode()) && !shared->native()) {
1403 if (receiver_type->Is(Type::NullOrUndefined())) {
1404 // Change {receiver} to global proxy of {function}.
1405 receiver =
1406 jsgraph()->Constant(handle(function->global_proxy(), isolate()));
1407 } else if (!receiver_type->Is(Type::Receiver())) {
1408 // TODO(bmeurer): Add support for wrapping abitrary receivers.
1409 return NoChange();
1410 }
1411 NodeProperties::ReplaceValueInput(node, receiver, 1);
1412 }
1413
1414 // Grab the context from the {function}.
1415 Node* context =
1416 jsgraph()->Constant(handle(function->context(), isolate()));
1404 NodeProperties::ReplaceContextInput(node, context); 1417 NodeProperties::ReplaceContextInput(node, context);
1405 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState; 1418 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState;
1406 if (p.AllowTailCalls()) { 1419 if (p.AllowTailCalls()) {
1407 flags |= CallDescriptor::kSupportsTailCalls; 1420 flags |= CallDescriptor::kSupportsTailCalls;
1408 } 1421 }
1409 NodeProperties::ChangeOp(node, 1422 NodeProperties::ChangeOp(node,
1410 common()->Call(Linkage::GetJSCallDescriptor( 1423 common()->Call(Linkage::GetJSCallDescriptor(
1411 graph()->zone(), false, 1 + arity, flags))); 1424 graph()->zone(), false, 1 + arity, flags)));
1412 return Changed(node); 1425 return Changed(node);
1413 } 1426 }
1414 } 1427 }
1428
1415 return NoChange(); 1429 return NoChange();
1416 } 1430 }
1417 1431
1418 1432
1419 Reduction JSTypedLowering::ReduceJSForInDone(Node* node) { 1433 Reduction JSTypedLowering::ReduceJSForInDone(Node* node) {
1420 DCHECK_EQ(IrOpcode::kJSForInDone, node->opcode()); 1434 DCHECK_EQ(IrOpcode::kJSForInDone, node->opcode());
1421 node->TrimInputCount(2); 1435 node->TrimInputCount(2);
1422 NodeProperties::ChangeOp(node, machine()->Word32Equal()); 1436 NodeProperties::ChangeOp(node, machine()->Word32Equal());
1423 return Changed(node); 1437 return Changed(node);
1424 } 1438 }
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 } 1851 }
1838 1852
1839 1853
1840 MachineOperatorBuilder* JSTypedLowering::machine() const { 1854 MachineOperatorBuilder* JSTypedLowering::machine() const {
1841 return jsgraph()->machine(); 1855 return jsgraph()->machine();
1842 } 1856 }
1843 1857
1844 } // namespace compiler 1858 } // namespace compiler
1845 } // namespace internal 1859 } // namespace internal
1846 } // namespace v8 1860 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/compiler/node-properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698