KJS::Interpreter
#include <interpreter.h>

Public Types | |
enum | CompatMode { NativeMode, IECompat, NetscapeCompat } |
typedef WTF::HashMap< UString::Rep *, std::pair< KJS::StringImp *, int > > | InternedStringsTable |
Public Member Functions | |
Interpreter () | |
Interpreter (JSGlobalObject *globalObject) | |
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 UChar *code, int codeLength) |
Completion | checkSyntax (const UString &sourceURL, int startingLineNumber, const UString &code) |
bool | checkTimeout () |
CompatMode | compatMode () const |
Debugger * | debugger () 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) |
ExecState * | execState () |
ActivationImp * | getRecycledActivation () |
virtual ExecState * | globalExec () |
JSGlobalObject * | globalObject () const |
Package * | globalPackage () |
void | initGlobalObject () |
virtual bool | isSafeScript (const Interpreter *) |
virtual void | mark (bool currentThreadIsMainThread) |
Interpreter * | nextInterpreter () const |
void | pauseTimeoutCheck () |
Interpreter * | prevInterpreter () 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 Interpreter * | firstInterpreter () |
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
◆ Interpreter() [1/2]
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
-
globalObject The object to use as the global object for this interpreter
Definition at line 218 of file interpreter.cpp.
◆ Interpreter() [2/2]
KJS::Interpreter::Interpreter | ( | ) |
Creates a new interpreter.
A global object will be created and initialized with the standard global properties.
Definition at line 226 of file interpreter.cpp.
Member Function Documentation
◆ builtinArray()
JSObject * KJS::Interpreter::builtinArray | ( | ) | const |
Returns the builtin "Array" object.
Definition at line 629 of file interpreter.cpp.
◆ builtinArrayPrototype()
JSObject * KJS::Interpreter::builtinArrayPrototype | ( | ) | const |
Returns the builtin "Array.prototype" object.
Definition at line 674 of file interpreter.cpp.
◆ builtinBoolean()
JSObject * KJS::Interpreter::builtinBoolean | ( | ) | const |
Returns the builtin "Boolean" object.
Definition at line 634 of file interpreter.cpp.
◆ builtinBooleanPrototype()
JSObject * KJS::Interpreter::builtinBooleanPrototype | ( | ) | const |
Returns the builtin "Boolean.prototype" object.
Definition at line 679 of file interpreter.cpp.
◆ builtinDate()
JSObject * KJS::Interpreter::builtinDate | ( | ) | const |
Returns the builtin "Date" object.
Definition at line 649 of file interpreter.cpp.
◆ builtinDatePrototype()
JSObject * KJS::Interpreter::builtinDatePrototype | ( | ) | const |
Returns the builtin "Date.prototype" object.
Definition at line 694 of file interpreter.cpp.
◆ builtinError()
JSObject * KJS::Interpreter::builtinError | ( | ) | const |
Returns the builtin "Error" object.
Definition at line 659 of file interpreter.cpp.
◆ builtinErrorPrototype()
JSObject * KJS::Interpreter::builtinErrorPrototype | ( | ) | const |
Returns the builtin "Error.prototype" object.
Definition at line 704 of file interpreter.cpp.
◆ builtinEvalError()
JSObject * KJS::Interpreter::builtinEvalError | ( | ) | const |
The initial value of "Error" global property.
Definition at line 709 of file interpreter.cpp.
◆ builtinFunction()
JSObject * KJS::Interpreter::builtinFunction | ( | ) | const |
Returns the builtin "Function" object.
Definition at line 624 of file interpreter.cpp.
◆ builtinFunctionPrototype()
JSObject * KJS::Interpreter::builtinFunctionPrototype | ( | ) | const |
Returns the builtin "Function.prototype" object.
Definition at line 669 of file interpreter.cpp.
◆ builtinNumber()
JSObject * KJS::Interpreter::builtinNumber | ( | ) | const |
Returns the builtin "Number" object.
Definition at line 644 of file interpreter.cpp.
◆ builtinNumberPrototype()
JSObject * KJS::Interpreter::builtinNumberPrototype | ( | ) | const |
Returns the builtin "Number.prototype" object.
Definition at line 689 of file interpreter.cpp.
◆ builtinObject()
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 619 of file interpreter.cpp.
◆ builtinObjectPrototype()
JSObject * KJS::Interpreter::builtinObjectPrototype | ( | ) | const |
Returns the builtin "Object.prototype" object.
Definition at line 664 of file interpreter.cpp.
◆ builtinRegExp()
JSObject * KJS::Interpreter::builtinRegExp | ( | ) | const |
Returns the builtin "RegExp" object.
Definition at line 654 of file interpreter.cpp.
◆ builtinRegExpPrototype()
JSObject * KJS::Interpreter::builtinRegExpPrototype | ( | ) | const |
Returns the builtin "RegExp.prototype" object.
Definition at line 699 of file interpreter.cpp.
◆ builtinString()
JSObject * KJS::Interpreter::builtinString | ( | ) | const |
Returns the builtin "String" object.
Definition at line 639 of file interpreter.cpp.
◆ builtinStringPrototype()
JSObject * KJS::Interpreter::builtinStringPrototype | ( | ) | const |
Returns the builtin "String.prototype" object.
Definition at line 684 of file interpreter.cpp.
◆ checkSyntax()
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 sourceURL A URL denoting the origin of the code startingLineNumber The 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 498 of file interpreter.cpp.
◆ collect()
|
static |
Run the garbage collection.
Returns true when at least one object was collected; false otherwise.
Definition at line 769 of file interpreter.cpp.
◆ evaluate()
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
-
sourceURL A URL denoting the origin of the code startingLineNumber The line offset within an embedding context code The code to evaluate codeLength The length of 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 521 of file interpreter.cpp.
◆ 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 483 of file interpreter.cpp.
◆ globalObject()
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 352 of file interpreter.cpp.
◆ globalPackage()
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 493 of file interpreter.cpp.
◆ isSafeScript()
|
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.
◆ mark()
|
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 774 of file interpreter.cpp.
◆ 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 792 of file interpreter.cpp.
◆ normalizeCode()
|
static |
Pretty-prints the supplied ECMAScript code after checking it for syntax errors.
- Parameters
-
sourceURL A URL denoting the origin of the code startingLineNumber The line offset within an embedding context codeIn The code to check codeIn Pointer 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 601 of file interpreter.cpp.
◆ 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.
◆ setCompatMode()
|
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.
◆ setGlobalPackage()
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 488 of file interpreter.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Feb 3 2023 04:01:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.