|
Yate
|
Javascript Object. More...
#include <yatescript.h>
Public Types | |
| enum | DumpFlags { DumpFunc = 0x01 , DumpProp = 0x02 , DumpRecursive = 0x10 , DumpType = 0x20 , DumpProto = 0x40 , DumpPropObjType = 0x80 , DumpFuncOnly = DumpRecursive | DumpProto | DumpFunc , DumpPropOnly = DumpRecursive | DumpPropObjType | DumpProp } |
Public Member Functions | |
| 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 ScriptMutex * | mutex () |
| virtual JsObject * | clone (const char *name, const ExpOperation &oper) const |
| JsObject * | clone (const ExpOperation &oper) const |
| void | setPrototype (GenObject *context, const String &objName) |
| virtual JsObject * | copy (ScriptMutex *mtx, const ExpOperation &oper) const |
| virtual void | fillFieldNames (ObjList &names) |
| virtual const HashList * | getHashListParams () const |
| virtual bool | hasField (ObjList &stack, const String &name, GenObject *context) const |
| virtual NamedString * | getField (ObjList &stack, const String &name, GenObject *context) const |
| virtual void | initConstructor (JsFunction *construct) |
| virtual JsObject * | runConstructor (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 ExpOperation * | popValue (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) | |
| NamedList & | params () |
| const NamedList & | params () const |
| virtual NamedList * | nativeParams () const |
| virtual const String & | toString () const |
| virtual void * | getObject (const String &name) const |
| virtual RefObject * | refObj () |
| 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 ObjList * | countAllocations () |
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 String & | traceId () const |
| NamedCounter * | getObjCounter () const |
| NamedCounter * | setObjCounter (NamedCounter *counter) |
Public Member Functions inherited from ExpExtender | |
| virtual | ~ExpExtender () |
Static Public Member Functions | |
| static void | addObject (NamedList ¶ms, const char *name, JsObject *obj) |
| static void | addConstructor (NamedList ¶ms, const char *name, JsObject *obj) |
| static int | extractArgs (JsObject *obj, ObjList &stack, const ExpOperation &oper, GenObject *context, ObjList &arguments) |
| static JsObject * | buildCallContext (ScriptMutex *mtx, JsObject *thisObj=0) |
| static void | initialize (ScriptContext *context) |
| static void | setLineForObj (JsObject *obj, unsigned int lineNo, bool recursive) |
| static const String & | protoName () |
| 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 ExpOperation * | toJSON (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 NamedCounter * | getObjCounter (const String &name, bool create=true) |
| static ObjList & | getObjCounters () |
Protected Member Functions | |
| virtual bool | runNative (ObjList &stack, const ExpOperation &oper, GenObject *context) |
| ScriptMutex * | mutex () const |
| void | setMutex (ScriptMutex *mtx) |
Protected Member Functions inherited from RefObject | |
| virtual void | zeroRefs () |
| bool | resurrect () |
| virtual void | destroyed () |
Static Protected Member Functions | |
| static void | toJSON (const NamedString *ns, String &buf, int spaces, int indent=0) |
| static String | strEscape (const char *str) |
Friends | |
| class | JsFunction |
Javascript Object.
Javascript Object class, base for all JS objects
| enum DumpFlags |
Dump object flags
| JsObject | ( | const char * | name = "Object", |
| ScriptMutex * | mtx = 0, | ||
| bool | frozen = false ) |
Constructor
| name | Name of the object |
| mtx | Pointer to the mutex that serializes this object |
| frozen | True if the object is to be frozen from creation |
References frozen().
Referenced by addConstructor(), addObject(), buildCallContext(), clone(), clone(), JsRegExp::clone(), JsFunction::copy(), JsFunction::copy(), copy(), JsRegExp::copy(), extractArgs(), getObjField(), runConstructor(), JsRegExp::runConstructor(), JsFunction::runDefined(), setLineForObj(), and setObjField().
| JsObject | ( | ScriptMutex * | mtx, |
| const char * | name, | ||
| unsigned int | line, | ||
| bool | frozen = 0 ) |
Constructor for an empty object
| mtx | Pointer to the mutex that serializes this object |
| name | Full name of the object |
| line | Code line where this object was created |
| frozen | True if the object is to be frozen from creation |
References frozen().
| JsObject | ( | GenObject * | context, |
| unsigned int | line, | ||
| ScriptMutex * | mtx = 0, | ||
| bool | frozen = false ) |
Constructor for an empty object with prototype
| context | Script context from which Object prototype is obtained |
| line | Code line where this object was created |
| mtx | Pointer to the mutex that serializes this object |
| frozen | True if the object is to be frozen from creation |
References frozen(), and GenObject::GenObject().
|
virtual |
Destructor
Helper static method that adds a constructor to a parent
| params | List of parameters where to add the constructor |
| name | Name of the new parameter |
| obj | Pointer to the prototype object to add |
References JsObject(), and ScriptContext::params().
Helper static method that adds an object to a parent
| params | List of parameters where to add the object |
| name | Name of the new parameter |
| obj | Pointer to the object to add |
References JsObject(), and ScriptContext::params().
|
static |
Create an empty function call context
| mtx | Pointer to the mutex that serializes this object |
| thisObj | Optional object that will be set as "this" |
References JsObject().
|
inlinevirtual |
Delete a field of the object
| name | Name of field to remove |
References ScriptContext::params().
|
inlinevirtual |
Clone and rename method
| name | Name of the cloned object |
| oper | ExpOperation that required the clone |
Reimplemented in JsArray, and JsRegExp.
References JsObject(), and ExpOperation::lineNumber().
Referenced by clone().
|
inline |
Clone method
| oper | ExpOperation that required the clone |
References clone(), JsObject(), and ScriptContext::toString().
|
virtual |
Deep copy method
| mtx | Pointer to the mutex that serializes the copied object |
| oper | Caller of copying operation |
Reimplemented in JsArray, JsFunction, and JsRegExp.
References JsObject().
|
static |
Static helper method that deep copies all parameters
| dst | Destination parameters |
| src | Source parameters |
| mtx | Mutex to be used to synchronize all new objects |
|
static |
Helper method to return the hierarchical structure of an object
| obj | Object to dump structure |
| buf | String to which the structure is added |
| flags | Flags indicating what to dump |
References GenObject::GenObject().
|
static |
Helper static method that pops arguments off a stack to a list in proper order
| obj | Pointer to the object to use when popping each argument |
| stack | Evaluation stack in use, parameters are popped off this stack |
| oper | Function that is being evaluated |
| context | Pointer to arbitrary object passed from evaluation methods |
| arguments | List where the arguments are added in proper order |
References GenObject::GenObject(), and JsObject().
Referenced by extractArgs().
|
inline |
Helper method that pops arguments off a stack to a list in proper order
| stack | Evaluation stack in use, parameters are popped off this stack |
| oper | Function that is being evaluated |
| context | Pointer to arbitrary object passed from evaluation methods |
| arguments | List where the arguments are added in proper order |
References extractArgs(), and GenObject::GenObject().
|
virtual |
Fill a list with the unique names of all fields
| names | List to which key names must be added |
Reimplemented from ScriptContext.
|
inline |
Freeze the Javascript object preventing external changes to it
|
inline |
Retrieve the object frozen status (cannot modify attributes or methods)
Referenced by JsArray::JsArray(), JsObject(), JsObject(), JsObject(), JsRegExp::JsRegExp(), and JsRegExp::JsRegExp().
| bool getBoolField | ( | const String & | name, |
| bool & | val ) |
Get the boolean value of the field with the given name
| name | Name of field to retrieve |
| val | Field where to put the retrieved value |
|
virtual |
Get a pointer to a field in the object or its prototype
| stack | Evaluation stack in use |
| name | Name of the field to retrieve |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented from ScriptContext.
References GenObject::GenObject().
|
virtual |
Retrieve enclosed hashed list paramsters
| bool getIntField | ( | const String & | name, |
| int64_t & | val ) |
Get the integer value of the field with the given name
| name | Name of field to retrieve |
| val | Field where to put the retrieved value |
Get the object associated with the field with the given name
| name | Name of field to retrieve |
| obj | Field where to put the retrieved value |
References JsObject().
Get the string value of the field with the given name
| name | Name of field to retrieve |
| val | Field where to put the retrieved value |
Check if a certain field is assigned in the object or its prototype
| stack | Evaluation stack in use |
| name | Name of the field to test |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented from ScriptContext.
References GenObject::GenObject().
|
inlinevirtual |
Native constructor initialization, called by addConstructor on the prototype
| construct | Function that has this object as prototype |
Reimplemented in JsArray, and JsFunction.
|
static |
Initialize the standard global objects in a context
| context | Script context to initialize |
References ScriptContext::ScriptContext().
|
inline |
Get the script line number at which this object was created;
|
inline |
Set the script line number at which this object was created
| line | Line number |
Referenced by setLineForObj().
|
inlinevirtual |
Retrieve the Mutex object used to serialize object access
Implements ScriptContext.
Referenced by JsArray::clone(), and JsRegExp::clone().
|
inlineprotected |
Retrieve the Mutex object used to serialize object access
|
virtual |
Pops and evaluate the value of an operand off an evaluation stack, does not pop a barrier
| stack | Evaluation stack to remove the operand from |
| context | Pointer to arbitrary object to be passed to called methods |
References GenObject::GenObject().
|
static |
Helper method to display the hierarchical structure of an object
| obj | Object to display |
| flags | Flags indicating what to dump (display) |
References GenObject::GenObject().
|
inlinestatic |
Get the name of the internal property used to track prototypes
|
virtual |
Try to assign a value to a single field if object is not frozen
| stack | Evaluation stack in use |
| oper | Field to assign to, contains the field name and new value |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented from ScriptContext.
Reimplemented in JsArray, and JsRegExp.
References GenObject::GenObject().
|
virtual |
Native object constructor, it's run on the prototype
| stack | Evaluation stack in use |
| oper | Constructor function to evaluate |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented in JsArray, and JsRegExp.
References GenObject::GenObject(), and JsObject().
|
virtual |
Try to evaluate a single field
| stack | Evaluation stack in use, field value must be pushed on it |
| oper | Field to evaluate |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented from ScriptContext.
Reimplemented in JsArray.
References GenObject::GenObject().
|
virtual |
Try to evaluate a single method
| stack | Evaluation stack in use, parameters are popped off this stack and results are pushed back on stack |
| oper | Function to evaluate |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented from ScriptContext.
References GenObject::GenObject().
|
protectedvirtual |
Try to evaluate a single native method
| stack | Evaluation stack in use, parameters are popped off this stack and results are pushed back on stack |
| oper | Function to evaluate |
| context | Pointer to arbitrary object passed from evaluation methods |
Reimplemented in JsArray, JsFunction, and JsRegExp.
References GenObject::GenObject().
|
inline |
Set a boolean field in this object
| name | Name of field to set |
| val | Boolean value to set |
References ScriptContext::params().
|
inline |
Set a integer field in this object
| name | Name of field to set |
| val | Integer value to set |
References ScriptContext::params().
|
static |
Set the creation line for this object and its properties
| obj | Object t set the line for |
| lineNo | The line number to set |
| recursive | True to set it to its sub-objects, false otherwise |
References JsObject(), and lineNo().
|
inlineprotected |
|
inline |
Set a object field in this object
| name | Name of field to set |
| obj | Object value to set |
References JsObject(), and ScriptContext::params().
Set the object prototype
| context | Pointer to arbitrary object passed from evaluation methods |
| objName | Name of the object prototype to set the this object |
References GenObject::GenObject().
|
inline |
Set a string field in this object
| name | Name of field to set |
| val | String value to set |
References ScriptContext::params().
|
staticprotected |
Static helper method for escaping special characters when JSON stringifying
| str | String to escape |
References GenObject::GenObject().
|
static |
Static method to obtain a JSON representation of the given object
| oper | Object to represent in JSON format |
| spaces | Number of spaces used for one indentation level |
|
inlinestaticprotected |
Static method to obtain a JSON representation of the given object
| ns | Object to represent in JSON format |
| buf | String used as output for the JSON represantion |
| spaces | Number of spaces used for one indentation level |
| indent | Current number of spaces used for indentation |