# class JsObject | Javascript Object. More...
Full name | `TelEngine::JsObject`
Definition | `#include <libs/yscript/yatescript.h>`
Inherits | TelEngine::ScriptContext [public ]
Inherited by | JsArray, JsFunction, JsRegExp
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- JsObject (const char* name = "Object", Mutex* mtx = 0, bool frozen = false)
- JsObject (Mutex* mtx, const char* name, bool frozen = false)
- virtual ~JsObject ()
- virtual Mutex* mutex ()
- virtual JsObject* clone (const char* name) const
- inline JsObject* clone () const
- virtual JsObject* copy (Mutex* mtx) const
- virtual void fillFieldNames (ObjList& names)
- 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)
- inline bool frozen () const
- inline void freeze ()
- inline int extractArgs (ObjList& stack, const ExpOperation& oper, GenObject* context, ObjList& arguments)

#### Public Static Methods

- 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 JsObject* buildCallContext (Mutex* mtx, JsObject* thisObj = 0)
- static void initialize (ScriptContext* context)
- static inline const String& protoName ()
- static void deepCopyParams (NamedList& dst, const NamedList& src, Mutex* mtx)
- static void dumpRecursive (const GenObject* obj, String& buf)
- static void printRecursive (const GenObject* obj)

#### Protected Methods

- virtual bool runNative (ObjList& stack, const ExpOperation& oper, GenObject* context)
- inline Mutex* mutex () const

## Detailed Description

Javascript Object class, base for all JS objects

JsObject (const char* name = "Object", Mutex* mtx = 0, bool frozen = false) | ### JsObject

Constructor

Parameters:

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

JsObject (Mutex* mtx, const char* name, bool frozen = false) | ### JsObject

Constructor for an empty object

Parameters:

mtx | Pointer to the mutex that serializes this object
name | Full name of the object
frozen | True if the object is to be frozen from creation

~JsObject () | ### ~JsObject

[virtual]

Destructor

Mutex* mutex () | ### mutex

[virtual]

Retrieve the Mutex object used to serialize object access

Returns: Pointer to the mutex of the context this object belongs to

Reimplemented from ScriptContext.

JsObject* clone (const char* name) | ### clone

[const virtual]

Clone and rename method

Parameters:

name | Name of the cloned object

Returns: New object instance

inline JsObject* clone () | ### clone

[const]

Clone method

Returns: New object instance

JsObject* copy (Mutex* mtx) | ### copy

[const virtual]

Deep copy method

Parameters:

mtx | Pointer to the mutex that serializes the copied object

Returns: New object instance, does not keep references to old object

void fillFieldNames (ObjList& names) | ### fillFieldNames

[virtual]

Fill a list with the unique names of all fields

Parameters:

names | List to which key names must be added

Reimplemented from ScriptContext.

bool hasField (ObjList& stack, const String& name, GenObject* context) | ### hasField

[const virtual]

Check if a certain field is assigned in the object or its prototype

Parameters:

stack | Evaluation stack in use
name | Name of the field to test
context | Pointer to arbitrary object passed from evaluation methods

Returns: True if the field is present

Reimplemented from ScriptContext.

NamedString* getField (ObjList& stack, const String& name, GenObject* context) | ### getField

[const virtual]

Get a pointer to a field in the object or its prototype

Parameters:

stack | Evaluation stack in use
name | Name of the field to retrieve
context | Pointer to arbitrary object passed from evaluation methods

Returns: Pointer to field, NULL if not present

Reimplemented from ScriptContext.

void initConstructor (JsFunction* construct) | ### initConstructor

[virtual]

Native constructor initialization, called by addConstructor on the prototype

Parameters:

construct | Function that has this object as prototype

JsObject* runConstructor (ObjList& stack, const ExpOperation& oper, GenObject* context) | ### runConstructor

[virtual]

Native object constructor, it's run on the prototype

Parameters:

stack | Evaluation stack in use
oper | Constructor function to evaluate
context | Pointer to arbitrary object passed from evaluation methods

Returns: New created and populated Javascript object

bool runFunction (ObjList& stack, const ExpOperation& oper, GenObject* context) | ### runFunction

[virtual]

Try to evaluate a single method

Parameters:

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

Returns: True if evaluation succeeded

Reimplemented from ScriptContext.

bool runField (ObjList& stack, const ExpOperation& oper, GenObject* context) | ### runField

[virtual]

Try to evaluate a single field

Parameters:

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

Returns: True if evaluation succeeded

Reimplemented from ScriptContext.

bool runAssign (ObjList& stack, const ExpOperation& oper, GenObject* context) | ### runAssign

[virtual]

Try to assign a value to a single field if object is not frozen

Parameters:

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

Returns: True if assignment succeeded

Reimplemented from ScriptContext.

ExpOperation* popValue (ObjList& stack, GenObject* context = 0) | ### popValue

[virtual]

Pops and evaluate the value of an operand off an evaluation stack, does not pop a barrier

Parameters:

stack | Evaluation stack to remove the operand from
context | Pointer to arbitrary object to be passed to called methods

Returns: Value removed from stack, NULL if stack underflow or field not evaluable

inline bool frozen () | ### frozen

[const]

Retrieve the object frozen status (cannot modify attributes or methods)

Returns: True if the object is frozen

inline void freeze () | ### freeze

Freeze the Javascript object preventing external changes to it

void addObject (NamedList& params, const char* name, JsObject* obj) | ### addObject

[static]

Helper static method that adds an object to a parent

Parameters:

params | List of parameters where to add the object
name | Name of the new parameter
obj | Pointer to the object to add

void addConstructor (NamedList& params, const char* name, JsObject* obj) | ### addConstructor

[static]

Helper static method that adds a constructor to a parent

Parameters:

params | List of parameters where to add the constructor
name | Name of the new parameter
obj | Pointer to the prototype object to add

int extractArgs (JsObject* obj, ObjList& stack, const ExpOperation& oper, GenObject* context, ObjList& arguments) | ### extractArgs

[static]

Helper static method that pops arguments off a stack to a list in proper order

Parameters:

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

Returns: Number of arguments popped off stack

inline int extractArgs (ObjList& stack, const ExpOperation& oper, GenObject* context, ObjList& arguments) | ### extractArgs

Helper method that pops arguments off a stack to a list in proper order

Parameters:

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

Returns: Number of arguments popped off stack

JsObject* buildCallContext (Mutex* mtx, JsObject* thisObj = 0) | ### buildCallContext

[static]

Create an empty function call context

Parameters:

mtx | Pointer to the mutex that serializes this object
thisObj | Optional object that will be set as "this"

Returns: New empty object usable as call context

void initialize (ScriptContext* context) | ### initialize

[static]

Initialize the standard global objects in a context

Parameters:

context | Script context to initialize

inline const String& protoName () | ### protoName

[static]

Get the name of the internal property used to track prototypes

Returns: The "__proto__" constant string

void deepCopyParams (NamedList& dst, const NamedList& src, Mutex* mtx) | ### deepCopyParams

[static]

Static helper method that deep copies all parameters

Parameters:

dst | Destination parameters
src | Source parameters
mtx | Mutex to be used to synchronize all new objects

void dumpRecursive (const GenObject* obj, String& buf) | ### dumpRecursive

[static]

Helper method to return the hierarchical structure of an object

Parameters:

obj | Object to dump structure
buf | String to which the structure is added

void printRecursive (const GenObject* obj) | ### printRecursive

[static]

Helper method to display the hierarchical structure of an object

Parameters:

obj | Object to display

bool runNative (ObjList& stack, const ExpOperation& oper, GenObject* context) | ### runNative

[protected virtual]

Try to evaluate a single native method

Parameters:

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

Returns: True if evaluation succeeded

inline Mutex* mutex () | ### mutex

[protected const]

Retrieve the Mutex object used to serialize object access

Returns: Pointer to the mutex of the context this object belongs to

Reimplemented from ScriptContext.

Generated by: paulc on bussard on Mon Feb 10 13:15:47 2014, using kdoc 2.0a54.