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