bug 307005: If the passed-in object itself isn't an XPCNativeWrapper, look up its prototype chain for one so we don't throw if a property was found on a wrapped prototype of a non-wrapped object. r=jst sr=brendan

git-svn-id: svn://10.0.0.236/trunk@180116 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mrbkap%gmail.com 2005-09-13 16:48:28 +00:00
parent f0110ebc1d
commit b9a11ccab2

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et tw=80: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -340,8 +341,15 @@ XPC_NW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
JSObject *funObj = JSVAL_TO_OBJECT(argv[-2]);
if (!::JS_ObjectIsFunction(cx, funObj) ||
!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
if (!::JS_ObjectIsFunction(cx, funObj)) {
obj = nsnull;
}
while (obj && !XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
obj = ::JS_GetPrototype(cx, obj);
}
if (!obj) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
}
@ -380,10 +388,11 @@ XPC_NW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
return JS_TRUE;
}
// Be paranoid, don't let people use this as another object's
// prototype or anything like that.
if (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
while (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
obj = ::JS_GetPrototype(cx, obj);
if (!obj) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
}
}
XPCWrappedNative *wrappedNative =
@ -657,10 +666,11 @@ XPC_NW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
return JS_TRUE;
}
// Be paranoid, don't let people use this as another object's
// prototype or anything like that.
if (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
while (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
obj = ::JS_GetPrototype(cx, obj);
if (!obj) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
}
}
XPCWrappedNative *wrappedNative =
@ -1135,10 +1145,11 @@ JS_STATIC_DLL_CALLBACK(JSBool)
XPC_NW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
// Be paranoid, don't let people use this as another object's
// prototype or anything like that.
if (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
while (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
obj = ::JS_GetPrototype(cx, obj);
if (!obj) {
return ThrowException(NS_ERROR_UNEXPECTED, cx);
}
}
// Check whether toString was overridden in any object along