зеркало из https://github.com/mozilla/gecko-dev.git
- 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:
Родитель
9d79a81d45
Коммит
a86ed74f9f
|
@ -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, \
|
||||
|
|
Загрузка…
Ссылка в новой задаче