summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-10-30 05:24:51 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-10-30 05:24:51 (GMT)
commit46eec6d54bad7a686b3dd5cd6e4aa8577d38740d (patch)
treee4c828d1d1456b3fafe74a339562263b3f2c156d /src/script
parentd85d7addc5084ee7d5de31dec562437f9c31c35d (diff)
parentd788c0127b86d8245aa0a8e2472562f444d98ee9 (diff)
downloadQt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.zip
Qt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.tar.gz
Qt-46eec6d54bad7a686b3dd5cd6e4aa8577d38740d.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts: src/declarative/qml/qmlcomponentjs.cpp src/declarative/qml/qmlcomponentjs_p.h src/declarative/qml/qmlcomponentjs_p_p.h
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/qscriptengine.cpp8
-rw-r--r--src/script/api/qscriptprogram.cpp36
-rw-r--r--src/script/api/qscriptprogram.h4
-rw-r--r--src/script/api/qscriptprogram_p.h4
4 files changed, 31 insertions, 21 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index f695a77..de759c6 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -1179,15 +1179,16 @@ JSC::JSValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, intptr_t
JSC::EvalExecutable *executable,
bool &compile)
{
+ Q_Q(QScriptEngine);
JSC::JSLock lock(false); // ### hmmm
QBoolBlocker inEvalBlocker(inEval, true);
- q_func()->currentContext()->activationObject(); //force the creation of a context for native function;
+ q->currentContext()->activationObject(); //force the creation of a context for native function;
JSC::Debugger* debugger = originalGlobalObject()->debugger();
if (debugger)
debugger->evaluateStart(sourceId);
- exec->clearException();
+ q->clearExceptions();
JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject());
if (compile) {
@@ -2215,6 +2216,9 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file
/*!
\internal
\since 4.6
+
+ Evaluates the given \a program and returns the result of the
+ evaluation.
*/
QScriptValue QScriptEngine::evaluate(const QScriptProgram &program)
{
diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp
index aff9817..c30f381 100644
--- a/src/script/api/qscriptprogram.cpp
+++ b/src/script/api/qscriptprogram.cpp
@@ -39,12 +39,7 @@
**
****************************************************************************/
-#include <QtCore/qglobal.h>
-#ifdef Q_WS_WIN
-#define max max
-#define min min
-#endif
-
+#include "config.h"
#include "qscriptprogram.h"
#include "qscriptprogram_p.h"
#include "qscriptengine.h"
@@ -60,14 +55,25 @@ QT_BEGIN_NAMESPACE
\since 4.6
\class QScriptProgram
+ \brief The QScriptProgram class encapsulates a Qt Script program.
+
\ingroup script
+ QScriptProgram retains the compiled representation of the script if
+ possible. Thus, QScriptProgram can be used to evaluate the same
+ script multiple times more efficiently.
+
+ \code
+ QScriptEngine engine;
+ QScriptProgram program("1 + 2");
+ QScriptValue result = engine.evaluate(program);
+ \endcode
*/
QScriptProgramPrivate::QScriptProgramPrivate(const QString &src,
const QString &fn,
int ln)
- : sourceCode(src), fileName(fn), lineNumber(ln),
+ : sourceCode(src), fileName(fn), firstLineNumber(ln),
engine(0), _executable(0), sourceId(-1), isCompiled(false)
{
ref = 0;
@@ -92,9 +98,9 @@ JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec,
delete _executable;
}
WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider
- = QScript::UStringSourceProviderWithFeedback::create(sourceCode, fileName, lineNumber, eng);
+ = QScript::UStringSourceProviderWithFeedback::create(sourceCode, fileName, firstLineNumber, eng);
sourceId = provider->asID();
- JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null.
+ JSC::SourceCode source(provider, firstLineNumber); //after construction of SourceCode provider variable will be null.
_executable = new JSC::EvalExecutable(exec, source);
engine = eng;
isCompiled = false;
@@ -111,12 +117,12 @@ QScriptProgram::QScriptProgram()
/*!
Constructs a new QScriptProgram with the given \a sourceCode, \a
- fileName and \a lineNumber.
+ fileName and \a firstLineNumber.
*/
QScriptProgram::QScriptProgram(const QString &sourceCode,
const QString fileName,
- int lineNumber)
- : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, lineNumber))
+ int firstLineNumber)
+ : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, firstLineNumber))
{
}
@@ -185,12 +191,12 @@ QString QScriptProgram::fileName() const
/*!
Returns the line number associated with this program.
*/
-int QScriptProgram::lineNumber() const
+int QScriptProgram::firstLineNumber() const
{
Q_D(const QScriptProgram);
if (!d)
return -1;
- return d->lineNumber;
+ return d->firstLineNumber;
}
/*!
@@ -204,7 +210,7 @@ bool QScriptProgram::operator==(const QScriptProgram &other) const
return true;
return (sourceCode() == other.sourceCode())
&& (fileName() == other.fileName())
- && (lineNumber() == other.lineNumber());
+ && (firstLineNumber() == other.firstLineNumber());
}
/*!
diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h
index 6ab56dc..de891cd 100644
--- a/src/script/api/qscriptprogram.h
+++ b/src/script/api/qscriptprogram.h
@@ -59,7 +59,7 @@ public:
QScriptProgram();
QScriptProgram(const QString &sourceCode,
const QString fileName = QString(),
- int lineNumber = 1);
+ int firstLineNumber = 1);
QScriptProgram(const QScriptProgram &other);
~QScriptProgram();
@@ -69,7 +69,7 @@ public:
QString sourceCode() const;
QString fileName() const;
- int lineNumber() const;
+ int firstLineNumber() const;
bool operator==(const QScriptProgram &other) const;
bool operator!=(const QScriptProgram &other) const;
diff --git a/src/script/api/qscriptprogram_p.h b/src/script/api/qscriptprogram_p.h
index 861ef32..5175079 100644
--- a/src/script/api/qscriptprogram_p.h
+++ b/src/script/api/qscriptprogram_p.h
@@ -70,7 +70,7 @@ class QScriptProgramPrivate
public:
QScriptProgramPrivate(const QString &sourceCode,
const QString &fileName,
- int lineNumber);
+ int firstLineNumber);
~QScriptProgramPrivate();
static QScriptProgramPrivate *get(const QScriptProgram &q);
@@ -82,7 +82,7 @@ public:
QString sourceCode;
QString fileName;
- int lineNumber;
+ int firstLineNumber;
QScriptEnginePrivate *engine;
JSC::EvalExecutable *_executable;