Changeset 29447 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jan 13, 2008, 3:08:39 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r29445 r29447 1 2008-01-13 Michael Goddard <[email protected]> 2 3 Reviewed by Anders Carlsson. 4 5 Add binding language type to Instance. 6 Allows runtime determination of the type of an 7 Instance, to allow safe casting. Doesn't actually 8 add any safe casting yet, though. 9 10 Add a helper function to get an Instance from a JSObject*. 11 Given an object and the expected binding language, see if 12 the JSObject actually wraps an Instance of the given type 13 and return it. Otherwise return 0. 14 15 Move RuntimeObjectImp creations into Instance. 16 Make the ctor protected, and Instance a friend class, so 17 that all creation of RuntimeObjectImps goes through 18 one place. 19 20 Remove copy ctor/assignment operator for QtInstance. 21 Instance itself is Noncopyable, so QtInstance doesn't 22 need to have these. 23 24 Add caching for QtInstance and associated RuntimeObjectImps. 25 Push any dealings with QtLanguage bindings into QtInstance, 26 and cache them there, rather than in the Instance layer. Add 27 a QtRuntimeObjectImp to help with caching. 28 29 * JavaScriptCore.exp: 30 * bindings/c/c_instance.h: 31 * bindings/jni/jni_instance.h: 32 * bindings/objc/objc_instance.h: 33 * bindings/qt/qt_instance.cpp: 34 (KJS::Bindings::QtRuntimeObjectImp::QtRuntimeObjectImp): 35 (KJS::Bindings::QtRuntimeObjectImp::~QtRuntimeObjectImp): 36 (KJS::Bindings::QtRuntimeObjectImp::invalidate): 37 (KJS::Bindings::QtRuntimeObjectImp::removeFromCache): 38 (KJS::Bindings::QtInstance::QtInstance): 39 (KJS::Bindings::QtInstance::~QtInstance): 40 (KJS::Bindings::QtInstance::getQtInstance): 41 (KJS::Bindings::QtInstance::getRuntimeObject): 42 * bindings/qt/qt_instance.h: 43 (KJS::Bindings::QtInstance::getBindingLanguage): 44 * bindings/runtime.cpp: 45 (KJS::Bindings::Instance::createBindingForLanguageInstance): 46 (KJS::Bindings::Instance::createRuntimeObject): 47 (KJS::Bindings::Instance::getInstance): 48 * bindings/runtime.h: 49 * bindings/runtime_object.h: 50 (KJS::RuntimeObjectImp::getInternalInstance): 51 1 52 2008-01-12 Alp Toker <[email protected]> 2 53 -
trunk/JavaScriptCore/JavaScriptCore.exp
r29396 r29447 159 159 __ZN3KJS16ParserRefCounted5derefEv 160 160 __ZN3KJS16RuntimeObjectImp4infoE 161 __ZN3KJS16RuntimeObjectImpC1EPNS_8Bindings8InstanceE162 161 __ZN3KJS17PropertyNameArray3addERKNS_10IdentifierE 163 162 __ZN3KJS19InternalFunctionImp4infoE … … 196 195 __ZN3KJS8Bindings24findProtectingRootObjectEPNS_8JSObjectE 197 196 __ZN3KJS8Bindings8Instance18didExecuteFunctionEv 197 __ZN3KJS8Bindings8Instance19createRuntimeObjectEPS1_ 198 198 __ZN3KJS8Bindings8Instance21setDidExecuteFunctionEPFvPNS_9ExecStateEPNS_8JSObjectEE 199 199 __ZN3KJS8Bindings8Instance32createBindingForLanguageInstanceENS1_15BindingLanguageEPvN3WTF10PassRefPtrINS0_10RootObjectEEE -
trunk/JavaScriptCore/bindings/c/c_instance.h
r25000 r29447 65 65 NPObject *getObject() const { return _object; } 66 66 67 virtual BindingLanguage getBindingLanguage() const { return CLanguage; } 68 67 69 private: 68 70 mutable CClass *_class; -
trunk/JavaScriptCore/bindings/jni/jni_instance.h
r27186 r29447 84 84 JSValue *numberValue() const; 85 85 JSValue *booleanValue() const; 86 86 87 virtual BindingLanguage getBindingLanguage() const { return JavaLanguage; } 88 87 89 private: 88 90 RefPtr<JObjectWrapper> _instance; -
trunk/JavaScriptCore/bindings/jni/jni_jsobject.cpp
r28468 r29447 470 470 JSLock lock; 471 471 JavaInstance* javaInstance = new JavaInstance(theObject, _rootObject); 472 RuntimeObjectImp* newImp = new RuntimeObjectImp(javaInstance); 473 474 return newImp; 472 return KJS::Bindings::Instance::createRuntimeObject(javaInstance); 475 473 } 476 474 -
trunk/JavaScriptCore/bindings/objc/objc_instance.h
r23472 r29447 65 65 JSValue *numberValue() const; 66 66 JSValue *booleanValue() const; 67 67 68 virtual BindingLanguage getBindingLanguage() const { return ObjectiveCLanguage; } 69 68 70 private: 69 71 RetainPtr<ObjectStructPtr> _instance; -
trunk/JavaScriptCore/bindings/qt/qt_instance.cpp
r26972 r29447 21 21 #include "qt_instance.h" 22 22 23 #include "list.h" 23 24 #include "qt_class.h" 24 25 #include "qt_runtime.h" 25 #include " list.h"26 #include "runtime_object.h" 26 27 27 28 #include <qmetaobject.h> 28 29 #include <qdebug.h> 30 #include <qhash.h> 29 31 30 32 namespace KJS { 31 33 namespace Bindings { 32 34 35 // Cache QtInstances 36 typedef QMultiHash<void*, QtInstance*> QObjectInstanceMap; 37 static QObjectInstanceMap cachedInstances; 38 39 // Cache JSObjects 40 typedef QHash<QtInstance*, JSObject*> InstanceJSObjectMap; 41 static InstanceJSObjectMap cachedObjects; 42 43 // Derived RuntimeObject 44 class QtRuntimeObjectImp : public RuntimeObjectImp { 45 public: 46 QtRuntimeObjectImp(Instance*); 47 ~QtRuntimeObjectImp(); 48 virtual void invalidate(); 49 protected: 50 void removeFromCache(); 51 }; 52 53 QtRuntimeObjectImp::QtRuntimeObjectImp(Instance* instance) 54 : RuntimeObjectImp(instance) 55 { 56 } 57 58 QtRuntimeObjectImp::~QtRuntimeObjectImp() 59 { 60 removeFromCache(); 61 } 62 63 void QtRuntimeObjectImp::invalidate() 64 { 65 removeFromCache(); 66 RuntimeObjectImp::invalidate(); 67 } 68 69 void QtRuntimeObjectImp::removeFromCache() 70 { 71 JSLock lock; 72 QtInstance* key = cachedObjects.key(this); 73 if (key) 74 cachedObjects.remove(key); 75 } 76 77 // QtInstance 33 78 QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject) 34 : Instance(rootObject), 35 _class(0), 36 _object(o) 37 { 38 } 39 40 QtInstance::~QtInstance() 41 { 42 } 43 44 QtInstance::QtInstance(const QtInstance& other) 45 : Instance(other.rootObject()), _class(0), _object(other._object) 46 { 47 } 48 49 QtInstance& QtInstance::operator=(const QtInstance& other) 50 { 51 if (this == &other) 52 return *this; 53 54 _object = other._object; 55 _class = 0; 56 57 return *this; 79 : Instance(rootObject) 80 , _class(0) 81 , _object(o) 82 , _hashkey(o) 83 { 84 } 85 86 QtInstance::~QtInstance() 87 { 88 JSLock lock; 89 cachedObjects.remove(this); 90 cachedInstances.remove(_hashkey); 91 } 92 93 QtInstance* QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObject> rootObject) 94 { 95 JSLock lock; 96 97 foreach(QtInstance* instance, cachedInstances.values(o)) { 98 if (instance->rootObject() == rootObject) 99 return instance; 100 } 101 102 QtInstance* ret = new QtInstance(o, rootObject); 103 cachedInstances.insert(o, ret); 104 105 return ret; 106 } 107 108 JSObject* QtInstance::getRuntimeObject(QtInstance* instance) 109 { 110 JSLock lock; 111 JSObject* ret = cachedObjects.value(instance); 112 if (!ret) { 113 ret = new QtRuntimeObjectImp(instance); 114 cachedObjects.insert(instance, ret); 115 } 116 return ret; 58 117 } 59 118 -
trunk/JavaScriptCore/bindings/qt/qt_instance.h
r22067 r29447 36 36 { 37 37 public: 38 QtInstance(QObject* instance, PassRefPtr<RootObject>);39 40 38 ~QtInstance (); 41 39 42 40 virtual Class* getClass() const; 43 44 QtInstance (const QtInstance &other);45 46 QtInstance &operator=(const QtInstance &other);47 41 48 42 virtual void begin(); … … 63 57 QObject* getObject() const { return _object; } 64 58 59 virtual BindingLanguage getBindingLanguage() const { return QtLanguage; } 60 61 static QtInstance* getQtInstance(QObject*, PassRefPtr<RootObject>); 62 static JSObject* getRuntimeObject(QtInstance*); 63 65 64 private: 65 QtInstance(QObject*, PassRefPtr<RootObject>); // Factory produced only.. 66 66 mutable QtClass* _class; 67 67 QPointer<QObject> _object; 68 QObject* _hashkey; 68 69 }; 69 70 -
trunk/JavaScriptCore/bindings/runtime.cpp
r25000 r29447 106 106 #if PLATFORM(QT) 107 107 case Instance::QtLanguage: { 108 newInstance = new Bindings::QtInstance((QObject *)nativeInstance, rootObject);108 newInstance = Bindings::QtInstance::getQtInstance((QObject *)nativeInstance, rootObject); 109 109 break; 110 110 } … … 120 120 { 121 121 Instance* instance = Instance::createBindingForLanguageInstance(language, nativeInstance, rootObject); 122 122 123 return createRuntimeObject(instance); 124 } 125 126 JSObject* Instance::createRuntimeObject(Instance* instance) 127 { 128 #if PLATFORM(QT) 129 if (instance->getBindingLanguage() == QtLanguage) 130 return QtInstance::getRuntimeObject(static_cast<QtInstance*>(instance)); 131 #endif 123 132 JSLock lock; 124 133 return new RuntimeObjectImp(instance); 125 134 } 126 135 127 RootObject* Instance::rootObject() const 128 { 136 Instance* Instance::getInstance(JSObject* object, BindingLanguage language) 137 { 138 if (!object) 139 return 0; 140 if (!object->inherits(&RuntimeObjectImp::info)) 141 return 0; 142 Instance* instance = (static_cast<RuntimeObjectImp*>(object))->getInternalInstance(); 143 if (!instance) 144 return 0; 145 if (instance->getBindingLanguage() != language) 146 return 0; 147 return instance; 148 } 149 150 RootObject* Instance::rootObject() const 151 { 129 152 return _rootObject && _rootObject->isValid() ? _rootObject.get() : 0; 130 153 } -
trunk/JavaScriptCore/bindings/runtime.h
r23512 r29447 102 102 static Instance* createBindingForLanguageInstance(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject>); 103 103 static JSObject* createRuntimeObject(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject>); 104 static JSObject* createRuntimeObject(Instance*); 105 106 static Instance* getInstance(JSObject*, BindingLanguage); 104 107 105 108 void ref() { _refCount++; } … … 139 142 virtual ~Instance(); 140 143 144 virtual BindingLanguage getBindingLanguage() const = 0; 145 141 146 protected: 142 147 RefPtr<RootObject> _rootObject; -
trunk/JavaScriptCore/bindings/runtime_object.h
r23538 r29447 36 36 class RuntimeObjectImp : public JSObject { 37 37 public: 38 RuntimeObjectImp(Bindings::Instance *i);39 38 virtual ~RuntimeObjectImp(); 40 39 … … 50 49 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 51 50 52 v oid invalidate();51 virtual void invalidate(); 53 52 Bindings::Instance *getInternalInstance() const { return instance.get(); } 54 53 … … 56 55 57 56 static const ClassInfo info; 57 58 protected: 59 friend class Bindings::Instance; 60 RuntimeObjectImp(Bindings::Instance*); // Only allow Instances and derived classes to create us 58 61 59 62 private:
Note:
See TracChangeset
for help on using the changeset viewer.