summaryrefslogtreecommitdiffstats
path: root/src/script/bridge/qscriptvariant_p.h
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-10 12:27:16 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-10 12:27:16 (GMT)
commit75bc0215080fcafea9ba1bafedd980d9ac71bf9d (patch)
tree61156a5b2eaf3377b304beb6df59343750d21804 /src/script/bridge/qscriptvariant_p.h
parent0579f4be2e79bb95c963a7e2368b6ee797c25e90 (diff)
downloadQt-75bc0215080fcafea9ba1bafedd980d9ac71bf9d.zip
Qt-75bc0215080fcafea9ba1bafedd980d9ac71bf9d.tar.gz
Qt-75bc0215080fcafea9ba1bafedd980d9ac71bf9d.tar.bz2
implement ability to dynamically change class of script objects
With an object created by QScriptEngine::newObject(), it should be possible to call QScriptValue::setClass() to dynamically change the behavior of that object. Similarly, it should be possible to promote plain script objects to QObject (QVariant) wrappers by calling the overload of QScriptEngine::newQObject() (newVariant()) that takes a script object as the first argument. This commit implements this capability. The premise is the (internal) QScriptObject class, which inherits JSC::JSObject. It reimplements all the methods for getting/setting properties etc. Then there's a level of indirection to facilitate dynamic change of the class: Each QScriptObject can have a delegate associated with it that will handle operations on the object. By default there is no delegate, so the object behaves as a normal JS object, as you expect. However, once a delegate is set (e.g., when QScriptValue::setScriptClass() is called), QScriptObject will give the delegate the chance to handle the object operation. In addition to a delegate implementation for QScriptClass-based objects, there are also delegates for QObject and QVariant wrappers. These replace the QObjectWrapperObject and QVariantWrapperObject classes.
Diffstat (limited to 'src/script/bridge/qscriptvariant_p.h')
-rw-r--r--src/script/bridge/qscriptvariant_p.h25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/script/bridge/qscriptvariant_p.h b/src/script/bridge/qscriptvariant_p.h
index 6e74a6b..ae6564c 100644
--- a/src/script/bridge/qscriptvariant_p.h
+++ b/src/script/bridge/qscriptvariant_p.h
@@ -27,36 +27,29 @@
#ifndef QT_NO_SCRIPT
-#include "JSObject.h"
+#include "qscriptobject_p.h"
QT_BEGIN_NAMESPACE
namespace QScript
{
-class QVariantWrapperObject : public JSC::JSObject
+class QVariantDelegate : public QScriptObjectDelegate
{
public:
- // work around CELL_SIZE limitation
- struct Data
- {
- QVariant value;
- };
+ QVariantDelegate(const QVariant &value);
+ ~QVariantDelegate();
- explicit QVariantWrapperObject(WTF::PassRefPtr<JSC::Structure> sid);
- ~QVariantWrapperObject();
-
- virtual const JSC::ClassInfo* classInfo() const { return &info; }
- static const JSC::ClassInfo info;
+ QVariant &value();
+ void setValue(const QVariant &value);
- inline QVariant &value() const { return data->value; }
- inline void setValue(const QVariant &value) { data->value = value; }
+ Type type() const;
private:
- Data *data;
+ QVariant m_value;
};
-class QVariantPrototype : public QVariantWrapperObject
+class QVariantPrototype : public QScriptObject
{
public:
QVariantPrototype(JSC::ExecState*, WTF::PassRefPtr<JSC::Structure>,