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_p_h
21 #define qscriptengine_p_h
23 #include "qscriptconverter_p.h"
24 #include "qscriptengine.h"
25 #include "qscriptvalue.h"
26 #include <JavaScriptCore/JavaScript.h>
27 #include <QtCore/qshareddata.h>
28 #include <QtCore/qstring.h>
32 class QScriptEnginePrivate
: public QSharedData
{
34 static QScriptEnginePtr
get(const QScriptEngine
* q
) { Q_ASSERT(q
); return q
->d_ptr
; }
35 static QScriptEngine
* get(const QScriptEnginePrivate
* d
) { Q_ASSERT(d
); return d
->q_ptr
; }
37 QScriptEnginePrivate(const QScriptEngine
*);
38 ~QScriptEnginePrivate();
40 QScriptValuePrivate
* evaluate(const QString
& program
, const QString
& fileName
, int lineNumber
);
41 inline void collectGarbage();
43 inline JSValueRef
makeJSValue(double number
) const;
44 inline JSValueRef
makeJSValue(int number
) const;
45 inline JSValueRef
makeJSValue(uint number
) const;
46 inline JSValueRef
makeJSValue(const QString
& string
) const;
47 inline JSValueRef
makeJSValue(bool number
) const;
48 inline JSValueRef
makeJSValue(QScriptValue::SpecialValue value
) const;
50 inline JSGlobalContextRef
context() const;
53 JSGlobalContextRef m_context
;
56 void QScriptEnginePrivate::collectGarbage()
58 JSGarbageCollect(m_context
);
61 JSValueRef
QScriptEnginePrivate::makeJSValue(double number
) const
63 return JSValueMakeNumber(m_context
, number
);
66 JSValueRef
QScriptEnginePrivate::makeJSValue(int number
) const
68 return JSValueMakeNumber(m_context
, number
);
71 JSValueRef
QScriptEnginePrivate::makeJSValue(uint number
) const
73 return JSValueMakeNumber(m_context
, number
);
76 JSValueRef
QScriptEnginePrivate::makeJSValue(const QString
& string
) const
78 return JSValueMakeString(m_context
, QScriptConverter::toString(string
));
81 JSValueRef
QScriptEnginePrivate::makeJSValue(bool value
) const
83 return JSValueMakeBoolean(m_context
, value
);
86 JSValueRef
QScriptEnginePrivate::makeJSValue(QScriptValue::SpecialValue value
) const
88 if (value
== QScriptValue::NullValue
)
89 return JSValueMakeNull(m_context
);
90 return JSValueMakeUndefined(m_context
);
93 JSGlobalContextRef
QScriptEnginePrivate::context() const