# class JsParser | Javascript parser. More...
Full name | `TelEngine::JsParser`
Definition | `#include <libs/yscript/yatescript.h>`
Inherits | TelEngine::ScriptParser [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- inline JsParser (bool allowLink = true, bool allowTrace = false)
- virtual bool parse (const char* text, bool fragment = false, const char* file = 0, int len = -1)
- virtual ScriptContext* createContext () const
- virtual ScriptRun* createRunner (ScriptCode* code, ScriptContext* context = 0, const char* title = 0) const
- inline ScriptRun* createRunner (ScriptContext* context = 0, const char* title = 0) const
- virtual bool callable (const String& name)
- void adjustPath (String& script) const
- inline const String& basePath () const
- inline void basePath (const char* path)
- inline const String& parsedFile () const
- bool scriptChanged (const char* file) const
- inline bool scriptChanged (const char* file, const String& path) const
- inline void link (bool allowed = true)
- inline void trace (bool allowed = true)

#### Public Static Methods

- static ScriptRun::Status eval (const String& text, ExpOperation** result = 0, ScriptContext* context = 0)
- static JsObject* parseJSON (const char* text)
- static ExpOperation* nullClone (const char* name = 0)
- static bool isNull (const ExpOperation& oper)
- static bool isUndefined (const ExpOperation& oper)

## Detailed Description

Javascript parser, takes source code and generates preparsed code

inline JsParser (bool allowLink = true, bool allowTrace = false) | ### JsParser

Constructor

Parameters:

allowLink | True to allow linking of the code, false otherwise.
allowTrace | True to allow the script to enable performance tracing

bool parse (const char* text, bool fragment = false, const char* file = 0, int len = -1) | ### parse

[virtual]

Parse a string as Javascript source code

Parameters:

text | Source code text
fragment | True if the code is just an included fragment
file | Name of the file that is being parsed
len | Length of text, negative if unknown

Returns: True if the text was successfully parsed

Reimplemented from ScriptParser.

ScriptContext* createContext () | ### createContext

[const virtual]

Create a context adequate for Javascript code

Returns: A new Javascript context

Reimplemented from ScriptParser.

ScriptRun* createRunner (ScriptCode* code, ScriptContext* context = 0, const char* title = 0) | ### createRunner

[const virtual]

Create a runner adequate for a block of parsed Javascript code

Parameters:

code | Parsed code block
context | Javascript context, an empty one will be allocated if NULL
title | An optional name for the runner

Returns: A new Javascript runner, NULL if code is NULL

Reimplemented from ScriptParser.

inline ScriptRun* createRunner (ScriptContext* context = 0, const char* title = 0) | ### createRunner

[const]

Create a runner adequate for the parsed Javascript code

Parameters:

context | Javascript context, an empty one will be allocated if NULL
title | An optional name for the runner

Returns: A new Javascript runner, NULL if code is not yet parsed

Reimplemented from ScriptParser.

bool callable (const String& name) | ### callable

[virtual]

Check if a script has a certain function or method

Parameters:

name | Name of the function to check

Returns: True if function exists in code

Reimplemented from ScriptParser.

void adjustPath (String& script) | ### adjustPath

[const]

Adjust a file script path to include default if needed

Parameters:

script | File path to adjust

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

[const]

Retrieve the base script path

Returns: Base path added to relative script paths

inline void basePath (const char* path) | ### basePath

Set the base script path

Parameters:

path | Base path to add to relative script paths

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

[const]

Retrieve the last parsed file name

Returns: Name of the successfully parsed file or an empty String

bool scriptChanged (const char* file) | ### scriptChanged

[const]

Check if the script or any includes have changed

Parameters:

file | Name of the file to check

Returns: True if the script may have changed, false if not changed

inline bool scriptChanged (const char* file, const String& path) | ### scriptChanged

[const]

Check if the script or any includes have changed

Parameters:

file | Name of the file to check
path | New base path to check

Returns: True if the script may have changed, false if not changed

inline void link (bool allowed = true) | ### link

Set whether the Javascript code should be linked or not

Parameters:

allowed | True to allow linking, false otherwise

inline void trace (bool allowed = true) | ### trace

Set whether the Javascript code can be traced or not

Parameters:

allowed | True to allow tracing, false otherwise

ScriptRun::Status eval (const String& text, ExpOperation** result = 0, ScriptContext* context = 0) | ### eval

[static]

Parse and run a piece of Javascript code

Parameters:

text | Source code fragment to execute
result | Pointer to an optional pointer to store returned value
context | Script context, an empty one will be allocated if NULL

Returns: Status of the runtime after code execution

JsObject* parseJSON (const char* text) | ### parseJSON

[static]

Parse a complete block of JSON text

Parameters:

text | JSON text to parse

Returns: JsObject holding the content of JSON, must be dereferenced after use, NULL if parse error

ExpOperation* nullClone (const char* name = 0) | ### nullClone

[static]

Get a "null" object wrapper that will identity match another "null"

Parameters:

name | Name of the new wrapper, "null" if empty

Returns: ExpWrapper for the "null" object

bool isNull (const ExpOperation& oper) | ### isNull

[static]

Check if an operation holds a null value

Returns: True if the operation holds a null object

bool isUndefined (const ExpOperation& oper) | ### isUndefined

[static]

Check if an operation holds an undefined value

Returns: True if the operation holds an undefined value

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