arguments.h 5.47 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_ARGUMENTS_H_
#define V8_OBJECTS_ARGUMENTS_H_

8
#include "src/objects/fixed-array.h"
9
#include "src/objects/js-objects.h"
10
#include "src/objects/struct.h"
11
#include "torque-generated/class-definitions-from-dsl.h"
12 13 14 15 16 17 18

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

19 20 21 22
// Superclass for all objects with instance type {JS_ARGUMENTS_TYPE}
class JSArgumentsObject : public JSObject {
 public:
  DECL_VERIFIER(JSArgumentsObject)
23
  DECL_CAST(JSArgumentsObject)
24
  OBJECT_CONSTRUCTORS(JSArgumentsObject, JSObject);
25 26
};

27
// Common superclass for JSSloppyArgumentsObject and JSStrictArgumentsObject.
28 29 30
// Note that the instance type {JS_ARGUMENTS_TYPE} does _not_ guarantee the
// below layout, the in-object properties might have transitioned to dictionary
// mode already. Only use the below layout with the specific initial maps.
31
class JSArgumentsObjectWithLength : public JSArgumentsObject {
32
 public:
33
  // Layout description.
34 35 36
  DEFINE_FIELD_OFFSET_CONSTANTS(
      JSObject::kHeaderSize,
      TORQUE_GENERATED_JSARGUMENTS_OBJECT_WITH_LENGTH_FIELDS)
37

38 39 40
  // Indices of in-object properties.
  static const int kLengthIndex = 0;

41
  DECL_VERIFIER(JSArgumentsObjectWithLength)
42 43

 private:
44
  DISALLOW_IMPLICIT_CONSTRUCTORS(JSArgumentsObjectWithLength);
45 46 47 48
};

// JSSloppyArgumentsObject is just a JSObject with specific initial map.
// This initial map adds in-object properties for "length" and "callee".
49
class JSSloppyArgumentsObject : public JSArgumentsObjectWithLength {
50
 public:
51 52 53 54 55 56 57 58 59
// Layout description.
#define JS_SLOPPY_ARGUMENTS_OBJECT_FIELDS(V) \
  V(kCalleeOffset, kTaggedSize)              \
  V(kSize, 0)

  DEFINE_FIELD_OFFSET_CONSTANTS(JSArgumentsObjectWithLength::kSize,
                                JS_SLOPPY_ARGUMENTS_OBJECT_FIELDS)
#undef JS_SLOPPY_ARGUMENTS_OBJECT_FIELDS

60 61 62
  // Indices of in-object properties.
  static const int kCalleeIndex = kLengthIndex + 1;

63 64 65 66
  inline static bool GetSloppyArgumentsLength(Isolate* isolate,
                                              Handle<JSObject> object,
                                              int* out);

67 68 69 70 71 72
 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(JSSloppyArgumentsObject);
};

// JSStrictArgumentsObject is just a JSObject with specific initial map.
// This initial map adds an in-object property for "length".
73
class JSStrictArgumentsObject : public JSArgumentsObjectWithLength {
74
 public:
75
  // Layout description.
76
  static const int kSize = JSArgumentsObjectWithLength::kSize;
77 78 79 80 81 82 83 84

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(JSStrictArgumentsObject);
};

// Helper class to access FAST_ and SLOW_SLOPPY_ARGUMENTS_ELEMENTS
//
// +---+-----------------------+
85
// | 0 | Context  context      |
86
// +---------------------------+
87
// | 1 | FixedArray arguments  +----+ HOLEY_ELEMENTS
88
// +---------------------------+    v-----+-----------+
89
// | 2 | Object param_1_map    |    |  0  | the_hole  |
90
// |...| ...                   |    | ... | ...       |
91
// |n+1| Object param_n_map    |    | n-1 | the_hole  |
92 93 94 95 96 97 98 99 100 101
// +---------------------------+    |  n  | element_1 |
//                                  | ... | ...       |
//                                  |n+m-1| element_m |
//                                  +-----------------+
//
// Parameter maps give the index into the provided context. If a map entry is
// the_hole it means that the given entry has been deleted from the arguments
// object.
// The arguments backing store kind depends on the ElementsKind of the outer
// JSArgumentsObject:
102
// - FAST_SLOPPY_ARGUMENTS_ELEMENTS: HOLEY_ELEMENTS
103
// - SLOW_SLOPPY_ARGUMENTS_ELEMENTS: DICTIONARY_ELEMENTS
104
class SloppyArgumentsElements : public FixedArray {
105 106 107 108 109
 public:
  static const int kContextIndex = 0;
  static const int kArgumentsIndex = 1;
  static const uint32_t kParameterMapStart = 2;

110
  inline Context context();
111 112
  inline FixedArray arguments();
  inline void set_arguments(FixedArray arguments);
113
  inline uint32_t parameter_map_length();
114 115
  inline Object get_mapped_entry(uint32_t entry);
  inline void set_mapped_entry(uint32_t entry, Object object);
116

117
  DECL_CAST(SloppyArgumentsElements)
118
#ifdef VERIFY_HEAP
119
  void SloppyArgumentsElementsVerify(Isolate* isolate, JSObject holder);
120 121
#endif

122
  OBJECT_CONSTRUCTORS(SloppyArgumentsElements, FixedArray);
123 124 125 126 127 128 129 130 131 132
};

// Representation of a slow alias as part of a sloppy arguments objects.
// For fast aliases (if HasSloppyArgumentsElements()):
// - the parameter map contains an index into the context
// - all attributes of the element have default values
// For slow aliases (if HasDictionaryArgumentsElements()):
// - the parameter map contains no fast alias mapping (i.e. the hole)
// - this struct (in the slow backing store) contains an index into the context
// - all attributes are available as part if the property details
133
class AliasedArgumentsEntry : public Struct {
134 135 136 137
 public:
  inline int aliased_context_slot() const;
  inline void set_aliased_context_slot(int count);

138
  DECL_CAST(AliasedArgumentsEntry)
139 140

  // Dispatched behavior.
141 142
  DECL_PRINTER(AliasedArgumentsEntry)
  DECL_VERIFIER(AliasedArgumentsEntry)
143

144
  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
145
                                TORQUE_GENERATED_ALIASED_ARGUMENTS_ENTRY_FIELDS)
146

147
  OBJECT_CONSTRUCTORS(AliasedArgumentsEntry, Struct);
148 149 150 151 152 153 154 155
};

}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_ARGUMENTS_H_