/src/node/deps/v8/include/v8-function.h
Line  | Count  | Source  | 
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 Location;  | 
22  |  | class UnboundScript;  | 
23  |  |  | 
24  |  | /**  | 
25  |  |  * A JavaScript function object (ECMA-262, 15.3).  | 
26  |  |  */  | 
27  |  | class V8_EXPORT Function : public Object { | 
28  |  |  public:  | 
29  |  |   /**  | 
30  |  |    * Create a function in the current execution context  | 
31  |  |    * for a given FunctionCallback.  | 
32  |  |    */  | 
33  |  |   static MaybeLocal<Function> New(  | 
34  |  |       Local<Context> context, FunctionCallback callback,  | 
35  |  |       Local<Value> data = Local<Value>(), int length = 0,  | 
36  |  |       ConstructorBehavior behavior = ConstructorBehavior::kAllow,  | 
37  |  |       SideEffectType side_effect_type = SideEffectType::kHasSideEffect);  | 
38  |  |  | 
39  |  |   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(  | 
40  |  |       Local<Context> context, int argc, Local<Value> argv[]) const;  | 
41  |  |  | 
42  |  |   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(  | 
43  | 35  |       Local<Context> context) const { | 
44  | 35  |     return NewInstance(context, 0, nullptr);  | 
45  | 35  |   }  | 
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  |  |    */  | 
52  |  |   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(  | 
53  |  |       Local<Context> context, int argc, Local<Value> argv[],  | 
54  |  |       SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;  | 
55  |  |  | 
56  |  |   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(v8::Isolate* isolate,  | 
57  |  |                                                Local<Context> context,  | 
58  |  |                                                Local<Value> recv, int argc,  | 
59  |  |                                                Local<Value> argv[]);  | 
60  |  |   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,  | 
61  |  |                                                Local<Value> recv, int argc,  | 
62  |  |                                                Local<Value> argv[]);  | 
63  |  |  | 
64  |  |   void SetName(Local<String> name);  | 
65  |  |   Local<Value> GetName() const;  | 
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  |  |    */  | 
73  |  |   Local<Value> GetInferredName() const;  | 
74  |  |  | 
75  |  |   /**  | 
76  |  |    * displayName if it is set, otherwise name if it is configured, otherwise  | 
77  |  |    * function name, otherwise inferred name.  | 
78  |  |    */  | 
79  |  |   Local<Value> GetDebugName() const;  | 
80  |  |  | 
81  |  |   /**  | 
82  |  |    * Returns zero based line number of function body and  | 
83  |  |    * kLineOffsetNotFound if no information available.  | 
84  |  |    */  | 
85  |  |   int GetScriptLineNumber() const;  | 
86  |  |   /**  | 
87  |  |    * Returns zero based column number of function body and  | 
88  |  |    * kLineOffsetNotFound if no information available.  | 
89  |  |    */  | 
90  |  |   int GetScriptColumnNumber() const;  | 
91  |  |  | 
92  |  |   /**  | 
93  |  |    * Returns zero based line and column number of function body, else returns  | 
94  |  |    * {-1, -1}. | 
95  |  |    */  | 
96  |  |   Location GetScriptLocation() const;  | 
97  |  |  | 
98  |  |   /**  | 
99  |  |    * Returns zero based start position (character offset) of function body and  | 
100  |  |    * kLineOffsetNotFound if no information available.  | 
101  |  |    */  | 
102  |  |   int GetScriptStartPosition() const;  | 
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  |  |    */  | 
113  |  |   Local<Value> GetBoundFunction() const;  | 
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  |  |    */  | 
121  |  |   V8_WARN_UNUSED_RESULT MaybeLocal<String> FunctionProtoToString(  | 
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  |  |    */  | 
130  |  |   V8_WARN_UNUSED_RESULT bool Experimental_IsNopFunction() const;  | 
131  |  |  | 
132  |  |   ScriptOrigin GetScriptOrigin() const;  | 
133  | 0  |   V8_INLINE static Function* Cast(Value* value) { | 
134  |  | #ifdef V8_ENABLE_CHECKS  | 
135  |  |     CheckCast(value);  | 
136  |  | #endif  | 
137  | 0  |     return static_cast<Function*>(value);  | 
138  | 0  |   }  | 
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_  |