2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef qscriptengine_h
21 #define qscriptengine_h
23 #include "qscriptprogram.h"
24 #include "qscriptstring.h"
25 #include "qscriptsyntaxcheckresult.h"
26 #include "qscriptvalue.h"
27 #include <QtCore/qobject.h>
28 #include <QtCore/qshareddata.h>
29 #include <QtCore/qstring.h>
32 class QScriptEnginePrivate
;
34 // FIXME: Remove this once QScriptContext is properly defined.
35 typedef void QScriptContext
;
38 typedef QExplicitlySharedDataPointer
<QScriptEnginePrivate
> QScriptEnginePtr
;
40 class QScriptEngine
: public QObject
{
45 static QScriptSyntaxCheckResult
checkSyntax(const QString
& program
);
46 QScriptValue
evaluate(const QString
& program
, const QString
& fileName
= QString(), int lineNumber
= 1);
47 QScriptValue
evaluate(const QScriptProgram
& program
);
49 bool hasUncaughtException() const;
50 QScriptValue
uncaughtException() const;
51 void clearExceptions();
52 int uncaughtExceptionLineNumber() const;
53 QStringList
uncaughtExceptionBacktrace() const;
55 void collectGarbage();
56 void reportAdditionalMemoryCost(int cost
);
58 QScriptString
toStringHandle(const QString
& str
);
59 QScriptValue
toObject(const QScriptValue
& value
);
61 QScriptValue
nullValue();
62 QScriptValue
undefinedValue();
64 typedef QScriptValue (*FunctionSignature
)(QScriptContext
*, QScriptEngine
*);
65 typedef QScriptValue (*FunctionWithArgSignature
)(QScriptContext
*, QScriptEngine
*, void *);
67 QScriptValue
newFunction(FunctionSignature fun
, int length
= 0);
68 QScriptValue
newFunction(FunctionSignature fun
, const QScriptValue
& prototype
, int length
= 0);
69 QScriptValue
newFunction(FunctionWithArgSignature fun
, void* arg
);
71 QScriptValue
newObject();
72 QScriptValue
newArray(uint length
= 0);
73 QScriptValue
newDate(qsreal value
);
74 QScriptValue
newDate(const QDateTime
& value
);
75 QScriptValue
globalObject() const;
77 friend class QScriptEnginePrivate
;
79 QScriptEnginePtr d_ptr
;