32 #include "JSGlobalObject.h" 33 #include "JSImmediate.h" 36 #include "JSFunction.h" 37 #include "Identifier.h" 38 #include "Operations.h" 39 #include "Arguments.h" 41 #include <QtCore/qvariant.h> 42 #include <QtCore/qvarlengtharray.h> 43 #include <QtCore/qnumeric.h> 342 #ifndef QT_NO_CAST_FROM_ASCII 470 #ifndef QT_NO_CAST_FROM_ASCII 500 if (!
d || !
d->isJSC())
514 if (!
d || !
d->isJSC())
528 if (!
d || !
d->isJSC())
542 if (!
d || !
d->isJSC())
557 if (!
d || !
d->isObject())
559 return d->engine->scriptValueFromJSCValue(JSC::asObject(
d->jscValue)->prototype());
576 if (!
d || !
d->isObject())
579 JSC::JSValue other =
d->engine->scriptValueToJSCValue(prototype);
580 if (!other || !(other.isObject() || other.isNull()))
585 qWarning(
"QScriptValue::setPrototype() failed: " 586 "cannot set a prototype created in " 587 "a different engine");
590 JSC::JSObject *thisObject = JSC::asObject(
d->jscValue);
593 JSC::JSValue nextPrototypeValue = other;
594 while (nextPrototypeValue && nextPrototypeValue.isObject()) {
595 JSC::JSObject *nextPrototype = JSC::asObject(nextPrototypeValue);
596 if (nextPrototype == thisObject) {
597 qWarning(
"QScriptValue::setPrototype() failed: cyclic prototype value");
600 nextPrototypeValue = nextPrototype->prototype();
603 thisObject->setPrototype(other);
606 if (((thisObject ==
d->engine->originalGlobalObjectProxy)
607 && !
d->engine->customGlobalObject())
608 || (thisObject ==
d->engine->customGlobalObject())) {
609 d->engine->originalGlobalObject()->setPrototype(other);
619 if (!
d || !
d->isObject())
624 return d->engine->scriptValueFromJSCValue(result);
633 if (!
d || !
d->isObject())
637 qWarning(
"QScriptValue::setScope() failed: " 638 "cannot set a scope object created in " 639 "a different engine");
642 JSC::JSValue other =
d->engine->scriptValueToJSCValue(scope);
643 JSC::ExecState *exec =
d->engine->currentFrame;
644 JSC::Identifier
id = JSC::Identifier(exec,
"__qt_scope__");
646 JSC::asObject(
d->jscValue)->removeDirect(
id);
649 JSC::asObject(
d->jscValue)->putDirect(
id, other);
665 if (!
d || !
d->isObject() || !other.
isObject())
668 qWarning(
"QScriptValue::instanceof: " 669 "cannot perform operation on a value created in " 670 "a different engine");
675 jscProto = JSC::jsUndefined();
676 JSC::ExecState *exec =
d->engine->currentFrame;
677 JSC::JSValue jscOther =
d->engine->scriptValueToJSCValue(other);
678 return JSC::asObject(jscOther)->hasInstance(exec,
d->jscValue, jscProto);
718 JSC::JSValue savedException;
720 JSC::JSValue result = JSC::asObject(pp->
jscValue)->toPrimitive(exec, hint);
784 #ifndef QT_NO_QOBJECT 852 "cannot compare to a value created in " 853 "a different engine");
891 "cannot compare to a value created in " 892 "a different engine");
902 JSC::JSValue savedException;
941 qWarning(
"QScriptValue::strictlyEquals: " 942 "cannot compare to a value created in " 943 "a different engine");
964 return JSC::JSValue::strictEqual(exec,
d->jscValue, other.
d_ptr->
jscValue);
1002 return d->stringValue;
1034 return d->numberValue;
1301 if (!
d || !
d->engine)
1316 if (!
d || !
d->engine)
1322 #ifndef QT_NO_REGEXP 1333 if (!
d || !
d->engine)
1338 #endif // QT_NO_REGEXP 1353 if (!
d || !
d->engine)
1368 if (!
d || !
d->engine)
1403 if (!
d || !
d->isObject())
1407 if (valueEngine && (valueEngine !=
d->engine)) {
1408 qWarning(
"QScriptValue::setProperty(%s) failed: " 1409 "cannot set value created in a different engine",
1413 JSC::JSValue jsValue =
d->engine->scriptValueToJSCValue(value);
1414 d->setProperty(name, jsValue, flags);
1433 const ResolveFlags &mode)
const 1436 if (!
d || !
d->isObject())
1439 return d->engine->scriptValueFromJSCValue(
d->property(name, mode));
1459 const ResolveFlags &mode)
const 1462 if (!
d || !
d->isObject())
1465 return d->engine->scriptValueFromJSCValue(
d->property(arrayIndex, mode));
1487 if (!
d || !
d->isObject())
1491 qWarning(
"QScriptValue::setProperty() failed: " 1492 "cannot set value created in a different engine");
1496 JSC::JSValue jsValue =
d->engine->scriptValueToJSCValue(value);
1497 d->setProperty(arrayIndex, jsValue, flags);
1516 const ResolveFlags &mode)
const 1522 return d->engine->scriptValueFromJSCValue(
d->property(name.
d_ptr->
identifier, mode));
1549 if (valueEngine && (valueEngine !=
d->engine)) {
1550 qWarning(
"QScriptValue::setProperty(%s) failed: " 1551 "cannot set value created in a different engine",
1556 JSC::JSValue jsValue =
d->engine->scriptValueToJSCValue(value);
1567 const ResolveFlags &mode)
const 1570 if (!
d || !
d->isObject())
1573 JSC::ExecState *exec =
d->engine->currentFrame;
1574 return d->propertyFlags(JSC::Identifier(exec, name), mode);
1590 const ResolveFlags &mode)
const 1625 if (!
d || !
d->isObject())
1628 JSC::JSValue callee =
d->jscValue;
1629 JSC::CallData callData;
1630 JSC::CallType callType = callee.getCallData(callData);
1631 if (callType == JSC::CallTypeNone)
1636 qWarning(
"QScriptValue::call() failed: " 1637 "cannot call function with thisObject created in " 1638 "a different engine");
1642 JSC::ExecState *exec =
d->engine->currentFrame;
1644 JSC::JSValue jscThisObject =
d->engine->scriptValueToJSCValue(thisObject);
1645 if (!jscThisObject || !jscThisObject.isObject())
1646 jscThisObject =
d->engine->globalObject();
1649 for (
int i = 0; i < args.
size(); ++i) {
1652 argsVector[i] = JSC::jsUndefined();
1655 qWarning(
"QScriptValue::call() failed: " 1656 "cannot call function with argument created in " 1657 "a different engine");
1660 argsVector[i] =
d->engine->scriptValueToJSCValue(arg);
1663 JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
1665 JSC::JSValue savedException;
1667 JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, jscArgs);
1668 if (exec->hadException()) {
1669 result = exec->exception();
1673 return d->engine->scriptValueFromJSCValue(result);
1703 if (!
d || !
d->isObject())
1706 JSC::JSValue callee =
d->jscValue;
1707 JSC::CallData callData;
1708 JSC::CallType callType = callee.getCallData(callData);
1709 if (callType == JSC::CallTypeNone)
1714 qWarning(
"QScriptValue::call() failed: " 1715 "cannot call function with thisObject created in " 1716 "a different engine");
1720 JSC::ExecState *exec =
d->engine->currentFrame;
1722 JSC::JSValue jscThisObject =
d->engine->scriptValueToJSCValue(thisObject);
1723 if (!jscThisObject || !jscThisObject.isObject())
1724 jscThisObject =
d->engine->globalObject();
1726 JSC::JSValue array =
d->engine->scriptValueToJSCValue(arguments);
1728 JSC::MarkedArgumentBuffer applyArgs;
1729 if (!array.isUndefinedOrNull()) {
1730 if (!array.isObject()) {
1731 return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError,
"Arguments must be an array"));
1734 JSC::asArguments(array)->fillArgList(exec, applyArgs);
1735 else if (JSC::isJSArray(&exec->globalData(), array))
1736 JSC::asArray(array)->fillArgList(exec, applyArgs);
1738 unsigned length = JSC::asArray(array)->get(exec, exec->propertyNames().length).
toUInt32(exec);
1739 for (
unsigned i = 0; i < length; ++i)
1740 applyArgs.append(JSC::asArray(array)->get(exec, i));
1742 return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError,
"Arguments must be an array"));
1746 JSC::JSValue savedException;
1748 JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, applyArgs);
1749 if (exec->hadException()) {
1750 result = exec->exception();
1754 return d->engine->scriptValueFromJSCValue(result);
1778 if (!
d || !
d->isObject())
1781 JSC::JSValue callee =
d->jscValue;
1782 JSC::ConstructData constructData;
1783 JSC::ConstructType constructType = callee.getConstructData(constructData);
1784 if (constructType == JSC::ConstructTypeNone)
1787 JSC::ExecState *exec =
d->engine->currentFrame;
1790 for (
int i = 0; i < args.
size(); ++i) {
1793 qWarning(
"QScriptValue::construct() failed: " 1794 "cannot construct function with argument created in " 1795 "a different engine");
1799 argsVector[i] = JSC::jsUndefined();
1801 argsVector[i] =
d->engine->scriptValueToJSCValue(args.
at(i));
1804 JSC::ArgList jscArgs(argsVector.data(), argsVector.size());
1806 JSC::JSValue savedException;
1808 JSC::JSValue result;
1809 JSC::JSObject *newObject =
JSC::construct(exec, callee, constructType, constructData, jscArgs);
1810 if (exec->hadException()) {
1811 result = exec->exception();
1816 return d->engine->scriptValueFromJSCValue(result);
1837 if (!
d || !
d->isObject())
1840 JSC::JSValue callee =
d->jscValue;
1841 JSC::ConstructData constructData;
1842 JSC::ConstructType constructType = callee.getConstructData(constructData);
1843 if (constructType == JSC::ConstructTypeNone)
1846 JSC::ExecState *exec =
d->engine->currentFrame;
1849 qWarning(
"QScriptValue::construct() failed: " 1850 "cannot construct function with argument created in " 1851 "a different engine");
1854 JSC::JSValue array =
d->engine->scriptValueToJSCValue(arguments);
1856 JSC::MarkedArgumentBuffer applyArgs;
1857 if (!array.isUndefinedOrNull()) {
1858 if (!array.isObject()) {
1859 return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError,
"Arguments must be an array"));
1862 JSC::asArguments(array)->fillArgList(exec, applyArgs);
1863 else if (JSC::isJSArray(&exec->globalData(), array))
1864 JSC::asArray(array)->fillArgList(exec, applyArgs);
1866 unsigned length = JSC::asArray(array)->get(exec, exec->propertyNames().length).
toUInt32(exec);
1867 for (
unsigned i = 0; i < length; ++i)
1868 applyArgs.append(JSC::asArray(array)->get(exec, i));
1870 return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError,
"Arguments must be an array"));
1874 JSC::JSValue savedException;
1876 JSC::JSValue result;
1877 JSC::JSObject *newObject =
JSC::construct(exec, callee, constructType, constructData, applyArgs);
1878 if (exec->hadException()) {
1879 result = exec->exception();
1884 return d->engine->scriptValueFromJSCValue(result);
1911 return d &&
d->isJSC() &&
d->jscValue.isBoolean();
1928 return d &&
d->isJSC() &&
d->jscValue.isBoolean();
1944 return d->jscValue.isNumber();
1966 return d->jscValue.isString();
1984 if (!
d || !
d->isJSC())
1998 return d &&
d->isJSC() &&
d->jscValue.isNull();
2010 return d &&
d->isJSC() &&
d->jscValue.isUndefined();
2025 return d &&
d->isObject();
2037 if (!
d || !
d->isJSC())
2054 if (!
d || !
d->isJSC())
2068 if (!
d || !
d->isJSC())
2080 return d && (!
d->isJSC() || !!
d->jscValue);
2097 if (!
d || !
d->isObject())
2101 return d->engine->scriptValueFromJSCValue(scriptObject->
data());
2124 if (!
d || !
d->isObject())
2127 JSC::JSValue other =
d->engine->scriptValueToJSCValue(data);
2132 JSC::ExecState *exec =
d->engine->currentFrame;
2133 JSC::Identifier
id = JSC::Identifier(exec,
"__qt_data__");
2135 JSC::asObject(
d->jscValue)->removeDirect(
id);
2138 JSC::asObject(
d->jscValue)->putDirect(
id, other);
2185 if (!
d || !
d->isObject())
2188 qWarning(
"QScriptValue::setScriptClass() failed: " 2189 "cannot change class of non-QScriptObject");
The QVariant class acts like a union for the most common Qt data types.
static bool isQMetaObject(JSC::JSValue)
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
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...
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...
QScriptValue & operator=(const QScriptValue &other)
Assigns the other value to this QScriptValue.
static mach_timebase_info_data_t info
virtual Type type() const =0
#define QT_END_NAMESPACE
This macro expands to.
static const QMetaObject * toQMetaObject(JSC::ExecState *, JSC::JSValue)
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
The QRegExp class provides pattern matching using regular expressions.
QScriptValue scope() const
QDateTime toDateTime() const
Returns a QDateTime representation of this value, in local time.
qsreal ToInteger(qsreal n)
bool equals(const QScriptValue &other) const
Returns true if this QScriptValue is equal to other, otherwise returns false.
static QScriptEnginePrivate * get(QScriptEngine *q)
static QVariant toVariant(JSC::ExecState *, JSC::JSValue)
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
static bool LessThan(QScriptValue lhs, QScriptValue rhs)
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
static QRegExp toRegExp(JSC::ExecState *, JSC::JSValue)
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
quint32 ToUInt32(qsreal n)
static QScriptValuePrivate * get(const QScriptValue &q)
static QObject * toQObject(JSC::ExecState *, JSC::JSValue)
QScriptObjectDelegate * delegate() const
bool isBoolean() const
Use isBool() instead.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static quint16 toUInt16(JSC::ExecState *, JSC::JSValue)
bool isQMetaObject() const
Returns true if this QScriptValue is a QMetaObject; otherwise returns false.
bool instanceOf(const QScriptValue &other) const
Returns true if this QScriptValue is an instance of other; otherwise returns false.
static qsreal toNumber(JSC::ExecState *, JSC::JSValue)
static const JSC::ClassInfo info
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QString class provides a Unicode character string.
The QObject class is the base class of all Qt objects.
~QScriptValue()
Destroys this QScriptValue.
static bool IsNumerical(const QScriptValue &value)
JSC::ExecState * currentFrame
QScriptValue construct(const QScriptValueList &args=QScriptValueList())
Creates a new Object and calls this QScriptValue as a constructor, using the created object as the `t...
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
SpecialValue
This enum is used to specify a single-valued type.
qint64 objectId() const
Returns the ID of this object, or -1 if this QScriptValue is not an object.
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptValue::PropertyFlags propertyFlags(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the flags of the property with the given name, using the given mode to resolve the property...
static bool isVariant(JSC::JSValue)
static qint32 toInt32(JSC::ExecState *, JSC::JSValue)
#define QT_BEGIN_NAMESPACE
This macro expands to.
QScriptClass * scriptClass() const
Returns the custom script class that this script object is an instance of, or 0 if the object is not ...
JSC::JSValue data() const
JSC::JSValue scriptValueToJSCValue(const QScriptValue &value)
static QScriptEnginePrivate * getEngine(const QScriptValue &q)
void setData(JSC::JSValue data)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
static JSC::UString toString(JSC::ExecState *, JSC::JSValue)
const T & at(int i) const
Returns the item at index position i in the list.
QScriptValue()
Constructs an invalid QScriptValue.
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
static QDateTime toDateTime(JSC::ExecState *, JSC::JSValue)
Q_CORE_EXPORT void qWarning(const char *,...)
bool isFunction(JSC::JSValue value)
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
static void restoreException(JSC::ExecState *, JSC::JSValue)
static qsreal toInteger(JSC::ExecState *, JSC::JSValue)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
void setScriptClass(QScriptClass *scriptClass)
Sets the custom script class of this script object to scriptClass.
const QMetaObject * toQMetaObject() const
If this QScriptValue is a QMetaObject, returns the QMetaObject pointer that the QScriptValue represen...
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
qsreal toInteger() const
Returns the integer value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
JSC::Identifier identifier
bool toBoolean() const
Use toBool() instead.
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
QScriptValue toObject() const
This function is obsolete; use QScriptEngine::toObject() instead.
static bool isDate(JSC::JSValue)
QExplicitlySharedDataPointer< QScriptStringPrivate > d_ptr
QScriptValue data() const
Returns the internal data of this QScriptValue object.
qsreal ToNumber(const QString &)
static bool isRegExp(JSC::JSValue)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue's property with the given name to the given value.
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
static bool isValid(const QScriptString &q)
void setScope(const QScriptValue &scope)
The QDateTime class provides date and time functions.
static void saveException(JSC::ExecState *, JSC::JSValue *)
void setPrototype(const QScriptValue &prototype)
If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to...
static void construct(QVariant::Private *x, const void *copy)
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
static bool isQObject(JSC::JSValue)
static quint32 toUInt32(JSC::ExecState *, JSC::JSValue)
static bool isError(JSC::JSValue)
int size() const
Returns the number of items in the list.
static QScriptValue ToPrimitive(const QScriptValue &object, JSC::PreferredPrimitiveType hint=JSC::NoPreference)
void initFrom(JSC::JSValue value)
static bool Equals(QScriptValue lhs, QScriptValue rhs)
QRegExp toRegExp() const
Returns the QRegExp representation of this value.
static const char * get(QDBusError::ErrorType code)
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
bool lessThan(const QScriptValue &other) const
Returns true if this QScriptValue is less than other, otherwise returns false.
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
void setDelegate(QScriptObjectDelegate *delegate)
quint16 ToUInt16(qsreal n)
QScriptValue scriptValueFromJSCValue(JSC::JSValue value)
quint16 toUInt16() const
Returns the unsigned 16-bit integer value of this QScriptValue, using the conversion rules described ...
static bool toBool(JSC::ExecState *, JSC::JSValue)
bool strictlyEquals(const QScriptValue &other) const
Returns true if this QScriptValue is equal to other using strict comparison (no conversion), otherwise returns false.
static bool isArray(JSC::JSValue)
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QString toString() const
Returns the string that this QScriptString represents, or a null string if this QScriptString is not ...
#define qPrintable(string)
The QScriptValue class acts as a container for the Qt Script data types.
QScriptValue toObject(const QScriptValue &value)
Converts the given value to an object, if such a conversion is possible; otherwise returns an invalid...
QScriptEnginePrivate * engine
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this' object in the function call...
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
static bool equal(const QChar *a, int l, const char *b)
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.
QScriptValue prototype() const
If this QScriptValue is an object, returns the internal prototype (__proto__ property) of this object...