5 #ifndef V8_OBJECTS_SHARED_FUNCTION_INFO_H_ 6 #define V8_OBJECTS_SHARED_FUNCTION_INFO_H_ 8 #include "src/bailout-reason.h" 9 #include "src/objects.h" 10 #include "src/objects/builtin-function-id.h" 11 #include "src/objects/script.h" 12 #include "src/objects/smi.h" 15 #include "src/objects/object-macros.h" 24 class WasmExportedFunctionData;
31 DECL_INT_ACCESSORS(length)
33 inline Object* child_data(
int index)
const;
34 inline void set_child_data(
int index,
Object* value,
35 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
40 inline void clear_padding();
47 #define PRE_PARSED_SCOPE_DATA_FIELDS(V) \ 48 V(kScopeDataOffset, kTaggedSize) \ 49 V(kLengthOffset, kIntSize) \ 50 V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \ 52 V(kChildDataStartOffset, 0) 54 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
55 PRE_PARSED_SCOPE_DATA_FIELDS)
56 #undef PRE_PARSED_SCOPE_DATA_FIELDS 60 static constexpr
int SizeFor(
int length) {
61 return kChildDataStartOffset + length * kTaggedSize;
72 DECL_ACCESSORS2(inferred_name,
String)
73 DECL_INT32_ACCESSORS(start_position)
74 DECL_INT32_ACCESSORS(end_position)
75 DECL_INT32_ACCESSORS(function_literal_id)
80 #define UNCOMPILED_DATA_FIELDS(V) \ 81 V(kStartOfPointerFieldsOffset, 0) \ 82 V(kInferredNameOffset, kTaggedSize) \ 83 V(kEndOfTaggedFieldsOffset, 0) \ 85 V(kStartPositionOffset, kInt32Size) \ 86 V(kEndPositionOffset, kInt32Size) \ 87 V(kFunctionLiteralIdOffset, kInt32Size) \ 88 V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \ 92 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, UNCOMPILED_DATA_FIELDS)
93 #undef UNCOMPILED_DATA_FIELDS 96 kEndOfTaggedFieldsOffset, kSize>
100 inline void clear_padding();
115 static const int kSize = UncompiledData::kSize;
135 #define UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_FIELDS(V) \ 136 V(kStartOfPointerFieldsOffset, 0) \ 137 V(kPreParsedScopeDataOffset, kTaggedSize) \ 138 V(kEndOfTaggedFieldsOffset, 0) \ 142 DEFINE_FIELD_OFFSET_CONSTANTS(UncompiledData::kSize,
143 UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_FIELDS)
144 #undef UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_FIELDS 147 STATIC_ASSERT(kSize == POINTER_SIZE_ALIGN(kSize));
162 DECL_ACCESSORS2(interpreter_trampoline,
Code)
165 #define INTERPRETER_DATA_FIELDS(V) \ 166 V(kBytecodeArrayOffset, kTaggedSize) \ 167 V(kInterpreterTrampolineOffset, kTaggedSize) \ 171 DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, INTERPRETER_DATA_FIELDS)
172 #undef INTERPRETER_DATA_FIELDS 186 static constexpr
ObjectPtr const kNoSharedNameSentinel = Smi::kZero;
190 inline void SetName(
String name);
193 Code GetCode()
const;
204 inline bool IsInterpreted()
const;
208 V8_EXPORT_PRIVATE
static void SetScript(
210 int function_literal_id,
bool reset_preparsed_scope_data =
true);
213 static const int kEntriesStart = 0;
214 static const int kContextOffset = 0;
215 static const int kCachedCodeOffset = 1;
216 static const int kEntryLength = 2;
217 static const int kInitialLength = kEntriesStart + kEntryLength;
219 static const int kNotFound = -1;
220 static const uint16_t kInvalidLength =
static_cast<uint16_t
>(-1);
226 V8_EXPORT_PRIVATE
int EndPosition()
const;
229 V8_EXPORT_PRIVATE
int StartPosition()
const;
233 V8_EXPORT_PRIVATE
void SetPosition(
int start_position,
int end_position);
237 DECL_ACCESSORS(raw_outer_scope_info_or_feedback_metadata,
HeapObject)
240 inline bool HasOuterScopeInfo()
const;
241 inline ScopeInfo GetOuterScopeInfo()
const;
245 inline bool HasFeedbackMetadata()
const;
249 inline bool is_compiled()
const;
255 inline uint16_t GetLength()
const;
256 inline bool HasLength()
const;
257 inline void set_length(
int value);
262 DECL_UINT16_ACCESSORS(internal_formal_parameter_count)
266 inline void DontAdaptArguments();
270 DECL_UINT8_ACCESSORS(expected_nof_properties)
272 #if V8_SFI_HAS_UNIQUE_ID 275 DECL_INT_ACCESSORS(unique_id)
291 DECL_ACCESSORS(function_data,
Object)
293 inline bool IsApiFunction()
const;
296 inline bool HasBytecodeArray()
const;
299 inline Code InterpreterTrampoline()
const;
300 inline bool HasInterpreterData()
const;
305 inline bool HasAsmWasmData()
const;
314 inline bool HasBuiltinId()
const;
315 inline int builtin_id()
const;
316 inline void set_builtin_id(
int builtin_id);
317 inline bool HasUncompiledData()
const;
320 inline bool HasUncompiledDataWithPreParsedScope()
const;
322 uncompiled_data_with_pre_parsed_scope()
const;
323 inline void set_uncompiled_data_with_pre_parsed_scope(
325 inline bool HasUncompiledDataWithoutPreParsedScope()
const;
326 inline bool HasWasmExportedFunctionData()
const;
332 inline void ClearPreParsedScopeData();
338 DECL_UINT8_ACCESSORS(raw_builtin_function_id)
339 inline bool HasBuiltinFunctionId();
340 inline BuiltinFunctionId builtin_function_id();
341 inline void set_builtin_function_id(BuiltinFunctionId
id);
343 STATIC_ASSERT((std::is_same<std::underlying_type<BuiltinFunctionId>::type,
350 inline bool HasInferredName();
351 inline String inferred_name();
354 V8_EXPORT_PRIVATE
int FunctionLiteralId(
Isolate* isolate)
const;
358 bool HasBreakInfo()
const;
359 bool BreakAtEntry()
const;
363 bool HasCoverageInfo()
const;
370 bool PassesFilter(
const char* raw_filter);
375 DECL_ACCESSORS(script_or_debug_info,
Object)
377 inline Object* script()
const;
378 inline void set_script(
Object* script);
381 inline bool HasDebugInfo()
const;
383 inline void SetDebugInfo(
DebugInfo* debug_info);
388 DECL_UINT16_ACCESSORS(raw_function_token_offset)
393 inline int function_token_position()
const;
396 inline bool HasSharedName()
const;
399 DECL_INT_ACCESSORS(flags)
402 DECL_BOOLEAN_ACCESSORS(is_named_expression)
405 DECL_BOOLEAN_ACCESSORS(is_toplevel)
408 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
411 inline LanguageMode language_mode()
const;
412 inline void set_language_mode(LanguageMode language_mode);
415 DECL_BOOLEAN_ACCESSORS(is_wrapped)
418 DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
424 DECL_BOOLEAN_ACCESSORS(native)
427 DECL_BOOLEAN_ACCESSORS(is_declaration)
430 DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken)
436 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
441 DECL_BOOLEAN_ACCESSORS(is_anonymous_expression)
444 DECL_BOOLEAN_ACCESSORS(deserialized)
447 DECL_BOOLEAN_ACCESSORS(has_reported_binary_coverage)
449 inline FunctionKind kind()
const;
453 DECL_INT_ACCESSORS(function_map_index)
457 inline void clear_padding();
460 inline void UpdateFunctionMapIndex();
465 inline bool optimization_disabled()
const;
468 inline BailoutReason disable_optimization_reason()
const;
472 void DisableOptimization(BailoutReason reason);
478 DECL_BOOLEAN_ACCESSORS(requires_instance_members_initializer)
481 bool HasSourceCode()
const;
490 inline bool IsSubjectToDebugging();
493 inline bool IsUserJavaScript();
497 inline bool CanDiscardCompiled()
const;
501 static inline void DiscardCompiled(
Isolate* isolate,
513 inline bool has_simple_parameters();
524 void SetFunctionTokenPosition(
int function_token_position,
527 inline bool construct_as_builtin()
const;
534 inline void CalculateConstructAsBuiltin();
540 void PrintSourceCode(std::ostream& os);
550 int CurrentIndex()
const {
return index_ - 1; }
553 void Reset(
Script* script);
572 DISALLOW_HEAP_ALLOCATION(no_gc_);
579 static const uint16_t kDontAdaptArgumentsSentinel =
static_cast<uint16_t
>(-1);
581 static const int kMaximumFunctionTokenOffset = kMaxUInt16 - 1;
582 static const uint16_t kFunctionTokenOutOfRange =
static_cast<uint16_t
>(-1);
583 STATIC_ASSERT(kMaximumFunctionTokenOffset + 1 == kFunctionTokenOutOfRange);
585 #if V8_SFI_HAS_UNIQUE_ID 586 static const int kUniqueIdFieldSize = kInt32Size;
589 static const int kUniqueIdFieldSize = 0;
593 #define SHARED_FUNCTION_INFO_FIELDS(V) \ 595 V(kStartOfPointerFieldsOffset, 0) \ 596 V(kFunctionDataOffset, kTaggedSize) \ 597 V(kNameOrScopeInfoOffset, kTaggedSize) \ 598 V(kOuterScopeInfoOrFeedbackMetadataOffset, kTaggedSize) \ 599 V(kScriptOrDebugInfoOffset, kTaggedSize) \ 600 V(kEndOfTaggedFieldsOffset, 0) \ 602 V(kUniqueIdOffset, kUniqueIdFieldSize) \ 603 V(kLengthOffset, kUInt16Size) \ 604 V(kFormalParameterCountOffset, kUInt16Size) \ 605 V(kExpectedNofPropertiesOffset, kUInt8Size) \ 606 V(kBuiltinFunctionId, kUInt8Size) \ 607 V(kFunctionTokenOffsetOffset, kUInt16Size) \ 608 V(kFlagsOffset, kInt32Size) \ 612 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
613 SHARED_FUNCTION_INFO_FIELDS)
614 #undef SHARED_FUNCTION_INFO_FIELDS 616 static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
619 kEndOfTaggedFieldsOffset, kAlignedSize>
623 #define FLAGS_BIT_FIELDS(V, _) \ 624 V(IsNativeBit, bool, 1, _) \ 625 V(IsStrictBit, bool, 1, _) \ 626 V(IsWrappedBit, bool, 1, _) \ 627 V(IsClassConstructorBit, bool, 1, _) \ 628 V(IsDerivedConstructorBit, bool, 1, _) \ 629 V(FunctionKindBits, FunctionKind, 5, _) \ 630 V(HasDuplicateParametersBit, bool, 1, _) \ 631 V(AllowLazyCompilationBit, bool, 1, _) \ 632 V(NeedsHomeObjectBit, bool, 1, _) \ 633 V(IsDeclarationBit, bool, 1, _) \ 634 V(IsAsmWasmBrokenBit, bool, 1, _) \ 635 V(FunctionMapIndexBits, int, 5, _) \ 636 V(DisabledOptimizationReasonBits, BailoutReason, 4, _) \ 637 V(RequiresInstanceMembersInitializer, bool, 1, _) \ 638 V(ConstructAsBuiltinBit, bool, 1, _) \ 639 V(IsAnonymousExpressionBit, bool, 1, _) \ 640 V(NameShouldPrintAsAnonymousBit, bool, 1, _) \ 641 V(IsDeserializedBit, bool, 1, _) \ 642 V(HasReportedBinaryCoverageBit, bool, 1, _) \ 643 V(IsNamedExpressionBit, bool, 1, _) \ 644 V(IsTopLevelBit, bool, 1, _) 645 DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
646 #undef FLAGS_BIT_FIELDS 649 STATIC_ASSERT(BailoutReason::kLastErrorMessage <=
650 DisabledOptimizationReasonBits::kMax);
652 STATIC_ASSERT(kLastFunctionKind <= FunctionKindBits::kMax);
657 inline bool needs_home_object()
const;
662 DECL_ACCESSORS(name_or_scope_info,
Object)
668 inline void set_kind(FunctionKind kind);
670 inline void set_needs_home_object(
bool value);
674 FRIEND_TEST(PreParserTest, LazyFunctionLength);
676 inline uint16_t length()
const;
680 int FindIndexInScript(
Isolate* isolate)
const;
688 : value(v), max_length(max) {}
693 std::ostream& operator<<(std::ostream& os,
const SourceCodeOf& v);
698 #include "src/objects/object-macros-undef.h" 700 #endif // V8_OBJECTS_SHARED_FUNCTION_INFO_H_