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