1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/code-stub-assembler.h" 6 7 namespace v8 { 8 namespace internal { 9 10 typedef compiler::Node Node; 11 typedef compiler::CodeAssemblerState CodeAssemblerState; 12 typedef compiler::CodeAssemblerLabel CodeAssemblerLabel; 13 14 class ArgumentsBuiltinsAssembler : public CodeStubAssembler { 15 public: ArgumentsBuiltinsAssembler(CodeAssemblerState * state)16 explicit ArgumentsBuiltinsAssembler(CodeAssemblerState* state) 17 : CodeStubAssembler(state) {} 18 19 Node* EmitFastNewStrictArguments(Node* context, Node* function); 20 Node* EmitFastNewSloppyArguments(Node* context, Node* function); 21 Node* EmitFastNewRestParameter(Node* context, Node* function); 22 23 private: 24 // Calculates and returns the the frame pointer, argument count and formal 25 // parameter count to be used to access a function's parameters, taking 26 // argument adapter frames into account. The tuple is of the form: 27 // <frame_ptr, # parameters actually passed, formal parameter count> 28 std::tuple<Node*, Node*, Node*> GetArgumentsFrameAndCount(Node* function, 29 ParameterMode mode); 30 31 // Allocates an an arguments (either rest, strict or sloppy) together with the 32 // FixedArray elements for the arguments and a parameter map (for sloppy 33 // arguments only). A tuple is returned with pointers to the arguments object, 34 // the elements and parameter map in the form: 35 // <argument object, arguments FixedArray, parameter map or nullptr> 36 std::tuple<Node*, Node*, Node*> AllocateArgumentsObject( 37 Node* map, Node* arguments, Node* mapped_arguments, 38 ParameterMode param_mode, int base_size); 39 40 // For Rest parameters and Strict arguments, the copying of parameters from 41 // the stack into the arguments object is straight-forward and shares much of 42 // the same underlying logic, which is encapsulated by this function. It 43 // allocates an arguments-like object of size |base_size| with the map |map|, 44 // and then copies |rest_count| arguments from the stack frame pointed to by 45 // |frame_ptr| starting from |first_arg|. |arg_count| == |first_arg| + 46 // |rest_count|. 47 Node* ConstructParametersObjectFromArgs(Node* map, Node* frame_ptr, 48 Node* arg_count, Node* first_arg, 49 Node* rest_count, 50 ParameterMode param_mode, 51 int base_size); 52 }; 53 54 } // namespace internal 55 } // namespace v8 56