V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
shared-function-info.h
1 // Copyright 2017 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_SHARED_FUNCTION_INFO_H_
6 #define V8_OBJECTS_SHARED_FUNCTION_INFO_H_
7 
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"
13 
14 // Has to be the last include (doesn't have include guards):
15 #include "src/objects/object-macros.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 class AsmWasmData;
21 class BytecodeArray;
22 class CoverageInfo;
23 class DebugInfo;
24 class WasmExportedFunctionData;
25 
26 // Data collected by the pre-parser storing information about scopes and inner
27 // functions.
29  public:
30  DECL_ACCESSORS2(scope_data, PodArray<uint8_t>)
31  DECL_INT_ACCESSORS(length)
32 
33  inline Object* child_data(int index) const;
34  inline void set_child_data(int index, Object* value,
35  WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
36 
37  inline ObjectSlot child_data_start() const;
38 
39  // Clear uninitialized padding space.
40  inline void clear_padding();
41 
42  DECL_CAST(PreParsedScopeData)
43  DECL_PRINTER(PreParsedScopeData)
44  DECL_VERIFIER(PreParsedScopeData)
45 
46 // Layout description.
47 #define PRE_PARSED_SCOPE_DATA_FIELDS(V) \
48  V(kScopeDataOffset, kTaggedSize) \
49  V(kLengthOffset, kIntSize) \
50  V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \
51  /* Header size. */ \
52  V(kChildDataStartOffset, 0)
53 
54  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
55  PRE_PARSED_SCOPE_DATA_FIELDS)
56 #undef PRE_PARSED_SCOPE_DATA_FIELDS
57 
58  class BodyDescriptor;
59 
60  static constexpr int SizeFor(int length) {
61  return kChildDataStartOffset + length * kTaggedSize;
62  }
63 
64  private:
65  DISALLOW_IMPLICIT_CONSTRUCTORS(PreParsedScopeData);
66 };
67 
68 // Abstract class representing extra data for an uncompiled function, which is
69 // not stored in the SharedFunctionInfo.
70 class UncompiledData : public HeapObject {
71  public:
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)
76 
77  DECL_CAST(UncompiledData)
78 
79 // Layout description.
80 #define UNCOMPILED_DATA_FIELDS(V) \
81  V(kStartOfPointerFieldsOffset, 0) \
82  V(kInferredNameOffset, kTaggedSize) \
83  V(kEndOfTaggedFieldsOffset, 0) \
84  /* Raw data fields. */ \
85  V(kStartPositionOffset, kInt32Size) \
86  V(kEndPositionOffset, kInt32Size) \
87  V(kFunctionLiteralIdOffset, kInt32Size) \
88  V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \
89  /* Header size. */ \
90  V(kSize, 0)
91 
92  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, UNCOMPILED_DATA_FIELDS)
93 #undef UNCOMPILED_DATA_FIELDS
94 
95  typedef FixedBodyDescriptor<kStartOfPointerFieldsOffset,
96  kEndOfTaggedFieldsOffset, kSize>
98 
99  // Clear uninitialized padding space.
100  inline void clear_padding();
101 
102  private:
103  DISALLOW_IMPLICIT_CONSTRUCTORS(UncompiledData);
104 };
105 
106 // Class representing data for an uncompiled function that does not have any
107 // data from the pre-parser, either because it's a leaf function or because the
108 // pre-parser bailed out.
110  public:
114 
115  static const int kSize = UncompiledData::kSize;
116 
117  // No extra fields compared to UncompiledData.
119 
120  private:
121  DISALLOW_IMPLICIT_CONSTRUCTORS(UncompiledDataWithoutPreParsedScope);
122 };
123 
124 // Class representing data for an uncompiled function that has pre-parsed scope
125 // data.
127  public:
128  DECL_ACCESSORS(pre_parsed_scope_data, PreParsedScopeData)
129 
132  DECL_VERIFIER(UncompiledDataWithPreParsedScope)
133 
134 // Layout description.
135 #define UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_FIELDS(V) \
136  V(kStartOfPointerFieldsOffset, 0) \
137  V(kPreParsedScopeDataOffset, kTaggedSize) \
138  V(kEndOfTaggedFieldsOffset, 0) \
139  /* Total size. */ \
140  V(kSize, 0)
141 
142  DEFINE_FIELD_OFFSET_CONSTANTS(UncompiledData::kSize,
143  UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_FIELDS)
144 #undef UNCOMPILED_DATA_WITH_PRE_PARSED_SCOPE_FIELDS
145 
146  // Make sure the size is aligned
147  STATIC_ASSERT(kSize == POINTER_SIZE_ALIGN(kSize));
148 
149  typedef SubclassBodyDescriptor<
151  FixedBodyDescriptor<kStartOfPointerFieldsOffset, kEndOfTaggedFieldsOffset,
152  kSize>>
154 
155  private:
156  DISALLOW_IMPLICIT_CONSTRUCTORS(UncompiledDataWithPreParsedScope);
157 };
158 
159 class InterpreterData : public Struct {
160  public:
161  DECL_ACCESSORS2(bytecode_array, BytecodeArray)
162  DECL_ACCESSORS2(interpreter_trampoline, Code)
163 
164 // Layout description.
165 #define INTERPRETER_DATA_FIELDS(V) \
166  V(kBytecodeArrayOffset, kTaggedSize) \
167  V(kInterpreterTrampolineOffset, kTaggedSize) \
168  /* Total size. */ \
169  V(kSize, 0)
170 
171  DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, INTERPRETER_DATA_FIELDS)
172 #undef INTERPRETER_DATA_FIELDS
173 
174  DECL_CAST(InterpreterData)
175  DECL_PRINTER(InterpreterData)
176  DECL_VERIFIER(InterpreterData)
177 
178  private:
179  DISALLOW_IMPLICIT_CONSTRUCTORS(InterpreterData);
180 };
181 
182 // SharedFunctionInfo describes the JSFunction information that can be
183 // shared by multiple instances of the function.
185  public:
186  static constexpr ObjectPtr const kNoSharedNameSentinel = Smi::kZero;
187 
188  // [name]: Returns shared name if it exists or an empty string otherwise.
189  inline String Name() const;
190  inline void SetName(String name);
191 
192  // Get the code object which represents the execution of this function.
193  Code GetCode() const;
194 
195  // Get the abstract code associated with the function, which will either be
196  // a Code object or a BytecodeArray.
197  inline AbstractCode abstract_code();
198 
199  // Tells whether or not this shared function info is interpreted.
200  //
201  // Note: function->IsInterpreted() does not necessarily return the same value
202  // as function->shared()->IsInterpreted() because the closure might have been
203  // optimized.
204  inline bool IsInterpreted() const;
205 
206  // Set up the link between shared function info and the script. The shared
207  // function info is added to the list on the script.
208  V8_EXPORT_PRIVATE static void SetScript(
209  Handle<SharedFunctionInfo> shared, Handle<Object> script_object,
210  int function_literal_id, bool reset_preparsed_scope_data = true);
211 
212  // Layout description of the optimized code map.
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;
218 
219  static const int kNotFound = -1;
220  static const uint16_t kInvalidLength = static_cast<uint16_t>(-1);
221 
222  // [scope_info]: Scope info.
223  DECL_ACCESSORS2(scope_info, ScopeInfo)
224 
225  // End position of this function in the script source.
226  V8_EXPORT_PRIVATE int EndPosition() const;
227 
228  // Start position of this function in the script source.
229  V8_EXPORT_PRIVATE int StartPosition() const;
230 
231  // Set the start and end position of this function in the script source.
232  // Updates the scope info if available.
233  V8_EXPORT_PRIVATE void SetPosition(int start_position, int end_position);
234 
235  // [outer scope info | feedback metadata] Shared storage for outer scope info
236  // (on uncompiled functions) and feedback metadata (on compiled functions).
237  DECL_ACCESSORS(raw_outer_scope_info_or_feedback_metadata, HeapObject)
238 
239  // Get the outer scope info whether this function is compiled or not.
240  inline bool HasOuterScopeInfo() const;
241  inline ScopeInfo GetOuterScopeInfo() const;
242 
243  // [feedback metadata] Metadata template for feedback vectors of instances of
244  // this function.
245  inline bool HasFeedbackMetadata() const;
246  DECL_ACCESSORS(feedback_metadata, FeedbackMetadata)
247 
248  // Returns if this function has been compiled to native code yet.
249  inline bool is_compiled() const;
250 
251  // [length]: The function length - usually the number of declared parameters.
252  // Use up to 2^16-2 parameters (16 bits of values, where one is reserved for
253  // kDontAdaptArgumentsSentinel). The value is only reliable when the function
254  // has been compiled.
255  inline uint16_t GetLength() const;
256  inline bool HasLength() const;
257  inline void set_length(int value);
258 
259  // [internal formal parameter count]: The declared number of parameters.
260  // For subclass constructors, also includes new.target.
261  // The size of function's frame is internal_formal_parameter_count + 1.
262  DECL_UINT16_ACCESSORS(internal_formal_parameter_count)
263 
264  // Set the formal parameter count so the function code will be
265  // called without using argument adaptor frames.
266  inline void DontAdaptArguments();
267 
268  // [expected_nof_properties]: Expected number of properties for the
269  // function. The value is only reliable when the function has been compiled.
270  DECL_UINT8_ACCESSORS(expected_nof_properties)
271 
272 #if V8_SFI_HAS_UNIQUE_ID
273  // [unique_id] - For --trace-maps purposes, an identifier that's persistent
274  // even if the GC moves this SharedFunctionInfo.
275  DECL_INT_ACCESSORS(unique_id)
276 #endif
277 
278  // [function data]: This field holds some additional data for function.
279  // Currently it has one of:
280  // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()].
281  // - a BytecodeArray for the interpreter [HasBytecodeArray()].
282  // - a InterpreterData with the BytecodeArray and a copy of the
283  // interpreter trampoline [HasInterpreterData()]
284  // - an AsmWasmData with Asm->Wasm conversion [HasAsmWasmData()].
285  // - a Smi containing the builtin id [HasBuiltinId()]
286  // - a UncompiledDataWithoutPreParsedScope for lazy compilation
287  // [HasUncompiledDataWithoutPreParsedScope()]
288  // - a UncompiledDataWithPreParsedScope for lazy compilation
289  // [HasUncompiledDataWithPreParsedScope()]
290  // - a WasmExportedFunctionData for Wasm [HasWasmExportedFunctionData()]
291  DECL_ACCESSORS(function_data, Object)
292 
293  inline bool IsApiFunction() const;
294  inline FunctionTemplateInfo* get_api_func_data();
295  inline void set_api_func_data(FunctionTemplateInfo* data);
296  inline bool HasBytecodeArray() const;
297  inline BytecodeArray GetBytecodeArray() const;
298  inline void set_bytecode_array(BytecodeArray bytecode);
299  inline Code InterpreterTrampoline() const;
300  inline bool HasInterpreterData() const;
301  inline InterpreterData* interpreter_data() const;
302  inline void set_interpreter_data(InterpreterData* interpreter_data);
303  inline BytecodeArray GetDebugBytecodeArray() const;
304  inline void SetDebugBytecodeArray(BytecodeArray bytecode);
305  inline bool HasAsmWasmData() const;
306  inline AsmWasmData* asm_wasm_data() const;
307  inline void set_asm_wasm_data(AsmWasmData* data);
308 
309  // A brief note to clear up possible confusion:
310  // builtin_id corresponds to the auto-generated
311  // Builtins::Name id, while builtin_function_id corresponds to
312  // BuiltinFunctionId (a manually maintained list of 'interesting' functions
313  // mainly used during optimization).
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;
318  inline UncompiledData* uncompiled_data() const;
319  inline void set_uncompiled_data(UncompiledData* data);
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;
327  WasmExportedFunctionData* wasm_exported_function_data() const;
328  inline void set_wasm_exported_function_data(WasmExportedFunctionData* data);
329 
330  // Clear out pre-parsed scope data from UncompiledDataWithPreParsedScope,
331  // turning it into UncompiledDataWithoutPreParsedScope.
332  inline void ClearPreParsedScopeData();
333 
334  // [raw_builtin_function_id]: The id of the built-in function this function
335  // represents, used during optimization to improve code generation.
336  // TODO(leszeks): Once there are no more JS builtins, this can be replaced
337  // by BuiltinId.
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);
342  // Make sure BuiltinFunctionIds fit in a uint8_t
343  STATIC_ASSERT((std::is_same<std::underlying_type<BuiltinFunctionId>::type,
344  uint8_t>::value));
345 
346  // The inferred_name is inferred from variable or property assignment of this
347  // function. It is used to facilitate debugging and profiling of JavaScript
348  // code written in OO style, where almost all functions are anonymous but are
349  // assigned to object properties.
350  inline bool HasInferredName();
351  inline String inferred_name();
352 
353  // Get the function literal id associated with this function, for parsing.
354  V8_EXPORT_PRIVATE int FunctionLiteralId(Isolate* isolate) const;
355 
356  // Break infos are contained in DebugInfo, this is a convenience method
357  // to simplify access.
358  bool HasBreakInfo() const;
359  bool BreakAtEntry() const;
360 
361  // Coverage infos are contained in DebugInfo, this is a convenience method
362  // to simplify access.
363  bool HasCoverageInfo() const;
364  CoverageInfo GetCoverageInfo() const;
365 
366  // The function's name if it is non-empty, otherwise the inferred name.
367  String DebugName();
368 
369  // Used for flags such as --turbo-filter.
370  bool PassesFilter(const char* raw_filter);
371 
372  // [script_or_debug_info]: One of:
373  // - Script from which the function originates.
374  // - a DebugInfo which holds the actual script [HasDebugInfo()].
375  DECL_ACCESSORS(script_or_debug_info, Object)
376 
377  inline Object* script() const;
378  inline void set_script(Object* script);
379 
380  // The function is subject to debugging if a debug info is attached.
381  inline bool HasDebugInfo() const;
382  inline DebugInfo* GetDebugInfo() const;
383  inline void SetDebugInfo(DebugInfo* debug_info);
384 
385  // The offset of the 'function' token in the script source relative to the
386  // start position. Can return kFunctionTokenOutOfRange if offset doesn't
387  // fit in 16 bits.
388  DECL_UINT16_ACCESSORS(raw_function_token_offset)
389 
390  // The position of the 'function' token in the script source. Can return
391  // kNoSourcePosition if raw_function_token_offset() returns
392  // kFunctionTokenOutOfRange.
393  inline int function_token_position() const;
394 
395  // Returns true if the function has shared name.
396  inline bool HasSharedName() const;
397 
398  // [flags] Bit field containing various flags about the function.
399  DECL_INT_ACCESSORS(flags)
400 
401  // Is this function a named function expression in the source code.
402  DECL_BOOLEAN_ACCESSORS(is_named_expression)
403 
404  // Is this function a top-level function (scripts, evals).
405  DECL_BOOLEAN_ACCESSORS(is_toplevel)
406 
407  // Indicates if this function can be lazy compiled.
408  DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
409 
410  // Indicates the language mode.
411  inline LanguageMode language_mode() const;
412  inline void set_language_mode(LanguageMode language_mode);
413 
414  // Indicates whether the source is implicitly wrapped in a function.
415  DECL_BOOLEAN_ACCESSORS(is_wrapped)
416 
417  // True if the function has any duplicated parameter names.
418  DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
419 
420  // Indicates whether the function is a native function.
421  // These needs special treatment in .call and .apply since
422  // null passed as the receiver should not be translated to the
423  // global object.
424  DECL_BOOLEAN_ACCESSORS(native)
425 
426  // Whether this function was created from a FunctionDeclaration.
427  DECL_BOOLEAN_ACCESSORS(is_declaration)
428 
429  // Indicates that asm->wasm conversion failed and should not be re-attempted.
430  DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken)
431 
432  // Indicates that the function was created by the Function function.
433  // Though it's anonymous, toString should treat it as if it had the name
434  // "anonymous". We don't set the name itself so that the system does not
435  // see a binding for it.
436  DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
437 
438  // Indicates that the function is either an anonymous expression
439  // or an arrow function (the name field can be set through the API,
440  // which does not change this flag).
441  DECL_BOOLEAN_ACCESSORS(is_anonymous_expression)
442 
443  // Indicates that the the shared function info is deserialized from cache.
444  DECL_BOOLEAN_ACCESSORS(deserialized)
445 
446  // Indicates that the function has been reported for binary code coverage.
447  DECL_BOOLEAN_ACCESSORS(has_reported_binary_coverage)
448 
449  inline FunctionKind kind() const;
450 
451  // Defines the index in a native context of closure's map instantiated using
452  // this shared function info.
453  DECL_INT_ACCESSORS(function_map_index)
454 
455  // Clear uninitialized padding space. This ensures that the snapshot content
456  // is deterministic.
457  inline void clear_padding();
458 
459  // Recalculates the |map_index| value after modifications of this shared info.
460  inline void UpdateFunctionMapIndex();
461 
462  // Indicates whether optimizations have been disabled for this shared function
463  // info. If we cannot optimize the function we disable optimization to avoid
464  // spending time attempting to optimize it again.
465  inline bool optimization_disabled() const;
466 
467  // The reason why optimization was disabled.
468  inline BailoutReason disable_optimization_reason() const;
469 
470  // Disable (further) attempted optimization of all functions sharing this
471  // shared function info.
472  void DisableOptimization(BailoutReason reason);
473 
474  // This class constructor needs to call out to an instance fields
475  // initializer. This flag is set when creating the
476  // SharedFunctionInfo as a reminder to emit the initializer call
477  // when generating code later.
478  DECL_BOOLEAN_ACCESSORS(requires_instance_members_initializer)
479 
480  // [source code]: Source code for the function.
481  bool HasSourceCode() const;
482  static Handle<Object> GetSourceCode(Handle<SharedFunctionInfo> shared);
483  static Handle<Object> GetSourceCodeHarmony(Handle<SharedFunctionInfo> shared);
484 
485  // Tells whether this function should be subject to debugging, e.g. for
486  // - scope inspection
487  // - internal break points
488  // - coverage and type profile
489  // - error stack trace
490  inline bool IsSubjectToDebugging();
491 
492  // Whether this function is defined in user-provided JavaScript code.
493  inline bool IsUserJavaScript();
494 
495  // True if one can flush compiled code from this function, in such a way that
496  // it can later be re-compiled.
497  inline bool CanDiscardCompiled() const;
498 
499  // Flush compiled data from this function, setting it back to CompileLazy and
500  // clearing any feedback metadata.
501  static inline void DiscardCompiled(Isolate* isolate,
502  Handle<SharedFunctionInfo> shared_info);
503 
504  // Check whether or not this function is inlineable.
505  bool IsInlineable();
506 
507  // Source size of this function.
508  int SourceSize();
509 
510  // Returns `false` if formal parameters include rest parameters, optional
511  // parameters, or destructuring parameters.
512  // TODO(caitp): make this a flag set during parsing
513  inline bool has_simple_parameters();
514 
515  // Initialize a SharedFunctionInfo from a parsed function literal.
516  static void InitFromFunctionLiteral(Handle<SharedFunctionInfo> shared_info,
517  FunctionLiteral* lit, bool is_toplevel);
518 
519  // Sets the expected number of properties based on estimate from parser.
520  void SetExpectedNofPropertiesFromEstimate(FunctionLiteral* literal);
521 
522  // Sets the FunctionTokenOffset field based on the given token position and
523  // start position.
524  void SetFunctionTokenPosition(int function_token_position,
525  int start_position);
526 
527  inline bool construct_as_builtin() const;
528 
529  // Determines and sets the ConstructAsBuiltinBit in |flags|, based on the
530  // |function_data|. Must be called when creating the SFI after other fields
531  // are initialized. The ConstructAsBuiltinBit determines whether
532  // JSBuiltinsConstructStub or JSConstructStubGeneric should be called to
533  // construct this function.
534  inline void CalculateConstructAsBuiltin();
535 
536  // Dispatched behavior.
537  DECL_PRINTER(SharedFunctionInfo)
538  DECL_VERIFIER(SharedFunctionInfo)
539 #ifdef OBJECT_PRINT
540  void PrintSourceCode(std::ostream& os);
541 #endif
542 
543  // Iterate over all shared function infos in a given script.
545  public:
546  ScriptIterator(Isolate* isolate, Script* script);
547  ScriptIterator(Isolate* isolate,
548  Handle<WeakFixedArray> shared_function_infos);
549  SharedFunctionInfo* Next();
550  int CurrentIndex() const { return index_ - 1; }
551 
552  // Reset the iterator to run on |script|.
553  void Reset(Script* script);
554 
555  private:
556  Isolate* isolate_;
557  Handle<WeakFixedArray> shared_function_infos_;
558  int index_;
559  DISALLOW_COPY_AND_ASSIGN(ScriptIterator);
560  };
561 
562  // Iterate over all shared function infos on the heap.
564  public:
565  explicit GlobalIterator(Isolate* isolate);
566  SharedFunctionInfo* Next();
567 
568  private:
569  Script::Iterator script_iterator_;
570  WeakArrayList::Iterator noscript_sfi_iterator_;
572  DISALLOW_HEAP_ALLOCATION(no_gc_);
573  DISALLOW_COPY_AND_ASSIGN(GlobalIterator);
574  };
575 
576  DECL_CAST(SharedFunctionInfo)
577 
578  // Constants.
579  static const uint16_t kDontAdaptArgumentsSentinel = static_cast<uint16_t>(-1);
580 
581  static const int kMaximumFunctionTokenOffset = kMaxUInt16 - 1;
582  static const uint16_t kFunctionTokenOutOfRange = static_cast<uint16_t>(-1);
583  STATIC_ASSERT(kMaximumFunctionTokenOffset + 1 == kFunctionTokenOutOfRange);
584 
585 #if V8_SFI_HAS_UNIQUE_ID
586  static const int kUniqueIdFieldSize = kInt32Size;
587 #else
588  // Just to not break the postmortrem support with conditional offsets
589  static const int kUniqueIdFieldSize = 0;
590 #endif
591 
592 // Layout description.
593 #define SHARED_FUNCTION_INFO_FIELDS(V) \
594  /* Pointer fields. */ \
595  V(kStartOfPointerFieldsOffset, 0) \
596  V(kFunctionDataOffset, kTaggedSize) \
597  V(kNameOrScopeInfoOffset, kTaggedSize) \
598  V(kOuterScopeInfoOrFeedbackMetadataOffset, kTaggedSize) \
599  V(kScriptOrDebugInfoOffset, kTaggedSize) \
600  V(kEndOfTaggedFieldsOffset, 0) \
601  /* Raw data fields. */ \
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) \
609  /* Total size. */ \
610  V(kSize, 0)
611 
612  DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
613  SHARED_FUNCTION_INFO_FIELDS)
614 #undef SHARED_FUNCTION_INFO_FIELDS
615 
616  static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
617 
618  typedef FixedBodyDescriptor<kStartOfPointerFieldsOffset,
619  kEndOfTaggedFieldsOffset, kAlignedSize>
621 
622 // Bit positions in |flags|.
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
647 
648  // Bailout reasons must fit in the DisabledOptimizationReason bitfield.
649  STATIC_ASSERT(BailoutReason::kLastErrorMessage <=
650  DisabledOptimizationReasonBits::kMax);
651 
652  STATIC_ASSERT(kLastFunctionKind <= FunctionKindBits::kMax);
653 
654  // Indicates that this function uses a super property (or an eval that may
655  // use a super property).
656  // This is needed to set up the [[HomeObject]] on the function instance.
657  inline bool needs_home_object() const;
658 
659  private:
660  // [name_or_scope_info]: Function name string, kNoSharedNameSentinel or
661  // ScopeInfo.
662  DECL_ACCESSORS(name_or_scope_info, Object)
663 
664  // [outer scope info] The outer scope info, needed to lazily parse this
665  // function.
666  DECL_ACCESSORS(outer_scope_info, HeapObject)
667 
668  inline void set_kind(FunctionKind kind);
669 
670  inline void set_needs_home_object(bool value);
671 
672  friend class Factory;
673  friend class V8HeapExplorer;
674  FRIEND_TEST(PreParserTest, LazyFunctionLength);
675 
676  inline uint16_t length() const;
677 
678  // Find the index of this function in the parent script. Slow path of
679  // FunctionLiteralId.
680  int FindIndexInScript(Isolate* isolate) const;
681 
682  DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
683 };
684 
685 // Printing support.
686 struct SourceCodeOf {
687  explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1)
688  : value(v), max_length(max) {}
689  const SharedFunctionInfo* value;
690  int max_length;
691 };
692 
693 std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v);
694 
695 } // namespace internal
696 } // namespace v8
697 
698 #include "src/objects/object-macros-undef.h"
699 
700 #endif // V8_OBJECTS_SHARED_FUNCTION_INFO_H_
Definition: libplatform.h:13