v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-function.h
Go to the documentation of this file.
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
18namespace v8 {
19
20class Context;
21class Location;
22class UnboundScript;
23
24/**
25 * A JavaScript function object (ECMA-262, 15.3).
26 */
27class V8_EXPORT Function : public Object {
28 public:
29 /**
30 * Create a function in the current execution context
31 * for a given FunctionCallback.
32 */
34 Local<Context> context, FunctionCallback callback,
35 Local<Value> data = Local<Value>(), int length = 0,
38
40 Local<Context> context, int argc, Local<Value> argv[]) const;
41
43 Local<Context> context) const {
44 return NewInstance(context, 0, nullptr);
45 }
46
47 /**
48 * When side effect checks are enabled, passing kHasNoSideEffect allows the
49 * constructor to be invoked without throwing. Calls made within the
50 * constructor are still checked.
51 */
53 Local<Context> context, int argc, Local<Value> argv[],
54 SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
55
57 Local<Context> context,
58 Local<Value> recv, int argc,
59 Local<Value> argv[]);
61 Local<Value> recv, int argc,
62 Local<Value> argv[]);
63
64 void SetName(Local<String> name);
66
67 /**
68 * Name inferred from variable or property assignment of this function.
69 * Used to facilitate debugging and profiling of JavaScript code written
70 * in an OO style, where many functions are anonymous but are assigned
71 * to object properties.
72 */
74
75 /**
76 * displayName if it is set, otherwise name if it is configured, otherwise
77 * function name, otherwise inferred name.
78 */
80
81 /**
82 * Returns zero based line number of function body and
83 * kLineOffsetNotFound if no information available.
84 */
86 /**
87 * Returns zero based column number of function body and
88 * kLineOffsetNotFound if no information available.
89 */
91
92 /**
93 * Returns zero based line and column number of function body, else returns
94 * {-1, -1}.
95 */
97
98 /**
99 * Returns zero based start position (character offset) of function body and
100 * kLineOffsetNotFound if no information available.
101 */
103
104 /**
105 * Returns scriptId.
106 */
107 int ScriptId() const;
108
109 /**
110 * Returns the original function if this function is bound, else returns
111 * v8::Undefined.
112 */
114
115 /**
116 * Calls builtin Function.prototype.toString on this function.
117 * This is different from Value::ToString() that may call a user-defined
118 * toString() function, and different than Object::ObjectProtoToString() which
119 * always serializes "[object Function]".
120 */
122 Local<Context> context);
123
124 /**
125 * Returns true if the function does nothing.
126 * The function returns false on error.
127 * Note that this function is experimental. Embedders should not rely on
128 * this existing. We may remove this function in the future.
129 */
131
133 V8_INLINE static Function* Cast(Value* value) {
134#ifdef V8_ENABLE_CHECKS
135 CheckCast(value);
136#endif
137 return static_cast<Function*>(value);
138 }
139
140 static const int kLineOffsetNotFound;
141
142 private:
143 Function();
144 static void CheckCast(Value* obj);
145};
146} // namespace v8
147
148#endif // INCLUDE_V8_FUNCTION_H_
int GetScriptStartPosition() const
Local< Value > GetDebugName() const
V8_WARN_UNUSED_RESULT bool Experimental_IsNopFunction() const
static MaybeLocal< Function > New(Local< Context > context, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
Local< Value > GetInferredName() const
Location GetScriptLocation() const
static V8_INLINE Function * Cast(Value *value)
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewInstance(Local< Context > context) const
Definition v8-function.h:42
V8_WARN_UNUSED_RESULT MaybeLocal< String > FunctionProtoToString(Local< Context > context)
static const int kLineOffsetNotFound
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewInstanceWithSideEffectType(Local< Context > context, int argc, Local< Value > argv[], SideEffectType side_effect_type=SideEffectType::kHasSideEffect) const
void SetName(Local< String > name)
Local< Value > GetName() const
ScriptOrigin GetScriptOrigin() const
int GetScriptColumnNumber() const
int ScriptId() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Call(v8::Isolate *isolate, Local< Context > context, Local< Value > recv, int argc, Local< Value > argv[])
Local< Value > GetBoundFunction() const
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewInstance(Local< Context > context, int argc, Local< Value > argv[]) const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Call(Local< Context > context, Local< Value > recv, int argc, Local< Value > argv[])
int GetScriptLineNumber() const
friend class Local
friend class MaybeLocal
SideEffectType
Definition v8-object.h:208
ConstructorBehavior
#define V8_EXPORT
Definition v8config.h:860
#define V8_INLINE
Definition v8config.h:513
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:684