diff --git a/js/src/liveconnect/jsj_JavaArray.c b/js/src/liveconnect/jsj_JavaArray.c index 662d9923fffa..e6df99faa829 100644 --- a/js/src/liveconnect/jsj_JavaArray.c +++ b/js/src/liveconnect/jsj_JavaArray.c @@ -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)) diff --git a/js/src/liveconnect/jsj_JavaClass.c b/js/src/liveconnect/jsj_JavaClass.c index 6d5299ffa028..4cd08b3f3950 100644 --- a/js/src/liveconnect/jsj_JavaClass.c +++ b/js/src/liveconnect/jsj_JavaClass.c @@ -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; diff --git a/js/src/liveconnect/jsj_JavaObject.c b/js/src/liveconnect/jsj_JavaObject.c index 367010034581..4a5cb8f77ddd 100644 --- a/js/src/liveconnect/jsj_JavaObject.c +++ b/js/src/liveconnect/jsj_JavaObject.c @@ -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, diff --git a/js/src/liveconnect/jsj_private.h b/js/src/liveconnect/jsj_private.h index 74321880e075..3937a68f05f2 100644 --- a/js/src/liveconnect/jsj_private.h +++ b/js/src/liveconnect/jsj_private.h @@ -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