mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
If the same JSObject is reflected into Java more than once then we should
return the same Java object, both for efficiency and so that the '==' operator works as expected in Java when comparing two JSObjects. However, it is not possible to hold a reference to a Java object without inhibiting GC of that object, at least not in a way that is portable to all vendor's JVMs, i.e. a weak reference. So, for now, JSObject identity is broken.
This commit is contained in:
parent
906b904d7a
commit
1bb1ec2907
@ -116,6 +116,15 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
|||||||
/* First, look in the hash table for an existing reflection of the same
|
/* First, look in the hash table for an existing reflection of the same
|
||||||
JavaScript object. If one is found, return it. */
|
JavaScript object. If one is found, return it. */
|
||||||
hep = PR_HashTableRawLookup(js_obj_reflections, (prhashcode)js_obj, js_obj);
|
hep = PR_HashTableRawLookup(js_obj_reflections, (prhashcode)js_obj, js_obj);
|
||||||
|
|
||||||
|
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||||
|
/* If the same JSObject is reflected into Java more than once then we should
|
||||||
|
return the same Java object, both for efficiency and so that the '=='
|
||||||
|
operator works as expected in Java when comparing two JSObjects.
|
||||||
|
However, it is not possible to hold a reference to a Java object without
|
||||||
|
inhibiting GC of that object, at least not in a portable way, i.e.
|
||||||
|
a weak reference. So, for now, JSObject identity is broken. */
|
||||||
|
|
||||||
he = *hep;
|
he = *hep;
|
||||||
if (he) {
|
if (he) {
|
||||||
java_wrapper_obj = (jobject)he->value;
|
java_wrapper_obj = (jobject)he->value;
|
||||||
@ -123,6 +132,7 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
|||||||
if (java_wrapper_obj)
|
if (java_wrapper_obj)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
#endif /* PRESERVE_JSOBJECT_IDENTITY */
|
||||||
|
|
||||||
/* No existing reflection found, so create a new Java object that wraps
|
/* No existing reflection found, so create a new Java object that wraps
|
||||||
the JavaScript object by storing its address in a private integer field. */
|
the JavaScript object by storing its address in a private integer field. */
|
||||||
|
Loading…
Reference in New Issue
Block a user