fix bug 82034 by making wrapped Java objects be not JS natives again but with their own slot accessors. This should bring JS -> Java communication back to life. sr=brendan r=beard a=drivers

This commit is contained in:
jband%netscape.com 2001-06-05 00:39:13 +00:00
parent 3d8ad4fec1
commit 6de619c0b1
4 changed files with 103 additions and 76 deletions

View File

@ -407,12 +407,12 @@ JavaArray_checkAccess(JSContext *cx, JSObject *obj, jsid id,
JSObjectOps JavaArray_ops = {
/* Mandatory non-null function pointer members. */
NULL, /* newObjectMap */
NULL, /* destroyObjectMap */
jsj_wrapper_newObjectMap, /* newObjectMap */
jsj_wrapper_destroyObjectMap, /* destroyObjectMap */
JavaArray_lookupProperty,
JavaArray_defineProperty,
JavaArray_getPropertyById, /* getProperty */
JavaArray_setPropertyById, /* setProperty */
JavaArray_getPropertyById, /* getProperty */
JavaArray_setPropertyById, /* setProperty */
JavaArray_getAttributes,
JavaArray_setAttributes,
JavaArray_deleteProperty,
@ -421,18 +421,18 @@ JSObjectOps JavaArray_ops = {
JavaArray_checkAccess,
/* Optionally non-null members start here. */
NULL, /* thisObject */
NULL, /* dropProperty */
NULL, /* call */
NULL, /* construct */
NULL, /* xdrObject */
NULL, /* hasInstance */
NULL, /* setProto */
NULL, /* setParent */
NULL, /* mark */
NULL, /* clear */
NULL, /* getRequiredSlot */
NULL /* setRequiredSlot */
NULL, /* thisObject */
NULL, /* dropProperty */
NULL, /* call */
NULL, /* construct */
NULL, /* xdrObject */
NULL, /* hasInstance */
NULL, /* setProto */
NULL, /* setParent */
NULL, /* mark */
NULL, /* clear */
jsj_wrapper_getRequiredSlot, /* getRequiredSlot */
jsj_wrapper_setRequiredSlot /* setRequiredSlot */
};
JS_STATIC_DLL_CALLBACK(JSObjectOps *)
@ -464,11 +464,6 @@ extern JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
JSBool
jsj_init_JavaArray(JSContext *cx, JSObject *global_obj)
{
JavaArray_ops.newObjectMap = js_ObjectOps.newObjectMap;
JavaArray_ops.destroyObjectMap = js_ObjectOps.destroyObjectMap;
JavaArray_ops.getRequiredSlot = js_ObjectOps.getRequiredSlot;
JavaArray_ops.setRequiredSlot = js_ObjectOps.setRequiredSlot;
if (!JS_InitClass(cx, global_obj,
0, &JavaArray_class, 0, 0,
0, 0, 0, 0))

View File

@ -539,12 +539,12 @@ done:
JSObjectOps JavaClass_ops = {
/* Mandatory non-null function pointer members. */
NULL, /* newObjectMap */
NULL, /* destroyObjectMap */
jsj_wrapper_newObjectMap, /* newObjectMap */
jsj_wrapper_destroyObjectMap, /* destroyObjectMap */
JavaClass_lookupProperty,
JavaClass_defineProperty,
JavaClass_getPropertyById, /* getProperty */
JavaClass_setPropertyById, /* setProperty */
JavaClass_getPropertyById, /* getProperty */
JavaClass_setPropertyById, /* setProperty */
JavaClass_getAttributes,
JavaClass_setAttributes,
JavaClass_deleteProperty,
@ -553,18 +553,18 @@ JSObjectOps JavaClass_ops = {
JavaClass_checkAccess,
/* Optionally non-null members start here. */
NULL, /* thisObject */
NULL, /* dropProperty */
jsj_JavaConstructorWrapper, /* call */
jsj_JavaConstructorWrapper, /* construct */
NULL, /* xdrObject */
JavaClass_hasInstance, /* hasInstance */
NULL, /* setProto */
NULL, /* setParent */
NULL, /* mark */
NULL, /* clear */
NULL, /* getRequiredSlot */
NULL /* setRequiredSlot */
NULL, /* thisObject */
NULL, /* dropProperty */
jsj_JavaConstructorWrapper, /* call */
jsj_JavaConstructorWrapper, /* construct */
NULL, /* xdrObject */
JavaClass_hasInstance, /* hasInstance */
NULL, /* setProto */
NULL, /* setParent */
NULL, /* mark */
NULL, /* clear */
jsj_wrapper_getRequiredSlot, /* getRequiredSlot */
jsj_wrapper_setRequiredSlot /* setRequiredSlot */
};
JS_STATIC_DLL_CALLBACK(JSObjectOps *)
@ -731,11 +731,6 @@ extern JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
JSBool
jsj_init_JavaClass(JSContext *cx, JSObject *global_obj)
{
JavaClass_ops.newObjectMap = js_ObjectOps.newObjectMap;
JavaClass_ops.destroyObjectMap = js_ObjectOps.destroyObjectMap;
JavaClass_ops.getRequiredSlot = js_ObjectOps.getRequiredSlot;
JavaClass_ops.setRequiredSlot = js_ObjectOps.setRequiredSlot;
/* Define JavaClass class */
if (!JS_InitClass(cx, global_obj, 0, &JavaClass_class, JavaClass_construct, 0, 0, 0, 0, 0))
return JS_FALSE;

View File

@ -891,14 +891,59 @@ JavaObject_checkAccess(JSContext *cx, JSObject *obj, jsid id,
}
}
#define JSJ_SLOT_COUNT (JSSLOT_PRIVATE+1)
JSObjectMap * JS_DLL_CALLBACK
jsj_wrapper_newObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
JSClass *clasp, JSObject *obj)
{
JSObjectMap * map;
map = (JSObjectMap *) JS_malloc(cx, sizeof(JSObjectMap));
if (map) {
map->nrefs = nrefs;
map->ops = ops;
map->nslots = JSJ_SLOT_COUNT;
map->freeslot = JSJ_SLOT_COUNT;
}
return map;
}
void JS_DLL_CALLBACK
jsj_wrapper_destroyObjectMap(JSContext *cx, JSObjectMap *map)
{
JS_free(cx, map);
}
jsval JS_DLL_CALLBACK
jsj_wrapper_getRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot)
{
JS_ASSERT(slot < JSJ_SLOT_COUNT);
JS_ASSERT(obj->slots);
JS_ASSERT(obj->map->nslots == JSJ_SLOT_COUNT);
JS_ASSERT(obj->map->freeslot == JSJ_SLOT_COUNT);
return obj->slots[slot];
}
void JS_DLL_CALLBACK
jsj_wrapper_setRequiredSlot(JSContext *cx, JSObject *obj,
uint32 slot, jsval v)
{
JS_ASSERT(slot < JSJ_SLOT_COUNT);
JS_ASSERT(obj->slots);
JS_ASSERT(obj->map->nslots == JSJ_SLOT_COUNT);
JS_ASSERT(obj->map->freeslot == JSJ_SLOT_COUNT);
obj->slots[slot] = v;
}
JSObjectOps JavaObject_ops = {
/* Mandatory non-null function pointer members. */
NULL, /* newObjectMap */
NULL, /* destroyObjectMap */
jsj_wrapper_newObjectMap, /* newObjectMap */
jsj_wrapper_destroyObjectMap, /* destroyObjectMap */
JavaObject_lookupProperty,
JavaObject_defineProperty,
JavaObject_getPropertyById, /* getProperty */
JavaObject_setPropertyById, /* setProperty */
JavaObject_getPropertyById, /* getProperty */
JavaObject_setPropertyById, /* setProperty */
JavaObject_getAttributes,
JavaObject_setAttributes,
JavaObject_deleteProperty,
@ -907,18 +952,18 @@ JSObjectOps JavaObject_ops = {
JavaObject_checkAccess,
/* Optionally non-null members start here. */
NULL, /* thisObject */
NULL, /* dropProperty */
NULL, /* call */
NULL, /* construct */
NULL, /* xdrObject */
NULL, /* hasInstance */
NULL, /* setProto */
NULL, /* setParent */
NULL, /* mark */
NULL, /* clear */
NULL, /* getRequiredSlot */
NULL /* setRequiredSlot */
NULL, /* thisObject */
NULL, /* dropProperty */
NULL, /* call */
NULL, /* construct */
NULL, /* xdrObject */
NULL, /* hasInstance */
NULL, /* setProto */
NULL, /* setParent */
NULL, /* mark */
NULL, /* clear */
jsj_wrapper_getRequiredSlot, /* getRequiredSlot */
jsj_wrapper_setRequiredSlot /* setRequiredSlot */
};
JS_STATIC_DLL_CALLBACK(JSObjectOps *)
@ -945,26 +990,9 @@ JSClass JavaObject_class = {
extern JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
/*
This is just a wrapper around the JS engine's newObjectMap() function,
required to avoid the JS engine confusing a JavaObject for a native
object. See bug #12367 for details
*/
JSObjectMap *
jsj_wrapper_newObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
JSClass *clasp, JSObject *obj)
{
return js_ObjectOps.newObjectMap(cx, nrefs, ops, clasp, obj);
}
JSBool
jsj_init_JavaObject(JSContext *cx, JSObject *global_obj)
{
JavaObject_ops.newObjectMap = js_ObjectOps.newObjectMap;
JavaObject_ops.destroyObjectMap = js_ObjectOps.destroyObjectMap;
JavaObject_ops.getRequiredSlot = js_ObjectOps.getRequiredSlot;
JavaObject_ops.setRequiredSlot = js_ObjectOps.setRequiredSlot;
if (!JS_InitClass(cx, global_obj,
0, &JavaObject_class, 0, 0,
0, 0,

View File

@ -633,10 +633,19 @@ jsj_EnterJava(JSContext *cx, JNIEnv **envp);
extern void
jsj_ExitJava(JSJavaThreadState *jsj_env);
JS_EXTERN_API(JSObjectMap *)
extern JSObjectMap * JS_DLL_CALLBACK
jsj_wrapper_newObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
JSClass *clasp, JSObject *obj);
extern void JS_DLL_CALLBACK
jsj_wrapper_destroyObjectMap(JSContext *cx, JSObjectMap *map);
extern jsval JS_DLL_CALLBACK
jsj_wrapper_getRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot);
extern void JS_DLL_CALLBACK
jsj_wrapper_setRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v);
#ifdef DEBUG
#define DEBUG_LOG(args) printf args
#endif