1 /* 2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 * 18 */ 19 20 #ifndef BINDINGS_QT_INSTANCE_H_ 21 #define BINDINGS_QT_INSTANCE_H_ 22 23 #include "Bridge.h" 24 #include "runtime_root.h" 25 #include <QtScript/qscriptengine.h> 26 #include <qhash.h> 27 #include <qpointer.h> 28 #include <qset.h> 29 30 namespace JSC { 31 32 namespace Bindings { 33 34 class QtClass; 35 class QtField; 36 class QtRuntimeMetaMethod; 37 38 class QtInstance : public Instance { 39 public: 40 ~QtInstance(); 41 42 virtual Class* getClass() const; 43 virtual RuntimeObjectImp* newRuntimeObject(ExecState*); 44 45 virtual void begin(); 46 virtual void end(); 47 48 virtual JSValue valueOf(ExecState*) const; 49 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; 50 51 void markAggregate(MarkStack&); 52 53 virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList&); 54 55 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 56 57 JSValue stringValue(ExecState* exec) const; 58 JSValue numberValue(ExecState* exec) const; 59 JSValue booleanValue() const; 60 61 QObject* getObject() const { return m_object; } 62 QObject* hashKey() const { return m_hashkey; } 63 64 static PassRefPtr<QtInstance> getQtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); 65 66 virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&); 67 virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&); 68 69 void removeCachedMethod(JSObject*); 70 71 static QtInstance* getInstance(JSObject*); 72 73 private: 74 static PassRefPtr<QtInstance> create(QObject *instance, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership) 75 { 76 return adoptRef(new QtInstance(instance, rootObject, ownership)); 77 } 78 79 friend class QtClass; 80 friend class QtField; 81 QtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); // Factory produced only.. 82 mutable QtClass* m_class; 83 QPointer<QObject> m_object; 84 QObject* m_hashkey; 85 mutable QHash<QByteArray, JSObject*> m_methods; 86 mutable QHash<QString, QtField*> m_fields; 87 mutable QtRuntimeMetaMethod* m_defaultMethod; 88 QScriptEngine::ValueOwnership m_ownership; 89 }; 90 91 } // namespace Bindings 92 93 } // namespace JSC 94 95 #endif 96