v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
elements.h
Go to the documentation of this file.
1// Copyright 2012 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_ELEMENTS_H_
6#define V8_OBJECTS_ELEMENTS_H_
7
11#include "src/objects/keys.h"
12#include "src/objects/objects.h"
13
14namespace v8 {
15namespace internal {
16
17class JSTypedArray;
18
19// Abstract base class for handles that can operate on objects with differing
20// ElementsKinds.
22 public:
23 ElementsAccessor() = default;
24 virtual ~ElementsAccessor() = default;
27
28 // Returns a shared ElementsAccessor for the specified ElementsKind.
29 static ElementsAccessor* ForKind(ElementsKind elements_kind) {
30 DCHECK_LT(static_cast<int>(elements_kind), kElementsKindCount);
31 return elements_accessors_[elements_kind];
32 }
33
34 // Checks the elements of an object for consistency, asserting when a problem
35 // is found.
36 virtual void Validate(Tagged<JSObject> obj) = 0;
37
38 // Returns true if a holder contains an element with the specified index
39 // without iterating up the prototype chain. The first version takes the
40 // backing store to use for the check, which must be compatible with the
41 // ElementsKind of the ElementsAccessor; the second version uses
42 // holder->elements() as the backing store. If a |filter| is specified,
43 // the PropertyAttributes of the element at the given index are compared
44 // to the given |filter|. If they match/overlap, the given index is ignored.
45 // Note that only Dictionary elements have custom
46 // PropertyAttributes associated, hence the |filter| argument is ignored for
47 // all but DICTIONARY_ELEMENTS and SLOW_SLOPPY_ARGUMENTS_ELEMENTS.
48 virtual bool HasElement(Tagged<JSObject> holder, uint32_t index,
49 Tagged<FixedArrayBase> backing_store,
50 PropertyFilter filter = ALL_PROPERTIES) = 0;
51
52 inline bool HasElement(Tagged<JSObject> holder, uint32_t index,
54
55 // Note: this is currently not implemented for string wrapper and
56 // typed array elements.
57 virtual bool HasEntry(Tagged<JSObject> holder, InternalIndex entry) = 0;
58
60 InternalIndex entry) = 0;
61
62 // Currently only shared array elements support sequentially consistent
63 // access.
66 InternalIndex entry,
67 SeqCstAccessTag tag) = 0;
68
69 virtual bool HasAccessors(Tagged<JSObject> holder) = 0;
70 virtual size_t NumberOfElements(Isolate* isolate,
71 Tagged<JSObject> holder) = 0;
72
73 // Modifies the length data property as specified for JSArrays and resizes the
74 // underlying backing store accordingly. The method honors the semantics of
75 // changing array sizes as defined in ECMAScript 5.1 15.4.5.2, i.e. array that
76 // have non-deletable elements can only be shrunk to the size of highest
77 // element that is non-deletable.
79 DirectHandle<JSArray> holder, uint32_t new_length) = 0;
80
81 // Copy all indices that have elements from |object| into the given
82 // KeyAccumulator. For Dictionary-based element-kinds we filter out elements
83 // whose PropertyAttribute match |filter|.
86 KeyAccumulator* keys) = 0;
87
90
92 Isolate* isolate, DirectHandle<JSObject> object,
93 DirectHandle<FixedArray> values_or_entries, bool get_entries,
94 int* nof_items, PropertyFilter filter = ALL_PROPERTIES) = 0;
95
97 Isolate* isolate, DirectHandle<JSObject> object,
99 GetKeysConversion convert, PropertyFilter filter = ALL_PROPERTIES) = 0;
100
102 Isolate* isolate, DirectHandle<JSObject> object,
105
108 AddKeyConversion convert) = 0;
109
111 DirectHandle<Map> map) = 0;
113 DirectHandle<JSObject> object, uint32_t capacity) = 0;
114 // Unlike GrowCapacityAndConvert do not attempt to convert the backing store
115 // and simply return false in this case.
117 DirectHandle<JSObject> object, uint32_t index) = 0;
118
119 static void InitializeOncePerProcess();
120 static void TearDown();
121
122 virtual void Set(DirectHandle<JSObject> holder, InternalIndex entry,
123 Tagged<Object> value) = 0;
124
125 // Currently only shared array elements support sequentially consistent
126 // access.
128 Tagged<Object> value, SeqCstAccessTag tag) = 0;
129
130 // Currently only shared array elements support sequentially consistent
131 // access.
134 InternalIndex entry, Tagged<Object> value,
135 SeqCstAccessTag tag) = 0;
136
138 Isolate* isolate, DirectHandle<JSObject> holder, InternalIndex entry,
139 Tagged<Object> expected, Tagged<Object> value, SeqCstAccessTag tag) = 0;
140
142 uint32_t index,
144 PropertyAttributes attributes,
145 uint32_t new_capacity) = 0;
146
148 uint32_t concat_size,
149 uint32_t result_length);
150
153 uint32_t push_size) = 0;
154
157 uint32_t unshift_size) = 0;
158
161
164
166 DirectHandle<JSObject> object) = 0;
167
168 virtual size_t GetCapacity(Tagged<JSObject> holder,
169 Tagged<FixedArrayBase> backing_store) = 0;
170
173 size_t start, size_t end) = 0;
174
175 // Check an Object's own elements for an element (using SameValueZero
176 // semantics)
179 DirectHandle<Object> value, size_t start,
180 size_t length) = 0;
181
182 // Check an Object's own elements for the index of an element (using SameValue
183 // semantics)
186 DirectHandle<Object> value, size_t start,
187 size_t length) = 0;
188
191 size_t start) = 0;
192
194
195 virtual void CopyElements(Isolate* isolate,
197 ElementsKind source_kind,
199 int size) = 0;
200
203 size_t length, size_t offset) = 0;
204
206 Isolate* isolate, DirectHandle<JSObject> object, uint32_t length) = 0;
207
210 size_t start, size_t end) = 0;
211
212 protected:
213 friend class LookupIterator;
214
215 // Element handlers distinguish between entries and indices when they
216 // manipulate elements. Entries refer to elements in terms of their location
217 // in the underlying storage's backing store representation, and are between 0
218 // and GetCapacity. Indices refer to elements in terms of the value that would
219 // be specified in JavaScript to access the element. In most implementations,
220 // indices are equivalent to entries. In the NumberDictionary
221 // ElementsAccessor, entries are mapped to an index using the KeyAt method on
222 // the NumberDictionary.
224 Tagged<JSObject> holder,
225 Tagged<FixedArrayBase> backing_store,
226 size_t index) = 0;
227
229 InternalIndex entry) = 0;
231 DirectHandle<FixedArrayBase> backing_store,
233 PropertyAttributes attributes) = 0;
234
235 // Deletes an element in an object.
236 virtual void Delete(DirectHandle<JSObject> holder, InternalIndex entry) = 0;
237
238 // NOTE: this method violates the handlified function signature convention:
239 // raw pointer parameter |source_holder| in the function that allocates.
240 // This is done intentionally to avoid ArrayConcat() builtin performance
241 // degradation.
242 virtual void CopyElements(Isolate* isolate, Tagged<JSObject> source_holder,
243 uint32_t source_start, ElementsKind source_kind,
245 uint32_t destination_start, int copy_size) = 0;
246
247 private:
249};
250
254
255// Called directly from CSA.
256// {raw_context}: Context pointer.
257// {raw_source}: JSArray pointer.
258// {raw_destination}: JSTypedArray pointer.
260 Address raw_source,
261 Address raw_destination,
262 uintptr_t length,
263 uintptr_t offset);
264// {raw_source}, {raw_destination}: JSTypedArray pointers.
266 Address raw_destination,
267 uintptr_t length, uintptr_t offset);
268// {raw_source}, {raw_destination}: JSTypedArray pointers.
269void CopyTypedArrayElementsSlice(Address raw_source, Address raw_destination,
270 uintptr_t start, uintptr_t end);
271
272} // namespace internal
273} // namespace v8
274
275#endif // V8_OBJECTS_ELEMENTS_H_
virtual bool HasElement(Tagged< JSObject > holder, uint32_t index, Tagged< FixedArrayBase > backing_store, PropertyFilter filter=ALL_PROPERTIES)=0
virtual Handle< Object > Get(Isolate *isolate, DirectHandle< JSObject > holder, InternalIndex entry)=0
virtual V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Fill(DirectHandle< JSObject > receiver, DirectHandle< Object > obj_value, size_t start, size_t end)=0
virtual ~ElementsAccessor()=default
virtual V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Shift(DirectHandle< JSArray > receiver)=0
static ElementsAccessor * ForKind(ElementsKind elements_kind)
Definition elements.h:29
virtual Maybe< bool > IncludesValue(Isolate *isolate, DirectHandle< JSObject > receiver, DirectHandle< Object > value, size_t start, size_t length)=0
virtual V8_WARN_UNUSED_RESULT Maybe< uint32_t > Push(DirectHandle< JSArray > receiver, BuiltinArguments *args, uint32_t push_size)=0
virtual V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > Pop(DirectHandle< JSArray > receiver)=0
virtual Handle< Object > CompareAndSwapAtomic(Isolate *isolate, DirectHandle< JSObject > holder, InternalIndex entry, Tagged< Object > expected, Tagged< Object > value, SeqCstAccessTag tag)=0
virtual void CopyElements(Isolate *isolate, DirectHandle< FixedArrayBase > source, ElementsKind source_kind, DirectHandle< FixedArrayBase > destination, int size)=0
virtual bool HasAccessors(Tagged< JSObject > holder)=0
virtual size_t GetCapacity(Tagged< JSObject > holder, Tagged< FixedArrayBase > backing_store)=0
virtual Handle< FixedArray > CreateListFromArrayLike(Isolate *isolate, DirectHandle< JSObject > object, uint32_t length)=0
virtual MaybeHandle< FixedArray > PrependElementIndices(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< FixedArrayBase > backing_store, DirectHandle< FixedArray > keys, GetKeysConversion convert, PropertyFilter filter=ALL_PROPERTIES)=0
virtual void CopyTypedArrayElementsSlice(Tagged< JSTypedArray > source, Tagged< JSTypedArray > destination, size_t start, size_t end)=0
virtual InternalIndex GetEntryForIndex(Isolate *isolate, Tagged< JSObject > holder, Tagged< FixedArrayBase > backing_store, size_t index)=0
virtual V8_WARN_UNUSED_RESULT ExceptionStatus AddElementsToKeyAccumulator(DirectHandle< JSObject > receiver, KeyAccumulator *accumulator, AddKeyConversion convert)=0
virtual V8_WARN_UNUSED_RESULT Maybe< bool > GrowCapacityAndConvert(DirectHandle< JSObject > object, uint32_t capacity)=0
virtual Handle< Object > SwapAtomic(Isolate *isolate, DirectHandle< JSObject > holder, InternalIndex entry, Tagged< Object > value, SeqCstAccessTag tag)=0
static V8_EXPORT_PRIVATE ElementsAccessor ** elements_accessors_
Definition elements.h:248
virtual V8_WARN_UNUSED_RESULT ExceptionStatus CollectElementIndices(DirectHandle< JSObject > object, DirectHandle< FixedArrayBase > backing_store, KeyAccumulator *keys)=0
virtual V8_WARN_UNUSED_RESULT Maybe< bool > GrowCapacity(DirectHandle< JSObject > object, uint32_t index)=0
virtual V8_WARN_UNUSED_RESULT Maybe< bool > SetLength(DirectHandle< JSArray > holder, uint32_t new_length)=0
virtual void Delete(DirectHandle< JSObject > holder, InternalIndex entry)=0
static void InitializeOncePerProcess()
Definition elements.cc:5728
virtual void TransitionElementsKind(DirectHandle< JSObject > object, DirectHandle< Map > map)=0
static DirectHandle< JSArray > Concat(Isolate *isolate, BuiltinArguments *args, uint32_t concat_size, uint32_t result_length)
Definition elements.cc:5765
virtual size_t NumberOfElements(Isolate *isolate, Tagged< JSObject > holder)=0
virtual void CopyElements(Isolate *isolate, Tagged< JSObject > source_holder, uint32_t source_start, ElementsKind source_kind, DirectHandle< FixedArrayBase > destination, uint32_t destination_start, int copy_size)=0
ElementsAccessor(const ElementsAccessor &)=delete
virtual Maybe< int64_t > LastIndexOfValue(DirectHandle< JSObject > receiver, DirectHandle< Object > value, size_t start)=0
virtual void Reconfigure(DirectHandle< JSObject > object, DirectHandle< FixedArrayBase > backing_store, InternalIndex entry, DirectHandle< Object > value, PropertyAttributes attributes)=0
virtual Tagged< Object > CopyElements(DirectHandle< JSAny > source, DirectHandle< JSObject > destination, size_t length, size_t offset)=0
virtual V8_WARN_UNUSED_RESULT Maybe< uint32_t > Unshift(DirectHandle< JSArray > receiver, BuiltinArguments *args, uint32_t unshift_size)=0
virtual void Validate(Tagged< JSObject > obj)=0
virtual Handle< Object > GetAtomic(Isolate *isolate, DirectHandle< JSObject > holder, InternalIndex entry, SeqCstAccessTag tag)=0
virtual PropertyDetails GetDetails(Tagged< JSObject > holder, InternalIndex entry)=0
virtual Maybe< bool > CollectValuesOrEntries(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< FixedArray > values_or_entries, bool get_entries, int *nof_items, PropertyFilter filter=ALL_PROPERTIES)=0
virtual void SetAtomic(DirectHandle< JSObject > holder, InternalIndex entry, Tagged< Object > value, SeqCstAccessTag tag)=0
virtual void Reverse(Tagged< JSObject > receiver)=0
ElementsAccessor & operator=(const ElementsAccessor &)=delete
virtual DirectHandle< NumberDictionary > Normalize(DirectHandle< JSObject > object)=0
virtual bool HasEntry(Tagged< JSObject > holder, InternalIndex entry)=0
virtual V8_WARN_UNUSED_RESULT Maybe< bool > Add(DirectHandle< JSObject > object, uint32_t index, DirectHandle< Object > value, PropertyAttributes attributes, uint32_t new_capacity)=0
virtual void Set(DirectHandle< JSObject > holder, InternalIndex entry, Tagged< Object > value)=0
virtual Maybe< int64_t > IndexOfValue(Isolate *isolate, DirectHandle< JSObject > receiver, DirectHandle< Object > value, size_t start, size_t length)=0
int start
int end
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
int32_t offset
TNode< Object > receiver
InstructionOperand destination
MaybeDirectHandle< Object > ArrayConstructInitializeElements(DirectHandle< JSArray > array, JavaScriptArguments *args)
Definition elements.cc:5579
GetKeysConversion
Definition keys.h:22
void CopyTypedArrayElementsToTypedArray(Address raw_source, Address raw_destination, uintptr_t length, uintptr_t offset)
Definition elements.cc:5691
void CopyTypedArrayElementsSlice(Address raw_source, Address raw_destination, uintptr_t start, uintptr_t end)
Definition elements.cc:5712
tsan_relaxed_store_8_bits tsan_relaxed_store_32_bits tsan_seq_cst_store_8_bits tsan_seq_cst_store_32_bits tsan_relaxed_load_32_bits Address raw_context
constexpr int kElementsKindCount
void CopyFastNumberJSArrayElementsToTypedArray(Address raw_context, Address raw_source, Address raw_destination, uintptr_t length, uintptr_t offset)
Definition elements.cc:5667
AddKeyConversion
Definition keys.h:20
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671