Yate
JsFunction Class Reference

Javascript Function. More...

#include <yatescript.h>

Inheritance diagram for JsFunction:
JsObject ScriptContext RefObject ExpExtender GenObject

Public Member Functions

 JsFunction (ScriptMutex *mtx=0)
 
 JsFunction (ScriptMutex *mtx, const char *name, unsigned int line, ObjList *args=0, long int lbl=0, ScriptCode *code=0)
 
virtual bool runDefined (ObjList &stack, const ExpOperation &oper, GenObject *context, JsObject *thisObj=0)
 
virtual void initConstructor (JsFunction *construct)
 
const ExpFunctiongetFunc () const
 
void firstName (const char *name)
 
const StringformalName (unsigned int index) const
 
long int label () const
 
JsObjectcopy (ScriptMutex *mtx, const ExpOperation &oper) const
 
virtual JsObjectcopy (ScriptMutex *mtx, const char *name, const ExpOperation &oper) const
 
virtual JsFunctioncloneFunction (const ExpOperation &oper, ScriptMutex *mtx=0)
 
- Public Member Functions inherited from JsObject
 JsObject (const char *name="Object", ScriptMutex *mtx=0, bool frozen=false)
 
 JsObject (ScriptMutex *mtx, const char *name, unsigned int line, bool frozen=0)
 
 JsObject (GenObject *context, unsigned int line, ScriptMutex *mtx=0, bool frozen=false)
 
virtual ~JsObject ()
 
virtual ScriptMutexmutex ()
 
virtual JsObjectclone (const char *name, const ExpOperation &oper) const
 
JsObjectclone (const ExpOperation &oper) const
 
void setPrototype (GenObject *context, const String &objName)
 
virtual void fillFieldNames (ObjList &names)
 
virtual const HashListgetHashListParams () const
 
virtual bool hasField (ObjList &stack, const String &name, GenObject *context) const
 
virtual NamedStringgetField (ObjList &stack, const String &name, GenObject *context) const
 
virtual JsObjectrunConstructor (ObjList &stack, const ExpOperation &oper, GenObject *context)
 
virtual bool runFunction (ObjList &stack, const ExpOperation &oper, GenObject *context)
 
virtual bool runField (ObjList &stack, const ExpOperation &oper, GenObject *context)
 
virtual bool runAssign (ObjList &stack, const ExpOperation &oper, GenObject *context)
 
virtual ExpOperationpopValue (ObjList &stack, GenObject *context=0)
 
virtual void clearField (const String &name)
 
bool setIntField (const char *name, int64_t val)
 
bool setBoolField (const char *name, bool val)
 
bool setStringField (const char *name, const char *val)
 
bool setObjField (const char *name, JsObject *obj)
 
bool getIntField (const String &name, int64_t &val)
 
bool getBoolField (const String &name, bool &val)
 
bool getStringField (const String &name, String &val)
 
bool getObjField (const String &name, JsObject *&obj)
 
bool frozen () const
 
void freeze ()
 
void lineNo (unsigned int line)
 
unsigned int lineNo () const
 
int extractArgs (ObjList &stack, const ExpOperation &oper, GenObject *context, ObjList &arguments)
 
- Public Member Functions inherited from ScriptContext
 ScriptContext (const char *name=0)
 
NamedListparams ()
 
const NamedListparams () const
 
virtual NamedListnativeParams () const
 
virtual const StringtoString () const
 
virtual void * getObject (const String &name) const
 
virtual RefObjectrefObj ()
 
virtual bool copyFields (ObjList &stack, const ScriptContext &original, GenObject *context)
 
virtual void addFields (const NamedList &list, const char *skipPrefix="__")
 
bool runMatchingField (ObjList &stack, const ExpOperation &oper, GenObject *context)
 
virtual void createdObj (GenObject *obj)
 
virtual void deletedObj (GenObject *obj)
 
virtual void trackObjs (unsigned int track=0)
 
virtual ObjListcountAllocations ()
 
- Public Member Functions inherited from RefObject
 RefObject ()
 
virtual ~RefObject ()
 
virtual bool alive () const
 
bool ref ()
 
bool deref ()
 
int refcount () const
 
virtual void destruct ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 
- Public Member Functions inherited from ExpExtender
virtual ~ExpExtender ()
 

Protected Member Functions

virtual bool runNative (ObjList &stack, const ExpOperation &oper, GenObject *context)
 
- Protected Member Functions inherited from JsObject
ScriptMutexmutex () const
 
void setMutex (ScriptMutex *mtx)
 
- Protected Member Functions inherited from RefObject
virtual void zeroRefs ()
 
bool resurrect ()
 
virtual void destroyed ()
 

Additional Inherited Members

- Public Types inherited from JsObject
enum  DumpFlags {
  DumpFunc = 0x01 , DumpProp = 0x02 , DumpRecursive = 0x10 , DumpType = 0x20 ,
  DumpProto = 0x40 , DumpPropObjType = 0x80 , DumpFuncOnly = DumpRecursive | DumpProto | DumpFunc , DumpPropOnly = DumpRecursive | DumpPropObjType | DumpProp
}
 
- Static Public Member Functions inherited from JsObject
static void addObject (NamedList &params, const char *name, JsObject *obj)
 
static void addConstructor (NamedList &params, const char *name, JsObject *obj)
 
static int extractArgs (JsObject *obj, ObjList &stack, const ExpOperation &oper, GenObject *context, ObjList &arguments)
 
static JsObjectbuildCallContext (ScriptMutex *mtx, JsObject *thisObj=0)
 
static void initialize (ScriptContext *context)
 
static void setLineForObj (JsObject *obj, unsigned int lineNo, bool recursive)
 
static const StringprotoName ()
 
static void deepCopyParams (NamedList &dst, const NamedList &src, ScriptMutex *mtx)
 
static void dumpRecursive (const GenObject *obj, String &buf, unsigned int flags=0xffffffff)
 
static void printRecursive (const GenObject *obj, unsigned int flags=0xffffffff)
 
static ExpOperationtoJSON (const ExpOperation *oper, int spaces)
 
- Static Public Member Functions inherited from ScriptContext
static void fillFieldNames (ObjList &names, const NamedList &list, bool checkDupl=true, const char *skip=0)
 
static void fillFieldNames (ObjList &names, const HashList &list)
 
- Static Public Member Functions inherited from RefObject
static bool alive (const RefObject *obj)
 
static bool efficientIncDec ()
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 
- Static Protected Member Functions inherited from JsObject
static void toJSON (const NamedString *ns, String &buf, int spaces, int indent=0)
 
static String strEscape (const char *str)
 

Detailed Description

Javascript Function.

Javascript Function class, implements user defined functions

Constructor & Destructor Documentation

◆ JsFunction() [1/2]

JsFunction ( ScriptMutex * mtx = 0)

Constructor

Parameters
mtxPointer to the mutex that serializes this object

Referenced by cloneFunction(), and initConstructor().

◆ JsFunction() [2/2]

JsFunction ( ScriptMutex * mtx,
const char * name,
unsigned int line,
ObjList * args = 0,
long int lbl = 0,
ScriptCode * code = 0 )

Constructor with function name

Parameters
mtxPointer to the mutex that serializes this object
nameName of the function
lineCode line where this object was created
argsOptional list of formal parameter names, will be emptied
lblNumber of the entry point label
codeThe script code to be used while running the function

Member Function Documentation

◆ cloneFunction()

virtual JsFunction * cloneFunction ( const ExpOperation & oper,
ScriptMutex * mtx = 0 )
virtual

Clone function

Parameters
operExpOperation that required the clone
mtxPointer to the mutex that serializes the cloning
Returns
A copy of JsFunction if not already cloned, a reference to itself is function is already a clone

References JsFunction().

◆ copy() [1/2]

virtual JsObject * copy ( ScriptMutex * mtx,
const char * name,
const ExpOperation & oper ) const
virtual

Deep copy method with given name

Parameters
mtxPointer to the mutex that serializes the copied array
nameName for the copied function
operExpOperation that required the copy
Returns
New object instance, does not keep references to old array

References JsObject::JsObject().

◆ copy() [2/2]

JsObject * copy ( ScriptMutex * mtx,
const ExpOperation & oper ) const
inlinevirtual

Deep copy method

Parameters
mtxPointer to the mutex that serializes the copied array
operExpOperation that required the copy
Returns
New object instance, does not keep references to old array

Reimplemented from JsObject.

References copy(), and JsObject::JsObject().

Referenced by copy().

◆ firstName()

void firstName ( const char * name)
inline

Set the name of this function if still empty

Parameters
nameName to set as first assigned name

◆ formalName()

const String * formalName ( unsigned int index) const
inline

Retrieve the name of the N-th formal argument

Parameters
indexIndex of the formal argument
Returns
Pointer to formal argument name, NULL if index too large

◆ getFunc()

const ExpFunction * getFunc ( ) const
inline

Retrieve the ExpFunction matching this Javascript function

Returns
Pointer to ExpFunction representation

◆ initConstructor()

virtual void initConstructor ( JsFunction * construct)
virtual

Function constructor initialization

Parameters
constructThe Function function

Reimplemented from JsObject.

References JsFunction().

◆ label()

long int label ( ) const
inline

Retrieve the entry label of the code for this function

Returns
Number of the entry point label, zero if no code defined

◆ runDefined()

virtual bool runDefined ( ObjList & stack,
const ExpOperation & oper,
GenObject * context,
JsObject * thisObj = 0 )
virtual

Try to evaluate a single user defined method

Parameters
stackEvaluation stack in use, parameters are popped off this stack and results are pushed back on stack
operFunction to evaluate
contextPointer to arbitrary object passed from evaluation methods
thisObjObject that should act as "this" for the function call
Returns
True if evaluation succeeded

References JsObject::JsObject().

◆ runNative()

virtual bool runNative ( ObjList & stack,
const ExpOperation & oper,
GenObject * context )
protectedvirtual

Try to evaluate a single native method

Parameters
stackEvaluation stack in use, parameters are popped off this stack and results are pushed back on stack
operFunction to evaluate
contextPointer to arbitrary object passed from evaluation methods
Returns
True if evaluation succeeded

Reimplemented from JsObject.


The documentation for this class was generated from the following file: