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 qt_instance_h 21 #define qt_instance_h 22 23 #include "BridgeJSC.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 RuntimeObject* 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 getMethod(ExecState* exec, const Identifier& propertyName); 54 virtual JSValue invokeMethod(ExecState*, RuntimeMethod*); 55 56 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 57 58 JSValue stringValue(ExecState* exec) const; 59 JSValue numberValue(ExecState* exec) const; 60 JSValue booleanValue() const; 61 getObject()62 QObject* getObject() const { return m_object; } hashKey()63 QObject* hashKey() const { return m_hashkey; } 64 65 static PassRefPtr<QtInstance> getQtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); 66 67 virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&); 68 virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&); 69 70 void removeCachedMethod(JSObject*); 71 72 static QtInstance* getInstance(JSObject*); 73 74 private: create(QObject * instance,PassRefPtr<RootObject> rootObject,QScriptEngine::ValueOwnership ownership)75 static PassRefPtr<QtInstance> create(QObject *instance, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership) 76 { 77 return adoptRef(new QtInstance(instance, rootObject, ownership)); 78 } 79 80 friend class QtClass; 81 friend class QtField; 82 QtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); // Factory produced only.. 83 mutable QtClass* m_class; 84 QPointer<QObject> m_object; 85 QObject* m_hashkey; 86 mutable QHash<QByteArray, WriteBarrier<JSObject> > m_methods; 87 mutable QHash<QString, QtField*> m_fields; 88 mutable WriteBarrier<QtRuntimeMetaMethod> m_defaultMethod; 89 QScriptEngine::ValueOwnership m_ownership; 90 }; 91 92 } // namespace Bindings 93 94 } // namespace JSC 95 96 #endif 97