- Add test code for calling back via a timer on potentially other JSConetxt

to the xpconnect echo interface. This will help fix bug 17736. This includes
using nsITimer which is a pretty messed up xpcom interface w/o a factory.

- Added dump() to xpcshell to make it compatible with browsers debug
output method.

- reformat beard's leak fix to follow 80 column rule.

- Add a missing dont_AddRef to avoid a leak in some debug code.

r=mccabe
This commit is contained in:
jband%netscape.com 1999-11-02 05:55:29 +00:00
Родитель 9d79a81d45
Коммит a86ed74f9f
8 изменённых файлов: 71 добавлений и 6 удалений

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

@ -124,6 +124,8 @@ interface nsIEcho : nsISupports {
void printArgTypes(/* optional params */);
void throwArg(/* optional param */);
void callReceiverSometimeLater();
};
/***************************************************************************/

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

@ -180,6 +180,30 @@ Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_TRUE;
}
static JSBool
Dump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSString *str;
if (!argc)
return JS_TRUE;
str = JS_ValueToString(cx, argv[0]);
if (!str)
return JS_FALSE;
char *bytes = JS_GetStringBytes(str);
bytes = nsCRT::strdup(bytes);
#ifdef XP_MAC
for (char *c = bytes; *c; c++)
if (*c == '\r')
*c = '\n';
#endif
fputs(bytes, stderr);
nsAllocator::Free(bytes);
return JS_TRUE;
}
static JSBool
Load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
@ -304,6 +328,7 @@ static JSFunctionSpec glob_functions[] = {
{"version", Version, 1},
{"build", BuildDate, 0},
{"dumpXPC", DumpXPC, 1},
{"dump", Dump, 1},
{"gc", GC, 0},
{0}
};

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

@ -72,7 +72,8 @@ nsXPCWrappedNativeClass::GetNewOrUsedClass(XPCContext* xpcc,
return clazz;
}
nsCOMPtr<nsIInterfaceInfoManager> iimgr = dont_AddRef(nsXPConnect::GetInterfaceInfoManager());
nsCOMPtr<nsIInterfaceInfoManager> iimgr =
dont_AddRef(nsXPConnect::GetInterfaceInfoManager());
if(!iimgr)
{
SET_ERROR_CODE(NS_ERROR_FAILURE);
@ -317,8 +318,9 @@ nsXPCWrappedNativeClass::HandlePossibleNameCaseError(jsid id)
const char* badName = JS_GetStringBytes(oldJSStr);
char* locationStr = nsnull;
nsCOMPtr<nsXPCException> e =
nsXPCException::NewException("", NS_OK, nsnull, nsnull);
nsCOMPtr<nsXPCException> e =
dont_AddRef(nsXPCException::NewException("", NS_OK,
nsnull, nsnull));
nsCOMPtr<nsIJSStackFrameLocation> loc = nsnull;
if(e)

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

@ -497,6 +497,13 @@ MyEcho::ThrowArg(void)
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void callReceiverSometimeLater (); */
NS_IMETHODIMP
MyEcho::CallReceiverSometimeLater(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/***************************************************************************/
// security manager test class

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

@ -59,5 +59,9 @@ CPPSRCS = \
xpctest_out.cpp \
$(NULL)
LIBS += \
$(MOZ_TIMER_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -70,6 +70,7 @@ LLIBS= $(LIBNSPR) \
$(DIST)\lib\js$(MOZ_BITS)$(VERSION_NUMBER).lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\xpc$(MOZ_BITS)$(VERSION_NUMBER).lib \
$(DIST)\lib\timer_s.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -36,12 +36,15 @@
#include "xpctest_private.h"
class xpctestEcho : public nsIEcho
class xpctestEcho : public nsIEcho, public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIECHO
// not very xpcom compilant method from nsITimerCallback
virtual void Notify(nsITimer *timer);
xpctestEcho();
virtual ~xpctestEcho();
private:
@ -50,8 +53,7 @@ private:
/***************************************************************************/
static NS_DEFINE_IID(kxpctestEchoIID, NS_IECHO_IID);
NS_IMPL_ISUPPORTS(xpctestEcho, kxpctestEchoIID);
NS_IMPL_ISUPPORTS2(xpctestEcho, nsIEcho, nsITimerCallback);
xpctestEcho::xpctestEcho()
: mReceiver(NULL)
@ -403,6 +405,25 @@ xpctestEcho::ThrowArg(void)
return NS_OK;
}
/* void callReceiverSometimeLater (); */
NS_IMETHODIMP
xpctestEcho::CallReceiverSometimeLater(void)
{
nsITimer *timer;
if(NS_FAILED(NS_NewTimer(&timer)))
return NS_ERROR_FAILURE;
timer->Init(NS_STATIC_CAST(nsITimerCallback*,this), 2000);
return NS_OK;
}
void
xpctestEcho::Notify(nsITimer *timer)
{
if(mReceiver)
mReceiver->CallReceiverSometimeLater();
NS_RELEASE(timer);
}
/***************************************************/
/***************************************************************************/

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

@ -51,6 +51,9 @@
#include "xpctest.h"
#include "jsapi.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
// {ED132C20-EED1-11d2-BAA4-00805F8A5DD7}
#define NS_ECHO_CID \
{ 0xed132c20, 0xeed1, 0x11d2, \