Class JSFunction

All Implemented Interfaces:
Serializable, Callable, ConstProperties, Constructable, DebuggableObject, Function, Scriptable, ScriptOrFn<JSFunction>, SymbolScriptable

public class JSFunction extends BaseFunction implements ScriptOrFn<JSFunction>
Represents a JavaScript function built upon a a JSDescriptor. All the immutable metadata associated with the function is stored on the descriptor, with only the lexically bound this, the home object required for super calls, and mutable properties held on the function object itself.
See Also:
  • Constructor Details

  • Method Details

    • getDeclarationScope

      public Scriptable getDeclarationScope()
      Description copied from interface: Function
      Return the scope in which this function was declared or closed over. This is the "[[Environment]]" defined in https://tc39.es/ecma262/#sec-ecmascript-function-objects. Although this is currently precisely equal to the parent scope (or "__parent__") of an object it is useful to distinguish the two concepts as parent scopes are no longer supported by the spec in general and present a significant barrier to future optimisations.
      Specified by:
      getDeclarationScope in interface Function
      Specified by:
      getDeclarationScope in interface ScriptOrFn<JSFunction>
    • getDescriptor

      public JSDescriptor<JSFunction> getDescriptor()
      Specified by:
      getDescriptor in interface ScriptOrFn<JSFunction>
    • isShorthand

      public boolean isShorthand()
    • isStrict

      public boolean isStrict()
    • getArity

      public int getArity()
      Overrides:
      getArity in class BaseFunction
    • getDebuggableView

      public DebuggableScript getDebuggableView()
    • getLanguageVersion

      protected int getLanguageVersion()
    • hasPrototypeProperty

      protected boolean hasPrototypeProperty()
      Overrides:
      hasPrototypeProperty in class BaseFunction
    • isGeneratorFunction

      protected boolean isGeneratorFunction()
      Overrides:
      isGeneratorFunction in class BaseFunction
    • getLength

      public int getLength()
      Overrides:
      getLength in class BaseFunction
    • getParamAndVarCount

      protected int getParamAndVarCount()
    • getParamCount

      protected int getParamCount()
    • getParamOrVarConst

      protected boolean getParamOrVarConst(int index)
    • getParamOrVarName

      protected String getParamOrVarName(int index)
    • getRawSource

      public String getRawSource()
    • createPrototypeProperty

      protected void createPrototypeProperty()
      Overrides:
      createPrototypeProperty in class BaseFunction
    • call

      public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
      Description copied from class: BaseFunction
      Should be overridden.
      Specified by:
      call in interface Callable
      Specified by:
      call in interface Function
      Overrides:
      call in class BaseFunction
      Parameters:
      cx - the current Context for this thread
      scope - the scope to execute the function relative to. This is set to the value returned by getParentScope() except when the function is called from a closure.
      thisObj - the JavaScript this object
      args - the array of arguments
      Returns:
      the result of the call
    • construct

      public Scriptable construct(Context cx, Scriptable scope, Object[] args)
      Description copied from interface: Function
      Call the function as a constructor.

      This method is invoked by the runtime in order to satisfy a use of the JavaScript new operator. This method is expected to create a new object and return it.

      Specified by:
      construct in interface Constructable
      Specified by:
      construct in interface Function
      Overrides:
      construct in class BaseFunction
      Parameters:
      cx - the current Context for this thread
      scope - an enclosing scope of the caller except when the function is called from a closure.
      args - the array of arguments
      Returns:
      the allocated object
    • isScript

      public boolean isScript()
    • hasDefaultParameters

      protected boolean hasDefaultParameters()
      Overrides:
      hasDefaultParameters in class BaseFunction
    • hasFunctionNamed

      public boolean hasFunctionNamed(String name)
    • getFunctionName

      public String getFunctionName()
      Overrides:
      getFunctionName in class BaseFunction
    • resumeGenerator

      public Object resumeGenerator(Context cx, Scriptable scope, int operation, Object state, Object value)
    • getHomeObject

      public Scriptable getHomeObject()
      Specified by:
      getHomeObject in interface ScriptOrFn<JSFunction>
      Overrides:
      getHomeObject in class BaseFunction
    • setHomeObject

      public void setHomeObject(Scriptable homeObject)
      Overrides:
      setHomeObject in class BaseFunction
    • getFunctionThis

      public Scriptable getFunctionThis(Scriptable functionThis)
    • createScript

      public static JSScript createScript(JSDescriptor<JSScript> desc, Scriptable homeObject, Object staticSecurityDomain)
      Create script from compiled bytecode.
    • createFunction

      public static JSFunction createFunction(Context cx, Scriptable scope, JSDescriptor<JSFunction> desc, Scriptable homeObject, Object staticSecurityDomain)
      Create function compiled from Function(...) constructor.