KJS::Interpreter

#include <interpreter.h>

Inheritance diagram for KJS::Interpreter:

Public Types

enum  CompatMode { NativeMode, IECompat, NetscapeCompat }
 
typedef WTF::HashMap< UString::Rep *, std::pair< KJS::StringImp *, int > > InternedStringsTable
 

Public Member Functions

 Interpreter (JSGlobalObject *globalObject)
 
 Interpreter ()
 
JSObject * builtinArray () const
 
JSObject * builtinArrayPrototype () const
 
JSObject * builtinBoolean () const
 
JSObject * builtinBooleanPrototype () const
 
JSObject * builtinDate () const
 
JSObject * builtinDatePrototype () const
 
JSObject * builtinError () const
 
JSObject * builtinErrorPrototype () const
 
JSObject * builtinEvalError () const
 
JSObject * builtinEvalErrorPrototype () const
 
JSObject * builtinFunction () const
 
JSObject * builtinFunctionPrototype () const
 
JSObject * builtinNumber () const
 
JSObject * builtinNumberPrototype () const
 
JSObject * builtinObject () const
 
JSObject * builtinObjectPrototype () const
 
JSObject * builtinRangeError () const
 
JSObject * builtinRangeErrorPrototype () const
 
JSObject * builtinReferenceError () const
 
JSObject * builtinReferenceErrorPrototype () const
 
JSObject * builtinRegExp () const
 
JSObject * builtinRegExpPrototype () const
 
JSObject * builtinString () const
 
JSObject * builtinStringPrototype () const
 
JSObject * builtinSyntaxError () const
 
JSObject * builtinSyntaxErrorPrototype () const
 
JSObject * builtinTypeError () const
 
JSObject * builtinTypeErrorPrototype () const
 
JSObject * builtinURIError () const
 
JSObject * builtinURIErrorPrototype () const
 
Completion checkSyntax (const UString &sourceURL, int startingLineNumber, const UString &code)
 
Completion checkSyntax (const UString &sourceURL, int startingLineNumber, const UChar *code, int codeLength)
 
bool checkTimeout ()
 
CompatMode compatMode () const
 
Debuggerdebugger () const
 
void deref ()
 
Completion evaluate (const UString &sourceURL, int startingLineNumber, const UChar *code, int codeLength, JSValue *thisV=nullptr)
 
Completion evaluate (const UString &sourceURL, int startingLineNumber, const UString &code, JSValue *thisV=nullptr)
 
ExecStateexecState ()
 
ActivationImp * getRecycledActivation ()
 
virtual ExecStateglobalExec ()
 
JSGlobalObject * globalObject () const
 
Package * globalPackage ()
 
void initGlobalObject ()
 
virtual bool isSafeScript (const Interpreter *)
 
virtual void mark (bool currentThreadIsMainThread)
 
InterpreternextInterpreter () const
 
void pauseTimeoutCheck ()
 
InterpreterprevInterpreter () const
 
void recycleActivation (ActivationImp *act)
 
void ref ()
 
int refCount () const
 
void restartTimeoutCheck ()
 
void restoreBuiltins (const SavedBuiltins &)
 
void resumeTimeoutCheck ()
 
virtual int rtti ()
 
void saveBuiltins (SavedBuiltins &) const
 
void setCompatMode (CompatMode mode)
 
void setDebugger (Debugger *d)
 
void setExecState (ExecState *e)
 
void setGlobalPackage (Package *p)
 
void setTimeoutTime (unsigned timeoutTime)
 
unsigned char * stackAlloc (size_t size)
 
void stackFree (size_t size)
 
void startTimeoutCheck ()
 
void stopTimeoutCheck ()
 

Static Public Member Functions

static bool collect ()
 
static InterpreterfirstInterpreter ()
 
static StringImp * internString (const UString &literal)
 
static void markSourceCachedObjects ()
 
static bool normalizeCode (const UString &codeIn, UString *codeOut, int *errLine=nullptr, UString *errMsg=nullptr)
 
static void releaseInternedString (const UString &literal)
 
static void setShouldPrintExceptions (bool)
 
static bool shouldPrintExceptions ()
 

Protected Member Functions

virtual bool shouldInterruptScript () const
 

Protected Attributes

long m_timeoutTime
 

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

Constructor & Destructor Documentation

KJS::Interpreter::Interpreter ( JSGlobalObject *  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
globalObjectThe object to use as the global object for this interpreter

Definition at line 220 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 228 of file interpreter.cpp.

Member Function Documentation

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

Returns the builtin "Array" object.

Definition at line 631 of file interpreter.cpp.

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

Returns the builtin "Array.prototype" object.

Definition at line 676 of file interpreter.cpp.

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

Returns the builtin "Boolean" object.

Definition at line 636 of file interpreter.cpp.

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

Returns the builtin "Boolean.prototype" object.

Definition at line 681 of file interpreter.cpp.

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

Returns the builtin "Date" object.

Definition at line 651 of file interpreter.cpp.

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

Returns the builtin "Date.prototype" object.

Definition at line 696 of file interpreter.cpp.

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

Returns the builtin "Error" object.

Definition at line 661 of file interpreter.cpp.

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

Returns the builtin "Error.prototype" object.

Definition at line 706 of file interpreter.cpp.

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

The initial value of "Error" global property.

Definition at line 711 of file interpreter.cpp.

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

Returns the builtin "Function" object.

Definition at line 626 of file interpreter.cpp.

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

Returns the builtin "Function.prototype" object.

Definition at line 671 of file interpreter.cpp.

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

Returns the builtin "Number" object.

Definition at line 646 of file interpreter.cpp.

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

Returns the builtin "Number.prototype" object.

Definition at line 691 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 621 of file interpreter.cpp.

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

Returns the builtin "Object.prototype" object.

Definition at line 666 of file interpreter.cpp.

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

Returns the builtin "RegExp" object.

Definition at line 656 of file interpreter.cpp.

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

Returns the builtin "RegExp.prototype" object.

Definition at line 701 of file interpreter.cpp.

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

Returns the builtin "String" object.

Definition at line 641 of file interpreter.cpp.

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

Returns the builtin "String.prototype" object.

Definition at line 686 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
codeThe code to check
sourceURLA URL denoting the origin of the code
startingLineNumberThe line offset within an embedding context
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 500 of file interpreter.cpp.

bool KJS::Interpreter::collect ( )
static

Run the garbage collection.

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

Definition at line 771 of file interpreter.cpp.

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

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
sourceURLA URL denoting the origin of the code
startingLineNumberThe line offset within an embedding context
codeThe code to evaluate
codeLengthThe length of the code to evaluate
thisVThe 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 523 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 485 of file interpreter.cpp.

JSGlobalObject * 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 354 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 495 of file interpreter.cpp.

virtual bool KJS::Interpreter::isSafeScript ( const Interpreter )
inlinevirtual

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

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.

Reimplemented in KJS::ScriptInterpreter.

Definition at line 776 of file interpreter.cpp.

void KJS::Interpreter::markSourceCachedObjects ( )
static

This marks all GC heap resources stored as optimizations; and which have their lifetime managed by the appropriate AST.

It's static since code can survive the interpreter by a bit.

Definition at line 794 of file interpreter.cpp.

bool KJS::Interpreter::normalizeCode ( const UString codeIn,
UString codeOut,
int *  errLine = nullptr,
UString errMsg = nullptr 
)
static

Pretty-prints the supplied ECMAScript code after checking it for syntax errors.

Parameters
sourceURLA URL denoting the origin of the code
startingLineNumberThe line offset within an embedding context
codeInThe code to check
codeInPointer to string that will contain reformatted code upon successful parsing.
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 603 of file interpreter.cpp.

virtual int KJS::Interpreter::rtti ( )
inlinevirtual

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

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

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


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 14 2020 23:00:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.