|
1 /* |
|
2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) |
|
3 |
|
4 This library is free software; you can redistribute it and/or |
|
5 modify it under the terms of the GNU Library General Public |
|
6 License as published by the Free Software Foundation; either |
|
7 version 2 of the License, or (at your option) any later version. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 Library General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Library General Public License |
|
15 along with this library; see the file COPYING.LIB. If not, write to |
|
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
17 Boston, MA 02110-1301, USA. |
|
18 */ |
|
19 |
|
20 #include "config.h" |
|
21 |
|
22 #include "qscriptvalue.h" |
|
23 |
|
24 #include "qscriptengine.h" |
|
25 #include "qscriptengine_p.h" |
|
26 #include "qscriptvalue_p.h" |
|
27 #include <QtCore/qdebug.h> |
|
28 |
|
29 /*! |
|
30 Constructs an invalid value. |
|
31 */ |
|
32 QScriptValue::QScriptValue() |
|
33 : d_ptr(new QScriptValuePrivate()) |
|
34 { |
|
35 } |
|
36 |
|
37 /*! |
|
38 Constructs a new QScriptValue with a boolean \a value. |
|
39 */ |
|
40 QScriptValue::QScriptValue(bool value) |
|
41 : d_ptr(new QScriptValuePrivate(value)) |
|
42 { |
|
43 } |
|
44 |
|
45 /*! |
|
46 Constructs a new QScriptValue with a number \a value. |
|
47 */ |
|
48 QScriptValue::QScriptValue(int value) |
|
49 : d_ptr(new QScriptValuePrivate(value)) |
|
50 { |
|
51 } |
|
52 |
|
53 /*! |
|
54 Constructs a new QScriptValue with a number \a value. |
|
55 */ |
|
56 QScriptValue::QScriptValue(uint value) |
|
57 : d_ptr(new QScriptValuePrivate(value)) |
|
58 { |
|
59 } |
|
60 |
|
61 /*! |
|
62 Constructs a new QScriptValue with a number \a value. |
|
63 */ |
|
64 QScriptValue::QScriptValue(qsreal value) |
|
65 : d_ptr(new QScriptValuePrivate(value)) |
|
66 { |
|
67 } |
|
68 |
|
69 /*! |
|
70 Constructs a new QScriptValue with a string \a value. |
|
71 */ |
|
72 QScriptValue::QScriptValue(const QString& value) |
|
73 : d_ptr(new QScriptValuePrivate(value)) |
|
74 { |
|
75 } |
|
76 |
|
77 /*! |
|
78 Constructs a new QScriptValue with a special \a value. |
|
79 */ |
|
80 QScriptValue::QScriptValue(SpecialValue value) |
|
81 : d_ptr(new QScriptValuePrivate(value)) |
|
82 { |
|
83 } |
|
84 |
|
85 /*! |
|
86 Constructs a new QScriptValue with a string \a value. |
|
87 */ |
|
88 QScriptValue::QScriptValue(const char* value) |
|
89 : d_ptr(new QScriptValuePrivate(QString::fromUtf8(value))) |
|
90 { |
|
91 } |
|
92 |
|
93 /*! |
|
94 Block automatic convertion to bool |
|
95 \internal |
|
96 */ |
|
97 QScriptValue::QScriptValue(void* d) |
|
98 { |
|
99 Q_ASSERT(false); |
|
100 } |
|
101 |
|
102 /*! |
|
103 Constructs a new QScriptValue from private |
|
104 \internal |
|
105 */ |
|
106 QScriptValue::QScriptValue(QScriptValuePrivate* d) |
|
107 : d_ptr(d) |
|
108 { |
|
109 } |
|
110 |
|
111 /*! |
|
112 \obsolete |
|
113 |
|
114 Constructs a new QScriptValue with the boolean \a value and |
|
115 registers it with the script \a engine. |
|
116 */ |
|
117 QScriptValue::QScriptValue(QScriptEngine* engine, bool value) |
|
118 { |
|
119 if (engine) |
|
120 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), value); |
|
121 else |
|
122 d_ptr = new QScriptValuePrivate(value); |
|
123 } |
|
124 |
|
125 /*! |
|
126 \obsolete |
|
127 |
|
128 Constructs a new QScriptValue with the integer \a value and |
|
129 registers it with the script \a engine. |
|
130 */ |
|
131 QScriptValue::QScriptValue(QScriptEngine* engine, int value) |
|
132 { |
|
133 if (engine) |
|
134 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), value); |
|
135 else |
|
136 d_ptr = new QScriptValuePrivate(value); |
|
137 } |
|
138 |
|
139 /*! |
|
140 \obsolete |
|
141 |
|
142 Constructs a new QScriptValue with the unsigned integer \a value and |
|
143 registers it with the script \a engine. |
|
144 */ |
|
145 QScriptValue::QScriptValue(QScriptEngine* engine, uint value) |
|
146 { |
|
147 if (engine) |
|
148 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), value); |
|
149 else |
|
150 d_ptr = new QScriptValuePrivate(value); |
|
151 } |
|
152 |
|
153 /*! |
|
154 \obsolete |
|
155 |
|
156 Constructs a new QScriptValue with the qsreal \a value and |
|
157 registers it with the script \a engine. |
|
158 */ |
|
159 QScriptValue::QScriptValue(QScriptEngine* engine, qsreal value) |
|
160 { |
|
161 if (engine) |
|
162 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), value); |
|
163 else |
|
164 d_ptr = new QScriptValuePrivate(value); |
|
165 } |
|
166 |
|
167 /*! |
|
168 \obsolete |
|
169 |
|
170 Constructs a new QScriptValue with the string \a value and |
|
171 registers it with the script \a engine. |
|
172 */ |
|
173 QScriptValue::QScriptValue(QScriptEngine* engine, const QString& value) |
|
174 { |
|
175 if (engine) |
|
176 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), value); |
|
177 else |
|
178 d_ptr = new QScriptValuePrivate(value); |
|
179 } |
|
180 |
|
181 /*! |
|
182 \obsolete |
|
183 |
|
184 Constructs a new QScriptValue with the string \a value and |
|
185 registers it with the script \a engine. |
|
186 */ |
|
187 QScriptValue::QScriptValue(QScriptEngine* engine, const char* value) |
|
188 { |
|
189 if (engine) |
|
190 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), QString::fromUtf8(value)); |
|
191 else |
|
192 d_ptr = new QScriptValuePrivate(QString::fromUtf8(value)); |
|
193 } |
|
194 |
|
195 /*! |
|
196 \obsolete |
|
197 |
|
198 Constructs a new QScriptValue with the special \a value and |
|
199 registers it with the script \a engine. |
|
200 */ |
|
201 QScriptValue::QScriptValue(QScriptEngine* engine, SpecialValue value) |
|
202 { |
|
203 if (engine) |
|
204 d_ptr = new QScriptValuePrivate(QScriptEnginePrivate::get(engine), value); |
|
205 else |
|
206 d_ptr = new QScriptValuePrivate(value); |
|
207 } |
|
208 |
|
209 /*! |
|
210 Constructs a new QScriptValue that is a copy of \a other. |
|
211 |
|
212 Note that if \a other is an object (i.e., isObject() would return |
|
213 true), then only a reference to the underlying object is copied into |
|
214 the new script value (i.e., the object itself is not copied). |
|
215 */ |
|
216 QScriptValue::QScriptValue(const QScriptValue& other) |
|
217 : d_ptr(other.d_ptr) |
|
218 { |
|
219 } |
|
220 |
|
221 /*! |
|
222 Destroys this QScriptValue. |
|
223 */ |
|
224 QScriptValue::~QScriptValue() |
|
225 { |
|
226 } |
|
227 |
|
228 /*! |
|
229 Returns true if this QScriptValue is valid; otherwise returns |
|
230 false. |
|
231 */ |
|
232 bool QScriptValue::isValid() const |
|
233 { |
|
234 return d_ptr->isValid(); |
|
235 } |
|
236 |
|
237 /*! |
|
238 Returns true if this QScriptValue is of the primitive type Boolean; |
|
239 otherwise returns false. |
|
240 |
|
241 \sa toBool() |
|
242 */ |
|
243 bool QScriptValue::isBool() const |
|
244 { |
|
245 return d_ptr->isBool(); |
|
246 } |
|
247 |
|
248 /*! |
|
249 \obsolete |
|
250 |
|
251 Use isBool() instead. |
|
252 Returns true if this QScriptValue is of the primitive type Boolean; |
|
253 otherwise returns false. |
|
254 */ |
|
255 bool QScriptValue::isBoolean() const |
|
256 { |
|
257 return d_ptr->isBool(); |
|
258 } |
|
259 |
|
260 /*! |
|
261 Returns true if this QScriptValue is of the primitive type Number; |
|
262 otherwise returns false. |
|
263 |
|
264 \sa toNumber() |
|
265 */ |
|
266 bool QScriptValue::isNumber() const |
|
267 { |
|
268 return d_ptr->isNumber(); |
|
269 } |
|
270 |
|
271 /*! |
|
272 Returns true if this QScriptValue is of the primitive type Null; |
|
273 otherwise returns false. |
|
274 |
|
275 \sa QScriptEngine::nullValue() |
|
276 */ |
|
277 bool QScriptValue::isNull() const |
|
278 { |
|
279 return d_ptr->isNull(); |
|
280 } |
|
281 |
|
282 /*! |
|
283 Returns true if this QScriptValue is of the primitive type String; |
|
284 otherwise returns false. |
|
285 |
|
286 \sa toString() |
|
287 */ |
|
288 bool QScriptValue::isString() const |
|
289 { |
|
290 return d_ptr->isString(); |
|
291 } |
|
292 |
|
293 /*! |
|
294 Returns true if this QScriptValue is of the primitive type Undefined; |
|
295 otherwise returns false. |
|
296 |
|
297 \sa QScriptEngine::undefinedValue() |
|
298 */ |
|
299 bool QScriptValue::isUndefined() const |
|
300 { |
|
301 return d_ptr->isUndefined(); |
|
302 } |
|
303 |
|
304 /*! |
|
305 Returns true if this QScriptValue is an object of the Error class; |
|
306 otherwise returns false. |
|
307 |
|
308 \sa QScriptContext::throwError() |
|
309 */ |
|
310 bool QScriptValue::isError() const |
|
311 { |
|
312 return d_ptr->isError(); |
|
313 } |
|
314 |
|
315 /*! |
|
316 Returns true if this QScriptValue is an object of the Array class; |
|
317 otherwise returns false. |
|
318 |
|
319 \sa QScriptEngine::newArray() |
|
320 */ |
|
321 bool QScriptValue::isArray() const |
|
322 { |
|
323 return d_ptr->isArray(); |
|
324 } |
|
325 |
|
326 /*! |
|
327 Returns true if this QScriptValue is of the Object type; otherwise |
|
328 returns false. |
|
329 |
|
330 Note that function values, variant values, and QObject values are |
|
331 objects, so this function returns true for such values. |
|
332 |
|
333 \sa toObject(), QScriptEngine::newObject() |
|
334 */ |
|
335 bool QScriptValue::isObject() const |
|
336 { |
|
337 return d_ptr->isObject(); |
|
338 } |
|
339 |
|
340 /*! |
|
341 Returns true if this QScriptValue is a function; otherwise returns |
|
342 false. |
|
343 |
|
344 \sa call() |
|
345 */ |
|
346 bool QScriptValue::isFunction() const |
|
347 { |
|
348 return d_ptr->isFunction(); |
|
349 } |
|
350 |
|
351 /*! |
|
352 Returns the string value of this QScriptValue, as defined in |
|
353 \l{ECMA-262} section 9.8, "ToString". |
|
354 |
|
355 Note that if this QScriptValue is an object, calling this function |
|
356 has side effects on the script engine, since the engine will call |
|
357 the object's toString() function (and possibly valueOf()) in an |
|
358 attempt to convert the object to a primitive value (possibly |
|
359 resulting in an uncaught script exception). |
|
360 |
|
361 \sa isString() |
|
362 */ |
|
363 QString QScriptValue::toString() const |
|
364 { |
|
365 return d_ptr->toString(); |
|
366 } |
|
367 |
|
368 /*! |
|
369 Returns the number value of this QScriptValue, as defined in |
|
370 \l{ECMA-262} section 9.3, "ToNumber". |
|
371 |
|
372 Note that if this QScriptValue is an object, calling this function |
|
373 has side effects on the script engine, since the engine will call |
|
374 the object's valueOf() function (and possibly toString()) in an |
|
375 attempt to convert the object to a primitive value (possibly |
|
376 resulting in an uncaught script exception). |
|
377 |
|
378 \sa isNumber(), toInteger(), toInt32(), toUInt32(), toUInt16() |
|
379 */ |
|
380 qsreal QScriptValue::toNumber() const |
|
381 { |
|
382 return d_ptr->toNumber(); |
|
383 } |
|
384 |
|
385 /*! |
|
386 Returns the boolean value of this QScriptValue, using the conversion |
|
387 rules described in \l{ECMA-262} section 9.2, "ToBoolean". |
|
388 |
|
389 Note that if this QScriptValue is an object, calling this function |
|
390 has side effects on the script engine, since the engine will call |
|
391 the object's valueOf() function (and possibly toString()) in an |
|
392 attempt to convert the object to a primitive value (possibly |
|
393 resulting in an uncaught script exception). |
|
394 |
|
395 \sa isBool() |
|
396 */ |
|
397 bool QScriptValue::toBool() const |
|
398 { |
|
399 return d_ptr->toBool(); |
|
400 } |
|
401 |
|
402 /*! |
|
403 \obsolete |
|
404 |
|
405 Use toBool() instead. |
|
406 */ |
|
407 bool QScriptValue::toBoolean() const |
|
408 { |
|
409 return d_ptr->toBool(); |
|
410 } |
|
411 |
|
412 /*! |
|
413 Returns the integer value of this QScriptValue, using the conversion |
|
414 rules described in \l{ECMA-262} section 9.4, "ToInteger". |
|
415 |
|
416 Note that if this QScriptValue is an object, calling this function |
|
417 has side effects on the script engine, since the engine will call |
|
418 the object's valueOf() function (and possibly toString()) in an |
|
419 attempt to convert the object to a primitive value (possibly |
|
420 resulting in an uncaught script exception). |
|
421 |
|
422 \sa toNumber() |
|
423 */ |
|
424 qsreal QScriptValue::toInteger() const |
|
425 { |
|
426 return d_ptr->toInteger(); |
|
427 } |
|
428 |
|
429 /*! |
|
430 Returns the signed 32-bit integer value of this QScriptValue, using |
|
431 the conversion rules described in \l{ECMA-262} section 9.5, "ToInt32". |
|
432 |
|
433 Note that if this QScriptValue is an object, calling this function |
|
434 has side effects on the script engine, since the engine will call |
|
435 the object's valueOf() function (and possibly toString()) in an |
|
436 attempt to convert the object to a primitive value (possibly |
|
437 resulting in an uncaught script exception). |
|
438 |
|
439 \sa toNumber(), toUInt32() |
|
440 */ |
|
441 qint32 QScriptValue::toInt32() const |
|
442 { |
|
443 return d_ptr->toInt32(); |
|
444 } |
|
445 |
|
446 /*! |
|
447 Returns the unsigned 32-bit integer value of this QScriptValue, using |
|
448 the conversion rules described in \l{ECMA-262} section 9.6, "ToUint32". |
|
449 |
|
450 Note that if this QScriptValue is an object, calling this function |
|
451 has side effects on the script engine, since the engine will call |
|
452 the object's valueOf() function (and possibly toString()) in an |
|
453 attempt to convert the object to a primitive value (possibly |
|
454 resulting in an uncaught script exception). |
|
455 |
|
456 \sa toNumber(), toInt32() |
|
457 */ |
|
458 quint32 QScriptValue::toUInt32() const |
|
459 { |
|
460 return d_ptr->toUInt32(); |
|
461 } |
|
462 |
|
463 /*! |
|
464 Returns the unsigned 16-bit integer value of this QScriptValue, using |
|
465 the conversion rules described in \l{ECMA-262} section 9.7, "ToUint16". |
|
466 |
|
467 Note that if this QScriptValue is an object, calling this function |
|
468 has side effects on the script engine, since the engine will call |
|
469 the object's valueOf() function (and possibly toString()) in an |
|
470 attempt to convert the object to a primitive value (possibly |
|
471 resulting in an uncaught script exception). |
|
472 |
|
473 \sa toNumber() |
|
474 */ |
|
475 quint16 QScriptValue::toUInt16() const |
|
476 { |
|
477 return d_ptr->toUInt16(); |
|
478 } |
|
479 |
|
480 /*! |
|
481 \obsolete |
|
482 |
|
483 This function is obsolete; use QScriptEngine::toObject() instead. |
|
484 */ |
|
485 QScriptValue QScriptValue::toObject() const |
|
486 { |
|
487 return QScriptValuePrivate::get(d_ptr->toObject()); |
|
488 } |
|
489 |
|
490 /*! |
|
491 Calls this QScriptValue as a function, using \a thisObject as |
|
492 the `this' object in the function call, and passing \a args |
|
493 as arguments to the function. Returns the value returned from |
|
494 the function. |
|
495 |
|
496 If this QScriptValue is not a function, call() does nothing |
|
497 and returns an invalid QScriptValue. |
|
498 |
|
499 Note that if \a thisObject is not an object, the global object |
|
500 (see \l{QScriptEngine::globalObject()}) will be used as the |
|
501 `this' object. |
|
502 |
|
503 Calling call() can cause an exception to occur in the script engine; |
|
504 in that case, call() returns the value that was thrown (typically an |
|
505 \c{Error} object). You can call |
|
506 QScriptEngine::hasUncaughtException() to determine if an exception |
|
507 occurred. |
|
508 |
|
509 \snippet doc/src/snippets/code/src_script_qscriptvalue.cpp 2 |
|
510 |
|
511 \sa construct() |
|
512 */ |
|
513 QScriptValue QScriptValue::call(const QScriptValue& thisObject, const QScriptValueList& args) |
|
514 { |
|
515 return d_ptr->call(thisObject.d_ptr.data(), args); |
|
516 } |
|
517 |
|
518 /*! |
|
519 Returns the QScriptEngine that created this QScriptValue, |
|
520 or 0 if this QScriptValue is invalid or the value is not |
|
521 associated with a particular engine. |
|
522 */ |
|
523 QScriptEngine* QScriptValue::engine() const |
|
524 { |
|
525 QScriptEnginePrivate* engine = d_ptr->engine(); |
|
526 if (engine) |
|
527 return QScriptEnginePrivate::get(engine); |
|
528 return 0; |
|
529 } |
|
530 |
|
531 /*! |
|
532 If this QScriptValue is an object, returns the internal prototype |
|
533 (\c{__proto__} property) of this object; otherwise returns an |
|
534 invalid QScriptValue. |
|
535 |
|
536 \sa setPrototype(), isObject() |
|
537 */ |
|
538 QScriptValue QScriptValue::prototype() const |
|
539 { |
|
540 return QScriptValuePrivate::get(d_ptr->prototype()); |
|
541 } |
|
542 |
|
543 /*! |
|
544 If this QScriptValue is an object, sets the internal prototype |
|
545 (\c{__proto__} property) of this object to be \a prototype; |
|
546 otherwise does nothing. |
|
547 |
|
548 The internal prototype should not be confused with the public |
|
549 property with name "prototype"; the public prototype is usually |
|
550 only set on functions that act as constructors. |
|
551 |
|
552 \sa prototype(), isObject() |
|
553 */ |
|
554 void QScriptValue::setPrototype(const QScriptValue& prototype) |
|
555 { |
|
556 d_ptr->setPrototype(QScriptValuePrivate::get(prototype)); |
|
557 } |
|
558 |
|
559 /*! |
|
560 Assigns the \a other value to this QScriptValue. |
|
561 |
|
562 Note that if \a other is an object (isObject() returns true), |
|
563 only a reference to the underlying object will be assigned; |
|
564 the object itself will not be copied. |
|
565 */ |
|
566 QScriptValue& QScriptValue::operator=(const QScriptValue& other) |
|
567 { |
|
568 d_ptr = other.d_ptr; |
|
569 return *this; |
|
570 } |
|
571 |
|
572 /*! |
|
573 Returns true if this QScriptValue is equal to \a other, otherwise |
|
574 returns false. The comparison follows the behavior described in |
|
575 \l{ECMA-262} section 11.9.3, "The Abstract Equality Comparison |
|
576 Algorithm". |
|
577 |
|
578 This function can return true even if the type of this QScriptValue |
|
579 is different from the type of the \a other value; i.e. the |
|
580 comparison is not strict. For example, comparing the number 9 to |
|
581 the string "9" returns true; comparing an undefined value to a null |
|
582 value returns true; comparing a \c{Number} object whose primitive |
|
583 value is 6 to a \c{String} object whose primitive value is "6" |
|
584 returns true; and comparing the number 1 to the boolean value |
|
585 \c{true} returns true. If you want to perform a comparison |
|
586 without such implicit value conversion, use strictlyEquals(). |
|
587 |
|
588 Note that if this QScriptValue or the \a other value are objects, |
|
589 calling this function has side effects on the script engine, since |
|
590 the engine will call the object's valueOf() function (and possibly |
|
591 toString()) in an attempt to convert the object to a primitive value |
|
592 (possibly resulting in an uncaught script exception). |
|
593 |
|
594 \sa strictlyEquals(), lessThan() |
|
595 */ |
|
596 bool QScriptValue::equals(const QScriptValue& other) const |
|
597 { |
|
598 return d_ptr->equals(QScriptValuePrivate::get(other)); |
|
599 } |
|
600 |
|
601 /*! |
|
602 Returns true if this QScriptValue is equal to \a other using strict |
|
603 comparison (no conversion), otherwise returns false. The comparison |
|
604 follows the behavior described in \l{ECMA-262} section 11.9.6, "The |
|
605 Strict Equality Comparison Algorithm". |
|
606 |
|
607 If the type of this QScriptValue is different from the type of the |
|
608 \a other value, this function returns false. If the types are equal, |
|
609 the result depends on the type, as shown in the following table: |
|
610 |
|
611 \table |
|
612 \header \o Type \o Result |
|
613 \row \o Undefined \o true |
|
614 \row \o Null \o true |
|
615 \row \o Boolean \o true if both values are true, false otherwise |
|
616 \row \o Number \o false if either value is NaN (Not-a-Number); true if values are equal, false otherwise |
|
617 \row \o String \o true if both values are exactly the same sequence of characters, false otherwise |
|
618 \row \o Object \o true if both values refer to the same object, false otherwise |
|
619 \endtable |
|
620 |
|
621 \sa equals() |
|
622 */ |
|
623 bool QScriptValue::strictlyEquals(const QScriptValue& other) const |
|
624 { |
|
625 return d_ptr->strictlyEquals(QScriptValuePrivate::get(other)); |
|
626 } |
|
627 |
|
628 /*! |
|
629 Returns true if this QScriptValue is an instance of |
|
630 \a other; otherwise returns false. |
|
631 |
|
632 This QScriptValue is considered to be an instance of \a other if |
|
633 \a other is a function and the value of the \c{prototype} |
|
634 property of \a other is in the prototype chain of this |
|
635 QScriptValue. |
|
636 */ |
|
637 bool QScriptValue::instanceOf(const QScriptValue& other) const |
|
638 { |
|
639 return d_ptr->instanceOf(QScriptValuePrivate::get(other)); |
|
640 } |
|
641 |
|
642 /*! |
|
643 Returns the value of this QScriptValue's property with the given \a name, |
|
644 using the given \a mode to resolve the property. |
|
645 |
|
646 If no such property exists, an invalid QScriptValue is returned. |
|
647 |
|
648 If the property is implemented using a getter function (i.e. has the |
|
649 PropertyGetter flag set), calling property() has side-effects on the |
|
650 script engine, since the getter function will be called (possibly |
|
651 resulting in an uncaught script exception). If an exception |
|
652 occurred, property() returns the value that was thrown (typically |
|
653 an \c{Error} object). |
|
654 |
|
655 \sa setProperty(), propertyFlags(), QScriptValueIterator |
|
656 */ |
|
657 QScriptValue QScriptValue::property(const QString& name, const ResolveFlags& mode) const |
|
658 { |
|
659 return QScriptValuePrivate::get(d_ptr->property(name, mode)); |
|
660 } |
|
661 |
|
662 /*! |
|
663 \overload |
|
664 |
|
665 Returns the value of this QScriptValue's property with the given \a name, |
|
666 using the given \a mode to resolve the property. |
|
667 |
|
668 This overload of property() is useful when you need to look up the |
|
669 same property repeatedly, since the lookup can be performed faster |
|
670 when the name is represented as an interned string. |
|
671 |
|
672 \sa QScriptEngine::toStringHandle(), setProperty() |
|
673 */ |
|
674 QScriptValue QScriptValue::property(const QScriptString& name, const ResolveFlags& mode) const |
|
675 { |
|
676 return QScriptValuePrivate::get(d_ptr->property(QScriptStringPrivate::get(name).constData(), mode)); |
|
677 } |
|
678 |
|
679 /*! |
|
680 \overload |
|
681 |
|
682 Returns the property at the given \a arrayIndex, using the given \a |
|
683 mode to resolve the property. |
|
684 |
|
685 This function is provided for convenience and performance when |
|
686 working with array objects. |
|
687 |
|
688 If this QScriptValue is not an Array object, this function behaves |
|
689 as if property() was called with the string representation of \a |
|
690 arrayIndex. |
|
691 */ |
|
692 QScriptValue QScriptValue::property(quint32 arrayIndex, const ResolveFlags& mode) const |
|
693 { |
|
694 return QScriptValuePrivate::get(d_ptr->property(arrayIndex, mode)); |
|
695 } |
|
696 |
|
697 /*! |
|
698 Sets the value of this QScriptValue's property with the given \a name to |
|
699 the given \a value. |
|
700 |
|
701 If this QScriptValue is not an object, this function does nothing. |
|
702 |
|
703 If this QScriptValue does not already have a property with name \a name, |
|
704 a new property is created; the given \a flags then specify how this |
|
705 property may be accessed by script code. |
|
706 |
|
707 If \a value is invalid, the property is removed. |
|
708 |
|
709 If the property is implemented using a setter function (i.e. has the |
|
710 PropertySetter flag set), calling setProperty() has side-effects on |
|
711 the script engine, since the setter function will be called with the |
|
712 given \a value as argument (possibly resulting in an uncaught script |
|
713 exception). |
|
714 |
|
715 Note that you cannot specify custom getter or setter functions for |
|
716 built-in properties, such as the \c{length} property of Array objects |
|
717 or meta properties of QObject objects. |
|
718 |
|
719 \sa property() |
|
720 */ |
|
721 void QScriptValue::setProperty(const QString& name, const QScriptValue& value, const PropertyFlags& flags) |
|
722 { |
|
723 d_ptr->setProperty(name, QScriptValuePrivate::get(value), flags); |
|
724 } |
|
725 |
|
726 /*! |
|
727 \overload |
|
728 |
|
729 Sets the property at the given \a arrayIndex to the given \a value. |
|
730 |
|
731 This function is provided for convenience and performance when |
|
732 working with array objects. |
|
733 |
|
734 If this QScriptValue is not an Array object, this function behaves |
|
735 as if setProperty() was called with the string representation of \a |
|
736 arrayIndex. |
|
737 */ |
|
738 void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue& value, const PropertyFlags& flags) |
|
739 { |
|
740 d_ptr->setProperty(arrayIndex, QScriptValuePrivate::get(value), flags); |
|
741 } |
|
742 |
|
743 /*! |
|
744 Sets the value of this QScriptValue's property with the given \a |
|
745 name to the given \a value. The given \a flags specify how this |
|
746 property may be accessed by script code. |
|
747 |
|
748 This overload of setProperty() is useful when you need to set the |
|
749 same property repeatedly, since the operation can be performed |
|
750 faster when the name is represented as an interned string. |
|
751 |
|
752 \sa QScriptEngine::toStringHandle() |
|
753 */ |
|
754 void QScriptValue::setProperty(const QScriptString& name, const QScriptValue& value, const PropertyFlags& flags) |
|
755 { |
|
756 d_ptr->setProperty(QScriptStringPrivate::get(name).constData(), QScriptValuePrivate::get(value), flags); |
|
757 } |
|
758 |
|
759 /*! |
|
760 Returns the flags of the property with the given \a name, using the |
|
761 given \a mode to resolve the property. |
|
762 |
|
763 \sa property() |
|
764 */ |
|
765 QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QString& name, const ResolveFlags& mode) const |
|
766 { |
|
767 return d_ptr->propertyFlags(name, mode); |
|
768 } |
|
769 |
|
770 /*! |
|
771 Returns the flags of the property with the given \a name, using the |
|
772 given \a mode to resolve the property. |
|
773 |
|
774 \sa property() |
|
775 */ |
|
776 QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QScriptString& name, const ResolveFlags& mode) const |
|
777 { |
|
778 return d_ptr->propertyFlags(QScriptStringPrivate::get(name).constData(), mode); |
|
779 } |