11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_JS_FUNCTION_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_FUNCTION_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/objects/code-kind.h"
91cb0ef41Sopenharmony_ci#include "src/objects/js-objects.h"
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
121cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cinamespace v8 {
151cb0ef41Sopenharmony_cinamespace internal {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-function-tq.inc"
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci// An abstract superclass for classes representing JavaScript function values.
201cb0ef41Sopenharmony_ci// It doesn't carry any functionality but allows function classes to be
211cb0ef41Sopenharmony_ci// identified in the type system.
221cb0ef41Sopenharmony_ciclass JSFunctionOrBoundFunctionOrWrappedFunction
231cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSFunctionOrBoundFunctionOrWrappedFunction<
241cb0ef41Sopenharmony_ci          JSFunctionOrBoundFunctionOrWrappedFunction, JSObject> {
251cb0ef41Sopenharmony_ci public:
261cb0ef41Sopenharmony_ci  static const int kLengthDescriptorIndex = 0;
271cb0ef41Sopenharmony_ci  static const int kNameDescriptorIndex = 1;
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  // https://tc39.es/proposal-shadowrealm/#sec-copynameandlength
301cb0ef41Sopenharmony_ci  static Maybe<bool> CopyNameAndLength(
311cb0ef41Sopenharmony_ci      Isolate* isolate,
321cb0ef41Sopenharmony_ci      Handle<JSFunctionOrBoundFunctionOrWrappedFunction> function,
331cb0ef41Sopenharmony_ci      Handle<JSReceiver> target, Handle<String> prefix, int arg_count);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  STATIC_ASSERT(kHeaderSize == JSObject::kHeaderSize);
361cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSFunctionOrBoundFunctionOrWrappedFunction)
371cb0ef41Sopenharmony_ci};
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci// JSBoundFunction describes a bound function exotic object.
401cb0ef41Sopenharmony_ciclass JSBoundFunction
411cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSBoundFunction<
421cb0ef41Sopenharmony_ci          JSBoundFunction, JSFunctionOrBoundFunctionOrWrappedFunction> {
431cb0ef41Sopenharmony_ci public:
441cb0ef41Sopenharmony_ci  static MaybeHandle<String> GetName(Isolate* isolate,
451cb0ef41Sopenharmony_ci                                     Handle<JSBoundFunction> function);
461cb0ef41Sopenharmony_ci  static Maybe<int> GetLength(Isolate* isolate,
471cb0ef41Sopenharmony_ci                              Handle<JSBoundFunction> function);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  // Dispatched behavior.
501cb0ef41Sopenharmony_ci  DECL_PRINTER(JSBoundFunction)
511cb0ef41Sopenharmony_ci  DECL_VERIFIER(JSBoundFunction)
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  // The bound function's string representation implemented according
541cb0ef41Sopenharmony_ci  // to ES6 section 19.2.3.5 Function.prototype.toString ( ).
551cb0ef41Sopenharmony_ci  static Handle<String> ToString(Handle<JSBoundFunction> function);
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSBoundFunction)
581cb0ef41Sopenharmony_ci};
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci// JSWrappedFunction describes a wrapped function exotic object.
611cb0ef41Sopenharmony_ciclass JSWrappedFunction
621cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSWrappedFunction<
631cb0ef41Sopenharmony_ci          JSWrappedFunction, JSFunctionOrBoundFunctionOrWrappedFunction> {
641cb0ef41Sopenharmony_ci public:
651cb0ef41Sopenharmony_ci  static MaybeHandle<String> GetName(Isolate* isolate,
661cb0ef41Sopenharmony_ci                                     Handle<JSWrappedFunction> function);
671cb0ef41Sopenharmony_ci  static Maybe<int> GetLength(Isolate* isolate,
681cb0ef41Sopenharmony_ci                              Handle<JSWrappedFunction> function);
691cb0ef41Sopenharmony_ci  // https://tc39.es/proposal-shadowrealm/#sec-wrappedfunctioncreate
701cb0ef41Sopenharmony_ci  static MaybeHandle<Object> Create(Isolate* isolate,
711cb0ef41Sopenharmony_ci                                    Handle<NativeContext> creation_context,
721cb0ef41Sopenharmony_ci                                    Handle<JSReceiver> value);
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci  // Dispatched behavior.
751cb0ef41Sopenharmony_ci  DECL_PRINTER(JSWrappedFunction)
761cb0ef41Sopenharmony_ci  DECL_VERIFIER(JSWrappedFunction)
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci  // The wrapped function's string representation implemented according
791cb0ef41Sopenharmony_ci  // to ES6 section 19.2.3.5 Function.prototype.toString ( ).
801cb0ef41Sopenharmony_ci  static Handle<String> ToString(Handle<JSWrappedFunction> function);
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSWrappedFunction)
831cb0ef41Sopenharmony_ci};
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci// JSFunction describes JavaScript functions.
861cb0ef41Sopenharmony_ciclass JSFunction : public TorqueGeneratedJSFunction<
871cb0ef41Sopenharmony_ci                       JSFunction, JSFunctionOrBoundFunctionOrWrappedFunction> {
881cb0ef41Sopenharmony_ci public:
891cb0ef41Sopenharmony_ci  // [prototype_or_initial_map]:
901cb0ef41Sopenharmony_ci  DECL_RELEASE_ACQUIRE_ACCESSORS(prototype_or_initial_map, HeapObject)
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci  // [shared]: The information about the function that can be shared by
931cb0ef41Sopenharmony_ci  // instances.
941cb0ef41Sopenharmony_ci  DECL_ACCESSORS(shared, SharedFunctionInfo)
951cb0ef41Sopenharmony_ci  DECL_RELAXED_GETTER(shared, SharedFunctionInfo)
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci  // Fast binding requires length and name accessors.
981cb0ef41Sopenharmony_ci  static const int kMinDescriptorsForFastBindAndWrap = 2;
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  // [context]: The context for this function.
1011cb0ef41Sopenharmony_ci  inline Context context();
1021cb0ef41Sopenharmony_ci  DECL_RELAXED_GETTER(context, Context)
1031cb0ef41Sopenharmony_ci  inline bool has_context() const;
1041cb0ef41Sopenharmony_ci  inline JSGlobalProxy global_proxy();
1051cb0ef41Sopenharmony_ci  inline NativeContext native_context();
1061cb0ef41Sopenharmony_ci  inline int length();
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ci  static Handle<String> GetName(Isolate* isolate, Handle<JSFunction> function);
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ci  // [code]: The generated code object for this function.  Executed
1111cb0ef41Sopenharmony_ci  // when the function is invoked, e.g. foo() or new foo(). See
1121cb0ef41Sopenharmony_ci  // [[Call]] and [[Construct]] description in ECMA-262, section
1131cb0ef41Sopenharmony_ci  // 8.6.2, page 27.
1141cb0ef41Sopenharmony_ci  // Release/Acquire accessors are used when storing a newly-created
1151cb0ef41Sopenharmony_ci  // optimized code object, or when reading from the background thread.
1161cb0ef41Sopenharmony_ci  // Storing a builtin doesn't require release semantics because these objects
1171cb0ef41Sopenharmony_ci  // are fully initialized.
1181cb0ef41Sopenharmony_ci  DECL_ACCESSORS(code, CodeT)
1191cb0ef41Sopenharmony_ci  DECL_RELEASE_ACQUIRE_ACCESSORS(code, CodeT)
1201cb0ef41Sopenharmony_ci#ifdef V8_EXTERNAL_CODE_SPACE
1211cb0ef41Sopenharmony_ci  // Convenient overloads to avoid unnecessary Code <-> CodeT conversions.
1221cb0ef41Sopenharmony_ci  // TODO(v8:11880): remove once |code| accessors are migrated to CodeT.
1231cb0ef41Sopenharmony_ci  inline void set_code(Code code, ReleaseStoreTag,
1241cb0ef41Sopenharmony_ci                       WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1251cb0ef41Sopenharmony_ci#endif
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_ci  // Returns the address of the function code's instruction start.
1281cb0ef41Sopenharmony_ci  inline Address code_entry_point() const;
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_ci  // Get the abstract code associated with the function, which will either be
1311cb0ef41Sopenharmony_ci  // a Code object or a BytecodeArray.
1321cb0ef41Sopenharmony_ci  template <typename IsolateT>
1331cb0ef41Sopenharmony_ci  inline AbstractCode abstract_code(IsolateT* isolate);
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci  // The predicates for querying code kinds related to this function have
1361cb0ef41Sopenharmony_ci  // specific terminology:
1371cb0ef41Sopenharmony_ci  //
1381cb0ef41Sopenharmony_ci  // - Attached: all code kinds that are directly attached to this JSFunction
1391cb0ef41Sopenharmony_ci  //   object.
1401cb0ef41Sopenharmony_ci  // - Available: all code kinds that are either attached or available through
1411cb0ef41Sopenharmony_ci  //   indirect means such as the feedback vector's optimized code cache.
1421cb0ef41Sopenharmony_ci  // - Active: the single code kind that would be executed if this function
1431cb0ef41Sopenharmony_ci  //   were called in its current state. Note that there may not be an active
1441cb0ef41Sopenharmony_ci  //   code kind if the function is not compiled. Also, asm/wasm functions are
1451cb0ef41Sopenharmony_ci  //   currently not supported.
1461cb0ef41Sopenharmony_ci  //
1471cb0ef41Sopenharmony_ci  // Note: code objects that are marked_for_deoptimization are not part of the
1481cb0ef41Sopenharmony_ci  // attached/available/active sets. This is because the JSFunction might have
1491cb0ef41Sopenharmony_ci  // been already deoptimized but its code() still needs to be unlinked, which
1501cb0ef41Sopenharmony_ci  // will happen on its next activation.
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ci  // True, iff any generated code kind is attached/available to this function.
1531cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE bool HasAttachedOptimizedCode() const;
1541cb0ef41Sopenharmony_ci  bool HasAvailableOptimizedCode() const;
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_ci  bool HasAttachedCodeKind(CodeKind kind) const;
1571cb0ef41Sopenharmony_ci  bool HasAvailableCodeKind(CodeKind kind) const;
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ci  base::Optional<CodeKind> GetActiveTier() const;
1601cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE bool ActiveTierIsIgnition() const;
1611cb0ef41Sopenharmony_ci  bool ActiveTierIsBaseline() const;
1621cb0ef41Sopenharmony_ci  bool ActiveTierIsMaglev() const;
1631cb0ef41Sopenharmony_ci  bool ActiveTierIsTurbofan() const;
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci  // Similar to SharedFunctionInfo::CanDiscardCompiled. Returns true, if the
1661cb0ef41Sopenharmony_ci  // attached code can be recreated at a later point by replacing it with
1671cb0ef41Sopenharmony_ci  // CompileLazy.
1681cb0ef41Sopenharmony_ci  bool CanDiscardCompiled() const;
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci  // Tells whether function's code object checks its tiering state (some code
1711cb0ef41Sopenharmony_ci  // kinds, e.g. TURBOFAN, ignore the tiering state).
1721cb0ef41Sopenharmony_ci  inline bool ChecksTieringState();
1731cb0ef41Sopenharmony_ci
1741cb0ef41Sopenharmony_ci  inline TieringState tiering_state() const;
1751cb0ef41Sopenharmony_ci  inline void set_tiering_state(TieringState state);
1761cb0ef41Sopenharmony_ci  inline void reset_tiering_state();
1771cb0ef41Sopenharmony_ci
1781cb0ef41Sopenharmony_ci  // Mark this function for lazy recompilation. The function will be recompiled
1791cb0ef41Sopenharmony_ci  // the next time it is executed.
1801cb0ef41Sopenharmony_ci  void MarkForOptimization(Isolate* isolate, CodeKind target_kind,
1811cb0ef41Sopenharmony_ci                           ConcurrencyMode mode);
1821cb0ef41Sopenharmony_ci
1831cb0ef41Sopenharmony_ci  inline TieringState osr_tiering_state();
1841cb0ef41Sopenharmony_ci  inline void set_osr_tiering_state(TieringState marker);
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci  // Sets the interrupt budget based on whether the function has a feedback
1871cb0ef41Sopenharmony_ci  // vector and any optimized code.
1881cb0ef41Sopenharmony_ci  void SetInterruptBudget(Isolate* isolate);
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci  // If slack tracking is active, it computes instance size of the initial map
1911cb0ef41Sopenharmony_ci  // with minimum permissible object slack.  If it is not active, it simply
1921cb0ef41Sopenharmony_ci  // returns the initial map's instance size.
1931cb0ef41Sopenharmony_ci  int ComputeInstanceSizeWithMinSlack(Isolate* isolate);
1941cb0ef41Sopenharmony_ci
1951cb0ef41Sopenharmony_ci  // Completes inobject slack tracking on initial map if it is active.
1961cb0ef41Sopenharmony_ci  inline void CompleteInobjectSlackTrackingIfActive();
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci  // [raw_feedback_cell]: Gives raw access to the FeedbackCell used to hold the
1991cb0ef41Sopenharmony_ci  /// FeedbackVector eventually. Generally this shouldn't be used to get the
2001cb0ef41Sopenharmony_ci  // feedback_vector, instead use feedback_vector() which correctly deals with
2011cb0ef41Sopenharmony_ci  // the JSFunction's bytecode being flushed.
2021cb0ef41Sopenharmony_ci  DECL_ACCESSORS(raw_feedback_cell, FeedbackCell)
2031cb0ef41Sopenharmony_ci
2041cb0ef41Sopenharmony_ci  // [raw_feedback_cell] (synchronized version) When this is initialized from a
2051cb0ef41Sopenharmony_ci  // newly allocated object (instead of a root sentinel), it should
2061cb0ef41Sopenharmony_ci  // be written with release store semantics.
2071cb0ef41Sopenharmony_ci  DECL_RELEASE_ACQUIRE_ACCESSORS(raw_feedback_cell, FeedbackCell)
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci  // Functions related to feedback vector. feedback_vector() can be used once
2101cb0ef41Sopenharmony_ci  // the function has feedback vectors allocated. feedback vectors may not be
2111cb0ef41Sopenharmony_ci  // available after compile when lazily allocating feedback vectors.
2121cb0ef41Sopenharmony_ci  inline FeedbackVector feedback_vector() const;
2131cb0ef41Sopenharmony_ci  inline bool has_feedback_vector() const;
2141cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static void EnsureFeedbackVector(
2151cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> function,
2161cb0ef41Sopenharmony_ci      IsCompiledScope* compiled_scope);
2171cb0ef41Sopenharmony_ci  static void CreateAndAttachFeedbackVector(Isolate* isolate,
2181cb0ef41Sopenharmony_ci                                            Handle<JSFunction> function,
2191cb0ef41Sopenharmony_ci                                            IsCompiledScope* compiled_scope);
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ci  // Functions related to closure feedback cell array that holds feedback cells
2221cb0ef41Sopenharmony_ci  // used to create closures from this function. We allocate closure feedback
2231cb0ef41Sopenharmony_ci  // cell arrays after compile, when we want to allocate feedback vectors
2241cb0ef41Sopenharmony_ci  // lazily.
2251cb0ef41Sopenharmony_ci  inline bool has_closure_feedback_cell_array() const;
2261cb0ef41Sopenharmony_ci  inline ClosureFeedbackCellArray closure_feedback_cell_array() const;
2271cb0ef41Sopenharmony_ci  static void EnsureClosureFeedbackCellArray(
2281cb0ef41Sopenharmony_ci      Handle<JSFunction> function, bool reset_budget_for_feedback_allocation);
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_ci  // Initializes the feedback cell of |function|. In lite mode, this would be
2311cb0ef41Sopenharmony_ci  // initialized to the closure feedback cell array that holds the feedback
2321cb0ef41Sopenharmony_ci  // cells for create closure calls from this function. In the regular mode,
2331cb0ef41Sopenharmony_ci  // this allocates feedback vector.
2341cb0ef41Sopenharmony_ci  static void InitializeFeedbackCell(Handle<JSFunction> function,
2351cb0ef41Sopenharmony_ci                                     IsCompiledScope* compiled_scope,
2361cb0ef41Sopenharmony_ci                                     bool reset_budget_for_feedback_allocation);
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci  // Unconditionally clear the type feedback vector.
2391cb0ef41Sopenharmony_ci  void ClearTypeFeedbackInfo();
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci  // Resets function to clear compiled data after bytecode has been flushed.
2421cb0ef41Sopenharmony_ci  inline bool NeedsResetDueToFlushedBytecode();
2431cb0ef41Sopenharmony_ci  inline void ResetIfCodeFlushed(
2441cb0ef41Sopenharmony_ci      base::Optional<std::function<void(HeapObject object, ObjectSlot slot,
2451cb0ef41Sopenharmony_ci                                        HeapObject target)>>
2461cb0ef41Sopenharmony_ci          gc_notify_updated_slot = base::nullopt);
2471cb0ef41Sopenharmony_ci
2481cb0ef41Sopenharmony_ci  // Returns if the closure's code field has to be updated because it has
2491cb0ef41Sopenharmony_ci  // stale baseline code.
2501cb0ef41Sopenharmony_ci  inline bool NeedsResetDueToFlushedBaselineCode();
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci  // Returns if baseline code is a candidate for flushing. This method is called
2531cb0ef41Sopenharmony_ci  // from concurrent marking so we should be careful when accessing data fields.
2541cb0ef41Sopenharmony_ci  inline bool ShouldFlushBaselineCode(
2551cb0ef41Sopenharmony_ci      base::EnumSet<CodeFlushMode> code_flush_mode);
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci  DECL_GETTER(has_prototype_slot, bool)
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  // The initial map for an object created by this constructor.
2601cb0ef41Sopenharmony_ci  DECL_GETTER(initial_map, Map)
2611cb0ef41Sopenharmony_ci
2621cb0ef41Sopenharmony_ci  static void SetInitialMap(Isolate* isolate, Handle<JSFunction> function,
2631cb0ef41Sopenharmony_ci                            Handle<Map> map, Handle<HeapObject> prototype);
2641cb0ef41Sopenharmony_ci  static void SetInitialMap(Isolate* isolate, Handle<JSFunction> function,
2651cb0ef41Sopenharmony_ci                            Handle<Map> map, Handle<HeapObject> prototype,
2661cb0ef41Sopenharmony_ci                            Handle<JSFunction> constructor);
2671cb0ef41Sopenharmony_ci  DECL_GETTER(has_initial_map, bool)
2681cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static void EnsureHasInitialMap(
2691cb0ef41Sopenharmony_ci      Handle<JSFunction> function);
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_ci  // Creates a map that matches the constructor's initial map, but with
2721cb0ef41Sopenharmony_ci  // [[prototype]] being new.target.prototype. Because new.target can be a
2731cb0ef41Sopenharmony_ci  // JSProxy, this can call back into JavaScript.
2741cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle<Map> GetDerivedMap(
2751cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> constructor,
2761cb0ef41Sopenharmony_ci      Handle<JSReceiver> new_target);
2771cb0ef41Sopenharmony_ci
2781cb0ef41Sopenharmony_ci  // Like GetDerivedMap, but returns a map with a RAB / GSAB ElementsKind.
2791cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT Handle<Map> GetDerivedRabGsabMap(
2801cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> constructor,
2811cb0ef41Sopenharmony_ci      Handle<JSReceiver> new_target);
2821cb0ef41Sopenharmony_ci
2831cb0ef41Sopenharmony_ci  // Get and set the prototype property on a JSFunction. If the
2841cb0ef41Sopenharmony_ci  // function has an initial map the prototype is set on the initial
2851cb0ef41Sopenharmony_ci  // map. Otherwise, the prototype is put in the initial map field
2861cb0ef41Sopenharmony_ci  // until an initial map is needed.
2871cb0ef41Sopenharmony_ci  DECL_GETTER(has_prototype, bool)
2881cb0ef41Sopenharmony_ci  DECL_GETTER(has_instance_prototype, bool)
2891cb0ef41Sopenharmony_ci  DECL_GETTER(prototype, Object)
2901cb0ef41Sopenharmony_ci  DECL_GETTER(instance_prototype, HeapObject)
2911cb0ef41Sopenharmony_ci  DECL_GETTER(has_prototype_property, bool)
2921cb0ef41Sopenharmony_ci  DECL_GETTER(PrototypeRequiresRuntimeLookup, bool)
2931cb0ef41Sopenharmony_ci  static void SetPrototype(Handle<JSFunction> function, Handle<Object> value);
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ci  // Returns if this function has been compiled to native code yet.
2961cb0ef41Sopenharmony_ci  inline bool is_compiled() const;
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ci  static int GetHeaderSize(bool function_has_prototype_slot) {
2991cb0ef41Sopenharmony_ci    return function_has_prototype_slot ? JSFunction::kSizeWithPrototype
3001cb0ef41Sopenharmony_ci                                       : JSFunction::kSizeWithoutPrototype;
3011cb0ef41Sopenharmony_ci  }
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ci  std::unique_ptr<char[]> DebugNameCStr();
3041cb0ef41Sopenharmony_ci  void PrintName(FILE* out = stdout);
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci  // Calculate the instance size and in-object properties count.
3071cb0ef41Sopenharmony_ci  // {CalculateExpectedNofProperties} can trigger compilation.
3081cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT int CalculateExpectedNofProperties(
3091cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> function);
3101cb0ef41Sopenharmony_ci  static void CalculateInstanceSizeHelper(InstanceType instance_type,
3111cb0ef41Sopenharmony_ci                                          bool has_prototype_slot,
3121cb0ef41Sopenharmony_ci                                          int requested_embedder_fields,
3131cb0ef41Sopenharmony_ci                                          int requested_in_object_properties,
3141cb0ef41Sopenharmony_ci                                          int* instance_size,
3151cb0ef41Sopenharmony_ci                                          int* in_object_properties);
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ci  // Dispatched behavior.
3181cb0ef41Sopenharmony_ci  DECL_PRINTER(JSFunction)
3191cb0ef41Sopenharmony_ci  DECL_VERIFIER(JSFunction)
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci  static Handle<String> GetName(Handle<JSFunction> function);
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ci  // ES6 section 9.2.11 SetFunctionName
3241cb0ef41Sopenharmony_ci  // Because of the way this abstract operation is used in the spec,
3251cb0ef41Sopenharmony_ci  // it should never fail, but in practice it will fail if the generated
3261cb0ef41Sopenharmony_ci  // function name's length exceeds String::kMaxLength.
3271cb0ef41Sopenharmony_ci  static V8_WARN_UNUSED_RESULT bool SetName(Handle<JSFunction> function,
3281cb0ef41Sopenharmony_ci                                            Handle<Name> name,
3291cb0ef41Sopenharmony_ci                                            Handle<String> prefix);
3301cb0ef41Sopenharmony_ci
3311cb0ef41Sopenharmony_ci  // The function's name if it is configured, otherwise shared function info
3321cb0ef41Sopenharmony_ci  // debug name.
3331cb0ef41Sopenharmony_ci  static Handle<String> GetDebugName(Handle<JSFunction> function);
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_ci  // The function's string representation implemented according to
3361cb0ef41Sopenharmony_ci  // ES6 section 19.2.3.5 Function.prototype.toString ( ).
3371cb0ef41Sopenharmony_ci  static Handle<String> ToString(Handle<JSFunction> function);
3381cb0ef41Sopenharmony_ci
3391cb0ef41Sopenharmony_ci  class BodyDescriptor;
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_ci private:
3421cb0ef41Sopenharmony_ci  // JSFunction doesn't have a fixed header size:
3431cb0ef41Sopenharmony_ci  // Hide TorqueGeneratedClass::kHeaderSize to avoid confusion.
3441cb0ef41Sopenharmony_ci  static const int kHeaderSize;
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_ci  // Hide generated accessors; custom accessors are called "shared".
3471cb0ef41Sopenharmony_ci  DECL_ACCESSORS(shared_function_info, SharedFunctionInfo)
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ci  // Hide generated accessors; custom accessors are called "raw_feedback_cell".
3501cb0ef41Sopenharmony_ci  DECL_ACCESSORS(feedback_cell, FeedbackCell)
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ci  // Returns the set of code kinds of compilation artifacts (bytecode,
3531cb0ef41Sopenharmony_ci  // generated code) attached to this JSFunction.
3541cb0ef41Sopenharmony_ci  // Note that attached code objects that are marked_for_deoptimization are not
3551cb0ef41Sopenharmony_ci  // included in this set.
3561cb0ef41Sopenharmony_ci  // TODO(jgruber): Currently at most one code kind can be attached. Consider
3571cb0ef41Sopenharmony_ci  // adding a NOT_COMPILED kind and changing this function to simply return the
3581cb0ef41Sopenharmony_ci  // kind if this becomes more convenient in the future.
3591cb0ef41Sopenharmony_ci  CodeKinds GetAttachedCodeKinds() const;
3601cb0ef41Sopenharmony_ci
3611cb0ef41Sopenharmony_ci  // As above, but also considers locations outside of this JSFunction. For
3621cb0ef41Sopenharmony_ci  // example the optimized code cache slot in the feedback vector, and the
3631cb0ef41Sopenharmony_ci  // shared function info.
3641cb0ef41Sopenharmony_ci  CodeKinds GetAvailableCodeKinds() const;
3651cb0ef41Sopenharmony_ci
3661cb0ef41Sopenharmony_ci public:
3671cb0ef41Sopenharmony_ci  static constexpr int kSizeWithoutPrototype = kPrototypeOrInitialMapOffset;
3681cb0ef41Sopenharmony_ci  static constexpr int kSizeWithPrototype = TorqueGeneratedClass::kHeaderSize;
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSFunction)
3711cb0ef41Sopenharmony_ci};
3721cb0ef41Sopenharmony_ci
3731cb0ef41Sopenharmony_ci}  // namespace internal
3741cb0ef41Sopenharmony_ci}  // namespace v8
3751cb0ef41Sopenharmony_ci
3761cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_JS_FUNCTION_H_
379