1) adding the fix for 7926 from brendan and sfraser (with cleanup from me).

2) added where I was not checking for JSVAL_NULL from brendan.
3) got rid of 'xpcom32' references.
4) added nsIEcho::ReturnInterface as a loopback for testing the above.
5) removed some redundant retval setting code.
This commit is contained in:
jband%netscape.com 1999-06-11 02:04:42 +00:00
parent 7c8cb8eb81
commit 5e7127dd45
7 changed files with 85 additions and 27 deletions

View File

@ -77,6 +77,8 @@ interface nsIEcho : nsISupports {
void ReturnCode_NS_ERROR_NULL_POINTER();
void ReturnCode_NS_ERROR_UNEXPECTED();
void ReturnCode_NS_ERROR_OUT_OF_MEMORY();
nsISupports ReturnInterface(in nsISupports obj);
};
/***************************************************************************/

View File

@ -58,7 +58,7 @@ static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
#ifdef XP_PC
#define XPCOM_DLL "xpcom32.dll"
#define XPCOM_DLL "xpcom.dll"
#else
#ifdef XP_MAC
#define XPCOM_DLL "XPCOM_DLL"

View File

@ -199,10 +199,7 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
{
nsID* iid = *((nsID**)s);
if(!iid)
{
*d = JSVAL_NULL;
break;
}
JSObject* obj;
if(!(obj = xpc_NewIIDObject(cx, *iid)))
return JS_FALSE;
@ -219,10 +216,7 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
{
char* p = *((char**)s);
if(!p)
{
*d = JSVAL_NULL;
break;
}
JSString* str;
if(!(str = JS_NewStringCopyZ(cx, p)))
return JS_FALSE;
@ -234,10 +228,7 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
{
jschar* p = *((jschar**)s);
if(!p)
{
*d = JSVAL_NULL;
break;
}
JSString* str;
if(!(str = JS_NewUCStringCopyZ(cx, p)))
return JS_FALSE;
@ -250,11 +241,8 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
{
nsISupports* iface = *((nsISupports**)s);
if(!iface)
{
*d = JSVAL_NULL;
break;
}
JSObject* aJSObj;
JSObject* aJSObj = NULL;
// is this a wrapped JS object?
if(nsXPCWrappedJSClass::IsWrappedJS(iface))
{
@ -270,21 +258,60 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
}
else
{
// we need to build a wrapper
nsXPCWrappedNative* wrapper=NULL;
XPCContext* xpcc;
if(!iid || !(xpcc = nsXPConnect::GetContext(cx)) ||
!(wrapper = nsXPCWrappedNative::GetNewOrUsedWrapper(xpcc,
iface, *iid)))
nsIScriptObjectOwner* owner = NULL;
nsresult rv;
rv = iface->QueryInterface(nsIScriptObjectOwner::GetIID(),
(void**)&owner);
if(NS_SUCCEEDED(rv) && owner)
{
return JS_FALSE;
JSObject* globalObject;
nsISupports* domObject;
if(NULL != (globalObject =
JS_GetGlobalObject(cx)) &&
NULL != (domObject = (nsISupports*)
JS_GetPrivate(cx, globalObject)))
{
nsIScriptGlobalObject* scriptObject = NULL;
rv = domObject->QueryInterface(
nsIScriptGlobalObject::GetIID(),
(void**)&scriptObject);
if(NS_SUCCEEDED(rv) && scriptObject)
{
nsIScriptContext* scriptContext = NULL;
scriptObject->GetContext(&scriptContext);
if(scriptContext)
{
rv = owner->GetScriptObject(scriptContext,
(void **)&aJSObj);
NS_RELEASE(scriptContext);
if (NS_FAILED(rv))
return JS_FALSE;
}
NS_RELEASE(scriptObject);
}
}
NS_RELEASE(owner);
}
if(!aJSObj)
{
// we need to build a wrapper
nsXPCWrappedNative* wrapper = NULL;
XPCContext* xpcc;
if(!iid ||
!(xpcc = nsXPConnect::GetContext(cx)) ||
!(wrapper =
nsXPCWrappedNative::GetNewOrUsedWrapper(xpcc,
iface, *iid)))
{
return JS_FALSE;
}
aJSObj = wrapper->GetJSObject();
NS_RELEASE(wrapper);
}
aJSObj = wrapper->GetJSObject();
NS_RELEASE(wrapper);
if(aJSObj)
*d = OBJECT_TO_JSVAL(aJSObj);
}
break;
}
default:

View File

@ -47,6 +47,10 @@
#include "xpcjsid.h"
#include "prlong.h"
#include "nsIScriptObjectOwner.h" // for DOM hack in xpcconvert.cpp
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
extern const char* XPC_VAL_STR; // 'value' property name for out params
extern const char* XPC_COMPONENTS_STR; // 'Components' property name

View File

@ -521,7 +521,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
dp->ptr = &dp->val;
if(!param.IsRetval() &&
(!JSVAL_IS_OBJECT(argv[i]) ||
(JSVAL_IS_PRIMITIVE(argv[i]) ||
!JS_GetProperty(cx, JSVAL_TO_OBJECT(argv[i]), XPC_VAL_STR, &src)))
{
ThrowBadParamException(XPCJSError::NEED_OUT_OBJECT,

View File

@ -43,7 +43,7 @@ static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
#ifdef XP_PC
#define XPCOM_DLL "xpcom32.dll"
#define XPCOM_DLL "xpcom.dll"
#else
#ifdef XP_MAC
#define XPCOM_DLL "XPCOM_DLL"
@ -308,7 +308,8 @@ public:
/* void ReturnCode_NS_ERROR_OUT_OF_MEMORY (); */
NS_IMETHOD ReturnCode_NS_ERROR_OUT_OF_MEMORY();
/* nsISupports ReturnInterface (in nsISupports obj); */
NS_IMETHOD ReturnInterface(nsISupports *obj, nsISupports **_retval);
MyEcho();
private:
@ -487,6 +488,17 @@ NS_IMETHODIMP
MyEcho::ReturnCode_NS_ERROR_OUT_OF_MEMORY()
{return NS_ERROR_OUT_OF_MEMORY;}
NS_IMETHODIMP
MyEcho::ReturnInterface(nsISupports *obj, nsISupports **_retval)
{
if(!_retval)
return NS_ERROR_NULL_POINTER;
if(obj)
NS_ADDREF(obj);
*_retval = obj;
return NS_OK;
}
/***************************************************************************/
// security manager test class

View File

@ -90,6 +90,8 @@ public:
/* void ReturnCode_NS_ERROR_OUT_OF_MEMORY (); */
NS_IMETHOD ReturnCode_NS_ERROR_OUT_OF_MEMORY();
/* nsISupports ReturnInterface (in nsISupports obj); */
NS_IMETHOD ReturnInterface(nsISupports *obj, nsISupports **_retval);
xpctestEcho();
private:
@ -266,6 +268,17 @@ NS_IMETHODIMP
xpctestEcho::ReturnCode_NS_ERROR_OUT_OF_MEMORY()
{return NS_ERROR_OUT_OF_MEMORY;}
NS_IMETHODIMP
xpctestEcho::ReturnInterface(nsISupports *obj, nsISupports **_retval)
{
if(!_retval)
return NS_ERROR_NULL_POINTER;
if(obj)
NS_ADDREF(obj);
*_retval = obj;
return NS_OK;
}
/***************************************************************************/
// static