author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 22 | 79de32ba3296 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtScript module of the Qt Toolkit. |
|
8 |
** |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:LGPL-ONLY$ |
0 | 10 |
** GNU Lesser General Public License Usage |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
11 |
** This file may be used under the terms of the GNU Lesser |
0 | 12 |
** General Public License version 2.1 as published by the Free Software |
13 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
14 |
** packaging of this file. Please review the following information to |
|
15 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
16 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
17 |
** |
|
18 |
** If you have questions regarding the use of this file, please contact |
|
19 |
** Nokia at qt-info@nokia.com. |
|
20 |
** $QT_END_LICENSE$ |
|
21 |
** |
|
22 |
****************************************************************************/ |
|
23 |
||
24 |
#include "config.h" |
|
25 |
#include "qscriptengine.h" |
|
26 |
#include "qscriptsyntaxchecker_p.h" |
|
27 |
||
28 |
#include "qscriptengine_p.h" |
|
29 |
#include "qscriptengineagent_p.h" |
|
30 |
#include "qscriptcontext_p.h" |
|
31 |
#include "qscriptstring_p.h" |
|
32 |
#include "qscriptvalue_p.h" |
|
33 |
#include "qscriptvalueiterator.h" |
|
34 |
#include "qscriptclass.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
35 |
#include "qscriptcontextinfo.h" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
#include "qscriptprogram.h" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
37 |
#include "qscriptprogram_p.h" |
0 | 38 |
#include "qdebug.h" |
39 |
||
40 |
#include <QtCore/qstringlist.h> |
|
41 |
#include <QtCore/qmetaobject.h> |
|
42 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
43 |
#include <math.h> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
44 |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
45 |
#include "CodeBlock.h" |
0 | 46 |
#include "Error.h" |
47 |
#include "JSLock.h" |
|
48 |
#include "Interpreter.h" |
|
49 |
||
50 |
#include "PrototypeFunction.h" |
|
51 |
#include "InitializeThreading.h" |
|
52 |
#include "ObjectPrototype.h" |
|
53 |
#include "SourceCode.h" |
|
54 |
#include "FunctionPrototype.h" |
|
55 |
#include "TimeoutChecker.h" |
|
56 |
#include "JSFunction.h" |
|
57 |
#include "Parser.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
58 |
#include "PropertyNameArray.h" |
0 | 59 |
#include "Operations.h" |
60 |
||
61 |
#include "bridge/qscriptfunction_p.h" |
|
62 |
#include "bridge/qscriptclassobject_p.h" |
|
63 |
#include "bridge/qscriptvariant_p.h" |
|
64 |
#include "bridge/qscriptqobject_p.h" |
|
65 |
#include "bridge/qscriptglobalobject_p.h" |
|
66 |
#include "bridge/qscriptactivationobject_p.h" |
|
67 |
||
68 |
#ifndef QT_NO_QOBJECT |
|
69 |
#include <QtCore/qcoreapplication.h> |
|
70 |
#include <QtCore/qdir.h> |
|
71 |
#include <QtCore/qfile.h> |
|
72 |
#include <QtCore/qfileinfo.h> |
|
73 |
#include <QtCore/qpluginloader.h> |
|
74 |
#include <QtCore/qset.h> |
|
75 |
#include <QtCore/qtextstream.h> |
|
76 |
#include "qscriptextensioninterface.h" |
|
77 |
#endif |
|
78 |
||
79 |
Q_DECLARE_METATYPE(QScriptValue) |
|
80 |
#ifndef QT_NO_QOBJECT |
|
81 |
Q_DECLARE_METATYPE(QObjectList) |
|
82 |
#endif |
|
83 |
Q_DECLARE_METATYPE(QList<int>) |
|
84 |
||
85 |
QT_BEGIN_NAMESPACE |
|
86 |
||
87 |
/*! |
|
88 |
\since 4.3 |
|
89 |
\class QScriptEngine |
|
90 |
\reentrant |
|
91 |
||
92 |
\brief The QScriptEngine class provides an environment for evaluating Qt Script code. |
|
93 |
||
94 |
\ingroup script |
|
95 |
\mainclass |
|
96 |
||
97 |
See the \l{QtScript} documentation for information about the Qt Script language, |
|
98 |
and how to get started with scripting your C++ application. |
|
99 |
||
100 |
\section1 Evaluating Scripts |
|
101 |
||
102 |
Use evaluate() to evaluate script code; this is the C++ equivalent |
|
103 |
of the built-in script function \c{eval()}. |
|
104 |
||
105 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 0 |
|
106 |
||
107 |
evaluate() returns a QScriptValue that holds the result of the |
|
108 |
evaluation. The QScriptValue class provides functions for converting |
|
109 |
the result to various C++ types (e.g. QScriptValue::toString() |
|
110 |
and QScriptValue::toNumber()). |
|
111 |
||
112 |
The following code snippet shows how a script function can be |
|
113 |
defined and then invoked from C++ using QScriptValue::call(): |
|
114 |
||
115 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 1 |
|
116 |
||
117 |
As can be seen from the above snippets, a script is provided to the |
|
118 |
engine in the form of a string. One common way of loading scripts is |
|
119 |
by reading the contents of a file and passing it to evaluate(): |
|
120 |
||
121 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 2 |
|
122 |
||
123 |
Here we pass the name of the file as the second argument to |
|
124 |
evaluate(). This does not affect evaluation in any way; the second |
|
125 |
argument is a general-purpose string that is used to identify the |
|
126 |
script for debugging purposes (for example, our filename will now |
|
127 |
show up in any uncaughtExceptionBacktrace() involving the script). |
|
128 |
||
129 |
\section1 Engine Configuration |
|
130 |
||
131 |
The globalObject() function returns the \bold {Global Object} |
|
132 |
associated with the script engine. Properties of the Global Object |
|
133 |
are accessible from any script code (i.e. they are global |
|
134 |
variables). Typically, before evaluating "user" scripts, you will |
|
135 |
want to configure a script engine by adding one or more properties |
|
136 |
to the Global Object: |
|
137 |
||
138 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 3 |
|
139 |
||
140 |
Adding custom properties to the scripting environment is one of the |
|
141 |
standard means of providing a scripting API that is specific to your |
|
142 |
application. Usually these custom properties are objects created by |
|
143 |
the newQObject() or newObject() functions, or constructor functions |
|
144 |
created by newFunction(). |
|
145 |
||
146 |
\section1 Script Exceptions |
|
147 |
||
148 |
evaluate() can throw a script exception (e.g. due to a syntax |
|
149 |
error); in that case, the return value is the value that was thrown |
|
150 |
(typically an \c{Error} object). You can check whether the |
|
151 |
evaluation caused an exception by calling hasUncaughtException(). In |
|
152 |
that case, you can call toString() on the error object to obtain an |
|
153 |
error message. The current uncaught exception is also available |
|
154 |
through uncaughtException(). You can obtain a human-readable |
|
155 |
backtrace of the exception with uncaughtExceptionBacktrace(). |
|
156 |
Calling clearExceptions() will cause any uncaught exceptions to be |
|
157 |
cleared. |
|
158 |
||
159 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 4 |
|
160 |
||
161 |
The checkSyntax() function can be used to determine whether code can be |
|
162 |
usefully passed to evaluate(). |
|
163 |
||
164 |
\section1 Script Object Creation |
|
165 |
||
166 |
Use newObject() to create a standard Qt Script object; this is the |
|
167 |
C++ equivalent of the script statement \c{new Object()}. You can use |
|
168 |
the object-specific functionality in QScriptValue to manipulate the |
|
169 |
script object (e.g. QScriptValue::setProperty()). Similarly, use |
|
170 |
newArray() to create a Qt Script array object. Use newDate() to |
|
171 |
create a \c{Date} object, and newRegExp() to create a \c{RegExp} |
|
172 |
object. |
|
173 |
||
174 |
\section1 QObject Integration |
|
175 |
||
176 |
Use newQObject() to wrap a QObject (or subclass) |
|
177 |
pointer. newQObject() returns a proxy script object; properties, |
|
178 |
children, and signals and slots of the QObject are available as |
|
179 |
properties of the proxy object. No binding code is needed because it |
|
180 |
is done dynamically using the Qt meta object system. |
|
181 |
||
182 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 5 |
|
183 |
||
184 |
Use qScriptConnect() to connect a C++ signal to a script function; |
|
185 |
this is the Qt Script equivalent of QObject::connect(). When a |
|
186 |
script function is invoked in response to a C++ signal, it can cause |
|
187 |
a script exception; you can connect to the signalHandlerException() |
|
188 |
signal to catch such an exception. |
|
189 |
||
190 |
Use newQMetaObject() to wrap a QMetaObject; this gives you a "script |
|
191 |
representation" of a QObject-based class. newQMetaObject() returns a |
|
192 |
proxy script object; enum values of the class are available as |
|
193 |
properties of the proxy object. You can also specify a function that |
|
194 |
will be used to construct objects of the class (e.g. when the |
|
195 |
constructor is invoked from a script). For classes that have a |
|
196 |
"standard" Qt constructor, Qt Script can provide a default script |
|
197 |
constructor for you; see scriptValueFromQMetaObject(). |
|
198 |
||
199 |
See the \l{QtScript} documentation for more information on |
|
200 |
the QObject integration. |
|
201 |
||
202 |
\section1 Support for Custom C++ Types |
|
203 |
||
204 |
Use newVariant() to wrap a QVariant. This can be used to store |
|
205 |
values of custom (non-QObject) C++ types that have been registered |
|
206 |
with the Qt meta-type system. To make such types scriptable, you |
|
207 |
typically associate a prototype (delegate) object with the C++ type |
|
208 |
by calling setDefaultPrototype(); the prototype object defines the |
|
209 |
scripting API for the C++ type. Unlike the QObject integration, |
|
210 |
there is no automatic binding possible here; i.e. you have to create |
|
211 |
the scripting API yourself, for example by using the QScriptable |
|
212 |
class. |
|
213 |
||
214 |
Use fromScriptValue() to cast from a QScriptValue to another type, |
|
215 |
and toScriptValue() to create a QScriptValue from another value. |
|
216 |
You can specify how the conversion of C++ types is to be performed |
|
217 |
with qScriptRegisterMetaType() and qScriptRegisterSequenceMetaType(). |
|
218 |
By default, Qt Script will use QVariant to store values of custom |
|
219 |
types. |
|
220 |
||
221 |
\section1 Importing Extensions |
|
222 |
||
223 |
Use importExtension() to import plugin-based extensions into the |
|
224 |
engine. Call availableExtensions() to obtain a list naming all the |
|
225 |
available extensions, and importedExtensions() to obtain a list |
|
226 |
naming only those extensions that have been imported. |
|
227 |
||
228 |
Call pushContext() to open up a new variable scope, and popContext() |
|
229 |
to close the current scope. This is useful if you are implementing |
|
230 |
an extension that evaluates script code containing temporary |
|
231 |
variable definitions (e.g. \c{var foo = 123;}) that are safe to |
|
232 |
discard when evaluation has completed. |
|
233 |
||
234 |
\section1 Native Functions |
|
235 |
||
236 |
Use newFunction() to wrap native (C++) functions, including |
|
237 |
constructors for your own custom types, so that these can be invoked |
|
238 |
from script code. Such functions must have the signature |
|
239 |
QScriptEngine::FunctionSignature. You may then pass the function as |
|
240 |
argument to newFunction(). Here is an example of a function that |
|
241 |
returns the sum of its first two arguments: |
|
242 |
||
243 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 6 |
|
244 |
||
245 |
To expose this function to script code, you can set it as a property |
|
246 |
of the Global Object: |
|
247 |
||
248 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 7 |
|
249 |
||
250 |
Once this is done, script code can call your function in the exact |
|
251 |
same manner as a "normal" script function: |
|
252 |
||
253 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 8 |
|
254 |
||
255 |
\section1 Long-running Scripts |
|
256 |
||
257 |
If you need to evaluate possibly long-running scripts from the main |
|
258 |
(GUI) thread, you should first call setProcessEventsInterval() to |
|
259 |
make sure that the GUI stays responsive. You can abort a currently |
|
260 |
running script by calling abortEvaluation(). You can determine |
|
261 |
whether an engine is currently running a script by calling |
|
262 |
isEvaluating(). |
|
263 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
264 |
\section1 Garbage Collection |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
265 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
266 |
Qt Script objects may be garbage collected when they are no longer |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
267 |
referenced. There is no guarantee as to when automatic garbage |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
268 |
collection will take place. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
269 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
270 |
The collectGarbage() function can be called to explicitly request |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
271 |
garbage collection. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
272 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
273 |
The reportAdditionalMemoryCost() function can be called to indicate |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
274 |
that a Qt Script object occupies memory that isn't managed by the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
275 |
scripting environment. Reporting the additional cost makes it more |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
276 |
likely that the garbage collector will be triggered. This can be |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
277 |
useful, for example, when many custom, native Qt Script objects are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
278 |
allocated. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
279 |
|
0 | 280 |
\section1 Core Debugging/Tracing Facilities |
281 |
||
282 |
Since Qt 4.4, you can be notified of events pertaining to script |
|
283 |
execution (e.g. script function calls and statement execution) |
|
284 |
through the QScriptEngineAgent interface; see the setAgent() |
|
285 |
function. This can be used to implement debugging and profiling of a |
|
286 |
QScriptEngine. |
|
287 |
||
288 |
\sa QScriptValue, QScriptContext, QScriptEngineAgent |
|
289 |
||
290 |
*/ |
|
291 |
||
292 |
/*! |
|
293 |
\enum QScriptEngine::ValueOwnership |
|
294 |
||
295 |
This enum specifies the ownership when wrapping a C++ value, e.g. by using newQObject(). |
|
296 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
297 |
\value QtOwnership The standard Qt ownership rules apply, i.e. the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
298 |
associated object will never be explicitly deleted by the script |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
299 |
engine. This is the default. (QObject ownership is explained in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
300 |
\l{Object Trees & Ownership}.) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
301 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
302 |
\value ScriptOwnership The value is owned by the script |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
303 |
environment. The associated data will be deleted when appropriate |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
304 |
(i.e. after the garbage collector has discovered that there are no |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
305 |
more live references to the value). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
306 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
307 |
\value AutoOwnership If the associated object has a parent, the Qt |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
308 |
ownership rules apply (QtOwnership); otherwise, the object is |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
309 |
owned by the script environment (ScriptOwnership). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
310 |
|
0 | 311 |
*/ |
312 |
||
313 |
/*! |
|
314 |
\enum QScriptEngine::QObjectWrapOption |
|
315 |
||
316 |
These flags specify options when wrapping a QObject pointer with newQObject(). |
|
317 |
||
318 |
\value ExcludeChildObjects The script object will not expose child objects as properties. |
|
319 |
\value ExcludeSuperClassMethods The script object will not expose signals and slots inherited from the superclass. |
|
320 |
\value ExcludeSuperClassProperties The script object will not expose properties inherited from the superclass. |
|
321 |
\value ExcludeSuperClassContents Shorthand form for ExcludeSuperClassMethods | ExcludeSuperClassProperties |
|
322 |
\value ExcludeDeleteLater The script object will not expose the QObject::deleteLater() slot. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
323 |
\value ExcludeSlots The script object will not expose the QObject's slots. |
0 | 324 |
\value AutoCreateDynamicProperties Properties that don't already exist in the QObject will be created as dynamic properties of that object, rather than as properties of the script object. |
325 |
\value PreferExistingWrapperObject If a wrapper object with the requested configuration already exists, return that object. |
|
326 |
\value SkipMethodsInEnumeration Don't include methods (signals and slots) when enumerating the object's properties. |
|
327 |
*/ |
|
328 |
||
329 |
class QScriptSyntaxCheckResultPrivate |
|
330 |
{ |
|
331 |
public: |
|
332 |
QScriptSyntaxCheckResultPrivate() { ref = 0; } |
|
333 |
~QScriptSyntaxCheckResultPrivate() {} |
|
334 |
||
335 |
QScriptSyntaxCheckResult::State state; |
|
336 |
int errorColumnNumber; |
|
337 |
int errorLineNumber; |
|
338 |
QString errorMessage; |
|
339 |
QBasicAtomicInt ref; |
|
340 |
}; |
|
341 |
||
342 |
class QScriptTypeInfo |
|
343 |
{ |
|
344 |
public: |
|
345 |
QScriptTypeInfo() : signature(0, '\0'), marshal(0), demarshal(0) |
|
346 |
{ } |
|
347 |
||
348 |
QByteArray signature; |
|
349 |
QScriptEngine::MarshalFunction marshal; |
|
350 |
QScriptEngine::DemarshalFunction demarshal; |
|
351 |
JSC::JSValue prototype; |
|
352 |
}; |
|
353 |
||
354 |
namespace QScript |
|
355 |
{ |
|
356 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
357 |
static const qsreal D32 = 4294967296.0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
358 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
359 |
qint32 ToInt32(qsreal n) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
360 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
361 |
if (qIsNaN(n) || qIsInf(n) || (n == 0)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
362 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
363 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
364 |
qsreal sign = (n < 0) ? -1.0 : 1.0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
365 |
qsreal abs_n = fabs(n); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
366 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
367 |
n = ::fmod(sign * ::floor(abs_n), D32); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
368 |
const double D31 = D32 / 2.0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
369 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
370 |
if (sign == -1 && n < -D31) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
371 |
n += D32; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
372 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
373 |
else if (sign != -1 && n >= D31) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
374 |
n -= D32; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
375 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
376 |
return qint32 (n); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
377 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
378 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
379 |
quint32 ToUInt32(qsreal n) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
380 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
381 |
if (qIsNaN(n) || qIsInf(n) || (n == 0)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
382 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
383 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
384 |
qsreal sign = (n < 0) ? -1.0 : 1.0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
385 |
qsreal abs_n = fabs(n); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
386 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
387 |
n = ::fmod(sign * ::floor(abs_n), D32); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
388 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
389 |
if (n < 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
390 |
n += D32; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
391 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
392 |
return quint32 (n); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
393 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
394 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
395 |
quint16 ToUInt16(qsreal n) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
396 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
397 |
static const qsreal D16 = 65536.0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
398 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
399 |
if (qIsNaN(n) || qIsInf(n) || (n == 0)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
400 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
401 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
402 |
qsreal sign = (n < 0) ? -1.0 : 1.0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
403 |
qsreal abs_n = fabs(n); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
404 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
405 |
n = ::fmod(sign * ::floor(abs_n), D16); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
406 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
407 |
if (n < 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
408 |
n += D16; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
409 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
410 |
return quint16 (n); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
411 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
412 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
413 |
qsreal ToInteger(qsreal n) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
414 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
415 |
if (qIsNaN(n)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
416 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
417 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
418 |
if (n == 0 || qIsInf(n)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
419 |
return n; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
420 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
421 |
int sign = n < 0 ? -1 : 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
422 |
return sign * ::floor(::fabs(n)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
423 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
424 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
425 |
#ifdef Q_CC_MSVC |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
426 |
// MSVC2008 crashes if these are inlined. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
427 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
428 |
QString ToString(qsreal value) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
429 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
430 |
return JSC::UString::from(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
431 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
432 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
433 |
qsreal ToNumber(const QString &value) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
434 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
435 |
return ((JSC::UString)value).toDouble(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
436 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
437 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
438 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
439 |
|
0 | 440 |
void GlobalClientData::mark(JSC::MarkStack& markStack) |
441 |
{ |
|
442 |
engine->mark(markStack); |
|
443 |
} |
|
444 |
||
445 |
class TimeoutCheckerProxy : public JSC::TimeoutChecker |
|
446 |
{ |
|
447 |
public: |
|
448 |
TimeoutCheckerProxy(const JSC::TimeoutChecker& originalChecker) |
|
449 |
: JSC::TimeoutChecker(originalChecker) |
|
450 |
, m_shouldProcessEvents(false) |
|
451 |
, m_shouldAbortEvaluation(false) |
|
452 |
{} |
|
453 |
||
454 |
void setShouldProcessEvents(bool shouldProcess) { m_shouldProcessEvents = shouldProcess; } |
|
455 |
void setShouldAbort(bool shouldAbort) { m_shouldAbortEvaluation = shouldAbort; } |
|
456 |
bool shouldAbort() { return m_shouldAbortEvaluation; } |
|
457 |
||
458 |
virtual bool didTimeOut(JSC::ExecState* exec) |
|
459 |
{ |
|
460 |
if (JSC::TimeoutChecker::didTimeOut(exec)) |
|
461 |
return true; |
|
462 |
||
463 |
if (m_shouldProcessEvents) |
|
464 |
QCoreApplication::processEvents(); |
|
465 |
||
466 |
return m_shouldAbortEvaluation; |
|
467 |
} |
|
468 |
||
469 |
private: |
|
470 |
bool m_shouldProcessEvents; |
|
471 |
bool m_shouldAbortEvaluation; |
|
472 |
}; |
|
473 |
||
474 |
static int toDigit(char c) |
|
475 |
{ |
|
476 |
if ((c >= '0') && (c <= '9')) |
|
477 |
return c - '0'; |
|
478 |
else if ((c >= 'a') && (c <= 'z')) |
|
479 |
return 10 + c - 'a'; |
|
480 |
else if ((c >= 'A') && (c <= 'Z')) |
|
481 |
return 10 + c - 'A'; |
|
482 |
return -1; |
|
483 |
} |
|
484 |
||
485 |
qsreal integerFromString(const char *buf, int size, int radix) |
|
486 |
{ |
|
487 |
if (size == 0) |
|
488 |
return qSNaN(); |
|
489 |
||
490 |
qsreal sign = 1.0; |
|
491 |
int i = 0; |
|
492 |
if (buf[0] == '+') { |
|
493 |
++i; |
|
494 |
} else if (buf[0] == '-') { |
|
495 |
sign = -1.0; |
|
496 |
++i; |
|
497 |
} |
|
498 |
||
499 |
if (((size-i) >= 2) && (buf[i] == '0')) { |
|
500 |
if (((buf[i+1] == 'x') || (buf[i+1] == 'X')) |
|
501 |
&& (radix < 34)) { |
|
502 |
if ((radix != 0) && (radix != 16)) |
|
503 |
return 0; |
|
504 |
radix = 16; |
|
505 |
i += 2; |
|
506 |
} else { |
|
507 |
if (radix == 0) { |
|
508 |
radix = 8; |
|
509 |
++i; |
|
510 |
} |
|
511 |
} |
|
512 |
} else if (radix == 0) { |
|
513 |
radix = 10; |
|
514 |
} |
|
515 |
||
516 |
int j = i; |
|
517 |
for ( ; i < size; ++i) { |
|
518 |
int d = toDigit(buf[i]); |
|
519 |
if ((d == -1) || (d >= radix)) |
|
520 |
break; |
|
521 |
} |
|
522 |
qsreal result; |
|
523 |
if (j == i) { |
|
524 |
if (!qstrcmp(buf, "Infinity")) |
|
525 |
result = qInf(); |
|
526 |
else |
|
527 |
result = qSNaN(); |
|
528 |
} else { |
|
529 |
result = 0; |
|
530 |
qsreal multiplier = 1; |
|
531 |
for (--i ; i >= j; --i, multiplier *= radix) |
|
532 |
result += toDigit(buf[i]) * multiplier; |
|
533 |
} |
|
534 |
result *= sign; |
|
535 |
return result; |
|
536 |
} |
|
537 |
||
538 |
qsreal integerFromString(const QString &str, int radix) |
|
539 |
{ |
|
540 |
QByteArray ba = str.trimmed().toUtf8(); |
|
541 |
return integerFromString(ba.constData(), ba.size(), radix); |
|
542 |
} |
|
543 |
||
544 |
bool isFunction(JSC::JSValue value) |
|
545 |
{ |
|
546 |
if (!value || !value.isObject()) |
|
547 |
return false; |
|
548 |
JSC::CallData callData; |
|
549 |
return (JSC::asObject(value)->getCallData(callData) != JSC::CallTypeNone); |
|
550 |
} |
|
551 |
||
552 |
static JSC::JSValue JSC_HOST_CALL functionConnect(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
553 |
static JSC::JSValue JSC_HOST_CALL functionDisconnect(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
554 |
||
555 |
JSC::JSValue JSC_HOST_CALL functionDisconnect(JSC::ExecState *exec, JSC::JSObject * /*callee*/, JSC::JSValue thisObject, const JSC::ArgList &args) |
|
556 |
{ |
|
557 |
#ifndef QT_NO_QOBJECT |
|
558 |
if (args.size() == 0) { |
|
559 |
return JSC::throwError(exec, JSC::GeneralError, "Function.prototype.disconnect: no arguments given"); |
|
560 |
} |
|
561 |
||
562 |
if (!JSC::asObject(thisObject)->inherits(&QScript::QtFunction::info)) { |
|
563 |
return JSC::throwError(exec, JSC::TypeError, "Function.prototype.disconnect: this object is not a signal"); |
|
564 |
} |
|
565 |
||
566 |
QScript::QtFunction *qtSignal = static_cast<QScript::QtFunction*>(JSC::asObject(thisObject)); |
|
567 |
||
568 |
const QMetaObject *meta = qtSignal->metaObject(); |
|
569 |
if (!meta) { |
|
570 |
return JSC::throwError(exec, JSC::TypeError, "Function.prototype.discconnect: cannot disconnect from deleted QObject"); |
|
571 |
} |
|
572 |
||
573 |
QMetaMethod sig = meta->method(qtSignal->initialIndex()); |
|
574 |
if (sig.methodType() != QMetaMethod::Signal) { |
|
575 |
QString message = QString::fromLatin1("Function.prototype.disconnect: %0::%1 is not a signal") |
|
576 |
.arg(QLatin1String(qtSignal->metaObject()->className())) |
|
577 |
.arg(QLatin1String(sig.signature())); |
|
578 |
return JSC::throwError(exec, JSC::TypeError, message); |
|
579 |
} |
|
580 |
||
581 |
QScriptEnginePrivate *engine = scriptEngineFromExec(exec); |
|
582 |
||
583 |
JSC::JSValue receiver; |
|
584 |
JSC::JSValue slot; |
|
585 |
JSC::JSValue arg0 = args.at(0); |
|
586 |
if (args.size() < 2) { |
|
587 |
slot = arg0; |
|
588 |
} else { |
|
589 |
receiver = arg0; |
|
590 |
JSC::JSValue arg1 = args.at(1); |
|
591 |
if (isFunction(arg1)) |
|
592 |
slot = arg1; |
|
593 |
else { |
|
594 |
QScript::SaveFrameHelper saveFrame(engine, exec); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
595 |
JSC::UString propertyName = QScriptEnginePrivate::toString(exec, arg1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
596 |
slot = QScriptEnginePrivate::property(exec, arg0, propertyName, QScriptValue::ResolvePrototype); |
0 | 597 |
} |
598 |
} |
|
599 |
||
600 |
if (!isFunction(slot)) { |
|
601 |
return JSC::throwError(exec, JSC::TypeError, "Function.prototype.disconnect: target is not a function"); |
|
602 |
} |
|
603 |
||
604 |
bool ok = engine->scriptDisconnect(thisObject, receiver, slot); |
|
605 |
if (!ok) { |
|
606 |
QString message = QString::fromLatin1("Function.prototype.disconnect: failed to disconnect from %0::%1") |
|
607 |
.arg(QLatin1String(qtSignal->metaObject()->className())) |
|
608 |
.arg(QLatin1String(sig.signature())); |
|
609 |
return JSC::throwError(exec, JSC::GeneralError, message); |
|
610 |
} |
|
611 |
return JSC::jsUndefined(); |
|
612 |
#else |
|
613 |
Q_UNUSED(eng); |
|
614 |
return context->throwError(QScriptContext::TypeError, |
|
615 |
QLatin1String("Function.prototype.disconnect")); |
|
616 |
#endif // QT_NO_QOBJECT |
|
617 |
} |
|
618 |
||
619 |
JSC::JSValue JSC_HOST_CALL functionConnect(JSC::ExecState *exec, JSC::JSObject * /*callee*/, JSC::JSValue thisObject, const JSC::ArgList &args) |
|
620 |
{ |
|
621 |
#ifndef QT_NO_QOBJECT |
|
622 |
if (args.size() == 0) { |
|
623 |
return JSC::throwError(exec, JSC::GeneralError,"Function.prototype.connect: no arguments given"); |
|
624 |
} |
|
625 |
||
626 |
if (!JSC::asObject(thisObject)->inherits(&QScript::QtFunction::info)) { |
|
627 |
return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: this object is not a signal"); |
|
628 |
} |
|
629 |
||
630 |
QScript::QtFunction *qtSignal = static_cast<QScript::QtFunction*>(JSC::asObject(thisObject)); |
|
631 |
||
632 |
const QMetaObject *meta = qtSignal->metaObject(); |
|
633 |
if (!meta) { |
|
634 |
return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: cannot connect to deleted QObject"); |
|
635 |
} |
|
636 |
||
637 |
QMetaMethod sig = meta->method(qtSignal->initialIndex()); |
|
638 |
if (sig.methodType() != QMetaMethod::Signal) { |
|
639 |
QString message = QString::fromLatin1("Function.prototype.connect: %0::%1 is not a signal") |
|
640 |
.arg(QLatin1String(qtSignal->metaObject()->className())) |
|
641 |
.arg(QLatin1String(sig.signature())); |
|
642 |
return JSC::throwError(exec, JSC::TypeError, message); |
|
643 |
} |
|
644 |
||
645 |
{ |
|
646 |
QList<int> overloads = qtSignal->overloadedIndexes(); |
|
647 |
if (!overloads.isEmpty()) { |
|
648 |
overloads.append(qtSignal->initialIndex()); |
|
649 |
QByteArray signature = sig.signature(); |
|
650 |
QString message = QString::fromLatin1("Function.prototype.connect: ambiguous connect to %0::%1(); candidates are\n") |
|
651 |
.arg(QLatin1String(qtSignal->metaObject()->className())) |
|
652 |
.arg(QLatin1String(signature.left(signature.indexOf('(')))); |
|
653 |
for (int i = 0; i < overloads.size(); ++i) { |
|
654 |
QMetaMethod mtd = meta->method(overloads.at(i)); |
|
655 |
message.append(QString::fromLatin1(" %0\n").arg(QString::fromLatin1(mtd.signature()))); |
|
656 |
} |
|
657 |
message.append(QString::fromLatin1("Use e.g. object['%0'].connect() to connect to a particular overload") |
|
658 |
.arg(QLatin1String(signature))); |
|
659 |
return JSC::throwError(exec, JSC::GeneralError, message); |
|
660 |
} |
|
661 |
} |
|
662 |
||
663 |
QScriptEnginePrivate *engine = scriptEngineFromExec(exec); |
|
664 |
||
665 |
JSC::JSValue receiver; |
|
666 |
JSC::JSValue slot; |
|
667 |
JSC::JSValue arg0 = args.at(0); |
|
668 |
if (args.size() < 2) { |
|
669 |
slot = arg0; |
|
670 |
} else { |
|
671 |
receiver = arg0; |
|
672 |
JSC::JSValue arg1 = args.at(1); |
|
673 |
if (isFunction(arg1)) |
|
674 |
slot = arg1; |
|
675 |
else { |
|
676 |
QScript::SaveFrameHelper saveFrame(engine, exec); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
677 |
JSC::UString propertyName = QScriptEnginePrivate::toString(exec, arg1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
678 |
slot = QScriptEnginePrivate::property(exec, arg0, propertyName, QScriptValue::ResolvePrototype); |
0 | 679 |
} |
680 |
} |
|
681 |
||
682 |
if (!isFunction(slot)) { |
|
683 |
return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: target is not a function"); |
|
684 |
} |
|
685 |
||
686 |
bool ok = engine->scriptConnect(thisObject, receiver, slot, Qt::AutoConnection); |
|
687 |
if (!ok) { |
|
688 |
QString message = QString::fromLatin1("Function.prototype.connect: failed to connect to %0::%1") |
|
689 |
.arg(QLatin1String(qtSignal->metaObject()->className())) |
|
690 |
.arg(QLatin1String(sig.signature())); |
|
691 |
return JSC::throwError(exec, JSC::GeneralError, message); |
|
692 |
} |
|
693 |
return JSC::jsUndefined(); |
|
694 |
#else |
|
695 |
Q_UNUSED(eng); |
|
696 |
Q_UNUSED(classInfo); |
|
697 |
return context->throwError(QScriptContext::TypeError, |
|
698 |
QLatin1String("Function.prototype.connect")); |
|
699 |
#endif // QT_NO_QOBJECT |
|
700 |
} |
|
701 |
||
702 |
static JSC::JSValue JSC_HOST_CALL functionPrint(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
703 |
static JSC::JSValue JSC_HOST_CALL functionGC(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
704 |
static JSC::JSValue JSC_HOST_CALL functionVersion(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
705 |
||
706 |
JSC::JSValue JSC_HOST_CALL functionPrint(JSC::ExecState* exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList& args) |
|
707 |
{ |
|
708 |
QString result; |
|
709 |
for (unsigned i = 0; i < args.size(); ++i) { |
|
710 |
if (i != 0) |
|
711 |
result.append(QLatin1Char(' ')); |
|
712 |
QString s(args.at(i).toString(exec)); |
|
713 |
if (exec->hadException()) |
|
714 |
break; |
|
715 |
result.append(s); |
|
716 |
} |
|
717 |
if (exec->hadException()) |
|
718 |
return exec->exception(); |
|
719 |
qDebug("%s", qPrintable(result)); |
|
720 |
return JSC::jsUndefined(); |
|
721 |
} |
|
722 |
||
723 |
JSC::JSValue JSC_HOST_CALL functionGC(JSC::ExecState* exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&) |
|
724 |
{ |
|
725 |
QScriptEnginePrivate *engine = scriptEngineFromExec(exec); |
|
726 |
engine->collectGarbage(); |
|
727 |
return JSC::jsUndefined(); |
|
728 |
} |
|
729 |
||
730 |
JSC::JSValue JSC_HOST_CALL functionVersion(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&) |
|
731 |
{ |
|
732 |
return JSC::JSValue(exec, 1); |
|
733 |
} |
|
734 |
||
735 |
static JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
736 |
static JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
737 |
static JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
738 |
static JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
739 |
||
740 |
JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args) |
|
741 |
{ |
|
742 |
if (args.size() < 2) |
|
743 |
return JSC::throwError(exec, JSC::GeneralError, "qsTranslate() requires at least two arguments"); |
|
744 |
if (!args.at(0).isString()) |
|
745 |
return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): first argument (context) must be a string"); |
|
746 |
if (!args.at(1).isString()) |
|
747 |
return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): second argument (text) must be a string"); |
|
748 |
if ((args.size() > 2) && !args.at(2).isString()) |
|
749 |
return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): third argument (comment) must be a string"); |
|
750 |
if ((args.size() > 3) && !args.at(3).isString()) |
|
751 |
return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): fourth argument (encoding) must be a string"); |
|
752 |
if ((args.size() > 4) && !args.at(4).isNumber()) |
|
753 |
return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): fifth argument (n) must be a number"); |
|
754 |
#ifndef QT_NO_QOBJECT |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
755 |
JSC::UString context = args.at(0).toString(exec); |
0 | 756 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
757 |
JSC::UString text = args.at(1).toString(exec); |
0 | 758 |
#ifndef QT_NO_QOBJECT |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
759 |
JSC::UString comment; |
0 | 760 |
if (args.size() > 2) |
761 |
comment = args.at(2).toString(exec); |
|
762 |
QCoreApplication::Encoding encoding = QCoreApplication::CodecForTr; |
|
763 |
if (args.size() > 3) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
764 |
JSC::UString encStr = args.at(3).toString(exec); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
765 |
if (encStr == "CodecForTr") |
0 | 766 |
encoding = QCoreApplication::CodecForTr; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
767 |
else if (encStr == "UnicodeUTF8") |
0 | 768 |
encoding = QCoreApplication::UnicodeUTF8; |
769 |
else |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
770 |
return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("qsTranslate(): invalid encoding '%0'").arg(encStr)); |
0 | 771 |
} |
772 |
int n = -1; |
|
773 |
if (args.size() > 4) |
|
774 |
n = args.at(4).toInt32(exec); |
|
775 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
776 |
JSC::UString result; |
0 | 777 |
#ifndef QT_NO_QOBJECT |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
778 |
result = QCoreApplication::translate(QScript::convertToLatin1(context).constData(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
779 |
QScript::convertToLatin1(text).constData(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
780 |
QScript::convertToLatin1(comment).constData(), |
0 | 781 |
encoding, n); |
782 |
#else |
|
783 |
result = text; |
|
784 |
#endif |
|
785 |
return JSC::jsString(exec, result); |
|
786 |
} |
|
787 |
||
788 |
JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args) |
|
789 |
{ |
|
790 |
if (args.size() < 2) |
|
791 |
return JSC::jsUndefined(); |
|
792 |
return args.at(1); |
|
793 |
} |
|
794 |
||
795 |
JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args) |
|
796 |
{ |
|
797 |
if (args.size() < 1) |
|
798 |
return JSC::throwError(exec, JSC::GeneralError, "qsTr() requires at least one argument"); |
|
799 |
if (!args.at(0).isString()) |
|
800 |
return JSC::throwError(exec, JSC::GeneralError, "qsTr(): first argument (text) must be a string"); |
|
801 |
if ((args.size() > 1) && !args.at(1).isString()) |
|
802 |
return JSC::throwError(exec, JSC::GeneralError, "qsTr(): second argument (comment) must be a string"); |
|
803 |
if ((args.size() > 2) && !args.at(2).isNumber()) |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
804 |
return JSC::throwError(exec, JSC::GeneralError, "qsTr(): third argument (n) must be a number"); |
0 | 805 |
#ifndef QT_NO_QOBJECT |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
806 |
QScriptEnginePrivate *engine = scriptEngineFromExec(exec); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
807 |
JSC::UString context; |
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
808 |
// The first non-empty source URL in the call stack determines the translation context. |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
809 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
810 |
JSC::ExecState *frame = exec->callerFrame()->removeHostCallFrameFlag(); |
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
811 |
while (frame) { |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
812 |
if (frame->codeBlock() && frame->codeBlock()->source() |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
813 |
&& !frame->codeBlock()->source()->url().isEmpty()) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
814 |
context = engine->translationContextFromUrl(frame->codeBlock()->source()->url()); |
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
815 |
break; |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
816 |
} |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
817 |
frame = frame->callerFrame()->removeHostCallFrameFlag(); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
818 |
} |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
819 |
} |
0 | 820 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
821 |
JSC::UString text = args.at(0).toString(exec); |
0 | 822 |
#ifndef QT_NO_QOBJECT |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
823 |
JSC::UString comment; |
0 | 824 |
if (args.size() > 1) |
825 |
comment = args.at(1).toString(exec); |
|
826 |
int n = -1; |
|
827 |
if (args.size() > 2) |
|
828 |
n = args.at(2).toInt32(exec); |
|
829 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
830 |
JSC::UString result; |
0 | 831 |
#ifndef QT_NO_QOBJECT |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
832 |
result = QCoreApplication::translate(QScript::convertToLatin1(context).constData(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
833 |
QScript::convertToLatin1(text).constData(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
834 |
QScript::convertToLatin1(comment).constData(), |
0 | 835 |
QCoreApplication::CodecForTr, n); |
836 |
#else |
|
837 |
result = text; |
|
838 |
#endif |
|
839 |
return JSC::jsString(exec, result); |
|
840 |
} |
|
841 |
||
842 |
JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args) |
|
843 |
{ |
|
844 |
if (args.size() < 1) |
|
845 |
return JSC::jsUndefined(); |
|
846 |
return args.at(0); |
|
847 |
} |
|
848 |
||
849 |
static JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&); |
|
850 |
||
851 |
JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue thisObject, const JSC::ArgList &args) |
|
852 |
{ |
|
853 |
QString value(thisObject.toString(exec)); |
|
854 |
JSC::JSValue arg = (args.size() != 0) ? args.at(0) : JSC::jsUndefined(); |
|
855 |
QString result; |
|
856 |
if (arg.isString()) |
|
857 |
result = value.arg(arg.toString(exec)); |
|
858 |
else if (arg.isNumber()) |
|
859 |
result = value.arg(arg.toNumber(exec)); |
|
860 |
return JSC::jsString(exec, result); |
|
861 |
} |
|
862 |
||
863 |
||
864 |
#if !defined(QT_NO_QOBJECT) && !defined(QT_NO_LIBRARY) |
|
865 |
static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng) |
|
866 |
{ |
|
867 |
QString path = ctx->argument(0).toString(); |
|
868 |
QStringList components = path.split(QLatin1Char('.')); |
|
869 |
QScriptValue o = eng->globalObject(); |
|
870 |
for (int i = 0; i < components.count(); ++i) { |
|
871 |
QString name = components.at(i); |
|
872 |
QScriptValue oo = o.property(name); |
|
873 |
if (!oo.isValid()) { |
|
874 |
oo = eng->newObject(); |
|
875 |
o.setProperty(name, oo); |
|
876 |
} |
|
877 |
o = oo; |
|
878 |
} |
|
879 |
return o; |
|
880 |
} |
|
881 |
#endif |
|
882 |
||
883 |
} // namespace QScript |
|
884 |
||
885 |
QScriptEnginePrivate::QScriptEnginePrivate() |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
886 |
: registeredScriptValues(0), freeScriptValues(0), freeScriptValuesCount(0), |
0 | 887 |
registeredScriptStrings(0), inEval(false) |
888 |
{ |
|
889 |
qMetaTypeId<QScriptValue>(); |
|
890 |
qMetaTypeId<QList<int> >(); |
|
891 |
#ifndef QT_NO_QOBJECT |
|
892 |
qMetaTypeId<QObjectList>(); |
|
893 |
#endif |
|
894 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
895 |
if (!QCoreApplication::instance()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
896 |
qFatal("QScriptEngine: Must construct a Q(Core)Application before a QScriptEngine"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
897 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
898 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
899 |
JSC::initializeThreading(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
900 |
JSC::IdentifierTable *oldTable = JSC::currentIdentifierTable(); |
0 | 901 |
globalData = JSC::JSGlobalData::create().releaseRef(); |
902 |
globalData->clientData = new QScript::GlobalClientData(this); |
|
903 |
JSC::JSGlobalObject *globalObject = new (globalData)QScript::GlobalObject(); |
|
904 |
||
905 |
JSC::ExecState* exec = globalObject->globalExec(); |
|
906 |
||
907 |
scriptObjectStructure = QScriptObject::createStructure(globalObject->objectPrototype()); |
|
908 |
||
909 |
qobjectPrototype = new (exec) QScript::QObjectPrototype(exec, QScript::QObjectPrototype::createStructure(globalObject->objectPrototype()), globalObject->prototypeFunctionStructure()); |
|
910 |
qobjectWrapperObjectStructure = QScriptObject::createStructure(qobjectPrototype); |
|
911 |
||
912 |
qmetaobjectPrototype = new (exec) QScript::QMetaObjectPrototype(exec, QScript::QMetaObjectPrototype::createStructure(globalObject->objectPrototype()), globalObject->prototypeFunctionStructure()); |
|
913 |
qmetaobjectWrapperObjectStructure = QScript::QMetaObjectWrapperObject::createStructure(qmetaobjectPrototype); |
|
914 |
||
915 |
variantPrototype = new (exec) QScript::QVariantPrototype(exec, QScript::QVariantPrototype::createStructure(globalObject->objectPrototype()), globalObject->prototypeFunctionStructure()); |
|
916 |
variantWrapperObjectStructure = QScriptObject::createStructure(variantPrototype); |
|
917 |
||
918 |
globalObject->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "print"), QScript::functionPrint)); |
|
919 |
globalObject->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 0, JSC::Identifier(exec, "gc"), QScript::functionGC)); |
|
920 |
globalObject->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 0, JSC::Identifier(exec, "version"), QScript::functionVersion)); |
|
921 |
||
922 |
// ### rather than extending Function.prototype, consider creating a QtSignal.prototype |
|
923 |
globalObject->functionPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "disconnect"), QScript::functionDisconnect)); |
|
924 |
globalObject->functionPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, globalObject->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "connect"), QScript::functionConnect)); |
|
925 |
||
926 |
JSC::TimeoutChecker* originalChecker = globalData->timeoutChecker; |
|
927 |
globalData->timeoutChecker = new QScript::TimeoutCheckerProxy(*originalChecker); |
|
928 |
delete originalChecker; |
|
929 |
||
930 |
currentFrame = exec; |
|
931 |
||
932 |
originalGlobalObjectProxy = 0; |
|
933 |
activeAgent = 0; |
|
934 |
agentLineNumber = -1; |
|
935 |
processEventsInterval = -1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
936 |
cachedTranslationUrl = JSC::UString(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
937 |
cachedTranslationContext = JSC::UString(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
938 |
JSC::setCurrentIdentifierTable(oldTable); |
0 | 939 |
} |
940 |
||
941 |
QScriptEnginePrivate::~QScriptEnginePrivate() |
|
942 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
943 |
QScript::APIShim shim(this); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
944 |
|
0 | 945 |
//disconnect all loadedScripts and generate all jsc::debugger::scriptUnload events |
946 |
QHash<intptr_t,QScript::UStringSourceProviderWithFeedback*>::const_iterator it; |
|
947 |
for (it = loadedScripts.constBegin(); it != loadedScripts.constEnd(); ++it) |
|
948 |
it.value()->disconnectFromEngine(); |
|
949 |
||
950 |
while (!ownedAgents.isEmpty()) |
|
951 |
delete ownedAgents.takeFirst(); |
|
952 |
||
953 |
detachAllRegisteredScriptValues(); |
|
954 |
detachAllRegisteredScriptStrings(); |
|
955 |
qDeleteAll(m_qobjectData); |
|
956 |
qDeleteAll(m_typeInfos); |
|
957 |
JSC::JSLock lock(false); |
|
958 |
globalData->heap.destroy(); |
|
959 |
globalData->deref(); |
|
960 |
while (freeScriptValues) { |
|
961 |
QScriptValuePrivate *p = freeScriptValues; |
|
962 |
freeScriptValues = p->next; |
|
963 |
qFree(p); |
|
964 |
} |
|
965 |
} |
|
966 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
967 |
QVariant QScriptEnginePrivate::jscValueToVariant(JSC::ExecState *exec, JSC::JSValue value, int targetType) |
0 | 968 |
{ |
969 |
QVariant v(targetType, (void *)0); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
970 |
if (convertValue(exec, value, targetType, v.data())) |
0 | 971 |
return v; |
972 |
if (uint(targetType) == QVariant::LastType) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
973 |
return toVariant(exec, value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
974 |
if (isVariant(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
975 |
v = variantValue(value); |
0 | 976 |
if (v.canConvert(QVariant::Type(targetType))) { |
977 |
v.convert(QVariant::Type(targetType)); |
|
978 |
return v; |
|
979 |
} |
|
980 |
QByteArray typeName = v.typeName(); |
|
981 |
if (typeName.endsWith('*') |
|
982 |
&& (QMetaType::type(typeName.left(typeName.size()-1)) == targetType)) { |
|
983 |
return QVariant(targetType, *reinterpret_cast<void* *>(v.data())); |
|
984 |
} |
|
985 |
} |
|
986 |
return QVariant(); |
|
987 |
} |
|
988 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
989 |
JSC::JSValue QScriptEnginePrivate::arrayFromStringList(JSC::ExecState *exec, const QStringList &lst) |
0 | 990 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
991 |
JSC::JSValue arr = newArray(exec, lst.size()); |
0 | 992 |
for (int i = 0; i < lst.size(); ++i) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
993 |
setProperty(exec, arr, i, JSC::jsString(exec, lst.at(i))); |
0 | 994 |
return arr; |
995 |
} |
|
996 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
997 |
QStringList QScriptEnginePrivate::stringListFromArray(JSC::ExecState *exec, JSC::JSValue arr) |
0 | 998 |
{ |
999 |
QStringList lst; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1000 |
uint len = toUInt32(exec, property(exec, arr, exec->propertyNames().length)); |
0 | 1001 |
for (uint i = 0; i < len; ++i) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1002 |
lst.append(toString(exec, property(exec, arr, i))); |
0 | 1003 |
return lst; |
1004 |
} |
|
1005 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1006 |
JSC::JSValue QScriptEnginePrivate::arrayFromVariantList(JSC::ExecState *exec, const QVariantList &lst) |
0 | 1007 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1008 |
JSC::JSValue arr = newArray(exec, lst.size()); |
0 | 1009 |
for (int i = 0; i < lst.size(); ++i) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1010 |
setProperty(exec, arr, i, jscValueFromVariant(exec, lst.at(i))); |
0 | 1011 |
return arr; |
1012 |
} |
|
1013 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1014 |
QVariantList QScriptEnginePrivate::variantListFromArray(JSC::ExecState *exec, JSC::JSValue arr) |
0 | 1015 |
{ |
1016 |
QVariantList lst; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1017 |
uint len = toUInt32(exec, property(exec, arr, exec->propertyNames().length)); |
0 | 1018 |
for (uint i = 0; i < len; ++i) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1019 |
lst.append(toVariant(exec, property(exec, arr, i))); |
0 | 1020 |
return lst; |
1021 |
} |
|
1022 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1023 |
JSC::JSValue QScriptEnginePrivate::objectFromVariantMap(JSC::ExecState *exec, const QVariantMap &vmap) |
0 | 1024 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1025 |
JSC::JSValue obj = JSC::constructEmptyObject(exec); |
0 | 1026 |
QVariantMap::const_iterator it; |
1027 |
for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1028 |
setProperty(exec, obj, it.key(), jscValueFromVariant(exec, it.value())); |
0 | 1029 |
return obj; |
1030 |
} |
|
1031 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1032 |
QVariantMap QScriptEnginePrivate::variantMapFromObject(JSC::ExecState *exec, JSC::JSValue obj) |
0 | 1033 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1034 |
JSC::PropertyNameArray propertyNames(exec); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1035 |
JSC::asObject(obj)->getOwnPropertyNames(exec, propertyNames, JSC::IncludeDontEnumProperties); |
0 | 1036 |
QVariantMap vmap; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1037 |
JSC::PropertyNameArray::const_iterator it = propertyNames.begin(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1038 |
for( ; it != propertyNames.end(); ++it) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1039 |
vmap.insert(it->ustring(), toVariant(exec, property(exec, obj, *it))); |
0 | 1040 |
return vmap; |
1041 |
} |
|
1042 |
||
1043 |
JSC::JSValue QScriptEnginePrivate::defaultPrototype(int metaTypeId) const |
|
1044 |
{ |
|
1045 |
QScriptTypeInfo *info = m_typeInfos.value(metaTypeId); |
|
1046 |
if (!info) |
|
1047 |
return JSC::JSValue(); |
|
1048 |
return info->prototype; |
|
1049 |
} |
|
1050 |
||
1051 |
void QScriptEnginePrivate::setDefaultPrototype(int metaTypeId, JSC::JSValue prototype) |
|
1052 |
{ |
|
1053 |
QScriptTypeInfo *info = m_typeInfos.value(metaTypeId); |
|
1054 |
if (!info) { |
|
1055 |
info = new QScriptTypeInfo(); |
|
1056 |
m_typeInfos.insert(metaTypeId, info); |
|
1057 |
} |
|
1058 |
info->prototype = prototype; |
|
1059 |
} |
|
1060 |
||
1061 |
JSC::JSGlobalObject *QScriptEnginePrivate::originalGlobalObject() const |
|
1062 |
{ |
|
1063 |
return globalData->head; |
|
1064 |
} |
|
1065 |
||
1066 |
JSC::JSObject *QScriptEnginePrivate::customGlobalObject() const |
|
1067 |
{ |
|
1068 |
QScript::GlobalObject *glob = static_cast<QScript::GlobalObject*>(originalGlobalObject()); |
|
1069 |
return glob->customGlobalObject; |
|
1070 |
} |
|
1071 |
||
1072 |
JSC::JSObject *QScriptEnginePrivate::getOriginalGlobalObjectProxy() |
|
1073 |
{ |
|
1074 |
if (!originalGlobalObjectProxy) { |
|
1075 |
JSC::ExecState* exec = currentFrame; |
|
1076 |
originalGlobalObjectProxy = new (exec)QScript::OriginalGlobalObjectProxy(scriptObjectStructure, originalGlobalObject()); |
|
1077 |
} |
|
1078 |
return originalGlobalObjectProxy; |
|
1079 |
} |
|
1080 |
||
1081 |
JSC::JSObject *QScriptEnginePrivate::globalObject() const |
|
1082 |
{ |
|
1083 |
QScript::GlobalObject *glob = static_cast<QScript::GlobalObject*>(originalGlobalObject()); |
|
1084 |
if (glob->customGlobalObject) |
|
1085 |
return glob->customGlobalObject; |
|
1086 |
return glob; |
|
1087 |
} |
|
1088 |
||
1089 |
void QScriptEnginePrivate::setGlobalObject(JSC::JSObject *object) |
|
1090 |
{ |
|
1091 |
if (object == globalObject()) |
|
1092 |
return; |
|
1093 |
QScript::GlobalObject *glob = static_cast<QScript::GlobalObject*>(originalGlobalObject()); |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1094 |
if (object == originalGlobalObjectProxy) { |
0 | 1095 |
glob->customGlobalObject = 0; |
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1096 |
// Sync the internal prototype, since JSObject::prototype() is not virtual. |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1097 |
glob->setPrototype(originalGlobalObjectProxy->prototype()); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1098 |
} else { |
0 | 1099 |
Q_ASSERT(object != originalGlobalObject()); |
1100 |
glob->customGlobalObject = object; |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1101 |
// Sync the internal prototype, since JSObject::prototype() is not virtual. |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1102 |
glob->setPrototype(object->prototype()); |
0 | 1103 |
} |
1104 |
} |
|
1105 |
||
1106 |
/*! |
|
1107 |
\internal |
|
1108 |
||
1109 |
If the given \a value is the original global object, returns the custom |
|
1110 |
global object or a proxy to the original global object; otherwise returns \a |
|
1111 |
value. |
|
1112 |
*/ |
|
1113 |
JSC::JSValue QScriptEnginePrivate::toUsableValue(JSC::JSValue value) |
|
1114 |
{ |
|
1115 |
if (!value || !value.isObject() || !JSC::asObject(value)->isGlobalObject()) |
|
1116 |
return value; |
|
1117 |
Q_ASSERT(JSC::asObject(value) == originalGlobalObject()); |
|
1118 |
if (customGlobalObject()) |
|
1119 |
return customGlobalObject(); |
|
1120 |
if (!originalGlobalObjectProxy) |
|
1121 |
originalGlobalObjectProxy = new (currentFrame)QScript::OriginalGlobalObjectProxy(scriptObjectStructure, originalGlobalObject()); |
|
1122 |
return originalGlobalObjectProxy; |
|
1123 |
} |
|
1124 |
/*! |
|
1125 |
\internal |
|
1126 |
Return the 'this' value for a given context |
|
1127 |
*/ |
|
1128 |
JSC::JSValue QScriptEnginePrivate::thisForContext(JSC::ExecState *frame) |
|
1129 |
{ |
|
1130 |
if (frame->codeBlock() != 0) { |
|
1131 |
return frame->thisValue(); |
|
1132 |
} else if(frame == frame->lexicalGlobalObject()->globalExec()) { |
|
1133 |
return frame->globalThisValue(); |
|
1134 |
} else { |
|
1135 |
JSC::Register *thisRegister = thisRegisterForFrame(frame); |
|
1136 |
return thisRegister->jsValue(); |
|
1137 |
} |
|
1138 |
} |
|
1139 |
||
1140 |
JSC::Register* QScriptEnginePrivate::thisRegisterForFrame(JSC::ExecState *frame) |
|
1141 |
{ |
|
1142 |
Q_ASSERT(frame->codeBlock() == 0); // only for native calls |
|
1143 |
return frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - frame->argumentCount(); |
|
1144 |
} |
|
1145 |
||
1146 |
/*! \internal |
|
1147 |
For native context, we use the ReturnValueRegister entry in the stackframe header to store flags. |
|
1148 |
We can do that because this header is not used as the native function return their value thought C++ |
|
1149 |
||
1150 |
when setting flags, NativeContext should always be set |
|
1151 |
||
1152 |
contextFlags returns 0 for non native context |
|
1153 |
*/ |
|
1154 |
uint QScriptEnginePrivate::contextFlags(JSC::ExecState *exec) |
|
1155 |
{ |
|
1156 |
if (exec->codeBlock()) |
|
1157 |
return 0; //js function doesn't have flags |
|
1158 |
||
1159 |
return exec->returnValueRegister(); |
|
1160 |
} |
|
1161 |
||
1162 |
void QScriptEnginePrivate::setContextFlags(JSC::ExecState *exec, uint flags) |
|
1163 |
{ |
|
1164 |
Q_ASSERT(!exec->codeBlock()); |
|
1165 |
exec->registers()[JSC::RegisterFile::ReturnValueRegister] = JSC::Register::withInt(flags); |
|
1166 |
} |
|
1167 |
||
1168 |
||
1169 |
void QScriptEnginePrivate::mark(JSC::MarkStack& markStack) |
|
1170 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1171 |
Q_Q(QScriptEngine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1172 |
|
0 | 1173 |
markStack.append(originalGlobalObject()); |
1174 |
markStack.append(globalObject()); |
|
1175 |
if (originalGlobalObjectProxy) |
|
1176 |
markStack.append(originalGlobalObjectProxy); |
|
1177 |
||
1178 |
if (qobjectPrototype) |
|
1179 |
markStack.append(qobjectPrototype); |
|
1180 |
if (qmetaobjectPrototype) |
|
1181 |
markStack.append(qmetaobjectPrototype); |
|
1182 |
if (variantPrototype) |
|
1183 |
markStack.append(variantPrototype); |
|
1184 |
||
1185 |
{ |
|
1186 |
QScriptValuePrivate *it; |
|
1187 |
for (it = registeredScriptValues; it != 0; it = it->next) { |
|
1188 |
if (it->isJSC()) |
|
1189 |
markStack.append(it->jscValue); |
|
1190 |
} |
|
1191 |
} |
|
1192 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1193 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1194 |
QHash<int, QScriptTypeInfo*>::const_iterator it; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1195 |
for (it = m_typeInfos.constBegin(); it != m_typeInfos.constEnd(); ++it) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1196 |
if ((*it)->prototype) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1197 |
markStack.append((*it)->prototype); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1198 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1199 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1200 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1201 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1202 |
QScriptContext *context = q->currentContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1203 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
while (context) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1205 |
JSC::ScopeChainNode *node = frameForContext(context)->scopeChain(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1206 |
JSC::ScopeChainIterator it(node); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1207 |
for (it = node->begin(); it != node->end(); ++it) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1208 |
JSC::JSObject *object = *it; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1209 |
if (object) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1210 |
markStack.append(object); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1211 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1212 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1213 |
context = context->parentContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1214 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1216 |
|
0 | 1217 |
#ifndef QT_NO_QOBJECT |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1218 |
markStack.drain(); // make sure everything is marked before marking qobject data |
0 | 1219 |
{ |
1220 |
QHash<QObject*, QScript::QObjectData*>::const_iterator it; |
|
1221 |
for (it = m_qobjectData.constBegin(); it != m_qobjectData.constEnd(); ++it) { |
|
1222 |
QScript::QObjectData *qdata = it.value(); |
|
1223 |
qdata->mark(markStack); |
|
1224 |
} |
|
1225 |
} |
|
1226 |
#endif |
|
1227 |
} |
|
1228 |
||
1229 |
bool QScriptEnginePrivate::isCollecting() const |
|
1230 |
{ |
|
1231 |
return globalData->heap.isBusy(); |
|
1232 |
} |
|
1233 |
||
1234 |
void QScriptEnginePrivate::collectGarbage() |
|
1235 |
{ |
|
1236 |
JSC::JSLock lock(false); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1237 |
QScript::APIShim shim(this); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1238 |
globalData->heap.collectAllGarbage(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1239 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1240 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1241 |
void QScriptEnginePrivate::reportAdditionalMemoryCost(int size) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1242 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1243 |
if (size > 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1244 |
globalData->heap.reportExtraMemoryCost(size); |
0 | 1245 |
} |
1246 |
||
1247 |
QScript::TimeoutCheckerProxy *QScriptEnginePrivate::timeoutChecker() const |
|
1248 |
{ |
|
1249 |
return static_cast<QScript::TimeoutCheckerProxy*>(globalData->timeoutChecker); |
|
1250 |
} |
|
1251 |
||
1252 |
void QScriptEnginePrivate::agentDeleted(QScriptEngineAgent *agent) |
|
1253 |
{ |
|
1254 |
ownedAgents.removeOne(agent); |
|
1255 |
if (activeAgent == agent) { |
|
1256 |
QScriptEngineAgentPrivate::get(agent)->detach(); |
|
1257 |
activeAgent = 0; |
|
1258 |
} |
|
1259 |
} |
|
1260 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1261 |
JSC::JSValue QScriptEnginePrivate::evaluateHelper(JSC::ExecState *exec, intptr_t sourceId, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1262 |
JSC::EvalExecutable *executable, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1263 |
bool &compile) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1264 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1265 |
Q_Q(QScriptEngine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1266 |
JSC::JSLock lock(false); // ### hmmm |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1267 |
QBoolBlocker inEvalBlocker(inEval, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
q->currentContext()->activationObject(); //force the creation of a context for native function; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1269 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
JSC::Debugger* debugger = originalGlobalObject()->debugger(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
if (debugger) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1272 |
debugger->evaluateStart(sourceId); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1274 |
q->clearExceptions(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1275 |
JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1277 |
if (compile) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1278 |
JSC::JSObject* error = executable->compile(exec, exec->scopeChain()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1279 |
if (error) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1280 |
compile = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1281 |
exec->setException(error); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1282 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1283 |
if (debugger) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1284 |
debugger->exceptionThrow(JSC::DebuggerCallFrame(exec, error), sourceId, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1285 |
debugger->evaluateStop(error, sourceId); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1286 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1287 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1288 |
return error; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1289 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1291 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1292 |
JSC::JSValue thisValue = thisForContext(exec); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1293 |
JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1294 |
? exec->dynamicGlobalObject() : thisValue.toObject(exec); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
JSC::JSValue exceptionValue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1296 |
timeoutChecker()->setShouldAbort(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
if (processEventsInterval > 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1298 |
timeoutChecker()->reset(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1299 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1300 |
JSC::JSValue result = exec->interpreter()->execute(executable, exec, thisObject, exec->scopeChain(), &exceptionValue); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1301 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1302 |
if (timeoutChecker()->shouldAbort()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
if (abortResult.isError()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
exec->setException(scriptValueToJSCValue(abortResult)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1305 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1306 |
if (debugger) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1307 |
debugger->evaluateStop(scriptValueToJSCValue(abortResult), sourceId); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1309 |
return scriptValueToJSCValue(abortResult); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1310 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1311 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1312 |
if (exceptionValue) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1313 |
exec->setException(exceptionValue); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1314 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1315 |
if (debugger) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1316 |
debugger->evaluateStop(exceptionValue, sourceId); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1317 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1318 |
return exceptionValue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1319 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1320 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1321 |
if (debugger) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
debugger->evaluateStop(result, sourceId); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1324 |
Q_ASSERT(!exec->hadException()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1325 |
return result; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1326 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1327 |
|
0 | 1328 |
#ifndef QT_NO_QOBJECT |
1329 |
||
1330 |
JSC::JSValue QScriptEnginePrivate::newQObject( |
|
1331 |
QObject *object, QScriptEngine::ValueOwnership ownership, |
|
1332 |
const QScriptEngine::QObjectWrapOptions &options) |
|
1333 |
{ |
|
1334 |
if (!object) |
|
1335 |
return JSC::jsNull(); |
|
1336 |
JSC::ExecState* exec = currentFrame; |
|
1337 |
QScript::QObjectData *data = qobjectData(object); |
|
1338 |
bool preferExisting = (options & QScriptEngine::PreferExistingWrapperObject) != 0; |
|
1339 |
QScriptEngine::QObjectWrapOptions opt = options & ~QScriptEngine::PreferExistingWrapperObject; |
|
1340 |
QScriptObject *result = 0; |
|
1341 |
if (preferExisting) { |
|
1342 |
result = data->findWrapper(ownership, opt); |
|
1343 |
if (result) |
|
1344 |
return result; |
|
1345 |
} |
|
1346 |
result = new (exec) QScriptObject(qobjectWrapperObjectStructure); |
|
1347 |
if (preferExisting) |
|
1348 |
data->registerWrapper(result, ownership, opt); |
|
1349 |
result->setDelegate(new QScript::QObjectDelegate(object, ownership, options)); |
|
1350 |
/*if (setDefaultPrototype)*/ { |
|
1351 |
const QMetaObject *meta = object->metaObject(); |
|
1352 |
while (meta) { |
|
1353 |
QByteArray typeString = meta->className(); |
|
1354 |
typeString.append('*'); |
|
1355 |
int typeId = QMetaType::type(typeString); |
|
1356 |
if (typeId != 0) { |
|
1357 |
JSC::JSValue proto = defaultPrototype(typeId); |
|
1358 |
if (proto) { |
|
1359 |
result->setPrototype(proto); |
|
1360 |
break; |
|
1361 |
} |
|
1362 |
} |
|
1363 |
meta = meta->superClass(); |
|
1364 |
} |
|
1365 |
} |
|
1366 |
return result; |
|
1367 |
} |
|
1368 |
||
1369 |
JSC::JSValue QScriptEnginePrivate::newQMetaObject( |
|
1370 |
const QMetaObject *metaObject, JSC::JSValue ctor) |
|
1371 |
{ |
|
1372 |
if (!metaObject) |
|
1373 |
return JSC::jsNull(); |
|
1374 |
JSC::ExecState* exec = currentFrame; |
|
1375 |
QScript::QMetaObjectWrapperObject *result = new (exec) QScript::QMetaObjectWrapperObject(exec, metaObject, ctor, qmetaobjectWrapperObjectStructure); |
|
1376 |
return result; |
|
1377 |
} |
|
1378 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1379 |
bool QScriptEnginePrivate::convertToNativeQObject(JSC::ExecState *exec, JSC::JSValue value, |
0 | 1380 |
const QByteArray &targetType, |
1381 |
void **result) |
|
1382 |
{ |
|
1383 |
if (!targetType.endsWith('*')) |
|
1384 |
return false; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1385 |
if (QObject *qobject = toQObject(exec, value)) { |
0 | 1386 |
int start = targetType.startsWith("const ") ? 6 : 0; |
1387 |
QByteArray className = targetType.mid(start, targetType.size()-start-1); |
|
1388 |
if (void *instance = qobject->qt_metacast(className)) { |
|
1389 |
*result = instance; |
|
1390 |
return true; |
|
1391 |
} |
|
1392 |
} |
|
1393 |
return false; |
|
1394 |
} |
|
1395 |
||
1396 |
QScript::QObjectData *QScriptEnginePrivate::qobjectData(QObject *object) |
|
1397 |
{ |
|
1398 |
QHash<QObject*, QScript::QObjectData*>::const_iterator it; |
|
1399 |
it = m_qobjectData.constFind(object); |
|
1400 |
if (it != m_qobjectData.constEnd()) |
|
1401 |
return it.value(); |
|
1402 |
||
1403 |
QScript::QObjectData *data = new QScript::QObjectData(this); |
|
1404 |
m_qobjectData.insert(object, data); |
|
1405 |
QObject::connect(object, SIGNAL(destroyed(QObject*)), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1406 |
q_func(), SLOT(_q_objectDestroyed(QObject*))); |
0 | 1407 |
return data; |
1408 |
} |
|
1409 |
||
1410 |
void QScriptEnginePrivate::_q_objectDestroyed(QObject *object) |
|
1411 |
{ |
|
1412 |
QHash<QObject*, QScript::QObjectData*>::iterator it; |
|
1413 |
it = m_qobjectData.find(object); |
|
1414 |
Q_ASSERT(it != m_qobjectData.end()); |
|
1415 |
QScript::QObjectData *data = it.value(); |
|
1416 |
m_qobjectData.erase(it); |
|
1417 |
delete data; |
|
1418 |
} |
|
1419 |
||
1420 |
void QScriptEnginePrivate::disposeQObject(QObject *object) |
|
1421 |
{ |
|
1422 |
// TODO |
|
1423 |
/* if (isCollecting()) { |
|
1424 |
// wait until we're done with GC before deleting it |
|
1425 |
int index = m_qobjectsToBeDeleted.indexOf(object); |
|
1426 |
if (index == -1) |
|
1427 |
m_qobjectsToBeDeleted.append(object); |
|
1428 |
} else*/ { |
|
1429 |
delete object; |
|
1430 |
} |
|
1431 |
} |
|
1432 |
||
1433 |
void QScriptEnginePrivate::emitSignalHandlerException() |
|
1434 |
{ |
|
1435 |
Q_Q(QScriptEngine); |
|
1436 |
emit q->signalHandlerException(q->uncaughtException()); |
|
1437 |
} |
|
1438 |
||
1439 |
bool QScriptEnginePrivate::scriptConnect(QObject *sender, const char *signal, |
|
1440 |
JSC::JSValue receiver, JSC::JSValue function, |
|
1441 |
Qt::ConnectionType type) |
|
1442 |
{ |
|
1443 |
Q_ASSERT(sender); |
|
1444 |
Q_ASSERT(signal); |
|
1445 |
const QMetaObject *meta = sender->metaObject(); |
|
1446 |
int index = meta->indexOfSignal(QMetaObject::normalizedSignature(signal+1)); |
|
1447 |
if (index == -1) |
|
1448 |
return false; |
|
1449 |
return scriptConnect(sender, index, receiver, function, /*wrapper=*/JSC::JSValue(), type); |
|
1450 |
} |
|
1451 |
||
1452 |
bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, const char *signal, |
|
1453 |
JSC::JSValue receiver, JSC::JSValue function) |
|
1454 |
{ |
|
1455 |
Q_ASSERT(sender); |
|
1456 |
Q_ASSERT(signal); |
|
1457 |
const QMetaObject *meta = sender->metaObject(); |
|
1458 |
int index = meta->indexOfSignal(QMetaObject::normalizedSignature(signal+1)); |
|
1459 |
if (index == -1) |
|
1460 |
return false; |
|
1461 |
return scriptDisconnect(sender, index, receiver, function); |
|
1462 |
} |
|
1463 |
||
1464 |
bool QScriptEnginePrivate::scriptConnect(QObject *sender, int signalIndex, |
|
1465 |
JSC::JSValue receiver, JSC::JSValue function, |
|
1466 |
JSC::JSValue senderWrapper, |
|
1467 |
Qt::ConnectionType type) |
|
1468 |
{ |
|
1469 |
QScript::QObjectData *data = qobjectData(sender); |
|
1470 |
return data->addSignalHandler(sender, signalIndex, receiver, function, senderWrapper, type); |
|
1471 |
} |
|
1472 |
||
1473 |
bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, int signalIndex, |
|
1474 |
JSC::JSValue receiver, JSC::JSValue function) |
|
1475 |
{ |
|
1476 |
QScript::QObjectData *data = qobjectData(sender); |
|
1477 |
if (!data) |
|
1478 |
return false; |
|
1479 |
return data->removeSignalHandler(sender, signalIndex, receiver, function); |
|
1480 |
} |
|
1481 |
||
1482 |
bool QScriptEnginePrivate::scriptConnect(JSC::JSValue signal, JSC::JSValue receiver, |
|
1483 |
JSC::JSValue function, Qt::ConnectionType type) |
|
1484 |
{ |
|
1485 |
QScript::QtFunction *fun = static_cast<QScript::QtFunction*>(JSC::asObject(signal)); |
|
1486 |
int index = fun->mostGeneralMethod(); |
|
1487 |
return scriptConnect(fun->qobject(), index, receiver, function, fun->wrapperObject(), type); |
|
1488 |
} |
|
1489 |
||
1490 |
bool QScriptEnginePrivate::scriptDisconnect(JSC::JSValue signal, JSC::JSValue receiver, |
|
1491 |
JSC::JSValue function) |
|
1492 |
{ |
|
1493 |
QScript::QtFunction *fun = static_cast<QScript::QtFunction*>(JSC::asObject(signal)); |
|
1494 |
int index = fun->mostGeneralMethod(); |
|
1495 |
return scriptDisconnect(fun->qobject(), index, receiver, function); |
|
1496 |
} |
|
1497 |
||
1498 |
#endif |
|
1499 |
||
1500 |
void QScriptEnginePrivate::detachAllRegisteredScriptValues() |
|
1501 |
{ |
|
1502 |
QScriptValuePrivate *it; |
|
1503 |
QScriptValuePrivate *next; |
|
1504 |
for (it = registeredScriptValues; it != 0; it = next) { |
|
1505 |
it->detachFromEngine(); |
|
1506 |
next = it->next; |
|
1507 |
it->prev = 0; |
|
1508 |
it->next = 0; |
|
1509 |
} |
|
1510 |
registeredScriptValues = 0; |
|
1511 |
} |
|
1512 |
||
1513 |
void QScriptEnginePrivate::detachAllRegisteredScriptStrings() |
|
1514 |
{ |
|
1515 |
QScriptStringPrivate *it; |
|
1516 |
QScriptStringPrivate *next; |
|
1517 |
for (it = registeredScriptStrings; it != 0; it = next) { |
|
1518 |
it->detachFromEngine(); |
|
1519 |
next = it->next; |
|
1520 |
it->prev = 0; |
|
1521 |
it->next = 0; |
|
1522 |
} |
|
1523 |
registeredScriptStrings = 0; |
|
1524 |
} |
|
1525 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1526 |
#ifndef QT_NO_REGEXP |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1527 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1528 |
Q_DECL_IMPORT extern QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1529 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1530 |
JSC::JSValue QScriptEnginePrivate::newRegExp(JSC::ExecState *exec, const QRegExp ®exp) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1531 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1532 |
JSC::JSValue buf[2]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1533 |
JSC::ArgList args(buf, sizeof(buf)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1534 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1535 |
//convert the pattern to a ECMAScript pattern |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1536 |
QString pattern = qt_regexp_toCanonical(regexp.pattern(), regexp.patternSyntax()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1537 |
if (regexp.isMinimal()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1538 |
QString ecmaPattern; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1539 |
int len = pattern.length(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1540 |
ecmaPattern.reserve(len); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1541 |
int i = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1542 |
const QChar *wc = pattern.unicode(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1543 |
bool inBracket = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1544 |
while (i < len) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1545 |
QChar c = wc[i++]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1546 |
ecmaPattern += c; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1547 |
switch (c.unicode()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1548 |
case '?': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1549 |
case '+': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1550 |
case '*': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1551 |
case '}': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1552 |
if (!inBracket) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1553 |
ecmaPattern += QLatin1Char('?'); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1554 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1555 |
case '\\': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1556 |
if (i < len) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1557 |
ecmaPattern += wc[i++]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1558 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1559 |
case '[': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1560 |
inBracket = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1561 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1562 |
case ']': |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1563 |
inBracket = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1564 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1565 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1566 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1567 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1568 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1569 |
pattern = ecmaPattern; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1570 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1571 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1572 |
JSC::UString jscPattern = pattern; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1573 |
QString flags; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1574 |
if (regexp.caseSensitivity() == Qt::CaseInsensitive) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1575 |
flags.append(QLatin1Char('i')); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1576 |
JSC::UString jscFlags = flags; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1577 |
buf[0] = JSC::jsString(exec, jscPattern); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1578 |
buf[1] = JSC::jsString(exec, jscFlags); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1579 |
return JSC::constructRegExp(exec, args); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1580 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1581 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1582 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1583 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1584 |
JSC::JSValue QScriptEnginePrivate::newRegExp(JSC::ExecState *exec, const QString &pattern, const QString &flags) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1585 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1586 |
JSC::JSValue buf[2]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1587 |
JSC::ArgList args(buf, sizeof(buf)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1588 |
JSC::UString jscPattern = pattern; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1589 |
QString strippedFlags; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1590 |
if (flags.contains(QLatin1Char('i'))) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1591 |
strippedFlags += QLatin1Char('i'); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1592 |
if (flags.contains(QLatin1Char('m'))) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1593 |
strippedFlags += QLatin1Char('m'); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1594 |
if (flags.contains(QLatin1Char('g'))) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1595 |
strippedFlags += QLatin1Char('g'); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1596 |
JSC::UString jscFlags = strippedFlags; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1597 |
buf[0] = JSC::jsString(exec, jscPattern); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1598 |
buf[1] = JSC::jsString(exec, jscFlags); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1599 |
return JSC::constructRegExp(exec, args); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1600 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1601 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1602 |
JSC::JSValue QScriptEnginePrivate::newVariant(const QVariant &value) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1603 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1604 |
QScriptObject *obj = new (currentFrame) QScriptObject(variantWrapperObjectStructure); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1605 |
obj->setDelegate(new QScript::QVariantDelegate(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1606 |
JSC::JSValue proto = defaultPrototype(value.userType()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1607 |
if (proto) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1608 |
obj->setPrototype(proto); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1609 |
return obj; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1610 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1611 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1612 |
JSC::JSValue QScriptEnginePrivate::newVariant(JSC::JSValue objectValue, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1613 |
const QVariant &value) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1614 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1615 |
if (!isObject(objectValue)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1616 |
return newVariant(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1617 |
JSC::JSObject *jscObject = JSC::asObject(objectValue); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1618 |
if (!jscObject->inherits(&QScriptObject::info)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1619 |
qWarning("QScriptEngine::newVariant(): changing class of non-QScriptObject not supported"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1620 |
return JSC::JSValue(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1621 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1622 |
QScriptObject *jscScriptObject = static_cast<QScriptObject*>(jscObject); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1623 |
if (!isVariant(objectValue)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1624 |
jscScriptObject->setDelegate(new QScript::QVariantDelegate(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1625 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1626 |
setVariantValue(objectValue, value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1627 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1628 |
return objectValue; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1629 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1630 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1631 |
#ifndef QT_NO_REGEXP |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1632 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1633 |
QRegExp QScriptEnginePrivate::toRegExp(JSC::ExecState *exec, JSC::JSValue value) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1634 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1635 |
if (!isRegExp(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1636 |
return QRegExp(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1637 |
QString pattern = toString(exec, property(exec, value, "source", QScriptValue::ResolvePrototype)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1638 |
Qt::CaseSensitivity kase = Qt::CaseSensitive; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1639 |
if (toBool(exec, property(exec, value, "ignoreCase", QScriptValue::ResolvePrototype))) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1640 |
kase = Qt::CaseInsensitive; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1641 |
return QRegExp(pattern, kase, QRegExp::RegExp2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1642 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1643 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1644 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1645 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1646 |
QVariant QScriptEnginePrivate::toVariant(JSC::ExecState *exec, JSC::JSValue value) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1647 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1648 |
if (!value) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1649 |
return QVariant(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1650 |
} else if (isObject(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1651 |
if (isVariant(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1652 |
return variantValue(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1653 |
#ifndef QT_NO_QOBJECT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1654 |
else if (isQObject(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1655 |
return qVariantFromValue(toQObject(exec, value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1656 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1657 |
else if (isDate(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1658 |
return QVariant(toDateTime(exec, value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1659 |
#ifndef QT_NO_REGEXP |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1660 |
else if (isRegExp(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1661 |
return QVariant(toRegExp(exec, value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1662 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1663 |
else if (isArray(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1664 |
return variantListFromArray(exec, value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1665 |
else if (QScriptDeclarativeClass *dc = declarativeClass(value)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1666 |
return dc->toVariant(declarativeObject(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1667 |
// try to convert to primitive |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1668 |
JSC::JSValue savedException; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1669 |
saveException(exec, &savedException); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1670 |
JSC::JSValue prim = value.toPrimitive(exec); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1671 |
restoreException(exec, savedException); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1672 |
if (!prim.isObject()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1673 |
return toVariant(exec, prim); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1674 |
} else if (value.isNumber()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1675 |
return QVariant(toNumber(exec, value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1676 |
} else if (value.isString()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1677 |
return QVariant(toString(exec, value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1678 |
} else if (value.isBoolean()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1679 |
return QVariant(toBool(exec, value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1680 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1681 |
return QVariant(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1682 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1683 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1684 |
JSC::JSValue QScriptEnginePrivate::propertyHelper(JSC::ExecState *exec, JSC::JSValue value, const JSC::Identifier &id, int resolveMode) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1685 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1686 |
JSC::JSValue result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1687 |
if (!(resolveMode & QScriptValue::ResolvePrototype)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1688 |
// Look in the object's own properties |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1689 |
JSC::JSObject *object = JSC::asObject(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1690 |
JSC::PropertySlot slot(object); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1691 |
if (object->getOwnPropertySlot(exec, id, slot)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1692 |
result = slot.getValue(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1693 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1694 |
if (!result && (resolveMode & QScriptValue::ResolveScope)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1695 |
// ### check if it's a function object and look in the scope chain |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1696 |
JSC::JSValue scope = property(exec, value, "__qt_scope__", QScriptValue::ResolveLocal); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1697 |
if (isObject(scope)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1698 |
result = property(exec, scope, id, resolveMode); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1699 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1700 |
return result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1701 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1702 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1703 |
JSC::JSValue QScriptEnginePrivate::propertyHelper(JSC::ExecState *exec, JSC::JSValue value, quint32 index, int resolveMode) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1704 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1705 |
JSC::JSValue result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1706 |
if (!(resolveMode & QScriptValue::ResolvePrototype)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1707 |
// Look in the object's own properties |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1708 |
JSC::JSObject *object = JSC::asObject(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1709 |
JSC::PropertySlot slot(object); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1710 |
if (object->getOwnPropertySlot(exec, index, slot)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1711 |
result = slot.getValue(exec, index); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1712 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1713 |
return result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1714 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1715 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1716 |
void QScriptEnginePrivate::setProperty(JSC::ExecState *exec, JSC::JSValue objectValue, const JSC::Identifier &id, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1717 |
JSC::JSValue value, const QScriptValue::PropertyFlags &flags) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1718 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1719 |
JSC::JSObject *thisObject = JSC::asObject(objectValue); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1720 |
JSC::JSValue setter = thisObject->lookupSetter(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1721 |
JSC::JSValue getter = thisObject->lookupGetter(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1722 |
if ((flags & QScriptValue::PropertyGetter) || (flags & QScriptValue::PropertySetter)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1723 |
if (!value) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1724 |
// deleting getter/setter |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1725 |
if ((flags & QScriptValue::PropertyGetter) && (flags & QScriptValue::PropertySetter)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1726 |
// deleting both: just delete the property |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1727 |
thisObject->deleteProperty(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1728 |
} else if (flags & QScriptValue::PropertyGetter) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1729 |
// preserve setter, if there is one |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1730 |
thisObject->deleteProperty(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1731 |
if (setter && setter.isObject()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1732 |
thisObject->defineSetter(exec, id, JSC::asObject(setter)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1733 |
} else { // flags & QScriptValue::PropertySetter |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1734 |
// preserve getter, if there is one |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1735 |
thisObject->deleteProperty(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1736 |
if (getter && getter.isObject()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1737 |
thisObject->defineGetter(exec, id, JSC::asObject(getter)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1738 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1739 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1740 |
if (value.isObject()) { // ### should check if it has callData() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1741 |
// defining getter/setter |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1742 |
if (id == exec->propertyNames().underscoreProto) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1743 |
qWarning("QScriptValue::setProperty() failed: " |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1744 |
"cannot set getter or setter of native property `__proto__'"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1745 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1746 |
if (flags & QScriptValue::PropertyGetter) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1747 |
thisObject->defineGetter(exec, id, JSC::asObject(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1748 |
if (flags & QScriptValue::PropertySetter) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1749 |
thisObject->defineSetter(exec, id, JSC::asObject(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1750 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1751 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1752 |
qWarning("QScriptValue::setProperty(): getter/setter must be a function"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1753 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1754 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1755 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1756 |
// setting the value |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1757 |
if (getter && getter.isObject() && !(setter && setter.isObject())) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1758 |
qWarning("QScriptValue::setProperty() failed: " |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1759 |
"property '%s' has a getter but no setter", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1760 |
qPrintable(QString(id.ustring()))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1761 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1762 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1763 |
if (!value) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1764 |
// ### check if it's a getter/setter property |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1765 |
thisObject->deleteProperty(exec, id); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1766 |
} else if (flags != QScriptValue::KeepExistingFlags) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1767 |
if (thisObject->hasOwnProperty(exec, id)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1768 |
thisObject->deleteProperty(exec, id); // ### hmmm - can't we just update the attributes? |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1769 |
unsigned attribs = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1770 |
if (flags & QScriptValue::ReadOnly) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1771 |
attribs |= JSC::ReadOnly; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1772 |
if (flags & QScriptValue::SkipInEnumeration) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1773 |
attribs |= JSC::DontEnum; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1774 |
if (flags & QScriptValue::Undeletable) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1775 |
attribs |= JSC::DontDelete; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1776 |
attribs |= flags & QScriptValue::UserRange; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1777 |
thisObject->putWithAttributes(exec, id, value, attribs); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1778 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1779 |
JSC::PutPropertySlot slot; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1780 |
thisObject->put(exec, id, value, slot); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1781 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1782 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1783 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1784 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1785 |
void QScriptEnginePrivate::setProperty(JSC::ExecState *exec, JSC::JSValue objectValue, quint32 index, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1786 |
JSC::JSValue value, const QScriptValue::PropertyFlags &flags) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1787 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1788 |
if (!value) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1789 |
JSC::asObject(objectValue)->deleteProperty(exec, index); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1790 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1791 |
if ((flags & QScriptValue::PropertyGetter) || (flags & QScriptValue::PropertySetter)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1792 |
// fall back to string-based setProperty(), since there is no |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1793 |
// JSC::JSObject::defineGetter(unsigned) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1794 |
setProperty(exec, objectValue, JSC::Identifier::from(exec, index), value, flags); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1795 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1796 |
if (flags != QScriptValue::KeepExistingFlags) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1797 |
// if (JSC::asObject(d->jscValue)->hasOwnProperty(exec, arrayIndex)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1798 |
// JSC::asObject(d->jscValue)->deleteProperty(exec, arrayIndex); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1799 |
unsigned attribs = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1800 |
if (flags & QScriptValue::ReadOnly) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1801 |
attribs |= JSC::ReadOnly; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1802 |
if (flags & QScriptValue::SkipInEnumeration) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1803 |
attribs |= JSC::DontEnum; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1804 |
if (flags & QScriptValue::Undeletable) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1805 |
attribs |= JSC::DontDelete; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1806 |
attribs |= flags & QScriptValue::UserRange; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1807 |
JSC::asObject(objectValue)->putWithAttributes(exec, index, value, attribs); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1808 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1809 |
JSC::asObject(objectValue)->put(exec, index, value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1810 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1811 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1812 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1813 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1814 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1815 |
QScriptValue::PropertyFlags QScriptEnginePrivate::propertyFlags(JSC::ExecState *exec, JSC::JSValue value, const JSC::Identifier &id, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1816 |
const QScriptValue::ResolveFlags &mode) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1817 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1818 |
JSC::JSObject *object = JSC::asObject(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1819 |
unsigned attribs = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1820 |
JSC::PropertyDescriptor descriptor; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1821 |
if (object->getOwnPropertyDescriptor(exec, id, descriptor)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1822 |
attribs = descriptor.attributes(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1823 |
else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1824 |
if ((mode & QScriptValue::ResolvePrototype) && object->prototype() && object->prototype().isObject()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1825 |
JSC::JSValue proto = object->prototype(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1826 |
return propertyFlags(exec, proto, id, mode); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1827 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1828 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1829 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1830 |
QScriptValue::PropertyFlags result = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1831 |
if (attribs & JSC::ReadOnly) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1832 |
result |= QScriptValue::ReadOnly; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1833 |
if (attribs & JSC::DontEnum) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1834 |
result |= QScriptValue::SkipInEnumeration; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1835 |
if (attribs & JSC::DontDelete) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1836 |
result |= QScriptValue::Undeletable; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1837 |
//We cannot rely on attribs JSC::Setter/Getter because they are not necesserly set by JSC (bug?) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1838 |
if (attribs & JSC::Getter || !object->lookupGetter(exec, id).isUndefinedOrNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1839 |
result |= QScriptValue::PropertyGetter; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1840 |
if (attribs & JSC::Setter || !object->lookupSetter(exec, id).isUndefinedOrNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1841 |
result |= QScriptValue::PropertySetter; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1842 |
#ifndef QT_NO_QOBJECT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1843 |
if (attribs & QScript::QObjectMemberAttribute) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1844 |
result |= QScriptValue::QObjectMember; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1845 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1846 |
result |= QScriptValue::PropertyFlag(attribs & QScriptValue::UserRange); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1847 |
return result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1848 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1849 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1850 |
QScriptString QScriptEnginePrivate::toStringHandle(const JSC::Identifier &name) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1851 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1852 |
QScriptString result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1853 |
QScriptStringPrivate *p = new QScriptStringPrivate(this, name, QScriptStringPrivate::HeapAllocated); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1854 |
QScriptStringPrivate::init(result, p); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1855 |
registerScriptString(p); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1856 |
return result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1857 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1858 |
|
0 | 1859 |
#ifdef QT_NO_QOBJECT |
1860 |
||
1861 |
QScriptEngine::QScriptEngine() |
|
1862 |
: d_ptr(new QScriptEnginePrivate) |
|
1863 |
{ |
|
1864 |
d_ptr->q_ptr = this; |
|
1865 |
} |
|
1866 |
||
1867 |
/*! \internal |
|
1868 |
*/ |
|
1869 |
QScriptEngine::QScriptEngine(QScriptEnginePrivate &dd) |
|
1870 |
: d_ptr(&dd) |
|
1871 |
{ |
|
1872 |
d_ptr->q_ptr = this; |
|
1873 |
} |
|
1874 |
#else |
|
1875 |
||
1876 |
/*! |
|
1877 |
Constructs a QScriptEngine object. |
|
1878 |
||
1879 |
The globalObject() is initialized to have properties as described in |
|
1880 |
\l{ECMA-262}, Section 15.1. |
|
1881 |
*/ |
|
1882 |
QScriptEngine::QScriptEngine() |
|
1883 |
: QObject(*new QScriptEnginePrivate, 0) |
|
1884 |
{ |
|
1885 |
} |
|
1886 |
||
1887 |
/*! |
|
1888 |
Constructs a QScriptEngine object with the given \a parent. |
|
1889 |
||
1890 |
The globalObject() is initialized to have properties as described in |
|
1891 |
\l{ECMA-262}, Section 15.1. |
|
1892 |
*/ |
|
1893 |
||
1894 |
QScriptEngine::QScriptEngine(QObject *parent) |
|
1895 |
: QObject(*new QScriptEnginePrivate, parent) |
|
1896 |
{ |
|
1897 |
} |
|
1898 |
||
1899 |
/*! \internal |
|
1900 |
*/ |
|
1901 |
QScriptEngine::QScriptEngine(QScriptEnginePrivate &dd, QObject *parent) |
|
1902 |
: QObject(dd, parent) |
|
1903 |
{ |
|
1904 |
} |
|
1905 |
#endif |
|
1906 |
||
1907 |
/*! |
|
1908 |
Destroys this QScriptEngine. |
|
1909 |
*/ |
|
1910 |
QScriptEngine::~QScriptEngine() |
|
1911 |
{ |
|
1912 |
#ifdef QT_NO_QOBJECT |
|
1913 |
delete d_ptr; |
|
1914 |
d_ptr = 0; |
|
1915 |
#endif |
|
1916 |
} |
|
1917 |
||
1918 |
/*! |
|
1919 |
Returns this engine's Global Object. |
|
1920 |
||
1921 |
By default, the Global Object contains the built-in objects that are |
|
1922 |
part of \l{ECMA-262}, such as Math, Date and String. Additionally, |
|
1923 |
you can set properties of the Global Object to make your own |
|
1924 |
extensions available to all script code. Non-local variables in |
|
1925 |
script code will be created as properties of the Global Object, as |
|
1926 |
well as local variables in global code. |
|
1927 |
*/ |
|
1928 |
QScriptValue QScriptEngine::globalObject() const |
|
1929 |
{ |
|
1930 |
Q_D(const QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1931 |
QScript::APIShim shim(const_cast<QScriptEnginePrivate*>(d)); |
0 | 1932 |
JSC::JSObject *result = d->globalObject(); |
1933 |
return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(result); |
|
1934 |
} |
|
1935 |
||
1936 |
/*! |
|
1937 |
\since 4.5 |
|
1938 |
||
1939 |
Sets this engine's Global Object to be the given \a object. |
|
1940 |
If \a object is not a valid script object, this function does |
|
1941 |
nothing. |
|
1942 |
||
1943 |
When setting a custom global object, you may want to use |
|
1944 |
QScriptValueIterator to copy the properties of the standard Global |
|
1945 |
Object; alternatively, you can set the internal prototype of your |
|
1946 |
custom object to be the original Global Object. |
|
1947 |
*/ |
|
1948 |
void QScriptEngine::setGlobalObject(const QScriptValue &object) |
|
1949 |
{ |
|
1950 |
Q_D(QScriptEngine); |
|
1951 |
if (!object.isObject()) |
|
1952 |
return; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
1953 |
QScript::APIShim shim(d); |
0 | 1954 |
JSC::JSObject *jscObject = JSC::asObject(d->scriptValueToJSCValue(object)); |
1955 |
d->setGlobalObject(jscObject); |
|
1956 |
} |
|
1957 |
||
1958 |
/*! |
|
1959 |
Returns a QScriptValue of the primitive type Null. |
|
1960 |
||
1961 |
\sa undefinedValue() |
|
1962 |
*/ |
|
1963 |
QScriptValue QScriptEngine::nullValue() |
|
1964 |
{ |
|
1965 |
Q_D(QScriptEngine); |
|
1966 |
return d->scriptValueFromJSCValue(JSC::jsNull()); |
|
1967 |
} |
|
1968 |
||
1969 |
/*! |
|
1970 |
Returns a QScriptValue of the primitive type Undefined. |
|
1971 |
||
1972 |
\sa nullValue() |
|
1973 |
*/ |
|
1974 |
QScriptValue QScriptEngine::undefinedValue() |
|
1975 |
{ |
|
1976 |
Q_D(QScriptEngine); |
|
1977 |
return d->scriptValueFromJSCValue(JSC::jsUndefined()); |
|
1978 |
} |
|
1979 |
||
1980 |
/*! |
|
1981 |
Creates a constructor function from \a fun, with the given \a length. |
|
1982 |
The \c{prototype} property of the resulting function is set to be the |
|
1983 |
given \a prototype. The \c{constructor} property of \a prototype is |
|
1984 |
set to be the resulting function. |
|
1985 |
||
1986 |
When a function is called as a constructor (e.g. \c{new Foo()}), the |
|
1987 |
`this' object associated with the function call is the new object |
|
1988 |
that the function is expected to initialize; the prototype of this |
|
1989 |
default constructed object will be the function's public |
|
1990 |
\c{prototype} property. If you always want the function to behave as |
|
1991 |
a constructor (e.g. \c{Foo()} should also create a new object), or |
|
1992 |
if you need to create your own object rather than using the default |
|
1993 |
`this' object, you should make sure that the prototype of your |
|
1994 |
object is set correctly; either by setting it manually, or, when |
|
1995 |
wrapping a custom type, by having registered the defaultPrototype() |
|
1996 |
of that type. Example: |
|
1997 |
||
1998 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 9 |
|
1999 |
||
2000 |
To wrap a custom type and provide a constructor for it, you'd typically |
|
2001 |
do something like this: |
|
2002 |
||
2003 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 10 |
|
2004 |
*/ |
|
2005 |
QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionSignature fun, |
|
2006 |
const QScriptValue &prototype, |
|
2007 |
int length) |
|
2008 |
{ |
|
2009 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2010 |
QScript::APIShim shim(d); |
0 | 2011 |
JSC::ExecState* exec = d->currentFrame; |
2012 |
JSC::JSValue function = new (exec)QScript::FunctionWrapper(exec, length, JSC::Identifier(exec, ""), fun); |
|
2013 |
QScriptValue result = d->scriptValueFromJSCValue(function); |
|
2014 |
result.setProperty(QLatin1String("prototype"), prototype, QScriptValue::Undeletable); |
|
2015 |
const_cast<QScriptValue&>(prototype) |
|
2016 |
.setProperty(QLatin1String("constructor"), result, |
|
2017 |
QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); |
|
2018 |
return result; |
|
2019 |
} |
|
2020 |
||
2021 |
#ifndef QT_NO_REGEXP |
|
2022 |
||
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2023 |
Q_DECL_IMPORT extern QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax); |
0 | 2024 |
|
2025 |
/*! |
|
2026 |
Creates a QtScript object of class RegExp with the given |
|
2027 |
\a regexp. |
|
2028 |
||
2029 |
\sa QScriptValue::toRegExp() |
|
2030 |
*/ |
|
2031 |
QScriptValue QScriptEngine::newRegExp(const QRegExp ®exp) |
|
2032 |
{ |
|
2033 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2034 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2035 |
return d->scriptValueFromJSCValue(d->newRegExp(d->currentFrame, regexp)); |
0 | 2036 |
} |
2037 |
||
2038 |
#endif // QT_NO_REGEXP |
|
2039 |
||
2040 |
/*! |
|
2041 |
Creates a QtScript object holding the given variant \a value. |
|
2042 |
||
2043 |
If a default prototype has been registered with the meta type id of |
|
2044 |
\a value, then the prototype of the created object will be that |
|
2045 |
prototype; otherwise, the prototype will be the Object prototype |
|
2046 |
object. |
|
2047 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2048 |
\sa setDefaultPrototype(), QScriptValue::toVariant(), reportAdditionalMemoryCost() |
0 | 2049 |
*/ |
2050 |
QScriptValue QScriptEngine::newVariant(const QVariant &value) |
|
2051 |
{ |
|
2052 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2053 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2054 |
return d->scriptValueFromJSCValue(d->newVariant(value)); |
0 | 2055 |
} |
2056 |
||
2057 |
/*! |
|
2058 |
\since 4.4 |
|
2059 |
\overload |
|
2060 |
||
2061 |
Initializes the given Qt Script \a object to hold the given variant |
|
2062 |
\a value, and returns the \a object. |
|
2063 |
||
2064 |
This function enables you to "promote" a plain Qt Script object |
|
2065 |
(created by the newObject() function) to a variant, or to replace |
|
2066 |
the variant contained inside an object previously created by the |
|
2067 |
newVariant() function. |
|
2068 |
||
2069 |
The prototype() of the \a object will remain unchanged. |
|
2070 |
||
2071 |
If \a object is not an object, this function behaves like the normal |
|
2072 |
newVariant(), i.e. it creates a new script object and returns it. |
|
2073 |
||
2074 |
This function is useful when you want to provide a script |
|
2075 |
constructor for a C++ type. If your constructor is invoked in a |
|
2076 |
\c{new} expression (QScriptContext::isCalledAsConstructor() returns |
|
2077 |
true), you can pass QScriptContext::thisObject() (the default |
|
2078 |
constructed script object) to this function to initialize the new |
|
2079 |
object. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2080 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2081 |
\sa reportAdditionalMemoryCost() |
0 | 2082 |
*/ |
2083 |
QScriptValue QScriptEngine::newVariant(const QScriptValue &object, |
|
2084 |
const QVariant &value) |
|
2085 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2086 |
Q_D(QScriptEngine); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2087 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2088 |
JSC::JSValue jsObject = d->scriptValueToJSCValue(object); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2089 |
return d->scriptValueFromJSCValue(d->newVariant(jsObject, value)); |
0 | 2090 |
} |
2091 |
||
2092 |
#ifndef QT_NO_QOBJECT |
|
2093 |
/*! |
|
2094 |
Creates a QtScript object that wraps the given QObject \a |
|
2095 |
object, using the given \a ownership. The given \a options control |
|
2096 |
various aspects of the interaction with the resulting script object. |
|
2097 |
||
2098 |
Signals and slots, properties and children of \a object are |
|
2099 |
available as properties of the created QScriptValue. For more |
|
2100 |
information, see the \l{QtScript} documentation. |
|
2101 |
||
2102 |
If \a object is a null pointer, this function returns nullValue(). |
|
2103 |
||
2104 |
If a default prototype has been registered for the \a object's class |
|
2105 |
(or its superclass, recursively), the prototype of the new script |
|
2106 |
object will be set to be that default prototype. |
|
2107 |
||
2108 |
If the given \a object is deleted outside of QtScript's control, any |
|
2109 |
attempt to access the deleted QObject's members through the QtScript |
|
2110 |
wrapper object (either by script code or C++) will result in a |
|
2111 |
script exception. |
|
2112 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2113 |
\sa QScriptValue::toQObject(), reportAdditionalMemoryCost() |
0 | 2114 |
*/ |
2115 |
QScriptValue QScriptEngine::newQObject(QObject *object, ValueOwnership ownership, |
|
2116 |
const QObjectWrapOptions &options) |
|
2117 |
{ |
|
2118 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2119 |
QScript::APIShim shim(d); |
0 | 2120 |
JSC::JSValue jscQObject = d->newQObject(object, ownership, options); |
2121 |
return d->scriptValueFromJSCValue(jscQObject); |
|
2122 |
} |
|
2123 |
||
2124 |
/*! |
|
2125 |
\since 4.4 |
|
2126 |
\overload |
|
2127 |
||
2128 |
Initializes the given \a scriptObject to hold the given \a qtObject, |
|
2129 |
and returns the \a scriptObject. |
|
2130 |
||
2131 |
This function enables you to "promote" a plain Qt Script object |
|
2132 |
(created by the newObject() function) to a QObject proxy, or to |
|
2133 |
replace the QObject contained inside an object previously created by |
|
2134 |
the newQObject() function. |
|
2135 |
||
2136 |
The prototype() of the \a scriptObject will remain unchanged. |
|
2137 |
||
2138 |
If \a scriptObject is not an object, this function behaves like the |
|
2139 |
normal newQObject(), i.e. it creates a new script object and returns |
|
2140 |
it. |
|
2141 |
||
2142 |
This function is useful when you want to provide a script |
|
2143 |
constructor for a QObject-based class. If your constructor is |
|
2144 |
invoked in a \c{new} expression |
|
2145 |
(QScriptContext::isCalledAsConstructor() returns true), you can pass |
|
2146 |
QScriptContext::thisObject() (the default constructed script object) |
|
2147 |
to this function to initialize the new object. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2148 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2149 |
\sa reportAdditionalMemoryCost() |
0 | 2150 |
*/ |
2151 |
QScriptValue QScriptEngine::newQObject(const QScriptValue &scriptObject, |
|
2152 |
QObject *qtObject, |
|
2153 |
ValueOwnership ownership, |
|
2154 |
const QObjectWrapOptions &options) |
|
2155 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2156 |
Q_D(QScriptEngine); |
0 | 2157 |
if (!scriptObject.isObject()) |
2158 |
return newQObject(qtObject, ownership, options); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2159 |
QScript::APIShim shim(d); |
0 | 2160 |
JSC::JSObject *jscObject = JSC::asObject(QScriptValuePrivate::get(scriptObject)->jscValue); |
2161 |
if (!jscObject->inherits(&QScriptObject::info)) { |
|
2162 |
qWarning("QScriptEngine::newQObject(): changing class of non-QScriptObject not supported"); |
|
2163 |
return QScriptValue(); |
|
2164 |
} |
|
2165 |
QScriptObject *jscScriptObject = static_cast<QScriptObject*>(jscObject); |
|
2166 |
if (!scriptObject.isQObject()) { |
|
2167 |
jscScriptObject->setDelegate(new QScript::QObjectDelegate(qtObject, ownership, options)); |
|
2168 |
} else { |
|
2169 |
QScript::QObjectDelegate *delegate = static_cast<QScript::QObjectDelegate*>(jscScriptObject->delegate()); |
|
2170 |
delegate->setValue(qtObject); |
|
2171 |
delegate->setOwnership(ownership); |
|
2172 |
delegate->setOptions(options); |
|
2173 |
} |
|
2174 |
return scriptObject; |
|
2175 |
} |
|
2176 |
||
2177 |
#endif // QT_NO_QOBJECT |
|
2178 |
||
2179 |
/*! |
|
2180 |
Creates a QtScript object of class Object. |
|
2181 |
||
2182 |
The prototype of the created object will be the Object |
|
2183 |
prototype object. |
|
2184 |
||
2185 |
\sa newArray(), QScriptValue::setProperty() |
|
2186 |
*/ |
|
2187 |
QScriptValue QScriptEngine::newObject() |
|
2188 |
{ |
|
2189 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2190 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2191 |
return d->scriptValueFromJSCValue(d->newObject()); |
0 | 2192 |
} |
2193 |
||
2194 |
/*! |
|
2195 |
\since 4.4 |
|
2196 |
\overload |
|
2197 |
||
2198 |
Creates a QtScript Object of the given class, \a scriptClass. |
|
2199 |
||
2200 |
The prototype of the created object will be the Object |
|
2201 |
prototype object. |
|
2202 |
||
2203 |
\a data, if specified, is set as the internal data of the |
|
2204 |
new object (using QScriptValue::setData()). |
|
2205 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2206 |
\sa QScriptValue::scriptClass(), reportAdditionalMemoryCost() |
0 | 2207 |
*/ |
2208 |
QScriptValue QScriptEngine::newObject(QScriptClass *scriptClass, |
|
2209 |
const QScriptValue &data) |
|
2210 |
{ |
|
2211 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2212 |
QScript::APIShim shim(d); |
0 | 2213 |
JSC::ExecState* exec = d->currentFrame; |
2214 |
QScriptObject *result = new (exec) QScriptObject(d->scriptObjectStructure); |
|
2215 |
result->setDelegate(new QScript::ClassObjectDelegate(scriptClass)); |
|
2216 |
QScriptValue scriptObject = d->scriptValueFromJSCValue(result); |
|
2217 |
scriptObject.setData(data); |
|
2218 |
QScriptValue proto = scriptClass->prototype(); |
|
2219 |
if (proto.isValid()) |
|
2220 |
scriptObject.setPrototype(proto); |
|
2221 |
return scriptObject; |
|
2222 |
} |
|
2223 |
||
2224 |
/*! |
|
2225 |
\internal |
|
2226 |
*/ |
|
2227 |
QScriptValue QScriptEngine::newActivationObject() |
|
2228 |
{ |
|
2229 |
qWarning("QScriptEngine::newActivationObject() not implemented"); |
|
2230 |
// ### JSActivation or JSVariableObject? |
|
2231 |
return QScriptValue(); |
|
2232 |
} |
|
2233 |
||
2234 |
/*! |
|
2235 |
Creates a QScriptValue that wraps a native (C++) function. \a fun |
|
2236 |
must be a C++ function with signature QScriptEngine::FunctionSignature. \a |
|
2237 |
length is the number of arguments that \a fun expects; this becomes |
|
2238 |
the \c{length} property of the created QScriptValue. |
|
2239 |
||
2240 |
Note that \a length only gives an indication of the number of |
|
2241 |
arguments that the function expects; an actual invocation of a |
|
2242 |
function can include any number of arguments. You can check the |
|
2243 |
\l{QScriptContext::argumentCount()}{argumentCount()} of the |
|
2244 |
QScriptContext associated with the invocation to determine the |
|
2245 |
actual number of arguments passed. |
|
2246 |
||
2247 |
A \c{prototype} property is automatically created for the resulting |
|
2248 |
function object, to provide for the possibility that the function |
|
2249 |
will be used as a constructor. |
|
2250 |
||
2251 |
By combining newFunction() and the property flags |
|
2252 |
QScriptValue::PropertyGetter and QScriptValue::PropertySetter, you |
|
2253 |
can create script object properties that behave like normal |
|
2254 |
properties in script code, but are in fact accessed through |
|
2255 |
functions (analogous to how properties work in \l{Qt's Property |
|
2256 |
System}). Example: |
|
2257 |
||
2258 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 11 |
|
2259 |
||
2260 |
When the property \c{foo} of the script object is subsequently |
|
2261 |
accessed in script code, \c{getSetFoo()} will be invoked to handle |
|
2262 |
the access. In this particular case, we chose to store the "real" |
|
2263 |
value of \c{foo} as a property of the accessor function itself; you |
|
2264 |
are of course free to do whatever you like in this function. |
|
2265 |
||
2266 |
In the above example, a single native function was used to handle |
|
2267 |
both reads and writes to the property; the argument count is used to |
|
2268 |
determine if we are handling a read or write. You can also use two |
|
2269 |
separate functions; just specify the relevant flag |
|
2270 |
(QScriptValue::PropertyGetter or QScriptValue::PropertySetter) when |
|
2271 |
setting the property, e.g.: |
|
2272 |
||
2273 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 12 |
|
2274 |
||
2275 |
\sa QScriptValue::call() |
|
2276 |
*/ |
|
2277 |
QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionSignature fun, int length) |
|
2278 |
{ |
|
2279 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2280 |
QScript::APIShim shim(d); |
0 | 2281 |
JSC::ExecState* exec = d->currentFrame; |
2282 |
JSC::JSValue function = new (exec)QScript::FunctionWrapper(exec, length, JSC::Identifier(exec, ""), fun); |
|
2283 |
QScriptValue result = d->scriptValueFromJSCValue(function); |
|
2284 |
QScriptValue proto = newObject(); |
|
2285 |
result.setProperty(QLatin1String("prototype"), proto, QScriptValue::Undeletable); |
|
2286 |
proto.setProperty(QLatin1String("constructor"), result, |
|
2287 |
QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); |
|
2288 |
return result; |
|
2289 |
} |
|
2290 |
||
2291 |
/*! |
|
2292 |
\internal |
|
2293 |
\since 4.4 |
|
2294 |
*/ |
|
2295 |
QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionWithArgSignature fun, void *arg) |
|
2296 |
{ |
|
2297 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2298 |
QScript::APIShim shim(d); |
0 | 2299 |
JSC::ExecState* exec = d->currentFrame; |
2300 |
JSC::JSValue function = new (exec)QScript::FunctionWithArgWrapper(exec, /*length=*/0, JSC::Identifier(exec, ""), fun, arg); |
|
2301 |
QScriptValue result = d->scriptValueFromJSCValue(function); |
|
2302 |
QScriptValue proto = newObject(); |
|
2303 |
result.setProperty(QLatin1String("prototype"), proto, QScriptValue::Undeletable); |
|
2304 |
proto.setProperty(QLatin1String("constructor"), result, |
|
2305 |
QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); |
|
2306 |
return result; |
|
2307 |
} |
|
2308 |
||
2309 |
/*! |
|
2310 |
Creates a QtScript object of class Array with the given \a length. |
|
2311 |
||
2312 |
\sa newObject() |
|
2313 |
*/ |
|
2314 |
QScriptValue QScriptEngine::newArray(uint length) |
|
2315 |
{ |
|
2316 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2317 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2318 |
return d->scriptValueFromJSCValue(d->newArray(d->currentFrame, length)); |
0 | 2319 |
} |
2320 |
||
2321 |
/*! |
|
2322 |
Creates a QtScript object of class RegExp with the given |
|
2323 |
\a pattern and \a flags. |
|
2324 |
||
2325 |
The legal flags are 'g' (global), 'i' (ignore case), and 'm' |
|
2326 |
(multiline). |
|
2327 |
*/ |
|
2328 |
QScriptValue QScriptEngine::newRegExp(const QString &pattern, const QString &flags) |
|
2329 |
{ |
|
2330 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2331 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2332 |
return d->scriptValueFromJSCValue(d->newRegExp(d->currentFrame, pattern, flags)); |
0 | 2333 |
} |
2334 |
||
2335 |
/*! |
|
2336 |
Creates a QtScript object of class Date with the given |
|
2337 |
\a value (the number of milliseconds since 01 January 1970, |
|
2338 |
UTC). |
|
2339 |
*/ |
|
2340 |
QScriptValue QScriptEngine::newDate(qsreal value) |
|
2341 |
{ |
|
2342 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2343 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2344 |
return d->scriptValueFromJSCValue(d->newDate(d->currentFrame, value)); |
0 | 2345 |
} |
2346 |
||
2347 |
/*! |
|
2348 |
Creates a QtScript object of class Date from the given \a value. |
|
2349 |
||
2350 |
\sa QScriptValue::toDateTime() |
|
2351 |
*/ |
|
2352 |
QScriptValue QScriptEngine::newDate(const QDateTime &value) |
|
2353 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2354 |
Q_D(QScriptEngine); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2355 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2356 |
return d->scriptValueFromJSCValue(d->newDate(d->currentFrame, value)); |
0 | 2357 |
} |
2358 |
||
2359 |
#ifndef QT_NO_QOBJECT |
|
2360 |
/*! |
|
2361 |
Creates a QtScript object that represents a QObject class, using the |
|
2362 |
the given \a metaObject and constructor \a ctor. |
|
2363 |
||
2364 |
Enums of \a metaObject (declared with Q_ENUMS) are available as |
|
2365 |
properties of the created QScriptValue. When the class is called as |
|
2366 |
a function, \a ctor will be called to create a new instance of the |
|
2367 |
class. |
|
2368 |
||
2369 |
Example: |
|
2370 |
||
2371 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 27 |
|
2372 |
||
2373 |
\sa newQObject(), scriptValueFromQMetaObject() |
|
2374 |
*/ |
|
2375 |
QScriptValue QScriptEngine::newQMetaObject( |
|
2376 |
const QMetaObject *metaObject, const QScriptValue &ctor) |
|
2377 |
{ |
|
2378 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2379 |
QScript::APIShim shim(d); |
0 | 2380 |
JSC::JSValue jscCtor = d->scriptValueToJSCValue(ctor); |
2381 |
JSC::JSValue jscQMetaObject = d->newQMetaObject(metaObject, jscCtor); |
|
2382 |
return d->scriptValueFromJSCValue(jscQMetaObject); |
|
2383 |
} |
|
2384 |
||
2385 |
/*! |
|
2386 |
\fn QScriptValue QScriptEngine::scriptValueFromQMetaObject() |
|
2387 |
||
2388 |
Creates a QScriptValue that represents the Qt class \c{T}. |
|
2389 |
||
2390 |
This function is used in combination with one of the |
|
2391 |
Q_SCRIPT_DECLARE_QMETAOBJECT() macro. Example: |
|
2392 |
||
2393 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 13 |
|
2394 |
||
2395 |
\warning This function is not available with MSVC 6. Use |
|
2396 |
qScriptValueFromQMetaObject() instead if you need to support that version |
|
2397 |
of the compiler. |
|
2398 |
||
2399 |
\sa QScriptEngine::newQMetaObject() |
|
2400 |
*/ |
|
2401 |
||
2402 |
/*! |
|
2403 |
\fn QScriptValue qScriptValueFromQMetaObject(QScriptEngine *engine) |
|
2404 |
\since 4.3 |
|
2405 |
\relates QScriptEngine |
|
2406 |
||
2407 |
Uses \a engine to create a QScriptValue that represents the Qt class |
|
2408 |
\c{T}. |
|
2409 |
||
2410 |
This function is equivalent to |
|
2411 |
QScriptEngine::scriptValueFromQMetaObject(). It is provided as a |
|
2412 |
work-around for MSVC 6, which doesn't support member template |
|
2413 |
functions. |
|
2414 |
||
2415 |
\sa QScriptEngine::newQMetaObject() |
|
2416 |
*/ |
|
2417 |
#endif // QT_NO_QOBJECT |
|
2418 |
||
2419 |
/*! |
|
2420 |
\obsolete |
|
2421 |
||
2422 |
Returns true if \a program can be evaluated; i.e. the code is |
|
2423 |
sufficient to determine whether it appears to be a syntactically |
|
2424 |
correct program, or contains a syntax error. |
|
2425 |
||
2426 |
This function returns false if \a program is incomplete; i.e. the |
|
2427 |
input is syntactically correct up to the point where the input is |
|
2428 |
terminated. |
|
2429 |
||
2430 |
Note that this function only does a static check of \a program; |
|
2431 |
e.g. it does not check whether references to variables are |
|
2432 |
valid, and so on. |
|
2433 |
||
2434 |
A typical usage of canEvaluate() is to implement an interactive |
|
2435 |
interpreter for QtScript. The user is repeatedly queried for |
|
2436 |
individual lines of code; the lines are concatened internally, and |
|
2437 |
only when canEvaluate() returns true for the resulting program is it |
|
2438 |
passed to evaluate(). |
|
2439 |
||
2440 |
The following are some examples to illustrate the behavior of |
|
2441 |
canEvaluate(). (Note that all example inputs are assumed to have an |
|
2442 |
explicit newline as their last character, since otherwise the |
|
2443 |
QtScript parser would automatically insert a semi-colon character at |
|
2444 |
the end of the input, and this could cause canEvaluate() to produce |
|
2445 |
different results.) |
|
2446 |
||
2447 |
Given the input |
|
2448 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 14 |
|
2449 |
canEvaluate() will return true, since the program appears to be complete. |
|
2450 |
||
2451 |
Given the input |
|
2452 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 15 |
|
2453 |
canEvaluate() will return false, since the if-statement is not complete, |
|
2454 |
but is syntactically correct so far. |
|
2455 |
||
2456 |
Given the input |
|
2457 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 16 |
|
2458 |
canEvaluate() will return true, but evaluate() will throw a |
|
2459 |
SyntaxError given the same input. |
|
2460 |
||
2461 |
Given the input |
|
2462 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 17 |
|
2463 |
canEvaluate() will return true, even though the code is clearly not |
|
2464 |
syntactically valid QtScript code. evaluate() will throw a |
|
2465 |
SyntaxError when this code is evaluated. |
|
2466 |
||
2467 |
Given the input |
|
2468 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 18 |
|
2469 |
canEvaluate() will return true, but evaluate() will throw a |
|
2470 |
ReferenceError if \c{foo} is not defined in the script |
|
2471 |
environment. |
|
2472 |
||
2473 |
\sa evaluate(), checkSyntax() |
|
2474 |
*/ |
|
2475 |
bool QScriptEngine::canEvaluate(const QString &program) const |
|
2476 |
{ |
|
2477 |
return QScriptEnginePrivate::canEvaluate(program); |
|
2478 |
} |
|
2479 |
||
2480 |
||
2481 |
bool QScriptEnginePrivate::canEvaluate(const QString &program) |
|
2482 |
{ |
|
2483 |
QScript::SyntaxChecker checker; |
|
2484 |
QScript::SyntaxChecker::Result result = checker.checkSyntax(program); |
|
2485 |
return (result.state != QScript::SyntaxChecker::Intermediate); |
|
2486 |
} |
|
2487 |
||
2488 |
/*! |
|
2489 |
\since 4.5 |
|
2490 |
||
2491 |
Checks the syntax of the given \a program. Returns a |
|
2492 |
QScriptSyntaxCheckResult object that contains the result of the check. |
|
2493 |
*/ |
|
2494 |
QScriptSyntaxCheckResult QScriptEngine::checkSyntax(const QString &program) |
|
2495 |
{ |
|
2496 |
return QScriptEnginePrivate::checkSyntax(program); |
|
2497 |
} |
|
2498 |
||
2499 |
QScriptSyntaxCheckResult QScriptEnginePrivate::checkSyntax(const QString &program) |
|
2500 |
{ |
|
2501 |
QScript::SyntaxChecker checker; |
|
2502 |
QScript::SyntaxChecker::Result result = checker.checkSyntax(program); |
|
2503 |
QScriptSyntaxCheckResultPrivate *p = new QScriptSyntaxCheckResultPrivate(); |
|
2504 |
switch (result.state) { |
|
2505 |
case QScript::SyntaxChecker::Error: |
|
2506 |
p->state = QScriptSyntaxCheckResult::Error; |
|
2507 |
break; |
|
2508 |
case QScript::SyntaxChecker::Intermediate: |
|
2509 |
p->state = QScriptSyntaxCheckResult::Intermediate; |
|
2510 |
break; |
|
2511 |
case QScript::SyntaxChecker::Valid: |
|
2512 |
p->state = QScriptSyntaxCheckResult::Valid; |
|
2513 |
break; |
|
2514 |
} |
|
2515 |
p->errorLineNumber = result.errorLineNumber; |
|
2516 |
p->errorColumnNumber = result.errorColumnNumber; |
|
2517 |
p->errorMessage = result.errorMessage; |
|
2518 |
return QScriptSyntaxCheckResult(p); |
|
2519 |
} |
|
2520 |
||
2521 |
||
2522 |
||
2523 |
/*! |
|
2524 |
Evaluates \a program, using \a lineNumber as the base line number, |
|
2525 |
and returns the result of the evaluation. |
|
2526 |
||
2527 |
The script code will be evaluated in the current context. |
|
2528 |
||
2529 |
The evaluation of \a program can cause an exception in the |
|
2530 |
engine; in this case the return value will be the exception |
|
2531 |
that was thrown (typically an \c{Error} object). You can call |
|
2532 |
hasUncaughtException() to determine if an exception occurred in |
|
2533 |
the last call to evaluate(). |
|
2534 |
||
2535 |
\a lineNumber is used to specify a starting line number for \a |
|
2536 |
program; line number information reported by the engine that pertain |
|
2537 |
to this evaluation (e.g. uncaughtExceptionLineNumber()) will be |
|
2538 |
based on this argument. For example, if \a program consists of two |
|
2539 |
lines of code, and the statement on the second line causes a script |
|
2540 |
exception, uncaughtExceptionLineNumber() would return the given \a |
|
2541 |
lineNumber plus one. When no starting line number is specified, line |
|
2542 |
numbers will be 1-based. |
|
2543 |
||
2544 |
\a fileName is used for error reporting. For example in error objects |
|
2545 |
the file name is accessible through the "fileName" property if it's |
|
2546 |
provided with this function. |
|
2547 |
||
2548 |
\sa canEvaluate(), hasUncaughtException(), isEvaluating(), abortEvaluation() |
|
2549 |
*/ |
|
2550 |
||
2551 |
QScriptValue QScriptEngine::evaluate(const QString &program, const QString &fileName, int lineNumber) |
|
2552 |
{ |
|
2553 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2554 |
QScript::APIShim shim(d); |
0 | 2555 |
WTF::PassRefPtr<QScript::UStringSourceProviderWithFeedback> provider |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2556 |
= QScript::UStringSourceProviderWithFeedback::create(program, fileName, lineNumber, d); |
0 | 2557 |
intptr_t sourceId = provider->asID(); |
2558 |
JSC::SourceCode source(provider, lineNumber); //after construction of SourceCode provider variable will be null. |
|
2559 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2560 |
JSC::ExecState* exec = d->currentFrame; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2561 |
WTF::RefPtr<JSC::EvalExecutable> executable = JSC::EvalExecutable::create(exec, source); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2562 |
bool compile = true; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2563 |
return d->scriptValueFromJSCValue(d->evaluateHelper(exec, sourceId, executable.get(), compile)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2564 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2565 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2566 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2567 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2568 |
\since 4.6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2569 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2570 |
Evaluates the given \a program and returns the result of the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2571 |
evaluation. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2572 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2573 |
QScriptValue QScriptEngine::evaluate(const QScriptProgram &program) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2574 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2575 |
Q_D(QScriptEngine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2576 |
QScriptProgramPrivate *program_d = QScriptProgramPrivate::get(program); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2577 |
if (!program_d) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2578 |
return QScriptValue(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2579 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2580 |
QScript::APIShim shim(d); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2581 |
JSC::ExecState* exec = d->currentFrame; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2582 |
JSC::EvalExecutable *executable = program_d->executable(exec, d); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2583 |
bool compile = !program_d->isCompiled; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2584 |
JSC::JSValue result = d->evaluateHelper(exec, program_d->sourceId, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2585 |
executable, compile); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2586 |
if (compile) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2587 |
program_d->isCompiled = true; |
0 | 2588 |
return d->scriptValueFromJSCValue(result); |
2589 |
} |
|
2590 |
||
2591 |
/*! |
|
2592 |
Returns the current context. |
|
2593 |
||
2594 |
The current context is typically accessed to retrieve the arguments |
|
2595 |
and `this' object in native functions; for convenience, it is |
|
2596 |
available as the first argument in QScriptEngine::FunctionSignature. |
|
2597 |
*/ |
|
2598 |
QScriptContext *QScriptEngine::currentContext() const |
|
2599 |
{ |
|
2600 |
Q_D(const QScriptEngine); |
|
2601 |
return const_cast<QScriptEnginePrivate*>(d)->contextForFrame(d->currentFrame); |
|
2602 |
} |
|
2603 |
||
2604 |
/*! |
|
2605 |
Enters a new execution context and returns the associated |
|
2606 |
QScriptContext object. |
|
2607 |
||
2608 |
Once you are done with the context, you should call popContext() to |
|
2609 |
restore the old context. |
|
2610 |
||
2611 |
By default, the `this' object of the new context is the Global Object. |
|
2612 |
The context's \l{QScriptContext::callee()}{callee}() will be invalid. |
|
2613 |
||
2614 |
This function is useful when you want to evaluate script code |
|
2615 |
as if it were the body of a function. You can use the context's |
|
2616 |
\l{QScriptContext::activationObject()}{activationObject}() to initialize |
|
2617 |
local variables that will be available to scripts. Example: |
|
2618 |
||
2619 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 19 |
|
2620 |
||
2621 |
In the above example, the new variable "tmp" defined in the script |
|
2622 |
will be local to the context; in other words, the script doesn't |
|
2623 |
have any effect on the global environment. |
|
2624 |
||
2625 |
Returns 0 in case of stack overflow |
|
2626 |
||
2627 |
\sa popContext() |
|
2628 |
*/ |
|
2629 |
QScriptContext *QScriptEngine::pushContext() |
|
2630 |
{ |
|
2631 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2632 |
QScript::APIShim shim(d); |
0 | 2633 |
|
2634 |
JSC::CallFrame* newFrame = d->pushContext(d->currentFrame, d->currentFrame->globalData().dynamicGlobalObject, |
|
2635 |
JSC::ArgList(), /*callee = */0); |
|
2636 |
||
2637 |
if (agent()) |
|
2638 |
agent()->contextPush(); |
|
2639 |
||
2640 |
return d->contextForFrame(newFrame); |
|
2641 |
} |
|
2642 |
||
2643 |
/*! \internal |
|
2644 |
push a context for a native function. |
|
2645 |
JSC native function doesn't have different stackframe or context. so we need to create one. |
|
2646 |
||
2647 |
use popContext right after to go back to the previous context the context if no stack overflow has hapenned |
|
2648 |
||
2649 |
exec is the current top frame. |
|
2650 |
||
2651 |
return the new top frame. (might be the same as exec if a new stackframe was not needed) or 0 if stack overflow |
|
2652 |
*/ |
|
2653 |
JSC::CallFrame *QScriptEnginePrivate::pushContext(JSC::CallFrame *exec, JSC::JSValue _thisObject, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2654 |
const JSC::ArgList& args, JSC::JSObject *callee, bool calledAsConstructor, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2655 |
bool clearScopeChain) |
0 | 2656 |
{ |
2657 |
JSC::JSValue thisObject = _thisObject; |
|
2658 |
if (calledAsConstructor) { |
|
2659 |
//JSC doesn't create default created object for native functions. so we do it |
|
2660 |
JSC::JSValue prototype = callee->get(exec, exec->propertyNames().prototype); |
|
2661 |
JSC::Structure *structure = prototype.isObject() ? JSC::asObject(prototype)->inheritorID() |
|
2662 |
: originalGlobalObject()->emptyObjectStructure(); |
|
2663 |
thisObject = new (exec) QScriptObject(structure); |
|
2664 |
} |
|
2665 |
||
2666 |
int flags = NativeContext; |
|
2667 |
if (calledAsConstructor) |
|
2668 |
flags |= CalledAsConstructorContext; |
|
2669 |
||
2670 |
//build a frame |
|
2671 |
JSC::CallFrame *newCallFrame = exec; |
|
2672 |
if (callee == 0 //called from public QScriptEngine::pushContext |
|
2673 |
|| exec->returnPC() == 0 || (contextFlags(exec) & NativeContext) //called from native-native call |
|
2674 |
|| (exec->codeBlock() && exec->callee() != callee)) { //the interpreter did not build a frame for us. |
|
2675 |
//We need to check if the Interpreter might have already created a frame for function called from JS. |
|
2676 |
JSC::Interpreter *interp = exec->interpreter(); |
|
2677 |
JSC::Register *oldEnd = interp->registerFile().end(); |
|
2678 |
int argc = args.size() + 1; //add "this" |
|
2679 |
JSC::Register *newEnd = oldEnd + argc + JSC::RegisterFile::CallFrameHeaderSize; |
|
2680 |
if (!interp->registerFile().grow(newEnd)) |
|
2681 |
return 0; //### Stack overflow |
|
2682 |
newCallFrame = JSC::CallFrame::create(oldEnd); |
|
2683 |
newCallFrame[0] = thisObject; |
|
2684 |
int dst = 0; |
|
2685 |
JSC::ArgList::const_iterator it; |
|
2686 |
for (it = args.begin(); it != args.end(); ++it) |
|
2687 |
newCallFrame[++dst] = *it; |
|
2688 |
newCallFrame += argc + JSC::RegisterFile::CallFrameHeaderSize; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2689 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2690 |
if (!clearScopeChain) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2691 |
newCallFrame->init(0, /*vPC=*/0, exec->scopeChain(), exec, flags | ShouldRestoreCallFrame, argc, callee); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2692 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2693 |
JSC::JSObject *jscObject = originalGlobalObject(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2694 |
JSC::ScopeChainNode *scn = new JSC::ScopeChainNode(0, jscObject, &exec->globalData(), exec->lexicalGlobalObject(), jscObject); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2695 |
newCallFrame->init(0, /*vPC=*/0, scn, exec, flags | ShouldRestoreCallFrame, argc, callee); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2696 |
} |
0 | 2697 |
} else { |
2698 |
setContextFlags(newCallFrame, flags); |
|
2699 |
#if ENABLE(JIT) |
|
2700 |
exec->registers()[JSC::RegisterFile::Callee] = JSC::JSValue(callee); //JIT let the callee set the 'callee' |
|
2701 |
#endif |
|
2702 |
if (calledAsConstructor) { |
|
2703 |
//update the new created this |
|
2704 |
JSC::Register* thisRegister = thisRegisterForFrame(newCallFrame); |
|
2705 |
*thisRegister = thisObject; |
|
2706 |
} |
|
2707 |
} |
|
2708 |
currentFrame = newCallFrame; |
|
2709 |
return newCallFrame; |
|
2710 |
} |
|
2711 |
||
2712 |
||
2713 |
/*! |
|
2714 |
Pops the current execution context and restores the previous one. |
|
2715 |
This function must be used in conjunction with pushContext(). |
|
2716 |
||
2717 |
\sa pushContext() |
|
2718 |
*/ |
|
2719 |
void QScriptEngine::popContext() |
|
2720 |
{ |
|
2721 |
if (agent()) |
|
2722 |
agent()->contextPop(); |
|
2723 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2724 |
QScript::APIShim shim(d); |
0 | 2725 |
if (d->currentFrame->returnPC() != 0 || d->currentFrame->codeBlock() != 0 |
2726 |
|| !currentContext()->parentContext()) { |
|
2727 |
qWarning("QScriptEngine::popContext() doesn't match with pushContext()"); |
|
2728 |
return; |
|
2729 |
} |
|
2730 |
||
2731 |
d->popContext(); |
|
2732 |
} |
|
2733 |
||
2734 |
/*! \internal |
|
2735 |
counter part of QScriptEnginePrivate::pushContext |
|
2736 |
*/ |
|
2737 |
void QScriptEnginePrivate::popContext() |
|
2738 |
{ |
|
2739 |
uint flags = contextFlags(currentFrame); |
|
2740 |
bool hasScope = flags & HasScopeContext; |
|
2741 |
if (flags & ShouldRestoreCallFrame) { //normal case |
|
2742 |
JSC::RegisterFile ®isterFile = currentFrame->interpreter()->registerFile(); |
|
2743 |
JSC::Register *const newEnd = currentFrame->registers() - JSC::RegisterFile::CallFrameHeaderSize - currentFrame->argumentCount(); |
|
2744 |
if (hasScope) |
|
2745 |
currentFrame->scopeChain()->pop()->deref(); |
|
2746 |
registerFile.shrink(newEnd); |
|
2747 |
} else if(hasScope) { //the stack frame was created by the Interpreter, we don't need to rewind it. |
|
2748 |
currentFrame->setScopeChain(currentFrame->scopeChain()->pop()); |
|
2749 |
currentFrame->scopeChain()->deref(); |
|
2750 |
} |
|
2751 |
currentFrame = currentFrame->callerFrame(); |
|
2752 |
} |
|
2753 |
||
2754 |
/*! |
|
2755 |
Returns true if the last script evaluation resulted in an uncaught |
|
2756 |
exception; otherwise returns false. |
|
2757 |
||
2758 |
The exception state is cleared when evaluate() is called. |
|
2759 |
||
2760 |
\sa uncaughtException(), uncaughtExceptionLineNumber(), |
|
2761 |
uncaughtExceptionBacktrace() |
|
2762 |
*/ |
|
2763 |
bool QScriptEngine::hasUncaughtException() const |
|
2764 |
{ |
|
2765 |
Q_D(const QScriptEngine); |
|
2766 |
JSC::ExecState* exec = d->globalExec(); |
|
2767 |
return exec->hadException() || d->currentException().isValid(); |
|
2768 |
} |
|
2769 |
||
2770 |
/*! |
|
2771 |
Returns the current uncaught exception, or an invalid QScriptValue |
|
2772 |
if there is no uncaught exception. |
|
2773 |
||
2774 |
The exception value is typically an \c{Error} object; in that case, |
|
2775 |
you can call toString() on the return value to obtain an error |
|
2776 |
message. |
|
2777 |
||
2778 |
\sa hasUncaughtException(), uncaughtExceptionLineNumber(), |
|
2779 |
uncaughtExceptionBacktrace() |
|
2780 |
*/ |
|
2781 |
QScriptValue QScriptEngine::uncaughtException() const |
|
2782 |
{ |
|
2783 |
Q_D(const QScriptEngine); |
|
2784 |
QScriptValue result; |
|
2785 |
JSC::ExecState* exec = d->globalExec(); |
|
2786 |
if (exec->hadException()) |
|
2787 |
result = const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(exec->exception()); |
|
2788 |
else |
|
2789 |
result = d->currentException(); |
|
2790 |
return result; |
|
2791 |
} |
|
2792 |
||
2793 |
/*! |
|
2794 |
Returns the line number where the last uncaught exception occurred. |
|
2795 |
||
2796 |
Line numbers are 1-based, unless a different base was specified as |
|
2797 |
the second argument to evaluate(). |
|
2798 |
||
2799 |
\sa hasUncaughtException(), uncaughtExceptionBacktrace() |
|
2800 |
*/ |
|
2801 |
int QScriptEngine::uncaughtExceptionLineNumber() const |
|
2802 |
{ |
|
2803 |
if (!hasUncaughtException()) |
|
2804 |
return -1; |
|
2805 |
return uncaughtException().property(QLatin1String("lineNumber")).toInt32(); |
|
2806 |
} |
|
2807 |
||
2808 |
/*! |
|
2809 |
Returns a human-readable backtrace of the last uncaught exception. |
|
2810 |
||
2811 |
Each line is of the form \c{<function-name>(<arguments>)@<file-name>:<line-number>}. |
|
2812 |
||
2813 |
\sa uncaughtException() |
|
2814 |
*/ |
|
2815 |
QStringList QScriptEngine::uncaughtExceptionBacktrace() const |
|
2816 |
{ |
|
2817 |
if (!hasUncaughtException()) |
|
2818 |
return QStringList(); |
|
2819 |
// ### currently no way to get a full backtrace from JSC without installing a |
|
2820 |
// debugger that reimplements exception() and store the backtrace there. |
|
2821 |
QScriptValue value = uncaughtException(); |
|
2822 |
if (!value.isError()) |
|
2823 |
return QStringList(); |
|
2824 |
QStringList result; |
|
2825 |
result.append(QString::fromLatin1("<anonymous>()@%0:%1") |
|
2826 |
.arg(value.property(QLatin1String("fileName")).toString()) |
|
2827 |
.arg(value.property(QLatin1String("lineNumber")).toInt32())); |
|
2828 |
return result; |
|
2829 |
} |
|
2830 |
||
2831 |
/*! |
|
2832 |
\since 4.4 |
|
2833 |
||
2834 |
Clears any uncaught exceptions in this engine. |
|
2835 |
||
2836 |
\sa hasUncaughtException() |
|
2837 |
*/ |
|
2838 |
void QScriptEngine::clearExceptions() |
|
2839 |
{ |
|
2840 |
Q_D(QScriptEngine); |
|
2841 |
JSC::ExecState* exec = d->currentFrame; |
|
2842 |
exec->clearException(); |
|
2843 |
d->clearCurrentException(); |
|
2844 |
} |
|
2845 |
||
2846 |
/*! |
|
2847 |
Returns the default prototype associated with the given \a metaTypeId, |
|
2848 |
or an invalid QScriptValue if no default prototype has been set. |
|
2849 |
||
2850 |
\sa setDefaultPrototype() |
|
2851 |
*/ |
|
2852 |
QScriptValue QScriptEngine::defaultPrototype(int metaTypeId) const |
|
2853 |
{ |
|
2854 |
Q_D(const QScriptEngine); |
|
2855 |
return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(d->defaultPrototype(metaTypeId)); |
|
2856 |
} |
|
2857 |
||
2858 |
/*! |
|
2859 |
Sets the default prototype of the C++ type identified by the given |
|
2860 |
\a metaTypeId to \a prototype. |
|
2861 |
||
2862 |
The default prototype provides a script interface for values of |
|
2863 |
type \a metaTypeId when a value of that type is accessed from script |
|
2864 |
code. Whenever the script engine (implicitly or explicitly) creates |
|
2865 |
a QScriptValue from a value of type \a metaTypeId, the default |
|
2866 |
prototype will be set as the QScriptValue's prototype. |
|
2867 |
||
2868 |
The \a prototype object itself may be constructed using one of two |
|
2869 |
principal techniques; the simplest is to subclass QScriptable, which |
|
2870 |
enables you to define the scripting API of the type through QObject |
|
2871 |
properties and slots. Another possibility is to create a script |
|
2872 |
object by calling newObject(), and populate the object with the |
|
2873 |
desired properties (e.g. native functions wrapped with |
|
2874 |
newFunction()). |
|
2875 |
||
2876 |
\sa defaultPrototype(), qScriptRegisterMetaType(), QScriptable, {Default Prototypes Example} |
|
2877 |
*/ |
|
2878 |
void QScriptEngine::setDefaultPrototype(int metaTypeId, const QScriptValue &prototype) |
|
2879 |
{ |
|
2880 |
Q_D(QScriptEngine); |
|
2881 |
d->setDefaultPrototype(metaTypeId, d->scriptValueToJSCValue(prototype)); |
|
2882 |
} |
|
2883 |
||
2884 |
/*! |
|
2885 |
\typedef QScriptEngine::FunctionSignature |
|
2886 |
\relates QScriptEngine |
|
2887 |
||
2888 |
The function signature \c{QScriptValue f(QScriptContext *, QScriptEngine *)}. |
|
2889 |
||
2890 |
A function with such a signature can be passed to |
|
2891 |
QScriptEngine::newFunction() to wrap the function. |
|
2892 |
*/ |
|
2893 |
||
2894 |
/*! |
|
2895 |
\typedef QScriptEngine::FunctionWithArgSignature |
|
2896 |
\relates QScriptEngine |
|
2897 |
||
2898 |
The function signature \c{QScriptValue f(QScriptContext *, QScriptEngine *, void *)}. |
|
2899 |
||
2900 |
A function with such a signature can be passed to |
|
2901 |
QScriptEngine::newFunction() to wrap the function. |
|
2902 |
*/ |
|
2903 |
||
2904 |
/*! |
|
2905 |
\typedef QScriptEngine::MarshalFunction |
|
2906 |
\internal |
|
2907 |
*/ |
|
2908 |
||
2909 |
/*! |
|
2910 |
\typedef QScriptEngine::DemarshalFunction |
|
2911 |
\internal |
|
2912 |
*/ |
|
2913 |
||
2914 |
/*! |
|
2915 |
\internal |
|
2916 |
*/ |
|
2917 |
QScriptValue QScriptEngine::create(int type, const void *ptr) |
|
2918 |
{ |
|
2919 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2920 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2921 |
return d->scriptValueFromJSCValue(d->create(d->currentFrame, type, ptr)); |
0 | 2922 |
} |
2923 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2924 |
JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const void *ptr) |
0 | 2925 |
{ |
2926 |
Q_ASSERT(ptr != 0); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2927 |
JSC::JSValue result; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2928 |
QScriptEnginePrivate *eng = exec ? QScript::scriptEngineFromExec(exec) : 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2929 |
QScriptTypeInfo *info = eng ? eng->m_typeInfos.value(type) : 0; |
0 | 2930 |
if (info && info->marshal) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2931 |
result = eng->scriptValueToJSCValue(info->marshal(eng->q_func(), ptr)); |
0 | 2932 |
} else { |
2933 |
// check if it's one of the types we know |
|
2934 |
switch (QMetaType::Type(type)) { |
|
2935 |
case QMetaType::Void: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2936 |
return JSC::jsUndefined(); |
0 | 2937 |
case QMetaType::Bool: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2938 |
return JSC::jsBoolean(*reinterpret_cast<const bool*>(ptr)); |
0 | 2939 |
case QMetaType::Int: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2940 |
return JSC::jsNumber(exec, *reinterpret_cast<const int*>(ptr)); |
0 | 2941 |
case QMetaType::UInt: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2942 |
return JSC::jsNumber(exec, *reinterpret_cast<const uint*>(ptr)); |
0 | 2943 |
case QMetaType::LongLong: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2944 |
return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const qlonglong*>(ptr))); |
0 | 2945 |
case QMetaType::ULongLong: |
2946 |
#if defined(Q_OS_WIN) && defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 12008804 |
|
2947 |
#pragma message("** NOTE: You need the Visual Studio Processor Pack to compile support for 64bit unsigned integers.") |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2948 |
return JSC::jsNumber(exec, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr))); |
0 | 2949 |
#elif defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2950 |
return JSC::jsNumber(exec, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr))); |
0 | 2951 |
#else |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2952 |
return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const qulonglong*>(ptr))); |
0 | 2953 |
#endif |
2954 |
case QMetaType::Double: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2955 |
return JSC::jsNumber(exec, qsreal(*reinterpret_cast<const double*>(ptr))); |
0 | 2956 |
case QMetaType::QString: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2957 |
return JSC::jsString(exec, *reinterpret_cast<const QString*>(ptr)); |
0 | 2958 |
case QMetaType::Float: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2959 |
return JSC::jsNumber(exec, *reinterpret_cast<const float*>(ptr)); |
0 | 2960 |
case QMetaType::Short: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2961 |
return JSC::jsNumber(exec, *reinterpret_cast<const short*>(ptr)); |
0 | 2962 |
case QMetaType::UShort: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2963 |
return JSC::jsNumber(exec, *reinterpret_cast<const unsigned short*>(ptr)); |
0 | 2964 |
case QMetaType::Char: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2965 |
return JSC::jsNumber(exec, *reinterpret_cast<const char*>(ptr)); |
0 | 2966 |
case QMetaType::UChar: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2967 |
return JSC::jsNumber(exec, *reinterpret_cast<const unsigned char*>(ptr)); |
0 | 2968 |
case QMetaType::QChar: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2969 |
return JSC::jsNumber(exec, (*reinterpret_cast<const QChar*>(ptr)).unicode()); |
0 | 2970 |
case QMetaType::QStringList: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2971 |
result = arrayFromStringList(exec, *reinterpret_cast<const QStringList *>(ptr)); |
0 | 2972 |
break; |
2973 |
case QMetaType::QVariantList: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2974 |
result = arrayFromVariantList(exec, *reinterpret_cast<const QVariantList *>(ptr)); |
0 | 2975 |
break; |
2976 |
case QMetaType::QVariantMap: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2977 |
result = objectFromVariantMap(exec, *reinterpret_cast<const QVariantMap *>(ptr)); |
0 | 2978 |
break; |
2979 |
case QMetaType::QDateTime: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2980 |
result = newDate(exec, *reinterpret_cast<const QDateTime *>(ptr)); |
0 | 2981 |
break; |
2982 |
case QMetaType::QDate: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2983 |
result = newDate(exec, QDateTime(*reinterpret_cast<const QDate *>(ptr))); |
0 | 2984 |
break; |
2985 |
#ifndef QT_NO_REGEXP |
|
2986 |
case QMetaType::QRegExp: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2987 |
result = newRegExp(exec, *reinterpret_cast<const QRegExp *>(ptr)); |
0 | 2988 |
break; |
2989 |
#endif |
|
2990 |
#ifndef QT_NO_QOBJECT |
|
2991 |
case QMetaType::QObjectStar: |
|
2992 |
case QMetaType::QWidgetStar: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2993 |
result = eng->newQObject(*reinterpret_cast<QObject* const *>(ptr)); |
0 | 2994 |
break; |
2995 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2996 |
case QMetaType::QVariant: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2997 |
result = jscValueFromVariant(exec, *reinterpret_cast<const QVariant*>(ptr)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
2998 |
break; |
0 | 2999 |
default: |
3000 |
if (type == qMetaTypeId<QScriptValue>()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3001 |
result = eng->scriptValueToJSCValue(*reinterpret_cast<const QScriptValue*>(ptr)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3002 |
if (!result) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3003 |
return JSC::jsUndefined(); |
0 | 3004 |
} |
3005 |
||
3006 |
#ifndef QT_NO_QOBJECT |
|
3007 |
// lazy registration of some common list types |
|
3008 |
else if (type == qMetaTypeId<QObjectList>()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3009 |
qScriptRegisterSequenceMetaType<QObjectList>(eng->q_func()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3010 |
return create(exec, type, ptr); |
0 | 3011 |
} |
3012 |
#endif |
|
3013 |
else if (type == qMetaTypeId<QList<int> >()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3014 |
qScriptRegisterSequenceMetaType<QList<int> >(eng->q_func()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3015 |
return create(exec, type, ptr); |
0 | 3016 |
} |
3017 |
||
3018 |
else { |
|
3019 |
QByteArray typeName = QMetaType::typeName(type); |
|
3020 |
if (typeName.endsWith('*') && !*reinterpret_cast<void* const *>(ptr)) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3021 |
return JSC::jsNull(); |
0 | 3022 |
else |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3023 |
result = eng->newVariant(QVariant(type, ptr)); |
0 | 3024 |
} |
3025 |
} |
|
3026 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3027 |
if (result && result.isObject() && info && info->prototype |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3028 |
&& JSC::JSValue::strictEqual(exec, JSC::asObject(result)->prototype(), eng->originalGlobalObject()->objectPrototype())) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3029 |
JSC::asObject(result)->setPrototype(info->prototype); |
0 | 3030 |
} |
3031 |
return result; |
|
3032 |
} |
|
3033 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3034 |
bool QScriptEnginePrivate::convertValue(JSC::ExecState *exec, JSC::JSValue value, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3035 |
int type, void *ptr) |
0 | 3036 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3037 |
QScriptEnginePrivate *eng = exec ? QScript::scriptEngineFromExec(exec) : 0; |
0 | 3038 |
if (eng) { |
3039 |
QScriptTypeInfo *info = eng->m_typeInfos.value(type); |
|
3040 |
if (info && info->demarshal) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3041 |
info->demarshal(eng->scriptValueFromJSCValue(value), ptr); |
0 | 3042 |
return true; |
3043 |
} |
|
3044 |
} |
|
3045 |
||
3046 |
// check if it's one of the types we know |
|
3047 |
switch (QMetaType::Type(type)) { |
|
3048 |
case QMetaType::Bool: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3049 |
*reinterpret_cast<bool*>(ptr) = toBool(exec, value); |
0 | 3050 |
return true; |
3051 |
case QMetaType::Int: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3052 |
*reinterpret_cast<int*>(ptr) = toInt32(exec, value); |
0 | 3053 |
return true; |
3054 |
case QMetaType::UInt: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3055 |
*reinterpret_cast<uint*>(ptr) = toUInt32(exec, value); |
0 | 3056 |
return true; |
3057 |
case QMetaType::LongLong: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3058 |
*reinterpret_cast<qlonglong*>(ptr) = qlonglong(toInteger(exec, value)); |
0 | 3059 |
return true; |
3060 |
case QMetaType::ULongLong: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3061 |
*reinterpret_cast<qulonglong*>(ptr) = qulonglong(toInteger(exec, value)); |
0 | 3062 |
return true; |
3063 |
case QMetaType::Double: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3064 |
*reinterpret_cast<double*>(ptr) = toNumber(exec, value); |
0 | 3065 |
return true; |
3066 |
case QMetaType::QString: |
|
3067 |
if (value.isUndefined() || value.isNull()) |
|
3068 |
*reinterpret_cast<QString*>(ptr) = QString(); |
|
3069 |
else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3070 |
*reinterpret_cast<QString*>(ptr) = toString(exec, value); |
0 | 3071 |
return true; |
3072 |
case QMetaType::Float: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3073 |
*reinterpret_cast<float*>(ptr) = toNumber(exec, value); |
0 | 3074 |
return true; |
3075 |
case QMetaType::Short: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3076 |
*reinterpret_cast<short*>(ptr) = short(toInt32(exec, value)); |
0 | 3077 |
return true; |
3078 |
case QMetaType::UShort: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3079 |
*reinterpret_cast<unsigned short*>(ptr) = QScript::ToUInt16(toNumber(exec, value)); |
0 | 3080 |
return true; |
3081 |
case QMetaType::Char: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3082 |
*reinterpret_cast<char*>(ptr) = char(toInt32(exec, value)); |
0 | 3083 |
return true; |
3084 |
case QMetaType::UChar: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3085 |
*reinterpret_cast<unsigned char*>(ptr) = (unsigned char)(toInt32(exec, value)); |
0 | 3086 |
return true; |
3087 |
case QMetaType::QChar: |
|
3088 |
if (value.isString()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3089 |
QString str = toString(exec, value); |
0 | 3090 |
*reinterpret_cast<QChar*>(ptr) = str.isEmpty() ? QChar() : str.at(0); |
3091 |
} else { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3092 |
*reinterpret_cast<QChar*>(ptr) = QChar(QScript::ToUInt16(toNumber(exec, value))); |
0 | 3093 |
} |
3094 |
return true; |
|
3095 |
case QMetaType::QDateTime: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3096 |
if (isDate(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3097 |
*reinterpret_cast<QDateTime *>(ptr) = toDateTime(exec, value); |
0 | 3098 |
return true; |
3099 |
} break; |
|
3100 |
case QMetaType::QDate: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3101 |
if (isDate(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3102 |
*reinterpret_cast<QDate *>(ptr) = toDateTime(exec, value).date(); |
0 | 3103 |
return true; |
3104 |
} break; |
|
3105 |
#ifndef QT_NO_REGEXP |
|
3106 |
case QMetaType::QRegExp: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3107 |
if (isRegExp(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3108 |
*reinterpret_cast<QRegExp *>(ptr) = toRegExp(exec, value); |
0 | 3109 |
return true; |
3110 |
} break; |
|
3111 |
#endif |
|
3112 |
#ifndef QT_NO_QOBJECT |
|
3113 |
case QMetaType::QObjectStar: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3114 |
if (isQObject(value) || value.isNull()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3115 |
*reinterpret_cast<QObject* *>(ptr) = toQObject(exec, value); |
0 | 3116 |
return true; |
3117 |
} break; |
|
3118 |
case QMetaType::QWidgetStar: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3119 |
if (isQObject(value) || value.isNull()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3120 |
QObject *qo = toQObject(exec, value); |
0 | 3121 |
if (!qo || qo->isWidgetType()) { |
3122 |
*reinterpret_cast<QWidget* *>(ptr) = reinterpret_cast<QWidget*>(qo); |
|
3123 |
return true; |
|
3124 |
} |
|
3125 |
} break; |
|
3126 |
#endif |
|
3127 |
case QMetaType::QStringList: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3128 |
if (isArray(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3129 |
*reinterpret_cast<QStringList *>(ptr) = stringListFromArray(exec, value); |
0 | 3130 |
return true; |
3131 |
} break; |
|
3132 |
case QMetaType::QVariantList: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3133 |
if (isArray(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3134 |
*reinterpret_cast<QVariantList *>(ptr) = variantListFromArray(exec, value); |
0 | 3135 |
return true; |
3136 |
} break; |
|
3137 |
case QMetaType::QVariantMap: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3138 |
if (isObject(value)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3139 |
*reinterpret_cast<QVariantMap *>(ptr) = variantMapFromObject(exec, value); |
0 | 3140 |
return true; |
3141 |
} break; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3142 |
case QMetaType::QVariant: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3143 |
*reinterpret_cast<QVariant*>(ptr) = toVariant(exec, value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3144 |
return true; |
0 | 3145 |
default: |
3146 |
; |
|
3147 |
} |
|
3148 |
||
3149 |
QByteArray name = QMetaType::typeName(type); |
|
3150 |
#ifndef QT_NO_QOBJECT |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3151 |
if (convertToNativeQObject(exec, value, name, reinterpret_cast<void* *>(ptr))) |
0 | 3152 |
return true; |
3153 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3154 |
if (isVariant(value) && name.endsWith('*')) { |
0 | 3155 |
int valueType = QMetaType::type(name.left(name.size()-1)); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3156 |
QVariant &var = variantValue(value); |
0 | 3157 |
if (valueType == var.userType()) { |
3158 |
*reinterpret_cast<void* *>(ptr) = var.data(); |
|
3159 |
return true; |
|
3160 |
} else { |
|
3161 |
// look in the prototype chain |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3162 |
JSC::JSValue proto = JSC::asObject(value)->prototype(); |
0 | 3163 |
while (proto.isObject()) { |
3164 |
bool canCast = false; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3165 |
if (isVariant(proto)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3166 |
canCast = (type == variantValue(proto).userType()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3167 |
|| (valueType && (valueType == variantValue(proto).userType())); |
0 | 3168 |
} |
3169 |
#ifndef QT_NO_QOBJECT |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3170 |
else if (isQObject(proto)) { |
0 | 3171 |
QByteArray className = name.left(name.size()-1); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3172 |
if (QObject *qobject = toQObject(exec, proto)) |
0 | 3173 |
canCast = qobject->qt_metacast(className) != 0; |
3174 |
} |
|
3175 |
#endif |
|
3176 |
if (canCast) { |
|
3177 |
QByteArray varTypeName = QMetaType::typeName(var.userType()); |
|
3178 |
if (varTypeName.endsWith('*')) |
|
3179 |
*reinterpret_cast<void* *>(ptr) = *reinterpret_cast<void* *>(var.data()); |
|
3180 |
else |
|
3181 |
*reinterpret_cast<void* *>(ptr) = var.data(); |
|
3182 |
return true; |
|
3183 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3184 |
proto = JSC::asObject(proto)->prototype(); |
0 | 3185 |
} |
3186 |
} |
|
3187 |
} else if (value.isNull() && name.endsWith('*')) { |
|
3188 |
*reinterpret_cast<void* *>(ptr) = 0; |
|
3189 |
return true; |
|
3190 |
} else if (type == qMetaTypeId<QScriptValue>()) { |
|
3191 |
if (!eng) |
|
3192 |
return false; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3193 |
*reinterpret_cast<QScriptValue*>(ptr) = eng->scriptValueFromJSCValue(value); |
0 | 3194 |
return true; |
3195 |
} |
|
3196 |
||
3197 |
// lazy registration of some common list types |
|
3198 |
#ifndef QT_NO_QOBJECT |
|
3199 |
else if (type == qMetaTypeId<QObjectList>()) { |
|
3200 |
if (!eng) |
|
3201 |
return false; |
|
3202 |
qScriptRegisterSequenceMetaType<QObjectList>(eng->q_func()); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3203 |
return convertValue(exec, value, type, ptr); |
0 | 3204 |
} |
3205 |
#endif |
|
3206 |
else if (type == qMetaTypeId<QList<int> >()) { |
|
3207 |
if (!eng) |
|
3208 |
return false; |
|
3209 |
qScriptRegisterSequenceMetaType<QList<int> >(eng->q_func()); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3210 |
return convertValue(exec, value, type, ptr); |
0 | 3211 |
} |
3212 |
||
3213 |
#if 0 |
|
3214 |
if (!name.isEmpty()) { |
|
3215 |
qWarning("QScriptEngine::convert: unable to convert value to type `%s'", |
|
3216 |
name.constData()); |
|
3217 |
} |
|
3218 |
#endif |
|
3219 |
return false; |
|
3220 |
} |
|
3221 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3222 |
bool QScriptEnginePrivate::convertNumber(qsreal value, int type, void *ptr) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3223 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3224 |
switch (QMetaType::Type(type)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3225 |
case QMetaType::Bool: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3226 |
*reinterpret_cast<bool*>(ptr) = QScript::ToBool(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3227 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3228 |
case QMetaType::Int: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3229 |
*reinterpret_cast<int*>(ptr) = QScript::ToInt32(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3230 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3231 |
case QMetaType::UInt: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3232 |
*reinterpret_cast<uint*>(ptr) = QScript::ToUInt32(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3233 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3234 |
case QMetaType::LongLong: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3235 |
*reinterpret_cast<qlonglong*>(ptr) = qlonglong(QScript::ToInteger(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3236 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3237 |
case QMetaType::ULongLong: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3238 |
*reinterpret_cast<qulonglong*>(ptr) = qulonglong(QScript::ToInteger(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3239 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3240 |
case QMetaType::Double: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3241 |
*reinterpret_cast<double*>(ptr) = value; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3242 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3243 |
case QMetaType::QString: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3244 |
*reinterpret_cast<QString*>(ptr) = QScript::ToString(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3245 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3246 |
case QMetaType::Float: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3247 |
*reinterpret_cast<float*>(ptr) = value; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3248 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3249 |
case QMetaType::Short: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3250 |
*reinterpret_cast<short*>(ptr) = short(QScript::ToInt32(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3251 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3252 |
case QMetaType::UShort: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3253 |
*reinterpret_cast<unsigned short*>(ptr) = QScript::ToUInt16(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3254 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3255 |
case QMetaType::Char: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3256 |
*reinterpret_cast<char*>(ptr) = char(QScript::ToInt32(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3257 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3258 |
case QMetaType::UChar: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3259 |
*reinterpret_cast<unsigned char*>(ptr) = (unsigned char)(QScript::ToInt32(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3260 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3261 |
case QMetaType::QChar: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3262 |
*reinterpret_cast<QChar*>(ptr) = QChar(QScript::ToUInt16(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3263 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3264 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3265 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3266 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3267 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3268 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3269 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3270 |
bool QScriptEnginePrivate::convertString(const QString &value, int type, void *ptr) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3271 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3272 |
switch (QMetaType::Type(type)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3273 |
case QMetaType::Bool: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3274 |
*reinterpret_cast<bool*>(ptr) = QScript::ToBool(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3275 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3276 |
case QMetaType::Int: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3277 |
*reinterpret_cast<int*>(ptr) = QScript::ToInt32(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3278 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3279 |
case QMetaType::UInt: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3280 |
*reinterpret_cast<uint*>(ptr) = QScript::ToUInt32(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3281 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3282 |
case QMetaType::LongLong: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3283 |
*reinterpret_cast<qlonglong*>(ptr) = qlonglong(QScript::ToInteger(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3284 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3285 |
case QMetaType::ULongLong: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3286 |
*reinterpret_cast<qulonglong*>(ptr) = qulonglong(QScript::ToInteger(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3287 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3288 |
case QMetaType::Double: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3289 |
*reinterpret_cast<double*>(ptr) = QScript::ToNumber(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3290 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3291 |
case QMetaType::QString: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3292 |
*reinterpret_cast<QString*>(ptr) = value; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3293 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3294 |
case QMetaType::Float: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3295 |
*reinterpret_cast<float*>(ptr) = QScript::ToNumber(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3296 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3297 |
case QMetaType::Short: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3298 |
*reinterpret_cast<short*>(ptr) = short(QScript::ToInt32(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3299 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3300 |
case QMetaType::UShort: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3301 |
*reinterpret_cast<unsigned short*>(ptr) = QScript::ToUInt16(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3302 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3303 |
case QMetaType::Char: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3304 |
*reinterpret_cast<char*>(ptr) = char(QScript::ToInt32(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3305 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3306 |
case QMetaType::UChar: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3307 |
*reinterpret_cast<unsigned char*>(ptr) = (unsigned char)(QScript::ToInt32(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3308 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3309 |
case QMetaType::QChar: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3310 |
*reinterpret_cast<QChar*>(ptr) = QChar(QScript::ToUInt16(value)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3311 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3312 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3313 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3314 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3315 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3316 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3317 |
|
0 | 3318 |
bool QScriptEnginePrivate::hasDemarshalFunction(int type) const |
3319 |
{ |
|
3320 |
QScriptTypeInfo *info = m_typeInfos.value(type); |
|
3321 |
return info && (info->demarshal != 0); |
|
3322 |
} |
|
3323 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3324 |
JSC::UString QScriptEnginePrivate::translationContextFromUrl(const JSC::UString &url) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3325 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3326 |
if (url != cachedTranslationUrl) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3327 |
cachedTranslationContext = QFileInfo(url).baseName(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3328 |
cachedTranslationUrl = url; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3329 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3330 |
return cachedTranslationContext; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3331 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3332 |
|
0 | 3333 |
/*! |
3334 |
\internal |
|
3335 |
*/ |
|
3336 |
bool QScriptEngine::convert(const QScriptValue &value, int type, void *ptr) |
|
3337 |
{ |
|
3338 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3339 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3340 |
return QScriptEnginePrivate::convertValue(d->currentFrame, d->scriptValueToJSCValue(value), type, ptr); |
0 | 3341 |
} |
3342 |
||
3343 |
/*! |
|
3344 |
\internal |
|
3345 |
*/ |
|
3346 |
bool QScriptEngine::convertV2(const QScriptValue &value, int type, void *ptr) |
|
3347 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3348 |
QScriptValuePrivate *vp = QScriptValuePrivate::get(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3349 |
if (vp) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3350 |
switch (vp->type) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3351 |
case QScriptValuePrivate::JavaScriptCore: { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3352 |
if (vp->engine) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3353 |
QScript::APIShim shim(vp->engine); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3354 |
return QScriptEnginePrivate::convertValue(vp->engine->currentFrame, vp->jscValue, type, ptr); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3355 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3356 |
return QScriptEnginePrivate::convertValue(0, vp->jscValue, type, ptr); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3357 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3358 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3359 |
case QScriptValuePrivate::Number: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3360 |
return QScriptEnginePrivate::convertNumber(vp->numberValue, type, ptr); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3361 |
case QScriptValuePrivate::String: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3362 |
return QScriptEnginePrivate::convertString(vp->stringValue, type, ptr); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3363 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3364 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3365 |
return false; |
0 | 3366 |
} |
3367 |
||
3368 |
/*! |
|
3369 |
\internal |
|
3370 |
*/ |
|
3371 |
void QScriptEngine::registerCustomType(int type, MarshalFunction mf, |
|
3372 |
DemarshalFunction df, |
|
3373 |
const QScriptValue &prototype) |
|
3374 |
{ |
|
3375 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3376 |
QScript::APIShim shim(d); |
0 | 3377 |
QScriptTypeInfo *info = d->m_typeInfos.value(type); |
3378 |
if (!info) { |
|
3379 |
info = new QScriptTypeInfo(); |
|
3380 |
d->m_typeInfos.insert(type, info); |
|
3381 |
} |
|
3382 |
info->marshal = mf; |
|
3383 |
info->demarshal = df; |
|
3384 |
info->prototype = d->scriptValueToJSCValue(prototype); |
|
3385 |
} |
|
3386 |
||
3387 |
/*! |
|
3388 |
\since 4.5 |
|
3389 |
||
3390 |
Installs translator functions on the given \a object, or on the Global |
|
3391 |
Object if no object is specified. |
|
3392 |
||
3393 |
The relation between Qt Script translator functions and C++ translator |
|
3394 |
functions is described in the following table: |
|
3395 |
||
3396 |
\table |
|
3397 |
\header \o Script Function \o Corresponding C++ Function |
|
3398 |
\row \o qsTr() \o QObject::tr() |
|
3399 |
\row \o QT_TR_NOOP() \o QT_TR_NOOP() |
|
3400 |
\row \o qsTranslate() \o QCoreApplication::translate() |
|
3401 |
\row \o QT_TRANSLATE_NOOP() \o QT_TRANSLATE_NOOP() |
|
3402 |
\endtable |
|
3403 |
||
3404 |
\sa {Internationalization with Qt} |
|
3405 |
*/ |
|
3406 |
void QScriptEngine::installTranslatorFunctions(const QScriptValue &object) |
|
3407 |
{ |
|
3408 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3409 |
QScript::APIShim shim(d); |
0 | 3410 |
JSC::ExecState* exec = d->currentFrame; |
3411 |
JSC::JSValue jscObject = d->scriptValueToJSCValue(object); |
|
3412 |
JSC::JSGlobalObject *glob = d->originalGlobalObject(); |
|
3413 |
if (!jscObject || !jscObject.isObject()) |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3414 |
jscObject = d->globalObject(); |
0 | 3415 |
// unsigned attribs = JSC::DontEnum; |
3416 |
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 5, JSC::Identifier(exec, "qsTranslate"), QScript::functionQsTranslate)); |
|
3417 |
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 2, JSC::Identifier(exec, "QT_TRANSLATE_NOOP"), QScript::functionQsTranslateNoOp)); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3418 |
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr)); |
0 | 3419 |
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TR_NOOP"), QScript::functionQsTrNoOp)); |
3420 |
||
3421 |
glob->stringPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "arg"), QScript::stringProtoFuncArg)); |
|
3422 |
} |
|
3423 |
||
3424 |
/*! |
|
3425 |
Imports the given \a extension into this QScriptEngine. Returns |
|
3426 |
undefinedValue() if the extension was successfully imported. You |
|
3427 |
can call hasUncaughtException() to check if an error occurred; in |
|
3428 |
that case, the return value is the value that was thrown by the |
|
3429 |
exception (usually an \c{Error} object). |
|
3430 |
||
3431 |
QScriptEngine ensures that a particular extension is only imported |
|
3432 |
once; subsequent calls to importExtension() with the same extension |
|
3433 |
name will do nothing and return undefinedValue(). |
|
3434 |
||
3435 |
\sa availableExtensions(), QScriptExtensionPlugin, {Creating QtScript Extensions} |
|
3436 |
*/ |
|
3437 |
QScriptValue QScriptEngine::importExtension(const QString &extension) |
|
3438 |
{ |
|
3439 |
#if defined(QT_NO_QOBJECT) || defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS) |
|
3440 |
Q_UNUSED(extension); |
|
3441 |
#else |
|
3442 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3443 |
QScript::APIShim shim(d); |
0 | 3444 |
if (d->importedExtensions.contains(extension)) |
3445 |
return undefinedValue(); // already imported |
|
3446 |
||
3447 |
QScriptContext *context = currentContext(); |
|
3448 |
QCoreApplication *app = QCoreApplication::instance(); |
|
3449 |
if (!app) |
|
3450 |
return context->throwError(QLatin1String("No application object")); |
|
3451 |
||
3452 |
QObjectList staticPlugins = QPluginLoader::staticInstances(); |
|
3453 |
QStringList libraryPaths = app->libraryPaths(); |
|
3454 |
QString dot = QLatin1String("."); |
|
3455 |
QStringList pathComponents = extension.split(dot); |
|
3456 |
QString initDotJs = QLatin1String("__init__.js"); |
|
3457 |
||
3458 |
QString ext; |
|
3459 |
for (int i = 0; i < pathComponents.count(); ++i) { |
|
3460 |
if (!ext.isEmpty()) |
|
3461 |
ext.append(dot); |
|
3462 |
ext.append(pathComponents.at(i)); |
|
3463 |
if (d->importedExtensions.contains(ext)) |
|
3464 |
continue; // already imported |
|
3465 |
||
3466 |
if (d->extensionsBeingImported.contains(ext)) { |
|
3467 |
return context->throwError(QString::fromLatin1("recursive import of %0") |
|
3468 |
.arg(extension)); |
|
3469 |
} |
|
3470 |
d->extensionsBeingImported.insert(ext); |
|
3471 |
||
3472 |
QScriptExtensionInterface *iface = 0; |
|
3473 |
QString initjsContents; |
|
3474 |
QString initjsFileName; |
|
3475 |
||
3476 |
// look for the extension in static plugins |
|
3477 |
for (int j = 0; j < staticPlugins.size(); ++j) { |
|
3478 |
iface = qobject_cast<QScriptExtensionInterface*>(staticPlugins.at(j)); |
|
3479 |
if (!iface) |
|
3480 |
continue; |
|
3481 |
if (iface->keys().contains(ext)) |
|
3482 |
break; // use this one |
|
3483 |
else |
|
3484 |
iface = 0; // keep looking |
|
3485 |
} |
|
3486 |
||
3487 |
{ |
|
3488 |
// look for __init__.js resource |
|
3489 |
QString path = QString::fromLatin1(":/qtscriptextension"); |
|
3490 |
for (int j = 0; j <= i; ++j) { |
|
3491 |
path.append(QLatin1Char('/')); |
|
3492 |
path.append(pathComponents.at(j)); |
|
3493 |
} |
|
3494 |
path.append(QLatin1Char('/')); |
|
3495 |
path.append(initDotJs); |
|
3496 |
QFile file(path); |
|
3497 |
if (file.open(QIODevice::ReadOnly)) { |
|
3498 |
QTextStream ts(&file); |
|
3499 |
initjsContents = ts.readAll(); |
|
3500 |
initjsFileName = path; |
|
3501 |
file.close(); |
|
3502 |
} |
|
3503 |
} |
|
3504 |
||
3505 |
if (!iface && initjsContents.isEmpty()) { |
|
3506 |
// look for the extension in library paths |
|
3507 |
for (int j = 0; j < libraryPaths.count(); ++j) { |
|
3508 |
QString libPath = libraryPaths.at(j) + QDir::separator() + QLatin1String("script"); |
|
3509 |
QDir dir(libPath); |
|
3510 |
if (!dir.exists(dot)) |
|
3511 |
continue; |
|
3512 |
||
3513 |
// look for C++ plugin |
|
3514 |
QFileInfoList files = dir.entryInfoList(QDir::Files); |
|
3515 |
for (int k = 0; k < files.count(); ++k) { |
|
3516 |
QFileInfo entry = files.at(k); |
|
3517 |
QString filePath = entry.canonicalFilePath(); |
|
3518 |
QPluginLoader loader(filePath); |
|
3519 |
iface = qobject_cast<QScriptExtensionInterface*>(loader.instance()); |
|
3520 |
if (iface) { |
|
3521 |
if (iface->keys().contains(ext)) |
|
3522 |
break; // use this one |
|
3523 |
else |
|
3524 |
iface = 0; // keep looking |
|
3525 |
} |
|
3526 |
} |
|
3527 |
||
3528 |
// look for __init__.js in the corresponding dir |
|
3529 |
QDir dirdir(libPath); |
|
3530 |
bool dirExists = dirdir.exists(); |
|
3531 |
for (int k = 0; dirExists && (k <= i); ++k) |
|
3532 |
dirExists = dirdir.cd(pathComponents.at(k)); |
|
3533 |
if (dirExists && dirdir.exists(initDotJs)) { |
|
3534 |
QFile file(dirdir.canonicalPath() |
|
3535 |
+ QDir::separator() + initDotJs); |
|
3536 |
if (file.open(QIODevice::ReadOnly)) { |
|
3537 |
QTextStream ts(&file); |
|
3538 |
initjsContents = ts.readAll(); |
|
3539 |
initjsFileName = file.fileName(); |
|
3540 |
file.close(); |
|
3541 |
} |
|
3542 |
} |
|
3543 |
||
3544 |
if (iface || !initjsContents.isEmpty()) |
|
3545 |
break; |
|
3546 |
} |
|
3547 |
} |
|
3548 |
||
3549 |
if (!iface && initjsContents.isEmpty()) { |
|
3550 |
d->extensionsBeingImported.remove(ext); |
|
3551 |
return context->throwError( |
|
3552 |
QString::fromLatin1("Unable to import %0: no such extension") |
|
3553 |
.arg(extension)); |
|
3554 |
} |
|
3555 |
||
3556 |
// initialize the extension in a new context |
|
3557 |
QScriptContext *ctx = pushContext(); |
|
3558 |
ctx->setThisObject(globalObject()); |
|
3559 |
ctx->activationObject().setProperty(QLatin1String("__extension__"), ext, |
|
3560 |
QScriptValue::ReadOnly | QScriptValue::Undeletable); |
|
3561 |
ctx->activationObject().setProperty(QLatin1String("__setupPackage__"), |
|
3562 |
newFunction(QScript::__setupPackage__)); |
|
3563 |
ctx->activationObject().setProperty(QLatin1String("__postInit__"), QScriptValue(QScriptValue::UndefinedValue)); |
|
3564 |
||
3565 |
// the script is evaluated first |
|
3566 |
if (!initjsContents.isEmpty()) { |
|
3567 |
QScriptValue ret = evaluate(initjsContents, initjsFileName); |
|
3568 |
if (hasUncaughtException()) { |
|
3569 |
popContext(); |
|
3570 |
d->extensionsBeingImported.remove(ext); |
|
3571 |
return ret; |
|
3572 |
} |
|
3573 |
} |
|
3574 |
||
3575 |
// next, the C++ plugin is called |
|
3576 |
if (iface) { |
|
3577 |
iface->initialize(ext, this); |
|
3578 |
if (hasUncaughtException()) { |
|
3579 |
QScriptValue ret = uncaughtException(); // ctx_p->returnValue(); |
|
3580 |
popContext(); |
|
3581 |
d->extensionsBeingImported.remove(ext); |
|
3582 |
return ret; |
|
3583 |
} |
|
3584 |
} |
|
3585 |
||
3586 |
// if the __postInit__ function has been set, we call it |
|
3587 |
QScriptValue postInit = ctx->activationObject().property(QLatin1String("__postInit__")); |
|
3588 |
if (postInit.isFunction()) { |
|
3589 |
postInit.call(globalObject()); |
|
3590 |
if (hasUncaughtException()) { |
|
3591 |
QScriptValue ret = uncaughtException(); // ctx_p->returnValue(); |
|
3592 |
popContext(); |
|
3593 |
d->extensionsBeingImported.remove(ext); |
|
3594 |
return ret; |
|
3595 |
} |
|
3596 |
} |
|
3597 |
||
3598 |
popContext(); |
|
3599 |
||
3600 |
d->importedExtensions.insert(ext); |
|
3601 |
d->extensionsBeingImported.remove(ext); |
|
3602 |
} // for (i) |
|
3603 |
#endif // QT_NO_QOBJECT |
|
3604 |
return undefinedValue(); |
|
3605 |
} |
|
3606 |
||
3607 |
/*! |
|
3608 |
\since 4.4 |
|
3609 |
||
3610 |
Returns a list naming the available extensions that can be |
|
3611 |
imported using the importExtension() function. This list includes |
|
3612 |
extensions that have been imported. |
|
3613 |
||
3614 |
\sa importExtension(), importedExtensions() |
|
3615 |
*/ |
|
3616 |
QStringList QScriptEngine::availableExtensions() const |
|
3617 |
{ |
|
3618 |
#if defined(QT_NO_QOBJECT) || defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS) |
|
3619 |
return QStringList(); |
|
3620 |
#else |
|
3621 |
QCoreApplication *app = QCoreApplication::instance(); |
|
3622 |
if (!app) |
|
3623 |
return QStringList(); |
|
3624 |
||
3625 |
QSet<QString> result; |
|
3626 |
||
3627 |
QObjectList staticPlugins = QPluginLoader::staticInstances(); |
|
3628 |
for (int i = 0; i < staticPlugins.size(); ++i) { |
|
3629 |
QScriptExtensionInterface *iface; |
|
3630 |
iface = qobject_cast<QScriptExtensionInterface*>(staticPlugins.at(i)); |
|
3631 |
if (iface) { |
|
3632 |
QStringList keys = iface->keys(); |
|
3633 |
for (int j = 0; j < keys.count(); ++j) |
|
3634 |
result << keys.at(j); |
|
3635 |
} |
|
3636 |
} |
|
3637 |
||
3638 |
QStringList libraryPaths = app->libraryPaths(); |
|
3639 |
for (int i = 0; i < libraryPaths.count(); ++i) { |
|
3640 |
QString libPath = libraryPaths.at(i) + QDir::separator() + QLatin1String("script"); |
|
3641 |
QDir dir(libPath); |
|
3642 |
if (!dir.exists()) |
|
3643 |
continue; |
|
3644 |
||
3645 |
// look for C++ plugins |
|
3646 |
QFileInfoList files = dir.entryInfoList(QDir::Files); |
|
3647 |
for (int j = 0; j < files.count(); ++j) { |
|
3648 |
QFileInfo entry = files.at(j); |
|
3649 |
QString filePath = entry.canonicalFilePath(); |
|
3650 |
QPluginLoader loader(filePath); |
|
3651 |
QScriptExtensionInterface *iface; |
|
3652 |
iface = qobject_cast<QScriptExtensionInterface*>(loader.instance()); |
|
3653 |
if (iface) { |
|
3654 |
QStringList keys = iface->keys(); |
|
3655 |
for (int k = 0; k < keys.count(); ++k) |
|
3656 |
result << keys.at(k); |
|
3657 |
} |
|
3658 |
} |
|
3659 |
||
3660 |
// look for scripts |
|
3661 |
QString initDotJs = QLatin1String("__init__.js"); |
|
3662 |
QList<QFileInfo> stack; |
|
3663 |
stack << dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); |
|
3664 |
while (!stack.isEmpty()) { |
|
3665 |
QFileInfo entry = stack.takeLast(); |
|
3666 |
QDir dd(entry.canonicalFilePath()); |
|
3667 |
if (dd.exists(initDotJs)) { |
|
3668 |
QString rpath = dir.relativeFilePath(dd.canonicalPath()); |
|
3669 |
QStringList components = rpath.split(QLatin1Char('/')); |
|
3670 |
result << components.join(QLatin1String(".")); |
|
3671 |
stack << dd.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); |
|
3672 |
} |
|
3673 |
} |
|
3674 |
} |
|
3675 |
||
3676 |
QStringList lst = result.toList(); |
|
3677 |
qSort(lst); |
|
3678 |
return lst; |
|
3679 |
#endif |
|
3680 |
} |
|
3681 |
||
3682 |
/*! |
|
3683 |
\since 4.4 |
|
3684 |
||
3685 |
Returns a list naming the extensions that have been imported |
|
3686 |
using the importExtension() function. |
|
3687 |
||
3688 |
\sa availableExtensions() |
|
3689 |
*/ |
|
3690 |
QStringList QScriptEngine::importedExtensions() const |
|
3691 |
{ |
|
3692 |
Q_D(const QScriptEngine); |
|
3693 |
QStringList lst = d->importedExtensions.toList(); |
|
3694 |
qSort(lst); |
|
3695 |
return lst; |
|
3696 |
} |
|
3697 |
||
3698 |
/*! \fn QScriptValue QScriptEngine::toScriptValue(const T &value) |
|
3699 |
||
3700 |
Creates a QScriptValue with the given \a value. |
|
3701 |
||
3702 |
Note that the template type \c{T} must be known to QMetaType. |
|
3703 |
||
3704 |
See \l{Conversion Between QtScript and C++ Types} for a |
|
3705 |
description of the built-in type conversion provided by |
|
3706 |
QtScript. By default, the types that are not specially handled by |
|
3707 |
QtScript are represented as QVariants (e.g. the \a value is passed |
|
3708 |
to newVariant()); you can change this behavior by installing your |
|
3709 |
own type conversion functions with qScriptRegisterMetaType(). |
|
3710 |
||
3711 |
\warning This function is not available with MSVC 6. Use |
|
3712 |
qScriptValueFromValue() instead if you need to support that |
|
3713 |
version of the compiler. |
|
3714 |
||
3715 |
\sa fromScriptValue(), qScriptRegisterMetaType() |
|
3716 |
*/ |
|
3717 |
||
3718 |
/*! \fn T QScriptEngine::fromScriptValue(const QScriptValue &value) |
|
3719 |
||
3720 |
Returns the given \a value converted to the template type \c{T}. |
|
3721 |
||
3722 |
Note that \c{T} must be known to QMetaType. |
|
3723 |
||
3724 |
See \l{Conversion Between QtScript and C++ Types} for a |
|
3725 |
description of the built-in type conversion provided by |
|
3726 |
QtScript. |
|
3727 |
||
3728 |
\warning This function is not available with MSVC 6. Use |
|
3729 |
qScriptValueToValue() or qscriptvalue_cast() instead if you need |
|
3730 |
to support that version of the compiler. |
|
3731 |
||
3732 |
\sa toScriptValue(), qScriptRegisterMetaType() |
|
3733 |
*/ |
|
3734 |
||
3735 |
/*! |
|
3736 |
\fn QScriptValue qScriptValueFromValue(QScriptEngine *engine, const T &value) |
|
3737 |
\since 4.3 |
|
3738 |
\relates QScriptEngine |
|
3739 |
||
3740 |
Creates a QScriptValue using the given \a engine with the given \a |
|
3741 |
value of template type \c{T}. |
|
3742 |
||
3743 |
This function is equivalent to QScriptEngine::toScriptValue(). |
|
3744 |
It is provided as a work-around for MSVC 6, which doesn't support |
|
3745 |
member template functions. |
|
3746 |
||
3747 |
\sa qScriptValueToValue() |
|
3748 |
*/ |
|
3749 |
||
3750 |
/*! |
|
3751 |
\fn T qScriptValueToValue(const QScriptValue &value) |
|
3752 |
\since 4.3 |
|
3753 |
\relates QScriptEngine |
|
3754 |
||
3755 |
Returns the given \a value converted to the template type \c{T}. |
|
3756 |
||
3757 |
This function is equivalent to QScriptEngine::fromScriptValue(). |
|
3758 |
It is provided as a work-around for MSVC 6, which doesn't |
|
3759 |
support member template functions. |
|
3760 |
||
3761 |
\sa qScriptValueFromValue() |
|
3762 |
*/ |
|
3763 |
||
3764 |
/*! |
|
3765 |
\fn QScriptValue qScriptValueFromSequence(QScriptEngine *engine, const Container &container) |
|
3766 |
\since 4.3 |
|
3767 |
\relates QScriptEngine |
|
3768 |
||
3769 |
Creates an array in the form of a QScriptValue using the given \a engine |
|
3770 |
with the given \a container of template type \c{Container}. |
|
3771 |
||
3772 |
The \c Container type must provide a \c const_iterator class to enable the |
|
3773 |
contents of the container to be copied into the array. |
|
3774 |
||
3775 |
Additionally, the type of each element in the sequence should be |
|
3776 |
suitable for conversion to a QScriptValue. See |
|
3777 |
\l{Conversion Between QtScript and C++ Types} for more information |
|
3778 |
about the restrictions on types that can be used with QScriptValue. |
|
3779 |
||
3780 |
\sa qScriptValueFromValue() |
|
3781 |
*/ |
|
3782 |
||
3783 |
/*! |
|
3784 |
\fn void qScriptValueToSequence(const QScriptValue &value, Container &container) |
|
3785 |
\since 4.3 |
|
3786 |
\relates QScriptEngine |
|
3787 |
||
3788 |
Copies the elements in the sequence specified by \a value to the given |
|
3789 |
\a container of template type \c{Container}. |
|
3790 |
||
3791 |
The \a value used is typically an array, but any container can be copied |
|
3792 |
as long as it provides a \c length property describing how many elements |
|
3793 |
it contains. |
|
3794 |
||
3795 |
Additionally, the type of each element in the sequence must be |
|
3796 |
suitable for conversion to a C++ type from a QScriptValue. See |
|
3797 |
\l{Conversion Between QtScript and C++ Types} for more information |
|
3798 |
about the restrictions on types that can be used with |
|
3799 |
QScriptValue. |
|
3800 |
||
3801 |
\sa qscriptvalue_cast() |
|
3802 |
*/ |
|
3803 |
||
3804 |
/*! |
|
3805 |
\fn T qscriptvalue_cast(const QScriptValue &value) |
|
3806 |
\since 4.3 |
|
3807 |
\relates QScriptValue |
|
3808 |
||
3809 |
Returns the given \a value converted to the template type \c{T}. |
|
3810 |
||
3811 |
\sa qScriptRegisterMetaType(), QScriptEngine::toScriptValue() |
|
3812 |
*/ |
|
3813 |
||
3814 |
/*! \fn int qScriptRegisterMetaType( |
|
3815 |
QScriptEngine *engine, |
|
3816 |
QScriptValue (*toScriptValue)(QScriptEngine *, const T &t), |
|
3817 |
void (*fromScriptValue)(const QScriptValue &, T &t), |
|
3818 |
const QScriptValue &prototype = QScriptValue()) |
|
3819 |
\relates QScriptEngine |
|
3820 |
||
3821 |
Registers the type \c{T} in the given \a engine. \a toScriptValue must |
|
3822 |
be a function that will convert from a value of type \c{T} to a |
|
3823 |
QScriptValue, and \a fromScriptValue a function that does the |
|
3824 |
opposite. \a prototype, if valid, is the prototype that's set on |
|
3825 |
QScriptValues returned by \a toScriptValue. |
|
3826 |
||
3827 |
Returns the internal ID used by QMetaType. |
|
3828 |
||
3829 |
You only need to call this function if you want to provide custom |
|
3830 |
conversion of values of type \c{T}, i.e. if the default |
|
3831 |
QVariant-based representation and conversion is not |
|
3832 |
appropriate. (Note that custom QObject-derived types also fall in |
|
3833 |
this category; e.g. for a QObject-derived class called MyObject, |
|
3834 |
you probably want to define conversion functions for MyObject* |
|
3835 |
that utilize QScriptEngine::newQObject() and |
|
3836 |
QScriptValue::toQObject().) |
|
3837 |
||
3838 |
If you only want to define a common script interface for values of |
|
3839 |
type \c{T}, and don't care how those values are represented |
|
3840 |
(i.e. storing them in QVariants is fine), use |
|
3841 |
\l{QScriptEngine::setDefaultPrototype()}{setDefaultPrototype}() |
|
3842 |
instead; this will minimize conversion costs. |
|
3843 |
||
3844 |
You need to declare the custom type first with |
|
3845 |
Q_DECLARE_METATYPE(). |
|
3846 |
||
3847 |
After a type has been registered, you can convert from a |
|
3848 |
QScriptValue to that type using |
|
3849 |
\l{QScriptEngine::fromScriptValue()}{fromScriptValue}(), and |
|
3850 |
create a QScriptValue from a value of that type using |
|
3851 |
\l{QScriptEngine::toScriptValue()}{toScriptValue}(). The engine |
|
3852 |
will take care of calling the proper conversion function when |
|
3853 |
calling C++ slots, and when getting or setting a C++ property; |
|
3854 |
i.e. the custom type may be used seamlessly on both the C++ side |
|
3855 |
and the script side. |
|
3856 |
||
3857 |
The following is an example of how to use this function. We will |
|
3858 |
specify custom conversion of our type \c{MyStruct}. Here's the C++ |
|
3859 |
type: |
|
3860 |
||
3861 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 20 |
|
3862 |
||
3863 |
We must declare it so that the type will be known to QMetaType: |
|
3864 |
||
3865 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 21 |
|
3866 |
||
3867 |
Next, the \c{MyStruct} conversion functions. We represent the |
|
3868 |
\c{MyStruct} value as a script object and just copy the properties: |
|
3869 |
||
3870 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 22 |
|
3871 |
||
3872 |
Now we can register \c{MyStruct} with the engine: |
|
3873 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 23 |
|
3874 |
||
3875 |
Working with \c{MyStruct} values is now easy: |
|
3876 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 24 |
|
3877 |
||
3878 |
If you want to be able to construct values of your custom type |
|
3879 |
from script code, you have to register a constructor function for |
|
3880 |
the type. For example: |
|
3881 |
||
3882 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 25 |
|
3883 |
||
3884 |
\sa qScriptRegisterSequenceMetaType(), qRegisterMetaType() |
|
3885 |
*/ |
|
3886 |
||
3887 |
/*! |
|
3888 |
\macro Q_SCRIPT_DECLARE_QMETAOBJECT(QMetaObject, ArgType) |
|
3889 |
\since 4.3 |
|
3890 |
\relates QScriptEngine |
|
3891 |
||
3892 |
Declares the given \a QMetaObject. Used in combination with |
|
3893 |
QScriptEngine::scriptValueFromQMetaObject() to make enums and |
|
3894 |
instantiation of \a QMetaObject available to script code. The |
|
3895 |
constructor generated by this macro takes a single argument of |
|
3896 |
type \a ArgType; typically the argument is the parent type of the |
|
3897 |
new instance, in which case \a ArgType is \c{QWidget*} or |
|
3898 |
\c{QObject*}. Objects created by the constructor will have |
|
3899 |
QScriptEngine::AutoOwnership ownership. |
|
3900 |
*/ |
|
3901 |
||
3902 |
/*! \fn int qScriptRegisterSequenceMetaType( |
|
3903 |
QScriptEngine *engine, |
|
3904 |
const QScriptValue &prototype = QScriptValue()) |
|
3905 |
\relates QScriptEngine |
|
3906 |
||
3907 |
Registers the sequence type \c{T} in the given \a engine. This |
|
3908 |
function provides conversion functions that convert between \c{T} |
|
3909 |
and Qt Script \c{Array} objects. \c{T} must provide a |
|
3910 |
const_iterator class and begin(), end() and push_back() |
|
3911 |
functions. If \a prototype is valid, it will be set as the |
|
3912 |
prototype of \c{Array} objects due to conversion from \c{T}; |
|
3913 |
otherwise, the standard \c{Array} prototype will be used. |
|
3914 |
||
3915 |
Returns the internal ID used by QMetaType. |
|
3916 |
||
3917 |
You need to declare the container type first with |
|
3918 |
Q_DECLARE_METATYPE(). If the element type isn't a standard Qt/C++ |
|
3919 |
type, it must be declared using Q_DECLARE_METATYPE() as well. |
|
3920 |
Example: |
|
3921 |
||
3922 |
\snippet doc/src/snippets/code/src_script_qscriptengine.cpp 26 |
|
3923 |
||
3924 |
\sa qScriptRegisterMetaType() |
|
3925 |
*/ |
|
3926 |
||
3927 |
/*! |
|
3928 |
Runs the garbage collector. |
|
3929 |
||
3930 |
The garbage collector will attempt to reclaim memory by locating and |
|
3931 |
disposing of objects that are no longer reachable in the script |
|
3932 |
environment. |
|
3933 |
||
3934 |
Normally you don't need to call this function; the garbage collector |
|
3935 |
will automatically be invoked when the QScriptEngine decides that |
|
3936 |
it's wise to do so (i.e. when a certain number of new objects have |
|
3937 |
been created). However, you can call this function to explicitly |
|
3938 |
request that garbage collection should be performed as soon as |
|
3939 |
possible. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3940 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3941 |
\sa reportAdditionalMemoryCost() |
0 | 3942 |
*/ |
3943 |
void QScriptEngine::collectGarbage() |
|
3944 |
{ |
|
3945 |
Q_D(QScriptEngine); |
|
3946 |
d->collectGarbage(); |
|
3947 |
} |
|
3948 |
||
3949 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3950 |
\since 4.7 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3951 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3952 |
Reports an additional memory cost of the given \a size, measured in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3953 |
bytes, to the garbage collector. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3954 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3955 |
This function can be called to indicate that a Qt Script object has |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3956 |
memory associated with it that isn't managed by Qt Script itself. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3957 |
Reporting the additional cost makes it more likely that the garbage |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3958 |
collector will be triggered. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3959 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3960 |
Note that if the additional memory is shared with objects outside |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3961 |
the scripting environment, the cost should not be reported, since |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3962 |
collecting the Qt Script object would not cause the memory to be |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3963 |
freed anyway. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3964 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3965 |
Negative \a size values are ignored, i.e. this function can't be |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3966 |
used to report that the additional memory has been deallocated. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3967 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3968 |
\sa collectGarbage() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3969 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3970 |
void QScriptEngine::reportAdditionalMemoryCost(int size) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3971 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3972 |
Q_D(QScriptEngine); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3973 |
d->reportAdditionalMemoryCost(size); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3974 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3975 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
3976 |
/*! |
0 | 3977 |
|
3978 |
Sets the interval between calls to QCoreApplication::processEvents |
|
3979 |
to \a interval milliseconds. |
|
3980 |
||
3981 |
While the interpreter is running, all event processing is by default |
|
3982 |
blocked. This means for instance that the gui will not be updated |
|
3983 |
and timers will not be fired. To allow event processing during |
|
3984 |
interpreter execution one can specify the processing interval to be |
|
3985 |
a positive value, indicating the number of milliseconds between each |
|
3986 |
time QCoreApplication::processEvents() is called. |
|
3987 |
||
3988 |
The default value is -1, which disables event processing during |
|
3989 |
interpreter execution. |
|
3990 |
||
3991 |
You can use QCoreApplication::postEvent() to post an event that |
|
3992 |
performs custom processing at the next interval. For example, you |
|
3993 |
could keep track of the total running time of the script and call |
|
3994 |
abortEvaluation() when you detect that the script has been running |
|
3995 |
for a long time without completing. |
|
3996 |
||
3997 |
\sa processEventsInterval() |
|
3998 |
*/ |
|
3999 |
void QScriptEngine::setProcessEventsInterval(int interval) |
|
4000 |
{ |
|
4001 |
Q_D(QScriptEngine); |
|
4002 |
d->processEventsInterval = interval; |
|
4003 |
||
4004 |
if (interval > 0) |
|
4005 |
d->globalData->timeoutChecker->setCheckInterval(interval); |
|
4006 |
||
4007 |
d->timeoutChecker()->setShouldProcessEvents(interval > 0); |
|
4008 |
} |
|
4009 |
||
4010 |
/*! |
|
4011 |
||
4012 |
Returns the interval in milliseconds between calls to |
|
4013 |
QCoreApplication::processEvents() while the interpreter is running. |
|
4014 |
||
4015 |
\sa setProcessEventsInterval() |
|
4016 |
*/ |
|
4017 |
int QScriptEngine::processEventsInterval() const |
|
4018 |
{ |
|
4019 |
Q_D(const QScriptEngine); |
|
4020 |
return d->processEventsInterval; |
|
4021 |
} |
|
4022 |
||
4023 |
/*! |
|
4024 |
\since 4.4 |
|
4025 |
||
4026 |
Returns true if this engine is currently evaluating a script, |
|
4027 |
otherwise returns false. |
|
4028 |
||
4029 |
\sa evaluate(), abortEvaluation() |
|
4030 |
*/ |
|
4031 |
bool QScriptEngine::isEvaluating() const |
|
4032 |
{ |
|
4033 |
Q_D(const QScriptEngine); |
|
4034 |
return (d->currentFrame != d->globalExec()) || d->inEval; |
|
4035 |
} |
|
4036 |
||
4037 |
/*! |
|
4038 |
\since 4.4 |
|
4039 |
||
4040 |
Aborts any script evaluation currently taking place in this engine. |
|
4041 |
The given \a result is passed back as the result of the evaluation |
|
4042 |
(i.e. it is returned from the call to evaluate() being aborted). |
|
4043 |
||
4044 |
If the engine isn't evaluating a script (i.e. isEvaluating() returns |
|
4045 |
false), this function does nothing. |
|
4046 |
||
4047 |
Call this function if you need to abort a running script for some |
|
4048 |
reason, e.g. when you have detected that the script has been |
|
4049 |
running for several seconds without completing. |
|
4050 |
||
4051 |
\sa evaluate(), isEvaluating(), setProcessEventsInterval() |
|
4052 |
*/ |
|
4053 |
void QScriptEngine::abortEvaluation(const QScriptValue &result) |
|
4054 |
{ |
|
4055 |
Q_D(QScriptEngine); |
|
4056 |
||
4057 |
d->timeoutChecker()->setShouldAbort(true); |
|
4058 |
d->abortResult = result; |
|
4059 |
} |
|
4060 |
||
4061 |
#ifndef QT_NO_QOBJECT |
|
4062 |
||
4063 |
/*! |
|
4064 |
\since 4.4 |
|
4065 |
\relates QScriptEngine |
|
4066 |
||
4067 |
Creates a connection from the \a signal in the \a sender to the |
|
4068 |
given \a function. If \a receiver is an object, it will act as the |
|
4069 |
`this' object when the signal handler function is invoked. Returns |
|
4070 |
true if the connection succeeds; otherwise returns false. |
|
4071 |
||
4072 |
\sa qScriptDisconnect(), QScriptEngine::signalHandlerException() |
|
4073 |
*/ |
|
4074 |
bool qScriptConnect(QObject *sender, const char *signal, |
|
4075 |
const QScriptValue &receiver, const QScriptValue &function) |
|
4076 |
{ |
|
4077 |
if (!sender || !signal) |
|
4078 |
return false; |
|
4079 |
if (!function.isFunction()) |
|
4080 |
return false; |
|
4081 |
if (receiver.isObject() && (receiver.engine() != function.engine())) |
|
4082 |
return false; |
|
4083 |
QScriptEnginePrivate *engine = QScriptEnginePrivate::get(function.engine()); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4084 |
QScript::APIShim shim(engine); |
0 | 4085 |
JSC::JSValue jscReceiver = engine->scriptValueToJSCValue(receiver); |
4086 |
JSC::JSValue jscFunction = engine->scriptValueToJSCValue(function); |
|
4087 |
return engine->scriptConnect(sender, signal, jscReceiver, jscFunction, |
|
4088 |
Qt::AutoConnection); |
|
4089 |
} |
|
4090 |
||
4091 |
/*! |
|
4092 |
\since 4.4 |
|
4093 |
\relates QScriptEngine |
|
4094 |
||
4095 |
Disconnects the \a signal in the \a sender from the given (\a |
|
4096 |
receiver, \a function) pair. Returns true if the connection is |
|
4097 |
successfully broken; otherwise returns false. |
|
4098 |
||
4099 |
\sa qScriptConnect() |
|
4100 |
*/ |
|
4101 |
bool qScriptDisconnect(QObject *sender, const char *signal, |
|
4102 |
const QScriptValue &receiver, const QScriptValue &function) |
|
4103 |
{ |
|
4104 |
if (!sender || !signal) |
|
4105 |
return false; |
|
4106 |
if (!function.isFunction()) |
|
4107 |
return false; |
|
4108 |
if (receiver.isObject() && (receiver.engine() != function.engine())) |
|
4109 |
return false; |
|
4110 |
QScriptEnginePrivate *engine = QScriptEnginePrivate::get(function.engine()); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4111 |
QScript::APIShim shim(engine); |
0 | 4112 |
JSC::JSValue jscReceiver = engine->scriptValueToJSCValue(receiver); |
4113 |
JSC::JSValue jscFunction = engine->scriptValueToJSCValue(function); |
|
4114 |
return engine->scriptDisconnect(sender, signal, jscReceiver, jscFunction); |
|
4115 |
} |
|
4116 |
||
4117 |
/*! |
|
4118 |
\since 4.4 |
|
4119 |
\fn void QScriptEngine::signalHandlerException(const QScriptValue &exception) |
|
4120 |
||
4121 |
This signal is emitted when a script function connected to a signal causes |
|
4122 |
an \a exception. |
|
4123 |
||
4124 |
\sa qScriptConnect() |
|
4125 |
*/ |
|
4126 |
||
4127 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
4128 |
#include "moc_qscriptengine.cpp" |
|
4129 |
QT_END_INCLUDE_NAMESPACE |
|
4130 |
||
4131 |
#endif // QT_NO_QOBJECT |
|
4132 |
||
4133 |
/*! |
|
4134 |
\since 4.4 |
|
4135 |
||
4136 |
Installs the given \a agent on this engine. The agent will be |
|
4137 |
notified of various events pertaining to script execution. This is |
|
4138 |
useful when you want to find out exactly what the engine is doing, |
|
4139 |
e.g. when evaluate() is called. The agent interface is the basis of |
|
4140 |
tools like debuggers and profilers. |
|
4141 |
||
4142 |
The engine maintains ownership of the \a agent. |
|
4143 |
||
4144 |
Calling this function will replace the existing agent, if any. |
|
4145 |
||
4146 |
\sa agent() |
|
4147 |
*/ |
|
4148 |
void QScriptEngine::setAgent(QScriptEngineAgent *agent) |
|
4149 |
{ |
|
4150 |
Q_D(QScriptEngine); |
|
4151 |
if (agent && (agent->engine() != this)) { |
|
4152 |
qWarning("QScriptEngine::setAgent(): " |
|
4153 |
"cannot set agent belonging to different engine"); |
|
4154 |
return; |
|
4155 |
} |
|
4156 |
if (d->activeAgent) |
|
4157 |
QScriptEngineAgentPrivate::get(d->activeAgent)->detach(); |
|
4158 |
d->activeAgent = agent; |
|
4159 |
if (agent) { |
|
4160 |
QScriptEngineAgentPrivate::get(agent)->attach(); |
|
4161 |
} |
|
4162 |
} |
|
4163 |
||
4164 |
/*! |
|
4165 |
\since 4.4 |
|
4166 |
||
4167 |
Returns the agent currently installed on this engine, or 0 if no |
|
4168 |
agent is installed. |
|
4169 |
||
4170 |
\sa setAgent() |
|
4171 |
*/ |
|
4172 |
QScriptEngineAgent *QScriptEngine::agent() const |
|
4173 |
{ |
|
4174 |
Q_D(const QScriptEngine); |
|
4175 |
return d->activeAgent; |
|
4176 |
} |
|
4177 |
||
4178 |
/*! |
|
4179 |
\since 4.4 |
|
4180 |
||
4181 |
Returns a handle that represents the given string, \a str. |
|
4182 |
||
4183 |
QScriptString can be used to quickly look up properties, and |
|
4184 |
compare property names, of script objects. |
|
4185 |
||
4186 |
\sa QScriptValue::property() |
|
4187 |
*/ |
|
4188 |
QScriptString QScriptEngine::toStringHandle(const QString &str) |
|
4189 |
{ |
|
4190 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4191 |
QScript::APIShim shim(d); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4192 |
return d->toStringHandle(JSC::Identifier(d->currentFrame, str)); |
0 | 4193 |
} |
4194 |
||
4195 |
/*! |
|
4196 |
\since 4.5 |
|
4197 |
||
4198 |
Converts the given \a value to an object, if such a conversion is |
|
4199 |
possible; otherwise returns an invalid QScriptValue. The conversion |
|
4200 |
is performed according to the following table: |
|
4201 |
||
4202 |
\table |
|
4203 |
\header \o Input Type \o Result |
|
4204 |
\row \o Undefined \o An invalid QScriptValue. |
|
4205 |
\row \o Null \o An invalid QScriptValue. |
|
4206 |
\row \o Boolean \o A new Boolean object whose internal value is set to the value of the boolean. |
|
4207 |
\row \o Number \o A new Number object whose internal value is set to the value of the number. |
|
4208 |
\row \o String \o A new String object whose internal value is set to the value of the string. |
|
4209 |
\row \o Object \o The result is the object itself (no conversion). |
|
4210 |
\endtable |
|
4211 |
||
4212 |
\sa newObject() |
|
4213 |
*/ |
|
4214 |
QScriptValue QScriptEngine::toObject(const QScriptValue &value) |
|
4215 |
{ |
|
4216 |
Q_D(QScriptEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4217 |
QScript::APIShim shim(d); |
0 | 4218 |
JSC::JSValue jscValue = d->scriptValueToJSCValue(value); |
4219 |
if (!jscValue || jscValue.isUndefined() || jscValue.isNull()) |
|
4220 |
return QScriptValue(); |
|
4221 |
JSC::ExecState* exec = d->currentFrame; |
|
4222 |
JSC::JSValue result = jscValue.toObject(exec); |
|
4223 |
return d->scriptValueFromJSCValue(result); |
|
4224 |
} |
|
4225 |
||
4226 |
/*! |
|
4227 |
\internal |
|
4228 |
||
4229 |
Returns the object with the given \a id, or an invalid |
|
4230 |
QScriptValue if there is no object with that id. |
|
4231 |
||
4232 |
\sa QScriptValue::objectId() |
|
4233 |
*/ |
|
4234 |
QScriptValue QScriptEngine::objectById(qint64 id) const |
|
4235 |
{ |
|
4236 |
Q_D(const QScriptEngine); |
|
4237 |
// Assumes that the cell was not been garbage collected |
|
4238 |
return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue((JSC::JSCell*)id); |
|
4239 |
} |
|
4240 |
||
4241 |
/*! |
|
4242 |
\since 4.5 |
|
4243 |
\class QScriptSyntaxCheckResult |
|
4244 |
||
4245 |
\brief The QScriptSyntaxCheckResult class provides the result of a script syntax check. |
|
4246 |
||
4247 |
\ingroup script |
|
4248 |
\mainclass |
|
4249 |
||
4250 |
QScriptSyntaxCheckResult is returned by QScriptEngine::checkSyntax() to |
|
4251 |
provide information about the syntactical (in)correctness of a script. |
|
4252 |
*/ |
|
4253 |
||
4254 |
/*! |
|
4255 |
\enum QScriptSyntaxCheckResult::State |
|
4256 |
||
4257 |
This enum specifies the state of a syntax check. |
|
4258 |
||
4259 |
\value Error The program contains a syntax error. |
|
4260 |
\value Intermediate The program is incomplete. |
|
4261 |
\value Valid The program is a syntactically correct Qt Script program. |
|
4262 |
*/ |
|
4263 |
||
4264 |
/*! |
|
4265 |
Constructs a new QScriptSyntaxCheckResult from the \a other result. |
|
4266 |
*/ |
|
4267 |
QScriptSyntaxCheckResult::QScriptSyntaxCheckResult(const QScriptSyntaxCheckResult &other) |
|
4268 |
: d_ptr(other.d_ptr) |
|
4269 |
{ |
|
4270 |
} |
|
4271 |
||
4272 |
/*! |
|
4273 |
\internal |
|
4274 |
*/ |
|
4275 |
QScriptSyntaxCheckResult::QScriptSyntaxCheckResult(QScriptSyntaxCheckResultPrivate *d) |
|
4276 |
: d_ptr(d) |
|
4277 |
{ |
|
4278 |
} |
|
4279 |
||
4280 |
/*! |
|
4281 |
\internal |
|
4282 |
*/ |
|
4283 |
QScriptSyntaxCheckResult::QScriptSyntaxCheckResult() |
|
4284 |
: d_ptr(0) |
|
4285 |
{ |
|
4286 |
} |
|
4287 |
||
4288 |
/*! |
|
4289 |
Destroys this QScriptSyntaxCheckResult. |
|
4290 |
*/ |
|
4291 |
QScriptSyntaxCheckResult::~QScriptSyntaxCheckResult() |
|
4292 |
{ |
|
4293 |
} |
|
4294 |
||
4295 |
/*! |
|
4296 |
Returns the state of this QScriptSyntaxCheckResult. |
|
4297 |
*/ |
|
4298 |
QScriptSyntaxCheckResult::State QScriptSyntaxCheckResult::state() const |
|
4299 |
{ |
|
4300 |
Q_D(const QScriptSyntaxCheckResult); |
|
4301 |
if (!d) |
|
4302 |
return Valid; |
|
4303 |
return d->state; |
|
4304 |
} |
|
4305 |
||
4306 |
/*! |
|
4307 |
Returns the error line number of this QScriptSyntaxCheckResult, or -1 if |
|
4308 |
there is no error. |
|
4309 |
||
4310 |
\sa state(), errorMessage() |
|
4311 |
*/ |
|
4312 |
int QScriptSyntaxCheckResult::errorLineNumber() const |
|
4313 |
{ |
|
4314 |
Q_D(const QScriptSyntaxCheckResult); |
|
4315 |
if (!d) |
|
4316 |
return -1; |
|
4317 |
return d->errorLineNumber; |
|
4318 |
} |
|
4319 |
||
4320 |
/*! |
|
4321 |
Returns the error column number of this QScriptSyntaxCheckResult, or -1 if |
|
4322 |
there is no error. |
|
4323 |
||
4324 |
\sa state(), errorLineNumber() |
|
4325 |
*/ |
|
4326 |
int QScriptSyntaxCheckResult::errorColumnNumber() const |
|
4327 |
{ |
|
4328 |
Q_D(const QScriptSyntaxCheckResult); |
|
4329 |
if (!d) |
|
4330 |
return -1; |
|
4331 |
return d->errorColumnNumber; |
|
4332 |
} |
|
4333 |
||
4334 |
/*! |
|
4335 |
Returns the error message of this QScriptSyntaxCheckResult, or an empty |
|
4336 |
string if there is no error. |
|
4337 |
||
4338 |
\sa state(), errorLineNumber() |
|
4339 |
*/ |
|
4340 |
QString QScriptSyntaxCheckResult::errorMessage() const |
|
4341 |
{ |
|
4342 |
Q_D(const QScriptSyntaxCheckResult); |
|
4343 |
if (!d) |
|
4344 |
return QString(); |
|
4345 |
return d->errorMessage; |
|
4346 |
} |
|
4347 |
||
4348 |
/*! |
|
4349 |
Assigns the \a other result to this QScriptSyntaxCheckResult, and returns a |
|
4350 |
reference to this QScriptSyntaxCheckResult. |
|
4351 |
*/ |
|
4352 |
QScriptSyntaxCheckResult &QScriptSyntaxCheckResult::operator=(const QScriptSyntaxCheckResult &other) |
|
4353 |
{ |
|
4354 |
d_ptr = other.d_ptr; |
|
4355 |
return *this; |
|
4356 |
} |
|
4357 |
||
4358 |
#ifdef QT_BUILD_INTERNAL |
|
4359 |
Q_AUTOTEST_EXPORT bool qt_script_isJITEnabled() |
|
4360 |
{ |
|
4361 |
#if ENABLE(JIT) |
|
4362 |
return true; |
|
4363 |
#else |
|
4364 |
return false; |
|
4365 |
#endif |
|
4366 |
} |
|
4367 |
#endif |
|
4368 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4369 |
#ifdef Q_CC_MSVC |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4370 |
// Try to prevent compiler from crashing. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4371 |
#pragma optimize("", off) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4372 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
4373 |
|
0 | 4374 |
QT_END_NAMESPACE |