зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
fc7e40f15c
Коммит
eb2dc0ac61
|
@ -407,8 +407,8 @@ 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 */
|
||||
|
@ -431,8 +431,8 @@ JSObjectOps JavaArray_ops = {
|
|||
NULL, /* setParent */
|
||||
NULL, /* mark */
|
||||
NULL, /* clear */
|
||||
NULL, /* getRequiredSlot */
|
||||
NULL /* setRequiredSlot */
|
||||
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))
|
||||
|
|
|
@ -539,8 +539,8 @@ 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 */
|
||||
|
@ -563,8 +563,8 @@ JSObjectOps JavaClass_ops = {
|
|||
NULL, /* setParent */
|
||||
NULL, /* mark */
|
||||
NULL, /* clear */
|
||||
NULL, /* getRequiredSlot */
|
||||
NULL /* setRequiredSlot */
|
||||
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;
|
||||
|
|
|
@ -891,10 +891,55 @@ 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 */
|
||||
|
@ -917,8 +962,8 @@ JSObjectOps JavaObject_ops = {
|
|||
NULL, /* setParent */
|
||||
NULL, /* mark */
|
||||
NULL, /* clear */
|
||||
NULL, /* getRequiredSlot */
|
||||
NULL /* setRequiredSlot */
|
||||
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,
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче