]> git.saurik.com Git - apple/javascriptcore.git/blob - qt/api/qscriptengine_p.h
JavaScriptCore-576.tar.gz
[apple/javascriptcore.git] / qt / api / qscriptengine_p.h
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_p_h
21 #define qscriptengine_p_h
22
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>
29
30 class QScriptEngine;
31
32 class QScriptEnginePrivate : public QSharedData {
33 public:
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; }
36
37 QScriptEnginePrivate(const QScriptEngine*);
38 ~QScriptEnginePrivate();
39
40 QScriptValuePrivate* evaluate(const QString& program, const QString& fileName, int lineNumber);
41 inline void collectGarbage();
42
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;
49
50 inline JSGlobalContextRef context() const;
51 private:
52 QScriptEngine* q_ptr;
53 JSGlobalContextRef m_context;
54 };
55
56 void QScriptEnginePrivate::collectGarbage()
57 {
58 JSGarbageCollect(m_context);
59 }
60
61 JSValueRef QScriptEnginePrivate::makeJSValue(double number) const
62 {
63 return JSValueMakeNumber(m_context, number);
64 }
65
66 JSValueRef QScriptEnginePrivate::makeJSValue(int number) const
67 {
68 return JSValueMakeNumber(m_context, number);
69 }
70
71 JSValueRef QScriptEnginePrivate::makeJSValue(uint number) const
72 {
73 return JSValueMakeNumber(m_context, number);
74 }
75
76 JSValueRef QScriptEnginePrivate::makeJSValue(const QString& string) const
77 {
78 return JSValueMakeString(m_context, QScriptConverter::toString(string));
79 }
80
81 JSValueRef QScriptEnginePrivate::makeJSValue(bool value) const
82 {
83 return JSValueMakeBoolean(m_context, value);
84 }
85
86 JSValueRef QScriptEnginePrivate::makeJSValue(QScriptValue::SpecialValue value) const
87 {
88 if (value == QScriptValue::NullValue)
89 return JSValueMakeNull(m_context);
90 return JSValueMakeUndefined(m_context);
91 }
92
93 JSGlobalContextRef QScriptEnginePrivate::context() const
94 {
95 return m_context;
96 }
97
98 #endif