5 #ifndef V8_OBJECTS_JS_OBJECTS_H_ 6 #define V8_OBJECTS_JS_OBJECTS_H_ 8 #include "src/objects.h" 9 #include "src/objects/embedder-data-slot.h" 10 #include "src/objects/property-array.h" 13 #include "src/objects/object-macros.h" 18 enum InstanceType : uint16_t;
27 inline bool HasFastProperties()
const;
60 DECL_ACCESSORS(raw_properties_or_hash,
Object)
62 inline void initialize_properties();
72 ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
84 V8_WARN_UNUSED_RESULT
static Maybe<bool> HasInPrototypeChain(
91 V8_WARN_UNUSED_RESULT
static Maybe<bool> SetOrCopyDataProperties(
98 V8_WARN_UNUSED_RESULT
static inline Maybe<bool> HasProperty(
100 V8_WARN_UNUSED_RESULT
static inline Maybe<bool> HasElement(
103 V8_WARN_UNUSED_RESULT
static Maybe<bool> HasOwnProperty(
105 V8_WARN_UNUSED_RESULT
static inline Maybe<bool> HasOwnProperty(
116 V8_WARN_UNUSED_RESULT
static Maybe<bool> DeletePropertyOrElement(
118 LanguageMode language_mode = LanguageMode::kSloppy);
119 V8_WARN_UNUSED_RESULT
static Maybe<bool> DeleteProperty(
121 LanguageMode language_mode = LanguageMode::kSloppy);
122 V8_WARN_UNUSED_RESULT
static Maybe<bool> DeleteProperty(
124 V8_WARN_UNUSED_RESULT
static Maybe<bool> DeleteElement(
126 LanguageMode language_mode = LanguageMode::kSloppy);
128 V8_WARN_UNUSED_RESULT
static Object* DefineProperty(
135 V8_WARN_UNUSED_RESULT
static Maybe<bool> DefineOwnProperty(
140 V8_WARN_UNUSED_RESULT
static Maybe<bool> CreateDataProperty(
143 V8_WARN_UNUSED_RESULT
static Maybe<bool> CreateDataProperty(
147 V8_WARN_UNUSED_RESULT
static Maybe<bool> OrdinaryDefineOwnProperty(
150 V8_WARN_UNUSED_RESULT
static Maybe<bool> OrdinaryDefineOwnProperty(
153 V8_WARN_UNUSED_RESULT
static Maybe<bool> IsCompatiblePropertyDescriptor(
156 ShouldThrow should_throw);
160 V8_WARN_UNUSED_RESULT
static Maybe<bool> ValidateAndApplyPropertyDescriptor(
165 V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT
static Maybe<bool> 168 V8_WARN_UNUSED_RESULT
static Maybe<bool> GetOwnPropertyDescriptor(
171 typedef PropertyAttributes IntegrityLevel;
175 V8_WARN_UNUSED_RESULT
static Maybe<bool> SetIntegrityLevel(
180 V8_WARN_UNUSED_RESULT
static Maybe<bool> TestIntegrityLevel(
184 V8_WARN_UNUSED_RESULT
static Maybe<bool> PreventExtensions(
187 V8_WARN_UNUSED_RESULT
static Maybe<bool> IsExtensible(
191 V8_EXPORT_PRIVATE
String class_name();
219 V8_WARN_UNUSED_RESULT
static Maybe<bool> SetPrototype(
221 ShouldThrow should_throw);
229 Object* GetIdentityHash();
234 Smi GetOrCreateIdentityHash(
Isolate* isolate);
238 void SetIdentityHash(
int masked_hash);
246 bool try_fast_path =
true);
250 bool try_fast_path =
true);
255 static const int kHashMask = PropertyArray::HashField::kMask;
258 static const int kPropertiesOrHashOffset = HeapObject::kHeaderSize;
259 static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize;
261 bool HasProxyInPrototype(
Isolate* isolate);
263 bool HasComplexElements();
275 static bool IsUnmodifiedApiObject(
ObjectSlot o);
306 inline void initialize_elements();
309 inline ElementsKind GetElementsKind()
const;
313 inline bool HasSmiElements();
316 inline bool HasObjectElements();
319 inline bool HasSmiOrObjectElements();
321 inline bool HasFastElements();
323 inline bool HasFastPackedElements();
326 inline bool HasDoubleElements();
329 inline bool HasHoleyElements();
330 inline bool HasSloppyArgumentsElements();
331 inline bool HasStringWrapperElements();
332 inline bool HasDictionaryElements();
334 inline bool HasFixedTypedArrayElements();
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();
349 inline bool HasFastArgumentsElements();
350 inline bool HasSlowArgumentsElements();
351 inline bool HasFastStringWrapperElements();
352 inline bool HasSlowStringWrapperElements();
353 bool HasEnumerableElements();
360 V8_WARN_UNUSED_RESULT
static Maybe<bool> SetPropertyWithInterceptor(
366 enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD };
369 DefineOwnPropertyIgnoreAttributes(
371 AccessorInfoHandling handling = DONT_FORCE_FIELD);
373 V8_WARN_UNUSED_RESULT
static Maybe<bool> DefineOwnPropertyIgnoreAttributes(
375 ShouldThrow should_throw,
376 AccessorInfoHandling handling = DONT_FORCE_FIELD);
381 PropertyAttributes attributes);
386 PropertyAttributes attributes);
394 PropertyAttributes attributes = NONE);
398 V8_WARN_UNUSED_RESULT
static Maybe<bool> CreateDataProperty(
400 ShouldThrow should_throw = kDontThrow);
404 PropertyAttributes attributes);
408 PropertyAttributes attributes);
429 PropertyAttributes attributes);
433 PropertyAttributes attributes);
436 bool enable_setup_mode =
true);
439 WhereToStart where_to_start,
Isolate* isolate);
441 static void UpdatePrototypeUserRegistration(
Handle<Map> old_map,
445 static Map InvalidatePrototypeChains(
Map map);
446 static void InvalidatePrototypeValidityCell(
JSGlobalObject* global);
454 static inline bool PrototypeHasNoElements(
Isolate* isolate,
JSObject*
object);
457 static void PrototypeRegistryCompactionCallback(
HeapObject* value,
458 int old_index,
int new_index);
476 PropertyAttributes attributes);
480 PropertyAttributes attributes);
485 PropertyAttributes attributes);
493 static void ValidateElements(
JSObject*
object);
496 static inline void EnsureCanContainHeapObjectElements(
Handle<JSObject> obj);
502 EnsureElementsMode mode);
506 EnsureElementsMode mode);
510 EnsureElementsMode mode);
514 bool WouldConvertToSlowElements(
uint32_t index);
516 static const uint32_t kMinAddedElementsCapacity = 16;
521 return old_capacity + (old_capacity >> 1) + kMinAddedElementsCapacity;
525 template <AllocationSiteUpdateMode update_or_check =
526 AllocationSiteUpdateMode::kUpdate>
528 ElementsKind to_kind);
532 inline bool HasNamedInterceptor();
533 inline bool HasIndexedInterceptor();
536 V8_WARN_UNUSED_RESULT
static Maybe<bool> HasRealNamedProperty(
538 V8_WARN_UNUSED_RESULT
static Maybe<bool> HasRealElementProperty(
540 V8_WARN_UNUSED_RESULT
static Maybe<bool> HasRealNamedCallbackProperty(
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;
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);
566 bool IsDroppableApiWrapper();
571 ElementsKind to_kind);
573 ElementsKind to_kind);
579 int expected_additional_properties = 0);
590 PropertyNormalizationMode mode,
591 int expected_additional_properties,
602 int unused_property_fields,
const char* reason);
604 inline bool IsUnboxedDoubleField(
FieldIndex index);
611 inline double RawFastDoublePropertyAt(
FieldIndex index);
612 inline uint64_t RawFastDoublePropertyAsBitsAt(
FieldIndex index);
616 inline void RawFastDoublePropertyAsBitsAtPut(
FieldIndex index, uint64_t bits);
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);
627 V8_WARN_UNUSED_RESULT
static Maybe<bool> SetPrototype(
629 ShouldThrow should_throw);
640 inline void InitializeBody(
Map map,
int start_offset,
644 bool ReferencesObject(
Object* obj);
646 V8_WARN_UNUSED_RESULT
static Maybe<bool> TestIntegrityLevel(
649 V8_WARN_UNUSED_RESULT
static Maybe<bool> PreventExtensions(
661 bool PrintProperties(std::ostream& os);
662 void PrintElements(std::ostream& os);
664 #if defined(DEBUG) || defined(OBJECT_PRINT) 665 void PrintTransitions(std::ostream& os);
669 ElementsKind from_kind,
671 ElementsKind to_kind,
674 void PrintInstanceMigration(FILE* file,
Map original_map,
Map new_map);
678 class SpillInformation {
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_;
695 void IncrementSpillStatistics(
Isolate* isolate, SpillInformation* info);
702 bool ElementsAreSafeToExamine()
const;
709 static const uint32_t kMaxElementCount = 0xffffffffu;
716 static const uint32_t kMaxGap = 1024;
720 static const int kMaxUncheckedFastElementsLength = 5000;
724 static const int kMaxUncheckedOldFastElementsLength = 500;
728 static const int kInitialGlobalObjectUnusedPropertiesCount = 4;
730 static const int kMaxInstanceSize = 255 * kPointerSize;
735 static const int kFieldsAdded = 3;
736 STATIC_ASSERT(kMaxNumberOfDescriptors + kFieldsAdded <=
737 PropertyArray::kMaxLength);
740 static const int kElementsOffset = JSReceiver::kHeaderSize;
741 static const int kHeaderSize = kElementsOffset + kPointerSize;
743 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize);
744 static const int kMaxInObjectProperties =
745 (kMaxInstanceSize - kHeaderSize) >> kPointerSizeLog2;
746 STATIC_ASSERT(kMaxInObjectProperties <= kMaxNumberOfDescriptors);
748 static const int kMaxEmbedderFields =
749 (((1 << kFirstInobjectPropertyOffsetBitCount) - 1 - kHeaderSize) >>
751 kEmbedderDataSlotSizeInTaggedSlots;
752 STATIC_ASSERT(kMaxEmbedderFields <= kMaxInObjectProperties);
759 int GetFastElementsUsage();
772 V8_WARN_UNUSED_RESULT
static Maybe<bool> SetPropertyWithFailedAccessCheck(
775 V8_WARN_UNUSED_RESULT
static Maybe<bool> DeletePropertyWithInterceptor(
778 bool ReferencesObjectFromElements(
FixedArray elements, ElementsKind kind,
783 template <PropertyAttributes attrs>
784 V8_WARN_UNUSED_RESULT
static Maybe<bool> PreventExtensionsWithTransition(
787 DISALLOW_IMPLICIT_CONSTRUCTORS(
JSObject);
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;
803 static const int kGetIndex = 0;
804 static const int kSetIndex = 1;
805 static const int kEnumerableIndex = 2;
806 static const int kConfigurableIndex = 3;
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;
825 static const int kValueIndex = 0;
826 static const int kWritableIndex = 1;
827 static const int kEnumerableIndex = 2;
828 static const int kConfigurableIndex = 3;
839 DECL_ACCESSORS(value,
Object)
841 DECL_ACCESSORS(done,
Object)
844 static const int kValueOffset = JSObject::kHeaderSize;
845 static const int kDoneOffset = kValueOffset + kPointerSize;
846 static const int kSize = kDoneOffset + kPointerSize;
848 static const int kValueIndex = 0;
849 static const int kDoneIndex = 1;
859 inline Object* raw_bound_target_function()
const;
860 DECL_ACCESSORS(bound_target_function,
JSReceiver)
864 DECL_ACCESSORS(bound_this,
Object)
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;
901 DECL_ACCESSORS(prototype_or_initial_map,
Object)
907 static const int kLengthDescriptorIndex = 0;
908 static const int kNameDescriptorIndex = 1;
910 static const int kMaybeHomeObjectDescriptorIndex = 2;
914 inline bool has_context()
const;
915 inline void set_context(
Object* context);
917 inline Context native_context();
928 inline void set_code(
Code code);
929 inline void set_code_no_write_barrier(
Code code);
940 inline bool IsInterpreted();
944 inline bool ChecksOptimizationMarker();
950 inline bool IsOptimized();
955 inline bool HasOptimizedCode();
958 inline bool HasOptimizationMarker();
962 void MarkForOptimization(ConcurrencyMode mode);
965 inline bool IsMarkedForOptimization();
966 inline bool IsMarkedForConcurrentOptimization();
969 inline bool IsInOptimizationQueue();
972 inline void ClearOptimizedCodeSlot(
const char* reason);
975 inline void SetOptimizationMarker(OptimizationMarker marker);
978 inline void ClearOptimizationMarker();
983 int ComputeInstanceSizeWithMinSlack(
Isolate* isolate);
986 inline void CompleteInobjectSlackTrackingIfActive();
994 inline bool has_feedback_vector()
const;
998 void ClearTypeFeedbackInfo();
1000 inline bool has_prototype_slot()
const;
1003 inline Map initial_map();
1006 inline bool has_initial_map();
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();
1029 inline bool is_compiled();
1031 static int GetHeaderSize(
bool function_has_prototype_slot) {
1032 return function_has_prototype_slot ? JSFunction::kSizeWithPrototype
1033 : JSFunction::kSizeWithoutPrototype;
1037 void PrintName(FILE* out = stdout);
1042 static bool CalculateInstanceSizeForDerivedClass(
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,
1051 int* in_object_properties);
1081 #define JS_FUNCTION_FIELDS(V) \ 1083 V(kSharedFunctionInfoOffset, kPointerSize) \ 1084 V(kContextOffset, kPointerSize) \ 1085 V(kFeedbackCellOffset, kPointerSize) \ 1086 V(kEndOfStrongFieldsOffset, 0) \ 1087 V(kCodeOffset, kPointerSize) \ 1089 V(kSizeWithoutPrototype, 0) \ 1090 V(kPrototypeOrInitialMapOffset, kPointerSize) \ 1092 V(kSizeWithPrototype, 0) 1094 DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize, JS_FUNCTION_FIELDS)
1095 #undef JS_FUNCTION_FIELDS 1113 DECL_ACCESSORS(native_context,
Object)
1119 static int SizeWithEmbedderFields(
int embedder_field_count);
1126 static const int kNativeContextOffset = JSObject::kHeaderSize;
1127 static const int kSize = kNativeContextOffset + kPointerSize;
1137 DECL_ACCESSORS2(native_context,
Context)
1140 DECL_ACCESSORS(global_proxy,
JSObject)
1151 PropertyCellType cell_type,
int* entry_out =
nullptr);
1155 inline bool IsDetached();
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;
1175 DECL_ACCESSORS(value,
Object)
1184 static const int kValueOffset = JSObject::kHeaderSize;
1185 static const int kSize = kValueOffset + kPointerSize;
1188 DISALLOW_IMPLICIT_CONSTRUCTORS(
JSValue);
1201 DECL_ACCESSORS(value,
Object)
1203 DECL_ACCESSORS(year,
Object)
1205 DECL_ACCESSORS(month,
Object)
1207 DECL_ACCESSORS(day,
Object)
1209 DECL_ACCESSORS(weekday,
Object)
1211 DECL_ACCESSORS(hour,
Object)
1213 DECL_ACCESSORS(min,
Object)
1215 DECL_ACCESSORS(sec,
Object)
1218 DECL_ACCESSORS(cache_stamp,
Object)
1223 static double CurrentTimeValue(
Isolate* isolate);
1232 void SetValue(
Object* value,
bool is_value_nan);
1249 kFirstUncachedField,
1250 kMillisecond = kFirstUncachedField,
1254 kYearUTC = kFirstUTCField,
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;
1280 inline Object* DoGetField(FieldIndex index);
1282 Object* GetUTCField(FieldIndex index,
double value,
DateCache* date_cache);
1287 DISALLOW_IMPLICIT_CONSTRUCTORS(
JSDate);
1299 inline MessageTemplate
type()
const;
1300 inline void set_type(MessageTemplate value);
1303 DECL_ACCESSORS(argument,
Object)
1306 DECL_ACCESSORS(script,
Script)
1309 DECL_ACCESSORS(stack_frames,
Object)
1312 inline int start_position()
const;
1313 inline void set_start_position(
int value);
1316 inline int end_position()
const;
1317 inline void set_end_position(
int value);
1321 int GetLineNumber()
const;
1324 int GetColumnNumber()
const;
1330 inline int error_level()
const;
1331 inline void set_error_level(
int level);
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;
1350 kStackFramesOffset + kPointerSize, kSize>
1374 DECL_ACCESSORS(next,
Object)
1377 static const int kSyncIteratorOffset = JSObject::kHeaderSize;
1378 static const int kNextOffset = kSyncIteratorOffset + kPointerSize;
1379 static const int kSize = kNextOffset + kPointerSize;
1394 DECL_ACCESSORS2(
string,
String)
1397 inline int index()
const;
1398 inline void set_index(
int value);
1400 static const int kStringOffset = JSObject::kHeaderSize;
1401 static const int kNextIndexOffset = kStringOffset + kPointerSize;
1402 static const int kSize = kNextIndexOffset + kPointerSize;
1411 #include "src/objects/object-macros-undef.h" 1413 #endif // V8_OBJECTS_JS_OBJECTS_H_