Qt 4.8
qscriptprogram.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #include "config.h"
25 #include "qscriptprogram.h"
26 #include "qscriptprogram_p.h"
27 #include "qscriptengine.h"
28 #include "qscriptengine_p.h"
29 
30 #include "SamplingTool.h"
31 #include "Executable.h"
32 
34 
58  const QString &fn,
59  int ln)
60  : sourceCode(src), fileName(fn), firstLineNumber(ln),
61  engine(0), _executable(0), sourceId(-1), isCompiled(false)
62 {
63  ref = 0;
64 }
65 
67 {
68  if (engine) {
70  _executable.clear();
72  }
73 }
74 
76 {
77  return const_cast<QScriptProgramPrivate*>(q.d_func());
78 }
79 
80 JSC::EvalExecutable *QScriptProgramPrivate::executable(JSC::ExecState *exec,
82 {
83  if (_executable) {
84  if (eng == engine)
85  return _executable.get();
86  // "Migrating" to another engine; clean up old state
88  _executable.clear();
90  }
91  WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider
93  sourceId = provider->asID();
94  JSC::SourceCode source(provider, firstLineNumber); //after construction of SourceCode provider variable will be null.
96  engine = eng;
98  isCompiled = false;
99  return _executable.get();
100 }
101 
103 {
104  _executable.clear();
105  sourceId = -1;
106  isCompiled = false;
107  engine = 0;
108 }
109 
114  : d_ptr(0)
115 {
116 }
117 
123  const QString fileName,
124  int firstLineNumber)
125  : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, firstLineNumber))
126 {
127 }
128 
133  : d_ptr(other.d_ptr)
134 {
135 }
136 
141 {
142 }
143 
148 {
149  d_ptr = other.d_ptr;
150  return *this;
151 }
152 
158 {
159  Q_D(const QScriptProgram);
160  return (d == 0);
161 }
162 
167 {
168  Q_D(const QScriptProgram);
169  if (!d)
170  return QString();
171  return d->sourceCode;
172 }
173 
178 {
179  Q_D(const QScriptProgram);
180  if (!d)
181  return QString();
182  return d->fileName;
183 }
184 
189 {
190  Q_D(const QScriptProgram);
191  if (!d)
192  return -1;
193  return d->firstLineNumber;
194 }
195 
201 {
202  Q_D(const QScriptProgram);
203  if (d == other.d_func())
204  return true;
205  return (sourceCode() == other.sourceCode())
206  && (fileName() == other.fileName())
207  && (firstLineNumber() == other.firstLineNumber());
208 }
209 
215 {
216  return !operator==(other);
217 }
218 
double d
Definition: qnumeric_p.h:62
QExplicitlySharedDataPointer< QScriptProgramPrivate > d_ptr
bool operator==(const QScriptProgram &other) const
Returns true if this QScriptProgram is equal to other; otherwise returns false.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
WTF::RefPtr< JSC::EvalExecutable > _executable
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
~QScriptProgram()
Destroys this QScriptProgram.
JSC::EvalExecutable * executable(JSC::ExecState *exec, QScriptEnginePrivate *engine)
static PassRefPtr< UStringSourceProviderWithFeedback > create(const JSC::UString &source, const JSC::UString &url, int lineNumber, QScriptEnginePrivate *engine)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QString sourceCode() const
Returns the source code of this program.
bool isNull() const
Returns true if this QScriptProgram is null; otherwise returns false.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void registerScriptProgram(QScriptProgramPrivate *program)
void unregisterScriptProgram(QScriptProgramPrivate *program)
bool operator!=(const QScriptProgram &other) const
Returns true if this QScriptProgram is not equal to other; otherwise returns false.
QScriptEnginePrivate * engine
QString fileName() const
Returns the filename associated with this program.
The QScriptProgram class encapsulates a Qt Script program.
QScriptProgram()
Constructs a null QScriptProgram.
int firstLineNumber() const
Returns the line number associated with this program.
static QScriptProgramPrivate * get(const QScriptProgram &q)
QScriptProgram & operator=(const QScriptProgram &other)
Assigns the other value to this QScriptProgram.
static QString fileName(const QString &fileUrl)
QScriptProgramPrivate(const QString &sourceCode, const QString &fileName, int firstLineNumber)