
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQScriptEngineAgent class provides an interface to report events pertaining toQScriptEngine execution.More...
| Header: | #include <QScriptEngineAgent> |
| Since: | Qt 4.4 |
| enum | Extension { DebuggerInvocationRequest } |
| QScriptEngineAgent(QScriptEngine * engine) | |
| virtual | ~QScriptEngineAgent() |
| virtual void | contextPop() |
| virtual void | contextPush() |
| QScriptEngine * | engine() const |
| virtual void | exceptionCatch(qint64 scriptId, const QScriptValue & exception) |
| virtual void | exceptionThrow(qint64 scriptId, const QScriptValue & exception, bool hasHandler) |
| virtual QVariant | extension(Extension extension, const QVariant & argument = QVariant()) |
| virtual void | functionEntry(qint64 scriptId) |
| virtual void | functionExit(qint64 scriptId, const QScriptValue & returnValue) |
| virtual void | positionChange(qint64 scriptId, int lineNumber, int columnNumber) |
| virtual void | scriptLoad(qint64 id, const QString & program, const QString & fileName, int baseLineNumber) |
| virtual void | scriptUnload(qint64 id) |
| virtual bool | supportsExtension(Extension extension) const |
TheQScriptEngineAgent class provides an interface to report events pertaining toQScriptEngine execution.
TheQScriptEngineAgent class is the basis of tools that monitor and/or control the execution of aQScriptEngine, such as debuggers and profilers.
To process script loading and unloading events, reimplement thescriptLoad() andscriptUnload() functions.scriptLoad() is called after the input toQScriptEngine::evaluate() has been parsed, right before the given script is executed. The engine assigns each script an ID, which is available as one of the arguments toscriptLoad(); subsequently, other event handlers can use the ID to identify a particular script. One common usage ofscriptLoad() is to retain the script text, filename and base line number (the original input toQScriptEngine::evaluate()), so that other event handlers can e.g. map a line number to the corresponding line of text.
scriptUnload() is called when theQScriptEngine has no further use for a script; theQScriptEngineAgent may at this point safely discard any resources associated with the script (such as the script text). Note that afterscriptUnload() has been called, theQScriptEngine may reuse the relevant script ID for new scripts (i.e. as argument to a subsequent call toscriptLoad()).
Evaluating the following script will result inscriptUnload() being called immediately after evaluation has completed:
var a= Math.random()+2;
Evaluating the following script willnot result in a call toscriptUnload() when evaluation has completed:
function cube(a) {return a* a* a;}var a= cube(3);The script isn't unloaded because it defines a function (cube) that remains in the script environment after evaluation has completed. If a subsequent script removed thecube function (e.g. by setting it tonull),scriptUnload() would be called when the function is garbage collected. In general terms, a script isn't unloaded until the engine has determined that none of its contents is referenced.
To process script function calls and returns, reimplement thefunctionEntry() andfunctionExit() functions.functionEntry() is called when a script function is about to be executed;functionExit() is called when a script function is about to return, either normally or due to an exception.
To process individual script statements, reimplementpositionChange().positionChange() is called each time the engine is about to execute a new statement of a script, and thus offers the finest level of script monitoring.
To process exceptions, reimplementexceptionThrow() andexceptionCatch().exceptionThrow() is called when a script exception is thrown, before it has been handled.exceptionCatch() is called when an exception handler is present, and execution is about to be resumed at the handler code.
See alsoQScriptEngine::setAgent() andQScriptContextInfo.
This enum specifies the possible extensions to aQScriptEngineAgent.
| Constant | Value | Description |
|---|---|---|
QScriptEngineAgent::DebuggerInvocationRequest | 0 | The agent handlesdebugger script statements. |
See alsoextension().
Constructs aQScriptEngineAgent object for the givenengine.
The engine takes ownership of the agent.
CallQScriptEngine::setAgent() to make this agent the active agent.
[virtual]QScriptEngineAgent::~QScriptEngineAgent()Destroys thisQScriptEngineAgent.
[virtual]void QScriptEngineAgent::contextPop()This function is called when the current script context is about to be popped.
The default implementation does nothing.
See alsocontextPush() andfunctionExit().
[virtual]void QScriptEngineAgent::contextPush()This function is called when a new script context has been pushed.
The default implementation does nothing.
See alsocontextPop() andfunctionEntry().
Returns theQScriptEngine that this agent is associated with.
[virtual]void QScriptEngineAgent::exceptionCatch(qint64 scriptId, constQScriptValue & exception)This function is called when the givenexception is about to be caught, in the script identified byscriptId.
Reimplement this function if you want to handle this event.
The default implementation does nothing.
See alsoexceptionThrow().
[virtual]void QScriptEngineAgent::exceptionThrow(qint64 scriptId, constQScriptValue & exception,bool hasHandler)This function is called when the givenexception has occurred in the engine, in the script identified byscriptId. If the exception was thrown by a native Qt Script function,scriptId is -1.
IfhasHandler is true, there is acatch orfinally block that will handle the exception. IfhasHandler is false, there is no handler for the exception.
Reimplement this function if you want to handle this event. For example, a debugger can notify the user when an uncaught exception occurs (i.e.hasHandler is false).
The default implementation does nothing.
See alsoexceptionCatch().
[virtual]QVariant QScriptEngineAgent::extension(Extension extension, constQVariant & argument = QVariant())This virtual function can be reimplemented in aQScriptEngineAgent subclass to provide support for extensions. The optionalargument can be provided as input to theextension; the result must be returned in the form of aQVariant. You can callsupportsExtension() to check if an extension is supported by theQScriptEngineAgent. By default, no extensions are supported, and this function returns an invalidQVariant.
If you implement theDebuggerInvocationRequest extension, Qt Script will call this function when adebugger statement is encountered in a script. Theargument is aQVariantList containing three items: The first item is the scriptId (a qint64), the second item is the line number (an int), and the third item is the column number (an int).
See alsosupportsExtension().
[virtual]void QScriptEngineAgent::functionEntry(qint64 scriptId)This function is called when a script function is called in the engine. If the script function is not a native Qt Script function, it resides in the script identified byscriptId; otherwise,scriptId is -1.
This function is called just before execution of the script function begins. You can obtain theQScriptContext associated with the function call withQScriptEngine::currentContext(). The arguments passed to the function are available.
Reimplement this function to handle this event. For example, a debugger implementation could reimplement this function (andfunctionExit()) to keep track of the call stack and provide step-over functionality.
The default implementation does nothing.
See alsofunctionExit(),positionChange(), andQScriptEngine::currentContext().
[virtual]void QScriptEngineAgent::functionExit(qint64 scriptId, constQScriptValue & returnValue)This function is called when the currently executing script function is about to return. If the script function is not a native Qt Script function, it resides in the script identified byscriptId; otherwise,scriptId is -1. ThereturnValue is the value that the script function will return.
This function is called just before the script function returns. You can still access theQScriptContext associated with the script function call withQScriptEngine::currentContext().
If the engine'shasUncaughtException() function returns true, the script function is exiting due to an exception; otherwise, the script function is returning normally.
Reimplement this function to handle this event; typically you will then also want to reimplementfunctionEntry().
The default implementation does nothing.
See alsofunctionEntry() andQScriptEngine::hasUncaughtException().
[virtual]void QScriptEngineAgent::positionChange(qint64 scriptId,int lineNumber,int columnNumber)This function is called when the engine is about to execute a new statement in the script identified byscriptId. The statement begins on the line and column specified bylineNumber This event is not generated for native Qt Script functions.
Reimplement this function to handle this event. For example, a debugger implementation could reimplement this function to provide line-by-line stepping, and a profiler implementation could use it to count the number of times each statement is executed.
The default implementation does nothing.
Note:columnNumber is undefined
See alsoscriptLoad() andfunctionEntry().
[virtual]void QScriptEngineAgent::scriptLoad(qint64 id, constQString & program, constQString & fileName,int baseLineNumber)This function is called when the engine has parsed a script and has associated it with the givenid. The id can be used to identify this particular script in subsequent event notifications.
program,fileName andbaseLineNumber are the original arguments to theQScriptEngine::evaluate() call that triggered this event.
This function is called just before the script is about to be evaluated.
You can reimplement this function to record information about the script; for example, by retaining the script text, you can obtain the line of text corresponding to a line number in a subsequent call topositionChange().
The default implementation does nothing.
See alsoscriptUnload().
[virtual]void QScriptEngineAgent::scriptUnload(qint64 id)This function is called when the engine has discarded the script identified by the givenid.
You can reimplement this function to clean up any resources you have associated with the script.
The default implementation does nothing.
See alsoscriptLoad().
[virtual]bool QScriptEngineAgent::supportsExtension(Extension extension) constReturns true if theQScriptEngineAgent supports the givenextension; otherwise, false is returned. By default, no extensions are supported.
See alsoextension().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.