• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KJS

KJS::Interpreter

KJS::Interpreter Class Reference

#include <interpreter.h>

List of all members.


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 52 of file interpreter.h.


Public Types

enum  CompatMode { NativeMode, IECompat, NetscapeCompat }

Public Member Functions

 Interpreter (JSObject *globalObject)
 Interpreter ()
JSObject * globalObject () const
void initGlobalObject ()
virtual ExecState * globalExec ()
void setGlobalPackage (Package *p)
Package * globalPackage ()
Completion checkSyntax (const UString &sourceURL, int startingLineNumber, const UString &code)
Completion checkSyntax (const UString &sourceURL, int startingLineNumber, const UChar *code, int codeLength)
Completion evaluate (const UString &sourceURL, int startingLineNumber, const UChar *code, int codeLength, JSValue *thisV=0)
Completion evaluate (const UString &sourceURL, int startingLineNumber, const UString &code, JSValue *thisV=0)
JSObject * builtinObject () const
JSObject * builtinFunction () const
JSObject * builtinArray () const
JSObject * builtinBoolean () const
JSObject * builtinString () const
JSObject * builtinNumber () const
JSObject * builtinDate () const
JSObject * builtinRegExp () const
JSObject * builtinError () const
JSObject * builtinObjectPrototype () const
JSObject * builtinFunctionPrototype () const
JSObject * builtinArrayPrototype () const
JSObject * builtinBooleanPrototype () const
JSObject * builtinStringPrototype () const
JSObject * builtinNumberPrototype () const
JSObject * builtinDatePrototype () const
JSObject * builtinRegExpPrototype () const
JSObject * builtinErrorPrototype () const
JSObject * builtinEvalError () const
JSObject * builtinRangeError () const
JSObject * builtinReferenceError () const
JSObject * builtinSyntaxError () const
JSObject * builtinTypeError () const
JSObject * builtinURIError () const
JSObject * builtinEvalErrorPrototype () const
JSObject * builtinRangeErrorPrototype () const
JSObject * builtinReferenceErrorPrototype () const
JSObject * builtinSyntaxErrorPrototype () const
JSObject * builtinTypeErrorPrototype () const
JSObject * builtinURIErrorPrototype () const
void setCompatMode (CompatMode mode)
CompatMode compatMode () const
virtual void mark (bool currentThreadIsMainThread)
virtual int rtti ()
void saveBuiltins (SavedBuiltins &) const
void restoreBuiltins (const SavedBuiltins &)
virtual bool isGlobalObject (JSValue *)
virtual Interpreter * interpreterForGlobalObject (const JSValue *)
virtual bool isSafeScript (const Interpreter *)
Interpreter * nextInterpreter () const
Interpreter * prevInterpreter () const
Debugger * debugger () const
void setDebugger (Debugger *d)
void setContext (Context *c)
Context * context () const
void setTimeoutTime (unsigned timeoutTime)
void startTimeoutCheck ()
void stopTimeoutCheck ()
void restartTimeoutCheck ()
void pauseTimeoutCheck ()
void resumeTimeoutCheck ()
bool checkTimeout ()
void ref ()
void deref ()
int refCount () const

Static Public Member Functions

static bool collect ()
static bool shouldPrintExceptions ()
static void setShouldPrintExceptions (bool)
static Interpreter * firstInterpreter ()
static Interpreter * interpreterWithGlobalObject (JSObject *)

Protected Member Functions

virtual ~Interpreter ()
virtual bool shouldInterruptScript () const

Protected Attributes

long m_timeoutTime

Friends

class Collector
class TimeoutChecker

Member Enumeration Documentation

enum KJS::Interpreter::CompatMode

Enumerator:
NativeMode 
IECompat 
NetscapeCompat 

Definition at line 259 of file interpreter.h.


Constructor & Destructor Documentation

KJS::Interpreter::Interpreter ( JSObject *  globalObject  ) 

Creates a new interpreter.

The supplied object will be used as the global object for all scripts executed with this interpreter. During construction, 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 216 of file interpreter.cpp.

KJS::Interpreter::Interpreter (  ) 

Creates a new interpreter.

A global object will be created and initialized with the standard global properties.

Definition at line 224 of file interpreter.cpp.

KJS::Interpreter::~Interpreter (  )  [protected, virtual]

Definition at line 262 of file interpreter.cpp.


Member Function Documentation

JSObject * KJS::Interpreter::globalObject (  )  const

Returns the object that is used as the global object during all script execution performed by this interpreter.

Definition at line 285 of file interpreter.cpp.

void KJS::Interpreter::initGlobalObject (  ) 

Definition at line 290 of file interpreter.cpp.

ExecState * KJS::Interpreter::globalExec (  )  [virtual]

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 406 of file interpreter.cpp.

void KJS::Interpreter::setGlobalPackage ( Package *  p  ) 

Sets the package instance that will be used to resolve the first level of identifiers of import statements.

If no package is set which will make any "import" script statement fail with an error. This is the default in e.g. a Web browser where package imports should be disabled for security reasons.

Definition at line 411 of file interpreter.cpp.

Package * KJS::Interpreter::globalPackage (  ) 

Returns the package that was installed to handle top level package requests.

Returns 0, the default, when no package was set.

Returns:
The global package

Definition at line 416 of file interpreter.cpp.

Completion KJS::Interpreter::checkSyntax ( const UString &  sourceURL,
int  startingLineNumber,
const UString &  code 
)

Parses the supplied ECMAScript code and checks for syntax errors.

Parameters:
code The code to check
Returns:
A normal completion if there were no syntax errors in the code, otherwise a throw completion with the syntax error as its value.

Definition at line 421 of file interpreter.cpp.

Completion KJS::Interpreter::checkSyntax ( const UString &  sourceURL,
int  startingLineNumber,
const UChar *  code,
int  codeLength 
)

Definition at line 426 of file interpreter.cpp.

Completion KJS::Interpreter::evaluate ( const UString &  sourceURL,
int  startingLineNumber,
const UChar *  code,
int  codeLength,
JSValue *  thisV = 0 
)

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 jsNull() or an Object.
Returns:
A completion object representing the result of the execution.

Definition at line 443 of file interpreter.cpp.

Completion KJS::Interpreter::evaluate ( const UString &  sourceURL,
int  startingLineNumber,
const UString &  code,
JSValue *  thisV = 0 
)

Definition at line 438 of file interpreter.cpp.

JSObject * KJS::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 516 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinFunction (  )  const

Returns the builtin "Function" object.

Definition at line 521 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinArray (  )  const

Returns the builtin "Array" object.

Definition at line 526 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinBoolean (  )  const

Returns the builtin "Boolean" object.

Definition at line 531 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinString (  )  const

Returns the builtin "String" object.

Definition at line 536 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinNumber (  )  const

Returns the builtin "Number" object.

Definition at line 541 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinDate (  )  const

Returns the builtin "Date" object.

Definition at line 546 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinRegExp (  )  const

Returns the builtin "RegExp" object.

Definition at line 551 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinError (  )  const

Returns the builtin "Error" object.

Definition at line 556 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinObjectPrototype (  )  const

Returns the builtin "Object.prototype" object.

Definition at line 561 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinFunctionPrototype (  )  const

Returns the builtin "Function.prototype" object.

Definition at line 566 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinArrayPrototype (  )  const

Returns the builtin "Array.prototype" object.

Definition at line 571 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinBooleanPrototype (  )  const

Returns the builtin "Boolean.prototype" object.

Definition at line 576 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinStringPrototype (  )  const

Returns the builtin "String.prototype" object.

Definition at line 581 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinNumberPrototype (  )  const

Returns the builtin "Number.prototype" object.

Definition at line 586 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinDatePrototype (  )  const

Returns the builtin "Date.prototype" object.

Definition at line 591 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinRegExpPrototype (  )  const

Returns the builtin "RegExp.prototype" object.

Definition at line 596 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinErrorPrototype (  )  const

Returns the builtin "Error.prototype" object.

Definition at line 601 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinEvalError (  )  const

The initial value of "Error" global property.

Definition at line 606 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinRangeError (  )  const

Definition at line 611 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinReferenceError (  )  const

Definition at line 616 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinSyntaxError (  )  const

Definition at line 621 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinTypeError (  )  const

Definition at line 626 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinURIError (  )  const

Definition at line 631 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinEvalErrorPrototype (  )  const

Definition at line 636 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinRangeErrorPrototype (  )  const

Definition at line 641 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinReferenceErrorPrototype (  )  const

Definition at line 646 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinSyntaxErrorPrototype (  )  const

Definition at line 651 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinTypeErrorPrototype (  )  const

Definition at line 656 of file interpreter.cpp.

JSObject * KJS::Interpreter::builtinURIErrorPrototype (  )  const

Definition at line 661 of file interpreter.cpp.

void KJS::Interpreter::setCompatMode ( CompatMode  mode  )  [inline]

Call this to enable a compatibility mode with another browser.

(by default konqueror is in "native mode"). Currently, in KJS, this only changes the behavior of Date::getYear() which returns the full year under IE.

Definition at line 266 of file interpreter.h.

CompatMode KJS::Interpreter::compatMode (  )  const [inline]

Definition at line 267 of file interpreter.h.

bool KJS::Interpreter::collect (  )  [static]

Run the garbage collection.

Returns true when at least one object was collected; false otherwise.

Definition at line 666 of file interpreter.cpp.

void KJS::Interpreter::mark ( bool  currentThreadIsMainThread  )  [virtual]

Called during the mark phase of the garbage collector.

Subclasses implementing custom mark methods must make sure to chain to this one.

Definition at line 671 of file interpreter.cpp.

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 287 of file interpreter.h.

bool KJS::Interpreter::shouldPrintExceptions (  )  [static]

Definition at line 699 of file interpreter.cpp.

void KJS::Interpreter::setShouldPrintExceptions ( bool  print  )  [static]

Definition at line 704 of file interpreter.cpp.

void KJS::Interpreter::saveBuiltins ( SavedBuiltins &  builtins  )  const

Definition at line 731 of file interpreter.cpp.

void KJS::Interpreter::restoreBuiltins ( const SavedBuiltins &  builtins  ) 

Definition at line 771 of file interpreter.cpp.

virtual bool KJS::Interpreter::isGlobalObject ( JSValue *   )  [inline, virtual]

Determine if the value is a global object (for any interpreter).

This may be difficult to determine for multiple uses of JSC in a process that are logically independent of each other. In the case of a Web browser, this method is used to determine if an object is the Window object so we can perform security checks.

Definition at line 302 of file interpreter.h.

virtual Interpreter* KJS::Interpreter::interpreterForGlobalObject ( const JSValue *   )  [inline, virtual]

Find the interpreter for a particular global object.

This should really be a static method, but we can't do that is C++. Again, as with isGlobalObject() implementation really need to know about all instances of Interpreter created in an application to correctly implement this method. The only override of this method is currently in WebCore.

Definition at line 311 of file interpreter.h.

virtual bool KJS::Interpreter::isSafeScript ( const Interpreter *   )  [inline, virtual]

Determine if the it is 'safe' to execute code in the target interpreter from an object that originated in this interpreter.

This check is used to enforce WebCore cross frame security rules. In particular, attempts to access 'bound' objects are not allowed unless isSafeScript returns true.

Definition at line 319 of file interpreter.h.

static Interpreter* KJS::Interpreter::firstInterpreter (  )  [inline, static]

Definition at line 326 of file interpreter.h.

Interpreter* KJS::Interpreter::nextInterpreter (  )  const [inline]

Definition at line 327 of file interpreter.h.

Interpreter* KJS::Interpreter::prevInterpreter (  )  const [inline]

Definition at line 328 of file interpreter.h.

Debugger* KJS::Interpreter::debugger (  )  const [inline]

Definition at line 330 of file interpreter.h.

void KJS::Interpreter::setDebugger ( Debugger *  d  )  [inline]

Definition at line 331 of file interpreter.h.

void KJS::Interpreter::setContext ( Context *  c  )  [inline]

Definition at line 333 of file interpreter.h.

Context* KJS::Interpreter::context (  )  const [inline]

Definition at line 334 of file interpreter.h.

Interpreter * KJS::Interpreter::interpreterWithGlobalObject ( JSObject *  globalObject  )  [static]

Definition at line 681 of file interpreter.cpp.

void KJS::Interpreter::setTimeoutTime ( unsigned  timeoutTime  )  [inline]

Definition at line 338 of file interpreter.h.

void KJS::Interpreter::startTimeoutCheck (  ) 

Definition at line 811 of file interpreter.cpp.

void KJS::Interpreter::stopTimeoutCheck (  ) 

Definition at line 819 of file interpreter.cpp.

void KJS::Interpreter::restartTimeoutCheck (  ) 

Definition at line 826 of file interpreter.cpp.

void KJS::Interpreter::pauseTimeoutCheck (  ) 

Definition at line 836 of file interpreter.cpp.

void KJS::Interpreter::resumeTimeoutCheck (  ) 

Definition at line 843 of file interpreter.cpp.

bool KJS::Interpreter::checkTimeout (  )  [inline]

Definition at line 437 of file interpreter.h.

void KJS::Interpreter::ref (  )  [inline]

Definition at line 351 of file interpreter.h.

void KJS::Interpreter::deref (  )  [inline]

Definition at line 352 of file interpreter.h.

int KJS::Interpreter::refCount (  )  const [inline]

Definition at line 353 of file interpreter.h.

virtual bool KJS::Interpreter::shouldInterruptScript (  )  const [inline, protected, virtual]

Definition at line 357 of file interpreter.h.


Friends And Related Function Documentation

friend class Collector [friend]

Definition at line 53 of file interpreter.h.

friend class TimeoutChecker [friend]

Definition at line 54 of file interpreter.h.


Member Data Documentation

long KJS::Interpreter::m_timeoutTime [protected]

Definition at line 359 of file interpreter.h.


The documentation for this class was generated from the following files:
  • interpreter.h
  • interpreter.cpp

KJS

Skip menu "KJS"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal