Qt 4.8
qscriptengineagent.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #include "config.h"
25 #include "qscriptengineagent.h"
26 #include "qscriptengineagent_p.h"
27 #include "qscriptengine.h"
28 #include "qscriptengine_p.h"
29 
30 #include "CodeBlock.h"
31 #include "Instruction.h"
32 
34 
122 {
123  if (engine->originalGlobalObject()->debugger())
124  engine->originalGlobalObject()->setDebugger(0);
125  JSC::Debugger::attach(engine->originalGlobalObject());
126  if (!QScriptEnginePrivate::get(engine)->isEvaluating())
127  JSC::Debugger::recompileAllJSFunctions(engine->globalData);
128 }
129 
131 {
132  JSC::Debugger::detach(engine->originalGlobalObject());
133 }
134 
135 void QScriptEngineAgentPrivate::returnEvent(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno)
136 {
137  Q_UNUSED(frame);
138  Q_UNUSED(lineno);
139  Q_UNUSED(sourceID);
140 }
141 
142 void QScriptEngineAgentPrivate::exceptionThrow(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, bool hasHandler)
143 {
144  JSC::CallFrame *oldFrame = engine->currentFrame;
145  int oldAgentLineNumber = engine->agentLineNumber;
146  engine->currentFrame = frame.callFrame();
147  QScriptValue value(engine->scriptValueFromJSCValue(frame.exception()));
148  engine->agentLineNumber = value.property(QLatin1String("lineNumber")).toInt32();
149  q_ptr->exceptionThrow(sourceID, value, hasHandler);
150  engine->agentLineNumber = oldAgentLineNumber;
151  engine->currentFrame = oldFrame;
152  engine->setCurrentException(value);
153 };
154 
155 void QScriptEngineAgentPrivate::exceptionCatch(const JSC::DebuggerCallFrame& frame, intptr_t sourceID)
156 {
157  JSC::CallFrame *oldFrame = engine->currentFrame;
158  engine->currentFrame = frame.callFrame();
159  QScriptValue value(engine->scriptValueFromJSCValue(frame.exception()));
160  q_ptr->exceptionCatch(sourceID, value);
161  engine->currentFrame = oldFrame;
163 }
164 
165 void QScriptEngineAgentPrivate::atStatement(const JSC::DebuggerCallFrame& frame, intptr_t sourceID, int lineno/*, int column*/)
166 {
168  if (!source) {
169  // QTBUG-6108: We don't have the source for this script, so ignore.
170  return;
171  }
172 // column = source->columnNumberFromOffset(column);
173  int column = 1;
174  JSC::CallFrame *oldFrame = engine->currentFrame;
175  int oldAgentLineNumber = engine->agentLineNumber;
176  engine->currentFrame = frame.callFrame();
177  engine->agentLineNumber = lineno;
178  q_ptr->positionChange(sourceID, lineno, column);
179  engine->currentFrame = oldFrame;
180  engine->agentLineNumber = oldAgentLineNumber;
181 }
182 
183 void QScriptEngineAgentPrivate::functionExit(const JSC::JSValue& returnValue, intptr_t sourceID)
184 {
185  QScriptValue result = engine->scriptValueFromJSCValue(returnValue);
186  q_ptr->functionExit(sourceID, result);
187  q_ptr->contextPop();
188 }
189 
190 void QScriptEngineAgentPrivate::evaluateStop(const JSC::JSValue& returnValue, intptr_t sourceID)
191 {
192  QScriptValue result = engine->scriptValueFromJSCValue(returnValue);
193  q_ptr->functionExit(sourceID, result);
194 }
195 
196 void QScriptEngineAgentPrivate::didReachBreakpoint(const JSC::DebuggerCallFrame& frame,
197  intptr_t sourceID, int lineno/*, int column*/)
198 {
201  if (!source) {
202  // QTBUG-6108: We don't have the source for this script, so ignore.
203  return;
204  }
205 // column = source->columnNumberFromOffset(column);
206  int column = 1;
207  JSC::CallFrame *oldFrame = engine->currentFrame;
208  int oldAgentLineNumber = engine->agentLineNumber;
209  engine->currentFrame = frame.callFrame();
210  engine->agentLineNumber = lineno;
211  QList<QVariant> args;
212  args << qint64(sourceID) << lineno << column;
214  engine->currentFrame = oldFrame;
215  engine->agentLineNumber = oldAgentLineNumber;
216  }
217 };
218 
228  : d_ptr(new QScriptEngineAgentPrivate())
229 {
230  d_ptr->q_ptr = this;
232  d_ptr->engine->ownedAgents.append(this);
233 }
234 
239  : d_ptr(&dd)
240 {
241  d_ptr->q_ptr = this;
243 }
244 
249 {
250  d_ptr->engine->agentDeleted(this); //### TODO: Can this throw?
251 }
252 
276  const QString &fileName, int baseLineNumber)
277 {
278  Q_UNUSED(id);
279  Q_UNUSED(program);
280  Q_UNUSED(fileName);
281  Q_UNUSED(baseLineNumber);
282 }
283 
296 {
297  Q_UNUSED(id);
298 }
299 
308 {
309 }
310 
320 {
321 }
322 
344 {
345  Q_UNUSED(scriptId);
346 }
347 
372  const QScriptValue &returnValue)
373 {
374  Q_UNUSED(scriptId);
375  Q_UNUSED(returnValue);
376 }
377 
396  int lineNumber, int columnNumber)
397 {
398  Q_UNUSED(scriptId);
399  Q_UNUSED(lineNumber);
400  Q_UNUSED(columnNumber);
401 }
402 
422  const QScriptValue &exception,
423  bool hasHandler)
424 {
425  Q_UNUSED(scriptId);
426  Q_UNUSED(exception);
427  Q_UNUSED(hasHandler);
428 }
429 
441  const QScriptValue &exception)
442 {
443  Q_UNUSED(scriptId);
444  Q_UNUSED(exception);
445 }
446 
447 #if 0
448 
456 void QScriptEngineAgent::propertyChange(qint64 scriptId,
457  const QScriptValue &object,
458  const QString &propertyName,
459  PropertyChange change)
460 {
461  Q_UNUSED(scriptId);
462  Q_UNUSED(object);
463  Q_UNUSED(propertyName);
464  Q_UNUSED(change);
465 }
466 #endif
467 
476 {
477  Q_UNUSED(extension);
478  return false;
479 }
480 
500  const QVariant &argument)
501 {
502  Q_UNUSED(extension);
503  Q_UNUSED(argument);
504  return QVariant();
505 }
506 
511 {
512  Q_D(const QScriptEngineAgent);
513  return QScriptEnginePrivate::get(d->engine);
514 }
515 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
virtual void returnEvent(const JSC::DebuggerCallFrame &frame, intptr_t sourceID, int lineno)
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
virtual void scriptUnload(qint64 id)
This function is called when the engine has discarded the script identified by the given id...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QScriptEngine * engine() const
Returns the QScriptEngine that this agent is associated with.
static QScriptEnginePrivate * get(QScriptEngine *q)
QScopedPointer< QScriptEngineAgentPrivate > d_ptr
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
QList< QScriptEngineAgent * > ownedAgents
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScriptEngineAgent(QScriptEngine *engine)
Constructs a QScriptEngineAgent object for the given engine.
virtual void exceptionThrow(qint64 scriptId, const QScriptValue &exception, bool hasHandler)
This function is called when the given exception has occurred in the engine, in the script identified...
virtual ~QScriptEngineAgent()
Destroys this QScriptEngineAgent.
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void scriptLoad(qint64 id, const QString &program, const QString &fileName, int baseLineNumber)
This function is called when the engine has parsed a script and has associated it with the given id...
void setCurrentException(QScriptValue exception)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
JSC::ExecState * currentFrame
virtual void evaluateStop(const JSC::JSValue &returnValue, intptr_t sourceID)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual QVariant extension(Extension extension, const QVariant &argument=QVariant())
This virtual function can be reimplemented in a QScriptEngineAgent subclass to provide support for ex...
virtual void exceptionCatch(qint64 scriptId, const QScriptValue &exception)
This function is called when the given exception is about to be caught, in the script identified by s...
JSC::JSGlobalObject * originalGlobalObject() const
virtual void exceptionThrow(const JSC::DebuggerCallFrame &frame, intptr_t sourceID, bool hasHandler)
QHash< intptr_t, QScript::UStringSourceProviderWithFeedback * > loadedScripts
__int64 qint64
Definition: qglobal.h:942
virtual void functionExit(const JSC::JSValue &returnValue, intptr_t sourceID)
virtual bool supportsExtension(Extension extension) const
Returns true if the QScriptEngineAgent supports the given extension; otherwise, false is returned...
virtual void functionEntry(qint64 scriptId)
This function is called when a script function is called in the engine.
virtual void contextPop()
This function is called when the current script context is about to be popped.
QScriptEnginePrivate * engine
virtual void exceptionCatch(const JSC::DebuggerCallFrame &frame, intptr_t sourceID)
virtual void 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 ...
virtual void didReachBreakpoint(const JSC::DebuggerCallFrame &frame, intptr_t sourceID, int lineno)
virtual void contextPush()
This function is called when a new script context has been pushed.
JSC::JSGlobalData * globalData
QScriptValue scriptValueFromJSCValue(JSC::JSValue value)
ExecState CallFrame
Extension
This enum specifies the possible extensions to a QScriptEngineAgent.
void agentDeleted(QScriptEngineAgent *agent)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual void functionExit(qint64 scriptId, const QScriptValue &returnValue)
This function is called when the currently executing script function is about to return.
static QString fileName(const QString &fileUrl)
The QScriptEngineAgent class provides an interface to report events pertaining to QScriptEngine execu...
virtual void atStatement(const JSC::DebuggerCallFrame &, intptr_t sourceID, int lineno)
INT_PTR intptr_t