42 #include "private/qdeclarativeobjectscriptclass_p.h" 44 #include "private/qdeclarativeengine_p.h" 45 #include "private/qdeclarativecontext_p.h" 46 #include "private/qdeclarativedata_p.h" 47 #include "private/qdeclarativetypenamescriptclass_p.h" 48 #include "private/qdeclarativelistscriptclass_p.h" 49 #include "private/qdeclarativebinding_p.h" 50 #include "private/qdeclarativeguard_p.h" 51 #include "private/qdeclarativevmemetaobject_p.h" 53 #include <QtCore/qtimer.h> 54 #include <QtCore/qvarlengtharray.h> 55 #include <QtScript/qscriptcontextinfo.h> 60 # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 63 # pragma GCC diagnostic ignored "-Wstrict-aliasing" 81 object->deleteLater();
96 methods(bindEngine), lastData(0), engine(bindEngine)
151 QScriptClass::QueryFlags
153 QScriptClass::QueryFlags flags)
158 QScriptClass::QueryFlags
187 if (!evalContext &&
context()) {
197 if (evalContext && evalContext->
imports) {
206 if (!(hints & ImplicitObject)) {
275 void *args[] = { &rv, 0 };
280 void *args[] = { &rv, 0 };
282 return Value(scriptEngine, rv);
285 void *args[] = { &rv, 0 };
287 return Value(scriptEngine, rv);
290 void *args[] = { &rv, 0 };
292 return Value(scriptEngine, rv);
295 void *args[] = { &rv, 0 };
297 return Value(scriptEngine, rv);
300 void *args[] = { &rv, 0 };
302 return Value(scriptEngine, rv);
305 void *args[] = { &rv, 0 };
307 return Value(scriptEngine, rv);
310 void *args[] = { &rv, 0 };
312 return Value(scriptEngine, rv);
315 void *args[] = { &rv, 0 };
317 return Value(scriptEngine, rv);
332 int qRoundDouble(
double d)
334 return d >= double(0.0) ? int(d +
double(0.5)) : int(d -
int(d-1) +
double(0.5)) + int(d-1);
397 void *argv[] = { &o, 0, &
status, &flags };
413 int rawValue = qRoundDouble(value.
toNumber());
416 void *
a[] = { (
void *)&rawValue, 0, &status, &flags };
424 void *
a[] = { (
void *)&rawValue, 0, &status, &flags };
432 void *
a[] = { (
void *)&rawValue, 0, &status, &flags };
445 const char *valueType = 0;
537 cache = enginePrivate->
cache(obj);
548 for (
int i=po; i<pc; ++i)
575 qRegisterMetaType<QList<QObject *> >(
"QList<QObject *>");
648 QScriptClass::QueryFlags
650 QScriptClass::QueryFlags flags)
674 struct MetaCallArgument {
675 inline MetaCallArgument();
676 inline ~MetaCallArgument();
677 inline void *dataPtr();
684 MetaCallArgument(
const MetaCallArgument &);
710 MetaCallArgument::MetaCallArgument()
715 MetaCallArgument::~MetaCallArgument()
723 qstringPtr->~QString();
725 qvariantPtr->~QVariant();
726 }
else if (
type == qMetaTypeId<QScriptValue>()) {
727 qscriptValuePtr->~QScriptValue();
733 void *MetaCallArgument::dataPtr()
736 return qvariantPtr->data();
738 return (
void *)&allocData;
744 if (callType == 0)
return;
748 if (callType == qMetaTypeId<QScriptValue>()) {
761 qstringPtr =
new (&allocData)
QString();
763 }
else if (callType == qMetaTypeId<QVariant>()) {
765 qvariantPtr =
new (&allocData)
QVariant();
771 qvariantPtr =
new (&allocData)
QVariant(callType, (
void *)0);
779 if (callType == qMetaTypeId<QScriptValue>()) {
781 type = qMetaTypeId<QScriptValue>();
789 boolValue = value.
toBool();
792 doubleValue = double(value.
toNumber());
795 floatValue = float(value.
toNumber());
799 qstringPtr =
new (&allocData)
QString();
806 }
else if (callType == qMetaTypeId<QVariant>()) {
808 qvariantPtr =
new (&allocData)
QVariant(other);
814 for (
int ii = 0; ii < length; ++ii) {
824 qvariantPtr =
new (&allocData)
QVariant();
839 while (objMo && objMo != mo) objMo = objMo->
superClass();
843 *qvariantPtr =
QVariant(callType, &obj);
845 *qvariantPtr =
QVariant(callType, (
void *)0);
854 if (
type == qMetaTypeId<QScriptValue>()) {
877 for (
int ii = 0; ii < list.
count(); ++ii) {
883 }
else if (
type == -1 ||
type == qMetaTypeId<QVariant>()) {
903 if (scopeIdx != -1) {
904 scope = str.
left(scopeIdx);
905 name = str.
mid(scopeIdx + 2);
938 for (
int ii = 0; ii < argTypeNames.
count(); ++ii) {
960 int returnType,
int argCount,
int *argTypes,
966 args[0].initAsType(returnType, engine);
968 for (
int ii = 0; ii < argCount; ++ii)
972 for (
int ii = 0; ii < args.
count(); ++ii)
973 argData[ii] = args[ii].dataPtr();
977 return args[0].toValue(engine);
979 }
else if (returnType != 0) {
981 MetaCallArgument arg;
982 arg.initAsType(returnType, engine);
984 void *args[] = { arg.dataPtr() };
988 return arg.toValue(engine);
992 void *args[] = { 0 };
1018 int bestParameterScore =
INT_MAX;
1030 int methodArgumentCount = methodArgTypeNames.
count();
1032 if (methodArgumentCount > argumentCount)
1035 int methodParameterScore = argumentCount - methodArgumentCount;
1036 if (methodParameterScore > bestParameterScore)
1039 int methodMatchScore = 0;
1042 bool unknownArgument =
false;
1043 for (
int ii = 0; ii < methodArgumentCount; ++ii) {
1049 unknownArgument =
true;
1052 methodMatchScore +=
matchScore(ctxt->
argument(ii), methodArgTypes[ii], methodArgTypeNames.
at(ii));
1054 if (unknownArgument)
1057 if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) {
1059 bestParameterScore = methodParameterScore;
1060 bestMatchScore = methodMatchScore;
1063 if (bestParameterScore == 0 && bestMatchScore == 0)
1091 switch (conversionType) {
1116 switch (conversionType) {
1123 switch (conversionType) {
1129 }
else if (actual.
isDate()) {
1130 switch (conversionType) {
1141 switch (conversionType) {
1148 if (conversionType == qMetaTypeId<QVariant>())
1154 }
else if (actual.
isArray()) {
1155 switch (conversionType) {
1163 switch (conversionType) {
1169 }
else if (actual.
isNull()) {
1170 switch (conversionType) {
1175 if (!conversionTypeName.
endsWith(
'*'))
1191 int classInfoCount, classInfoData;
1192 int methodCount, methodData;
1195 return reinterpret_cast<const Private *
>(metaObject->
d.
data)->methodCount;
1205 return sig.
left(paren);
1235 for (
int ii = current->
relatedIndex - 1; ii >= methodOffset; --ii) {
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
The QScriptContext class represents a Qt Script function invocation.
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
QDeclarativeTypeNameScriptClass * typeNameClass
QDeclarativePropertyCache * propertyCache
Value callPrecise(QObject *, const QDeclarativePropertyCache::Data &, QScriptContext *)
bool isNull() const
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false...
static QDeclarativeData * get(const QObject *object, bool create=false)
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue's property with the given name, using the given mode to resolv...
PersistentIdentifier m_disconnectId
~QDeclarativeObjectScriptClass()
static QScriptValue destroy(QScriptContext *context, QScriptEngine *engine)
QIntegerForSizeof< void * >::Unsigned quintptr
#define QT_END_NAMESPACE
This macro expands to.
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
void setImplicitDestructible()
Q_SCRIPT_EXPORT bool qScriptDisconnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
QByteArray & append(char c)
Appends the character ch to this byte array.
static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *)
QScriptClass::QueryFlags queryProperty(QObject *, const Identifier &, QScriptClass::QueryFlags flags, QDeclarativeContextData *evalContext, QueryHints hints=0)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
QString objectName
the name of this object
The QByteArray class provides an array of bytes.
QObject * toQObject(const QScriptValue &) const
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
QDeclarativePropertyCache * cache(QObject *obj)
Returns a QDeclarativePropertyCache for obj if one is available.
void setTarget(const QDeclarativeProperty &)
virtual void destroy(DestroyMode mode=DisconnectBinding)
Destroy the binding.
QDeclarativeGuard< QObject > object
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QDeclarativePropertyCache::Data data
int matchScore(const QScriptValue &, int, const QByteArray &)
Returns the match score for converting actual to be of type conversionType.
Value callMethod(QObject *, int index, int returnType, int argCount, int *argTypes, QScriptContext *ctxt)
static LibLoadStatus status
bool isBoolean() const
Use isBool() instead.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static Object * object(const QScriptValue &)
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
QDeclarativeContextData * contextFromValue(const QScriptValue &)
The QString class provides a Unicode character string.
QScriptValue m_disconnect
static QScriptValue tostring(QScriptContext *context, QScriptEngine *engine)
The QObject class is the base class of all Qt objects.
int enumType(const QMetaObject *, const QString &)
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QObjectPrivate * get(QObject *o)
Value callOverloaded(MethodData *, QScriptContext *)
Resolve the overloaded method to call.
~QDeclarativeObjectMethodScriptClass()
PersistentIdentifier createPersistentIdentifier(const QString &)
The QScriptDeclarativeClass::Value class acts as a container for JavaScript data types.
QDeclarativeTypeNameCache * imports
virtual bool isQObject() const
QScriptValue newQObject(QObject *, int type=QMetaType::QObjectStar)
QVariant scriptValueToVariant(const QScriptValue &, int hint=QVariant::Invalid)
QString fileName() const
Returns the name of the file where the code being executed was defined, if available; otherwise retur...
ObjectData(QObject *o, int t)
QDeclarativePropertyCache::Data local
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
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.
bool canConvert(Type t) const
Returns true if the variant's type can be cast to the requested type, t.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
virtual QStringList propertyNames(Object *)
QScriptValue newObject(QObject *, QDeclarativeType *, TypeNameMode=IncludeEnums)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
QDeclarativePropertyCache::Data * lastData
PersistentIdentifier m_toStringId
QScriptEngine * engine() const
const T & at(int i) const
Returns the item at index position i in the list.
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
The QStringList class provides a list of strings.
Data * property(const QScriptDeclarativeClass::Identifier &id) const
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
QScriptValue scriptValueFromVariant(const QVariant &)
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
PersistentIdentifier m_destroyId
QDeclarativeGuard< QObject > object
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Type
This enum type defines the types of variable that a QVariant can contain.
quint32 objectDataRefCount
virtual Value call(Object *, QScriptContext *)
void load(const QMetaProperty &, QDeclarativeEngine *engine=0)
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
QStringList propertyNames() const
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
QDeclarativeValueTypeScriptClass * valueTypeClass
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
static QDeclarativeAbstractBinding * setBinding(QObject *, int coreIndex, int valueTypeIndex, QDeclarativeAbstractBinding *, WriteFlags flags=DontRemoveBinding)
void setEvaluateFlags(EvaluateFlags flags)
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int functionStartLineNumber() const
Returns the line number where the definition of the called function starts, or -1 if the line number ...
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QDeclarativeObjectMethodScriptClass methods
QDeclarativeObjectMethodScriptClass(QDeclarativeEngine *)
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
QScriptValue newObject(QObject *object, int coreIndex, QDeclarativeValueType *)
bool convert(Type t)
Casts the variant to the requested type, t.
QDeclarativeObjectScriptClass * objectClass
const char * constData() const
Returns a pointer to the data stored in the byte array.
static QScriptValue connect(QScriptContext *context, QScriptEngine *engine)
static QByteArray QMetaMethod_name(const QMetaMethod &m)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue's property with the given name to the given value.
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
The QScriptContextInfo class provides additional information about a QScriptContext.
void setSupportsCall(bool)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
int userType() const
Returns the storage type of the value stored in the variant.
QDeclarativeTypeNameCache::Data * lastTNData
virtual bool compare(Object *, Object *)
static bool isValueType(int)
bool isAllowedInRevision(Data *) const
The QDeclarativeEngine class provides an environment for instantiating QML components.
int objectType(const QScriptValue &) const
QDeclarativeListScriptClass * listClass
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
QDeclarativeValueTypeFactory valueTypes
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Q_SCRIPT_EXPORT bool qScriptConnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
virtual Value property(Object *, const Identifier &)
QObject * parent() const
Returns a pointer to the parent object.
virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags)
static QDeclarativeProperty restore(const QByteArray &, QObject *, QDeclarativeContextData *)
bool singleShot
This static function calls a slot after a given time interval.
MethodData(QObject *o, const QDeclarativePropertyCache::Data &d)
virtual QString expression() const
QScriptContext * currentContext() const
Returns the current context.
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...
static JSAgentWatchData fromScriptValue(const QString &expression, const QScriptValue &value)
static QScriptValue scopeChainValue(QScriptContext *, int index)
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
QDeclarativeTypeNameCache * typeNamespace
void setSourceLocation(const QString &fileName, int line)
Set the location of this expression to line of url.
QDeclarativePropertyCache::Data * relatedMethod(QObject *, QDeclarativePropertyCache::Data *current, QDeclarativePropertyCache::Data &dummy)
Returns the next related method, if one, or 0.
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
QObject * toQObject(const QVariant &, bool *ok=0) const
QDeclarativeObjectScriptClass(QDeclarativeEngine *)
static QScriptDeclarativeClass * scriptClass(const QScriptValue &)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
static QScriptValue disconnect(QScriptContext *context, QScriptEngine *engine)
PersistentIdentifier m_connectId
void setProperty(QObject *, const Identifier &name, const QScriptValue &, QScriptContext *context, QDeclarativeContextData *evalContext=0)
Data * data(const QString &) const
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QScriptValue newList(QObject *, int, int)
QScriptValue * scriptValue
QScriptValue thisObject() const
Returns the `this' object associated with this QScriptContext.
QScriptContext * context() const
The QScriptValue class acts as a container for the Qt Script data types.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
const QMetaObject * rawMetaObjectForType(int) const
QString toString(const Identifier &)
void deleteLater()
Schedules this object for deletion.
QScriptValue argument(int index) const
Returns the function argument at the given index.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
Value property(QObject *, const Identifier &)
QPODVector< CapturedProperty, 16 > capturedProperties
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
EvaluateFlags evaluateFlags() const
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
QScriptValue newMethod(QObject *, const QDeclarativePropertyCache::Data *)
The QList class is a template class that provides lists.
static int QMetaObject_methods(const QMetaObject *metaObject)
QDeclarativeContextScriptClass * contextClass
static bool write(QObject *, const QDeclarativePropertyCache::Data &, const QVariant &, QDeclarativeContextData *, WriteFlags flags=0)