]>
git.saurik.com Git - apple/javascriptcore.git/blob - qt/api/qscriptprogram_p.h
2 Copyright (C) 2010 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 qscriptprogram_p_h
21 #define qscriptprogram_p_h
23 #include "qscriptconverter_p.h"
24 #include "qscriptprogram.h"
25 #include <JavaScriptCore/JavaScript.h>
26 #include <QtCore/qshareddata.h>
27 #include <QtCore/qstring.h>
30 FIXME The QScriptProgramPrivate potentially could be much faster. In current implementation we
31 gain CPU time only by avoiding QString -> JSStringRef conversion. In the ideal world we should
32 have a function inside the JSC C API that could provide us "parse once, execute multiple times"
36 class QScriptProgramPrivate
: public QSharedData
{
38 inline static QScriptProgramPrivate
* get(const QScriptProgram
& program
);
39 inline QScriptProgramPrivate();
40 inline QScriptProgramPrivate(const QString
& sourceCode
,
41 const QString fileName
,
44 inline ~QScriptProgramPrivate();
46 inline bool isNull() const;
48 inline QString
sourceCode() const;
49 inline QString
fileName() const;
50 inline int firstLineNumber() const;
52 inline bool operator==(const QScriptProgramPrivate
& other
) const;
53 inline bool operator!=(const QScriptProgramPrivate
& other
) const;
55 inline JSStringRef
program() const;
56 inline JSStringRef
file() const;
57 inline int line() const;
59 JSStringRef m_program
;
60 JSStringRef m_fileName
;
64 QScriptProgramPrivate
* QScriptProgramPrivate::get(const QScriptProgram
& program
)
66 return const_cast<QScriptProgramPrivate
*>(program
.d_ptr
.constData());
69 QScriptProgramPrivate::QScriptProgramPrivate()
75 QScriptProgramPrivate::QScriptProgramPrivate(const QString
& sourceCode
,
76 const QString fileName
,
78 : m_program(QScriptConverter::toString(sourceCode
))
79 , m_fileName(QScriptConverter::toString(fileName
))
80 , m_line(firstLineNumber
)
83 QScriptProgramPrivate::~QScriptProgramPrivate()
86 JSStringRelease(m_program
);
87 JSStringRelease(m_fileName
);
91 bool QScriptProgramPrivate::isNull() const
96 QString
QScriptProgramPrivate::sourceCode() const
98 return QScriptConverter::toString(m_program
);
101 QString
QScriptProgramPrivate::fileName() const
103 return QScriptConverter::toString(m_fileName
);
106 int QScriptProgramPrivate::firstLineNumber() const
111 bool QScriptProgramPrivate::operator==(const QScriptProgramPrivate
& other
) const
113 return m_line
== other
.m_line
114 && JSStringIsEqual(m_fileName
, other
.m_fileName
)
115 && JSStringIsEqual(m_program
, other
.m_program
);
118 bool QScriptProgramPrivate::operator!=(const QScriptProgramPrivate
& other
) const
120 return m_line
!= other
.m_line
121 || !JSStringIsEqual(m_fileName
, other
.m_fileName
)
122 || !JSStringIsEqual(m_program
, other
.m_program
);
125 JSStringRef
QScriptProgramPrivate::program() const { return m_program
; }
126 JSStringRef
QScriptProgramPrivate::file() const {return m_fileName
; }
127 int QScriptProgramPrivate::line() const { return m_line
; }
129 #endif // qscriptprogram_p_h