fix bug 13125. Add support for wrapped native xpcom objects to be used as __proto__ objects for JavaScript objects. a,r=brendan@mozilla.org

This commit is contained in:
jband%netscape.com 2000-09-07 18:49:06 +00:00
Родитель f9fdff0825
Коммит 45fb207d7e
3 изменённых файлов: 40 добавлений и 26 удалений

Просмотреть файл

@ -41,8 +41,6 @@ extern "C" JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
NS_IMPL_THREADSAFE_ISUPPORTS1(nsXPCArbitraryScriptable, nsIXPCScriptable)
#define REAL_WRAPPER(w) ((nsXPCWrappedNative*)(w))
NS_IMETHODIMP
nsXPCArbitraryScriptable::Create(JSContext *cx, JSObject *obj,
nsIXPConnectWrappedNative* wrapper,
@ -51,7 +49,6 @@ nsXPCArbitraryScriptable::Create(JSContext *cx, JSObject *obj,
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
return NS_OK;
}
@ -65,7 +62,6 @@ nsXPCArbitraryScriptable::GetFlags(JSContext *cx, JSObject *obj,
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(flagsp, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*flagsp = 0;
return NS_OK;
}
@ -81,7 +77,6 @@ nsXPCArbitraryScriptable::LookupProperty(JSContext *cx, JSObject *obj, jsid id,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.lookupProperty(cx, obj, id, objp, propp
#if defined JS_THREADSAFE && defined DEBUG
, "unknown file", 1
@ -103,7 +98,6 @@ nsXPCArbitraryScriptable::DefineProperty(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.defineProperty(cx, obj, id, value, getter, setter,
attrs, propp);
return NS_OK;
@ -120,7 +114,6 @@ nsXPCArbitraryScriptable::GetProperty(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.getProperty(cx, obj, id, vp);
return NS_OK;
}
@ -136,7 +129,6 @@ nsXPCArbitraryScriptable::SetProperty(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.setProperty(cx, obj, id, vp);
return NS_OK;
}
@ -152,7 +144,6 @@ nsXPCArbitraryScriptable::GetAttributes(JSContext *cx, JSObject *obj, jsid id,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.getAttributes(cx, obj, id, prop, attrsp);
return NS_OK;
}
@ -168,7 +159,6 @@ nsXPCArbitraryScriptable::SetAttributes(JSContext *cx, JSObject *obj, jsid id,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.setAttributes(cx, obj, id, prop, attrsp);
return NS_OK;
}
@ -184,7 +174,6 @@ nsXPCArbitraryScriptable::DeleteProperty(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.deleteProperty(cx, obj, id, vp);
return NS_OK;
}
@ -200,7 +189,6 @@ nsXPCArbitraryScriptable::DefaultValue(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.defaultValue(cx, obj, type, vp);
return NS_OK;
}
@ -217,7 +205,6 @@ nsXPCArbitraryScriptable::Enumerate(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.enumerate(cx, obj, enum_op, statep, idp);
return NS_OK;
}
@ -233,7 +220,6 @@ nsXPCArbitraryScriptable::CheckAccess(JSContext *cx, JSObject *obj, jsid id,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.checkAccess(cx, obj, id, mode, vp, attrsp);
return NS_OK;
}
@ -250,7 +236,6 @@ nsXPCArbitraryScriptable::Call(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.call(cx, obj, argc, argv, rval);
return NS_OK;
}
@ -267,7 +252,6 @@ nsXPCArbitraryScriptable::Construct(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.construct(cx, obj, argc, argv, rval);
return NS_OK;
}
@ -284,7 +268,6 @@ nsXPCArbitraryScriptable::HasInstance(JSContext *cx, JSObject *obj,
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.hasInstance(cx, obj, v, bp);
return NS_OK;
}
@ -297,7 +280,6 @@ nsXPCArbitraryScriptable::Finalize(JSContext *cx, JSObject *obj,
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
/* XPConnect does the finalization on the wrapper itself anyway */
return NS_OK;
}

Просмотреть файл

@ -1042,6 +1042,7 @@ done:
void* p = dp->val.p;
if(!p)
continue;
if(dp->IsValArray())
{
// going to have to cleanup the array and perhaps its contents
@ -1303,12 +1304,7 @@ nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(JSContext* cx,
if(JS_InstanceOf(cx, cur, &WrappedNative_class, nsnull) ||
JS_InstanceOf(cx, cur, &WrappedNativeWithCall_class, nsnull))
return (nsXPCWrappedNative*) JS_GetPrivate(cx, cur);
// This was an attempt to make it possible to use a wrapped
// native as a __proto__ for a plain JS object. There are still
// problems with making this work.
// cur = JS_GetPrototype(cx, cur);
break;
cur = JS_GetPrototype(cx, cur);
}
return nsnull;
}

Просмотреть файл

@ -794,6 +794,40 @@ WrappedNative_DropProperty(JSContext *cx, JSObject *obj, JSProperty *prop)
}
}
JS_STATIC_DLL_CALLBACK(JSBool)
WrappedNative_Resolve(JSContext *cx, JSObject *obj, jsval idval)
{
AUTO_PUSH_JSCONTEXT(cx);
SET_CALLER_JAVASCRIPT(cx);
nsXPCWrappedNative* wrapper;
wrapper = GET_WRAPPER(cx, obj);
if(wrapper && wrapper->IsValid())
{
nsXPCWrappedNativeClass* clazz = wrapper->GetClass();
NS_ASSERTION(clazz,"wrapper without class");
jsid id;
if(JS_ValueToId(cx, idval, &id))
{
const XPCNativeMemberDescriptor* desc = clazz->LookupMemberByID(id);
if(desc)
{
jsval val;
JSObject* real_obj = wrapper->GetJSObject();
if(WrappedNative_GetProperty(cx, real_obj, id, &val))
{
return js_ObjectOps.defineProperty(cx, real_obj,
id, val,
nsnull, nsnull,
0, nsnull);
}
}
}
}
return JS_TRUE;
}
/*
* We have two classes - one with and one without call and construct. We use
* the one without for any object without an nsIXPCScriptable so that the
@ -875,7 +909,8 @@ JSClass WrappedNative_class = {
"XPCWrappedNative",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub,
JS_EnumerateStub,
WrappedNative_Resolve,
WrappedNative_Convert,
WrappedNative_Finalize,
/* Optionally non-null members start here. */
@ -891,7 +926,8 @@ JSClass WrappedNativeWithCall_class = {
"XPCWrappedNativeWithCall",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub,
JS_EnumerateStub,
WrappedNative_Resolve,
WrappedNative_Convert,
WrappedNative_Finalize,
/* Optionally non-null members start here. */