V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
objects.h
1 // Copyright 2015 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_H_
6 #define V8_OBJECTS_H_
7 
8 #include <iosfwd>
9 #include <memory>
10 
11 #include "include/v8-internal.h"
12 #include "include/v8.h"
13 #include "include/v8config.h"
14 #include "src/assert-scope.h"
15 #include "src/base/bits.h"
16 #include "src/base/build_config.h"
17 #include "src/base/flags.h"
18 #include "src/base/logging.h"
19 #include "src/checks.h"
20 #include "src/constants-arch.h"
21 #include "src/elements-kind.h"
22 #include "src/field-index.h"
23 #include "src/flags.h"
24 #include "src/message-template.h"
25 #include "src/objects-definitions.h"
26 #include "src/property-details.h"
27 #include "src/roots.h"
28 #include "src/utils.h"
29 
30 
31 // Has to be the last include (doesn't have include guards):
32 #include "src/objects/object-macros.h"
33 
34 //
35 // Most object types in the V8 JavaScript are described in this file.
36 //
37 // Inheritance hierarchy:
38 // - Object
39 // - Smi (immediate small integer)
40 // - HeapObject (superclass for everything allocated in the heap)
41 // - JSReceiver (suitable for property access)
42 // - JSObject
43 // - JSArray
44 // - JSArrayBuffer
45 // - JSArrayBufferView
46 // - JSTypedArray
47 // - JSDataView
48 // - JSBoundFunction
49 // - JSCollection
50 // - JSSet
51 // - JSMap
52 // - JSStringIterator
53 // - JSSetIterator
54 // - JSMapIterator
55 // - JSWeakCollection
56 // - JSWeakMap
57 // - JSWeakSet
58 // - JSRegExp
59 // - JSFunction
60 // - JSGeneratorObject
61 // - JSGlobalObject
62 // - JSGlobalProxy
63 // - JSValue
64 // - JSDate
65 // - JSMessageObject
66 // - JSModuleNamespace
67 // - JSV8BreakIterator // If V8_INTL_SUPPORT enabled.
68 // - JSCollator // If V8_INTL_SUPPORT enabled.
69 // - JSDateTimeFormat // If V8_INTL_SUPPORT enabled.
70 // - JSListFormat // If V8_INTL_SUPPORT enabled.
71 // - JSLocale // If V8_INTL_SUPPORT enabled.
72 // - JSNumberFormat // If V8_INTL_SUPPORT enabled.
73 // - JSPluralRules // If V8_INTL_SUPPORT enabled.
74 // - JSRelativeTimeFormat // If V8_INTL_SUPPORT enabled.
75 // - JSSegmentIterator // If V8_INTL_SUPPORT enabled.
76 // - JSSegmenter // If V8_INTL_SUPPORT enabled.
77 // - WasmExceptionObject
78 // - WasmGlobalObject
79 // - WasmInstanceObject
80 // - WasmMemoryObject
81 // - WasmModuleObject
82 // - WasmTableObject
83 // - JSProxy
84 // - FixedArrayBase
85 // - ByteArray
86 // - BytecodeArray
87 // - FixedArray
88 // - FrameArray
89 // - HashTable
90 // - Dictionary
91 // - StringTable
92 // - StringSet
93 // - CompilationCacheTable
94 // - MapCache
95 // - OrderedHashTable
96 // - OrderedHashSet
97 // - OrderedHashMap
98 // - FeedbackMetadata
99 // - TemplateList
100 // - TransitionArray
101 // - ScopeInfo
102 // - ModuleInfo
103 // - ScriptContextTable
104 // - FixedDoubleArray
105 // - Name
106 // - String
107 // - SeqString
108 // - SeqOneByteString
109 // - SeqTwoByteString
110 // - SlicedString
111 // - ConsString
112 // - ThinString
113 // - ExternalString
114 // - ExternalOneByteString
115 // - ExternalTwoByteString
116 // - InternalizedString
117 // - SeqInternalizedString
118 // - SeqOneByteInternalizedString
119 // - SeqTwoByteInternalizedString
120 // - ConsInternalizedString
121 // - ExternalInternalizedString
122 // - ExternalOneByteInternalizedString
123 // - ExternalTwoByteInternalizedString
124 // - Symbol
125 // - Context
126 // - NativeContext
127 // - HeapNumber
128 // - BigInt
129 // - Cell
130 // - DescriptorArray
131 // - PropertyCell
132 // - PropertyArray
133 // - Code
134 // - AbstractCode, a wrapper around Code or BytecodeArray
135 // - Map
136 // - Oddball
137 // - Foreign
138 // - SmallOrderedHashTable
139 // - SmallOrderedHashMap
140 // - SmallOrderedHashSet
141 // - SharedFunctionInfo
142 // - Struct
143 // - AccessorInfo
144 // - AsmWasmData
145 // - PromiseReaction
146 // - PromiseCapability
147 // - AccessorPair
148 // - AccessCheckInfo
149 // - InterceptorInfo
150 // - CallHandlerInfo
151 // - EnumCache
152 // - TemplateInfo
153 // - FunctionTemplateInfo
154 // - ObjectTemplateInfo
155 // - Script
156 // - DebugInfo
157 // - BreakPoint
158 // - BreakPointInfo
159 // - StackFrameInfo
160 // - SourcePositionTableWithFrameCache
161 // - CodeCache
162 // - PrototypeInfo
163 // - Microtask
164 // - CallbackTask
165 // - CallableTask
166 // - PromiseReactionJobTask
167 // - PromiseFulfillReactionJobTask
168 // - PromiseRejectReactionJobTask
169 // - PromiseResolveThenableJobTask
170 // - Module
171 // - ModuleInfoEntry
172 // - FeedbackCell
173 // - FeedbackVector
174 // - PreParsedScopeData
175 // - UncompiledData
176 // - UncompiledDataWithoutPreParsedScope
177 // - UncompiledDataWithPreParsedScope
178 //
179 // Formats of Object*:
180 // Smi: [31 bit signed int] 0
181 // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
182 
183 namespace v8 {
184 namespace internal {
185 
186 struct InliningPosition;
187 class PropertyDescriptorObject;
188 
189 // SKIP_WRITE_BARRIER skips the write barrier.
190 // UPDATE_WEAK_WRITE_BARRIER skips the marking part of the write barrier and
191 // only performs the generational part.
192 // UPDATE_WRITE_BARRIER is doing the full barrier, marking and generational.
193 enum WriteBarrierMode {
194  SKIP_WRITE_BARRIER,
195  UPDATE_WEAK_WRITE_BARRIER,
196  UPDATE_WRITE_BARRIER
197 };
198 
199 
200 // PropertyNormalizationMode is used to specify whether to keep
201 // inobject properties when normalizing properties of a JSObject.
202 enum PropertyNormalizationMode {
203  CLEAR_INOBJECT_PROPERTIES,
204  KEEP_INOBJECT_PROPERTIES
205 };
206 
207 
208 // Indicates whether transitions can be added to a source map or not.
209 enum TransitionFlag {
210  INSERT_TRANSITION,
211  OMIT_TRANSITION
212 };
213 
214 
215 // Indicates whether the transition is simple: the target map of the transition
216 // either extends the current map with a new property, or it modifies the
217 // property that was added last to the current map.
218 enum SimpleTransitionFlag {
219  SIMPLE_PROPERTY_TRANSITION,
220  PROPERTY_TRANSITION,
221  SPECIAL_TRANSITION
222 };
223 
224 // Indicates whether we are only interested in the descriptors of a particular
225 // map, or in all descriptors in the descriptor array.
226 enum DescriptorFlag {
227  ALL_DESCRIPTORS,
228  OWN_DESCRIPTORS
229 };
230 
231 // Instance size sentinel for objects of variable size.
232 const int kVariableSizeSentinel = 0;
233 
234 // We may store the unsigned bit field as signed Smi value and do not
235 // use the sign bit.
236 const int kStubMajorKeyBits = 8;
237 const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
238 
239 // Result of an abstract relational comparison of x and y, implemented according
240 // to ES6 section 7.2.11 Abstract Relational Comparison.
241 enum class ComparisonResult {
242  kLessThan, // x < y
243  kEqual, // x = y
244  kGreaterThan, // x > y
245  kUndefined // at least one of x or y was undefined or NaN
246 };
247 
248 // (Returns false whenever {result} is kUndefined.)
249 bool ComparisonResultToBool(Operation op, ComparisonResult result);
250 
251 enum class OnNonExistent { kThrowReferenceError, kReturnUndefined };
252 
253 class AbstractCode;
254 class AccessorPair;
255 class AccessCheckInfo;
256 class AllocationSite;
257 class ByteArray;
258 class Cell;
259 class ConsString;
260 class DependentCode;
261 class ElementsAccessor;
262 class EnumCache;
263 class FixedArrayBase;
264 class FixedDoubleArray;
265 class FunctionLiteral;
266 class FunctionTemplateInfo;
267 class JSAsyncGeneratorObject;
268 class JSGlobalProxy;
269 class JSPromise;
270 class JSProxy;
271 class KeyAccumulator;
272 class LayoutDescriptor;
273 class LookupIterator;
274 class FieldType;
275 class MaybeObjectSlot;
276 class Module;
277 class ModuleInfoEntry;
278 class ObjectHashTable;
279 class ObjectTemplateInfo;
280 class ObjectVisitor;
281 class PreParsedScopeData;
282 class PropertyArray;
283 class PropertyCell;
284 class PropertyDescriptor;
285 class RegExpMatchInfo;
286 class RootVisitor;
287 class SafepointEntry;
288 class ScriptContextTable;
289 class SharedFunctionInfo;
290 class StringStream;
291 class Symbol;
292 class FeedbackCell;
293 class FeedbackMetadata;
294 class FeedbackVector;
295 class UncompiledData;
296 class TemplateInfo;
297 class TransitionArray;
298 class TemplateList;
299 class WasmInstanceObject;
300 class WasmMemoryObject;
301 template <typename T>
303 
304 #ifdef OBJECT_PRINT
305 #define DECL_PRINTER(Name) void Name##Print(std::ostream& os); // NOLINT
306 #else
307 #define DECL_PRINTER(Name)
308 #endif
309 
310 #define OBJECT_TYPE_LIST(V) \
311  V(Smi) \
312  V(LayoutDescriptor) \
313  V(HeapObject) \
314  V(Primitive) \
315  V(Number) \
316  V(Numeric)
317 
318 #define HEAP_OBJECT_ORDINARY_TYPE_LIST_BASE(V) \
319  V(AbstractCode) \
320  V(AccessCheckNeeded) \
321  V(AllocationSite) \
322  V(ArrayList) \
323  V(BigInt) \
324  V(BigIntWrapper) \
325  V(ObjectBoilerplateDescription) \
326  V(Boolean) \
327  V(BooleanWrapper) \
328  V(BreakPoint) \
329  V(BreakPointInfo) \
330  V(ByteArray) \
331  V(BytecodeArray) \
332  V(CallHandlerInfo) \
333  V(Callable) \
334  V(Cell) \
335  V(ClassBoilerplate) \
336  V(Code) \
337  V(CodeDataContainer) \
338  V(CompilationCacheTable) \
339  V(ConsString) \
340  V(Constructor) \
341  V(Context) \
342  V(CoverageInfo) \
343  V(DataHandler) \
344  V(DeoptimizationData) \
345  V(DependentCode) \
346  V(DescriptorArray) \
347  V(EmbedderDataArray) \
348  V(EphemeronHashTable) \
349  V(EnumCache) \
350  V(ExternalOneByteString) \
351  V(ExternalString) \
352  V(ExternalTwoByteString) \
353  V(FeedbackCell) \
354  V(FeedbackMetadata) \
355  V(FeedbackVector) \
356  V(Filler) \
357  V(FixedArray) \
358  V(FixedArrayBase) \
359  V(FixedArrayExact) \
360  V(FixedBigInt64Array) \
361  V(FixedBigUint64Array) \
362  V(FixedDoubleArray) \
363  V(FixedFloat32Array) \
364  V(FixedFloat64Array) \
365  V(FixedInt16Array) \
366  V(FixedInt32Array) \
367  V(FixedInt8Array) \
368  V(FixedTypedArrayBase) \
369  V(FixedUint16Array) \
370  V(FixedUint32Array) \
371  V(FixedUint8Array) \
372  V(FixedUint8ClampedArray) \
373  V(Foreign) \
374  V(FrameArray) \
375  V(FreeSpace) \
376  V(Function) \
377  V(GlobalDictionary) \
378  V(HandlerTable) \
379  V(HeapNumber) \
380  V(InternalizedString) \
381  V(JSArgumentsObject) \
382  V(JSArgumentsObjectWithLength) \
383  V(JSArray) \
384  V(JSArrayBuffer) \
385  V(JSArrayBufferView) \
386  V(JSArrayIterator) \
387  V(JSAsyncFromSyncIterator) \
388  V(JSAsyncFunctionObject) \
389  V(JSAsyncGeneratorObject) \
390  V(JSBoundFunction) \
391  V(JSCollection) \
392  V(JSContextExtensionObject) \
393  V(JSDataView) \
394  V(JSDate) \
395  V(JSError) \
396  V(JSFunction) \
397  V(JSGeneratorObject) \
398  V(JSGlobalObject) \
399  V(JSGlobalProxy) \
400  V(JSMap) \
401  V(JSMapIterator) \
402  V(JSMessageObject) \
403  V(JSModuleNamespace) \
404  V(JSObject) \
405  V(JSPromise) \
406  V(JSProxy) \
407  V(JSReceiver) \
408  V(JSRegExp) \
409  V(JSRegExpResult) \
410  V(JSRegExpStringIterator) \
411  V(JSSet) \
412  V(JSSetIterator) \
413  V(JSSloppyArgumentsObject) \
414  V(JSStringIterator) \
415  V(JSTypedArray) \
416  V(JSValue) \
417  V(JSWeakCell) \
418  V(JSWeakRef) \
419  V(JSWeakCollection) \
420  V(JSWeakFactory) \
421  V(JSWeakFactoryCleanupIterator) \
422  V(JSWeakMap) \
423  V(JSWeakSet) \
424  V(LoadHandler) \
425  V(Map) \
426  V(MapCache) \
427  V(Microtask) \
428  V(ModuleInfo) \
429  V(MutableHeapNumber) \
430  V(Name) \
431  V(NameDictionary) \
432  V(NativeContext) \
433  V(NormalizedMapCache) \
434  V(NumberDictionary) \
435  V(NumberWrapper) \
436  V(ObjectHashSet) \
437  V(ObjectHashTable) \
438  V(Oddball) \
439  V(OrderedHashMap) \
440  V(OrderedHashSet) \
441  V(OrderedNameDictionary) \
442  V(PreParsedScopeData) \
443  V(PromiseReactionJobTask) \
444  V(PropertyArray) \
445  V(PropertyCell) \
446  V(PropertyDescriptorObject) \
447  V(RegExpMatchInfo) \
448  V(ScopeInfo) \
449  V(ScriptContextTable) \
450  V(ScriptWrapper) \
451  V(SeqOneByteString) \
452  V(SeqString) \
453  V(SeqTwoByteString) \
454  V(SharedFunctionInfo) \
455  V(SimpleNumberDictionary) \
456  V(SlicedString) \
457  V(SloppyArgumentsElements) \
458  V(SmallOrderedHashMap) \
459  V(SmallOrderedHashSet) \
460  V(SmallOrderedNameDictionary) \
461  V(SourcePositionTableWithFrameCache) \
462  V(StoreHandler) \
463  V(String) \
464  V(StringSet) \
465  V(StringTable) \
466  V(StringWrapper) \
467  V(Struct) \
468  V(Symbol) \
469  V(SymbolWrapper) \
470  V(TemplateInfo) \
471  V(TemplateList) \
472  V(TemplateObjectDescription) \
473  V(ThinString) \
474  V(TransitionArray) \
475  V(UncompiledData) \
476  V(UncompiledDataWithPreParsedScope) \
477  V(UncompiledDataWithoutPreParsedScope) \
478  V(Undetectable) \
479  V(UniqueName) \
480  V(WasmExceptionObject) \
481  V(WasmGlobalObject) \
482  V(WasmInstanceObject) \
483  V(WasmMemoryObject) \
484  V(WasmModuleObject) \
485  V(WasmTableObject) \
486  V(WeakFixedArray) \
487  V(WeakArrayList)
488 
489 #ifdef V8_INTL_SUPPORT
490 #define HEAP_OBJECT_ORDINARY_TYPE_LIST(V) \
491  HEAP_OBJECT_ORDINARY_TYPE_LIST_BASE(V) \
492  V(JSV8BreakIterator) \
493  V(JSCollator) \
494  V(JSDateTimeFormat) \
495  V(JSListFormat) \
496  V(JSLocale) \
497  V(JSNumberFormat) \
498  V(JSPluralRules) \
499  V(JSRelativeTimeFormat) \
500  V(JSSegmentIterator) \
501  V(JSSegmenter)
502 #else
503 #define HEAP_OBJECT_ORDINARY_TYPE_LIST(V) HEAP_OBJECT_ORDINARY_TYPE_LIST_BASE(V)
504 #endif // V8_INTL_SUPPORT
505 
506 #define HEAP_OBJECT_TEMPLATE_TYPE_LIST(V) \
507  V(Dictionary) \
508  V(HashTable)
509 
510 #define HEAP_OBJECT_TYPE_LIST(V) \
511  HEAP_OBJECT_ORDINARY_TYPE_LIST(V) \
512  HEAP_OBJECT_TEMPLATE_TYPE_LIST(V)
513 
514 #define ODDBALL_LIST(V) \
515  V(Undefined, undefined_value) \
516  V(Null, null_value) \
517  V(TheHole, the_hole_value) \
518  V(Exception, exception) \
519  V(Uninitialized, uninitialized_value) \
520  V(True, true_value) \
521  V(False, false_value) \
522  V(ArgumentsMarker, arguments_marker) \
523  V(OptimizedOut, optimized_out) \
524  V(StaleRegister, stale_register)
525 
526 // The element types selection for CreateListFromArrayLike.
527 enum class ElementTypes { kAll, kStringAndSymbol };
528 
529 // TODO(3770): Get rid of this indirection when the migration is complete.
534 typedef Foreign* ForeignArgType;
536 typedef JSArray* JSArrayArgType;
540 typedef JSObject* JSObjectArgType;
541 typedef JSPromise* JSPromiseArgType;
542 typedef JSProxy* JSProxyArgType;
543 typedef Map MapArgType;
544 typedef Object* ObjectArgType;
549 typedef Smi SmiArgType;
550 typedef String StringArgType;
551 typedef Symbol SymbolArgType;
555 
556 // Object is the abstract superclass for all classes in the
557 // object hierarchy.
558 // Object does not use any virtual functions to avoid the
559 // allocation of the C++ vtable.
560 // Since both Smi and HeapObject are subclasses of Object no
561 // data members can be present in Object.
562 class Object {
563  public:
564  // Type testing.
565  bool IsObject() const { return true; }
566 
567  // Syntax compatibility with ObjectPtr, so the same macros can consume
568  // arguments of either type.
569  Address ptr() const { return reinterpret_cast<Address>(this); }
570 
571 #define IS_TYPE_FUNCTION_DECL(Type) V8_INLINE bool Is##Type() const;
572  OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
573  HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
574 #undef IS_TYPE_FUNCTION_DECL
575 
576  V8_INLINE bool IsExternal(Isolate* isolate) const;
577 
578 // Oddball checks are faster when they are raw pointer comparisons, so the
579 // isolate/read-only roots overloads should be preferred where possible.
580 #define IS_TYPE_FUNCTION_DECL(Type, Value) \
581  V8_INLINE bool Is##Type(Isolate* isolate) const; \
582  V8_INLINE bool Is##Type(ReadOnlyRoots roots) const; \
583  V8_INLINE bool Is##Type() const;
584  ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
585 #undef IS_TYPE_FUNCTION_DECL
586 
587  V8_INLINE bool IsNullOrUndefined(Isolate* isolate) const;
588  V8_INLINE bool IsNullOrUndefined(ReadOnlyRoots roots) const;
589  V8_INLINE bool IsNullOrUndefined() const;
590 
591  enum class Conversion { kToNumber, kToNumeric };
592 
593 #define RETURN_FAILURE(isolate, should_throw, call) \
594  do { \
595  if ((should_throw) == kDontThrow) { \
596  return Just(false); \
597  } else { \
598  isolate->Throw(*isolate->factory()->call); \
599  return Nothing<bool>(); \
600  } \
601  } while (false)
602 
603 #define MAYBE_RETURN(call, value) \
604  do { \
605  if ((call).IsNothing()) return value; \
606  } while (false)
607 
608 #define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>())
609 
610 #define MAYBE_ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call) \
611  do { \
612  Isolate* __isolate__ = (isolate); \
613  if (!(call).To(&dst)) { \
614  DCHECK(__isolate__->has_pending_exception()); \
615  return ReadOnlyRoots(__isolate__).exception(); \
616  } \
617  } while (false)
618 
619 #define DECL_STRUCT_PREDICATE(NAME, Name, name) V8_INLINE bool Is##Name() const;
620  STRUCT_LIST(DECL_STRUCT_PREDICATE)
621 #undef DECL_STRUCT_PREDICATE
622 
623  // ES6, #sec-isarray. NOT to be confused with %_IsArray.
624  V8_INLINE
625  V8_WARN_UNUSED_RESULT static Maybe<bool> IsArray(Handle<Object> object);
626 
627  V8_INLINE bool IsSmallOrderedHashTable() const;
628 
629  // Extract the number.
630  inline double Number() const;
631  V8_INLINE bool IsNaN() const;
632  V8_INLINE bool IsMinusZero() const;
633  V8_EXPORT_PRIVATE bool ToInt32(int32_t* value);
634  inline bool ToUint32(uint32_t* value) const;
635 
636  inline Representation OptimalRepresentation();
637 
638  inline ElementsKind OptimalElementsKind();
639 
640  inline bool FitsRepresentation(Representation representation);
641 
642  // Checks whether two valid primitive encodings of a property name resolve to
643  // the same logical property. E.g., the smi 1, the string "1" and the double
644  // 1 all refer to the same property, so this helper will return true.
645  inline bool KeyEquals(Object* other);
646 
647  inline bool FilterKey(PropertyFilter filter);
648 
649  Handle<FieldType> OptimalType(Isolate* isolate,
650  Representation representation);
651 
652  inline static Handle<Object> NewStorageFor(Isolate* isolate,
653  Handle<Object> object,
654  Representation representation);
655 
656  inline static Handle<Object> WrapForRead(Isolate* isolate,
657  Handle<Object> object,
658  Representation representation);
659 
660  // Returns true if the object is of the correct type to be used as a
661  // implementation of a JSObject's elements.
662  inline bool HasValidElements();
663 
664  // ECMA-262 9.2.
665  bool BooleanValue(Isolate* isolate);
666 
667  // ES6 section 7.2.11 Abstract Relational Comparison
668  V8_WARN_UNUSED_RESULT static Maybe<ComparisonResult> Compare(
669  Isolate* isolate, Handle<Object> x, Handle<Object> y);
670 
671  // ES6 section 7.2.12 Abstract Equality Comparison
672  V8_WARN_UNUSED_RESULT static Maybe<bool> Equals(Isolate* isolate,
673  Handle<Object> x,
674  Handle<Object> y);
675 
676  // ES6 section 7.2.13 Strict Equality Comparison
677  bool StrictEquals(Object* that);
678 
679  // ES6 section 7.1.13 ToObject
680  // Convert to a JSObject if needed.
681  // native_context is used when creating wrapper object.
682  //
683  // Passing a non-null method_name allows us to give a more informative
684  // error message for those cases where ToObject is being called on
685  // the receiver of a built-in method.
686  V8_WARN_UNUSED_RESULT static inline MaybeHandle<JSReceiver> ToObject(
687  Isolate* isolate, Handle<Object> object,
688  const char* method_name = nullptr);
689  V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> ToObject(
690  Isolate* isolate, Handle<Object> object, Handle<Context> native_context,
691  const char* method_name = nullptr);
692 
693  // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee.
694  V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> ConvertReceiver(
695  Isolate* isolate, Handle<Object> object);
696 
697  // ES6 section 7.1.14 ToPropertyKey
698  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Name> ToName(
699  Isolate* isolate, Handle<Object> input);
700 
701  // ES6 section 7.1.1 ToPrimitive
702  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToPrimitive(
703  Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
704 
705  // ES6 section 7.1.3 ToNumber
706  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToNumber(
707  Isolate* isolate, Handle<Object> input);
708 
709  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToNumeric(
710  Isolate* isolate, Handle<Object> input);
711 
712  // ES6 section 7.1.4 ToInteger
713  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToInteger(
714  Isolate* isolate, Handle<Object> input);
715 
716  // ES6 section 7.1.5 ToInt32
717  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToInt32(
718  Isolate* isolate, Handle<Object> input);
719 
720  // ES6 section 7.1.6 ToUint32
721  V8_WARN_UNUSED_RESULT inline static MaybeHandle<Object> ToUint32(
722  Isolate* isolate, Handle<Object> input);
723 
724  // ES6 section 7.1.12 ToString
725  V8_WARN_UNUSED_RESULT static inline MaybeHandle<String> ToString(
726  Isolate* isolate, Handle<Object> input);
727 
728  static Handle<String> NoSideEffectsToString(Isolate* isolate,
729  Handle<Object> input);
730 
731  // ES6 section 7.1.14 ToPropertyKey
732  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToPropertyKey(
733  Isolate* isolate, Handle<Object> value);
734 
735  // ES6 section 7.1.15 ToLength
736  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToLength(
737  Isolate* isolate, Handle<Object> input);
738 
739  // ES6 section 7.1.17 ToIndex
740  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> ToIndex(
741  Isolate* isolate, Handle<Object> input, MessageTemplate error_index);
742 
743  // ES6 section 7.3.9 GetMethod
744  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetMethod(
745  Handle<JSReceiver> receiver, Handle<Name> name);
746 
747  // ES6 section 7.3.17 CreateListFromArrayLike
748  V8_WARN_UNUSED_RESULT static MaybeHandle<FixedArray> CreateListFromArrayLike(
749  Isolate* isolate, Handle<Object> object, ElementTypes element_types);
750 
751  // Get length property and apply ToLength.
752  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetLengthFromArrayLike(
753  Isolate* isolate, Handle<JSReceiver> object);
754 
755  // ES6 section 12.5.6 The typeof Operator
756  static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object);
757 
758  // ES6 section 12.7 Additive Operators
759  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> Add(Isolate* isolate,
760  Handle<Object> lhs,
761  Handle<Object> rhs);
762 
763  // ES6 section 12.9 Relational Operators
764  V8_WARN_UNUSED_RESULT static inline Maybe<bool> GreaterThan(Isolate* isolate,
765  Handle<Object> x,
766  Handle<Object> y);
767  V8_WARN_UNUSED_RESULT static inline Maybe<bool> GreaterThanOrEqual(
768  Isolate* isolate, Handle<Object> x, Handle<Object> y);
769  V8_WARN_UNUSED_RESULT static inline Maybe<bool> LessThan(Isolate* isolate,
770  Handle<Object> x,
771  Handle<Object> y);
772  V8_WARN_UNUSED_RESULT static inline Maybe<bool> LessThanOrEqual(
773  Isolate* isolate, Handle<Object> x, Handle<Object> y);
774 
775  // ES6 section 7.3.19 OrdinaryHasInstance (C, O).
776  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> OrdinaryHasInstance(
777  Isolate* isolate, Handle<Object> callable, Handle<Object> object);
778 
779  // ES6 section 12.10.4 Runtime Semantics: InstanceofOperator(O, C)
780  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> InstanceOf(
781  Isolate* isolate, Handle<Object> object, Handle<Object> callable);
782 
783  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static MaybeHandle<Object>
784  GetProperty(LookupIterator* it,
785  OnNonExistent on_non_existent = OnNonExistent::kReturnUndefined);
786 
787  // ES6 [[Set]] (when passed kDontThrow)
788  // Invariants for this and related functions (unless stated otherwise):
789  // 1) When the result is Nothing, an exception is pending.
790  // 2) When passed kThrowOnError, the result is never Just(false).
791  // In some cases, an exception is thrown regardless of the ShouldThrow
792  // argument. These cases are either in accordance with the spec or not
793  // covered by it (eg., concerning API callbacks).
794  V8_WARN_UNUSED_RESULT static Maybe<bool> SetProperty(
795  LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
796  StoreOrigin store_origin);
797  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> SetProperty(
798  Isolate* isolate, Handle<Object> object, Handle<Name> name,
799  Handle<Object> value, LanguageMode language_mode,
800  StoreOrigin store_origin = StoreOrigin::kMaybeKeyed);
801  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> SetPropertyOrElement(
802  Isolate* isolate, Handle<Object> object, Handle<Name> name,
803  Handle<Object> value, LanguageMode language_mode,
804  StoreOrigin store_origin = StoreOrigin::kMaybeKeyed);
805 
806  V8_WARN_UNUSED_RESULT static Maybe<bool> SetSuperProperty(
807  LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
808  StoreOrigin store_origin);
809 
810  V8_WARN_UNUSED_RESULT static Maybe<bool> CannotCreateProperty(
811  Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
812  Handle<Object> value, ShouldThrow should_throw);
813  V8_WARN_UNUSED_RESULT static Maybe<bool> WriteToReadOnlyProperty(
814  LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
815  V8_WARN_UNUSED_RESULT static Maybe<bool> WriteToReadOnlyProperty(
816  Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
817  Handle<Object> value, ShouldThrow should_throw);
818  V8_WARN_UNUSED_RESULT static Maybe<bool> RedefineIncompatibleProperty(
819  Isolate* isolate, Handle<Object> name, Handle<Object> value,
820  ShouldThrow should_throw);
821  V8_WARN_UNUSED_RESULT static Maybe<bool> SetDataProperty(
822  LookupIterator* it, Handle<Object> value);
823  V8_WARN_UNUSED_RESULT static Maybe<bool> AddDataProperty(
824  LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
825  ShouldThrow should_throw, StoreOrigin store_origin);
826  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
827  Isolate* isolate, Handle<Object> object, Handle<Name> name);
828  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
829  Handle<Object> receiver, Handle<Name> name, Handle<JSReceiver> holder);
830  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetProperty(
831  Isolate* isolate, Handle<Object> object, Handle<Name> name);
832 
833  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetPropertyWithAccessor(
834  LookupIterator* it);
835  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPropertyWithAccessor(
836  LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
837 
838  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter(
839  Handle<Object> receiver, Handle<JSReceiver> getter);
840  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPropertyWithDefinedSetter(
841  Handle<Object> receiver, Handle<JSReceiver> setter, Handle<Object> value,
842  ShouldThrow should_throw);
843 
844  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> GetElement(
845  Isolate* isolate, Handle<Object> object, uint32_t index);
846 
847  V8_WARN_UNUSED_RESULT static inline MaybeHandle<Object> SetElement(
848  Isolate* isolate, Handle<Object> object, uint32_t index,
849  Handle<Object> value, LanguageMode language_mode);
850 
851  // Returns the permanent hash code associated with this object. May return
852  // undefined if not yet created.
853  inline Object* GetHash();
854 
855  // Returns the permanent hash code associated with this object depending on
856  // the actual object type. May create and store a hash code if needed and none
857  // exists.
858  Smi GetOrCreateHash(Isolate* isolate);
859 
860  // Checks whether this object has the same value as the given one. This
861  // function is implemented according to ES5, section 9.12 and can be used
862  // to implement the Object.is function.
863  V8_EXPORT_PRIVATE bool SameValue(Object* other);
864 
865  // Checks whether this object has the same value as the given one.
866  // +0 and -0 are treated equal. Everything else is the same as SameValue.
867  // This function is implemented according to ES6, section 7.2.4 and is used
868  // by ES6 Map and Set.
869  bool SameValueZero(Object* other);
870 
871  // ES6 section 9.4.2.3 ArraySpeciesCreate (part of it)
872  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ArraySpeciesConstructor(
873  Isolate* isolate, Handle<Object> original_array);
874 
875  // ES6 section 7.3.20 SpeciesConstructor ( O, defaultConstructor )
876  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> SpeciesConstructor(
877  Isolate* isolate, Handle<JSReceiver> recv,
878  Handle<JSFunction> default_ctor);
879 
880  // Tries to convert an object to an array length. Returns true and sets the
881  // output parameter if it succeeds.
882  inline bool ToArrayLength(uint32_t* index) const;
883 
884  // Tries to convert an object to an array index. Returns true and sets the
885  // output parameter if it succeeds. Equivalent to ToArrayLength, but does not
886  // allow kMaxUInt32.
887  V8_WARN_UNUSED_RESULT inline bool ToArrayIndex(uint32_t* index) const;
888 
889  // Returns true if the result of iterating over the object is the same
890  // (including observable effects) as simply accessing the properties between 0
891  // and length.
892  bool IterationHasObservableEffects();
893 
894  DECL_VERIFIER(Object)
895 #ifdef VERIFY_HEAP
896  // Verify a pointer is a valid object pointer.
897  static void VerifyPointer(Isolate* isolate, Object* p);
898 #endif
899 
900  inline void VerifyApiCallResultType();
901 
902  // Prints this object without details.
903  void ShortPrint(FILE* out = stdout);
904 
905  // Prints this object without details to a message accumulator.
906  void ShortPrint(StringStream* accumulator);
907 
908  void ShortPrint(std::ostream& os); // NOLINT
909 
910  DECL_CAST(Object)
911 
912  // Layout description.
913  static const int kHeaderSize = 0; // Object does not take up any space.
914 
915 #ifdef OBJECT_PRINT
916  // For our gdb macros, we should perhaps change these in the future.
917  void Print();
918 
919  // Prints this object with details.
920  void Print(std::ostream& os); // NOLINT
921 #else
922  void Print() { ShortPrint(); }
923  void Print(std::ostream& os) { ShortPrint(os); } // NOLINT
924 #endif
925 
926  private:
927  friend class LookupIterator;
928  friend class StringStream;
929 
930  // Return the map of the root of object's prototype chain.
931  Map GetPrototypeChainRootMap(Isolate* isolate) const;
932 
933  // Returns a non-SMI for JSReceivers, but returns the hash code for
934  // simple objects. This avoids a double lookup in the cases where
935  // we know we will add the hash to the JSReceiver if it does not
936  // already exist.
937  //
938  // Despite its size, this needs to be inlined for performance
939  // reasons.
940  static inline Object* GetSimpleHash(Object* object);
941 
942  // Helper for SetProperty and SetSuperProperty.
943  // Return value is only meaningful if [found] is set to true on return.
944  V8_WARN_UNUSED_RESULT static Maybe<bool> SetPropertyInternal(
945  LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
946  StoreOrigin store_origin, bool* found);
947 
948  V8_WARN_UNUSED_RESULT static MaybeHandle<Name> ConvertToName(
949  Isolate* isolate, Handle<Object> input);
950  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToPropertyKey(
951  Isolate* isolate, Handle<Object> value);
952  V8_WARN_UNUSED_RESULT static MaybeHandle<String> ConvertToString(
953  Isolate* isolate, Handle<Object> input);
954  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToNumberOrNumeric(
955  Isolate* isolate, Handle<Object> input, Conversion mode);
956  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToInteger(
957  Isolate* isolate, Handle<Object> input);
958  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToInt32(
959  Isolate* isolate, Handle<Object> input);
960  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToUint32(
961  Isolate* isolate, Handle<Object> input);
962  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToLength(
963  Isolate* isolate, Handle<Object> input);
964  V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToIndex(
965  Isolate* isolate, Handle<Object> input, MessageTemplate error_index);
966 
967  DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
968 };
969 
970 // In objects.h to be usable without objects-inl.h inclusion.
971 bool Object::IsSmi() const { return HAS_SMI_TAG(ptr()); }
972 bool Object::IsHeapObject() const {
973  DCHECK_EQ(!IsSmi(), Internals::HasHeapObjectTag(ptr()));
974  return !IsSmi();
975 }
976 
977 struct Brief {
978  V8_EXPORT_PRIVATE explicit Brief(const Object* v);
979  explicit Brief(const MaybeObject v);
980  // {value} is a tagged heap object reference (weak or strong), equivalent to
981  // a MaybeObject's payload. It has a plain Address type to keep #includes
982  // lightweight.
983  const Address value;
984 };
985 
986 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v);
987 
988 // Heap objects typically have a map pointer in their first word. However,
989 // during GC other data (e.g. mark bits, forwarding addresses) is sometimes
990 // encoded in the first word. The class MapWord is an abstraction of the
991 // value in a heap object's first word.
992 class MapWord {
993  public:
994  // Normal state: the map word contains a map pointer.
995 
996  // Create a map word from a map pointer.
997  static inline MapWord FromMap(const Map map);
998 
999  // View this map word as a map pointer.
1000  inline Map ToMap() const;
1001 
1002  // Scavenge collection: the map word of live objects in the from space
1003  // contains a forwarding address (a heap object pointer in the to space).
1004 
1005  // True if this map word is a forwarding address for a scavenge
1006  // collection. Only valid during a scavenge collection (specifically,
1007  // when all map words are heap object pointers, i.e. not during a full GC).
1008  inline bool IsForwardingAddress() const;
1009 
1010  // Create a map word from a forwarding address.
1011  static inline MapWord FromForwardingAddress(HeapObject* object);
1012 
1013  // View this map word as a forwarding address.
1014  inline HeapObject* ToForwardingAddress();
1015 
1016  static inline MapWord FromRawValue(uintptr_t value) {
1017  return MapWord(value);
1018  }
1019 
1020  inline uintptr_t ToRawValue() {
1021  return value_;
1022  }
1023 
1024  private:
1025  // HeapObject calls the private constructor and directly reads the value.
1026  friend class HeapObject;
1027  friend class HeapObjectPtr;
1028 
1029  explicit MapWord(Address value) : value_(value) {}
1030 
1031  Address value_;
1032 };
1033 
1034 
1035 // HeapObject is the superclass for all classes describing heap allocated
1036 // objects.
1037 class HeapObject: public Object {
1038  public:
1039  // [map]: Contains a map which contains the object's reflective
1040  // information.
1041  inline Map map() const;
1042  inline void set_map(Map value);
1043 
1044  inline ObjectSlot map_slot();
1045 
1046  // The no-write-barrier version. This is OK if the object is white and in
1047  // new space, or if the value is an immortal immutable object, like the maps
1048  // of primitive (non-JS) objects like strings, heap numbers etc.
1049  inline void set_map_no_write_barrier(Map value);
1050 
1051  // Get the map using acquire load.
1052  inline Map synchronized_map() const;
1053  inline MapWord synchronized_map_word() const;
1054 
1055  // Set the map using release store
1056  inline void synchronized_set_map(Map value);
1057  inline void synchronized_set_map_word(MapWord map_word);
1058 
1059  // Initialize the map immediately after the object is allocated.
1060  // Do not use this outside Heap.
1061  inline void set_map_after_allocation(
1062  Map value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1063 
1064  // During garbage collection, the map word of a heap object does not
1065  // necessarily contain a map pointer.
1066  inline MapWord map_word() const;
1067  inline void set_map_word(MapWord map_word);
1068 
1069  // TODO(v8:7464): Once RO_SPACE is shared between isolates, this method can be
1070  // removed as ReadOnlyRoots will be accessible from a global variable. For now
1071  // this method exists to help remove GetIsolate/GetHeap from HeapObject, in a
1072  // way that doesn't require passing Isolate/Heap down huge call chains or to
1073  // places where it might not be safe to access it.
1074  inline ReadOnlyRoots GetReadOnlyRoots() const;
1075 
1076 #define IS_TYPE_FUNCTION_DECL(Type) V8_INLINE bool Is##Type() const;
1077  HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
1078 #undef IS_TYPE_FUNCTION_DECL
1079 
1080  V8_INLINE bool IsExternal(Isolate* isolate) const;
1081 
1082 // Oddball checks are faster when they are raw pointer comparisons, so the
1083 // isolate/read-only roots overloads should be preferred where possible.
1084 #define IS_TYPE_FUNCTION_DECL(Type, Value) \
1085  V8_INLINE bool Is##Type(Isolate* isolate) const; \
1086  V8_INLINE bool Is##Type(ReadOnlyRoots roots) const; \
1087  V8_INLINE bool Is##Type() const;
1088  ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
1089 #undef IS_TYPE_FUNCTION_DECL
1090 
1091  V8_INLINE bool IsNullOrUndefined(Isolate* isolate) const;
1092  V8_INLINE bool IsNullOrUndefined(ReadOnlyRoots roots) const;
1093  V8_INLINE bool IsNullOrUndefined() const;
1094 
1095 #define DECL_STRUCT_PREDICATE(NAME, Name, name) V8_INLINE bool Is##Name() const;
1096  STRUCT_LIST(DECL_STRUCT_PREDICATE)
1097 #undef DECL_STRUCT_PREDICATE
1098 
1099  // Converts an address to a HeapObject pointer.
1100  static inline HeapObject* FromAddress(Address address) {
1101  DCHECK_TAG_ALIGNED(address);
1102  return reinterpret_cast<HeapObject*>(address + kHeapObjectTag);
1103  }
1104 
1105  // Returns the address of this HeapObject.
1106  inline Address address() const {
1107  return reinterpret_cast<Address>(this) - kHeapObjectTag;
1108  }
1109 
1110  // Iterates over pointers contained in the object (including the Map).
1111  // If it's not performance critical iteration use the non-templatized
1112  // version.
1113  void Iterate(ObjectVisitor* v);
1114 
1115  template <typename ObjectVisitor>
1116  inline void IterateFast(ObjectVisitor* v);
1117 
1118  // Iterates over all pointers contained in the object except the
1119  // first map pointer. The object type is given in the first
1120  // parameter. This function does not access the map pointer in the
1121  // object, and so is safe to call while the map pointer is modified.
1122  // If it's not performance critical iteration use the non-templatized
1123  // version.
1124  void IterateBody(ObjectVisitor* v);
1125  void IterateBody(Map map, int object_size, ObjectVisitor* v);
1126 
1127  template <typename ObjectVisitor>
1128  inline void IterateBodyFast(ObjectVisitor* v);
1129 
1130  template <typename ObjectVisitor>
1131  inline void IterateBodyFast(Map map, int object_size, ObjectVisitor* v);
1132 
1133  // Returns true if the object contains a tagged value at given offset.
1134  // It is used for invalid slots filtering. If the offset points outside
1135  // of the object or to the map word, the result is UNDEFINED (!!!).
1136  bool IsValidSlot(Map map, int offset);
1137 
1138  // Returns the heap object's size in bytes
1139  inline int Size() const;
1140 
1141  // Given a heap object's map pointer, returns the heap size in bytes
1142  // Useful when the map pointer field is used for other purposes.
1143  // GC internal.
1144  inline int SizeFromMap(Map map) const;
1145 
1146  // Returns the field at offset in obj, as a read/write Object* reference.
1147  // Does no checking, and is safe to use during GC, while maps are invalid.
1148  // Does not invoke write barrier, so should only be assigned to
1149  // during marking GC.
1150  inline ObjectSlot RawField(int byte_offset) const;
1151  static inline ObjectSlot RawField(const HeapObject* obj, int offset);
1152  inline MaybeObjectSlot RawMaybeWeakField(int byte_offset) const;
1153  static inline MaybeObjectSlot RawMaybeWeakField(HeapObject* obj, int offset);
1154 
1155  DECL_CAST(HeapObject)
1156 
1157  // Return the write barrier mode for this. Callers of this function
1158  // must be able to present a reference to an DisallowHeapAllocation
1159  // object as a sign that they are not going to use this function
1160  // from code that allocates and thus invalidates the returned write
1161  // barrier mode.
1162  inline WriteBarrierMode GetWriteBarrierMode(
1163  const DisallowHeapAllocation& promise);
1164 
1165  // Dispatched behavior.
1166  void HeapObjectShortPrint(std::ostream& os); // NOLINT
1167 #ifdef OBJECT_PRINT
1168  void PrintHeader(std::ostream& os, const char* id); // NOLINT
1169 #endif
1170  DECL_PRINTER(HeapObject)
1171  DECL_VERIFIER(HeapObject)
1172 #ifdef VERIFY_HEAP
1173  inline void VerifyObjectField(Isolate* isolate, int offset);
1174  inline void VerifySmiField(int offset);
1175  inline void VerifyMaybeObjectField(Isolate* isolate, int offset);
1176 
1177  // Verify a pointer is a valid HeapObject pointer that points to object
1178  // areas in the heap.
1179  static void VerifyHeapPointer(Isolate* isolate, Object* p);
1180 #endif
1181 
1182  static inline AllocationAlignment RequiredAlignment(Map map);
1183 
1184  // Whether the object needs rehashing. That is the case if the object's
1185  // content depends on FLAG_hash_seed. When the object is deserialized into
1186  // a heap with a different hash seed, these objects need to adapt.
1187  inline bool NeedsRehashing() const;
1188 
1189  // Rehashing support is not implemented for all objects that need rehashing.
1190  // With objects that need rehashing but cannot be rehashed, rehashing has to
1191  // be disabled.
1192  bool CanBeRehashed() const;
1193 
1194  // Rehash the object based on the layout inferred from its map.
1195  void RehashBasedOnMap(Isolate* isolate);
1196 
1197  // Layout description.
1198  // First field in a heap object is map.
1199  static const int kMapOffset = Object::kHeaderSize;
1200  static const int kHeaderSize = kMapOffset + kPointerSize;
1201 
1202  STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset);
1203 
1204  inline Address GetFieldAddress(int field_offset) const;
1205 
1206  private:
1207  DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1208 };
1209 
1210 // Mixin class for objects that can never be in RO space.
1211 // TODO(leszeks): Add checks in the factory that we never allocate these objects
1212 // in RO space.
1214  public:
1215  // The Heap the object was allocated in. Used also to access Isolate.
1216  inline Heap* GetHeap() const;
1217 
1218  // Convenience method to get current isolate.
1219  inline Isolate* GetIsolate() const;
1220 };
1221 
1222 template <int start_offset, int end_offset, int size>
1223 class FixedBodyDescriptor;
1224 
1225 template <int start_offset>
1227 
1228 template <int start_offset>
1230 
1231 template <class ParentBodyDescriptor, class ChildBodyDescriptor>
1233 
1234 // The HeapNumber class describes heap allocated numbers that cannot be
1235 // represented in a Smi (small integer). MutableHeapNumber is the same, but its
1236 // number value can change over time (it is used only as property storage).
1237 // HeapNumberBase merely exists to avoid code duplication.
1238 class HeapNumberBase : public HeapObject {
1239  public:
1240  // [value]: number value.
1241  inline double value() const;
1242  inline void set_value(double value);
1243 
1244  inline uint64_t value_as_bits() const;
1245  inline void set_value_as_bits(uint64_t bits);
1246 
1247  inline int get_exponent();
1248  inline int get_sign();
1249 
1250  // Layout description.
1251  static const int kValueOffset = HeapObject::kHeaderSize;
1252  // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1253  // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit
1254  // words within double numbers are endian dependent and they are set
1255  // accordingly.
1256 #if defined(V8_TARGET_LITTLE_ENDIAN)
1257  static const int kMantissaOffset = kValueOffset;
1258  static const int kExponentOffset = kValueOffset + 4;
1259 #elif defined(V8_TARGET_BIG_ENDIAN)
1260  static const int kMantissaOffset = kValueOffset + 4;
1261  static const int kExponentOffset = kValueOffset;
1262 #else
1263 #error Unknown byte ordering
1264 #endif
1265 
1266  static const int kSize = kValueOffset + kDoubleSize;
1267  static const uint32_t kSignMask = 0x80000000u;
1268  static const uint32_t kExponentMask = 0x7ff00000u;
1269  static const uint32_t kMantissaMask = 0xfffffu;
1270  static const int kMantissaBits = 52;
1271  static const int kExponentBits = 11;
1272  static const int kExponentBias = 1023;
1273  static const int kExponentShift = 20;
1274  static const int kInfinityOrNanExponent =
1275  (kExponentMask >> kExponentShift) - kExponentBias;
1276  static const int kMantissaBitsInTopWord = 20;
1277  static const int kNonMantissaBitsInTopWord = 12;
1278 
1279  private:
1280  DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumberBase)
1281 };
1282 
1283 class HeapNumber : public HeapNumberBase {
1284  public:
1285  DECL_CAST(HeapNumber)
1286  V8_EXPORT_PRIVATE void HeapNumberPrint(std::ostream& os);
1287 
1288  private:
1289  DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber)
1290 };
1291 
1293  public:
1294  DECL_CAST(MutableHeapNumber)
1295  V8_EXPORT_PRIVATE void MutableHeapNumberPrint(std::ostream& os);
1296 
1297  private:
1298  DISALLOW_IMPLICIT_CONSTRUCTORS(MutableHeapNumber)
1299 };
1300 
1301 enum EnsureElementsMode {
1302  DONT_ALLOW_DOUBLE_ELEMENTS,
1303  ALLOW_COPIED_DOUBLE_ELEMENTS,
1304  ALLOW_CONVERTED_DOUBLE_ELEMENTS
1305 };
1306 
1307 
1308 // Indicator for one component of an AccessorPair.
1309 enum AccessorComponent {
1310  ACCESSOR_GETTER,
1311  ACCESSOR_SETTER
1312 };
1313 
1314 enum class GetKeysConversion {
1315  kKeepNumbers = static_cast<int>(v8::KeyConversionMode::kKeepNumbers),
1316  kConvertToString = static_cast<int>(v8::KeyConversionMode::kConvertToString)
1317 };
1318 
1319 enum class KeyCollectionMode {
1320  kOwnOnly = static_cast<int>(v8::KeyCollectionMode::kOwnOnly),
1321  kIncludePrototypes =
1322  static_cast<int>(v8::KeyCollectionMode::kIncludePrototypes)
1323 };
1324 
1325 // FreeSpace are fixed-size free memory blocks used by the heap and GC.
1326 // They look like heap objects (are heap object tagged and have a map) so that
1327 // the heap remains iterable. They have a size and a next pointer.
1328 // The next pointer is the raw address of the next FreeSpace object (or NULL)
1329 // in the free list.
1330 class FreeSpace: public HeapObject {
1331  public:
1332  // [size]: size of the free space including the header.
1333  inline int size() const;
1334  inline void set_size(int value);
1335 
1336  inline int relaxed_read_size() const;
1337  inline void relaxed_write_size(int value);
1338 
1339  inline int Size();
1340 
1341  // Accessors for the next field.
1342  inline FreeSpace* next();
1343  inline void set_next(FreeSpace* next);
1344 
1345  inline static FreeSpace* cast(HeapObject* obj);
1346 
1347  // Dispatched behavior.
1348  DECL_PRINTER(FreeSpace)
1349  DECL_VERIFIER(FreeSpace)
1350 
1351  // Layout description.
1352  // Size is smi tagged when it is stored.
1353  static const int kSizeOffset = HeapObject::kHeaderSize;
1354  static const int kNextOffset = POINTER_SIZE_ALIGN(kSizeOffset + kPointerSize);
1355  static const int kSize = kNextOffset + kPointerSize;
1356 
1357  private:
1358  DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
1359 };
1360 
1361 class PrototypeInfo;
1362 
1363 // An abstract superclass, a marker class really, for simple structure classes.
1364 // It doesn't carry much functionality but allows struct classes to be
1365 // identified in the type system.
1366 class Struct: public HeapObject {
1367  public:
1368  inline void InitializeBody(int object_size);
1369  DECL_CAST(Struct)
1370  void BriefPrintDetails(std::ostream& os);
1371 };
1372 
1373 class Tuple2 : public Struct {
1374  public:
1375  DECL_ACCESSORS(value1, Object)
1376  DECL_ACCESSORS(value2, Object)
1377 
1378  DECL_CAST(Tuple2)
1379 
1380  // Dispatched behavior.
1381  DECL_PRINTER(Tuple2)
1382  DECL_VERIFIER(Tuple2)
1383  void BriefPrintDetails(std::ostream& os);
1384 
1385  static const int kValue1Offset = HeapObject::kHeaderSize;
1386  static const int kValue2Offset = kValue1Offset + kPointerSize;
1387  static const int kSize = kValue2Offset + kPointerSize;
1388 
1389  private:
1390  DISALLOW_IMPLICIT_CONSTRUCTORS(Tuple2);
1391 };
1392 
1393 class Tuple3 : public Tuple2 {
1394  public:
1395  DECL_ACCESSORS(value3, Object)
1396 
1397  DECL_CAST(Tuple3)
1398 
1399  // Dispatched behavior.
1400  DECL_PRINTER(Tuple3)
1401  DECL_VERIFIER(Tuple3)
1402  void BriefPrintDetails(std::ostream& os);
1403 
1404  static const int kValue3Offset = Tuple2::kSize;
1405  static const int kSize = kValue3Offset + kPointerSize;
1406 
1407  private:
1408  DISALLOW_IMPLICIT_CONSTRUCTORS(Tuple3);
1409 };
1410 
1411 // Utility superclass for stack-allocated objects that must be updated
1412 // on gc. It provides two ways for the gc to update instances, either
1413 // iterating or updating after gc.
1415  public:
1416  explicit inline Relocatable(Isolate* isolate);
1417  inline virtual ~Relocatable();
1418  virtual void IterateInstance(RootVisitor* v) {}
1419  virtual void PostGarbageCollection() { }
1420 
1421  static void PostGarbageCollectionProcessing(Isolate* isolate);
1422  static int ArchiveSpacePerThread();
1423  static char* ArchiveState(Isolate* isolate, char* to);
1424  static char* RestoreState(Isolate* isolate, char* from);
1425  static void Iterate(Isolate* isolate, RootVisitor* v);
1426  static void Iterate(RootVisitor* v, Relocatable* top);
1427  static char* Iterate(RootVisitor* v, char* t);
1428 
1429  private:
1430  Isolate* isolate_;
1431  Relocatable* prev_;
1432 };
1433 
1434 
1435 // The Oddball describes objects null, undefined, true, and false.
1436 class Oddball: public HeapObject {
1437  public:
1438  // [to_number_raw]: Cached raw to_number computed at startup.
1439  inline double to_number_raw() const;
1440  inline void set_to_number_raw(double value);
1441  inline void set_to_number_raw_as_bits(uint64_t bits);
1442 
1443  // [to_string]: Cached to_string computed at startup.
1444  DECL_ACCESSORS2(to_string, String)
1445 
1446  // [to_number]: Cached to_number computed at startup.
1447  DECL_ACCESSORS(to_number, Object)
1448 
1449  // [typeof]: Cached type_of computed at startup.
1450  DECL_ACCESSORS2(type_of, String)
1451 
1452  inline byte kind() const;
1453  inline void set_kind(byte kind);
1454 
1455  // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined.
1456  V8_WARN_UNUSED_RESULT static inline Handle<Object> ToNumber(
1457  Isolate* isolate, Handle<Oddball> input);
1458 
1459  DECL_CAST(Oddball)
1460 
1461  // Dispatched behavior.
1462  DECL_VERIFIER(Oddball)
1463 
1464  // Initialize the fields.
1465  static void Initialize(Isolate* isolate, Handle<Oddball> oddball,
1466  const char* to_string, Handle<Object> to_number,
1467  const char* type_of, byte kind);
1468 
1469  // Layout description.
1470  static const int kToNumberRawOffset = HeapObject::kHeaderSize;
1471  static const int kToStringOffset = kToNumberRawOffset + kDoubleSize;
1472  static const int kToNumberOffset = kToStringOffset + kPointerSize;
1473  static const int kTypeOfOffset = kToNumberOffset + kPointerSize;
1474  static const int kKindOffset = kTypeOfOffset + kPointerSize;
1475  static const int kSize = kKindOffset + kPointerSize;
1476 
1477  static const byte kFalse = 0;
1478  static const byte kTrue = 1;
1479  static const byte kNotBooleanMask = static_cast<byte>(~1);
1480  static const byte kTheHole = 2;
1481  static const byte kNull = 3;
1482  static const byte kArgumentsMarker = 4;
1483  static const byte kUndefined = 5;
1484  static const byte kUninitialized = 6;
1485  static const byte kOther = 7;
1486  static const byte kException = 8;
1487  static const byte kOptimizedOut = 9;
1488  static const byte kStaleRegister = 10;
1489  static const byte kSelfReferenceMarker = 10;
1490 
1491  typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize,
1492  kSize> BodyDescriptor;
1493 
1494  STATIC_ASSERT(kToNumberRawOffset == HeapNumber::kValueOffset);
1495  STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
1496  STATIC_ASSERT(kNull == Internals::kNullOddballKind);
1497  STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind);
1498 
1499  private:
1500  DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
1501 };
1502 
1503 
1504 class Cell: public HeapObject {
1505  public:
1506  // [value]: value of the cell.
1507  DECL_ACCESSORS(value, Object)
1508 
1509  DECL_CAST(Cell)
1510 
1511  static inline Cell* FromValueAddress(Address value) {
1512  Object* result = FromAddress(value - kValueOffset);
1513  return static_cast<Cell*>(result);
1514  }
1515 
1516  inline Address ValueAddress() {
1517  return address() + kValueOffset;
1518  }
1519 
1520  // Dispatched behavior.
1521  DECL_PRINTER(Cell)
1522  DECL_VERIFIER(Cell)
1523 
1524  // Layout description.
1525  static const int kValueOffset = HeapObject::kHeaderSize;
1526  static const int kSize = kValueOffset + kPointerSize;
1527 
1528  typedef FixedBodyDescriptor<kValueOffset,
1529  kValueOffset + kPointerSize,
1530  kSize> BodyDescriptor;
1531 
1532  private:
1533  DISALLOW_IMPLICIT_CONSTRUCTORS(Cell);
1534 };
1535 
1536 // This is a special cell used to maintain both the link between a
1537 // closure and it's feedback vector, as well as a way to count the
1538 // number of closures created for a certain function per native
1539 // context. There's at most one FeedbackCell for each function in
1540 // a native context.
1541 class FeedbackCell : public Struct {
1542  public:
1543  // [value]: value of the cell.
1544  DECL_ACCESSORS(value, HeapObject)
1545 
1546  DECL_CAST(FeedbackCell)
1547 
1548  // Dispatched behavior.
1549  DECL_PRINTER(FeedbackCell)
1550  DECL_VERIFIER(FeedbackCell)
1551 
1552  static const int kValueOffset = HeapObject::kHeaderSize;
1553  static const int kSize = kValueOffset + kPointerSize;
1554 
1557 
1558  private:
1559  DISALLOW_IMPLICIT_CONSTRUCTORS(FeedbackCell);
1560 };
1561 
1562 class PropertyCell : public HeapObject {
1563  public:
1564  // [name]: the name of the global property.
1565  DECL_ACCESSORS2(name, Name)
1566  // [property_details]: details of the global property.
1567  DECL_ACCESSORS(property_details_raw, Object)
1568  // [value]: value of the global property.
1569  DECL_ACCESSORS(value, Object)
1570  // [dependent_code]: dependent code that depends on the type of the global
1571  // property.
1572  DECL_ACCESSORS(dependent_code, DependentCode)
1573 
1574  inline PropertyDetails property_details() const;
1575  inline void set_property_details(PropertyDetails details);
1576 
1577  PropertyCellConstantType GetConstantType();
1578 
1579  // Computes the new type of the cell's contents for the given value, but
1580  // without actually modifying the details.
1581  static PropertyCellType UpdatedType(Isolate* isolate,
1582  Handle<PropertyCell> cell,
1583  Handle<Object> value,
1584  PropertyDetails details);
1585  // Prepares property cell at given entry for receiving given value.
1586  // As a result the old cell could be invalidated and/or dependent code could
1587  // be deoptimized. Returns the prepared property cell.
1588  static Handle<PropertyCell> PrepareForValue(
1589  Isolate* isolate, Handle<GlobalDictionary> dictionary, int entry,
1590  Handle<Object> value, PropertyDetails details);
1591 
1592  static Handle<PropertyCell> InvalidateEntry(
1593  Isolate* isolate, Handle<GlobalDictionary> dictionary, int entry);
1594 
1595  static void SetValueWithInvalidation(Isolate* isolate,
1596  Handle<PropertyCell> cell,
1597  Handle<Object> new_value);
1598 
1599  DECL_CAST(PropertyCell)
1600 
1601  // Dispatched behavior.
1602  DECL_PRINTER(PropertyCell)
1603  DECL_VERIFIER(PropertyCell)
1604 
1605  // Layout description.
1606  static const int kDetailsOffset = HeapObject::kHeaderSize;
1607  static const int kNameOffset = kDetailsOffset + kPointerSize;
1608  static const int kValueOffset = kNameOffset + kPointerSize;
1609  static const int kDependentCodeOffset = kValueOffset + kPointerSize;
1610  static const int kSize = kDependentCodeOffset + kPointerSize;
1611 
1613 
1614  private:
1615  DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell);
1616 };
1617 
1618 // Foreign describes objects pointing from JavaScript to C structures.
1619 class Foreign: public HeapObject {
1620  public:
1621  // [address]: field containing the address.
1622  inline Address foreign_address();
1623 
1624  static inline bool IsNormalized(Object* object);
1625 
1626  DECL_CAST(Foreign)
1627 
1628  // Dispatched behavior.
1629  DECL_PRINTER(Foreign)
1630  DECL_VERIFIER(Foreign)
1631 
1632  // Layout description.
1633 
1634  static const int kForeignAddressOffset = HeapObject::kHeaderSize;
1635  static const int kSize = kForeignAddressOffset + kPointerSize;
1636 
1637  STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset);
1638 
1639  class BodyDescriptor;
1640 
1641  private:
1642  friend class Factory;
1643  friend class SerializerDeserializer;
1644  friend class StartupSerializer;
1645 
1646  inline void set_foreign_address(Address value);
1647 
1648  DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
1649 };
1650 
1651 // Support for JavaScript accessors: A pair of a getter and a setter. Each
1652 // accessor can either be
1653 // * a JavaScript function or proxy: a real accessor
1654 // * a FunctionTemplateInfo: a real (lazy) accessor
1655 // * undefined: considered an accessor by the spec, too, strangely enough
1656 // * null: an accessor which has not been set
1657 class AccessorPair: public Struct {
1658  public:
1659  DECL_ACCESSORS(getter, Object)
1660  DECL_ACCESSORS(setter, Object)
1661 
1662  DECL_CAST(AccessorPair)
1663 
1664  static Handle<AccessorPair> Copy(Isolate* isolate, Handle<AccessorPair> pair);
1665 
1666  inline Object* get(AccessorComponent component);
1667  inline void set(AccessorComponent component, Object* value);
1668 
1669  // Note: Returns undefined if the component is not set.
1670  static Handle<Object> GetComponent(Isolate* isolate,
1671  Handle<AccessorPair> accessor_pair,
1672  AccessorComponent component);
1673 
1674  // Set both components, skipping arguments which are a JavaScript null.
1675  inline void SetComponents(Object* getter, Object* setter);
1676 
1677  inline bool Equals(AccessorPair* pair);
1678  inline bool Equals(Object* getter_value, Object* setter_value);
1679 
1680  inline bool ContainsAccessor();
1681 
1682  // Dispatched behavior.
1683  DECL_PRINTER(AccessorPair)
1684  DECL_VERIFIER(AccessorPair)
1685 
1686  static const int kGetterOffset = HeapObject::kHeaderSize;
1687  static const int kSetterOffset = kGetterOffset + kPointerSize;
1688  static const int kSize = kSetterOffset + kPointerSize;
1689 
1690  private:
1691  // Strangely enough, in addition to functions and harmony proxies, the spec
1692  // requires us to consider undefined as a kind of accessor, too:
1693  // var obj = {};
1694  // Object.defineProperty(obj, "foo", {get: undefined});
1695  // assertTrue("foo" in obj);
1696  inline bool IsJSAccessor(Object* obj);
1697 
1698  DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
1699 };
1700 
1701 // BooleanBit is a helper class for setting and getting a bit in an integer.
1702 class BooleanBit : public AllStatic {
1703  public:
1704  static inline bool get(int value, int bit_position) {
1705  return (value & (1 << bit_position)) != 0;
1706  }
1707 
1708  static inline int set(int value, int bit_position, bool v) {
1709  if (v) {
1710  value |= (1 << bit_position);
1711  } else {
1712  value &= ~(1 << bit_position);
1713  }
1714  return value;
1715  }
1716 };
1717 
1718 
1719 } // NOLINT, false-positive due to second-order macros.
1720 } // NOLINT, false-positive due to second-order macros.
1721 
1722 #include "src/objects/object-macros-undef.h"
1723 
1724 #endif // V8_OBJECTS_H_
KeyCollectionMode
Definition: v8.h:3217
Definition: v8.h:56
Definition: libplatform.h:13