1/*
2    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3
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.
8
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.
13
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.
18*/
19
20#ifndef qscriptengine_h
21#define qscriptengine_h
22
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>
30
31class QDateTime;
32class QScriptEnginePrivate;
33
34// FIXME: Remove this once QScriptContext is properly defined.
35typedef void QScriptContext;
36
37// Internal typedef
38typedef QExplicitlySharedDataPointer<QScriptEnginePrivate> QScriptEnginePtr;
39
40class QScriptEngine : public QObject {
41public:
42    QScriptEngine();
43    ~QScriptEngine();
44
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);
48
49    bool hasUncaughtException() const;
50    QScriptValue uncaughtException() const;
51    void clearExceptions();
52    int uncaughtExceptionLineNumber() const;
53    QStringList uncaughtExceptionBacktrace() const;
54
55    void collectGarbage();
56    void reportAdditionalMemoryCost(int cost);
57
58    QScriptString toStringHandle(const QString& str);
59    QScriptValue toObject(const QScriptValue& value);
60
61    QScriptValue nullValue();
62    QScriptValue undefinedValue();
63
64    typedef QScriptValue (*FunctionSignature)(QScriptContext *, QScriptEngine *);
65    typedef QScriptValue (*FunctionWithArgSignature)(QScriptContext *, QScriptEngine *, void *);
66
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);
70
71    QScriptValue newObject();
72    QScriptValue newArray(uint length = 0);
73    QScriptValue newDate(qsreal value);
74    QScriptValue newDate(const QDateTime& value);
75    QScriptValue globalObject() const;
76private:
77    friend class QScriptEnginePrivate;
78
79    QScriptEnginePtr d_ptr;
80};
81
82#endif
83