Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:05:24

0001 // Copyright 2021 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
0004 
0005 #ifndef INCLUDE_V8_FUNCTION_H_
0006 #define INCLUDE_V8_FUNCTION_H_
0007 
0008 #include <stddef.h>
0009 #include <stdint.h>
0010 
0011 #include "v8-function-callback.h"  // NOLINT(build/include_directory)
0012 #include "v8-local-handle.h"       // NOLINT(build/include_directory)
0013 #include "v8-message.h"            // NOLINT(build/include_directory)
0014 #include "v8-object.h"             // NOLINT(build/include_directory)
0015 #include "v8-template.h"           // NOLINT(build/include_directory)
0016 #include "v8config.h"              // NOLINT(build/include_directory)
0017 
0018 namespace v8 {
0019 
0020 class Context;
0021 class UnboundScript;
0022 
0023 /**
0024  * A JavaScript function object (ECMA-262, 15.3).
0025  */
0026 class V8_EXPORT Function : public Object {
0027  public:
0028   /**
0029    * Create a function in the current execution context
0030    * for a given FunctionCallback.
0031    */
0032   static MaybeLocal<Function> New(
0033       Local<Context> context, FunctionCallback callback,
0034       Local<Value> data = Local<Value>(), int length = 0,
0035       ConstructorBehavior behavior = ConstructorBehavior::kAllow,
0036       SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
0037 
0038   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
0039       Local<Context> context, int argc, Local<Value> argv[]) const;
0040 
0041   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(
0042       Local<Context> context) const {
0043     return NewInstance(context, 0, nullptr);
0044   }
0045 
0046   /**
0047    * When side effect checks are enabled, passing kHasNoSideEffect allows the
0048    * constructor to be invoked without throwing. Calls made within the
0049    * constructor are still checked.
0050    */
0051   V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstanceWithSideEffectType(
0052       Local<Context> context, int argc, Local<Value> argv[],
0053       SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const;
0054 
0055   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
0056                                                Local<Value> recv, int argc,
0057                                                Local<Value> argv[]);
0058 
0059   void SetName(Local<String> name);
0060   Local<Value> GetName() const;
0061 
0062   V8_DEPRECATED("No direct replacement")
0063   MaybeLocal<UnboundScript> GetUnboundScript() const;
0064 
0065   /**
0066    * Name inferred from variable or property assignment of this function.
0067    * Used to facilitate debugging and profiling of JavaScript code written
0068    * in an OO style, where many functions are anonymous but are assigned
0069    * to object properties.
0070    */
0071   Local<Value> GetInferredName() const;
0072 
0073   /**
0074    * displayName if it is set, otherwise name if it is configured, otherwise
0075    * function name, otherwise inferred name.
0076    */
0077   Local<Value> GetDebugName() const;
0078 
0079   /**
0080    * Returns zero based line number of function body and
0081    * kLineOffsetNotFound if no information available.
0082    */
0083   int GetScriptLineNumber() const;
0084   /**
0085    * Returns zero based column number of function body and
0086    * kLineOffsetNotFound if no information available.
0087    */
0088   int GetScriptColumnNumber() const;
0089 
0090   /**
0091    * Returns zero based start position (character offset) of function body and
0092    * kLineOffsetNotFound if no information available.
0093    */
0094   int GetScriptStartPosition() const;
0095 
0096   /**
0097    * Returns scriptId.
0098    */
0099   int ScriptId() const;
0100 
0101   /**
0102    * Returns the original function if this function is bound, else returns
0103    * v8::Undefined.
0104    */
0105   Local<Value> GetBoundFunction() const;
0106 
0107   /**
0108    * Calls builtin Function.prototype.toString on this function.
0109    * This is different from Value::ToString() that may call a user-defined
0110    * toString() function, and different than Object::ObjectProtoToString() which
0111    * always serializes "[object Function]".
0112    */
0113   V8_WARN_UNUSED_RESULT MaybeLocal<String> FunctionProtoToString(
0114       Local<Context> context);
0115 
0116   /**
0117    * Returns true if the function does nothing.
0118    * The function returns false on error.
0119    * Note that this function is experimental. Embedders should not rely on
0120    * this existing. We may remove this function in the future.
0121    */
0122   V8_WARN_UNUSED_RESULT bool Experimental_IsNopFunction() const;
0123 
0124   ScriptOrigin GetScriptOrigin() const;
0125   V8_INLINE static Function* Cast(Value* value) {
0126 #ifdef V8_ENABLE_CHECKS
0127     CheckCast(value);
0128 #endif
0129     return static_cast<Function*>(value);
0130   }
0131 
0132   static const int kLineOffsetNotFound;
0133 
0134  private:
0135   Function();
0136   static void CheckCast(Value* obj);
0137 };
0138 }  // namespace v8
0139 
0140 #endif  // INCLUDE_V8_FUNCTION_H_