summaryrefslogtreecommitdiffstats
path: root/src/script/bridge/qscriptclassobject_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/qscriptclassobject_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/qscriptclassobject_p.h')
-rw-r--r--src/script/bridge/qscriptclassobject_p.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/script/bridge/qscriptclassobject_p.h b/src/script/bridge/qscriptclassobject_p.h
new file mode 100644
index 0000000..b2d6d7f
--- /dev/null
+++ b/src/script/bridge/qscriptclassobject_p.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $TROLLTECH_DUAL_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSCRIPTCLASSOBJECT_P_H
+#define QSCRIPTCLASSOBJECT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobjectdefs.h>
+
+#ifndef QT_NO_SCRIPT
+
+#include "qscriptobject_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QScriptClass;
+
+namespace QScript
+{
+
+class ClassObjectDelegate : public QScriptObjectDelegate
+{
+public:
+ ClassObjectDelegate(QScriptClass *scriptClass);
+ ~ClassObjectDelegate();
+
+ QScriptClass *scriptClass() const;
+ void setScriptClass(QScriptClass *scriptClass);
+
+ virtual Type type() const;
+
+ virtual bool getOwnPropertySlot(QScriptObject*, JSC::ExecState*,
+ const JSC::Identifier& propertyName,
+ JSC::PropertySlot&);
+ virtual void put(QScriptObject*, JSC::ExecState* exec,
+ const JSC::Identifier& propertyName,
+ JSC::JSValue, JSC::PutPropertySlot&);
+ virtual bool deleteProperty(QScriptObject*, JSC::ExecState*,
+ const JSC::Identifier& propertyName);
+ virtual bool getPropertyAttributes(const QScriptObject*, JSC::ExecState*,
+ const JSC::Identifier&,
+ unsigned&) const;
+ virtual void getPropertyNames(QScriptObject*, JSC::ExecState*,
+ JSC::PropertyNameArray&);
+
+ 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&);
+ static JSC::JSObject* construct(JSC::ExecState*, JSC::JSObject*,
+ const JSC::ArgList&);
+
+ virtual bool hasInstance(QScriptObject*, JSC::ExecState*,
+ JSC::JSValue value, JSC::JSValue proto);
+
+private:
+ QScriptClass *m_scriptClass;
+};
+
+} // namespace QScript
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_SCRIPT
+
+#endif