Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:15:04

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