#include <kjsinterpreter.h>

Public Member Functions

 KJSInterpreter ()
 KJSInterpreter (const KJSGlobalObject &global)
 KJSInterpreter (const KJSInterpreter &other)
 ~KJSInterpreter ()
KJSResult evaluate (const QString &sourceURL, int startingLineNumber, const QString &code, KJSObject *thisValue=nullptr)
KJSResult evaluate (const QString &code, KJSObject *thisValue=nullptr)
KJSContextglobalContext ()
const KJSContextglobalContext () const
KJSObject globalObject ()
KJSInterpreteroperator= (const KJSInterpreter &other)
void setTimeoutTime (unsigned mSecs)
void startTimeoutCheck ()
void stopTimeoutCheck ()

Static Public Member Functions

static bool normalizeCode (const QString &codeIn, QString *codeOut, int *errLine=nullptr, QString *errMsg=nullptr)

Detailed Description

A class representing a JavaScript interpreter.

JavaScript interpreter

Definition at line 82 of file kjsinterpreter.h.

Constructor & Destructor Documentation

KJSInterpreter::KJSInterpreter ( )

Constructs an interpreter with a default global object.

Definition at line 96 of file kjsinterpreter.cpp.

KJSInterpreter::KJSInterpreter ( const KJSGlobalObject global)

Constructs an interpreter with a custom global object.

Definition at line 104 of file kjsinterpreter.cpp.

KJSInterpreter::KJSInterpreter ( const KJSInterpreter other)

Creates a copy of another interpreter.

Definition at line 120 of file kjsinterpreter.cpp.

KJSInterpreter::~KJSInterpreter ( )

Destructs this interpreter and frees resources it has allocated.

This renders any still existing objects referencing those invalid.

Definition at line 150 of file kjsinterpreter.cpp.

Member Function Documentation

KJSResult KJSInterpreter::evaluate ( const QString sourceURL,
int  startingLineNumber,
const QString code,
KJSObject thisValue = nullptr 

Evaluates a piece of code with a "this" set to (optionally set) value.

The sourceURL and startingLineNumber parameters are used to provide information about the origin of a parse error or runtime exception.

Definition at line 172 of file kjsinterpreter.cpp.

KJSResult KJSInterpreter::evaluate ( const QString code,
KJSObject thisValue = nullptr 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 208 of file kjsinterpreter.cpp.

KJSContext * KJSInterpreter::globalContext ( )

Returns a handle to the global execution context.

Definition at line 157 of file kjsinterpreter.cpp.

const KJSContext* KJSInterpreter::globalContext ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

KJSObject KJSInterpreter::globalObject ( )

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

Definition at line 165 of file kjsinterpreter.cpp.

bool KJSInterpreter::normalizeCode ( const QString codeIn,
QString codeOut,
int *  errLine = nullptr,
QString errMsg = nullptr 

Reformat the given script code to an easy to read format with only one statement per line.

This can be useful when debugging a script that was e.g. condensed into a single line to a single line. While comments will be removed the script will remain unchanged semantically.

codeInThe code to be reformatted
codeOutPoints to string holding the result.
errLineWill hold the line of a parse error
errMsgWill hold the message of a parse error
Returns true if the reformatting was successful, false on a parse error.

Definition at line 232 of file kjsinterpreter.cpp.

KJSInterpreter & KJSInterpreter::operator= ( const KJSInterpreter other)

Assign another interpreter instance to this object.

Definition at line 129 of file kjsinterpreter.cpp.

void KJSInterpreter::setTimeoutTime ( unsigned  mSecs)

Call this function in preparation of startTimeoutCheck() to set the number of milliseconds that a script evaluation is allowed to take at most.

This will protect the user from slow and long-running scripts or even infinite loops.

A 0 msecs value (the default setting) means no timeout at all.

mSecsThe number of milliseconds

Definition at line 214 of file kjsinterpreter.cpp.

void KJSInterpreter::startTimeoutCheck ( )

Start measuring executing time until the timeout value specified via setTimeoutTime().

In case the timeout expires a script error with the message "Execution timeout. Aborting." will be thrown upon evaluation of the next script expression or statement.

Definition at line 220 of file kjsinterpreter.cpp.

void KJSInterpreter::stopTimeoutCheck ( )

Stops measurement of execution time after the initial startTimeoutCheck() call.

Call this function after a evaluate() or if the check should temporarily be disabled. When showing a message box to the user for example.

Definition at line 226 of file kjsinterpreter.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 23:02:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.