summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptvalue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api/qscriptvalue.cpp')
-rw-r--r--src/script/api/qscriptvalue.cpp115
1 files changed, 64 insertions, 51 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp
index 1d08676..d5aaed7 100644
--- a/src/script/api/qscriptvalue.cpp
+++ b/src/script/api/qscriptvalue.cpp
@@ -278,7 +278,7 @@ qsreal ToInteger(qsreal n)
QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const
{
- Q_ASSERT(isJSC());
+ Q_ASSERT(isObject());
JSC::ExecState *exec = engine->currentFrame;
JSC::JSObject *object = jscValue.getObject();
JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object));
@@ -301,7 +301,7 @@ QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolv
QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const
{
- Q_ASSERT(isJSC());
+ Q_ASSERT(isObject());
JSC::ExecState *exec = engine->currentFrame;
JSC::JSObject *object = jscValue.getObject();
JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object));
@@ -393,6 +393,37 @@ void QScriptValuePrivate::setProperty(const JSC::Identifier &id, const QScriptVa
}
}
+QScriptValue::PropertyFlags QScriptValuePrivate::propertyFlags(const JSC::Identifier &id,
+ const QScriptValue::ResolveFlags &mode) const
+{
+ JSC::ExecState *exec = engine->currentFrame;
+ JSC::JSObject *object = JSC::asObject(jscValue);
+ unsigned attribs = 0;
+ if (!object->getPropertyAttributes(exec, id, attribs)) {
+ if ((mode & QScriptValue::ResolvePrototype) && object->prototype() && object->prototype().isObject()) {
+ QScriptValue proto = engine->scriptValueFromJSCValue(object->prototype());
+ return QScriptValuePrivate::get(proto)->propertyFlags(id, mode);
+ }
+ return 0;
+ }
+ QScriptValue::PropertyFlags result = 0;
+ if (attribs & JSC::ReadOnly)
+ result |= QScriptValue::ReadOnly;
+ if (attribs & JSC::DontEnum)
+ result |= QScriptValue::SkipInEnumeration;
+ if (attribs & JSC::DontDelete)
+ result |= QScriptValue::Undeletable;
+ //We cannot rely on attribs JSC::Setter/Getter because they are not necesserly set by JSC (bug?)
+ if (attribs & JSC::Getter || !object->lookupGetter(exec, id).isUndefinedOrNull())
+ result |= QScriptValue::PropertyGetter;
+ if (attribs & JSC::Setter || !object->lookupSetter(exec, id).isUndefinedOrNull())
+ result |= QScriptValue::PropertySetter;
+ if (attribs & QScript::QObjectMemberAttribute)
+ result |= QScriptValue::QObjectMember;
+ result |= QScriptValue::PropertyFlag(attribs & QScriptValue::UserRange);
+ return result;
+}
+
QVariant &QScriptValuePrivate::variantValue() const
{
Q_ASSERT(jscValue.isObject(&QScriptObject::info));
@@ -753,7 +784,7 @@ QScriptValue &QScriptValue::operator=(const QScriptValue &other)
bool QScriptValue::isError() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return false;
return d->jscValue.isObject(&JSC::ErrorInstance::info);
}
@@ -767,7 +798,7 @@ bool QScriptValue::isError() const
bool QScriptValue::isArray() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return false;
return d->jscValue.isObject(&JSC::JSArray::info);
}
@@ -781,7 +812,7 @@ bool QScriptValue::isArray() const
bool QScriptValue::isDate() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return false;
return d->jscValue.isObject(&JSC::DateInstance::info);
}
@@ -795,7 +826,7 @@ bool QScriptValue::isDate() const
bool QScriptValue::isRegExp() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return false;
return d->jscValue.isObject(&JSC::RegExpObject::info);
}
@@ -810,7 +841,7 @@ bool QScriptValue::isRegExp() const
QScriptValue QScriptValue::prototype() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return QScriptValue();
return d->engine->scriptValueFromJSCValue(JSC::asObject(d->jscValue)->prototype());
}
@@ -829,7 +860,7 @@ QScriptValue QScriptValue::prototype() const
void QScriptValue::setPrototype(const QScriptValue &prototype)
{
Q_D(QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return;
if (prototype.isValid() && prototype.engine()
&& (prototype.engine() != engine())) {
@@ -859,7 +890,7 @@ void QScriptValue::setPrototype(const QScriptValue &prototype)
QScriptValue QScriptValue::scope() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return QScriptValue();
// ### make hidden property
return d->property(QLatin1String("__qt_scope__"), QScriptValue::ResolveLocal);
@@ -871,7 +902,7 @@ QScriptValue QScriptValue::scope() const
void QScriptValue::setScope(const QScriptValue &scope)
{
Q_D(QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return;
if (scope.isValid() && scope.engine()
&& (scope.engine() != engine())) {
@@ -903,7 +934,7 @@ void QScriptValue::setScope(const QScriptValue &scope)
bool QScriptValue::instanceOf(const QScriptValue &other) const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject() || !other.isObject())
+ if (!d || !d->isObject() || !other.isObject())
return false;
if (other.engine() != engine()) {
qWarning("QScriptValue::instanceof: "
@@ -1662,7 +1693,7 @@ void QScriptValue::setProperty(const QString &name, const QScriptValue &value,
const PropertyFlags &flags)
{
Q_D(QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return;
JSC::ExecState *exec = d->engine->currentFrame;
d->setProperty(JSC::Identifier(exec, name), value, flags);
@@ -1687,7 +1718,7 @@ QScriptValue QScriptValue::property(const QString &name,
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return QScriptValue();
return d->property(name, mode);
}
@@ -1709,7 +1740,7 @@ QScriptValue QScriptValue::property(quint32 arrayIndex,
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return QScriptValue();
return d->property(arrayIndex, mode);
}
@@ -1730,7 +1761,7 @@ void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue &value,
const PropertyFlags &flags)
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return;
if (value.engine() && (value.engine() != engine())) {
qWarning("QScriptValue::setProperty() failed: "
@@ -1780,7 +1811,7 @@ QScriptValue QScriptValue::property(const QScriptString &name,
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject() || !name.isValid())
+ if (!d || !d->isObject() || !name.isValid())
return QScriptValue();
return d->property(name.d_ptr->identifier, mode);
}
@@ -1803,7 +1834,7 @@ void QScriptValue::setProperty(const QScriptString &name,
const PropertyFlags &flags)
{
Q_D(QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject() || !name.isValid())
+ if (!d || !d->isObject() || !name.isValid())
return;
d->setProperty(name.d_ptr->identifier, value, flags);
}
@@ -1817,9 +1848,11 @@ void QScriptValue::setProperty(const QScriptString &name,
QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QString &name,
const ResolveFlags &mode) const
{
- if (!isObject())
+ Q_D(const QScriptValue);
+ if (!d || !d->isObject())
return 0;
- return propertyFlags(engine()->toStringHandle(name), mode);
+ JSC::ExecState *exec = d->engine->currentFrame;
+ return d->propertyFlags(JSC::Identifier(exec, name), mode);
}
@@ -1835,33 +1868,9 @@ QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QScriptString &nam
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
- if (!isObject())
+ if (!d || !d->isObject() || !name.isValid())
return 0;
- JSC::ExecState *exec = d->engine->currentFrame;
- JSC::JSObject *object = JSC::asObject(d->jscValue);
- JSC::Identifier id = name.d_ptr->identifier;
- unsigned attribs = 0;
- if (!object->getPropertyAttributes(exec, id, attribs)) {
- if ((mode & QScriptValue::ResolvePrototype) && object->prototype())
- return d->engine->scriptValueFromJSCValue(object->prototype()).propertyFlags(name, mode);
- return 0;
- }
- QScriptValue::PropertyFlags result = 0;
- if (attribs & JSC::ReadOnly)
- result |= QScriptValue::ReadOnly;
- if (attribs & JSC::DontEnum)
- result |= QScriptValue::SkipInEnumeration;
- if (attribs & JSC::DontDelete)
- result |= QScriptValue::Undeletable;
- //We cannot rely on attribs JSC::Setter/Getter because they are not necesserly set by JSC (bug?)
- if (attribs & JSC::Getter || !object->lookupGetter(exec, id).isUndefinedOrNull())
- result |= QScriptValue::PropertyGetter;
- if (attribs & JSC::Setter || !object->lookupSetter(exec, id).isUndefinedOrNull())
- result |= QScriptValue::PropertySetter;
- if (attribs & QScript::QObjectMemberAttribute)
- result |= QScriptValue::QObjectMember;
- result |= QScriptValue::PropertyFlag(attribs & QScriptValue::UserRange);
- return result;
+ return d->propertyFlags(name.d_ptr->identifier, mode);
}
/*!
@@ -2263,7 +2272,7 @@ bool QScriptValue::isUndefined() const
bool QScriptValue::isObject() const
{
Q_D(const QScriptValue);
- return d && d->isJSC() && d->jscValue.isObject();
+ return d && d->isObject();
}
/*!
@@ -2310,10 +2319,9 @@ bool QScriptValue::isQObject() const
bool QScriptValue::isQMetaObject() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return false;
return JSC::asObject(d->jscValue)->isObject(&QScript::QMetaObjectWrapperObject::info);
- return false;
}
/*!
@@ -2337,7 +2345,7 @@ bool QScriptValue::isValid() const
QScriptValue QScriptValue::data() const
{
Q_D(const QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return QScriptValue();
if (d->jscValue.isObject(&QScriptObject::info)) {
QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
@@ -2359,7 +2367,7 @@ QScriptValue QScriptValue::data() const
void QScriptValue::setData(const QScriptValue &data)
{
Q_D(QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject())
+ if (!d || !d->isObject())
return;
JSC::JSValue other = d->engine->scriptValueToJSCValue(data);
if (d->jscValue.isObject(&QScriptObject::info)) {
@@ -2413,8 +2421,13 @@ QScriptClass *QScriptValue::scriptClass() const
void QScriptValue::setScriptClass(QScriptClass *scriptClass)
{
Q_D(QScriptValue);
- if (!d || !d->isJSC() || !d->jscValue.isObject(&QScriptObject::info))
+ if (!d || !d->isObject())
+ return;
+ if (!d->jscValue.isObject(&QScriptObject::info)) {
+ qWarning("QScriptValue::setScriptClass() failed: "
+ "cannot change class of non-QScriptObject");
return;
+ }
QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue));
QScriptObjectDelegate *delegate = scriptObject->delegate();
if (!delegate || (delegate->type() != QScriptObjectDelegate::ClassObject)) {