| # kjs Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# KJS::Interpreter Class Reference

Interpreter objects can be used to evaluate ECMAScript code. More...

`#include <interpreter.h>`

List of all members.

## Public Types
enum | CompatMode { NativeMode, IECompat, NetscapeCompat }
## Public Member Functions
| Interpreter (const Object &global)
| Creates a new interpreter.
| Interpreter ()
| Creates a new interpreter.
Object | globalObject () const
| Returns the object that is used as the global object during all script execution performed by this interpreter.
void | initGlobalObject ()
ExecState * | globalExec ()
| Returns the execution state object which can be used to execute scripts using this interpreter at a the "global" level, i.e.
bool | checkSyntax (const UString &code)
| Parses the supplied ECMAScript code and checks for syntax errors.
Completion | evaluate (const UString &code, const Value &thisV=Value())
| Evaluates the supplied ECMAScript code.
InterpreterImp * | imp ()
Object | builtinObject () const
| Returns the builtin "Object" object.
Object | builtinFunction () const
| Returns the builtin "Function" object.
Object | builtinArray () const
| Returns the builtin "Array" object.
Object | builtinBoolean () const
| Returns the builtin "Boolean" object.
Object | builtinString () const
| Returns the builtin "String" object.
Object | builtinNumber () const
| Returns the builtin "Number" object.
Object | builtinDate () const
| Returns the builtin "Date" object.
Object | builtinRegExp () const
| Returns the builtin "RegExp" object.
Object | builtinError () const
| Returns the builtin "Error" object.
Object | builtinObjectPrototype () const
| Returns the builtin "Object.prototype" object.
Object | builtinFunctionPrototype () const
| Returns the builtin "Function.prototype" object.
Object | builtinArrayPrototype () const
| Returns the builtin "Array.prototype" object.
Object | builtinBooleanPrototype () const
| Returns the builtin "Boolean.prototype" object.
Object | builtinStringPrototype () const
| Returns the builtin "String.prototype" object.
Object | builtinNumberPrototype () const
| Returns the builtin "Number.prototype" object.
Object | builtinDatePrototype () const
| Returns the builtin "Date.prototype" object.
Object | builtinRegExpPrototype () const
| Returns the builtin "RegExp.prototype" object.
Object | builtinErrorPrototype () const
| Returns the builtin "Error.prototype" object.
Object | builtinEvalError () const
| The initial value of "Error" global property.
Object | builtinRangeError () const
Object | builtinReferenceError () const
Object | builtinSyntaxError () const
Object | builtinTypeError () const
Object | builtinURIError () const
Object | builtinEvalErrorPrototype () const
Object | builtinRangeErrorPrototype () const
Object | builtinReferenceErrorPrototype () const
Object | builtinSyntaxErrorPrototype () const
Object | builtinTypeErrorPrototype () const
Object | builtinURIErrorPrototype () const
void | setCompatMode (CompatMode mode)
| Call this to enable a compatibility mode with another browser.
CompatMode | compatMode () const
virtual void | mark ()
| Called by InterpreterImp during the mark phase of the garbage collector Default implementation does nothing, this exist for classes that reimplement Interpreter.
virtual int | rtti ()
| Provides a way to distinguish derived classes.
## Static Public Member Functions
bool | collect ()
| Run the garbage collection.
## Protected Member Functions
virtual void | virtual_hook (int id, void *data)

## Detailed Description

Interpreter objects can be used to evaluate ECMAScript code.

Each interpreter has a global object which is used for the purposes of code evaluation, and also provides access to built-in properties such as " Object" and "Number".

Definition at line 119 of file interpreter.h.

## Constructor & Destructor Documentation

Interpreter::Interpreter | ( | const Object & | global | ) |

  | Creates a new interpreter. The supplied object will be used as the global object for all scripts executed with this interpreter. During constuction, all the standard properties such as "Object" and "Number" will be added to the global object. Note: You should not use the same global object for multiple interpreters. This is due do the fact that the built-in properties are set in the constructor, and if these objects have been modified from another interpreter (e.g. a script modifying String.prototype), the changes will be overridden. Parameters:
  global | The object to use as the global object for this interpreter
Definition at line 96 of file interpreter.cpp.

Interpreter::Interpreter | ( |  | ) |

| Creates a new interpreter. A global object will be created and initialized with the standard global properties. Definition at line 101 of file interpreter.cpp.

## Member Function Documentation

Object Interpreter::globalObject | ( |  | ) | const

| Returns the object that is used as the global object during all script execution performed by this interpreter. Definition at line 112 of file interpreter.cpp.

ExecState * Interpreter::globalExec | ( |  | ) |

| Returns the execution state object which can be used to execute scripts using this interpreter at a the "global" level, i.e. one with a execution context that has the global object as the "this" value, and who's scope chain contains only the global object. Note: this pointer remains constant for the life of the interpreter and should not be manually deleted. Returns: The interpreter global execution state object Definition at line 122 of file interpreter.cpp.

bool Interpreter::checkSyntax | ( | const UString & | code | ) |

  | Parses the supplied ECMAScript code and checks for syntax errors. Parameters:
  code | The code to check
Returns: true if there were no syntax errors in the code, otherwise false Definition at line 127 of file interpreter.cpp.

Completion Interpreter::evaluate | ( | const UString & | code,
|  | const Value & | thisV = Value()
| ) |

  | Evaluates the supplied ECMAScript code. Since this method returns a Completion, you should check the type of completion to detect an error or before attempting to access the returned value. For example, if an error occurs during script execution and is not caught by the script, the completion type will be Throw. If the supplied code is invalid, a SyntaxError will be thrown. Parameters:
  code | The code to evaluate
  thisV | The value to pass in as the "this" value for the script execution. This should either be Null() or an Object.
Returns: A completion object representing the result of the execution. Definition at line 132 of file interpreter.cpp.

Object Interpreter::builtinObject | ( |  | ) | const

| Returns the builtin "Object" object. This is the object that was set as a property of the global object during construction; if the property is replaced by script code, this method will still return the original object. Returns: The builtin "Object" object Definition at line 142 of file interpreter.cpp.

Object Interpreter::builtinFunction | ( |  | ) | const

| Returns the builtin "Function" object. Definition at line 147 of file interpreter.cpp.

Object Interpreter::builtinArray | ( |  | ) | const

| Returns the builtin "Array" object. Definition at line 152 of file interpreter.cpp.

Object Interpreter::builtinBoolean | ( |  | ) | const

| Returns the builtin "Boolean" object. Definition at line 157 of file interpreter.cpp.

Object Interpreter::builtinString | ( |  | ) | const

| Returns the builtin "String" object. Definition at line 162 of file interpreter.cpp.

Object Interpreter::builtinNumber | ( |  | ) | const

| Returns the builtin "Number" object. Definition at line 167 of file interpreter.cpp.

Object Interpreter::builtinDate | ( |  | ) | const

| Returns the builtin "Date" object. Definition at line 172 of file interpreter.cpp.

Object Interpreter::builtinRegExp | ( |  | ) | const

| Returns the builtin "RegExp" object. Definition at line 177 of file interpreter.cpp.

Object Interpreter::builtinError | ( |  | ) | const

| Returns the builtin "Error" object. Definition at line 182 of file interpreter.cpp. Referenced by KJS::Error::create().

Object Interpreter::builtinObjectPrototype | ( |  | ) | const

| Returns the builtin "Object.prototype" object. Definition at line 187 of file interpreter.cpp.

Object Interpreter::builtinFunctionPrototype | ( |  | ) | const

| Returns the builtin "Function.prototype" object. Definition at line 192 of file interpreter.cpp.

Object Interpreter::builtinArrayPrototype | ( |  | ) | const

| Returns the builtin "Array.prototype" object. Definition at line 197 of file interpreter.cpp.

Object Interpreter::builtinBooleanPrototype | ( |  | ) | const

| Returns the builtin "Boolean.prototype" object. Definition at line 202 of file interpreter.cpp.

Object Interpreter::builtinStringPrototype | ( |  | ) | const

| Returns the builtin "String.prototype" object. Definition at line 207 of file interpreter.cpp.

Object Interpreter::builtinNumberPrototype | ( |  | ) | const

| Returns the builtin "Number.prototype" object. Definition at line 212 of file interpreter.cpp.

Object Interpreter::builtinDatePrototype | ( |  | ) | const

| Returns the builtin "Date.prototype" object. Definition at line 217 of file interpreter.cpp.

Object Interpreter::builtinRegExpPrototype | ( |  | ) | const

| Returns the builtin "RegExp.prototype" object. Definition at line 222 of file interpreter.cpp.

Object Interpreter::builtinErrorPrototype | ( |  | ) | const

| Returns the builtin "Error.prototype" object. Definition at line 227 of file interpreter.cpp.

Object Interpreter::builtinEvalError | ( |  | ) | const

| The initial value of "Error" global property. Definition at line 232 of file interpreter.cpp. Referenced by KJS::Error::create().

void Interpreter::setCompatMode | ( | CompatMode | mode | ) |

| Call this to enable a compatibility mode with another browser. (by default konqueror is in "native mode"). Currently, in KJS, this only changes the behaviour of Date::getYear() which returns the full year under IE. Definition at line 292 of file interpreter.cpp.

bool Interpreter::collect | ( |  | ) | `[static]`

| Run the garbage collection. Returns true when at least one object was collected; false otherwise. Definition at line 302 of file interpreter.cpp.

virtual void KJS::Interpreter::mark | ( |  | ) | `[inline, virtual]`

| Called by InterpreterImp during the mark phase of the garbage collector Default implementation does nothing, this exist for classes that reimplement Interpreter. Definition at line 332 of file interpreter.h.

virtual int KJS::Interpreter::rtti | ( |  | ) | `[inline, virtual]`

| Provides a way to distinguish derived classes. Only useful if you reimplement Interpreter and if different kind of interpreters are created in the same process. The base class returns 0, the ECMA-bindings interpreter returns 1. Definition at line 340 of file interpreter.h.

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

- interpreter.h
- interpreter.cpp

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:08:56 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001