[webkit-changes] cvs commit: JavaScriptCore/bindings/jni
jni_class.cpp jni_class.h jni_instance.cpp jni_instance.h
Adele
adele at opensource.apple.com
Wed Aug 10 14:41:01 PDT 2005
adele 05/08/10 14:41:01
Modified: . Tag: Safari-2-0-branch ChangeLog
bindings/jni Tag: Safari-2-0-branch jni_class.cpp
jni_class.h jni_instance.cpp jni_instance.h
Log:
Merged fix from TOT to Safari-2-0-branch
2005-08-10 Geoffrey Garen <ggaren at apple.com>
-fixed <rdar://problem/4151132> REGRESSION: Some applet liveconnect calls
throws privilege exception.
Reviewed by richard and mjs.
-I removed the global static JavaClass cache, since it violated Java
security to cache classes between websites and applets.
* bindings/jni/jni_class.cpp:
-removed global static cache dictionary
-instance constructor and destructor now do the work that used to
be done by static factory methods
-removed obsolete functions
(JavaClass::JavaClass):
(JavaClass::~JavaClass):
* bindings/jni/jni_class.h:
-removed obsolete function declarations
-made copying private since it's unused and it's also not clear
excatly how copying would work with Java security
-made default construction private since it's meaningless
* bindings/jni/jni_instance.cpp:
-removed obsolete functions
(JavaInstance::~JavaInstance):
(JavaInstance::getClass):
* bindings/jni/jni_instance.h:
-made copying private since it's unused and it's also not clear
excatly how copying would work with Java security
-made default construction private since it's meaningless
Revision Changes Path
No revision
No revision
1.677.6.25 +35 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.677.6.24
retrieving revision 1.677.6.25
diff -u -r1.677.6.24 -r1.677.6.25
--- ChangeLog 10 Aug 2005 02:45:47 -0000 1.677.6.24
+++ ChangeLog 10 Aug 2005 21:40:59 -0000 1.677.6.25
@@ -1,3 +1,38 @@
+2005-08-10 Adele Peterson <adele at apple.com>
+
+ Merged fix from TOT to Safari-2-0-branch
+
+ 2005-08-10 Geoffrey Garen <ggaren at apple.com>
+
+ -fixed <rdar://problem/4151132> REGRESSION: Some applet liveconnect calls
+ throws privilege exception.
+
+ Reviewed by richard and mjs.
+
+ -I removed the global static JavaClass cache, since it violated Java
+ security to cache classes between websites and applets.
+
+ * bindings/jni/jni_class.cpp:
+ -removed global static cache dictionary
+ -instance constructor and destructor now do the work that used to
+ be done by static factory methods
+ -removed obsolete functions
+ (JavaClass::JavaClass):
+ (JavaClass::~JavaClass):
+ * bindings/jni/jni_class.h:
+ -removed obsolete function declarations
+ -made copying private since it's unused and it's also not clear
+ excatly how copying would work with Java security
+ -made default construction private since it's meaningless
+ * bindings/jni/jni_instance.cpp:
+ -removed obsolete functions
+ (JavaInstance::~JavaInstance):
+ (JavaInstance::getClass):
+ * bindings/jni/jni_instance.h:
+ -made copying private since it's unused and it's also not clear
+ excatly how copying would work with Java security
+ -made default construction private since it's meaningless
+
2005-08-09 Geoffrey Garen <ggaren at apple.com>
-fixed <rdar://problem/4197421> crash in ObjectImp::findPropertyHashEntry at ifilm.com
No revision
No revision
1.13.10.1 +19 -84 JavaScriptCore/bindings/jni/jni_class.cpp
Index: jni_class.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_class.cpp,v
retrieving revision 1.13
retrieving revision 1.13.10.1
diff -u -r1.13 -r1.13.10.1
--- jni_class.cpp 1 Oct 2004 00:24:39 -0000 1.13
+++ jni_class.cpp 10 Aug 2005 21:41:00 -0000 1.13.10.1
@@ -29,10 +29,21 @@
using namespace KJS::Bindings;
-void JavaClass::_commonInit (jobject aClass)
+JavaClass::JavaClass (jobject anInstance)
{
- long i;
+ jobject aClass = callJNIObjectMethod(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)callJNIObjectMethod(aClass, "getName", "()Ljava/lang/String;");
+ const char *classNameC = getCharactersFromJString (className);
+ _name = strdup (classNameC);
+ releaseCharactersForJString(className, classNameC);
+ long i;
JNIEnv *env = getJNIEnv();
// Get the fields
@@ -65,7 +76,7 @@
CFRelease (methodName);
env->DeleteLocalRef (aJMethod);
}
-
+
// Get the constructors
jarray constructors = (jarray)callJNIObjectMethod (aClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;");
_numConstructors = env->GetArrayLength (constructors);
@@ -77,86 +88,11 @@
}
}
-JavaClass::JavaClass (const char *className)
-{
- JNIEnv *env = getJNIEnv();
-
- _name = strdup (className);
-
- // Get the class
- jclass aClass = env->FindClass(_name);
- if (!aClass){
- fprintf (stderr, "%s: unable to find class %s\n", __PRETTY_FUNCTION__, _name);
- return;
- }
-
- _commonInit (aClass);
-
- env->DeleteLocalRef (aClass);
-}
-
-JavaClass::JavaClass (jobject aClass)
-{
- _name = 0;
- _commonInit (aClass);
-}
-
-static CFMutableDictionaryRef classesByName = 0;
-
-static void _createClassesByNameIfNecessary()
-{
- if (classesByName == 0)
- classesByName = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, NULL);
-}
-
-JavaClass *JavaClass::classForName (const char *name)
-{
- _createClassesByNameIfNecessary();
-
- CFStringRef stringName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
- JavaClass *aClass = (JavaClass *)CFDictionaryGetValue(classesByName, stringName);
- if (aClass == NULL) {
- aClass = new JavaClass (name);
- CFDictionaryAddValue (classesByName, stringName, aClass);
- }
- CFRelease (stringName);
-
- return aClass;
-}
-
-void JavaClass::setClassName (const char *n)
-{
- free ((void *)_name);
- _name = strdup(n);
-}
-
-JavaClass *JavaClass::classForInstance (jobject instance)
-{
- _createClassesByNameIfNecessary();
-
- jobject classOfInstance = callJNIObjectMethod(instance, "getClass", "()Ljava/lang/Class;");
-
- if (!classOfInstance) {
- fprintf (stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, instance);
- return 0;
- }
-
- jstring className = (jstring)callJNIObjectMethod(classOfInstance, "getName", "()Ljava/lang/String;");
-
- const char *classNameC = getCharactersFromJString (className);
-
- CFStringRef stringName = CFStringCreateWithCString(NULL, classNameC, kCFStringEncodingASCII);
- JavaClass *aClass = (JavaClass *)CFDictionaryGetValue(classesByName, stringName);
- if (aClass == NULL) {
- aClass = new JavaClass (classOfInstance);
- aClass->setClassName(classNameC);
- CFDictionaryAddValue (classesByName, stringName, aClass);
- }
- CFRelease (stringName);
-
- releaseCharactersForJString(className, classNameC);
-
- return aClass;
+JavaClass::~JavaClass () {
+ free((void *)_name);
+ CFRelease (_fields);
+ CFRelease (_methods);
+ delete [] _constructors;
}
MethodList JavaClass::methodsNamed(const char *name, Instance *instance) const
@@ -169,7 +105,6 @@
return MethodList();
}
-
Field *JavaClass::fieldNamed(const char *name, Instance *instance) const
{
CFStringRef fieldName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
1.9.10.1 +6 -57 JavaScriptCore/bindings/jni/jni_class.h
Index: jni_class.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_class.h,v
retrieving revision 1.9
retrieving revision 1.9.10.1
diff -u -r1.9 -r1.9.10.1
--- jni_class.h 1 Oct 2004 00:24:39 -0000 1.9
+++ jni_class.h 10 Aug 2005 21:41:00 -0000 1.9.10.1
@@ -38,63 +38,9 @@
class JavaClass : public Class
{
- // Use the public static factory methods to get instances of JavaClass.
-
-protected:
- void _commonInit (jobject aClass);
-
- JavaClass (const char *name);
-
- JavaClass (jobject aClass);
-
public:
- // Return the cached JavaClass from the class of the jobject.
- static JavaClass *classForInstance (jobject anInstance);
-
- // Return the cached JavaClass of the specified name.
- static JavaClass *classForName (const char *name);
-
- void _commonDelete() {
- free((void *)_name);
- CFRelease (_fields);
- CFRelease (_methods);
- delete [] _constructors;
- }
-
- ~JavaClass () {
- _commonDelete();
- }
-
- void _commonCopy(const JavaClass &other) {
- long i;
-
- _name = strdup (other._name);
-
- _methods = CFDictionaryCreateCopy (NULL, other._methods);
- _fields = CFDictionaryCreateCopy (NULL, other._fields);
-
- _numConstructors = other._numConstructors;
- _constructors = new JavaConstructor[_numConstructors];
- for (i = 0; i < _numConstructors; i++) {
- _constructors[i] = other._constructors[i];
- }
- }
-
- JavaClass (const JavaClass &other)
- : Class() {
- _commonCopy (other);
- };
-
- JavaClass &operator=(const JavaClass &other)
- {
- if (this == &other)
- return *this;
-
- _commonDelete();
- _commonCopy (other);
-
- return *this;
- }
+ JavaClass (jobject anInstance);
+ ~JavaClass ();
virtual const char *name() const { return _name; };
@@ -108,12 +54,15 @@
virtual long numConstructors() const { return _numConstructors; };
- void setClassName(const char *n);
bool isNumberClass() const;
bool isBooleanClass() const;
bool isStringClass() const;
private:
+ JavaClass (); // prevent default construction
+ JavaClass (const JavaClass &other); // prevent copying
+ JavaClass &operator=(const JavaClass &other); // prevent copying
+
const char *_name;
CFDictionaryRef _fields;
CFDictionaryRef _methods;
1.25.8.1 +2 -10 JavaScriptCore/bindings/jni/jni_instance.cpp
Index: jni_instance.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_instance.cpp,v
retrieving revision 1.25
retrieving revision 1.25.8.1
diff -u -r1.25 -r1.25.8.1
--- jni_instance.cpp 12 Feb 2005 00:58:13 -0000 1.25
+++ jni_instance.cpp 10 Aug 2005 21:41:00 -0000 1.25.8.1
@@ -51,17 +51,9 @@
JavaInstance::~JavaInstance ()
{
_instance->deref();
+ delete _class;
}
-
-JavaInstance::JavaInstance (const JavaInstance &other) : Instance()
-{
- _instance = other._instance;
- _instance->ref();
- // Classes are kept around forever.
- _class = other._class;
-};
-
#define NUM_LOCAL_REFS 64
void JavaInstance::begin()
@@ -77,7 +69,7 @@
Class *JavaInstance::getClass() const
{
if (_class == 0)
- _class = JavaClass::classForInstance (_instance->_instance);
+ _class = new JavaClass (_instance->_instance);
return _class;
}
1.17.8.1 +4 -17 JavaScriptCore/bindings/jni/jni_instance.h
Index: jni_instance.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_instance.h,v
retrieving revision 1.17
retrieving revision 1.17.8.1
diff -u -r1.17 -r1.17.8.1
--- jni_instance.h 17 Jan 2005 22:41:22 -0000 1.17
+++ jni_instance.h 10 Aug 2005 21:41:00 -0000 1.17.8.1
@@ -70,23 +70,6 @@
virtual Class *getClass() const;
- JavaInstance (const JavaInstance &other);
-
- JavaInstance &operator=(const JavaInstance &other){
- if (this == &other)
- return *this;
-
- JObjectWrapper *_oldInstance = _instance;
- _instance = other._instance;
- _instance->ref();
- _oldInstance->deref();
-
- // Classes are kept around forever.
- _class = other._class;
-
- return *this;
- };
-
virtual void begin();
virtual void end();
@@ -103,6 +86,10 @@
Value booleanValue() const;
private:
+ JavaInstance (); // prevent default construction
+ JavaInstance (JavaInstance &); // prevent copying
+ JavaInstance &operator=(JavaInstance &); // prevent copying
+
JObjectWrapper *_instance;
mutable JavaClass *_class;
};
More information about the webkit-changes
mailing list