Qt 4.8
Namespaces | Classes | Enumerations | Functions | Variables
QScript Namespace Reference

Namespaces

 AST
 

Classes

class  APIShim
 
class  ClassObjectDelegate
 
class  DeclarativeObjectDelegate
 
class  FunctionWithArgWrapper
 
class  FunctionWrapper
 
struct  GlobalClientData
 
class  GlobalObject
 
class  Lexer
 
class  OriginalGlobalObjectProxy
 
class  QMetaObjectPrototype
 
class  QMetaObjectWrapperObject
 
struct  QObjectConnection
 
class  QObjectConnectionManager
 
class  QObjectData
 
class  QObjectDelegate
 
class  QObjectNotifyCaller
 
class  QObjectPrototype
 
class  QObjectPrototypeObject
 
struct  QObjectWrapperInfo
 
class  QScriptActivationObject
 Represent a scope for native function call. More...
 
struct  QScriptMetaArguments
 
class  QScriptMetaMethod
 
class  QScriptMetaType
 
class  QtFunction
 
class  QtPropertyFunction
 
class  QVariantDelegate
 
class  QVariantPrototype
 
class  SaveFrameHelper
 
struct  StaticQtMetaObject
 
class  SyntaxChecker
 
class  TimeoutCheckerProxy
 
class  UStringSourceProviderWithFeedback
 

Enumerations

enum  AttributeExtension { QObjectMemberAttribute = 1 << 12 }
 
enum  Type {
  Undefined, Null, Boolean, String,
  Number, Object
}
 

Functions

static QScriptValue __setupPackage__ (QScriptContext *ctx, QScriptEngine *eng)
 
static JSC::JSValue callQtMethod (JSC::ExecState *exec, QMetaMethod::MethodType callType, QObject *thisQObject, const JSC::ArgList &scriptArgs, const QMetaObject *meta, int initialIndex, bool maybeOverloaded)
 
QByteArray convertToLatin1 (const JSC::UString &str)
 
void convertToLatin1_helper (const UChar *i, int length, char *s)
 
qsreal DateTimeToMs (JSC::ExecState *exec, const QDateTime &dt)
 Converts a QDateTime to a JS date value (milliseconds). More...
 
static bool Equals (QScriptValue lhs, QScriptValue rhs)
 
static unsigned flagsForMetaProperty (const QMetaProperty &prop)
 
static JSC::JSValue JSC_HOST_CALL functionConnect (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionDisconnect (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionGC (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionPrint (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionQsTr (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionQsTranslate (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionQsTrId (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionQsTrNoOp (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL functionVersion (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
static bool hasMethodAccess (const QMetaMethod &method, int index, const QScriptEngine::QObjectWrapOptions &opt)
 
static int indexOfMetaEnum (const QMetaObject *meta, const QByteArray &str)
 
qsreal integerFromString (const char *buf, int size, int radix)
 
qsreal integerFromString (const QString &str, int radix)
 
static bool isEnumerableMetaProperty (const QMetaProperty &prop, const QMetaObject *mo, int index)
 
bool isFunction (JSC::JSValue value)
 
static bool IsNumerical (const QScriptValue &value)
 
static bool LessThan (QScriptValue lhs, QScriptValue rhs)
 
static QMetaMethod metaMethod (const QMetaObject *meta, QMetaMethod::MethodType type, int index)
 
static QByteArray methodName (const char *signature, int nameLength)
 Makes a deep copy of the first nameLength characters of the given method signature and returns the copy. More...
 
static bool methodNameEquals (const QMetaMethod &method, const char *signature, int nameLength)
 Returns true if the name of the given method is the same as that specified by the (signature, nameLength) pair, otherwise returns false. More...
 
static int methodNameLength (const QMetaMethod &method)
 Calculates the length of the name of the given method by looking for the first '(' character. More...
 
static int MsFromTime (qsreal t)
 
QDateTime MsToDateTime (JSC::ExecState *exec, qsreal t)
 Converts a JS date value (milliseconds) to a QDateTime (local time). More...
 
static JSC::JSValue JSC_HOST_CALL qmetaobjectProtoFuncClassName (JSC::ExecState *exec, JSC::JSObject *, JSC::JSValue thisValue, const JSC::ArgList &)
 
static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChild (JSC::ExecState *exec, JSC::JSObject *, JSC::JSValue thisValue, const JSC::ArgList &args)
 
static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChildren (JSC::ExecState *exec, JSC::JSObject *, JSC::JSValue thisValue, const JSC::ArgList &args)
 
static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncToString (JSC::ExecState *exec, JSC::JSObject *, JSC::JSValue thisValue, const JSC::ArgList &)
 
static QScriptablescriptableFromQObject (QObject *qobj)
 
QScriptEnginePrivatescriptEngineFromExec (const JSC::ExecState *exec)
 
static JSC::JSValue JSC_HOST_CALL stringProtoFuncArg (JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &)
 
bool ToBool (qsreal)
 
bool ToBool (const QString &)
 
static int toDigit (char c)
 
qint32 ToInt32 (const QString &)
 
qint32 ToInt32 (qsreal n)
 
qsreal ToInteger (const QString &)
 
qsreal ToInteger (qsreal n)
 
qsreal ToNumber (const QString &)
 
static QScriptValue ToPrimitive (const QScriptValue &object, JSC::PreferredPrimitiveType hint=JSC::NoPreference)
 
QString ToString (qsreal)
 
quint16 ToUInt16 (const QString &)
 
quint16 ToUInt16 (qsreal n)
 
quint32 ToUInt32 (const QString &)
 
quint32 ToUInt32 (qsreal n)
 
static Type type (const QScriptValue &v)
 
static QVariant variantFromValue (JSC::ExecState *exec, int targetType, JSC::JSValue value)
 
static JSC::JSValue JSC_HOST_CALL variantProtoFuncToString (JSC::ExecState *exec, JSC::JSObject *callee, JSC::JSValue thisValue, const JSC::ArgList &args)
 
static JSC::JSValue JSC_HOST_CALL variantProtoFuncValueOf (JSC::ExecState *exec, JSC::JSObject *, JSC::JSValue thisValue, const JSC::ArgList &)
 

Variables

static const qsreal D32 = 4294967296.0
 
static const bool GeneratePropertyFunctions = true
 
static const qsreal MsPerSecond = 1000.0
 
static const uint qt_meta_data_QObjectConnectionManager []
 
static const char qt_meta_stringdata_QObjectConnectionManager []
 

Enumeration Type Documentation

◆ AttributeExtension

Enumerator
QObjectMemberAttribute 

Definition at line 50 of file qscriptqobject_p.h.

50  {
51  // ### Make sure there's no conflict with JSC::Attribute
52  QObjectMemberAttribute = 1 << 12
53 };

◆ Type

Enumerator
Undefined 
Null 
Boolean 
String 
Number 
Object 

Definition at line 686 of file qscriptvalue.cpp.

Function Documentation

◆ __setupPackage__()

static QScriptValue QScript::__setupPackage__ ( QScriptContext ctx,
QScriptEngine eng 
)
static

Definition at line 955 of file qscriptengine.cpp.

Referenced by QScriptEngine::importExtension().

956 {
957  QString path = ctx->argument(0).toString();
958  QStringList components = path.split(QLatin1Char('.'));
959  QScriptValue o = eng->globalObject();
960  for (int i = 0; i < components.count(); ++i) {
961  QString name = components.at(i);
962  QScriptValue oo = o.property(name);
963  if (!oo.isValid()) {
964  oo = eng->newObject();
965  o.setProperty(name, oo);
966  }
967  o = oo;
968  }
969  return o;
970 }
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...
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QScriptValue newObject()
Creates a QtScript object of class Object.
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.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ callQtMethod()

static JSC::JSValue QScript::callQtMethod ( JSC::ExecState *  exec,
QMetaMethod::MethodType  callType,
QObject thisQObject,
const JSC::ArgList &  scriptArgs,
const QMetaObject meta,
int  initialIndex,
bool  maybeOverloaded 
)
static

Definition at line 523 of file qscriptqobject.cpp.

Referenced by QScript::QtFunction::execute(), and QScript::QMetaObjectWrapperObject::execute().

527 {
528  QScriptMetaMethod chosenMethod;
529  int chosenIndex = -1;
533  QVector<int> tooFewArgs;
534  QVector<int> conversionFailed;
535  int index;
536  int nameLength = 0;
537  const char *initialMethodSignature = 0;
538  exec->clearException();
540  for (index = initialIndex; index >= 0; --index) {
541  QMetaMethod method = metaMethod(meta, callType, index);
542 
543  if (index == initialIndex) {
544  initialMethodSignature = method.signature();
545  nameLength = methodNameLength(method);
546  } else {
547  if (!methodNameEquals(method, initialMethodSignature, nameLength))
548  continue;
549  }
550 
551  QList<QByteArray> parameterTypeNames = method.parameterTypes();
552 
554  types.resize(1 + parameterTypeNames.size());
555  QScriptMetaType *typesData = types.data();
556  // resolve return type
557  QByteArray returnTypeName = method.typeName();
558  int rtype = QMetaType::type(returnTypeName);
559  if ((rtype == 0) && !returnTypeName.isEmpty()) {
560  int enumIndex = indexOfMetaEnum(meta, returnTypeName);
561  if (enumIndex != -1)
562  typesData[0] = QScriptMetaType::metaEnum(enumIndex, returnTypeName);
563  else
564  typesData[0] = QScriptMetaType::unresolved(returnTypeName);
565  } else {
566  if (callType == QMetaMethod::Constructor)
567  typesData[0] = QScriptMetaType::metaType(QMetaType::QObjectStar, "QObject*");
568  else if (rtype == QMetaType::QVariant)
569  typesData[0] = QScriptMetaType::variant();
570  else
571  typesData[0] = QScriptMetaType::metaType(rtype, returnTypeName);
572  }
573 
574  // resolve argument types
575  for (int i = 0; i < parameterTypeNames.count(); ++i) {
576  QByteArray argTypeName = parameterTypeNames.at(i);
577  int atype = QMetaType::type(argTypeName);
578  if (atype == 0) {
579  int enumIndex = indexOfMetaEnum(meta, argTypeName);
580  if (enumIndex != -1)
581  typesData[1 + i] = QScriptMetaType::metaEnum(enumIndex, argTypeName);
582  else
583  typesData[1 + i] = QScriptMetaType::unresolved(argTypeName);
584  } else if (atype == QMetaType::QVariant) {
585  typesData[1 + i] = QScriptMetaType::variant();
586  } else {
587  typesData[1 + i] = QScriptMetaType::metaType(atype, argTypeName);
588  }
589  }
590 
591  QScriptMetaMethod mtd = QScriptMetaMethod(types);
592 
593  if (int(scriptArgs.size()) < mtd.argumentCount()) {
594  tooFewArgs.append(index);
595  continue;
596  }
597 
598  if (!mtd.fullyResolved()) {
599  // remember it so we can give an error message later, if necessary
600  unresolved.append(QScriptMetaArguments(/*matchDistance=*/INT_MAX, index,
602  if (mtd.hasUnresolvedReturnType())
603  continue;
604  }
605 
606  if (args.count() != mtd.count())
607  args.resize(mtd.count());
608 
609  QScriptMetaType retType = mtd.returnType();
610  args[0] = QVariant(retType.typeId(), (void *)0); // the result
611 
612  // try to convert arguments
613  bool converted = true;
614  int matchDistance = 0;
615  for (int i = 0; converted && i < mtd.argumentCount(); ++i) {
616  JSC::JSValue actual;
617  if (i < (int)scriptArgs.size())
618  actual = scriptArgs.at(i);
619  else
620  actual = JSC::jsUndefined();
621  QScriptMetaType argType = mtd.argumentType(i);
622  int tid = -1;
623  QVariant v;
624  if (argType.isUnresolved()) {
625  v = QVariant(QMetaType::QObjectStar, (void *)0);
627  exec, actual, argType.name(), reinterpret_cast<void* *>(v.data()));
628  } else if (argType.isVariant()) {
629  if (QScriptEnginePrivate::isVariant(actual)) {
631  } else {
632  v = QScriptEnginePrivate::toVariant(exec, actual);
633  converted = v.isValid() || actual.isUndefined() || actual.isNull();
634  }
635  } else {
636  tid = argType.typeId();
637  v = QVariant(tid, (void *)0);
638  converted = QScriptEnginePrivate::convertValue(exec, actual, tid, v.data());
639  if (exec->hadException())
640  return exec->exception();
641  }
642 
643  if (!converted) {
644  if (QScriptEnginePrivate::isVariant(actual)) {
645  if (tid == -1)
646  tid = argType.typeId();
648  if (vv.canConvert(QVariant::Type(tid))) {
649  v = vv;
650  converted = v.convert(QVariant::Type(tid));
651  if (converted && (vv.userType() != tid))
652  matchDistance += 10;
653  } else {
654  QByteArray vvTypeName = vv.typeName();
655  if (vvTypeName.endsWith('*')
656  && (vvTypeName.left(vvTypeName.size()-1) == argType.name())) {
657  v = QVariant(tid, *reinterpret_cast<void* *>(vv.data()));
658  converted = true;
659  matchDistance += 10;
660  }
661  }
662  } else if (actual.isNumber() || actual.isString()) {
663  // see if it's an enum value
664  QMetaEnum m;
665  if (argType.isMetaEnum()) {
666  m = meta->enumerator(argType.enumeratorIndex());
667  } else {
668  int mi = indexOfMetaEnum(meta, argType.name());
669  if (mi != -1)
670  m = meta->enumerator(mi);
671  }
672  if (m.isValid()) {
673  if (actual.isNumber()) {
674  int ival = QScriptEnginePrivate::toInt32(exec, actual);
675  if (m.valueToKey(ival) != 0) {
676  v.setValue(ival);
677  converted = true;
678  matchDistance += 10;
679  }
680  } else {
681  JSC::UString sval = QScriptEnginePrivate::toString(exec, actual);
682  int ival = m.keyToValue(convertToLatin1(sval));
683  if (ival != -1) {
684  v.setValue(ival);
685  converted = true;
686  matchDistance += 10;
687  }
688  }
689  }
690  }
691  } else {
692  // determine how well the conversion matched
693  if (actual.isNumber()) {
694  switch (tid) {
695  case QMetaType::Double:
696  // perfect
697  break;
698  case QMetaType::Float:
699  matchDistance += 1;
700  break;
701  case QMetaType::LongLong:
703  matchDistance += 2;
704  break;
705  case QMetaType::Long:
706  case QMetaType::ULong:
707  matchDistance += 3;
708  break;
709  case QMetaType::Int:
710  case QMetaType::UInt:
711  matchDistance += 4;
712  break;
713  case QMetaType::Short:
714  case QMetaType::UShort:
715  matchDistance += 5;
716  break;
717  case QMetaType::Char:
718  case QMetaType::UChar:
719  matchDistance += 6;
720  break;
721  default:
722  matchDistance += 10;
723  break;
724  }
725  } else if (actual.isString()) {
726  switch (tid) {
727  case QMetaType::QString:
728  // perfect
729  break;
730  default:
731  matchDistance += 10;
732  break;
733  }
734  } else if (actual.isBoolean()) {
735  switch (tid) {
736  case QMetaType::Bool:
737  // perfect
738  break;
739  default:
740  matchDistance += 10;
741  break;
742  }
743  } else if (QScriptEnginePrivate::isDate(actual)) {
744  switch (tid) {
746  // perfect
747  break;
748  case QMetaType::QDate:
749  matchDistance += 1;
750  break;
751  case QMetaType::QTime:
752  matchDistance += 2;
753  break;
754  default:
755  matchDistance += 10;
756  break;
757  }
758  } else if (QScriptEnginePrivate::isRegExp(actual)) {
759  switch (tid) {
760  case QMetaType::QRegExp:
761  // perfect
762  break;
763  default:
764  matchDistance += 10;
765  break;
766  }
767  } else if (QScriptEnginePrivate::isVariant(actual)) {
768  if (argType.isVariant()
769  || (QScriptEnginePrivate::toVariant(exec, actual).userType() == tid)) {
770  // perfect
771  } else {
772  matchDistance += 10;
773  }
774  } else if (QScriptEnginePrivate::isArray(actual)) {
775  switch (tid) {
778  matchDistance += 5;
779  break;
780  default:
781  matchDistance += 10;
782  break;
783  }
784  } else if (QScriptEnginePrivate::isQObject(actual)) {
785  switch (tid) {
788  // perfect
789  break;
790  default:
791  matchDistance += 10;
792  break;
793  }
794  } else if (actual.isNull()) {
795  switch (tid) {
796  case QMetaType::VoidStar:
799  // perfect
800  break;
801  default:
802  if (!argType.name().endsWith('*'))
803  matchDistance += 10;
804  break;
805  }
806  } else {
807  matchDistance += 10;
808  }
809  }
810 
811  if (converted)
812  args[i+1] = v;
813  }
814 
815  if (converted) {
816  if ((scriptArgs.size() == (size_t)mtd.argumentCount())
817  && (matchDistance == 0)) {
818  // perfect match, use this one
819  chosenMethod = mtd;
820  chosenIndex = index;
821  break;
822  } else {
823  bool redundant = false;
824  if ((callType != QMetaMethod::Constructor)
825  && (index < meta->methodOffset())) {
826  // it is possible that a virtual method is redeclared in a subclass,
827  // in which case we want to ignore the superclass declaration
828  for (int i = 0; i < candidates.size(); ++i) {
829  const QScriptMetaArguments &other = candidates.at(i);
830  if (mtd.types() == other.method.types()) {
831  redundant = true;
832  break;
833  }
834  }
835  }
836  if (!redundant) {
837  QScriptMetaArguments metaArgs(matchDistance, index, mtd, args);
838  if (candidates.isEmpty()) {
839  candidates.append(metaArgs);
840  } else {
841  const QScriptMetaArguments &otherArgs = candidates.at(0);
842  if ((args.count() > otherArgs.args.count())
843  || ((args.count() == otherArgs.args.count())
844  && (matchDistance <= otherArgs.matchDistance))) {
845  candidates.prepend(metaArgs);
846  } else {
847  candidates.append(metaArgs);
848  }
849  }
850  }
851  }
852  } else if (mtd.fullyResolved()) {
853  conversionFailed.append(index);
854  }
855 
856  if (!maybeOverloaded)
857  break;
858  }
859 
860  JSC::JSValue result;
861  if ((chosenIndex == -1) && candidates.isEmpty()) {
862 // context->calleeMetaIndex = initialIndex;
863 //#ifndef Q_SCRIPT_NO_EVENT_NOTIFY
864 // engine->notifyFunctionEntry(context);
865 //#endif
866  QString funName = QString::fromLatin1(methodName(initialMethodSignature, nameLength));
867  if (!conversionFailed.isEmpty()) {
868  QString message = QString::fromLatin1("incompatible type of argument(s) in call to %0(); candidates were\n")
869  .arg(funName);
870  for (int i = 0; i < conversionFailed.size(); ++i) {
871  if (i > 0)
872  message += QLatin1String("\n");
873  QMetaMethod mtd = metaMethod(meta, callType, conversionFailed.at(i));
874  message += QString::fromLatin1(" %0").arg(QString::fromLatin1(mtd.signature()));
875  }
876  result = JSC::throwError(exec, JSC::TypeError, message);
877  } else if (!unresolved.isEmpty()) {
878  QScriptMetaArguments argsInstance = unresolved.first();
879  int unresolvedIndex = argsInstance.method.firstUnresolvedIndex();
880  Q_ASSERT(unresolvedIndex != -1);
881  QScriptMetaType unresolvedType = argsInstance.method.type(unresolvedIndex);
882  QString unresolvedTypeName = QString::fromLatin1(unresolvedType.name());
883  QString message = QString::fromLatin1("cannot call %0(): ")
884  .arg(funName);
885  if (unresolvedIndex > 0) {
886  message.append(QString::fromLatin1("argument %0 has unknown type `%1'").
887  arg(unresolvedIndex).arg(unresolvedTypeName));
888  } else {
889  message.append(QString::fromLatin1("unknown return type `%0'")
890  .arg(unresolvedTypeName));
891  }
892  message.append(QString::fromLatin1(" (register the type with qScriptRegisterMetaType())"));
893  result = JSC::throwError(exec, JSC::TypeError, message);
894  } else {
895  QString message = QString::fromLatin1("too few arguments in call to %0(); candidates are\n")
896  .arg(funName);
897  for (int i = 0; i < tooFewArgs.size(); ++i) {
898  if (i > 0)
899  message += QLatin1String("\n");
900  QMetaMethod mtd = metaMethod(meta, callType, tooFewArgs.at(i));
901  message += QString::fromLatin1(" %0").arg(QString::fromLatin1(mtd.signature()));
902  }
903  result = JSC::throwError(exec, JSC::SyntaxError, message);
904  }
905  } else {
906  if (chosenIndex == -1) {
907  QScriptMetaArguments metaArgs = candidates.at(0);
908  if ((candidates.size() > 1)
909  && (metaArgs.args.count() == candidates.at(1).args.count())
910  && (metaArgs.matchDistance == candidates.at(1).matchDistance)) {
911  // ambiguous call
912  QByteArray funName = methodName(initialMethodSignature, nameLength);
913  QString message = QString::fromLatin1("ambiguous call of overloaded function %0(); candidates were\n")
914  .arg(QLatin1String(funName));
915  for (int i = 0; i < candidates.size(); ++i) {
916  if (i > 0)
917  message += QLatin1String("\n");
918  QMetaMethod mtd = metaMethod(meta, callType, candidates.at(i).index);
919  message += QString::fromLatin1(" %0").arg(QString::fromLatin1(mtd.signature()));
920  }
921  result = JSC::throwError(exec, JSC::TypeError, message);
922  } else {
923  chosenMethod = metaArgs.method;
924  chosenIndex = metaArgs.index;
925  args = metaArgs.args;
926  }
927  }
928 
929  if (chosenIndex != -1) {
930  // call it
931 // context->calleeMetaIndex = chosenIndex;
932 
933  QVarLengthArray<void*, 9> array(args.count());
934  void **params = array.data();
935  for (int i = 0; i < args.count(); ++i) {
936  const QVariant &v = args[i];
937  switch (chosenMethod.type(i).kind()) {
938  case QScriptMetaType::Variant:
939  params[i] = const_cast<QVariant*>(&v);
940  break;
941  case QScriptMetaType::MetaType:
942  case QScriptMetaType::MetaEnum:
943  case QScriptMetaType::Unresolved:
944  params[i] = const_cast<void*>(v.constData());
945  break;
946  default:
947  Q_ASSERT(0);
948  }
949  }
950 
951  QScriptable *scriptable = 0;
952  if (thisQObject)
953  scriptable = scriptableFromQObject(thisQObject);
954  QScriptEngine *oldEngine = 0;
955  if (scriptable) {
956  oldEngine = QScriptablePrivate::get(scriptable)->engine;
958  }
959 
960 // ### fixme
961 //#ifndef Q_SCRIPT_NO_EVENT_NOTIFY
962 // engine->notifyFunctionEntry(context);
963 //#endif
964 
965  if (callType == QMetaMethod::Constructor) {
966  Q_ASSERT(meta != 0);
967  meta->static_metacall(QMetaObject::CreateInstance, chosenIndex, params);
968  } else {
969  QMetaObject::metacall(thisQObject, QMetaObject::InvokeMetaMethod, chosenIndex, params);
970  }
971 
972  if (scriptable)
973  QScriptablePrivate::get(scriptable)->engine = oldEngine;
974 
975  if (exec->hadException()) {
976  result = exec->exception() ; // propagate
977  } else {
978  QScriptMetaType retType = chosenMethod.returnType();
979  if (retType.isVariant()) {
980  result = QScriptEnginePrivate::jscValueFromVariant(exec, *(QVariant *)params[0]);
981  } else if (retType.typeId() != 0) {
982  result = QScriptEnginePrivate::create(exec, retType.typeId(), params[0]);
983  if (!result)
984  result = engine->newVariant(QVariant(retType.typeId(), params[0]));
985  } else {
986  result = JSC::jsUndefined();
987  }
988  }
989  }
990  }
991 
992  return result;
993 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void resize(int size)
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
static JSC::JSValue jscValueFromVariant(JSC::ExecState *, const QVariant &value)
static QScriptEnginePrivate * get(QScriptEngine *q)
bool isValid() const
Returns true if this enum is valid (has a name); otherwise returns false.
Definition: qmetaobject.h:168
static QVariant toVariant(JSC::ExecState *, JSC::JSValue)
static JSC::JSValue create(JSC::ExecState *, int type, const void *ptr)
static int metacall(QObject *, Call, int, void **)
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int static_metacall(Call, int, void **) const
const char * valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or 0 if value is not defi...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static int indexOfMetaEnum(const QMetaObject *meta, const QByteArray &str)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setValue(const T &value)
Stores a copy of value.
Definition: qvariant.h:527
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
The QScriptable class provides access to the Qt Script environment from Qt C++ member functions...
Definition: qscriptable.h:45
static QScriptablePrivate * get(QScriptable *q)
Definition: qscriptable_p.h:51
static bool convertToNativeQObject(JSC::ExecState *, JSC::JSValue, const QByteArray &targetType, void **result)
void * data()
Definition: qvariant.cpp:3077
The QScriptEngine class provides an environment for evaluating Qt Script code.
static bool isVariant(JSC::JSValue)
static qint32 toInt32(JSC::ExecState *, JSC::JSValue)
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
int methodOffset() const
Returns the method offset for this class; i.e.
static QScriptable * scriptableFromQObject(QObject *qobj)
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static bool methodNameEquals(const QMetaMethod &method, const char *signature, int nameLength)
Returns true if the name of the given method is the same as that specified by the (signature...
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static QMetaMethod metaMethod(const QMetaObject *meta, QMetaMethod::MethodType type, int index)
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
int count() const
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
JSC::JSValue newVariant(const QVariant &)
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
static bool convertValue(JSC::ExecState *, JSC::JSValue value, int type, void *ptr)
static bool isDate(JSC::JSValue)
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
static bool isRegExp(JSC::JSValue)
static int methodNameLength(const QMetaMethod &method)
Calculates the length of the name of the given method by looking for the first &#39;(&#39; character...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QString & append(QChar c)
Definition: qstring.cpp:1777
static const struct @32 types[]
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static bool isQObject(JSC::JSValue)
const void * constData() const
Definition: qvariant.cpp:3065
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QByteArray methodName(const char *signature, int nameLength)
Makes a deep copy of the first nameLength characters of the given method signature and returns the co...
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int keyToValue(const char *key) const
Returns the integer value of the given enumeration key, or -1 if key is not defined.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index
static QVariant & variantValue(JSC::JSValue value)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
const char * variant
static bool isArray(JSC::JSValue)
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void prepend(const T &t)
Inserts value at the beginning of the vector.
Definition: qvector.h:378
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define INT_MAX
QByteArray convertToLatin1(const JSC::UString &str)
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
QScriptEngine * engine
Definition: qscriptable_p.h:54

◆ convertToLatin1()

QByteArray QScript::convertToLatin1 ( const JSC::UString &  str)
inline

◆ convertToLatin1_helper()

void QScript::convertToLatin1_helper ( const UChar *  i,
int  length,
char *  s 
)
inline

Definition at line 562 of file qscriptengine_p.h.

Referenced by convertToLatin1().

563 {
564  const UChar *e = i + length;
565  while (i != e)
566  *(s++) = (uchar) *(i++);
567  *s = '\0';
568 }
unsigned char uchar
Definition: qglobal.h:994

◆ DateTimeToMs()

qsreal QScript::DateTimeToMs ( JSC::ExecState *  exec,
const QDateTime dt 
)

Converts a QDateTime to a JS date value (milliseconds).

Warning
This function is not part of the public interface.

Definition at line 483 of file qscriptengine.cpp.

Referenced by QScriptEnginePrivate::newDate().

484 {
485  if (!dt.isValid())
486  return qSNaN();
487  QDateTime utc = dt.toUTC();
488  QDate date = utc.date();
489  QTime time = utc.time();
490  JSC::GregorianDateTime tm;
491  tm.year = date.year() - 1900;
492  tm.month = date.month() - 1;
493  tm.monthDay = date.day();
494  tm.weekDay = date.dayOfWeek();
495  tm.yearDay = date.dayOfYear();
496  tm.hour = time.hour();
497  tm.minute = time.minute();
498  tm.second = time.second();
499  return JSC::gregorianDateTimeToMS(exec, tm, time.msec(), /*inputIsUTC=*/true);
500 }
int dayOfWeek() const
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition: qdatetime.cpp:408
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
The QDate class provides date functions.
Definition: qdatetime.h:55
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
The QTime class provides clock time functions.
Definition: qdatetime.h:148
int dayOfYear() const
Returns the day of the year (1 to 365 or 366 on leap years) for this date.
Definition: qdatetime.cpp:420
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:251
Q_CORE_EXPORT double qSNaN()
Returns the bit pattern of a signalling NaN as a double.
Definition: qnumeric.cpp:80
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ Equals()

static bool QScript::Equals ( QScriptValue  lhs,
QScriptValue  rhs 
)
static

Definition at line 764 of file qscriptvalue.cpp.

Referenced by QScriptValue::equals().

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 }
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
int type
Definition: qmetatype.cpp:239
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
static bool IsNumerical(const QScriptValue &value)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
static QScriptValue ToPrimitive(const QScriptValue &object, JSC::PreferredPrimitiveType hint=JSC::NoPreference)
static bool Equals(QScriptValue lhs, QScriptValue rhs)
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
bool strictlyEquals(const QScriptValue &other) const
Returns true if this QScriptValue is equal to other using strict comparison (no conversion), otherwise returns false.
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. ...

◆ flagsForMetaProperty()

static unsigned QScript::flagsForMetaProperty ( const QMetaProperty prop)
static

Definition at line 238 of file qscriptqobject.cpp.

Referenced by QScript::QObjectDelegate::getOwnPropertyDescriptor().

239 {
240  return (JSC::DontDelete
241  | (!prop.isWritable() ? unsigned(JSC::ReadOnly) : unsigned(0))
243  ? unsigned(JSC::Getter | JSC::Setter)
244  : unsigned(0))
246 }
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
static const bool GeneratePropertyFunctions

◆ functionConnect()

JSC::JSValue JSC_HOST_CALL QScript::functionConnect ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisObject,
const JSC::ArgList &  args 
)
static

Definition at line 681 of file qscriptengine.cpp.

Referenced by isFunction(), and QScriptEnginePrivate::QScriptEnginePrivate().

682 {
683 #ifndef QT_NO_QOBJECT
684  if (args.size() == 0) {
685  return JSC::throwError(exec, JSC::GeneralError,"Function.prototype.connect: no arguments given");
686  }
687 
688  if (!JSC::asObject(thisObject)->inherits(&QScript::QtFunction::info)) {
689  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: this object is not a signal");
690  }
691 
692  QScript::QtFunction *qtSignal = static_cast<QScript::QtFunction*>(JSC::asObject(thisObject));
693 
694  const QMetaObject *meta = qtSignal->metaObject();
695  if (!meta) {
696  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: cannot connect to deleted QObject");
697  }
698 
699  QMetaMethod sig = meta->method(qtSignal->initialIndex());
700  if (sig.methodType() != QMetaMethod::Signal) {
701  QString message = QString::fromLatin1("Function.prototype.connect: %0::%1 is not a signal")
702  .arg(QLatin1String(qtSignal->metaObject()->className()))
703  .arg(QLatin1String(sig.signature()));
704  return JSC::throwError(exec, JSC::TypeError, message);
705  }
706 
707  {
708  QList<int> overloads = qtSignal->overloadedIndexes();
709  if (!overloads.isEmpty()) {
710  overloads.append(qtSignal->initialIndex());
711  QByteArray signature = sig.signature();
712  QString message = QString::fromLatin1("Function.prototype.connect: ambiguous connect to %0::%1(); candidates are\n")
713  .arg(QLatin1String(qtSignal->metaObject()->className()))
714  .arg(QLatin1String(signature.left(signature.indexOf('('))));
715  for (int i = 0; i < overloads.size(); ++i) {
716  QMetaMethod mtd = meta->method(overloads.at(i));
717  message.append(QString::fromLatin1(" %0\n").arg(QString::fromLatin1(mtd.signature())));
718  }
719  message.append(QString::fromLatin1("Use e.g. object['%0'].connect() to connect to a particular overload")
720  .arg(QLatin1String(signature)));
721  return JSC::throwError(exec, JSC::GeneralError, message);
722  }
723  }
724 
726 
727  JSC::JSValue receiver;
728  JSC::JSValue slot;
729  JSC::JSValue arg0 = args.at(0);
730  if (args.size() < 2) {
731  slot = arg0;
732  } else {
733  receiver = arg0;
734  JSC::JSValue arg1 = args.at(1);
735  if (isFunction(arg1))
736  slot = arg1;
737  else {
738  QScript::SaveFrameHelper saveFrame(engine, exec);
739  JSC::UString propertyName = QScriptEnginePrivate::toString(exec, arg1);
740  slot = QScriptEnginePrivate::property(exec, arg0, propertyName, QScriptValue::ResolvePrototype);
741  }
742  }
743 
744  if (!isFunction(slot)) {
745  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.connect: target is not a function");
746  }
747 
748  bool ok = engine->scriptConnect(thisObject, receiver, slot, Qt::AutoConnection);
749  if (!ok) {
750  QString message = QString::fromLatin1("Function.prototype.connect: failed to connect to %0::%1")
751  .arg(QLatin1String(qtSignal->metaObject()->className()))
752  .arg(QLatin1String(sig.signature()));
753  return JSC::throwError(exec, JSC::GeneralError, message);
754  }
755  return JSC::jsUndefined();
756 #else
757  Q_UNUSED(eng);
758  Q_UNUSED(classInfo);
759  return context->throwError(QScriptContext::TypeError,
760  QLatin1String("Function.prototype.connect"));
761 #endif // QT_NO_QOBJECT
762 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isFunction(JSC::JSValue value)
const QMetaObject * metaObject() const
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QString & append(QChar c)
Definition: qstring.cpp:1777
static JSC::JSValue property(JSC::ExecState *, JSC::JSValue, const JSC::Identifier &id, int resolveMode=QScriptValue::ResolvePrototype)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QList< int > overloadedIndexes() const
static const JSC::ClassInfo info
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
bool scriptConnect(QObject *sender, const char *signal, JSC::JSValue receiver, JSC::JSValue function, Qt::ConnectionType type)

◆ functionDisconnect()

JSC::JSValue JSC_HOST_CALL QScript::functionDisconnect ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisObject,
const JSC::ArgList &  args 
)
static

Definition at line 617 of file qscriptengine.cpp.

Referenced by isFunction(), and QScriptEnginePrivate::QScriptEnginePrivate().

618 {
619 #ifndef QT_NO_QOBJECT
620  if (args.size() == 0) {
621  return JSC::throwError(exec, JSC::GeneralError, "Function.prototype.disconnect: no arguments given");
622  }
623 
624  if (!JSC::asObject(thisObject)->inherits(&QScript::QtFunction::info)) {
625  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.disconnect: this object is not a signal");
626  }
627 
628  QScript::QtFunction *qtSignal = static_cast<QScript::QtFunction*>(JSC::asObject(thisObject));
629 
630  const QMetaObject *meta = qtSignal->metaObject();
631  if (!meta) {
632  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.discconnect: cannot disconnect from deleted QObject");
633  }
634 
635  QMetaMethod sig = meta->method(qtSignal->initialIndex());
636  if (sig.methodType() != QMetaMethod::Signal) {
637  QString message = QString::fromLatin1("Function.prototype.disconnect: %0::%1 is not a signal")
638  .arg(QLatin1String(qtSignal->metaObject()->className()))
639  .arg(QLatin1String(sig.signature()));
640  return JSC::throwError(exec, JSC::TypeError, message);
641  }
642 
644 
645  JSC::JSValue receiver;
646  JSC::JSValue slot;
647  JSC::JSValue arg0 = args.at(0);
648  if (args.size() < 2) {
649  slot = arg0;
650  } else {
651  receiver = arg0;
652  JSC::JSValue arg1 = args.at(1);
653  if (isFunction(arg1))
654  slot = arg1;
655  else {
656  QScript::SaveFrameHelper saveFrame(engine, exec);
657  JSC::UString propertyName = QScriptEnginePrivate::toString(exec, arg1);
658  slot = QScriptEnginePrivate::property(exec, arg0, propertyName, QScriptValue::ResolvePrototype);
659  }
660  }
661 
662  if (!isFunction(slot)) {
663  return JSC::throwError(exec, JSC::TypeError, "Function.prototype.disconnect: target is not a function");
664  }
665 
666  bool ok = engine->scriptDisconnect(thisObject, receiver, slot);
667  if (!ok) {
668  QString message = QString::fromLatin1("Function.prototype.disconnect: failed to disconnect from %0::%1")
669  .arg(QLatin1String(qtSignal->metaObject()->className()))
670  .arg(QLatin1String(sig.signature()));
671  return JSC::throwError(exec, JSC::GeneralError, message);
672  }
673  return JSC::jsUndefined();
674 #else
675  Q_UNUSED(eng);
676  return context->throwError(QScriptContext::TypeError,
677  QLatin1String("Function.prototype.disconnect"));
678 #endif // QT_NO_QOBJECT
679 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
bool isFunction(JSC::JSValue value)
const QMetaObject * metaObject() const
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
bool scriptDisconnect(QObject *sender, const char *signal, JSC::JSValue receiver, JSC::JSValue function)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static JSC::JSValue property(JSC::ExecState *, JSC::JSValue, const JSC::Identifier &id, int resolveMode=QScriptValue::ResolvePrototype)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
static const JSC::ClassInfo info
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56

◆ functionGC()

JSC::JSValue JSC_HOST_CALL QScript::functionGC ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &   
)
static

Definition at line 785 of file qscriptengine.cpp.

Referenced by functionConnect(), and QScriptEnginePrivate::QScriptEnginePrivate().

786 {
788  engine->collectGarbage();
789  return JSC::jsUndefined();
790 }
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)

◆ functionPrint()

JSC::JSValue JSC_HOST_CALL QScript::functionPrint ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 768 of file qscriptengine.cpp.

Referenced by functionConnect(), and QScriptEnginePrivate::QScriptEnginePrivate().

769 {
770  QString result;
771  for (unsigned i = 0; i < args.size(); ++i) {
772  if (i != 0)
773  result.append(QLatin1Char(' '));
774  QString s(args.at(i).toString(exec));
775  if (exec->hadException())
776  break;
777  result.append(s);
778  }
779  if (exec->hadException())
780  return exec->exception();
781  qDebug("%s", qPrintable(result));
782  return JSC::jsUndefined();
783 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
QString & append(QChar c)
Definition: qstring.cpp:1777
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ functionQsTr()

JSC::JSValue JSC_HOST_CALL QScript::functionQsTr ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 861 of file qscriptengine.cpp.

Referenced by functionVersion(), and QScriptEngine::installTranslatorFunctions().

862 {
863  if (args.size() < 1)
864  return JSC::throwError(exec, JSC::GeneralError, "qsTr() requires at least one argument");
865  if (!args.at(0).isString())
866  return JSC::throwError(exec, JSC::GeneralError, "qsTr(): first argument (text) must be a string");
867  if ((args.size() > 1) && !args.at(1).isString())
868  return JSC::throwError(exec, JSC::GeneralError, "qsTr(): second argument (comment) must be a string");
869  if ((args.size() > 2) && !args.at(2).isNumber())
870  return JSC::throwError(exec, JSC::GeneralError, "qsTr(): third argument (n) must be a number");
871 #ifndef QT_NO_QOBJECT
873  JSC::UString context;
874  // The first non-empty source URL in the call stack determines the translation context.
875  {
876  JSC::ExecState *frame = exec->callerFrame()->removeHostCallFrameFlag();
877  while (frame) {
878  if (frame->codeBlock() && QScriptEnginePrivate::hasValidCodeBlockRegister(frame)
879  && frame->codeBlock()->source()
880  && !frame->codeBlock()->source()->url().isEmpty()) {
881  context = engine->translationContextFromUrl(frame->codeBlock()->source()->url());
882  break;
883  }
884  frame = frame->callerFrame()->removeHostCallFrameFlag();
885  }
886  }
887 #endif
888  JSC::UString text = args.at(0).toString(exec);
889 #ifndef QT_NO_QOBJECT
890  JSC::UString comment;
891  if (args.size() > 1)
892  comment = args.at(1).toString(exec);
893  int n = -1;
894  if (args.size() > 2)
895  n = args.at(2).toInt32(exec);
896 #endif
897  JSC::UString result;
898 #ifndef QT_NO_QOBJECT
899  result = QCoreApplication::translate(context.UTF8String().c_str(),
900  text.UTF8String().c_str(),
901  comment.UTF8String().c_str(),
903 #else
904  result = text;
905 #endif
906  return JSC::jsString(exec, result);
907 }
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
JSC::UString translationContextFromUrl(const JSC::UString &)
static bool hasValidCodeBlockRegister(JSC::ExecState *frame)
#define text
Definition: qobjectdefs.h:80

◆ functionQsTranslate()

JSC::JSValue JSC_HOST_CALL QScript::functionQsTranslate ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 806 of file qscriptengine.cpp.

Referenced by functionVersion(), and QScriptEngine::installTranslatorFunctions().

807 {
808  if (args.size() < 2)
809  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate() requires at least two arguments");
810  if (!args.at(0).isString())
811  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): first argument (context) must be a string");
812  if (!args.at(1).isString())
813  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): second argument (text) must be a string");
814  if ((args.size() > 2) && !args.at(2).isString())
815  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): third argument (comment) must be a string");
816  if ((args.size() > 3) && !args.at(3).isString())
817  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): fourth argument (encoding) must be a string");
818  if ((args.size() > 4) && !args.at(4).isNumber())
819  return JSC::throwError(exec, JSC::GeneralError, "qsTranslate(): fifth argument (n) must be a number");
820 #ifndef QT_NO_QOBJECT
821  JSC::UString context = args.at(0).toString(exec);
822 #endif
823  JSC::UString text = args.at(1).toString(exec);
824 #ifndef QT_NO_QOBJECT
825  JSC::UString comment;
826  if (args.size() > 2)
827  comment = args.at(2).toString(exec);
829  if (args.size() > 3) {
830  JSC::UString encStr = args.at(3).toString(exec);
831  if (encStr == "CodecForTr")
832  encoding = QCoreApplication::CodecForTr;
833  else if (encStr == "UnicodeUTF8")
835  else
836  return JSC::throwError(exec, JSC::GeneralError, QString::fromLatin1("qsTranslate(): invalid encoding '%0'").arg(encStr));
837  }
838  int n = -1;
839  if (args.size() > 4)
840  n = args.at(4).toInt32(exec);
841 #endif
842  JSC::UString result;
843 #ifndef QT_NO_QOBJECT
844  result = QCoreApplication::translate(context.UTF8String().c_str(),
845  text.UTF8String().c_str(),
846  comment.UTF8String().c_str(),
847  encoding, n);
848 #else
849  result = text;
850 #endif
851  return JSC::jsString(exec, result);
852 }
Encoding
This enum type defines the 8-bit encoding of character string arguments to translate(): ...
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define text
Definition: qobjectdefs.h:80

◆ functionQsTranslateNoOp()

JSC::JSValue JSC_HOST_CALL QScript::functionQsTranslateNoOp ( JSC::ExecState *  ,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 854 of file qscriptengine.cpp.

Referenced by functionVersion(), and QScriptEngine::installTranslatorFunctions().

855 {
856  if (args.size() < 2)
857  return JSC::jsUndefined();
858  return args.at(1);
859 }

◆ functionQsTrId()

JSC::JSValue JSC_HOST_CALL QScript::functionQsTrId ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 916 of file qscriptengine.cpp.

Referenced by functionVersion(), and QScriptEngine::installTranslatorFunctions().

917 {
918  if (args.size() < 1)
919  return JSC::throwError(exec, JSC::GeneralError, "qsTrId() requires at least one argument");
920  if (!args.at(0).isString())
921  return JSC::throwError(exec, JSC::TypeError, "qsTrId(): first argument (id) must be a string");
922  if ((args.size() > 1) && !args.at(1).isNumber())
923  return JSC::throwError(exec, JSC::TypeError, "qsTrId(): second argument (n) must be a number");
924  JSC::UString id = args.at(0).toString(exec);
925  int n = -1;
926  if (args.size() > 1)
927  n = args.at(1).toInt32(exec);
928  return JSC::jsString(exec, qtTrId(id.UTF8String().c_str(), n));
929 }
Q_CORE_EXPORT QString qtTrId(const char *id, int n=-1)

◆ functionQsTrIdNoOp()

JSC::JSValue JSC_HOST_CALL QScript::functionQsTrIdNoOp ( JSC::ExecState *  ,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 931 of file qscriptengine.cpp.

Referenced by functionVersion(), and QScriptEngine::installTranslatorFunctions().

932 {
933  if (args.size() < 1)
934  return JSC::jsUndefined();
935  return args.at(0);
936 }

◆ functionQsTrNoOp()

JSC::JSValue JSC_HOST_CALL QScript::functionQsTrNoOp ( JSC::ExecState *  ,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &  args 
)
static

Definition at line 909 of file qscriptengine.cpp.

Referenced by functionVersion(), and QScriptEngine::installTranslatorFunctions().

910 {
911  if (args.size() < 1)
912  return JSC::jsUndefined();
913  return args.at(0);
914 }

◆ functionVersion()

JSC::JSValue JSC_HOST_CALL QScript::functionVersion ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  ,
const JSC::ArgList &   
)
static

Definition at line 792 of file qscriptengine.cpp.

Referenced by functionConnect(), and QScriptEnginePrivate::QScriptEnginePrivate().

793 {
794  return JSC::JSValue(exec, 1);
795 }

◆ hasMethodAccess()

static bool QScript::hasMethodAccess ( const QMetaMethod method,
int  index,
const QScriptEngine::QObjectWrapOptions &  opt 
)
static

Definition at line 152 of file qscriptqobject.cpp.

Referenced by QScript::QObjectDelegate::getOwnPropertyDescriptor(), QScript::QObjectDelegate::getOwnPropertyNames(), QScript::QObjectDelegate::getOwnPropertySlot(), and QScript::QObjectDelegate::put().

153 {
154  return (method.access() != QMetaMethod::Private)
155  && ((index != 2) || !(opt & QScriptEngine::ExcludeDeleteLater))
156  && (!(opt & QScriptEngine::ExcludeSlots) || (method.methodType() != QMetaMethod::Slot));
157 }
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
quint16 index
Access access() const
Returns the access specification of this method (private, protected, or public).

◆ indexOfMetaEnum()

static int QScript::indexOfMetaEnum ( const QMetaObject meta,
const QByteArray str 
)
static

Definition at line 248 of file qscriptqobject.cpp.

Referenced by callQtMethod().

249 {
250  QByteArray scope;
252  int scopeIdx = str.lastIndexOf("::");
253  if (scopeIdx != -1) {
254  scope = str.left(scopeIdx);
255  name = str.mid(scopeIdx + 2);
256  } else {
257  name = str;
258  }
259  for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
260  QMetaEnum m = meta->enumerator(i);
261  if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
262  return i;
263  }
264  return -1;
265 }
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * scope() const
Returns the scope this enumerator was declared in.
const char * name() const
Returns the name of the enumerator (without the scope).
int lastIndexOf(char c, int from=-1) const
Returns the index position of the last occurrence of character ch in the byte array, searching backward from index position from.
const char * name
int enumeratorCount() const
Returns the number of enumerators in this class.
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ integerFromString() [1/2]

qsreal QScript::integerFromString ( const char *  buf,
int  size,
int  radix 
)

Definition at line 547 of file qscriptengine.cpp.

Referenced by QScript::Lexer::lex().

548 {
549  if (size == 0)
550  return qSNaN();
551 
552  qsreal sign = 1.0;
553  int i = 0;
554  if (buf[0] == '+') {
555  ++i;
556  } else if (buf[0] == '-') {
557  sign = -1.0;
558  ++i;
559  }
560 
561  if (((size-i) >= 2) && (buf[i] == '0')) {
562  if (((buf[i+1] == 'x') || (buf[i+1] == 'X'))
563  && (radix < 34)) {
564  if ((radix != 0) && (radix != 16))
565  return 0;
566  radix = 16;
567  i += 2;
568  } else {
569  if (radix == 0) {
570  radix = 8;
571  ++i;
572  }
573  }
574  } else if (radix == 0) {
575  radix = 10;
576  }
577 
578  int j = i;
579  for ( ; i < size; ++i) {
580  int d = toDigit(buf[i]);
581  if ((d == -1) || (d >= radix))
582  break;
583  }
584  qsreal result;
585  if (j == i) {
586  if (!qstrcmp(buf, "Infinity"))
587  result = qInf();
588  else
589  result = qSNaN();
590  } else {
591  result = 0;
592  qsreal multiplier = 1;
593  for (--i ; i >= j; --i, multiplier *= radix)
594  result += toDigit(buf[i]) * multiplier;
595  }
596  result *= sign;
597  return result;
598 }
double d
Definition: qnumeric_p.h:62
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
static int sign(int x)
Q_CORE_EXPORT double qSNaN()
Returns the bit pattern of a signalling NaN as a double.
Definition: qnumeric.cpp:80
Q_CORE_EXPORT double qInf()
Returns the bit pattern for an infinite number as a double.
Definition: qnumeric.cpp:90
double qsreal
Definition: qscriptvalue.h:52
static int toDigit(char c)

◆ integerFromString() [2/2]

qsreal QScript::integerFromString ( const QString str,
int  radix 
)

Definition at line 600 of file qscriptengine.cpp.

601 {
602  QByteArray ba = str.trimmed().toUtf8();
603  return integerFromString(ba.constData(), ba.size(), radix);
604 }
qsreal integerFromString(const QString &str, int radix)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ isEnumerableMetaProperty()

static bool QScript::isEnumerableMetaProperty ( const QMetaProperty prop,
const QMetaObject mo,
int  index 
)
static

Definition at line 159 of file qscriptqobject.cpp.

Referenced by QScript::QObjectDelegate::getOwnPropertyNames().

161 {
162  return prop.isScriptable() && prop.isValid()
163  // the following lookup is to ensure that we have the
164  // "most derived" occurrence of the property with this name
165  && (mo->indexOfProperty(prop.name()) == index);
166 }
bool isScriptable(const QObject *obj=0) const
Returns true if the property is scriptable for the given object; otherwise returns false...
bool isValid() const
Returns true if this property is valid (readable); otherwise returns false.
Definition: qmetaobject.h:213
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
const char * name() const
Returns this property&#39;s name.
quint16 index

◆ isFunction()

bool QScript::isFunction ( JSC::JSValue  value)

Definition at line 606 of file qscriptengine.cpp.

Referenced by QScriptDeclarativeClass::function(), functionConnect(), functionDisconnect(), QScriptDeclarativeClass::functionValue(), QScriptValue::isFunction(), QScriptEngine::qScriptConnect(), and QScriptEngine::qScriptDisconnect().

607 {
608  if (!value || !value.isObject())
609  return false;
610  JSC::CallData callData;
611  return (JSC::asObject(value)->getCallData(callData) != JSC::CallTypeNone);
612 }

◆ IsNumerical()

static bool QScript::IsNumerical ( const QScriptValue value)
static

Definition at line 725 of file qscriptvalue.cpp.

Referenced by Equals().

726 {
727  return value.isNumber() || value.isBool();
728 }
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...

◆ LessThan()

static bool QScript::LessThan ( QScriptValue  lhs,
QScriptValue  rhs 
)
static

Definition at line 730 of file qscriptvalue.cpp.

Referenced by QScriptValue::lessThan().

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 }
int type
Definition: qmetatype.cpp:239
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
static QScriptValue ToPrimitive(const QScriptValue &object, JSC::PreferredPrimitiveType hint=JSC::NoPreference)
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ metaMethod()

static QMetaMethod QScript::metaMethod ( const QMetaObject meta,
QMetaMethod::MethodType  type,
int  index 
)
static

Definition at line 513 of file qscriptqobject.cpp.

Referenced by callQtMethod(), and QDeclarativeEngineDebugService::setMethodBody().

516 {
518  return meta->method(index);
519  else
520  return meta->constructor(index);
521 }
int type
Definition: qmetatype.cpp:239
quint16 index
QMetaMethod constructor(int index) const
Returns the meta-data for the constructor with the given index.
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.

◆ methodName()

static QByteArray QScript::methodName ( const char *  signature,
int  nameLength 
)
inlinestatic

Makes a deep copy of the first nameLength characters of the given method signature and returns the copy.

Warning
This function is not part of the public interface.

Definition at line 191 of file qscriptqobject.cpp.

Referenced by QDeclarativePropertyCache::append(), QDeclarativeEngineDebugService::buildObjectDump(), callQtMethod(), QDeclarativePropertyCache::create(), QDeclarativePropertyPrivate::findSignalByName(), QDBusXmlParser::interfaces(), QDeclarativeEngineDebugService::messageReceived(), QDBusInterfacePrivate::metacall(), QDeclarativeObjectMethodScriptClass::relatedMethod(), and QSingleShotTimer::timerEvent().

192 {
193  return QByteArray(signature, nameLength);
194 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ methodNameEquals()

static bool QScript::methodNameEquals ( const QMetaMethod method,
const char *  signature,
int  nameLength 
)
inlinestatic

Returns true if the name of the given method is the same as that specified by the (signature, nameLength) pair, otherwise returns false.

Warning
This function is not part of the public interface.

Definition at line 205 of file qscriptqobject.cpp.

Referenced by callQtMethod(), QScript::QObjectDelegate::getOwnPropertyDescriptor(), QScript::QObjectDelegate::getOwnPropertySlot(), and QScript::QtFunction::overloadedIndexes().

207 {
208  const char *otherSignature = method.signature();
209  return !qstrncmp(otherSignature, signature, nameLength)
210  && (otherSignature[nameLength] == '(');
211 }
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).

◆ methodNameLength()

static int QScript::methodNameLength ( const QMetaMethod method)
inlinestatic

Calculates the length of the name of the given method by looking for the first '(' character.

Warning
This function is not part of the public interface.

Definition at line 175 of file qscriptqobject.cpp.

Referenced by callQtMethod(), and QScript::QtFunction::overloadedIndexes().

176 {
177  const char *signature = method.signature();
178  const char *s = signature;
179  while (*s && (*s != '('))
180  ++s;
181  return s - signature;
182 }
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).

◆ MsFromTime()

static int QScript::MsFromTime ( qsreal  t)
inlinestatic

Definition at line 451 of file qscriptengine.cpp.

Referenced by MsToDateTime().

452 {
453  int r = int(::fmod(t, MsPerSecond));
454  return (r >= 0) ? r : r + int(MsPerSecond);
455 }
static const qsreal MsPerSecond

◆ MsToDateTime()

QDateTime QScript::MsToDateTime ( JSC::ExecState *  exec,
qsreal  t 
)

Converts a JS date value (milliseconds) to a QDateTime (local time).

Warning
This function is not part of the public interface.

Definition at line 464 of file qscriptengine.cpp.

Referenced by QScriptEnginePrivate::toDateTime().

465 {
466  if (qIsNaN(t))
467  return QDateTime();
468  JSC::GregorianDateTime tm;
469  JSC::msToGregorianDateTime(exec, t, /*output UTC=*/true, tm);
470  int ms = MsFromTime(t);
471  QDateTime convertedUTC = QDateTime(QDate(tm.year + 1900, tm.month + 1, tm.monthDay),
472  QTime(tm.hour, tm.minute, tm.second, ms), Qt::UTC);
473  return convertedUTC.toLocalTime();
474 }
The QDate class provides date functions.
Definition: qdatetime.h:55
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QDateTime toLocalTime() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:250
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
static int MsFromTime(qsreal t)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216

◆ qmetaobjectProtoFuncClassName()

static JSC::JSValue JSC_HOST_CALL QScript::qmetaobjectProtoFuncClassName ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisValue,
const JSC::ArgList &   
)
static

Definition at line 2012 of file qscriptqobject.cpp.

Referenced by QScript::QMetaObjectPrototype::QMetaObjectPrototype().

2014 {
2016  thisValue = engine->toUsableValue(thisValue);
2017  if (!thisValue.inherits(&QMetaObjectWrapperObject::info))
2018  return throwError(exec, JSC::TypeError, "this object is not a QMetaObject");
2019  const QMetaObject *meta = static_cast<QMetaObjectWrapperObject*>(JSC::asObject(thisValue))->value();
2020  return JSC::jsString(exec, meta->className());
2021 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
static mach_timebase_info_data_t info
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491

◆ qobjectProtoFuncFindChild()

static JSC::JSValue JSC_HOST_CALL QScript::qobjectProtoFuncFindChild ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisValue,
const JSC::ArgList &  args 
)
static

Definition at line 1665 of file qscriptqobject.cpp.

Referenced by QScript::QObjectPrototype::QObjectPrototype().

1667 {
1669  thisValue = engine->toUsableValue(thisValue);
1670  if (!thisValue.inherits(&QScriptObject::info))
1671  return throwError(exec, JSC::TypeError, "this object is not a QObject");
1672  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(thisValue));
1673  QScriptObjectDelegate *delegate = scriptObject->delegate();
1674  if (!delegate || (delegate->type() != QScriptObjectDelegate::QtObject))
1675  return throwError(exec, JSC::TypeError, "this object is not a QObject");
1676  QObject *obj = static_cast<QObjectDelegate*>(delegate)->value();
1677  QString name;
1678  if (args.size() != 0)
1679  name = args.at(0).toString(exec);
1680  QObject *child = obj->findChild<QObject*>(name);
1681  QScriptEngine::QObjectWrapOptions opt = QScriptEngine::PreferExistingWrapperObject;
1682  return engine->newQObject(child, QScriptEngine::QtOwnership, opt);
1683 }
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
virtual Type type() const =0
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QScriptObjectDelegate * delegate() const
static const JSC::ClassInfo info
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
const char * name
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
JSC::JSValue newQObject(QObject *object, QScriptEngine::ValueOwnership ownership=QScriptEngine::QtOwnership, const QScriptEngine::QObjectWrapOptions &options=0)

◆ qobjectProtoFuncFindChildren()

static JSC::JSValue JSC_HOST_CALL QScript::qobjectProtoFuncFindChildren ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisValue,
const JSC::ArgList &  args 
)
static

Definition at line 1685 of file qscriptqobject.cpp.

Referenced by QScript::QObjectPrototype::QObjectPrototype().

1687 {
1689  thisValue = engine->toUsableValue(thisValue);
1690  // extract the QObject
1691  if (!thisValue.inherits(&QScriptObject::info))
1692  return throwError(exec, JSC::TypeError, "this object is not a QObject");
1693  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(thisValue));
1694  QScriptObjectDelegate *delegate = scriptObject->delegate();
1695  if (!delegate || (delegate->type() != QScriptObjectDelegate::QtObject))
1696  return throwError(exec, JSC::TypeError, "this object is not a QObject");
1697  const QObject *const obj = static_cast<QObjectDelegate*>(delegate)->value();
1698 
1699  // find the children
1700  QList<QObject *> children;
1701  if (args.size() != 0) {
1702  const JSC::JSValue arg = args.at(0);
1703  if (arg.inherits(&JSC::RegExpObject::info)) {
1704  const QObjectList allChildren= obj->children();
1705 
1706  JSC::RegExpObject *const regexp = JSC::asRegExpObject(arg);
1707 
1708  const int allChildrenCount = allChildren.size();
1709  for (int i = 0; i < allChildrenCount; ++i) {
1710  QObject *const child = allChildren.at(i);
1711  const JSC::UString childName = child->objectName();
1712  JSC::RegExpConstructor* regExpConstructor = engine->originalGlobalObject()->regExpConstructor();
1713  int position;
1714  int length;
1715  regExpConstructor->performMatch(regexp->regExp(), childName, 0, position, length);
1716  if (position >= 0)
1717  children.append(child);
1718  }
1719  } else {
1720  const QString name(args.at(0).toString(exec));
1721  children = obj->findChildren<QObject*>(name);
1722  }
1723  } else {
1724  children = obj->findChildren<QObject*>(QString());
1725  }
1726  // create the result array with the children
1727  const int length = children.size();
1728  JSC::JSArray *const result = JSC::constructEmptyArray(exec, length);
1729 
1730  QScriptEngine::QObjectWrapOptions opt = QScriptEngine::PreferExistingWrapperObject;
1731  for (int i = 0; i < length; ++i) {
1732  QObject *const child = children.at(i);
1733  result->put(exec, i, engine->newQObject(child, QScriptEngine::QtOwnership, opt));
1734  }
1735  return JSC::JSValue(result);
1736 }
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
static mach_timebase_info_data_t info
virtual Type type() const =0
QString objectName
the name of this object
Definition: qobject.h:114
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
QScriptObjectDelegate * delegate() const
static const JSC::ClassInfo info
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
JSC::JSGlobalObject * originalGlobalObject() const
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
JSC::JSValue newQObject(QObject *object, QScriptEngine::ValueOwnership ownership=QScriptEngine::QtOwnership, const QScriptEngine::QObjectWrapOptions &options=0)
QList< T > findChildren(const QString &aName=QString()) const
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
Definition: qobject.h:162
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ qobjectProtoFuncToString()

static JSC::JSValue JSC_HOST_CALL QScript::qobjectProtoFuncToString ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisValue,
const JSC::ArgList &   
)
static

Definition at line 1738 of file qscriptqobject.cpp.

Referenced by QScript::QObjectPrototype::QObjectPrototype().

1740 {
1742  thisValue = engine->toUsableValue(thisValue);
1743  if (!thisValue.inherits(&QScriptObject::info))
1744  return JSC::jsUndefined();
1745  QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(thisValue));
1746  QScriptObjectDelegate *delegate = scriptObject->delegate();
1747  if (!delegate || (delegate->type() != QScriptObjectDelegate::QtObject))
1748  return JSC::jsUndefined();
1749  QObject *obj = static_cast<QObjectDelegate*>(delegate)->value();
1750  const QMetaObject *meta = obj ? obj->metaObject() : &QObject::staticMetaObject;
1751  QString name = obj ? obj->objectName() : QString::fromUtf8("unnamed");
1752  QString str = QString::fromUtf8("%0(name = \"%1\")")
1753  .arg(QLatin1String(meta->className())).arg(name);
1754  return JSC::jsString(exec, str);
1755 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
virtual Type type() const =0
QString objectName
the name of this object
Definition: qobject.h:114
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
QScriptObjectDelegate * delegate() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static const JSC::ClassInfo info
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
const char * name
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ scriptableFromQObject()

static QScriptable* QScript::scriptableFromQObject ( QObject qobj)
inlinestatic

Definition at line 267 of file qscriptqobject.cpp.

Referenced by callQtMethod(), and QScript::QtPropertyFunction::execute().

268 {
269  void *ptr = qobj->qt_metacast("QScriptable");
270  return reinterpret_cast<QScriptable*>(ptr);
271 }
The QScriptable class provides access to the Qt Script environment from Qt C++ member functions...
Definition: qscriptable.h:45
const T * ptr(const T &t)

◆ scriptEngineFromExec()

QScriptEnginePrivate * QScript::scriptEngineFromExec ( const JSC::ExecState *  exec)
inline

Definition at line 512 of file qscriptengine_p.h.

Referenced by QScriptContext::activationObject(), QScriptContext::argumentsObject(), QScript::ClassObjectDelegate::call(), QScript::DeclarativeObjectDelegate::call(), QScript::QtFunction::call(), QScript::QMetaObjectWrapperObject::call(), QScriptContext::callee(), callQtMethod(), QScript::ClassObjectDelegate::construct(), QScript::QMetaObjectWrapperObject::construct(), QScriptEnginePrivate::contextForFrame(), QScriptEnginePrivate::convertValue(), QScriptEnginePrivate::create(), QScript::ClassObjectDelegate::deleteProperty(), QScriptContext::engine(), QScript::QtFunction::execute(), QScript::QtPropertyFunction::execute(), QScript::QMetaObjectWrapperObject::execute(), functionConnect(), functionDisconnect(), functionGC(), functionQsTr(), QScript::GlobalObject::getOwnPropertyDescriptor(), QScript::ClassObjectDelegate::getOwnPropertyDescriptor(), QScript::QObjectDelegate::getOwnPropertyDescriptor(), QScript::ClassObjectDelegate::getOwnPropertyNames(), QScript::GlobalObject::getOwnPropertySlot(), QScript::ClassObjectDelegate::getOwnPropertySlot(), QScript::QObjectDelegate::getOwnPropertySlot(), QScript::ClassObjectDelegate::hasInstance(), QScriptContext::isCalledAsConstructor(), QScriptContext::parentContext(), QScriptContext::popScope(), QScript::FunctionWrapper::proxyCall(), QScript::FunctionWithArgWrapper::proxyCall(), QScript::FunctionWrapper::proxyConstruct(), QScript::FunctionWithArgWrapper::proxyConstruct(), QScriptContext::pushScope(), QScript::ClassObjectDelegate::put(), QScript::DeclarativeObjectDelegate::put(), QScript::QObjectDelegate::put(), qmetaobjectProtoFuncClassName(), qobjectProtoFuncFindChild(), qobjectProtoFuncFindChildren(), qobjectProtoFuncToString(), QScriptContextInfoPrivate::QScriptContextInfoPrivate(), QScriptContext::scopeChain(), QScriptDeclarativeClass::scopeChainValue(), QScriptContext::setActivationObject(), QScriptContext::setReturnValue(), QScriptContext::setThisObject(), QScriptContext::thisObject(), QScriptContext::throwError(), QScriptContext::throwValue(), QScriptEnginePrivate::variantListFromArray(), QScriptEnginePrivate::variantMapFromObject(), variantProtoFuncToString(), and variantProtoFuncValueOf().

513 {
514  return static_cast<GlobalClientData*>(exec->globalData().clientData)->engine;
515 }

◆ stringProtoFuncArg()

JSC::JSValue JSC_HOST_CALL QScript::stringProtoFuncArg ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisObject,
const JSC::ArgList &  args 
)
static

Definition at line 941 of file qscriptengine.cpp.

Referenced by functionQsTrIdNoOp(), and QScriptEngine::installTranslatorFunctions().

942 {
943  QString value(thisObject.toString(exec));
944  JSC::JSValue arg = (args.size() != 0) ? args.at(0) : JSC::jsUndefined();
945  QString result;
946  if (arg.isString())
947  result = value.arg(arg.toString(exec));
948  else if (arg.isNumber())
949  result = value.arg(arg.toNumber(exec));
950  return JSC::jsString(exec, result);
951 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186

◆ ToBool() [1/2]

bool QScript::ToBool ( qsreal  value)
inline

Definition at line 552 of file qscriptengine_p.h.

Referenced by QScriptEnginePrivate::convertNumber(), QScriptEnginePrivate::convertString(), QScriptValue::toBool(), and QScriptValue::toBoolean().

553 {
554  return (value != 0) && !qIsNaN(value);
555 }
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55

◆ ToBool() [2/2]

bool QScript::ToBool ( const QString value)
inline

Definition at line 557 of file qscriptengine_p.h.

558 {
559  return !value.isEmpty();
560 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704

◆ toDigit()

static int QScript::toDigit ( char  c)
static

Definition at line 536 of file qscriptengine.cpp.

Referenced by integerFromString().

537 {
538  if ((c >= '0') && (c <= '9'))
539  return c - '0';
540  else if ((c >= 'a') && (c <= 'z'))
541  return 10 + c - 'a';
542  else if ((c >= 'A') && (c <= 'Z'))
543  return 10 + c - 'A';
544  return -1;
545 }
unsigned char c[8]
Definition: qnumeric_p.h:62

◆ ToInt32() [1/2]

qint32 QScript::ToInt32 ( const QString value)
inline

Definition at line 532 of file qscriptengine_p.h.

533 {
534  return ToInt32(ToNumber(value));
535 }
qint32 ToInt32(const QString &)
qsreal ToNumber(const QString &)

◆ ToInt32() [2/2]

qint32 QScript::ToInt32 ( qsreal  n)

Definition at line 368 of file qscriptengine.cpp.

Referenced by QScriptEnginePrivate::convertNumber(), QScriptEnginePrivate::convertString(), and QScriptValue::toInt32().

369 {
370  if (qIsNaN(n) || qIsInf(n) || (n == 0))
371  return 0;
372 
373  qsreal sign = (n < 0) ? -1.0 : 1.0;
374  qsreal abs_n = fabs(n);
375 
376  n = ::fmod(sign * ::floor(abs_n), D32);
377  const double D31 = D32 / 2.0;
378 
379  if (sign == -1 && n < -D31)
380  n += D32;
381 
382  else if (sign != -1 && n >= D31)
383  n -= D32;
384 
385  return qint32 (n);
386 }
int qint32
Definition: qglobal.h:937
static int sign(int x)
static const qsreal D32
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
T floor(const T &a)
double qsreal
Definition: qscriptvalue.h:52
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50

◆ ToInteger() [1/2]

qsreal QScript::ToInteger ( const QString value)
inline

Definition at line 547 of file qscriptengine_p.h.

548 {
549  return ToInteger(ToNumber(value));
550 }
qsreal ToNumber(const QString &)
qsreal ToInteger(const QString &)

◆ ToInteger() [2/2]

qsreal QScript::ToInteger ( qsreal  n)

Definition at line 422 of file qscriptengine.cpp.

Referenced by QScriptEnginePrivate::convertNumber(), QScriptEnginePrivate::convertString(), and QScriptValue::toInteger().

423 {
424  if (qIsNaN(n))
425  return 0;
426 
427  if (n == 0 || qIsInf(n))
428  return n;
429 
430  int sign = n < 0 ? -1 : 1;
431  return sign * ::floor(::fabs(n));
432 }
static int sign(int x)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50

◆ ToNumber()

qsreal QScript::ToNumber ( const QString value)
inline

Definition at line 525 of file qscriptengine_p.h.

Referenced by QScriptEnginePrivate::convertString(), ToInt32(), ToInteger(), QScriptValue::toNumber(), ToUInt16(), and ToUInt32().

526 {
527  return ((JSC::UString)value).toDouble();
528 }

◆ ToPrimitive()

static QScriptValue QScript::ToPrimitive ( const QScriptValue object,
JSC::PreferredPrimitiveType  hint = JSC::NoPreference 
)
static

Definition at line 711 of file qscriptvalue.cpp.

Referenced by Equals(), and LessThan().

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 }
static QScriptValuePrivate * get(const QScriptValue &q)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
JSC::ExecState * currentFrame
static void restoreException(JSC::ExecState *, JSC::JSValue)
static void saveException(JSC::ExecState *, JSC::JSValue *)
JSC::JSValue jscValue
QScriptValue scriptValueFromJSCValue(JSC::JSValue value)
QScriptEnginePrivate * engine

◆ ToString()

QString QScript::ToString ( qsreal  value)
inline

Definition at line 520 of file qscriptengine_p.h.

Referenced by QScriptEnginePrivate::convertNumber(), ToInteger(), and QScriptValue::toString().

521 {
522  return JSC::UString::from(value);
523 }

◆ ToUInt16() [1/2]

quint16 QScript::ToUInt16 ( const QString value)
inline

Definition at line 542 of file qscriptengine_p.h.

543 {
544  return ToUInt16(ToNumber(value));
545 }
quint16 ToUInt16(const QString &)
qsreal ToNumber(const QString &)

◆ ToUInt16() [2/2]

quint16 QScript::ToUInt16 ( qsreal  n)

Definition at line 404 of file qscriptengine.cpp.

Referenced by QScriptEnginePrivate::convertNumber(), QScriptEnginePrivate::convertString(), QScriptEnginePrivate::convertValue(), QScriptValue::toUInt16(), and QScriptEnginePrivate::toUInt16().

405 {
406  static const qsreal D16 = 65536.0;
407 
408  if (qIsNaN(n) || qIsInf(n) || (n == 0))
409  return 0;
410 
411  qsreal sign = (n < 0) ? -1.0 : 1.0;
412  qsreal abs_n = fabs(n);
413 
414  n = ::fmod(sign * ::floor(abs_n), D16);
415 
416  if (n < 0)
417  n += D16;
418 
419  return quint16 (n);
420 }
static int sign(int x)
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
T floor(const T &a)
double qsreal
Definition: qscriptvalue.h:52
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50

◆ ToUInt32() [1/2]

quint32 QScript::ToUInt32 ( const QString value)
inline

Definition at line 537 of file qscriptengine_p.h.

538 {
539  return ToUInt32(ToNumber(value));
540 }
qsreal ToNumber(const QString &)
quint32 ToUInt32(const QString &)

◆ ToUInt32() [2/2]

quint32 QScript::ToUInt32 ( qsreal  n)

Definition at line 388 of file qscriptengine.cpp.

Referenced by QScriptEnginePrivate::convertNumber(), QScriptEnginePrivate::convertString(), and QScriptValue::toUInt32().

389 {
390  if (qIsNaN(n) || qIsInf(n) || (n == 0))
391  return 0;
392 
393  qsreal sign = (n < 0) ? -1.0 : 1.0;
394  qsreal abs_n = fabs(n);
395 
396  n = ::fmod(sign * ::floor(abs_n), D32);
397 
398  if (n < 0)
399  n += D32;
400 
401  return quint32 (n);
402 }
static int sign(int x)
static const qsreal D32
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
T floor(const T &a)
unsigned int quint32
Definition: qglobal.h:938
double qsreal
Definition: qscriptvalue.h:52
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50

◆ type()

static Type QScript::type ( const QScriptValue v)
static

Definition at line 695 of file qscriptvalue.cpp.

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 }
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
bool isBoolean() const
Use isBool() instead.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ variantFromValue()

static QVariant QScript::variantFromValue ( JSC::ExecState *  exec,
int  targetType,
JSC::JSValue  value 
)
static

Definition at line 213 of file qscriptqobject.cpp.

Referenced by QScript::QtPropertyFunction::execute().

214 {
215  QVariant v(targetType, (void *)0);
216  if (QScriptEnginePrivate::convertValue(exec, value, targetType, v.data()))
217  return v;
218  if (uint(targetType) == QVariant::LastType)
219  return QScriptEnginePrivate::toVariant(exec, value);
220  if (QScriptEnginePrivate::isVariant(value)) {
222  if (v.canConvert(QVariant::Type(targetType))) {
223  v.convert(QVariant::Type(targetType));
224  return v;
225  }
226  QByteArray typeName = v.typeName();
227  if (typeName.endsWith('*')
228  && (QMetaType::type(typeName.left(typeName.size()-1)) == targetType)) {
229  return QVariant(targetType, *reinterpret_cast<void* *>(v.data()));
230  }
231  }
232 
233  return QVariant();
234 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QVariant toVariant(JSC::ExecState *, JSC::JSValue)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool isVariant(JSC::JSValue)
const char * typeName
Definition: qmetatype.cpp:239
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
static bool convertValue(JSC::ExecState *, JSC::JSValue value, int type, void *ptr)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
static QVariant & variantValue(JSC::JSValue value)
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ variantProtoFuncToString()

static JSC::JSValue JSC_HOST_CALL QScript::variantProtoFuncToString ( JSC::ExecState *  exec,
JSC::JSObject *  callee,
JSC::JSValue  thisValue,
const JSC::ArgList &  args 
)
static

Definition at line 109 of file qscriptvariant.cpp.

Referenced by QScript::QVariantPrototype::QVariantPrototype().

111 {
113  thisValue = engine->toUsableValue(thisValue);
114  if (!thisValue.inherits(&QScriptObject::info))
115  return throwError(exec, JSC::TypeError, "This object is not a QVariant");
116  QScriptObjectDelegate *delegate = static_cast<QScriptObject*>(JSC::asObject(thisValue))->delegate();
117  if (!delegate || (delegate->type() != QScriptObjectDelegate::Variant))
118  return throwError(exec, JSC::TypeError, "This object is not a QVariant");
119  const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
120  JSC::UString result;
121  JSC::JSValue value = variantProtoFuncValueOf(exec, callee, thisValue, args);
122  if (value.isObject()) {
123  result = v.toString();
124  if (result.isEmpty() && !v.canConvert(QVariant::String))
125  result = QString::fromLatin1("QVariant(%0)").arg(QString::fromLatin1(v.typeName()));
126  } else {
127  result = value.toString(exec);
128  }
129  return JSC::jsString(exec, result);
130 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
virtual Type type() const =0
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static const JSC::ClassInfo info
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
static JSC::JSValue JSC_HOST_CALL variantProtoFuncValueOf(JSC::ExecState *exec, JSC::JSObject *, JSC::JSValue thisValue, const JSC::ArgList &)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ variantProtoFuncValueOf()

static JSC::JSValue JSC_HOST_CALL QScript::variantProtoFuncValueOf ( JSC::ExecState *  exec,
JSC::JSObject *  ,
JSC::JSValue  thisValue,
const JSC::ArgList &   
)
static

Definition at line 71 of file qscriptvariant.cpp.

Referenced by QScript::QVariantPrototype::QVariantPrototype(), and variantProtoFuncToString().

73 {
75  thisValue = engine->toUsableValue(thisValue);
76  if (!thisValue.inherits(&QScriptObject::info))
77  return throwError(exec, JSC::TypeError);
78  QScriptObjectDelegate *delegate = static_cast<QScriptObject*>(JSC::asObject(thisValue))->delegate();
79  if (!delegate || (delegate->type() != QScriptObjectDelegate::Variant))
80  return throwError(exec, JSC::TypeError);
81  const QVariant &v = static_cast<QVariantDelegate*>(delegate)->value();
82  switch (v.type()) {
83  case QVariant::Invalid:
84  return JSC::jsUndefined();
85  case QVariant::String:
86  return JSC::jsString(exec, v.toString());
87 
88  case QVariant::Int:
89  return JSC::jsNumber(exec, v.toInt());
90 
91  case QVariant::Bool:
92  return JSC::jsBoolean(v.toBool());
93 
94  case QVariant::Double:
95  return JSC::jsNumber(exec, v.toDouble());
96 
97 // case QVariant::Char:
98 // return JSC::jsNumber(exec, v.toChar().unicode());
99 
100  case QVariant::UInt:
101  return JSC::jsNumber(exec, v.toUInt());
102 
103  default:
104  ;
105  }
106  return thisValue;
107 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
virtual Type type() const =0
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
static const JSC::ClassInfo info
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
JSC::JSValue toUsableValue(JSC::JSValue value)
If the given value is the original global object, returns the custom global object or a proxy to the ...
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
Definition: qvariant.cpp:2644
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710

Variable Documentation

◆ D32

const qsreal QScript::D32 = 4294967296.0
static

Definition at line 366 of file qscriptengine.cpp.

Referenced by ToInt32(), and ToUInt32().

◆ GeneratePropertyFunctions

const bool QScript::GeneratePropertyFunctions = true
static

Definition at line 236 of file qscriptqobject.cpp.

◆ MsPerSecond

const qsreal QScript::MsPerSecond = 1000.0
static

Definition at line 449 of file qscriptengine.cpp.

◆ qt_meta_data_QObjectConnectionManager

const uint QScript::qt_meta_data_QObjectConnectionManager[]
static
Initial value:
= {
1,
0,
0, 0,
1, 10,
0, 0,
0, 0,
35, 34, 34, 34, 0x0a,
0
}

Definition at line 2031 of file qscriptqobject.cpp.

◆ qt_meta_stringdata_QObjectConnectionManager

const char QScript::qt_meta_stringdata_QObjectConnectionManager[]
static
Initial value:
= {
"QScript::QObjectConnectionManager\0\0execute()\0"
}

Definition at line 2047 of file qscriptqobject.cpp.