diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-02-04 04:56:50 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-02-04 04:56:50 (GMT) |
commit | 7fec7ff568659c3816ce26d2d82d59dd372f1166 (patch) | |
tree | c2546e401f13ba5c55e3311744d83fa68e46f165 /src/script | |
parent | 5783f98ce5e243afbbd4c6a68c80d2dd959520e0 (diff) | |
parent | f7dfce110c96ef33200abf2dd93b86d3853095e5 (diff) | |
download | Qt-7fec7ff568659c3816ce26d2d82d59dd372f1166.zip Qt-7fec7ff568659c3816ce26d2d82d59dd372f1166.tar.gz Qt-7fec7ff568659c3816ce26d2d82d59dd372f1166.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git://git-nokia.trolltech.com.au/qtsoftware/qt/kinetic
Conflicts:
src/xmlpatterns/type/qprimitives_p.h
tools/linguist/lupdate/main.cpp
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/bridge/qscriptdeclarativeclass.cpp | 192 | ||||
-rw-r--r-- | src/script/bridge/qscriptdeclarativeclass_p.h | 37 | ||||
-rw-r--r-- | src/script/bridge/qscriptdeclarativeobject.cpp | 35 | ||||
-rw-r--r-- | src/script/bridge/qscriptdeclarativeobject_p.h | 6 |
4 files changed, 263 insertions, 7 deletions
diff --git a/src/script/bridge/qscriptdeclarativeclass.cpp b/src/script/bridge/qscriptdeclarativeclass.cpp index 24037e1..ce2fc23 100644 --- a/src/script/bridge/qscriptdeclarativeclass.cpp +++ b/src/script/bridge/qscriptdeclarativeclass.cpp @@ -35,7 +35,113 @@ QT_BEGIN_NAMESPACE +/*! +\class QScriptDeclarativeClass::Value +\internal +\brief The QScriptDeclarativeClass::Value class acts as a container for JavaScript data types. + +QScriptDeclarativeClass::Value class is similar to QScriptValue, but it is slightly faster. +Unlike QScriptValue, however, Value instances cannot be stored as they may not survive garbage +collection. If you need to store a Value, convert it to a QScriptValue and store that. +*/ + +QScriptDeclarativeClass::Value::Value() +{ + new (this) JSC::JSValue(JSC::jsUndefined()); +} + +QScriptDeclarativeClass::Value::Value(const Value &other) +{ + new (this) JSC::JSValue((JSC::JSValue &)other); +} + +static QScriptDeclarativeClass::Value jscToValue(const JSC::JSValue &val) +{ + return QScriptDeclarativeClass::Value((QScriptDeclarativeClass::Value &)val); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, int value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, uint value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, bool value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, double value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, float value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, const QString &value) +{ + new (this) JSC::JSValue(JSC::jsString(QScriptEnginePrivate::frameForContext(ctxt), value)); +} + +QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, const QScriptValue &value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(ctxt->engine())->scriptValueToJSCValue(value)); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, int value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->currentFrame, value); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, uint value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->currentFrame, value); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, bool value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->currentFrame, value); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, double value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->currentFrame, value); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, float value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->currentFrame, value); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, const QString &value) +{ + new (this) JSC::JSValue(JSC::jsString(QScriptEnginePrivate::get(eng)->currentFrame, value)); +} + +QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, const QScriptValue &value) +{ + new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->scriptValueToJSCValue(value)); +} + +QScriptDeclarativeClass::Value::~Value() +{ + ((JSC::JSValue *)(this))->~JSValue(); +} + +QScriptValue QScriptDeclarativeClass::Value::toScriptValue(QScriptEngine *engine) const +{ + return QScriptEnginePrivate::get(engine)->scriptValueFromJSCValue((JSC::JSValue &)*this); +} + QScriptDeclarativeClass::PersistentIdentifier::PersistentIdentifier() +: identifier(0) { new (&d) JSC::Identifier(); } @@ -82,6 +188,22 @@ QScriptValue QScriptDeclarativeClass::newObject(QScriptEngine *engine, return p->scriptValueFromJSCValue(result); } +QScriptDeclarativeClass::Value +QScriptDeclarativeClass::newObjectValue(QScriptEngine *engine, + QScriptDeclarativeClass *scriptClass, + Object *object) +{ + Q_ASSERT(engine); + Q_ASSERT(scriptClass); + + QScriptEnginePrivate *p = static_cast<QScriptEnginePrivate *>(QObjectPrivate::get(engine)); + + JSC::ExecState* exec = p->currentFrame; + QScriptObject *result = new (exec) QScriptObject(p->scriptObjectStructure); + result->setDelegate(new QScript::DeclarativeObjectDelegate(scriptClass, object)); + return jscToValue(JSC::JSValue(result)); +} + QScriptDeclarativeClass *QScriptDeclarativeClass::scriptClass(const QScriptValue &v) { QScriptValuePrivate *d = QScriptValuePrivate::get(v); @@ -151,6 +273,53 @@ QScriptValue QScriptDeclarativeClass::property(const QScriptValue &v, const Iden return QScriptValue(); } +QScriptDeclarativeClass::Value +QScriptDeclarativeClass::functionValue(const QScriptValue &v, const Identifier &name) +{ + QScriptValuePrivate *d = QScriptValuePrivate::get(v); + + if (!d->isObject()) + return Value(); + + JSC::ExecState *exec = d->engine->currentFrame; + JSC::JSObject *object = d->jscValue.getObject(); + JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); + JSC::JSValue result; + + JSC::Identifier id(exec, (JSC::UString::Rep *)name); + + if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { + result = slot.getValue(exec, id); + if (QScript::isFunction(result)) + return jscToValue(result); + } + + return Value(); +} + +QScriptDeclarativeClass::Value +QScriptDeclarativeClass::propertyValue(const QScriptValue &v, const Identifier &name) +{ + QScriptValuePrivate *d = QScriptValuePrivate::get(v); + + if (!d->isObject()) + return Value(); + + JSC::ExecState *exec = d->engine->currentFrame; + JSC::JSObject *object = d->jscValue.getObject(); + JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); + JSC::JSValue result; + + JSC::Identifier id(exec, (JSC::UString::Rep *)name); + + if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { + result = slot.getValue(exec, id); + return jscToValue(result); + } + + return Value(); +} + /* Returns the scope chain entry at \a index. If index is less than 0, returns entries starting at the end. For example, scopeChainValue(context, -1) will return @@ -241,6 +410,16 @@ QScriptEngine *QScriptDeclarativeClass::engine() const return d_ptr->engine; } +bool QScriptDeclarativeClass::supportsCall() const +{ + return d_ptr->supportsCall; +} + +void QScriptDeclarativeClass::setSupportsCall(bool c) +{ + d_ptr->supportsCall = c; +} + QScriptDeclarativeClass::PersistentIdentifier QScriptDeclarativeClass::createPersistentIdentifier(const QString &str) { @@ -290,11 +469,12 @@ QScriptDeclarativeClass::queryProperty(Object *object, const Identifier &name, return 0; } -QScriptValue QScriptDeclarativeClass::property(Object *object, const Identifier &name) +QScriptDeclarativeClass::Value +QScriptDeclarativeClass::property(Object *object, const Identifier &name) { Q_UNUSED(object); Q_UNUSED(name); - return QScriptValue(); + return Value(); } void QScriptDeclarativeClass::setProperty(Object *object, const Identifier &name, @@ -313,6 +493,14 @@ QScriptDeclarativeClass::propertyFlags(Object *object, const Identifier &name) return 0; } +QScriptDeclarativeClass::Value QScriptDeclarativeClass::call(Object *object, + QScriptContext *ctxt) +{ + Q_UNUSED(object); + Q_UNUSED(ctxt); + return Value(); +} + QStringList QScriptDeclarativeClass::propertyNames(Object *object) { Q_UNUSED(object); diff --git a/src/script/bridge/qscriptdeclarativeclass_p.h b/src/script/bridge/qscriptdeclarativeclass_p.h index d28a371..a0fd6d5 100644 --- a/src/script/bridge/qscriptdeclarativeclass_p.h +++ b/src/script/bridge/qscriptdeclarativeclass_p.h @@ -47,16 +47,47 @@ class QScriptContext; class Q_SCRIPT_EXPORT QScriptDeclarativeClass { public: +#define QT_HAVE_QSCRIPTDECLARATIVECLASS_VALUE + class Q_SCRIPT_EXPORT Value + { + public: + Value(); + Value(const Value &); + + Value(QScriptContext *, int); + Value(QScriptContext *, uint); + Value(QScriptContext *, bool); + Value(QScriptContext *, double); + Value(QScriptContext *, float); + Value(QScriptContext *, const QString &); + Value(QScriptContext *, const QScriptValue &); + Value(QScriptEngine *, int); + Value(QScriptEngine *, uint); + Value(QScriptEngine *, bool); + Value(QScriptEngine *, double); + Value(QScriptEngine *, float); + Value(QScriptEngine *, const QString &); + Value(QScriptEngine *, const QScriptValue &); + ~Value(); + + QScriptValue toScriptValue(QScriptEngine *) const; + private: + char dummy[8]; + }; + typedef void* Identifier; struct Object { virtual ~Object() {} }; static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *); + static Value newObjectValue(QScriptEngine *, QScriptDeclarativeClass *, Object *); static QScriptDeclarativeClass *scriptClass(const QScriptValue &); static Object *object(const QScriptValue &); static QScriptValue function(const QScriptValue &, const Identifier &); static QScriptValue property(const QScriptValue &, const Identifier &); + static Value functionValue(const QScriptValue &, const Identifier &); + static Value propertyValue(const QScriptValue &, const Identifier &); static QScriptValue scopeChainValue(QScriptContext *, int index); static QScriptContext *pushCleanContext(QScriptEngine *); @@ -82,6 +113,9 @@ public: QScriptEngine *engine() const; + bool supportsCall() const; + void setSupportsCall(bool); + PersistentIdentifier createPersistentIdentifier(const QString &); PersistentIdentifier createPersistentIdentifier(const Identifier &); @@ -91,9 +125,10 @@ public: virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags); - virtual QScriptValue property(Object *, const Identifier &); + virtual Value property(Object *, const Identifier &); virtual void setProperty(Object *, const Identifier &name, const QScriptValue &); virtual QScriptValue::PropertyFlags propertyFlags(Object *, const Identifier &); + virtual Value call(Object *, QScriptContext *); virtual QStringList propertyNames(Object *); diff --git a/src/script/bridge/qscriptdeclarativeobject.cpp b/src/script/bridge/qscriptdeclarativeobject.cpp index aecb09a..c6ab6a7 100644 --- a/src/script/bridge/qscriptdeclarativeobject.cpp +++ b/src/script/bridge/qscriptdeclarativeobject.cpp @@ -74,9 +74,9 @@ bool DeclarativeObjectDelegate::getOwnPropertySlot(QScriptObject* object, QScriptClass::QueryFlags flags = m_class->queryProperty(m_object, identifier, QScriptClass::HandlesReadAccess); if (flags & QScriptClass::HandlesReadAccess) { - QScriptValue value = m_class->property(m_object, identifier); + QScriptDeclarativeClass::Value val = m_class->property(m_object, identifier); p->context = 0; - slot.setValue(engine->scriptValueToJSCValue(value)); + slot.setValue((const JSC::JSValue &)val); return true; } p->context = 0; @@ -155,7 +155,36 @@ void DeclarativeObjectDelegate::getOwnPropertyNames(QScriptObject* object, JSC:: JSC::CallType DeclarativeObjectDelegate::getCallData(QScriptObject *object, JSC::CallData &callData) { - return QScriptObjectDelegate::getCallData(object, callData); + if (!QScriptDeclarativeClassPrivate::get(m_class)->supportsCall) + return JSC::CallTypeNone; + callData.native.function = call; + return JSC::CallTypeHost; +} + +JSC::JSValue DeclarativeObjectDelegate::call(JSC::ExecState *exec, JSC::JSObject *callee, + JSC::JSValue thisValue, const JSC::ArgList &args) +{ + if (!callee->inherits(&QScriptObject::info)) + return JSC::throwError(exec, JSC::TypeError, "callee is not a DeclarativeObject object"); + QScriptObject *obj = static_cast<QScriptObject*>(callee); + QScriptObjectDelegate *delegate = obj->delegate(); + if (!delegate || (delegate->type() != QScriptObjectDelegate::DeclarativeClassObject)) + return JSC::throwError(exec, JSC::TypeError, "callee is not a DeclarativeObject object"); + + QScriptDeclarativeClass *scriptClass = static_cast<DeclarativeObjectDelegate*>(delegate)->m_class; + QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec); + + JSC::ExecState *oldFrame = eng_p->currentFrame; + eng_p->pushContext(exec, thisValue, args, callee); + QScriptContext *ctxt = eng_p->contextForFrame(eng_p->currentFrame); + + QScriptValue scriptObject = eng_p->scriptValueFromJSCValue(obj); + QScriptDeclarativeClass::Value result = + scriptClass->call(static_cast<DeclarativeObjectDelegate*>(delegate)->m_object, ctxt); + + eng_p->popContext(); + eng_p->currentFrame = oldFrame; + return (JSC::JSValue &)(result); } JSC::ConstructType DeclarativeObjectDelegate::getConstructData(QScriptObject* object, JSC::ConstructData &constructData) diff --git a/src/script/bridge/qscriptdeclarativeobject_p.h b/src/script/bridge/qscriptdeclarativeobject_p.h index d5bf673..ec8a43e 100644 --- a/src/script/bridge/qscriptdeclarativeobject_p.h +++ b/src/script/bridge/qscriptdeclarativeobject_p.h @@ -48,11 +48,12 @@ class QScriptClass; class QScriptDeclarativeClassPrivate { public: - QScriptDeclarativeClassPrivate() : engine(0), q_ptr(0), context(0) {} + QScriptDeclarativeClassPrivate() : engine(0), q_ptr(0), context(0), supportsCall(false) {} QScriptEngine *engine; QScriptDeclarativeClass *q_ptr; QScriptContext *context; + bool supportsCall:1; static QScriptDeclarativeClassPrivate *get(QScriptDeclarativeClass *c) { return c->d_ptr.data(); @@ -90,6 +91,9 @@ public: bool includeNonEnumerable = false); virtual JSC::CallType getCallData(QScriptObject*, JSC::CallData&); + static JSC::JSValue JSC_HOST_CALL call(JSC::ExecState*, JSC::JSObject*, + JSC::JSValue, const JSC::ArgList&); + virtual JSC::ConstructType getConstructData(QScriptObject*, JSC::ConstructData&); virtual bool hasInstance(QScriptObject*, JSC::ExecState*, |