V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-objects.h
1 // Copyright 2018 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_JS_OBJECTS_H_
6 #define V8_OBJECTS_JS_OBJECTS_H_
7 
8 #include "src/objects.h"
9 #include "src/objects/embedder-data-slot.h"
10 #include "src/objects/property-array.h"
11 
12 // Has to be the last include (doesn't have include guards):
13 #include "src/objects/object-macros.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 enum InstanceType : uint16_t;
19 class JSGlobalObject;
20 class JSGlobalProxy;
21 
22 // JSReceiver includes types on which properties can be defined, i.e.,
23 // JSObject and JSProxy.
25  public:
26  // Returns true if there is no slow (ie, dictionary) backing store.
27  inline bool HasFastProperties() const;
28 
29  // Returns the properties array backing store if it
30  // exists. Otherwise, returns an empty_property_array when there's a
31  // Smi (hash code) or an empty_fixed_array for a fast properties
32  // map.
33  inline PropertyArray property_array() const;
34 
35  // Gets slow properties for non-global objects.
36  inline NameDictionary property_dictionary() const;
37 
38  // Sets the properties backing store and makes sure any existing hash is moved
39  // to the new properties store. To clear out the properties store, pass in the
40  // empty_fixed_array(), the hash will be maintained in this case as well.
41  void SetProperties(HeapObject* properties);
42 
43  // There are five possible values for the properties offset.
44  // 1) EmptyFixedArray/EmptyPropertyDictionary - This is the standard
45  // placeholder.
46  //
47  // 2) Smi - This is the hash code of the object.
48  //
49  // 3) PropertyArray - This is similar to a FixedArray but stores
50  // the hash code of the object in its length field. This is a fast
51  // backing store.
52  //
53  // 4) NameDictionary - This is the dictionary-mode backing store.
54  //
55  // 4) GlobalDictionary - This is the backing store for the
56  // GlobalObject.
57  //
58  // This is used only in the deoptimizer and heap. Please use the
59  // above typed getters and setters to access the properties.
60  DECL_ACCESSORS(raw_properties_or_hash, Object)
61 
62  inline void initialize_properties();
63 
64  // Deletes an existing named property in a normalized object.
65  static void DeleteNormalizedProperty(Handle<JSReceiver> object, int entry);
66 
67  DECL_CAST(JSReceiver)
68 
69  // ES6 section 7.1.1 ToPrimitive
70  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ToPrimitive(
71  Handle<JSReceiver> receiver,
72  ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
73 
74  // ES6 section 7.1.1.1 OrdinaryToPrimitive
75  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> OrdinaryToPrimitive(
76  Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint);
77 
78  static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver);
79 
80  // Get the first non-hidden prototype.
81  static inline MaybeHandle<Object> GetPrototype(Isolate* isolate,
82  Handle<JSReceiver> receiver);
83 
84  V8_WARN_UNUSED_RESULT static Maybe<bool> HasInPrototypeChain(
85  Isolate* isolate, Handle<JSReceiver> object, Handle<Object> proto);
86 
87  // Reads all enumerable own properties of source and adds them to
88  // target, using either Set or CreateDataProperty depending on the
89  // use_set argument. This only copies values not present in the
90  // maybe_excluded_properties list.
91  V8_WARN_UNUSED_RESULT static Maybe<bool> SetOrCopyDataProperties(
92  Isolate* isolate, Handle<JSReceiver> target, Handle<Object> source,
93  const ScopedVector<Handle<Object>>* excluded_properties = nullptr,
94  bool use_set = true);
95 
96  // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
97  V8_WARN_UNUSED_RESULT static Maybe<bool> HasProperty(LookupIterator* it);
98  V8_WARN_UNUSED_RESULT static inline Maybe<bool> HasProperty(
99  Handle<JSReceiver> object, Handle<Name> name);
100  V8_WARN_UNUSED_RESULT static inline Maybe<bool> HasElement(
101  Handle<JSReceiver> object, uint32_t index);
102 
103  V8_WARN_UNUSED_RESULT static Maybe<bool> HasOwnProperty(
104  Handle<JSReceiver> object, Handle<Name> name);
105  V8_WARN_UNUSED_RESULT static inline Maybe<bool> HasOwnProperty(
106  Handle<JSReceiver> object, uint32_t index);
107 
108  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetProperty(
109  Isolate* isolate, Handle<JSReceiver> receiver, const char* key);
110  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetProperty(
111  Isolate* isolate, Handle<JSReceiver> receiver, Handle<Name> name);
112  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetElement(
113  Isolate* isolate, Handle<JSReceiver> receiver, uint32_t index);
114 
115  // Implementation of ES6 [[Delete]]
116  V8_WARN_UNUSED_RESULT static Maybe<bool> DeletePropertyOrElement(
117  Handle<JSReceiver> object, Handle<Name> name,
118  LanguageMode language_mode = LanguageMode::kSloppy);
119  V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteProperty(
120  Handle<JSReceiver> object, Handle<Name> name,
121  LanguageMode language_mode = LanguageMode::kSloppy);
122  V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteProperty(
123  LookupIterator* it, LanguageMode language_mode);
124  V8_WARN_UNUSED_RESULT static Maybe<bool> DeleteElement(
125  Handle<JSReceiver> object, uint32_t index,
126  LanguageMode language_mode = LanguageMode::kSloppy);
127 
128  V8_WARN_UNUSED_RESULT static Object* DefineProperty(
129  Isolate* isolate, Handle<Object> object, Handle<Object> name,
130  Handle<Object> attributes);
131  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> DefineProperties(
132  Isolate* isolate, Handle<Object> object, Handle<Object> properties);
133 
134  // "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation.
135  V8_WARN_UNUSED_RESULT static Maybe<bool> DefineOwnProperty(
136  Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key,
137  PropertyDescriptor* desc, ShouldThrow should_throw);
138 
139  // ES6 7.3.4 (when passed kDontThrow)
140  V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
141  Isolate* isolate, Handle<JSReceiver> object, Handle<Name> key,
142  Handle<Object> value, ShouldThrow should_throw);
143  V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
144  LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
145 
146  // ES6 9.1.6.1
147  V8_WARN_UNUSED_RESULT static Maybe<bool> OrdinaryDefineOwnProperty(
148  Isolate* isolate, Handle<JSObject> object, Handle<Object> key,
149  PropertyDescriptor* desc, ShouldThrow should_throw);
150  V8_WARN_UNUSED_RESULT static Maybe<bool> OrdinaryDefineOwnProperty(
151  LookupIterator* it, PropertyDescriptor* desc, ShouldThrow should_throw);
152  // ES6 9.1.6.2
153  V8_WARN_UNUSED_RESULT static Maybe<bool> IsCompatiblePropertyDescriptor(
154  Isolate* isolate, bool extensible, PropertyDescriptor* desc,
155  PropertyDescriptor* current, Handle<Name> property_name,
156  ShouldThrow should_throw);
157  // ES6 9.1.6.3
158  // |it| can be NULL in cases where the ES spec passes |undefined| as the
159  // receiver. Exactly one of |it| and |property_name| must be provided.
160  V8_WARN_UNUSED_RESULT static Maybe<bool> ValidateAndApplyPropertyDescriptor(
161  Isolate* isolate, LookupIterator* it, bool extensible,
162  PropertyDescriptor* desc, PropertyDescriptor* current,
163  ShouldThrow should_throw, Handle<Name> property_name);
164 
165  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static Maybe<bool>
166  GetOwnPropertyDescriptor(Isolate* isolate, Handle<JSReceiver> object,
168  V8_WARN_UNUSED_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
170 
171  typedef PropertyAttributes IntegrityLevel;
172 
173  // ES6 7.3.14 (when passed kDontThrow)
174  // 'level' must be SEALED or FROZEN.
175  V8_WARN_UNUSED_RESULT static Maybe<bool> SetIntegrityLevel(
176  Handle<JSReceiver> object, IntegrityLevel lvl, ShouldThrow should_throw);
177 
178  // ES6 7.3.15
179  // 'level' must be SEALED or FROZEN.
180  V8_WARN_UNUSED_RESULT static Maybe<bool> TestIntegrityLevel(
181  Handle<JSReceiver> object, IntegrityLevel lvl);
182 
183  // ES6 [[PreventExtensions]] (when passed kDontThrow)
184  V8_WARN_UNUSED_RESULT static Maybe<bool> PreventExtensions(
185  Handle<JSReceiver> object, ShouldThrow should_throw);
186 
187  V8_WARN_UNUSED_RESULT static Maybe<bool> IsExtensible(
188  Handle<JSReceiver> object);
189 
190  // Returns the class name ([[Class]] property in the specification).
191  V8_EXPORT_PRIVATE String class_name();
192 
193  // Returns the constructor (the function that was used to instantiate the
194  // object).
195  static MaybeHandle<JSFunction> GetConstructor(Handle<JSReceiver> receiver);
196 
197  // Returns the constructor name (the name (possibly, inferred name) of the
198  // function that was used to instantiate the object).
199  static Handle<String> GetConstructorName(Handle<JSReceiver> receiver);
200 
201  Handle<Context> GetCreationContext();
202 
203  V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
204  GetPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
205  V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
206  GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
207  V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
208  GetOwnPropertyAttributes(Handle<JSReceiver> object, uint32_t index);
209 
210  V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
211  GetElementAttributes(Handle<JSReceiver> object, uint32_t index);
212  V8_WARN_UNUSED_RESULT static inline Maybe<PropertyAttributes>
213  GetOwnElementAttributes(Handle<JSReceiver> object, uint32_t index);
214 
215  V8_WARN_UNUSED_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
216  LookupIterator* it);
217 
218  // Set the object's prototype (only JSReceiver and null are allowed values).
219  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPrototype(
220  Handle<JSReceiver> object, Handle<Object> value, bool from_javascript,
221  ShouldThrow should_throw);
222 
223  inline static Handle<Object> GetDataProperty(Handle<JSReceiver> object,
224  Handle<Name> name);
225  static Handle<Object> GetDataProperty(LookupIterator* it);
226 
227  // Retrieves a permanent object identity hash code. The undefined value might
228  // be returned in case no hash was created yet.
229  Object* GetIdentityHash();
230 
231  // Retrieves a permanent object identity hash code. May create and store a
232  // hash code if needed and none exists.
233  static Smi CreateIdentityHash(Isolate* isolate, JSReceiver* key);
234  Smi GetOrCreateIdentityHash(Isolate* isolate);
235 
236  // Stores the hash code. The hash passed in must be masked with
237  // JSReceiver::kHashMask.
238  void SetIdentityHash(int masked_hash);
239 
240  // ES6 [[OwnPropertyKeys]] (modulo return type)
241  V8_WARN_UNUSED_RESULT static inline MaybeHandle<FixedArray> OwnPropertyKeys(
242  Handle<JSReceiver> object);
243 
244  V8_WARN_UNUSED_RESULT static MaybeHandle<FixedArray> GetOwnValues(
245  Handle<JSReceiver> object, PropertyFilter filter,
246  bool try_fast_path = true);
247 
248  V8_WARN_UNUSED_RESULT static MaybeHandle<FixedArray> GetOwnEntries(
249  Handle<JSReceiver> object, PropertyFilter filter,
250  bool try_fast_path = true);
251 
252  V8_WARN_UNUSED_RESULT static Handle<FixedArray> GetOwnElementIndices(
253  Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSObject> object);
254 
255  static const int kHashMask = PropertyArray::HashField::kMask;
256 
257  // Layout description.
258  static const int kPropertiesOrHashOffset = HeapObject::kHeaderSize;
259  static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize;
260 
261  bool HasProxyInPrototype(Isolate* isolate);
262 
263  bool HasComplexElements();
264 
265  private:
266  DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
267 };
268 
269 // The JSObject describes real heap allocated JavaScript objects with
270 // properties.
271 // Note that the map of JSObject changes during execution to enable inline
272 // caching.
273 class JSObject : public JSReceiver {
274  public:
275  static bool IsUnmodifiedApiObject(ObjectSlot o);
276 
277  static V8_WARN_UNUSED_RESULT MaybeHandle<JSObject> New(
278  Handle<JSFunction> constructor, Handle<JSReceiver> new_target,
280 
281  static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object);
282 
283  // 9.1.12 ObjectCreate ( proto [ , internalSlotsList ] )
284  // Notice: This is NOT 19.1.2.2 Object.create ( O, Properties )
285  static V8_WARN_UNUSED_RESULT MaybeHandle<JSObject> ObjectCreate(
286  Isolate* isolate, Handle<Object> prototype);
287 
288  // [elements]: The elements (properties with names that are integers).
289  //
290  // Elements can be in two general modes: fast and slow. Each mode
291  // corresponds to a set of object representations of elements that
292  // have something in common.
293  //
294  // In the fast mode elements is a FixedArray and so each element can
295  // be quickly accessed. This fact is used in the generated code. The
296  // elements array can have one of three maps in this mode:
297  // fixed_array_map, sloppy_arguments_elements_map or
298  // fixed_cow_array_map (for copy-on-write arrays). In the latter case
299  // the elements array may be shared by a few objects and so before
300  // writing to any element the array must be copied. Use
301  // EnsureWritableFastElements in this case.
302  //
303  // In the slow mode the elements is either a NumberDictionary, a
304  // FixedArray parameter map for a (sloppy) arguments object.
305  DECL_ACCESSORS2(elements, FixedArrayBase)
306  inline void initialize_elements();
307  static inline void SetMapAndElements(Handle<JSObject> object, Handle<Map> map,
308  Handle<FixedArrayBase> elements);
309  inline ElementsKind GetElementsKind() const;
310  ElementsAccessor* GetElementsAccessor();
311  // Returns true if an object has elements of PACKED_SMI_ELEMENTS or
312  // HOLEY_SMI_ELEMENTS ElementsKind.
313  inline bool HasSmiElements();
314  // Returns true if an object has elements of PACKED_ELEMENTS or
315  // HOLEY_ELEMENTS ElementsKind.
316  inline bool HasObjectElements();
317  // Returns true if an object has elements of PACKED_SMI_ELEMENTS,
318  // HOLEY_SMI_ELEMENTS, PACKED_ELEMENTS, or HOLEY_ELEMENTS.
319  inline bool HasSmiOrObjectElements();
320  // Returns true if an object has any of the "fast" elements kinds.
321  inline bool HasFastElements();
322  // Returns true if an object has any of the PACKED elements kinds.
323  inline bool HasFastPackedElements();
324  // Returns true if an object has elements of PACKED_DOUBLE_ELEMENTS or
325  // HOLEY_DOUBLE_ELEMENTS ElementsKind.
326  inline bool HasDoubleElements();
327  // Returns true if an object has elements of HOLEY_SMI_ELEMENTS,
328  // HOLEY_DOUBLE_ELEMENTS, or HOLEY_ELEMENTS ElementsKind.
329  inline bool HasHoleyElements();
330  inline bool HasSloppyArgumentsElements();
331  inline bool HasStringWrapperElements();
332  inline bool HasDictionaryElements();
333 
334  inline bool HasFixedTypedArrayElements();
335 
336  inline bool HasFixedUint8ClampedElements();
337  inline bool HasFixedArrayElements();
338  inline bool HasFixedInt8Elements();
339  inline bool HasFixedUint8Elements();
340  inline bool HasFixedInt16Elements();
341  inline bool HasFixedUint16Elements();
342  inline bool HasFixedInt32Elements();
343  inline bool HasFixedUint32Elements();
344  inline bool HasFixedFloat32Elements();
345  inline bool HasFixedFloat64Elements();
346  inline bool HasFixedBigInt64Elements();
347  inline bool HasFixedBigUint64Elements();
348 
349  inline bool HasFastArgumentsElements();
350  inline bool HasSlowArgumentsElements();
351  inline bool HasFastStringWrapperElements();
352  inline bool HasSlowStringWrapperElements();
353  bool HasEnumerableElements();
354 
355  inline NumberDictionary element_dictionary(); // Gets slow elements.
356 
357  // Requires: HasFastElements().
358  static void EnsureWritableFastElements(Handle<JSObject> object);
359 
360  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPropertyWithInterceptor(
361  LookupIterator* it, ShouldThrow should_throw, Handle<Object> value);
362 
363  // The API currently still wants DefineOwnPropertyIgnoreAttributes to convert
364  // AccessorInfo objects to data fields. We allow FORCE_FIELD as an exception
365  // to the default behavior that calls the setter.
366  enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD };
367 
368  V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
369  DefineOwnPropertyIgnoreAttributes(
370  LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
371  AccessorInfoHandling handling = DONT_FORCE_FIELD);
372 
373  V8_WARN_UNUSED_RESULT static Maybe<bool> DefineOwnPropertyIgnoreAttributes(
374  LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
375  ShouldThrow should_throw,
376  AccessorInfoHandling handling = DONT_FORCE_FIELD);
377 
378  V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
379  SetOwnPropertyIgnoreAttributes(Handle<JSObject> object, Handle<Name> name,
380  Handle<Object> value,
381  PropertyAttributes attributes);
382 
383  V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
384  SetOwnElementIgnoreAttributes(Handle<JSObject> object, uint32_t index,
385  Handle<Object> value,
386  PropertyAttributes attributes);
387 
388  // Equivalent to one of the above depending on whether |name| can be converted
389  // to an array index.
390  V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
391  DefinePropertyOrElementIgnoreAttributes(Handle<JSObject> object,
392  Handle<Name> name,
393  Handle<Object> value,
394  PropertyAttributes attributes = NONE);
395 
396  // Adds or reconfigures a property to attributes NONE. It will fail when it
397  // cannot.
398  V8_WARN_UNUSED_RESULT static Maybe<bool> CreateDataProperty(
399  LookupIterator* it, Handle<Object> value,
400  ShouldThrow should_throw = kDontThrow);
401 
402  static void AddProperty(Isolate* isolate, Handle<JSObject> object,
403  Handle<Name> name, Handle<Object> value,
404  PropertyAttributes attributes);
405 
406  static void AddDataElement(Handle<JSObject> receiver, uint32_t index,
407  Handle<Object> value,
408  PropertyAttributes attributes);
409 
410  // Extend the receiver with a single fast property appeared first in the
411  // passed map. This also extends the property backing store if necessary.
412  static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map);
413 
414  // Migrates the given object to a map whose field representations are the
415  // lowest upper bound of all known representations for that field.
416  static void MigrateInstance(Handle<JSObject> instance);
417 
418  // Migrates the given object only if the target map is already available,
419  // or returns false if such a map is not yet available.
420  static bool TryMigrateInstance(Handle<JSObject> instance);
421 
422  // Sets the property value in a normalized object given (key, value, details).
423  // Handles the special representation of JS global objects.
424  static void SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name,
425  Handle<Object> value,
426  PropertyDetails details);
427  static void SetDictionaryElement(Handle<JSObject> object, uint32_t index,
428  Handle<Object> value,
429  PropertyAttributes attributes);
430  static void SetDictionaryArgumentsElement(Handle<JSObject> object,
431  uint32_t index,
432  Handle<Object> value,
433  PropertyAttributes attributes);
434 
435  static void OptimizeAsPrototype(Handle<JSObject> object,
436  bool enable_setup_mode = true);
437  static void ReoptimizeIfPrototype(Handle<JSObject> object);
438  static void MakePrototypesFast(Handle<Object> receiver,
439  WhereToStart where_to_start, Isolate* isolate);
440  static void LazyRegisterPrototypeUser(Handle<Map> user, Isolate* isolate);
441  static void UpdatePrototypeUserRegistration(Handle<Map> old_map,
442  Handle<Map> new_map,
443  Isolate* isolate);
444  static bool UnregisterPrototypeUser(Handle<Map> user, Isolate* isolate);
445  static Map InvalidatePrototypeChains(Map map);
446  static void InvalidatePrototypeValidityCell(JSGlobalObject* global);
447 
448  // Updates prototype chain tracking information when an object changes its
449  // map from |old_map| to |new_map|.
450  static void NotifyMapChange(Handle<Map> old_map, Handle<Map> new_map,
451  Isolate* isolate);
452 
453  // Utility used by many Array builtins and runtime functions
454  static inline bool PrototypeHasNoElements(Isolate* isolate, JSObject* object);
455 
456  // To be passed to PrototypeUsers::Compact.
457  static void PrototypeRegistryCompactionCallback(HeapObject* value,
458  int old_index, int new_index);
459 
460  // Retrieve interceptors.
461  inline InterceptorInfo* GetNamedInterceptor();
462  inline InterceptorInfo* GetIndexedInterceptor();
463 
464  // Used from JSReceiver.
465  V8_WARN_UNUSED_RESULT static Maybe<PropertyAttributes>
466  GetPropertyAttributesWithInterceptor(LookupIterator* it);
467  V8_WARN_UNUSED_RESULT static Maybe<PropertyAttributes>
468  GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it);
469 
470  // Defines an AccessorPair property on the given object.
471  // TODO(mstarzinger): Rename to SetAccessor().
472  static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object,
473  Handle<Name> name,
474  Handle<Object> getter,
475  Handle<Object> setter,
476  PropertyAttributes attributes);
477  static MaybeHandle<Object> DefineAccessor(LookupIterator* it,
478  Handle<Object> getter,
479  Handle<Object> setter,
480  PropertyAttributes attributes);
481 
482  // Defines an AccessorInfo property on the given object.
483  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> SetAccessor(
485  PropertyAttributes attributes);
486 
487  // The result must be checked first for exceptions. If there's no exception,
488  // the output parameter |done| indicates whether the interceptor has a result
489  // or not.
490  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor(
491  LookupIterator* it, bool* done);
492 
493  static void ValidateElements(JSObject* object);
494 
495  // Makes sure that this object can contain HeapObject as elements.
496  static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj);
497 
498  // Makes sure that this object can contain the specified elements.
499  static inline void EnsureCanContainElements(Handle<JSObject> object,
500  ObjectSlot elements,
501  uint32_t count,
502  EnsureElementsMode mode);
503  static inline void EnsureCanContainElements(Handle<JSObject> object,
504  Handle<FixedArrayBase> elements,
505  uint32_t length,
506  EnsureElementsMode mode);
507  static void EnsureCanContainElements(Handle<JSObject> object,
508  Arguments* arguments, uint32_t first_arg,
509  uint32_t arg_count,
510  EnsureElementsMode mode);
511 
512  // Would we convert a fast elements array to dictionary mode given
513  // an access at key?
514  bool WouldConvertToSlowElements(uint32_t index);
515 
516  static const uint32_t kMinAddedElementsCapacity = 16;
517 
518  // Computes the new capacity when expanding the elements of a JSObject.
519  static uint32_t NewElementsCapacity(uint32_t old_capacity) {
520  // (old_capacity + 50%) + kMinAddedElementsCapacity
521  return old_capacity + (old_capacity >> 1) + kMinAddedElementsCapacity;
522  }
523 
524  // These methods do not perform access checks!
525  template <AllocationSiteUpdateMode update_or_check =
526  AllocationSiteUpdateMode::kUpdate>
527  static bool UpdateAllocationSite(Handle<JSObject> object,
528  ElementsKind to_kind);
529 
530  // Lookup interceptors are used for handling properties controlled by host
531  // objects.
532  inline bool HasNamedInterceptor();
533  inline bool HasIndexedInterceptor();
534 
535  // Support functions for v8 api (needed for correct interceptor behavior).
536  V8_WARN_UNUSED_RESULT static Maybe<bool> HasRealNamedProperty(
537  Handle<JSObject> object, Handle<Name> name);
538  V8_WARN_UNUSED_RESULT static Maybe<bool> HasRealElementProperty(
539  Handle<JSObject> object, uint32_t index);
540  V8_WARN_UNUSED_RESULT static Maybe<bool> HasRealNamedCallbackProperty(
541  Handle<JSObject> object, Handle<Name> name);
542 
543  // Get the header size for a JSObject. Used to compute the index of
544  // embedder fields as well as the number of embedder fields.
545  // The |function_has_prototype_slot| parameter is needed only for
546  // JSFunction objects.
547  static int GetHeaderSize(InstanceType instance_type,
548  bool function_has_prototype_slot = false);
549  static inline int GetHeaderSize(const Map map);
550  inline int GetHeaderSize() const;
551 
552  static inline int GetEmbedderFieldCount(const Map map);
553  inline int GetEmbedderFieldCount() const;
554  inline int GetEmbedderFieldOffset(int index);
555  inline Object* GetEmbedderField(int index);
556  inline void SetEmbedderField(int index, Object* value);
557  inline void SetEmbedderField(int index, Smi value);
558 
559  // Returns true when the object is potentially a wrapper that gets special
560  // garbage collection treatment.
561  // TODO(mlippautz): Make check exact and replace the pattern match in
562  // Heap::TracePossibleWrapper.
563  bool IsApiWrapper();
564 
565  // Same as IsApiWrapper() but also allow dropping the wrapper on minor GCs.
566  bool IsDroppableApiWrapper();
567 
568  // Returns a new map with all transitions dropped from the object's current
569  // map and the ElementsKind set.
570  static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
571  ElementsKind to_kind);
572  static void TransitionElementsKind(Handle<JSObject> object,
573  ElementsKind to_kind);
574 
575  // Always use this to migrate an object to a new map.
576  // |expected_additional_properties| is only used for fast-to-slow transitions
577  // and ignored otherwise.
578  static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map,
579  int expected_additional_properties = 0);
580 
581  // Forces a prototype without any of the checks that the regular SetPrototype
582  // would do.
583  static void ForceSetPrototype(Handle<JSObject> object, Handle<Object> proto);
584 
585  // Convert the object to use the canonical dictionary
586  // representation. If the object is expected to have additional properties
587  // added this number can be indicated to have the backing store allocated to
588  // an initial capacity for holding these properties.
589  static void NormalizeProperties(Handle<JSObject> object,
590  PropertyNormalizationMode mode,
591  int expected_additional_properties,
592  const char* reason);
593 
594  // Convert and update the elements backing store to be a
595  // NumberDictionary dictionary. Returns the backing after conversion.
596  static Handle<NumberDictionary> NormalizeElements(Handle<JSObject> object);
597 
598  void RequireSlowElements(NumberDictionary dictionary);
599 
600  // Transform slow named properties to fast variants.
601  static void MigrateSlowToFast(Handle<JSObject> object,
602  int unused_property_fields, const char* reason);
603 
604  inline bool IsUnboxedDoubleField(FieldIndex index);
605 
606  // Access fast-case object properties at index.
607  static Handle<Object> FastPropertyAt(Handle<JSObject> object,
608  Representation representation,
609  FieldIndex index);
610  inline Object* RawFastPropertyAt(FieldIndex index);
611  inline double RawFastDoublePropertyAt(FieldIndex index);
612  inline uint64_t RawFastDoublePropertyAsBitsAt(FieldIndex index);
613 
614  inline void FastPropertyAtPut(FieldIndex index, Object* value);
615  inline void RawFastPropertyAtPut(FieldIndex index, Object* value);
616  inline void RawFastDoublePropertyAsBitsAtPut(FieldIndex index, uint64_t bits);
617  inline void WriteToField(int descriptor, PropertyDetails details,
618  Object* value);
619 
620  // Access to in object properties.
621  inline int GetInObjectPropertyOffset(int index);
622  inline Object* InObjectPropertyAt(int index);
623  inline Object* InObjectPropertyAtPut(
624  int index, Object* value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
625 
626  // Set the object's prototype (only JSReceiver and null are allowed values).
627  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPrototype(
628  Handle<JSObject> object, Handle<Object> value, bool from_javascript,
629  ShouldThrow should_throw);
630 
631  // Makes the object prototype immutable
632  // Never called from JavaScript
633  static void SetImmutableProto(Handle<JSObject> object);
634 
635  // Initializes the body starting at |start_offset|. It is responsibility of
636  // the caller to initialize object header. Fill the pre-allocated fields with
637  // pre_allocated_value and the rest with filler_value.
638  // Note: this call does not update write barrier, the caller is responsible
639  // to ensure that |filler_value| can be collected without WB here.
640  inline void InitializeBody(Map map, int start_offset,
641  Object* pre_allocated_value, Object* filler_value);
642 
643  // Check whether this object references another object
644  bool ReferencesObject(Object* obj);
645 
646  V8_WARN_UNUSED_RESULT static Maybe<bool> TestIntegrityLevel(
647  Handle<JSObject> object, IntegrityLevel lvl);
648 
649  V8_WARN_UNUSED_RESULT static Maybe<bool> PreventExtensions(
650  Handle<JSObject> object, ShouldThrow should_throw);
651 
652  static bool IsExtensible(Handle<JSObject> object);
653 
654  DECL_CAST(JSObject)
655 
656  // Dispatched behavior.
657  void JSObjectShortPrint(StringStream* accumulator);
658  DECL_PRINTER(JSObject)
659  DECL_VERIFIER(JSObject)
660 #ifdef OBJECT_PRINT
661  bool PrintProperties(std::ostream& os); // NOLINT
662  void PrintElements(std::ostream& os); // NOLINT
663 #endif
664 #if defined(DEBUG) || defined(OBJECT_PRINT)
665  void PrintTransitions(std::ostream& os); // NOLINT
666 #endif
667 
668  static void PrintElementsTransition(FILE* file, Handle<JSObject> object,
669  ElementsKind from_kind,
670  Handle<FixedArrayBase> from_elements,
671  ElementsKind to_kind,
672  Handle<FixedArrayBase> to_elements);
673 
674  void PrintInstanceMigration(FILE* file, Map original_map, Map new_map);
675 
676 #ifdef DEBUG
677  // Structure for collecting spill information about JSObjects.
678  class SpillInformation {
679  public:
680  void Clear();
681  void Print();
682  int number_of_objects_;
683  int number_of_objects_with_fast_properties_;
684  int number_of_objects_with_fast_elements_;
685  int number_of_fast_used_fields_;
686  int number_of_fast_unused_fields_;
687  int number_of_slow_used_properties_;
688  int number_of_slow_unused_properties_;
689  int number_of_fast_used_elements_;
690  int number_of_fast_unused_elements_;
691  int number_of_slow_used_elements_;
692  int number_of_slow_unused_elements_;
693  };
694 
695  void IncrementSpillStatistics(Isolate* isolate, SpillInformation* info);
696 #endif
697 
698 #ifdef VERIFY_HEAP
699  // If a GC was caused while constructing this object, the elements pointer
700  // may point to a one pointer filler map. The object won't be rooted, but
701  // our heap verification code could stumble across it.
702  bool ElementsAreSafeToExamine() const;
703 #endif
704 
705  Object* SlowReverseLookup(Object* value);
706 
707  // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
708  // Also maximal value of JSArray's length property.
709  static const uint32_t kMaxElementCount = 0xffffffffu;
710 
711  // Constants for heuristics controlling conversion of fast elements
712  // to slow elements.
713 
714  // Maximal gap that can be introduced by adding an element beyond
715  // the current elements length.
716  static const uint32_t kMaxGap = 1024;
717 
718  // Maximal length of fast elements array that won't be checked for
719  // being dense enough on expansion.
720  static const int kMaxUncheckedFastElementsLength = 5000;
721 
722  // Same as above but for old arrays. This limit is more strict. We
723  // don't want to be wasteful with long lived objects.
724  static const int kMaxUncheckedOldFastElementsLength = 500;
725 
726  // This constant applies only to the initial map of "global.Object" and
727  // not to arbitrary other JSObject maps.
728  static const int kInitialGlobalObjectUnusedPropertiesCount = 4;
729 
730  static const int kMaxInstanceSize = 255 * kPointerSize;
731 
732  // When extending the backing storage for property values, we increase
733  // its size by more than the 1 entry necessary, so sequentially adding fields
734  // to the same object requires fewer allocations and copies.
735  static const int kFieldsAdded = 3;
736  STATIC_ASSERT(kMaxNumberOfDescriptors + kFieldsAdded <=
737  PropertyArray::kMaxLength);
738 
739  // Layout description.
740  static const int kElementsOffset = JSReceiver::kHeaderSize;
741  static const int kHeaderSize = kElementsOffset + kPointerSize;
742 
743  STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize);
744  static const int kMaxInObjectProperties =
745  (kMaxInstanceSize - kHeaderSize) >> kPointerSizeLog2;
746  STATIC_ASSERT(kMaxInObjectProperties <= kMaxNumberOfDescriptors);
747  // TODO(cbruni): Revisit calculation of the max supported embedder fields.
748  static const int kMaxEmbedderFields =
749  (((1 << kFirstInobjectPropertyOffsetBitCount) - 1 - kHeaderSize) >>
750  kPointerSizeLog2) /
751  kEmbedderDataSlotSizeInTaggedSlots;
752  STATIC_ASSERT(kMaxEmbedderFields <= kMaxInObjectProperties);
753 
754  class BodyDescriptor;
755 
756  class FastBodyDescriptor;
757 
758  // Gets the number of currently used elements.
759  int GetFastElementsUsage();
760 
761  static bool AllCanRead(LookupIterator* it);
762  static bool AllCanWrite(LookupIterator* it);
763 
764  private:
765  friend class JSReceiver;
766  friend class Object;
767 
768  // Used from Object::GetProperty().
769  V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
770  GetPropertyWithFailedAccessCheck(LookupIterator* it);
771 
772  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPropertyWithFailedAccessCheck(
773  LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
774 
775  V8_WARN_UNUSED_RESULT static Maybe<bool> DeletePropertyWithInterceptor(
776  LookupIterator* it, ShouldThrow should_throw);
777 
778  bool ReferencesObjectFromElements(FixedArray elements, ElementsKind kind,
779  Object* object);
780 
781  // Helper for fast versions of preventExtensions, seal, and freeze.
782  // attrs is one of NONE, SEALED, or FROZEN (depending on the operation).
783  template <PropertyAttributes attrs>
784  V8_WARN_UNUSED_RESULT static Maybe<bool> PreventExtensionsWithTransition(
785  Handle<JSObject> object, ShouldThrow should_throw);
786 
787  DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
788 };
789 
790 // JSAccessorPropertyDescriptor is just a JSObject with a specific initial
791 // map. This initial map adds in-object properties for "get", "set",
792 // "enumerable" and "configurable" properties, as assigned by the
793 // FromPropertyDescriptor function for regular accessor properties.
795  public:
796  // Offsets of object fields.
797  static const int kGetOffset = JSObject::kHeaderSize;
798  static const int kSetOffset = kGetOffset + kPointerSize;
799  static const int kEnumerableOffset = kSetOffset + kPointerSize;
800  static const int kConfigurableOffset = kEnumerableOffset + kPointerSize;
801  static const int kSize = kConfigurableOffset + kPointerSize;
802  // Indices of in-object properties.
803  static const int kGetIndex = 0;
804  static const int kSetIndex = 1;
805  static const int kEnumerableIndex = 2;
806  static const int kConfigurableIndex = 3;
807 
808  private:
809  DISALLOW_IMPLICIT_CONSTRUCTORS(JSAccessorPropertyDescriptor);
810 };
811 
812 // JSDataPropertyDescriptor is just a JSObject with a specific initial map.
813 // This initial map adds in-object properties for "value", "writable",
814 // "enumerable" and "configurable" properties, as assigned by the
815 // FromPropertyDescriptor function for regular data properties.
817  public:
818  // Offsets of object fields.
819  static const int kValueOffset = JSObject::kHeaderSize;
820  static const int kWritableOffset = kValueOffset + kPointerSize;
821  static const int kEnumerableOffset = kWritableOffset + kPointerSize;
822  static const int kConfigurableOffset = kEnumerableOffset + kPointerSize;
823  static const int kSize = kConfigurableOffset + kPointerSize;
824  // Indices of in-object properties.
825  static const int kValueIndex = 0;
826  static const int kWritableIndex = 1;
827  static const int kEnumerableIndex = 2;
828  static const int kConfigurableIndex = 3;
829 
830  private:
831  DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataPropertyDescriptor);
832 };
833 
834 // JSIteratorResult is just a JSObject with a specific initial map.
835 // This initial map adds in-object properties for "done" and "value",
836 // as specified by ES6 section 25.1.1.3 The IteratorResult Interface
837 class JSIteratorResult : public JSObject {
838  public:
839  DECL_ACCESSORS(value, Object)
840 
841  DECL_ACCESSORS(done, Object)
842 
843  // Offsets of object fields.
844  static const int kValueOffset = JSObject::kHeaderSize;
845  static const int kDoneOffset = kValueOffset + kPointerSize;
846  static const int kSize = kDoneOffset + kPointerSize;
847  // Indices of in-object properties.
848  static const int kValueIndex = 0;
849  static const int kDoneIndex = 1;
850 
851  private:
852  DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult);
853 };
854 
855 // JSBoundFunction describes a bound function exotic object.
856 class JSBoundFunction : public JSObject {
857  public:
858  // [bound_target_function]: The wrapped function object.
859  inline Object* raw_bound_target_function() const;
860  DECL_ACCESSORS(bound_target_function, JSReceiver)
861 
862  // [bound_this]: The value that is always passed as the this value when
863  // calling the wrapped function.
864  DECL_ACCESSORS(bound_this, Object)
865 
866  // [bound_arguments]: A list of values whose elements are used as the first
867  // arguments to any call to the wrapped function.
868  DECL_ACCESSORS2(bound_arguments, FixedArray)
869 
870  static MaybeHandle<String> GetName(Isolate* isolate,
871  Handle<JSBoundFunction> function);
872  static Maybe<int> GetLength(Isolate* isolate,
873  Handle<JSBoundFunction> function);
874  static MaybeHandle<Context> GetFunctionRealm(
875  Handle<JSBoundFunction> function);
876 
877  DECL_CAST(JSBoundFunction)
878 
879  // Dispatched behavior.
880  DECL_PRINTER(JSBoundFunction)
881  DECL_VERIFIER(JSBoundFunction)
882 
883  // The bound function's string representation implemented according
884  // to ES6 section 19.2.3.5 Function.prototype.toString ( ).
885  static Handle<String> ToString(Handle<JSBoundFunction> function);
886 
887  // Layout description.
888  static const int kBoundTargetFunctionOffset = JSObject::kHeaderSize;
889  static const int kBoundThisOffset = kBoundTargetFunctionOffset + kPointerSize;
890  static const int kBoundArgumentsOffset = kBoundThisOffset + kPointerSize;
891  static const int kSize = kBoundArgumentsOffset + kPointerSize;
892 
893  private:
894  DISALLOW_IMPLICIT_CONSTRUCTORS(JSBoundFunction);
895 };
896 
897 // JSFunction describes JavaScript functions.
898 class JSFunction : public JSObject {
899  public:
900  // [prototype_or_initial_map]:
901  DECL_ACCESSORS(prototype_or_initial_map, Object)
902 
903  // [shared]: The information about the function that
904  // can be shared by instances.
905  DECL_ACCESSORS(shared, SharedFunctionInfo)
906 
907  static const int kLengthDescriptorIndex = 0;
908  static const int kNameDescriptorIndex = 1;
909  // Home object descriptor index when function has a [[HomeObject]] slot.
910  static const int kMaybeHomeObjectDescriptorIndex = 2;
911 
912  // [context]: The context for this function.
913  inline Context context();
914  inline bool has_context() const;
915  inline void set_context(Object* context);
916  inline JSGlobalProxy* global_proxy();
917  inline Context native_context();
918 
919  static Handle<Object> GetName(Isolate* isolate, Handle<JSFunction> function);
920  static Maybe<int> GetLength(Isolate* isolate, Handle<JSFunction> function);
921  static Handle<Context> GetFunctionRealm(Handle<JSFunction> function);
922 
923  // [code]: The generated code object for this function. Executed
924  // when the function is invoked, e.g. foo() or new foo(). See
925  // [[Call]] and [[Construct]] description in ECMA-262, section
926  // 8.6.2, page 27.
927  inline Code code();
928  inline void set_code(Code code);
929  inline void set_code_no_write_barrier(Code code);
930 
931  // Get the abstract code associated with the function, which will either be
932  // a Code object or a BytecodeArray.
933  inline AbstractCode abstract_code();
934 
935  // Tells whether or not this function is interpreted.
936  //
937  // Note: function->IsInterpreted() does not necessarily return the same value
938  // as function->shared()->IsInterpreted() because the closure might have been
939  // optimized.
940  inline bool IsInterpreted();
941 
942  // Tells whether or not this function checks its optimization marker in its
943  // feedback vector.
944  inline bool ChecksOptimizationMarker();
945 
946  // Tells whether or not this function holds optimized code.
947  //
948  // Note: Returning false does not necessarily mean that this function hasn't
949  // been optimized, as it may have optimized code on its feedback vector.
950  inline bool IsOptimized();
951 
952  // Tells whether or not this function has optimized code available to it,
953  // either because it is optimized or because it has optimized code in its
954  // feedback vector.
955  inline bool HasOptimizedCode();
956 
957  // Tells whether or not this function has a (non-zero) optimization marker.
958  inline bool HasOptimizationMarker();
959 
960  // Mark this function for lazy recompilation. The function will be recompiled
961  // the next time it is executed.
962  void MarkForOptimization(ConcurrencyMode mode);
963 
964  // Tells whether or not the function is already marked for lazy recompilation.
965  inline bool IsMarkedForOptimization();
966  inline bool IsMarkedForConcurrentOptimization();
967 
968  // Tells whether or not the function is on the concurrent recompilation queue.
969  inline bool IsInOptimizationQueue();
970 
971  // Clears the optimized code slot in the function's feedback vector.
972  inline void ClearOptimizedCodeSlot(const char* reason);
973 
974  // Sets the optimization marker in the function's feedback vector.
975  inline void SetOptimizationMarker(OptimizationMarker marker);
976 
977  // Clears the optimization marker in the function's feedback vector.
978  inline void ClearOptimizationMarker();
979 
980  // If slack tracking is active, it computes instance size of the initial map
981  // with minimum permissible object slack. If it is not active, it simply
982  // returns the initial map's instance size.
983  int ComputeInstanceSizeWithMinSlack(Isolate* isolate);
984 
985  // Completes inobject slack tracking on initial map if it is active.
986  inline void CompleteInobjectSlackTrackingIfActive();
987 
988  // [feedback_cell]: The FeedbackCell used to hold the FeedbackVector
989  // eventually.
990  DECL_ACCESSORS(feedback_cell, FeedbackCell)
991 
992  // feedback_vector() can be used once the function is compiled.
993  inline FeedbackVector* feedback_vector() const;
994  inline bool has_feedback_vector() const;
995  static void EnsureFeedbackVector(Handle<JSFunction> function);
996 
997  // Unconditionally clear the type feedback vector.
998  void ClearTypeFeedbackInfo();
999 
1000  inline bool has_prototype_slot() const;
1001 
1002  // The initial map for an object created by this constructor.
1003  inline Map initial_map();
1004  static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map,
1005  Handle<Object> prototype);
1006  inline bool has_initial_map();
1007  static void EnsureHasInitialMap(Handle<JSFunction> function);
1008 
1009  // Creates a map that matches the constructor's initial map, but with
1010  // [[prototype]] being new.target.prototype. Because new.target can be a
1011  // JSProxy, this can call back into JavaScript.
1012  static V8_WARN_UNUSED_RESULT MaybeHandle<Map> GetDerivedMap(
1013  Isolate* isolate, Handle<JSFunction> constructor,
1014  Handle<JSReceiver> new_target);
1015 
1016  // Get and set the prototype property on a JSFunction. If the
1017  // function has an initial map the prototype is set on the initial
1018  // map. Otherwise, the prototype is put in the initial map field
1019  // until an initial map is needed.
1020  inline bool has_prototype();
1021  inline bool has_instance_prototype();
1022  inline Object* prototype();
1023  inline Object* instance_prototype();
1024  inline bool has_prototype_property();
1025  inline bool PrototypeRequiresRuntimeLookup();
1026  static void SetPrototype(Handle<JSFunction> function, Handle<Object> value);
1027 
1028  // Returns if this function has been compiled to native code yet.
1029  inline bool is_compiled();
1030 
1031  static int GetHeaderSize(bool function_has_prototype_slot) {
1032  return function_has_prototype_slot ? JSFunction::kSizeWithPrototype
1033  : JSFunction::kSizeWithoutPrototype;
1034  }
1035 
1036  // Prints the name of the function using PrintF.
1037  void PrintName(FILE* out = stdout);
1038 
1039  DECL_CAST(JSFunction)
1040 
1041  // Calculate the instance size and in-object properties count.
1042  static bool CalculateInstanceSizeForDerivedClass(
1043  Handle<JSFunction> function, InstanceType instance_type,
1044  int requested_embedder_fields, int* instance_size,
1045  int* in_object_properties);
1046  static void CalculateInstanceSizeHelper(InstanceType instance_type,
1047  bool has_prototype_slot,
1048  int requested_embedder_fields,
1049  int requested_in_object_properties,
1050  int* instance_size,
1051  int* in_object_properties);
1052 
1053  class BodyDescriptor;
1054 
1055  // Dispatched behavior.
1056  DECL_PRINTER(JSFunction)
1057  DECL_VERIFIER(JSFunction)
1058 
1059  // The function's name if it is configured, otherwise shared function info
1060  // debug name.
1061  static Handle<String> GetName(Handle<JSFunction> function);
1062 
1063  // ES6 section 9.2.11 SetFunctionName
1064  // Because of the way this abstract operation is used in the spec,
1065  // it should never fail, but in practice it will fail if the generated
1066  // function name's length exceeds String::kMaxLength.
1067  static V8_WARN_UNUSED_RESULT bool SetName(Handle<JSFunction> function,
1068  Handle<Name> name,
1069  Handle<String> prefix);
1070 
1071  // The function's displayName if it is set, otherwise name if it is
1072  // configured, otherwise shared function info
1073  // debug name.
1074  static Handle<String> GetDebugName(Handle<JSFunction> function);
1075 
1076  // The function's string representation implemented according to
1077  // ES6 section 19.2.3.5 Function.prototype.toString ( ).
1078  static Handle<String> ToString(Handle<JSFunction> function);
1079 
1080 // Layout description.
1081 #define JS_FUNCTION_FIELDS(V) \
1082  /* Pointer fields. */ \
1083  V(kSharedFunctionInfoOffset, kPointerSize) \
1084  V(kContextOffset, kPointerSize) \
1085  V(kFeedbackCellOffset, kPointerSize) \
1086  V(kEndOfStrongFieldsOffset, 0) \
1087  V(kCodeOffset, kPointerSize) \
1088  /* Size of JSFunction object without prototype field. */ \
1089  V(kSizeWithoutPrototype, 0) \
1090  V(kPrototypeOrInitialMapOffset, kPointerSize) \
1091  /* Size of JSFunction object with prototype field. */ \
1092  V(kSizeWithPrototype, 0)
1093 
1094  DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_FUNCTION_FIELDS)
1095 #undef JS_FUNCTION_FIELDS
1096 
1097  private:
1098  DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
1099 };
1100 
1101 // JSGlobalProxy's prototype must be a JSGlobalObject or null,
1102 // and the prototype is hidden. JSGlobalProxy always delegates
1103 // property accesses to its prototype if the prototype is not null.
1104 //
1105 // A JSGlobalProxy can be reinitialized which will preserve its identity.
1106 //
1107 // Accessing a JSGlobalProxy requires security check.
1108 
1109 class JSGlobalProxy : public JSObject {
1110  public:
1111  // [native_context]: the owner native context of this global proxy object.
1112  // It is null value if this object is not used by any context.
1113  DECL_ACCESSORS(native_context, Object)
1114 
1115  DECL_CAST(JSGlobalProxy)
1116 
1117  inline bool IsDetachedFrom(JSGlobalObject* global) const;
1118 
1119  static int SizeWithEmbedderFields(int embedder_field_count);
1120 
1121  // Dispatched behavior.
1122  DECL_PRINTER(JSGlobalProxy)
1123  DECL_VERIFIER(JSGlobalProxy)
1124 
1125  // Layout description.
1126  static const int kNativeContextOffset = JSObject::kHeaderSize;
1127  static const int kSize = kNativeContextOffset + kPointerSize;
1128 
1129  private:
1130  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
1131 };
1132 
1133 // JavaScript global object.
1134 class JSGlobalObject : public JSObject {
1135  public:
1136  // [native context]: the natives corresponding to this global object.
1137  DECL_ACCESSORS2(native_context, Context)
1138 
1139  // [global proxy]: the global proxy object of the context
1140  DECL_ACCESSORS(global_proxy, JSObject)
1141 
1142  // Gets global object properties.
1143  inline GlobalDictionary global_dictionary();
1144  inline void set_global_dictionary(GlobalDictionary dictionary);
1145 
1146  static void InvalidatePropertyCell(Handle<JSGlobalObject> object,
1147  Handle<Name> name);
1148  // Ensure that the global object has a cell for the given property name.
1149  static Handle<PropertyCell> EnsureEmptyPropertyCell(
1150  Handle<JSGlobalObject> global, Handle<Name> name,
1151  PropertyCellType cell_type, int* entry_out = nullptr);
1152 
1153  DECL_CAST(JSGlobalObject)
1154 
1155  inline bool IsDetached();
1156 
1157  // Dispatched behavior.
1158  DECL_PRINTER(JSGlobalObject)
1159  DECL_VERIFIER(JSGlobalObject)
1160 
1161  // Layout description.
1162  static const int kNativeContextOffset = JSObject::kHeaderSize;
1163  static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize;
1164  static const int kHeaderSize = kGlobalProxyOffset + kPointerSize;
1165  static const int kSize = kHeaderSize;
1166 
1167  private:
1168  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
1169 };
1170 
1171 // Representation for JS Wrapper objects, String, Number, Boolean, etc.
1172 class JSValue : public JSObject {
1173  public:
1174  // [value]: the object being wrapped.
1175  DECL_ACCESSORS(value, Object)
1176 
1177  DECL_CAST(JSValue)
1178 
1179  // Dispatched behavior.
1180  DECL_PRINTER(JSValue)
1181  DECL_VERIFIER(JSValue)
1182 
1183  // Layout description.
1184  static const int kValueOffset = JSObject::kHeaderSize;
1185  static const int kSize = kValueOffset + kPointerSize;
1186 
1187  private:
1188  DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
1189 };
1190 
1191 class DateCache;
1192 
1193 // Representation for JS date objects.
1194 class JSDate : public JSObject {
1195  public:
1196  static V8_WARN_UNUSED_RESULT MaybeHandle<JSDate> New(
1197  Handle<JSFunction> constructor, Handle<JSReceiver> new_target, double tv);
1198 
1199  // If one component is NaN, all of them are, indicating a NaN time value.
1200  // [value]: the time value.
1201  DECL_ACCESSORS(value, Object)
1202  // [year]: caches year. Either undefined, smi, or NaN.
1203  DECL_ACCESSORS(year, Object)
1204  // [month]: caches month. Either undefined, smi, or NaN.
1205  DECL_ACCESSORS(month, Object)
1206  // [day]: caches day. Either undefined, smi, or NaN.
1207  DECL_ACCESSORS(day, Object)
1208  // [weekday]: caches day of week. Either undefined, smi, or NaN.
1209  DECL_ACCESSORS(weekday, Object)
1210  // [hour]: caches hours. Either undefined, smi, or NaN.
1211  DECL_ACCESSORS(hour, Object)
1212  // [min]: caches minutes. Either undefined, smi, or NaN.
1213  DECL_ACCESSORS(min, Object)
1214  // [sec]: caches seconds. Either undefined, smi, or NaN.
1215  DECL_ACCESSORS(sec, Object)
1216  // [cache stamp]: sample of the date cache stamp at the
1217  // moment when chached fields were cached.
1218  DECL_ACCESSORS(cache_stamp, Object)
1219 
1220  DECL_CAST(JSDate)
1221 
1222  // Returns the time value (UTC) identifying the current time.
1223  static double CurrentTimeValue(Isolate* isolate);
1224 
1225  // Returns the date field with the specified index.
1226  // See FieldIndex for the list of date fields.
1227  // {smi_index} is a raw Address because this is called via ExternalReference.
1228  static Object* GetField(Object* date, Address smi_index);
1229 
1230  static Handle<Object> SetValue(Handle<JSDate> date, double v);
1231 
1232  void SetValue(Object* value, bool is_value_nan);
1233 
1234  // Dispatched behavior.
1235  DECL_PRINTER(JSDate)
1236  DECL_VERIFIER(JSDate)
1237 
1238  // The order is important. It must be kept in sync with date macros
1239  // in macros.py.
1240  enum FieldIndex {
1241  kDateValue,
1242  kYear,
1243  kMonth,
1244  kDay,
1245  kWeekday,
1246  kHour,
1247  kMinute,
1248  kSecond,
1249  kFirstUncachedField,
1250  kMillisecond = kFirstUncachedField,
1251  kDays,
1252  kTimeInDay,
1253  kFirstUTCField,
1254  kYearUTC = kFirstUTCField,
1255  kMonthUTC,
1256  kDayUTC,
1257  kWeekdayUTC,
1258  kHourUTC,
1259  kMinuteUTC,
1260  kSecondUTC,
1261  kMillisecondUTC,
1262  kDaysUTC,
1263  kTimeInDayUTC,
1264  kTimezoneOffset
1265  };
1266 
1267  // Layout description.
1268  static const int kValueOffset = JSObject::kHeaderSize;
1269  static const int kYearOffset = kValueOffset + kPointerSize;
1270  static const int kMonthOffset = kYearOffset + kPointerSize;
1271  static const int kDayOffset = kMonthOffset + kPointerSize;
1272  static const int kWeekdayOffset = kDayOffset + kPointerSize;
1273  static const int kHourOffset = kWeekdayOffset + kPointerSize;
1274  static const int kMinOffset = kHourOffset + kPointerSize;
1275  static const int kSecOffset = kMinOffset + kPointerSize;
1276  static const int kCacheStampOffset = kSecOffset + kPointerSize;
1277  static const int kSize = kCacheStampOffset + kPointerSize;
1278 
1279  private:
1280  inline Object* DoGetField(FieldIndex index);
1281 
1282  Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
1283 
1284  // Computes and caches the cacheable fields of the date.
1285  inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache);
1286 
1287  DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate);
1288 };
1289 
1290 // Representation of message objects used for error reporting through
1291 // the API. The messages are formatted in JavaScript so this object is
1292 // a real JavaScript object. The information used for formatting the
1293 // error messages are not directly accessible from JavaScript to
1294 // prevent leaking information to user code called during error
1295 // formatting.
1296 class JSMessageObject : public JSObject {
1297  public:
1298  // [type]: the type of error message.
1299  inline MessageTemplate type() const;
1300  inline void set_type(MessageTemplate value);
1301 
1302  // [arguments]: the arguments for formatting the error message.
1303  DECL_ACCESSORS(argument, Object)
1304 
1305  // [script]: the script from which the error message originated.
1306  DECL_ACCESSORS(script, Script)
1307 
1308  // [stack_frames]: an array of stack frames for this error object.
1309  DECL_ACCESSORS(stack_frames, Object)
1310 
1311  // [start_position]: the start position in the script for the error message.
1312  inline int start_position() const;
1313  inline void set_start_position(int value);
1314 
1315  // [end_position]: the end position in the script for the error message.
1316  inline int end_position() const;
1317  inline void set_end_position(int value);
1318 
1319  // Returns the line number for the error message (1-based), or
1320  // Message::kNoLineNumberInfo if the line cannot be determined.
1321  int GetLineNumber() const;
1322 
1323  // Returns the offset of the given position within the containing line.
1324  int GetColumnNumber() const;
1325 
1326  // Returns the source code line containing the given source
1327  // position, or the empty string if the position is invalid.
1328  Handle<String> GetSourceLine() const;
1329 
1330  inline int error_level() const;
1331  inline void set_error_level(int level);
1332 
1333  DECL_CAST(JSMessageObject)
1334 
1335  // Dispatched behavior.
1336  DECL_PRINTER(JSMessageObject)
1337  DECL_VERIFIER(JSMessageObject)
1338 
1339  // Layout description.
1340  static const int kTypeOffset = JSObject::kHeaderSize;
1341  static const int kArgumentsOffset = kTypeOffset + kPointerSize;
1342  static const int kScriptOffset = kArgumentsOffset + kPointerSize;
1343  static const int kStackFramesOffset = kScriptOffset + kPointerSize;
1344  static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
1345  static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
1346  static const int kErrorLevelOffset = kEndPositionOffset + kPointerSize;
1347  static const int kSize = kErrorLevelOffset + kPointerSize;
1348 
1349  typedef FixedBodyDescriptor<HeapObject::kMapOffset,
1350  kStackFramesOffset + kPointerSize, kSize>
1352 };
1353 
1354 // The [Async-from-Sync Iterator] object
1355 // (proposal-async-iteration/#sec-async-from-sync-iterator-objects)
1356 // An object which wraps an ordinary Iterator and converts it to behave
1357 // according to the Async Iterator protocol.
1358 // (See https://tc39.github.io/proposal-async-iteration/#sec-iteration)
1360  public:
1361  DECL_CAST(JSAsyncFromSyncIterator)
1362  DECL_PRINTER(JSAsyncFromSyncIterator)
1363  DECL_VERIFIER(JSAsyncFromSyncIterator)
1364 
1365  // Async-from-Sync Iterator instances are ordinary objects that inherit
1366  // properties from the %AsyncFromSyncIteratorPrototype% intrinsic object.
1367  // Async-from-Sync Iterator instances are initially created with the internal
1368  // slots listed in Table 4.
1369  // (proposal-async-iteration/#table-async-from-sync-iterator-internal-slots)
1370  DECL_ACCESSORS(sync_iterator, JSReceiver)
1371 
1372  // The "next" method is loaded during GetIterator, and is not reloaded for
1373  // subsequent "next" invocations.
1374  DECL_ACCESSORS(next, Object)
1375 
1376  // Offsets of object fields.
1377  static const int kSyncIteratorOffset = JSObject::kHeaderSize;
1378  static const int kNextOffset = kSyncIteratorOffset + kPointerSize;
1379  static const int kSize = kNextOffset + kPointerSize;
1380 
1381  private:
1382  DISALLOW_IMPLICIT_CONSTRUCTORS(JSAsyncFromSyncIterator);
1383 };
1384 
1385 class JSStringIterator : public JSObject {
1386  public:
1387  // Dispatched behavior.
1388  DECL_PRINTER(JSStringIterator)
1389  DECL_VERIFIER(JSStringIterator)
1390 
1391  DECL_CAST(JSStringIterator)
1392 
1393  // [string]: the [[IteratedString]] inobject property.
1394  DECL_ACCESSORS2(string, String)
1395 
1396  // [index]: The [[StringIteratorNextIndex]] inobject property.
1397  inline int index() const;
1398  inline void set_index(int value);
1399 
1400  static const int kStringOffset = JSObject::kHeaderSize;
1401  static const int kNextIndexOffset = kStringOffset + kPointerSize;
1402  static const int kSize = kNextIndexOffset + kPointerSize;
1403 
1404  private:
1405  DISALLOW_IMPLICIT_CONSTRUCTORS(JSStringIterator);
1406 };
1407 
1408 } // namespace internal
1409 } // namespace v8
1410 
1411 #include "src/objects/object-macros-undef.h"
1412 
1413 #endif // V8_OBJECTS_JS_OBJECTS_H_
Definition: v8.h:56
Definition: libplatform.h:13