MethodList EAClass::methodsNamed(const Identifier& identifier, Instance* instance) const { MethodList methodList; // Check to see if the method has been cached first. Method* method = mMethods.get(identifier.impl()); if (method) { methodList.append(method); return methodList; } // Method hasn't been called before, see if the object supports it. // Rather than doing identifier.ascii().data(), we need to create CString separately otherwise it goes out of scope. CString identStr = identifier.ascii(); const char *ident = identStr.data(); const EAInstance *inst = static_cast<const EAInstance*>(instance); EA::WebKit::IJSBoundObject *obj = inst->getObject(); if (obj->hasMethod(ident)) { // The object says it has this method, cache it so that the string // lookup can be avoided in the future. EAMethod* aMethod = new EAMethod(ident); { JSLock lock(SilenceAssertionsOnly); mMethods.set(identifier.impl(), aMethod); } methodList.append(aMethod); } return methodList; }
MethodList BalClass::methodsNamed(const Identifier& identifier, Instance* instance) const { MethodList methodList; Method* method = m_methods.get(identifier.ustring().rep()); if (method) { methodList.append(method); return methodList; } const UChar* ident16 = identifier.ustring().data(); char ident[256]; sprintf(ident,"%S",ident16); ident[identifier.ustring().size()] = '\0'; const BalInstance* inst = static_cast<const BalInstance*>(instance); BalObject* obj = inst->getObject(); if( obj->hasMethod( ident ) ) { BalMethod *aMethod= new BalMethod(obj, 0, ident, 0); m_methods.set(identifier.ustring().rep(), aMethod); methodList.append(aMethod); } return methodList; }
MethodList BalClass::methodsNamed(const Identifier& identifier, Instance* instance) const { MethodList methodList; Method* method = m_methods.get(identifier.ustring().rep()); if (method) { methodList.append(method); return methodList; } const char *ident = identifier.ascii(); const BalInstance* inst = static_cast<const BalInstance*>(instance); BalObject* obj = inst->getObject(); if( obj->hasMethod( ident ) ) { Method* aMethod = new BalMethod(ident); // deleted in the CClass destructor { JSLock lock(false); m_methods.set(identifier.ustring().rep(), aMethod); } methodList.append(aMethod); } return methodList; }
MethodList QtPixmapClass::methodsNamed(const Identifier& identifier, Instance*) const { MethodList methods; if (identifier == QtPixmapToDataUrlMethod::name()) methods.append(&qt_pixmap_metaData.toDataUrlMethod); else if (identifier == QtPixmapAssignToElementMethod::name()) methods.append(&qt_pixmap_metaData.assignToElementMethod); else if (identifier == QtPixmapToStringMethod::name()) methods.append(&qt_pixmap_metaData.toStringMethod); return methods; }
MethodList QtPixmapClass::methodsNamed(PropertyName identifier, Instance*) const { MethodList methods; UString ustring(identifier.publicName()); if (ustring == QtPixmapToDataUrlMethod::name()) methods.append(&qt_pixmap_metaData.toDataUrlMethod); else if (ustring == QtPixmapToImageDataMethod::name()) methods.append(&qt_pixmap_metaData.toImageDataMethod); else if (ustring == QtPixmapAssignToElementMethod::name()) methods.append(&qt_pixmap_metaData.assignToElementMethod); else if (ustring == QtPixmapToStringMethod::name()) methods.append(&qt_pixmap_metaData.toStringMethod); return methods; }
JavaClass::JavaClass(jobject anInstance) { jobject aClass = callJNIMethod<jobject>(anInstance, "getClass", "()Ljava/lang/Class;"); if (!aClass) { LOG_ERROR("Unable to call getClass on instance %p", anInstance); m_name = fastStrDup("<Unknown>"); return; } if (jstring className = (jstring)callJNIMethod<jobject>(aClass, "getName", "()Ljava/lang/String;")) { const char* classNameC = getCharactersFromJString(className); m_name = fastStrDup(classNameC); releaseCharactersForJString(className, classNameC); } else m_name = fastStrDup("<Unknown>"); int i; JNIEnv* env = getJNIEnv(); // Get the fields if (jarray fields = (jarray)callJNIMethod<jobject>(aClass, "getFields", "()[Ljava/lang/reflect/Field;")) { int numFields = env->GetArrayLength(fields); for (i = 0; i < numFields; i++) { jobject aJField = env->GetObjectArrayElement((jobjectArray)fields, i); JavaField* aField = new JavaField(env, aJField); // deleted in the JavaClass destructor { JSLock lock(SilenceAssertionsOnly); m_fields.set(((UString)aField->name()).rep(), aField); } env->DeleteLocalRef(aJField); } env->DeleteLocalRef(fields); } // Get the methods if (jarray methods = (jarray)callJNIMethod<jobject>(aClass, "getMethods", "()[Ljava/lang/reflect/Method;")) { int numMethods = env->GetArrayLength(methods); for (i = 0; i < numMethods; i++) { jobject aJMethod = env->GetObjectArrayElement((jobjectArray)methods, i); JavaMethod* aMethod = new JavaMethod(env, aJMethod); // deleted in the JavaClass destructor MethodList* methodList; { JSLock lock(SilenceAssertionsOnly); methodList = m_methods.get(((UString)aMethod->name()).rep()); if (!methodList) { methodList = new MethodList(); m_methods.set(((UString)aMethod->name()).rep(), methodList); } } methodList->append(aMethod); env->DeleteLocalRef(aJMethod); } env->DeleteLocalRef(methods); } env->DeleteLocalRef(aClass); }
JavaClassJobject::JavaClassJobject(jobject anInstance, bool requireAnnotation) : m_requireAnnotation(requireAnnotation) #else JavaClassJobject::JavaClassJobject(jobject anInstance) #endif { jobject aClass = callJNIMethod<jobject>(anInstance, "getClass", "()Ljava/lang/Class;"); if (!aClass) { LOG_ERROR("unable to call getClass on instance %p", anInstance); return; } JNIEnv* env = getJNIEnv(); // Get the fields jarray fields = static_cast<jarray>(callJNIMethod<jobject>(aClass, "getFields", "()[Ljava/lang/reflect/Field;")); int numFields = env->GetArrayLength(fields); for (int i = 0; i < numFields; i++) { jobject aJField = env->GetObjectArrayElement(static_cast<jobjectArray>(fields), i); JavaField* aField = new JavaFieldJobject(env, aJField); // deleted in the JavaClass destructor m_fields.set(aField->name(), aField); env->DeleteLocalRef(aJField); } // Get the methods jarray methods = static_cast<jarray>(callJNIMethod<jobject>(aClass, "getMethods", "()[Ljava/lang/reflect/Method;")); int numMethods = env->GetArrayLength(methods); #if PLATFORM(ANDROID) jmethodID isAnnotationPresentMethodID = getAnnotationMethodID(env); if (!isAnnotationPresentMethodID) { LOG_ERROR("unable to find method %s on instance %p", kIsAnnotationPresent, anInstance); return; } #endif for (int i = 0; i < numMethods; i++) { jobject aJMethod = env->GetObjectArrayElement(static_cast<jobjectArray>(methods), i); #if PLATFORM(ANDROID) if (jsAccessAllowed(env, isAnnotationPresentMethodID, aJMethod)) { #endif JavaMethod* aMethod = new JavaMethodJobject(env, aJMethod); // deleted in the JavaClass destructor MethodList* methodList = m_methods.get(aMethod->name()); if (!methodList) { methodList = new MethodList(); m_methods.set(aMethod->name(), methodList); } methodList->append(aMethod); #if PLATFORM(ANDROID) } #endif env->DeleteLocalRef(aJMethod); } env->DeleteLocalRef(fields); env->DeleteLocalRef(methods); env->DeleteLocalRef(aClass); }
JavaClass::JavaClass(jobject anInstance) { jobject aClass = callJNIMethod<jobject>(anInstance, "getClass", "()Ljava/lang/Class;"); if (!aClass) { fprintf(stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, anInstance); return; } jstring className = (jstring)callJNIMethod<jobject>(aClass, "getName", "()Ljava/lang/String;"); const char *classNameC = getCharactersFromJString(className); _name = strdup(classNameC); releaseCharactersForJString(className, classNameC); int i; JNIEnv *env = getJNIEnv(); JSGlobalData* globalData = WebCore::JSDOMWindow::commonJSGlobalData(); // Get the fields jarray fields = (jarray)callJNIMethod<jobject>(aClass, "getFields", "()[Ljava/lang/reflect/Field;"); int numFields = env->GetArrayLength(fields); for (i = 0; i < numFields; i++) { jobject aJField = env->GetObjectArrayElement((jobjectArray)fields, i); Field *aField = new JavaField(env, aJField); // deleted in the JavaClass destructor { JSLock lock(false); _fields.set(Identifier(globalData, UString(aField->name())).ustring().rep(), aField); } env->DeleteLocalRef(aJField); } // Get the methods jarray methods = (jarray)callJNIMethod<jobject>(aClass, "getMethods", "()[Ljava/lang/reflect/Method;"); int numMethods = env->GetArrayLength(methods); for (i = 0; i < numMethods; i++) { jobject aJMethod = env->GetObjectArrayElement((jobjectArray)methods, i); Method *aMethod = new JavaMethod(env, aJMethod); // deleted in the JavaClass destructor MethodList* methodList; { JSLock lock(false); methodList = _methods.get(Identifier(globalData, UString(aMethod->name())).ustring().rep()); if (!methodList) { methodList = new MethodList(); _methods.set(Identifier(globalData, UString(aMethod->name())).ustring().rep(), methodList); } } methodList->append(aMethod); env->DeleteLocalRef(aJMethod); } }