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 #ifndef V8_OBJECTS_ARGUMENTS_H_ 6 #define V8_OBJECTS_ARGUMENTS_H_ 7 8 #include "src/objects.h" 9 #include "src/objects/fixed-array.h" 10 11 // Has to be the last include (doesn't have include guards): 12 #include "src/objects/object-macros.h" 13 14 namespace v8 { 15 namespace internal { 16 17 // Common superclass for JSSloppyArgumentsObject and JSStrictArgumentsObject. 18 // Note that the instance type {JS_ARGUMENTS_TYPE} does _not_ guarantee the 19 // below layout, the in-object properties might have transitioned to dictionary 20 // mode already. Only use the below layout with the specific initial maps. 21 class JSArgumentsObject : public JSObject { 22 public: 23 // Offsets of object fields. 24 static const int kLengthOffset = JSObject::kHeaderSize; 25 static const int kSize = kLengthOffset + kPointerSize; 26 // Indices of in-object properties. 27 static const int kLengthIndex = 0; 28 29 DECL_VERIFIER(JSArgumentsObject) 30 DECL_CAST(JSArgumentsObject) 31 32 private: 33 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArgumentsObject); 34 }; 35 36 // JSSloppyArgumentsObject is just a JSObject with specific initial map. 37 // This initial map adds in-object properties for "length" and "callee". 38 class JSSloppyArgumentsObject : public JSArgumentsObject { 39 public: 40 // Offsets of object fields. 41 static const int kCalleeOffset = JSArgumentsObject::kSize; 42 static const int kSize = kCalleeOffset + kPointerSize; 43 // Indices of in-object properties. 44 static const int kCalleeIndex = kLengthIndex + 1; 45 46 inline static bool GetSloppyArgumentsLength(Isolate* isolate, 47 Handle<JSObject> object, 48 int* out); 49 50 private: 51 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSloppyArgumentsObject); 52 }; 53 54 // JSStrictArgumentsObject is just a JSObject with specific initial map. 55 // This initial map adds an in-object property for "length". 56 class JSStrictArgumentsObject : public JSArgumentsObject { 57 public: 58 // Offsets of object fields. 59 static const int kSize = JSArgumentsObject::kSize; 60 61 private: 62 DISALLOW_IMPLICIT_CONSTRUCTORS(JSStrictArgumentsObject); 63 }; 64 65 // Helper class to access FAST_ and SLOW_SLOPPY_ARGUMENTS_ELEMENTS 66 // 67 // +---+-----------------------+ 68 // | 0 | Context* context | 69 // +---------------------------+ 70 // | 1 | FixedArray* arguments +----+ HOLEY_ELEMENTS 71 // +---------------------------+ v-----+-----------+ 72 // | 2 | Object* param_1_map | | 0 | the_hole | 73 // |...| ... | | ... | ... | 74 // |n+1| Object* param_n_map | | n-1 | the_hole | 75 // +---------------------------+ | n | element_1 | 76 // | ... | ... | 77 // |n+m-1| element_m | 78 // +-----------------+ 79 // 80 // Parameter maps give the index into the provided context. If a map entry is 81 // the_hole it means that the given entry has been deleted from the arguments 82 // object. 83 // The arguments backing store kind depends on the ElementsKind of the outer 84 // JSArgumentsObject: 85 // - FAST_SLOPPY_ARGUMENTS_ELEMENTS: HOLEY_ELEMENTS 86 // - SLOW_SLOPPY_ARGUMENTS_ELEMENTS: DICTIONARY_ELEMENTS 87 class SloppyArgumentsElements : public FixedArray { 88 public: 89 static const int kContextIndex = 0; 90 static const int kArgumentsIndex = 1; 91 static const uint32_t kParameterMapStart = 2; 92 93 inline Context* context(); 94 inline FixedArray* arguments(); 95 inline void set_arguments(FixedArray* arguments); 96 inline uint32_t parameter_map_length(); 97 inline Object* get_mapped_entry(uint32_t entry); 98 inline void set_mapped_entry(uint32_t entry, Object* object); 99 100 DECL_CAST(SloppyArgumentsElements) 101 #ifdef VERIFY_HEAP 102 void SloppyArgumentsElementsVerify(Isolate* isolate, JSObject* holder); 103 #endif 104 105 private: 106 DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyArgumentsElements); 107 }; 108 109 // Representation of a slow alias as part of a sloppy arguments objects. 110 // For fast aliases (if HasSloppyArgumentsElements()): 111 // - the parameter map contains an index into the context 112 // - all attributes of the element have default values 113 // For slow aliases (if HasDictionaryArgumentsElements()): 114 // - the parameter map contains no fast alias mapping (i.e. the hole) 115 // - this struct (in the slow backing store) contains an index into the context 116 // - all attributes are available as part if the property details 117 class AliasedArgumentsEntry : public Struct { 118 public: 119 inline int aliased_context_slot() const; 120 inline void set_aliased_context_slot(int count); 121 122 DECL_CAST(AliasedArgumentsEntry) 123 124 // Dispatched behavior. 125 DECL_PRINTER(AliasedArgumentsEntry) 126 DECL_VERIFIER(AliasedArgumentsEntry) 127 128 static const int kAliasedContextSlot = HeapObject::kHeaderSize; 129 static const int kSize = kAliasedContextSlot + kPointerSize; 130 131 private: 132 DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); 133 }; 134 135 } // namespace internal 136 } // namespace v8 137 138 #include "src/objects/object-macros-undef.h" 139 140 #endif // V8_OBJECTS_ARGUMENTS_H_ 141