Qt 4.8
qscriptvalue.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #include "config.h"
25 #include "qscriptvalue.h"
26 
27 #include "qscriptvalue_p.h"
28 #include "qscriptengine.h"
29 #include "qscriptengine_p.h"
30 #include "qscriptstring_p.h"
31 
32 #include "JSGlobalObject.h"
33 #include "JSImmediate.h"
34 #include "JSObject.h"
35 #include "JSValue.h"
36 #include "JSFunction.h"
37 #include "Identifier.h"
38 #include "Operations.h"
39 #include "Arguments.h"
40 
41 #include <QtCore/qvariant.h>
42 #include <QtCore/qvarlengtharray.h>
43 #include <QtCore/qnumeric.h>
44 
182 
184 {
185  if (isJSC())
186  jscValue = JSC::JSValue();
187  engine = 0;
188 }
189 
194  : d_ptr(d)
195 {
196 }
197 
202  : d_ptr(0)
203 {
204 }
205 
210 {
211 }
212 
221  : d_ptr(other.d_ptr)
222 {
223 }
224 
236 {
237  switch (value) {
238  case NullValue:
239  d_ptr->initFrom(JSC::jsNull());
240  break;
241  case UndefinedValue:
242  d_ptr->initFrom(JSC::jsUndefined());
243  break;
244  }
245 }
246 
257 {
258  d_ptr->initFrom(JSC::jsBoolean(val));
259 }
260 
270 {
271  if (engine) {
273  JSC::ExecState *exec = d_ptr->engine->currentFrame;
274  d_ptr->initFrom(JSC::jsNumber(exec, val));
275  } else
276  d_ptr->initFrom(val);
277 }
278 
288 {
289  if (engine) {
291  JSC::ExecState *exec = d_ptr->engine->currentFrame;
292  d_ptr->initFrom(JSC::jsNumber(exec, val));
293  } else
294  d_ptr->initFrom(val);
295 }
296 
306 {
307  if (engine) {
309  JSC::ExecState *exec = d_ptr->engine->currentFrame;
310  d_ptr->initFrom(JSC::jsNumber(exec, val));
311  } else
312  d_ptr->initFrom(val);
313 }
314 
324 {
325  if (engine) {
327  JSC::ExecState *exec = d_ptr->engine->currentFrame;
328  d_ptr->initFrom(JSC::jsString(exec, val));
329  } else {
330  d_ptr->initFrom(val);
331  }
332 }
333 
342 #ifndef QT_NO_CAST_FROM_ASCII
345 {
346  if (engine) {
348  JSC::ExecState *exec = d_ptr->engine->currentFrame;
349  d_ptr->initFrom(JSC::jsString(exec, val));
350  } else {
352  }
353 }
354 #endif
355 
365  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
366 {
367  switch (value) {
368  case NullValue:
369  d_ptr->initFrom(JSC::jsNull());
370  break;
371  case UndefinedValue:
372  d_ptr->initFrom(JSC::jsUndefined());
373  break;
374  }
375 }
376 
386  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
387 {
388  d_ptr->initFrom(JSC::jsBoolean(value));
389 }
390 
400  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
401 {
402  d_ptr->initFrom(value);
403 }
404 
414  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
415 {
416  d_ptr->initFrom(value);
417 }
418 
428  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
429 {
430  d_ptr->initFrom(value);
431 }
432 
442  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
443 {
444  d_ptr->initFrom(value);
445 }
446 
456  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
457 {
458  d_ptr->initFrom(value);
459 }
460 
470 #ifndef QT_NO_CAST_FROM_ASCII
471 QScriptValue::QScriptValue(const char *value)
472  : d_ptr(new (/*engine=*/0)QScriptValuePrivate(/*engine=*/0))
473 {
475 }
476 #endif
477 
486 {
487  d_ptr = other.d_ptr;
488  return *this;
489 }
490 
498 {
499  Q_D(const QScriptValue);
500  if (!d || !d->isJSC())
501  return false;
502  return QScriptEnginePrivate::isError(d->jscValue);
503 }
504 
512 {
513  Q_D(const QScriptValue);
514  if (!d || !d->isJSC())
515  return false;
516  return QScriptEnginePrivate::isArray(d->jscValue);
517 }
518 
526 {
527  Q_D(const QScriptValue);
528  if (!d || !d->isJSC())
529  return false;
530  return QScriptEnginePrivate::isDate(d->jscValue);
531 }
532 
540 {
541  Q_D(const QScriptValue);
542  if (!d || !d->isJSC())
543  return false;
544  return QScriptEnginePrivate::isRegExp(d->jscValue);
545 }
546 
555 {
556  Q_D(const QScriptValue);
557  if (!d || !d->isObject())
558  return QScriptValue();
559  return d->engine->scriptValueFromJSCValue(JSC::asObject(d->jscValue)->prototype());
560 }
561 
574 {
575  Q_D(QScriptValue);
576  if (!d || !d->isObject())
577  return;
578 
579  JSC::JSValue other = d->engine->scriptValueToJSCValue(prototype);
580  if (!other || !(other.isObject() || other.isNull()))
581  return;
582 
583  if (QScriptValuePrivate::getEngine(prototype)
584  && (QScriptValuePrivate::getEngine(prototype) != d->engine)) {
585  qWarning("QScriptValue::setPrototype() failed: "
586  "cannot set a prototype created in "
587  "a different engine");
588  return;
589  }
590  JSC::JSObject *thisObject = JSC::asObject(d->jscValue);
591 
592  // check for cycle
593  JSC::JSValue nextPrototypeValue = other;
594  while (nextPrototypeValue && nextPrototypeValue.isObject()) {
595  JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue);
596  if (nextPrototype == thisObject) {
597  qWarning("QScriptValue::setPrototype() failed: cyclic prototype value");
598  return;
599  }
600  nextPrototypeValue = nextPrototype->prototype();
601  }
602 
603  thisObject->setPrototype(other);
604 
605  // Sync the internal Global Object prototype if appropriate.
606  if (((thisObject == d->engine->originalGlobalObjectProxy)
607  && !d->engine->customGlobalObject())
608  || (thisObject == d->engine->customGlobalObject())) {
609  d->engine->originalGlobalObject()->setPrototype(other);
610  }
611 }
612 
617 {
618  Q_D(const QScriptValue);
619  if (!d || !d->isObject())
620  return QScriptValue();
621  QScript::APIShim shim(d->engine);
622  // ### make hidden property
623  JSC::JSValue result = d->property("__qt_scope__", QScriptValue::ResolveLocal);
624  return d->engine->scriptValueFromJSCValue(result);
625 }
626 
631 {
632  Q_D(QScriptValue);
633  if (!d || !d->isObject())
634  return;
635  if (scope.isValid() && QScriptValuePrivate::getEngine(scope)
636  && (QScriptValuePrivate::getEngine(scope) != d->engine)) {
637  qWarning("QScriptValue::setScope() failed: "
638  "cannot set a scope object created in "
639  "a different engine");
640  return;
641  }
642  JSC::JSValue other = d->engine->scriptValueToJSCValue(scope);
643  JSC::ExecState *exec = d->engine->currentFrame;
644  JSC::Identifier id = JSC::Identifier(exec, "__qt_scope__");
645  if (!scope.isValid()) {
646  JSC::asObject(d->jscValue)->removeDirect(id);
647  } else {
648  // ### make hidden property
649  JSC::asObject(d->jscValue)->putDirect(id, other);
650  }
651 }
652 
662 bool QScriptValue::instanceOf(const QScriptValue &other) const
663 {
664  Q_D(const QScriptValue);
665  if (!d || !d->isObject() || !other.isObject())
666  return false;
667  if (QScriptValuePrivate::getEngine(other) != d->engine) {
668  qWarning("QScriptValue::instanceof: "
669  "cannot perform operation on a value created in "
670  "a different engine");
671  return false;
672  }
673  JSC::JSValue jscProto = d->engine->scriptValueToJSCValue(other.property(QLatin1String("prototype")));
674  if (!jscProto)
675  jscProto = JSC::jsUndefined();
676  JSC::ExecState *exec = d->engine->currentFrame;
677  JSC::JSValue jscOther = d->engine->scriptValueToJSCValue(other);
678  return JSC::asObject(jscOther)->hasInstance(exec, d->jscValue, jscProto);
679 }
680 
681 // ### move
682 
683 namespace QScript
684 {
685 
686 enum Type {
693 };
694 
695 static Type type(const QScriptValue &v)
696 {
697  if (v.isUndefined())
698  return Undefined;
699  else if (v.isNull())
700  return Null;
701  else if (v.isBoolean())
702  return Boolean;
703  else if (v.isString())
704  return String;
705  else if (v.isNumber())
706  return Number;
707  Q_ASSERT(v.isObject());
708  return Object;
709 }
710 
711 static QScriptValue ToPrimitive(const QScriptValue &object, JSC::PreferredPrimitiveType hint = JSC::NoPreference)
712 {
713  Q_ASSERT(object.isObject());
715  Q_ASSERT(pp->engine != 0);
716  QScript::APIShim shim(pp->engine);
717  JSC::ExecState *exec = pp->engine->currentFrame;
718  JSC::JSValue savedException;
719  QScriptEnginePrivate::saveException(exec, &savedException);
720  JSC::JSValue result = JSC::asObject(pp->jscValue)->toPrimitive(exec, hint);
721  QScriptEnginePrivate::restoreException(exec, savedException);
722  return pp->engine->scriptValueFromJSCValue(result);
723 }
724 
725 static bool IsNumerical(const QScriptValue &value)
726 {
727  return value.isNumber() || value.isBool();
728 }
729 
730 static bool LessThan(QScriptValue lhs, QScriptValue rhs)
731 {
732  if (type(lhs) == type(rhs)) {
733  switch (type(lhs)) {
734  case Undefined:
735  case Null:
736  return false;
737 
738  case Number:
739  return lhs.toNumber() < rhs.toNumber();
740 
741  case Boolean:
742  return lhs.toBool() < rhs.toBool();
743 
744  case String:
745  return lhs.toString() < rhs.toString();
746 
747  case Object:
748  break;
749  } // switch
750  }
751 
752  if (lhs.isObject())
753  lhs = ToPrimitive(lhs, JSC::PreferNumber);
754 
755  if (rhs.isObject())
756  rhs = ToPrimitive(rhs, JSC::PreferNumber);
757 
758  if (lhs.isString() && rhs.isString())
759  return lhs.toString() < rhs.toString();
760 
761  return lhs.toNumber() < rhs.toNumber();
762 }
763 
764 static bool Equals(QScriptValue lhs, QScriptValue rhs)
765 {
766  if (type(lhs) == type(rhs)) {
767  switch (type(lhs)) {
768  case QScript::Undefined:
769  case QScript::Null:
770  return true;
771 
772  case QScript::Number:
773  return lhs.toNumber() == rhs.toNumber();
774 
775  case QScript::Boolean:
776  return lhs.toBool() == rhs.toBool();
777 
778  case QScript::String:
779  return lhs.toString() == rhs.toString();
780 
781  case QScript::Object:
782  if (lhs.isVariant())
783  return lhs.strictlyEquals(rhs) || (lhs.toVariant() == rhs.toVariant());
784 #ifndef QT_NO_QOBJECT
785  else if (lhs.isQObject())
786  return (lhs.strictlyEquals(rhs)) || (lhs.toQObject() == rhs.toQObject());
787 #endif
788  else
789  return lhs.strictlyEquals(rhs);
790  }
791  }
792 
793  if (lhs.isNull() && rhs.isUndefined())
794  return true;
795 
796  else if (lhs.isUndefined() && rhs.isNull())
797  return true;
798 
799  else if (IsNumerical(lhs) && rhs.isString())
800  return lhs.toNumber() == rhs.toNumber();
801 
802  else if (lhs.isString() && IsNumerical(rhs))
803  return lhs.toNumber() == rhs.toNumber();
804 
805  else if (lhs.isBool())
806  return Equals(lhs.toNumber(), rhs);
807 
808  else if (rhs.isBool())
809  return Equals(lhs, rhs.toNumber());
810 
811  else if (lhs.isObject() && !rhs.isNull()) {
812  lhs = ToPrimitive(lhs);
813 
814  if (lhs.isValid() && !lhs.isObject())
815  return Equals(lhs, rhs);
816  }
817 
818  else if (rhs.isObject() && ! lhs.isNull()) {
819  rhs = ToPrimitive(rhs);
820  if (rhs.isValid() && !rhs.isObject())
821  return Equals(lhs, rhs);
822  }
823 
824  return false;
825 }
826 
827 } // namespace QScript
828 
843 bool QScriptValue::lessThan(const QScriptValue &other) const
844 {
845  Q_D(const QScriptValue);
846  // no equivalent function in JSC? There's a jsLess() in VM/Machine.cpp
847  if (!isValid() || !other.isValid())
848  return false;
849  if (QScriptValuePrivate::getEngine(other) && d->engine
850  && (QScriptValuePrivate::getEngine(other) != d->engine)) {
851  qWarning("QScriptValue::lessThan: "
852  "cannot compare to a value created in "
853  "a different engine");
854  return false;
855  }
856  return QScript::LessThan(*this, other);
857 }
858 
883 bool QScriptValue::equals(const QScriptValue &other) const
884 {
885  Q_D(const QScriptValue);
886  if (!d || !other.d_ptr)
887  return (d_ptr == other.d_ptr);
888  if (QScriptValuePrivate::getEngine(other) && d->engine
889  && (QScriptValuePrivate::getEngine(other) != d->engine)) {
890  qWarning("QScriptValue::equals: "
891  "cannot compare to a value created in "
892  "a different engine");
893  return false;
894  }
895  if (d->isJSC() && other.d_ptr->isJSC()) {
896  QScriptEnginePrivate *eng_p = d->engine;
897  if (!eng_p)
898  eng_p = other.d_ptr->engine;
899  if (eng_p) {
900  QScript::APIShim shim(eng_p);
901  JSC::ExecState *exec = eng_p->currentFrame;
902  JSC::JSValue savedException;
903  QScriptEnginePrivate::saveException(exec, &savedException);
904  bool result = JSC::JSValue::equal(exec, d->jscValue, other.d_ptr->jscValue);
905  QScriptEnginePrivate::restoreException(exec, savedException);
906  return result;
907  }
908  }
909  return QScript::Equals(*this, other);
910 }
911 
935 {
936  Q_D(const QScriptValue);
937  if (!d || !other.d_ptr)
938  return (d_ptr == other.d_ptr);
939  if (QScriptValuePrivate::getEngine(other) && d->engine
940  && (QScriptValuePrivate::getEngine(other) != d->engine)) {
941  qWarning("QScriptValue::strictlyEquals: "
942  "cannot compare to a value created in "
943  "a different engine");
944  return false;
945  }
946 
947  if (d->type != other.d_ptr->type) {
948  if (d->type == QScriptValuePrivate::JavaScriptCore) {
949  QScriptEnginePrivate *eng_p = d->engine ? d->engine : other.d_ptr->engine;
950  if (eng_p)
951  return JSC::JSValue::strictEqual(eng_p->currentFrame, d->jscValue, eng_p->scriptValueToJSCValue(other));
952  } else if (other.d_ptr->type == QScriptValuePrivate::JavaScriptCore) {
953  QScriptEnginePrivate *eng_p = other.d_ptr->engine ? other.d_ptr->engine : d->engine;
954  if (eng_p)
955  return JSC::JSValue::strictEqual(eng_p->currentFrame, eng_p->scriptValueToJSCValue(*this), other.d_ptr->jscValue);
956  }
957 
958  return false;
959  }
960  switch (d->type) {
962  QScriptEnginePrivate *eng_p = d->engine ? d->engine : other.d_ptr->engine;
963  JSC::ExecState *exec = eng_p ? eng_p->currentFrame : 0;
964  return JSC::JSValue::strictEqual(exec, d->jscValue, other.d_ptr->jscValue);
965  }
967  return (d->numberValue == other.d_ptr->numberValue);
969  return (d->stringValue == other.d_ptr->stringValue);
970  }
971  return false;
972 }
973 
987 {
988  Q_D(const QScriptValue);
989  if (!d)
990  return QString();
991  switch (d->type) {
993  if (d->engine) {
994  QScript::APIShim shim(d->engine);
995  return QScriptEnginePrivate::toString(d->engine->currentFrame, d->jscValue);
996  } else {
997  return QScriptEnginePrivate::toString(0, d->jscValue);
998  } }
1000  return QScript::ToString(d->numberValue);
1002  return d->stringValue;
1003  }
1004  return QString();
1005 }
1006 
1020 {
1021  Q_D(const QScriptValue);
1022  if (!d)
1023  return 0;
1024  switch (d->type) {
1026  if (d->engine) {
1027  QScript::APIShim shim(d->engine);
1028  return QScriptEnginePrivate::toNumber(d->engine->currentFrame, d->jscValue);
1029  } else {
1030  return QScriptEnginePrivate::toNumber(0, d->jscValue);
1031  }
1032  }
1034  return d->numberValue;
1036  return QScript::ToNumber(d->stringValue);
1037  }
1038  return 0;
1039 }
1040 
1050 {
1051  Q_D(const QScriptValue);
1052  if (!d)
1053  return false;
1054  switch (d->type) {
1056  if (d->engine) {
1057  QScript::APIShim shim(d->engine);
1058  return QScriptEnginePrivate::toBool(d->engine->currentFrame, d->jscValue);
1059  } else {
1060  return QScriptEnginePrivate::toBool(0, d->jscValue);
1061  }
1062  }
1064  return QScript::ToBool(d->numberValue);
1066  return QScript::ToBool(d->stringValue);
1067  }
1068  return false;
1069 }
1070 
1089 {
1090  Q_D(const QScriptValue);
1091  if (!d)
1092  return false;
1093  switch (d->type) {
1095  if (d->engine) {
1096  QScript::APIShim shim(d->engine);
1097  return QScriptEnginePrivate::toBool(d->engine->currentFrame, d->jscValue);
1098  } else {
1099  return QScriptEnginePrivate::toBool(0, d->jscValue);
1100  }
1101  }
1103  return QScript::ToBool(d->numberValue);
1105  return QScript::ToBool(d->stringValue);
1106  }
1107  return false;
1108 }
1109 
1123 {
1124  Q_D(const QScriptValue);
1125  if (!d)
1126  return 0;
1127  switch (d->type) {
1129  if (d->engine) {
1130  QScript::APIShim shim(d->engine);
1131  return QScriptEnginePrivate::toInt32(d->engine->currentFrame, d->jscValue);
1132  } else {
1133  return QScriptEnginePrivate::toInt32(0, d->jscValue);
1134  }
1135  }
1137  return QScript::ToInt32(d->numberValue);
1139  return QScript::ToInt32(d->stringValue);
1140  }
1141  return 0;
1142 }
1143 
1157 {
1158  Q_D(const QScriptValue);
1159  if (!d)
1160  return 0;
1161  switch (d->type) {
1163  if (d->engine) {
1164  QScript::APIShim shim(d->engine);
1165  return QScriptEnginePrivate::toUInt32(d->engine->currentFrame, d->jscValue);
1166  } else {
1167  return QScriptEnginePrivate::toUInt32(0, d->jscValue);
1168  }
1169  }
1171  return QScript::ToUInt32(d->numberValue);
1173  return QScript::ToUInt32(d->stringValue);
1174  }
1175  return 0;
1176 }
1177 
1191 {
1192  Q_D(const QScriptValue);
1193  if (!d)
1194  return 0;
1195  switch (d->type) {
1197  if (d->engine) {
1198  QScript::APIShim shim(d->engine);
1199  return QScriptEnginePrivate::toUInt16(d->engine->currentFrame, d->jscValue);
1200  } else {
1201  return QScriptEnginePrivate::toUInt16(0, d->jscValue);
1202  }
1203  }
1205  return QScript::ToUInt16(d->numberValue);
1207  return QScript::ToUInt16(d->stringValue);
1208  }
1209  return 0;
1210 }
1211 
1225 {
1226  Q_D(const QScriptValue);
1227  if (!d)
1228  return 0;
1229  switch (d->type) {
1231  if (d->engine) {
1232  QScript::APIShim shim(d->engine);
1233  return QScriptEnginePrivate::toInteger(d->engine->currentFrame, d->jscValue);
1234  } else {
1235  return QScriptEnginePrivate::toInteger(0, d->jscValue);
1236  }
1237  }
1239  return QScript::ToInteger(d->numberValue);
1241  return QScript::ToInteger(d->stringValue);
1242  }
1243  return 0;
1244 }
1245 
1269 {
1270  Q_D(const QScriptValue);
1271  if (!d)
1272  return QVariant();
1273  switch (d->type) {
1275  if (d->engine) {
1276  QScript::APIShim shim(d->engine);
1277  return QScriptEnginePrivate::toVariant(d->engine->currentFrame, d->jscValue);
1278  } else {
1279  return QScriptEnginePrivate::toVariant(0, d->jscValue);
1280  }
1281  }
1283  return QVariant(d->numberValue);
1285  return QVariant(d->stringValue);
1286  }
1287  return QVariant();
1288 }
1289 
1299 {
1300  Q_D(const QScriptValue);
1301  if (!d || !d->engine)
1302  return QScriptValue();
1303  return engine()->toObject(*this);
1304 }
1305 
1314 {
1315  Q_D(const QScriptValue);
1316  if (!d || !d->engine)
1317  return QDateTime();
1318  QScript::APIShim shim(d->engine);
1319  return QScriptEnginePrivate::toDateTime(d->engine->currentFrame, d->jscValue);
1320 }
1321 
1322 #ifndef QT_NO_REGEXP
1323 
1331 {
1332  Q_D(const QScriptValue);
1333  if (!d || !d->engine)
1334  return QRegExp();
1335  QScript::APIShim shim(d->engine);
1336  return QScriptEnginePrivate::toRegExp(d->engine->currentFrame, d->jscValue);
1337 }
1338 #endif // QT_NO_REGEXP
1339 
1351 {
1352  Q_D(const QScriptValue);
1353  if (!d || !d->engine)
1354  return 0;
1355  QScript::APIShim shim(d->engine);
1356  return QScriptEnginePrivate::toQObject(d->engine->currentFrame, d->jscValue);
1357 }
1358 
1366 {
1367  Q_D(const QScriptValue);
1368  if (!d || !d->engine)
1369  return 0;
1370  QScript::APIShim shim(d->engine);
1371  return QScriptEnginePrivate::toQMetaObject(d->engine->currentFrame, d->jscValue);
1372 }
1373 
1400  const PropertyFlags &flags)
1401 {
1402  Q_D(QScriptValue);
1403  if (!d || !d->isObject())
1404  return;
1405  QScript::APIShim shim(d->engine);
1407  if (valueEngine && (valueEngine != d->engine)) {
1408  qWarning("QScriptValue::setProperty(%s) failed: "
1409  "cannot set value created in a different engine",
1410  qPrintable(name));
1411  return;
1412  }
1413  JSC::JSValue jsValue = d->engine->scriptValueToJSCValue(value);
1414  d->setProperty(name, jsValue, flags);
1415 }
1416 
1433  const ResolveFlags &mode) const
1434 {
1435  Q_D(const QScriptValue);
1436  if (!d || !d->isObject())
1437  return QScriptValue();
1438  QScript::APIShim shim(d->engine);
1439  return d->engine->scriptValueFromJSCValue(d->property(name, mode));
1440 }
1441 
1459  const ResolveFlags &mode) const
1460 {
1461  Q_D(const QScriptValue);
1462  if (!d || !d->isObject())
1463  return QScriptValue();
1464  QScript::APIShim shim(d->engine);
1465  return d->engine->scriptValueFromJSCValue(d->property(arrayIndex, mode));
1466 }
1467 
1483 void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue &value,
1484  const PropertyFlags &flags)
1485 {
1486  Q_D(QScriptValue);
1487  if (!d || !d->isObject())
1488  return;
1490  && (QScriptValuePrivate::getEngine(value) != d->engine)) {
1491  qWarning("QScriptValue::setProperty() failed: "
1492  "cannot set value created in a different engine");
1493  return;
1494  }
1495  QScript::APIShim shim(d->engine);
1496  JSC::JSValue jsValue = d->engine->scriptValueToJSCValue(value);
1497  d->setProperty(arrayIndex, jsValue, flags);
1498 }
1499 
1516  const ResolveFlags &mode) const
1517 {
1518  Q_D(const QScriptValue);
1519  if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
1520  return QScriptValue();
1521  QScript::APIShim shim(d->engine);
1522  return d->engine->scriptValueFromJSCValue(d->property(name.d_ptr->identifier, mode));
1523 }
1524 
1542  const QScriptValue &value,
1543  const PropertyFlags &flags)
1544 {
1545  Q_D(QScriptValue);
1546  if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
1547  return;
1549  if (valueEngine && (valueEngine != d->engine)) {
1550  qWarning("QScriptValue::setProperty(%s) failed: "
1551  "cannot set value created in a different engine",
1552  qPrintable(name.toString()));
1553  return;
1554  }
1555  QScript::APIShim shim(d->engine);
1556  JSC::JSValue jsValue = d->engine->scriptValueToJSCValue(value);
1557  d->setProperty(name.d_ptr->identifier, jsValue, flags);
1558 }
1559 
1567  const ResolveFlags &mode) const
1568 {
1569  Q_D(const QScriptValue);
1570  if (!d || !d->isObject())
1571  return 0;
1572  QScript::APIShim shim(d->engine);
1573  JSC::ExecState *exec = d->engine->currentFrame;
1574  return d->propertyFlags(JSC::Identifier(exec, name), mode);
1575 
1576 }
1577 
1590  const ResolveFlags &mode) const
1591 {
1592  Q_D(const QScriptValue);
1593  if (!d || !d->isObject() || !QScriptStringPrivate::isValid(name))
1594  return 0;
1595  return d->propertyFlags(name.d_ptr->identifier, mode);
1596 }
1597 
1622  const QScriptValueList &args)
1623 {
1624  Q_D(const QScriptValue);
1625  if (!d || !d->isObject())
1626  return QScriptValue();
1627  QScript::APIShim shim(d->engine);
1628  JSC::JSValue callee = d->jscValue;
1629  JSC::CallData callData;
1630  JSC::CallType callType = callee.getCallData(callData);
1631  if (callType == JSC::CallTypeNone)
1632  return QScriptValue();
1633 
1634  if (QScriptValuePrivate::getEngine(thisObject)
1635  && (QScriptValuePrivate::getEngine(thisObject) != d->engine)) {
1636  qWarning("QScriptValue::call() failed: "
1637  "cannot call function with thisObject created in "
1638  "a different engine");
1639  return QScriptValue();
1640  }
1641 
1642  JSC::ExecState *exec = d->engine->currentFrame;
1643 
1644  JSC::JSValue jscThisObject = d->engine->scriptValueToJSCValue(thisObject);
1645  if (!jscThisObject || !jscThisObject.isObject())
1646  jscThisObject = d->engine->globalObject();
1647 
1648  QVarLengthArray<JSC::JSValue, 8> argsVector(args.size());
1649  for (int i = 0; i < args.size(); ++i) {
1650  const QScriptValue &arg = args.at(i);
1651  if (!arg.isValid()) {
1652  argsVector[i] = JSC::jsUndefined();
1653  } else if (QScriptValuePrivate::getEngine(arg)
1654  && (QScriptValuePrivate::getEngine(arg) != d->engine)) {
1655  qWarning("QScriptValue::call() failed: "
1656  "cannot call function with argument created in "
1657  "a different engine");
1658  return QScriptValue();
1659  } else {
1660  argsVector[i] = d->engine->scriptValueToJSCValue(arg);
1661  }
1662  }
1663  JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
1664 
1665  JSC::JSValue savedException;
1666  QScriptEnginePrivate::saveException(exec, &savedException);
1667  JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, jscArgs);
1668  if (exec->hadException()) {
1669  result = exec->exception();
1670  } else {
1671  QScriptEnginePrivate::restoreException(exec, savedException);
1672  }
1673  return d->engine->scriptValueFromJSCValue(result);
1674 }
1675 
1700  const QScriptValue &arguments)
1701 {
1702  Q_D(QScriptValue);
1703  if (!d || !d->isObject())
1704  return QScriptValue();
1705  QScript::APIShim shim(d->engine);
1706  JSC::JSValue callee = d->jscValue;
1707  JSC::CallData callData;
1708  JSC::CallType callType = callee.getCallData(callData);
1709  if (callType == JSC::CallTypeNone)
1710  return QScriptValue();
1711 
1712  if (QScriptValuePrivate::getEngine(thisObject)
1713  && (QScriptValuePrivate::getEngine(thisObject) != d->engine)) {
1714  qWarning("QScriptValue::call() failed: "
1715  "cannot call function with thisObject created in "
1716  "a different engine");
1717  return QScriptValue();
1718  }
1719 
1720  JSC::ExecState *exec = d->engine->currentFrame;
1721 
1722  JSC::JSValue jscThisObject = d->engine->scriptValueToJSCValue(thisObject);
1723  if (!jscThisObject || !jscThisObject.isObject())
1724  jscThisObject = d->engine->globalObject();
1725 
1726  JSC::JSValue array = d->engine->scriptValueToJSCValue(arguments);
1727  // copied from runtime/FunctionPrototype.cpp, functionProtoFuncApply()
1728  JSC::MarkedArgumentBuffer applyArgs;
1729  if (!array.isUndefinedOrNull()) {
1730  if (!array.isObject()) {
1731  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1732  }
1733  if (JSC::asObject(array)->classInfo() == &JSC::Arguments::info)
1734  JSC::asArguments(array)->fillArgList(exec, applyArgs);
1735  else if (JSC::isJSArray(&exec->globalData(), array))
1736  JSC::asArray(array)->fillArgList(exec, applyArgs);
1737  else if (JSC::asObject(array)->inherits(&JSC::JSArray::info)) {
1738  unsigned length = JSC::asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
1739  for (unsigned i = 0; i < length; ++i)
1740  applyArgs.append(JSC::asArray(array)->get(exec, i));
1741  } else {
1742  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1743  }
1744  }
1745 
1746  JSC::JSValue savedException;
1747  QScriptEnginePrivate::saveException(exec, &savedException);
1748  JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, applyArgs);
1749  if (exec->hadException()) {
1750  result = exec->exception();
1751  } else {
1752  QScriptEnginePrivate::restoreException(exec, savedException);
1753  }
1754  return d->engine->scriptValueFromJSCValue(result);
1755 }
1756 
1776 {
1777  Q_D(const QScriptValue);
1778  if (!d || !d->isObject())
1779  return QScriptValue();
1780  QScript::APIShim shim(d->engine);
1781  JSC::JSValue callee = d->jscValue;
1782  JSC::ConstructData constructData;
1783  JSC::ConstructType constructType = callee.getConstructData(constructData);
1784  if (constructType == JSC::ConstructTypeNone)
1785  return QScriptValue();
1786 
1787  JSC::ExecState *exec = d->engine->currentFrame;
1788 
1789  QVarLengthArray<JSC::JSValue, 8> argsVector(args.size());
1790  for (int i = 0; i < args.size(); ++i) {
1791  QScriptValue arg = args.at(i);
1792  if (QScriptValuePrivate::getEngine(arg) != d->engine && QScriptValuePrivate::getEngine(arg)) {
1793  qWarning("QScriptValue::construct() failed: "
1794  "cannot construct function with argument created in "
1795  "a different engine");
1796  return QScriptValue();
1797  }
1798  if (!arg.isValid())
1799  argsVector[i] = JSC::jsUndefined();
1800  else
1801  argsVector[i] = d->engine->scriptValueToJSCValue(args.at(i));
1802  }
1803 
1804  JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
1805 
1806  JSC::JSValue savedException;
1807  QScriptEnginePrivate::saveException(exec, &savedException);
1808  JSC::JSValue result;
1809  JSC::JSObject *newObject = JSC::construct(exec, callee, constructType, constructData, jscArgs);
1810  if (exec->hadException()) {
1811  result = exec->exception();
1812  } else {
1813  result = newObject;
1814  QScriptEnginePrivate::restoreException(exec, savedException);
1815  }
1816  return d->engine->scriptValueFromJSCValue(result);
1817 }
1818 
1835 {
1836  Q_D(QScriptValue);
1837  if (!d || !d->isObject())
1838  return QScriptValue();
1839  QScript::APIShim shim(d->engine);
1840  JSC::JSValue callee = d->jscValue;
1841  JSC::ConstructData constructData;
1842  JSC::ConstructType constructType = callee.getConstructData(constructData);
1843  if (constructType == JSC::ConstructTypeNone)
1844  return QScriptValue();
1845 
1846  JSC::ExecState *exec = d->engine->currentFrame;
1847 
1848  if (QScriptValuePrivate::getEngine(arguments) != d->engine && QScriptValuePrivate::getEngine(arguments)) {
1849  qWarning("QScriptValue::construct() failed: "
1850  "cannot construct function with argument created in "
1851  "a different engine");
1852  return QScriptValue();
1853  }
1854  JSC::JSValue array = d->engine->scriptValueToJSCValue(arguments);
1855  // copied from runtime/FunctionPrototype.cpp, functionProtoFuncApply()
1856  JSC::MarkedArgumentBuffer applyArgs;
1857  if (!array.isUndefinedOrNull()) {
1858  if (!array.isObject()) {
1859  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1860  }
1861  if (JSC::asObject(array)->classInfo() == &JSC::Arguments::info)
1862  JSC::asArguments(array)->fillArgList(exec, applyArgs);
1863  else if (JSC::isJSArray(&exec->globalData(), array))
1864  JSC::asArray(array)->fillArgList(exec, applyArgs);
1865  else if (JSC::asObject(array)->inherits(&JSC::JSArray::info)) {
1866  unsigned length = JSC::asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
1867  for (unsigned i = 0; i < length; ++i)
1868  applyArgs.append(JSC::asArray(array)->get(exec, i));
1869  } else {
1870  return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array"));
1871  }
1872  }
1873 
1874  JSC::JSValue savedException;
1875  QScriptEnginePrivate::saveException(exec, &savedException);
1876  JSC::JSValue result;
1877  JSC::JSObject *newObject = JSC::construct(exec, callee, constructType, constructData, applyArgs);
1878  if (exec->hadException()) {
1879  result = exec->exception();
1880  } else {
1881  result = newObject;
1882  QScriptEnginePrivate::restoreException(exec, savedException);
1883  }
1884  return d->engine->scriptValueFromJSCValue(result);
1885 }
1886 
1893 {
1894  Q_D(const QScriptValue);
1895  if (!d)
1896  return 0;
1897  return QScriptEnginePrivate::get(d->engine);
1898 }
1899 
1909 {
1910  Q_D(const QScriptValue);
1911  return d && d->isJSC() && d->jscValue.isBoolean();
1912 }
1913 
1926 {
1927  Q_D(const QScriptValue);
1928  return d && d->isJSC() && d->jscValue.isBoolean();
1929 }
1930 
1938 {
1939  Q_D(const QScriptValue);
1940  if (!d)
1941  return false;
1942  switch (d->type) {
1944  return d->jscValue.isNumber();
1946  return true;
1948  return false;
1949  }
1950  return false;
1951 }
1952 
1960 {
1961  Q_D(const QScriptValue);
1962  if (!d)
1963  return false;
1964  switch (d->type) {
1966  return d->jscValue.isString();
1968  return false;
1970  return true;
1971  }
1972  return false;
1973 }
1974 
1982 {
1983  Q_D(const QScriptValue);
1984  if (!d || !d->isJSC())
1985  return false;
1986  return QScript::isFunction(d->jscValue);
1987 }
1988 
1996 {
1997  Q_D(const QScriptValue);
1998  return d && d->isJSC() && d->jscValue.isNull();
1999 }
2000 
2008 {
2009  Q_D(const QScriptValue);
2010  return d && d->isJSC() && d->jscValue.isUndefined();
2011 }
2012 
2023 {
2024  Q_D(const QScriptValue);
2025  return d && d->isObject();
2026 }
2027 
2035 {
2036  Q_D(const QScriptValue);
2037  if (!d || !d->isJSC())
2038  return false;
2039  return QScriptEnginePrivate::isVariant(d->jscValue);
2040 }
2041 
2052 {
2053  Q_D(const QScriptValue);
2054  if (!d || !d->isJSC())
2055  return false;
2056  return QScriptEnginePrivate::isQObject(d->jscValue);
2057 }
2058 
2066 {
2067  Q_D(const QScriptValue);
2068  if (!d || !d->isJSC())
2069  return false;
2070  return QScriptEnginePrivate::isQMetaObject(d->jscValue);
2071 }
2072 
2078 {
2079  Q_D(const QScriptValue);
2080  return d && (!d->isJSC() || !!d->jscValue);
2081 }
2082 
2095 {
2096  Q_D(const QScriptValue);
2097  if (!d || !d->isObject())
2098  return QScriptValue();
2099  if (d->jscValue.inherits(&QScriptObject::info)) {
2100  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2101  return d->engine->scriptValueFromJSCValue(scriptObject->data());
2102  } else {
2103  // ### make hidden property
2104  return property(QLatin1String("__qt_data__"), QScriptValue::ResolveLocal);
2105  }
2106 }
2107 
2122 {
2123  Q_D(QScriptValue);
2124  if (!d || !d->isObject())
2125  return;
2126  QScript::APIShim shim(d->engine);
2127  JSC::JSValue other = d->engine->scriptValueToJSCValue(data);
2128  if (d->jscValue.inherits(&QScriptObject::info)) {
2129  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2130  scriptObject->setData(other);
2131  } else {
2132  JSC::ExecState *exec = d->engine->currentFrame;
2133  JSC::Identifier id = JSC::Identifier(exec, "__qt_data__");
2134  if (!data.isValid()) {
2135  JSC::asObject(d->jscValue)->removeDirect(id);
2136  } else {
2137  // ### make hidden property
2138  JSC::asObject(d->jscValue)->putDirect(id, other);
2139  }
2140  }
2141 }
2142 
2155 {
2156  Q_D(const QScriptValue);
2157  if (!d || !d->isJSC() || !d->jscValue.inherits(&QScriptObject::info))
2158  return 0;
2159  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2160  QScriptObjectDelegate *delegate = scriptObject->delegate();
2161  if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject))
2162  return 0;
2163  return static_cast<QScript::ClassObjectDelegate*>(delegate)->scriptClass();
2164 }
2165 
2183 {
2184  Q_D(QScriptValue);
2185  if (!d || !d->isObject())
2186  return;
2187  if (!d->jscValue.inherits(&QScriptObject::info)) {
2188  qWarning("QScriptValue::setScriptClass() failed: "
2189  "cannot change class of non-QScriptObject");
2190  return;
2191  }
2192  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
2193  if (!scriptClass) {
2194  scriptObject->setDelegate(0);
2195  } else {
2196  QScriptObjectDelegate *delegate = scriptObject->delegate();
2197  if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject)) {
2198  delegate = new QScript::ClassObjectDelegate(scriptClass);
2199  scriptObject->setDelegate(delegate);
2200  }
2201  static_cast<QScript::ClassObjectDelegate*>(delegate)->setScriptClass(scriptClass);
2202  }
2203 }
2204 
2217 {
2218  return d_ptr?d_ptr->objectId():-1;
2219 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static bool isQMetaObject(JSC::JSValue)
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
double d
Definition: qnumeric_p.h:62
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
int type
Definition: qmetatype.cpp:239
QScriptValue & operator=(const QScriptValue &other)
Assigns the other value to this QScriptValue.
static mach_timebase_info_data_t info
virtual Type type() const =0
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const QMetaObject * toQMetaObject(JSC::ExecState *, JSC::JSValue)
int qint32
Definition: qglobal.h:937
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
Definition: qscriptclass.h:43
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QScriptValue scope() const
QDateTime toDateTime() const
Returns a QDateTime representation of this value, in local time.
qsreal ToInteger(qsreal n)
bool equals(const QScriptValue &other) const
Returns true if this QScriptValue is equal to other, otherwise returns false.
static QScriptEnginePrivate * get(QScriptEngine *q)
static QVariant toVariant(JSC::ExecState *, JSC::JSValue)
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
static bool LessThan(QScriptValue lhs, QScriptValue rhs)
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
static QRegExp toRegExp(JSC::ExecState *, JSC::JSValue)
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
quint32 ToUInt32(qsreal n)
static QScriptValuePrivate * get(const QScriptValue &q)
static QObject * toQObject(JSC::ExecState *, JSC::JSValue)
QScriptObjectDelegate * delegate() const
bool isBoolean() const
Use isBool() instead.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static quint16 toUInt16(JSC::ExecState *, JSC::JSValue)
bool isQMetaObject() const
Returns true if this QScriptValue is a QMetaObject; otherwise returns false.
bool instanceOf(const QScriptValue &other) const
Returns true if this QScriptValue is an instance of other; otherwise returns false.
static qsreal toNumber(JSC::ExecState *, JSC::JSValue)
static const JSC::ClassInfo info
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
~QScriptValue()
Destroys this QScriptValue.
static bool IsNumerical(const QScriptValue &value)
JSC::ExecState * currentFrame
QScriptValue construct(const QScriptValueList &args=QScriptValueList())
Creates a new Object and calls this QScriptValue as a constructor, using the created object as the `t...
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
Definition: qscriptstring.h:38
SpecialValue
This enum is used to specify a single-valued type.
Definition: qscriptvalue.h:85
qint64 objectId() const
Returns the ID of this object, or -1 if this QScriptValue is not an object.
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptValue::PropertyFlags propertyFlags(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the flags of the property with the given name, using the given mode to resolve the property...
static bool isVariant(JSC::JSValue)
static qint32 toInt32(JSC::ExecState *, JSC::JSValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QScriptClass * scriptClass() const
Returns the custom script class that this script object is an instance of, or 0 if the object is not ...
JSC::JSValue data() const
JSC::JSValue scriptValueToJSCValue(const QScriptValue &value)
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
void setData(JSC::JSValue data)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QScriptValue()
Constructs an invalid QScriptValue.
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
static QDateTime toDateTime(JSC::ExecState *, JSC::JSValue)
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
QString ToString(qsreal)
bool isFunction(JSC::JSValue value)
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
static void restoreException(JSC::ExecState *, JSC::JSValue)
unsigned int uint
Definition: qglobal.h:996
static qsreal toInteger(JSC::ExecState *, JSC::JSValue)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
void setScriptClass(QScriptClass *scriptClass)
Sets the custom script class of this script object to scriptClass.
qint32 ToInt32(qsreal n)
__int64 qint64
Definition: qglobal.h:942
const QMetaObject * toQMetaObject() const
If this QScriptValue is a QMetaObject, returns the QMetaObject pointer that the QScriptValue represen...
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
qsreal toInteger() const
Returns the integer value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
JSC::Identifier identifier
bool toBoolean() const
Use toBool() instead.
bool ToBool(qsreal)
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
QScriptValue toObject() const
This function is obsolete; use QScriptEngine::toObject() instead.
static bool isDate(JSC::JSValue)
QExplicitlySharedDataPointer< QScriptStringPrivate > d_ptr
Definition: qscriptstring.h:58
QScriptValue data() const
Returns the internal data of this QScriptValue object.
qsreal ToNumber(const QString &)
static bool isRegExp(JSC::JSValue)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
static bool isValid(const QScriptString &q)
void setScope(const QScriptValue &scope)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static void saveException(JSC::ExecState *, JSC::JSValue *)
void setPrototype(const QScriptValue &prototype)
If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to...
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
PropertyFlags
Definition: qmetaobject_p.h:61
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
static bool isQObject(JSC::JSValue)
static quint32 toUInt32(JSC::ExecState *, JSC::JSValue)
static bool isError(JSC::JSValue)
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QScriptValue ToPrimitive(const QScriptValue &object, JSC::PreferredPrimitiveType hint=JSC::NoPreference)
void initFrom(JSC::JSValue value)
static bool Equals(QScriptValue lhs, QScriptValue rhs)
QRegExp toRegExp() const
Returns the QRegExp representation of this value.
double qsreal
Definition: qscriptvalue.h:52
static const char * get(QDBusError::ErrorType code)
Definition: qdbuserror.cpp:141
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
bool lessThan(const QScriptValue &other) const
Returns true if this QScriptValue is less than other, otherwise returns false.
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
JSC::JSValue jscValue
void setDelegate(QScriptObjectDelegate *delegate)
quint16 ToUInt16(qsreal n)
QScriptValue scriptValueFromJSCValue(JSC::JSValue value)
quint16 toUInt16() const
Returns the unsigned 16-bit integer value of this QScriptValue, using the conversion rules described ...
static bool toBool(JSC::ExecState *, JSC::JSValue)
bool strictlyEquals(const QScriptValue &other) const
Returns true if this QScriptValue is equal to other using strict comparison (no conversion), otherwise returns false.
static bool isArray(JSC::JSValue)
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QString toString() const
Returns the string that this QScriptString represents, or a null string if this QScriptString is not ...
#define qPrintable(string)
Definition: qglobal.h:1750
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue toObject(const QScriptValue &value)
Converts the given value to an object, if such a conversion is possible; otherwise returns an invalid...
QScriptEnginePrivate * engine
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this&#39; object in the function call...
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
static bool equal(const QChar *a, int l, const char *b)
Definition: qurl.cpp:3270
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.
QScriptValue prototype() const
If this QScriptValue is an object, returns the internal prototype (__proto__ property) of this object...