Coverage Report

Created: 2025-07-04 09:33

/src/node/deps/v8/include/v8-function.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2021 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 INCLUDE_V8_FUNCTION_H_
6
#define INCLUDE_V8_FUNCTION_H_
7
8
#include <stddef.h>
9
#include <stdint.h>
10
11
#include "v8-function-callback.h"  // NOLINT(build/include_directory)
12
#include "v8-local-handle.h"       // NOLINT(build/include_directory)
13
#include "v8-message.h"            // NOLINT(build/include_directory)
14
#include "v8-object.h"             // NOLINT(build/include_directory)
15
#include "v8-template.h"           // NOLINT(build/include_directory)
16
#include "v8config.h"              // NOLINT(build/include_directory)
17
18
namespace v8 {
19
20
class Context;
21
class UnboundScript;
22
23
/**
24
 * A JavaScript function object (ECMA-262, 15.3).
25
 */
26
class V8_EXPORT Function : public Object {
27
 public:
28
  /**
29
   * Create a function in the current execution context
30
   * for a given FunctionCallback.
31
   */
32
  static MaybeLocal<Function> New(
33
      Local<Context> context, FunctionCallback callback,
34
      Local<Value> data = Local<Value>(), int length = 0,
35
      ConstructorBehavior behavior = ConstructorBehavior::kAllow,
36
      SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
37
38
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
39
      Local<Context> context, int argc, Local<Value> argv[]) const;
40
41
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
42
135k
      Local<Context> context) const {
43
135k
    return NewInstance(context, 0, nullptr);
44
135k
  }
45
46
  /**
47
   * When side effect checks are enabled, passing kHasNoSideEffect allows the
48
   * constructor to be invoked without throwing. Calls made within the
49
   * constructor are still checked.
50
   */
51
  V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
52
      Local<Context> context, int argc, Local<Value> argv[],
53
      SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
54
55
  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
56
                                               Local<Value> recv, int argc,
57
                                               Local<Value> argv[]);
58
59
  void SetName(Local<String> name);
60
  Local<Value> GetName() const;
61
62
  V8_DEPRECATED("No direct replacement")
63
  MaybeLocal<UnboundScript> GetUnboundScript() const;
64
65
  /**
66
   * Name inferred from variable or property assignment of this function.
67
   * Used to facilitate debugging and profiling of JavaScript code written
68
   * in an OO style, where many functions are anonymous but are assigned
69
   * to object properties.
70
   */
71
  Local<Value> GetInferredName() const;
72
73
  /**
74
   * displayName if it is set, otherwise name if it is configured, otherwise
75
   * function name, otherwise inferred name.
76
   */
77
  Local<Value> GetDebugName() const;
78
79
  /**
80
   * Returns zero based line number of function body and
81
   * kLineOffsetNotFound if no information available.
82
   */
83
  int GetScriptLineNumber() const;
84
  /**
85
   * Returns zero based column number of function body and
86
   * kLineOffsetNotFound if no information available.
87
   */
88
  int GetScriptColumnNumber() const;
89
90
  /**
91
   * Returns zero based start position (character offset) of function body and
92
   * kLineOffsetNotFound if no information available.
93
   */
94
  int GetScriptStartPosition() const;
95
96
  /**
97
   * Returns scriptId.
98
   */
99
  int ScriptId() const;
100
101
  /**
102
   * Returns the original function if this function is bound, else returns
103
   * v8::Undefined.
104
   */
105
  Local<Value> GetBoundFunction() const;
106
107
  /**
108
   * Calls builtin Function.prototype.toString on this function.
109
   * This is different from Value::ToString() that may call a user-defined
110
   * toString() function, and different than Object::ObjectProtoToString() which
111
   * always serializes "[object Function]".
112
   */
113
  V8_WARN_UNUSED_RESULT MaybeLocal<String> FunctionProtoToString(
114
      Local<Context> context);
115
116
  /**
117
   * Returns true if the function does nothing.
118
   * The function returns false on error.
119
   * Note that this function is experimental. Embedders should not rely on
120
   * this existing. We may remove this function in the future.
121
   */
122
  V8_WARN_UNUSED_RESULT bool Experimental_IsNopFunction() const;
123
124
  ScriptOrigin GetScriptOrigin() const;
125
0
  V8_INLINE static Function* Cast(Value* value) {
126
#ifdef V8_ENABLE_CHECKS
127
    CheckCast(value);
128
#endif
129
0
    return static_cast<Function*>(value);
130
0
  }
131
132
  static const int kLineOffsetNotFound;
133
134
 private:
135
  Function();
136
  static void CheckCast(Value* obj);
137
};
138
}  // namespace v8
139
140
#endif  // INCLUDE_V8_FUNCTION_H_