зеркало из https://github.com/mozilla/gecko-dev.git
- added an interactive shell for xpconnect testing.
- added tests/components which autregs itself for testing. - added finalize listener for wrapped natives to support services. - added getService to CID class. - renamed newInstance to createInstance in CID class. - simplified api for Components object (easy attach to global object).
This commit is contained in:
Родитель
84a91f617a
Коммит
f9394a892b
|
@ -23,7 +23,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||||
DIRS = public src
|
DIRS = public src
|
||||||
|
|
||||||
ifdef ENABLE_TESTS
|
ifdef ENABLE_TESTS
|
||||||
DIRS += tests
|
DIRS += tests shell
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
xpidl -w -m header -o ..\public\nsrootidl nsrootidl.idl
|
xpidl -w -m header -o ..\public\nsrootidl nsrootidl.idl
|
||||||
xpidl -w -m header -o ..\public\xpccomponents xpccomponents.idl
|
xpidl -w -m header -o ..\public\xpccomponents xpccomponents.idl
|
||||||
xpidl -w -m header -o ..\public\xpcjsid xpcjsid.idl
|
xpidl -w -m header -o ..\public\xpcjsid xpcjsid.idl
|
||||||
xpidl -w -m header -o ..\tests\xpctest xpctest.idl
|
xpidl -w -m header -o ..\public\xpctest xpctest.idl
|
||||||
|
|
||||||
xpidl -w -m typelib -o ..\typelib\xpccomponents xpccomponents.idl
|
xpidl -w -m typelib -o ..\typelib\xpccomponents xpccomponents.idl
|
||||||
xpidl -w -m typelib -o ..\typelib\xpcjsid xpcjsid.idl
|
xpidl -w -m typelib -o ..\typelib\xpcjsid xpcjsid.idl
|
||||||
|
|
|
@ -44,7 +44,8 @@ interface nsIJSIID : nsIJSID
|
||||||
[scriptable, uuid(e3a24a60-d651-11d2-9843-006008962422)]
|
[scriptable, uuid(e3a24a60-d651-11d2-9843-006008962422)]
|
||||||
interface nsIJSCID : nsIJSID
|
interface nsIJSCID : nsIJSID
|
||||||
{
|
{
|
||||||
nsISupports newInstance();
|
nsISupports createInstance();
|
||||||
|
nsISupports getService();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* this goes into the C++ header verbatim. */
|
/* this goes into the C++ header verbatim. */
|
||||||
|
|
|
@ -17,6 +17,6 @@
|
||||||
DEPTH=..\..\..
|
DEPTH=..\..\..
|
||||||
IGNORE_MANIFEST=1
|
IGNORE_MANIFEST=1
|
||||||
|
|
||||||
DIRS=public src tests
|
DIRS=public src tests shell
|
||||||
|
|
||||||
include <$(DEPTH)\config\rules.mak>
|
include <$(DEPTH)\config\rules.mak>
|
||||||
|
|
|
@ -29,6 +29,7 @@ EXPORTS = \
|
||||||
xpccomponents.h \
|
xpccomponents.h \
|
||||||
xpcjsid.h \
|
xpcjsid.h \
|
||||||
xpclog.h \
|
xpclog.h \
|
||||||
|
xpctest.h \
|
||||||
nsrootidl.h \
|
nsrootidl.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ EXPORTS = \
|
||||||
xpccomponents.h \
|
xpccomponents.h \
|
||||||
xpcjsid.h \
|
xpcjsid.h \
|
||||||
xpclog.h \
|
xpclog.h \
|
||||||
|
xpctest.h \
|
||||||
nsrootidl.h \
|
nsrootidl.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,21 @@
|
||||||
// forward declarations...
|
// forward declarations...
|
||||||
class nsIXPCScriptable;
|
class nsIXPCScriptable;
|
||||||
class nsIInterfaceInfo;
|
class nsIInterfaceInfo;
|
||||||
|
class nsIXPConnectWrappedNative;
|
||||||
|
class nsIXPConnectFinalizeListener;
|
||||||
|
|
||||||
|
|
||||||
|
// {1B2DDB00-EEE8-11d2-BAA4-00805F8A5DD7}
|
||||||
|
#define NS_IXPCONNECT_FINALIZE_LISTENER_IID \
|
||||||
|
{ 0x1b2ddb00, 0xeee8, 0x11d2, \
|
||||||
|
{ 0xba, 0xa4, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
||||||
|
class nsIXPConnectFinalizeListener : public nsISupports
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_FINALIZE_LISTENER_IID)
|
||||||
|
|
||||||
|
NS_IMETHOD AboutToRelease(nsISupports* aObj) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
// {215DBE02-94A7-11d2-BA58-00805F8A5DD7}
|
// {215DBE02-94A7-11d2-BA58-00805F8A5DD7}
|
||||||
#define NS_IXPCONNECT_WRAPPED_NATIVE_IID \
|
#define NS_IXPCONNECT_WRAPPED_NATIVE_IID \
|
||||||
|
@ -72,6 +87,8 @@ public:
|
||||||
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
|
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
|
||||||
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
|
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
|
||||||
NS_IMETHOD DebugDump(int depth) = 0;
|
NS_IMETHOD DebugDump(int depth) = 0;
|
||||||
|
NS_IMETHOD SetFinalizeListener(nsIXPConnectFinalizeListener* aListener) = 0;
|
||||||
|
|
||||||
// XXX other methods?
|
// XXX other methods?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -119,13 +136,18 @@ public:
|
||||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_IID)
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_IID)
|
||||||
|
|
||||||
NS_IMETHOD InitJSContext(JSContext* aJSContext,
|
NS_IMETHOD InitJSContext(JSContext* aJSContext,
|
||||||
JSObject* aGlobalJSObj) = 0;
|
JSObject* aGlobalJSObj,
|
||||||
|
JSBool AddComponentsObject) = 0;
|
||||||
|
|
||||||
NS_IMETHOD InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
NS_IMETHOD InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
||||||
nsISupports* aCOMObj,
|
nsISupports* aCOMObj,
|
||||||
REFNSIID aIID,
|
REFNSIID aIID,
|
||||||
|
JSBool AddComponentsObject,
|
||||||
nsIXPConnectWrappedNative** aWrapper) = 0;
|
nsIXPConnectWrappedNative** aWrapper) = 0;
|
||||||
|
|
||||||
|
NS_IMETHOD AddNewComponentsObject(JSContext* aJSContext,
|
||||||
|
JSObject* aGlobalJSObj) = 0;
|
||||||
|
|
||||||
// XXX add 'AbandonJSContext' method and all that implies?
|
// XXX add 'AbandonJSContext' method and all that implies?
|
||||||
|
|
||||||
NS_IMETHOD WrapNative(JSContext* aJSContext,
|
NS_IMETHOD WrapNative(JSContext* aJSContext,
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
|
|
||||||
class nsIXPCInterfaces : public nsISupports {
|
class nsIXPCInterfaces : public nsISupports {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCINTERFACES_IID)
|
||||||
static nsIID iid = NS_IXPCINTERFACES_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||||
|
@ -43,10 +40,7 @@ class nsIXPCInterfaces : public nsISupports {
|
||||||
|
|
||||||
class nsIXPCClasses : public nsISupports {
|
class nsIXPCClasses : public nsISupports {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCCLASSES_IID)
|
||||||
static nsIID iid = NS_IXPCCLASSES_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||||
|
@ -64,32 +58,46 @@ class nsIXPCClasses : public nsISupports {
|
||||||
|
|
||||||
class nsIXPCComponents : public nsISupports {
|
class nsIXPCComponents : public nsISupports {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCCOMPONENTS_IID)
|
||||||
static nsIID iid = NS_IXPCCOMPONENTS_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* readonly attribute nsIXPCInterfaces interfaces; */
|
/* readonly attribute nsIXPCInterfaces interfaces; */
|
||||||
NS_IMETHOD GetInterfaces(nsIXPCInterfaces * *aInterfaces) = 0;
|
NS_IMETHOD GetInterfaces(nsIXPCInterfaces * *aInterfaces) = 0;
|
||||||
|
|
||||||
/* readonly attribute nsIXPCClasses classes; */
|
/* readonly attribute nsIXPCClasses classes; */
|
||||||
NS_IMETHOD GetClasses(nsIXPCClasses * *aClasses) = 0;
|
NS_IMETHOD GetClasses(nsIXPCClasses * *aClasses) = 0;
|
||||||
|
|
||||||
enum { RESULT_NS_OK = 0 };
|
enum { RESULT_NS_OK = 0 };
|
||||||
|
|
||||||
enum { RESULT_NS_COMFALSE = 1 };
|
enum { RESULT_NS_COMFALSE = 1 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_NOT_IMPLEMENTED = -2147467263 };
|
enum { RESULT_NS_ERROR_NOT_IMPLEMENTED = -2147467263 };
|
||||||
|
|
||||||
enum { RESULT_NS_NOINTERFACE = -2147467262 };
|
enum { RESULT_NS_NOINTERFACE = -2147467262 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_NO_INTERFACE = -2147467262 };
|
enum { RESULT_NS_ERROR_NO_INTERFACE = -2147467262 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_INVALID_POINTER = -2147467261 };
|
enum { RESULT_NS_ERROR_INVALID_POINTER = -2147467261 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_NULL_POINTER = -2147467261 };
|
enum { RESULT_NS_ERROR_NULL_POINTER = -2147467261 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_ABORT = -2147467260 };
|
enum { RESULT_NS_ERROR_ABORT = -2147467260 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_FAILURE = -2147467259 };
|
enum { RESULT_NS_ERROR_FAILURE = -2147467259 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_UNEXPECTED = -2147418113 };
|
enum { RESULT_NS_ERROR_UNEXPECTED = -2147418113 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_OUT_OF_MEMORY = -2147024882 };
|
enum { RESULT_NS_ERROR_OUT_OF_MEMORY = -2147024882 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_ILLEGAL_VALUE = -2147024809 };
|
enum { RESULT_NS_ERROR_ILLEGAL_VALUE = -2147024809 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_INVALID_ARG = -2147024809 };
|
enum { RESULT_NS_ERROR_INVALID_ARG = -2147024809 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_NO_AGGREGATION = -2147221232 };
|
enum { RESULT_NS_ERROR_NO_AGGREGATION = -2147221232 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_NOT_AVAILABLE = -2147221231 };
|
enum { RESULT_NS_ERROR_NOT_AVAILABLE = -2147221231 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_FACTORY_NOT_REGISTERED = -2147221164 };
|
enum { RESULT_NS_ERROR_FACTORY_NOT_REGISTERED = -2147221164 };
|
||||||
|
|
||||||
enum { RESULT_NS_ERROR_FACTORY_NOT_LOADED = -2147221000 };
|
enum { RESULT_NS_ERROR_FACTORY_NOT_LOADED = -2147221000 };
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
|
|
||||||
class nsIJSID : public nsISupports {
|
class nsIJSID : public nsISupports {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSID_IID)
|
||||||
static nsIID iid = NS_IJSID_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* readonly attribute string name; */
|
/* readonly attribute string name; */
|
||||||
NS_IMETHOD GetName(char * *aName) = 0;
|
NS_IMETHOD GetName(char * *aName) = 0;
|
||||||
|
@ -64,10 +61,7 @@ class nsIJSID : public nsISupports {
|
||||||
|
|
||||||
class nsIJSIID : public nsIJSID {
|
class nsIJSIID : public nsIJSID {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSIID_IID)
|
||||||
static nsIID iid = NS_IJSIID_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||||
|
@ -85,13 +79,13 @@ class nsIJSIID : public nsIJSID {
|
||||||
|
|
||||||
class nsIJSCID : public nsIJSID {
|
class nsIJSCID : public nsIJSID {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSCID_IID)
|
||||||
static nsIID iid = NS_IJSCID_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* nsISupports newInstance (); */
|
/* nsISupports createInstance (); */
|
||||||
NS_IMETHOD newInstance(nsISupports **_retval) = 0;
|
NS_IMETHOD createInstance(nsISupports **_retval) = 0;
|
||||||
|
|
||||||
|
/* nsISupports getService (); */
|
||||||
|
NS_IMETHOD getService(nsISupports **_retval) = 0;
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||||
|
|
|
@ -22,18 +22,18 @@
|
||||||
|
|
||||||
class nsITestXPCFoo : public nsISupports {
|
class nsITestXPCFoo : public nsISupports {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITESTXPCFOO_IID)
|
||||||
static nsIID iid = NS_ITESTXPCFOO_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* long Test (in long p1, in long p2); */
|
/* long Test (in long p1, in long p2); */
|
||||||
NS_IMETHOD Test(PRInt32 p1, PRInt32 p2, PRInt32 *_retval) = 0;
|
NS_IMETHOD Test(PRInt32 p1, PRInt32 p2, PRInt32 *_retval) = 0;
|
||||||
|
|
||||||
/* void Test2 (); */
|
/* void Test2 (); */
|
||||||
NS_IMETHOD Test2() = 0;
|
NS_IMETHOD Test2() = 0;
|
||||||
|
|
||||||
enum { one = 1 };
|
enum { one = 1 };
|
||||||
|
|
||||||
enum { five = 5 };
|
enum { five = 5 };
|
||||||
|
|
||||||
enum { six = 6 };
|
enum { six = 6 };
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
|
@ -52,10 +52,7 @@ class nsITestXPCFoo : public nsISupports {
|
||||||
|
|
||||||
class nsITestXPCFoo2 : public nsITestXPCFoo {
|
class nsITestXPCFoo2 : public nsITestXPCFoo {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITESTXPCFOO2_IID)
|
||||||
static nsIID iid = NS_ITESTXPCFOO2_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef XPIDL_JS_STUBS
|
#ifdef XPIDL_JS_STUBS
|
||||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||||
|
@ -73,10 +70,7 @@ class nsITestXPCFoo2 : public nsITestXPCFoo {
|
||||||
|
|
||||||
class nsIEcho : public nsISupports {
|
class nsIEcho : public nsISupports {
|
||||||
public:
|
public:
|
||||||
static const nsIID& GetIID() {
|
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IECHO_IID)
|
||||||
static nsIID iid = NS_IECHO_IID;
|
|
||||||
return iid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* void SetReceiver (in nsIEcho aReceiver); */
|
/* void SetReceiver (in nsIEcho aReceiver); */
|
||||||
NS_IMETHOD SetReceiver(nsIEcho *aReceiver) = 0;
|
NS_IMETHOD SetReceiver(nsIEcho *aReceiver) = 0;
|
|
@ -0,0 +1,2 @@
|
||||||
|
Makefile
|
||||||
|
mk.bat
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!gmake
|
||||||
|
#
|
||||||
|
# The contents of this file are subject to the Netscape Public License
|
||||||
|
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
# http://www.mozilla.org/NPL/
|
||||||
|
#
|
||||||
|
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
# for the specific language governing rights and limitations under the
|
||||||
|
# NPL.
|
||||||
|
#
|
||||||
|
# The Initial Developer of this code under the NPL is Netscape
|
||||||
|
# Communications Corporation. Portions created by Netscape are
|
||||||
|
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
# Reserved.
|
||||||
|
|
||||||
|
DEPTH = ../../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
MODULE = xpcshell
|
||||||
|
|
||||||
|
SIMPLE_PROGRAMS = xpcshell
|
||||||
|
|
||||||
|
CPPSRCS = \
|
||||||
|
xpcshell.cpp \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/config.mk
|
||||||
|
|
||||||
|
DEFINES += -DJS_THREADSAFE
|
||||||
|
|
||||||
|
LIBS = \
|
||||||
|
-L$(DIST)/bin \
|
||||||
|
-l$(MOZ_LIB_JS_PREFIX)js \
|
||||||
|
-lxpcom \
|
||||||
|
-lxpconnect \
|
||||||
|
-lxpt \
|
||||||
|
-lxptinfo \
|
||||||
|
-lxptcall \
|
||||||
|
-lxptcmd \
|
||||||
|
-lreg \
|
||||||
|
-l$(MOZ_LIB_UTIL_PREFIX)util \
|
||||||
|
$(NSPR_LIBS) \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
|
||||||
|
# PROGS = $(OBJDIR)/TestXPC
|
||||||
|
|
||||||
|
# TARGETS= $(PROGS)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
# INCLUDES += -I$(PUBLIC)/xpcom -I$(PUBLIC)/js -I$(PUBLIC)/xpconnect \
|
||||||
|
# -I$(PUBLIC)/raptor
|
||||||
|
|
||||||
|
#$(PROGS): $(OBJS)
|
||||||
|
# @$(MAKE_OBJDIR)
|
||||||
|
# $(CC) -o $@ $(OBJS) $(LD_FLAGS) -L$(DIST)/lib $(LIBS) $(OS_LIBS)
|
||||||
|
|
||||||
|
# export:: $(TARGETS)
|
||||||
|
# $(INSTALL) $(PROGS) $(DIST)/bin
|
||||||
|
# $(INSTALL) $(TEST_FILES) $(DIST)/bin
|
||||||
|
|
||||||
|
# clobber::
|
||||||
|
# rm -f $(DIST)/bin/TestXPC
|
||||||
|
# rm -f $(PROGS) $(OBJS)
|
|
@ -0,0 +1,65 @@
|
||||||
|
#!nmake
|
||||||
|
#
|
||||||
|
# The contents of this file are subject to the Netscape Public License
|
||||||
|
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
# http://www.mozilla.org/NPL/
|
||||||
|
#
|
||||||
|
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
# for the specific language governing rights and limitations under the
|
||||||
|
# NPL.
|
||||||
|
#
|
||||||
|
# The Initial Developer of this code under the NPL is Netscape
|
||||||
|
# Communications Corporation. Portions created by Netscape are
|
||||||
|
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
# Reserved.
|
||||||
|
|
||||||
|
DEPTH=..\..\..\..
|
||||||
|
|
||||||
|
IGNORE_MANIFEST=1
|
||||||
|
|
||||||
|
MAKE_OBJ_TYPE = EXE
|
||||||
|
PROG1 = .\$(OBJDIR)\xpcshell.exe
|
||||||
|
PROGRAMS = $(PROG1)
|
||||||
|
|
||||||
|
LCFLAGS=-DUSE_NSREG -DWIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
|
REQUIRES=xpcom js xpconnect
|
||||||
|
|
||||||
|
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect \
|
||||||
|
-I$(PUBLIC)\raptor -I$(PUBLIC)\xptinfo -I$(PUBLIC)\libxpt
|
||||||
|
|
||||||
|
LLIBS= \
|
||||||
|
$(DIST)\lib\xpcom32.lib \
|
||||||
|
$(LIBNSPR) \
|
||||||
|
$(DIST)\lib\js3250.lib \
|
||||||
|
$(DIST)\lib\xpc3250.lib \
|
||||||
|
$(DIST)\lib\raptorbase.lib \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include <$(DEPTH)\config\rules.mak>
|
||||||
|
|
||||||
|
install:: $(PROGRAMS)
|
||||||
|
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
|
||||||
|
|
||||||
|
clobber::
|
||||||
|
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
|
||||||
|
|
||||||
|
# Move this into config/obj.inc when it's allowed
|
||||||
|
.cpp{.\$(OBJDIR)\}.exe:
|
||||||
|
$(CC) @<<$(CFGFILE)
|
||||||
|
$(CFLAGS)
|
||||||
|
$(LCFLAGS)
|
||||||
|
$(LINCS)
|
||||||
|
$(LINCS_1)
|
||||||
|
$(INCS)
|
||||||
|
$(LLIBS)
|
||||||
|
$(OS_LIBS)
|
||||||
|
-Fd$(PDBFILE)
|
||||||
|
-Fe.\$(OBJDIR)\
|
||||||
|
-Fo.\$(OBJDIR)\
|
||||||
|
$(CURDIR)$(*B).cpp
|
||||||
|
<<KEEP
|
||||||
|
|
||||||
|
$(PROG1): $(OBJDIR) xpcshell.cpp
|
|
@ -0,0 +1,495 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* XPConnect JavaScript interactive shell. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "nsIXPConnect.h"
|
||||||
|
#include "nsIXPCScriptable.h"
|
||||||
|
#include "nsIInterfaceInfo.h"
|
||||||
|
#include "nsIInterfaceInfoManager.h"
|
||||||
|
#include "nsIXPCScriptable.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
#include "jsapi.h"
|
||||||
|
#include "xpclog.h"
|
||||||
|
#include "nscore.h"
|
||||||
|
#include "nsIAllocator.h"
|
||||||
|
#include "nsIGenericFactory.h"
|
||||||
|
|
||||||
|
// all this crap is needed to do the interactive shell stuff
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#ifdef XP_PC
|
||||||
|
#include <io.h> /* for isatty() */
|
||||||
|
#endif
|
||||||
|
#include "jsparse.h"
|
||||||
|
#include "jsscan.h"
|
||||||
|
#include "jsemit.h"
|
||||||
|
#include "jsscript.h"
|
||||||
|
#include "jsarena.h"
|
||||||
|
#include "jscntxt.h"
|
||||||
|
|
||||||
|
#include "nsSpecialSystemDirectory.h" // For exe dir
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
|
||||||
|
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||||
|
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||||
|
|
||||||
|
#ifdef XP_PC
|
||||||
|
#define XPCOM_DLL "xpcom32.dll"
|
||||||
|
#else
|
||||||
|
#ifdef XP_MAC
|
||||||
|
#define XPCOM_DLL "XPCOM_DLL"
|
||||||
|
#else
|
||||||
|
#define XPCOM_DLL "libxpcom.so"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void SetupRegistry()
|
||||||
|
{
|
||||||
|
// Autoregistration happens here. The rest of RegisterComponent() calls should happen
|
||||||
|
// only for dlls not in the components directory.
|
||||||
|
|
||||||
|
// Create exeDir/"components"
|
||||||
|
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||||
|
sysdir += "components";
|
||||||
|
const char *componentsDir = sysdir.GetCString(); // native path
|
||||||
|
if (componentsDir != NULL)
|
||||||
|
{
|
||||||
|
#ifdef XP_PC
|
||||||
|
/* The PC version of the directory from filePath is of the form
|
||||||
|
* /y|/moz/mozilla/dist/bin/components
|
||||||
|
* We need to remove the initial / and change the | to :
|
||||||
|
* for all this to work with NSPR.
|
||||||
|
*/
|
||||||
|
#endif /* XP_PC */
|
||||||
|
printf("nsComponentManager: Using components dir: %s\n", componentsDir);
|
||||||
|
|
||||||
|
#ifdef XP_MAC
|
||||||
|
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, nsnull);
|
||||||
|
#else
|
||||||
|
nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, componentsDir);
|
||||||
|
#endif /* XP_MAC */
|
||||||
|
// XXX Look for user specific components
|
||||||
|
// XXX UNIX: ~/.mozilla/components
|
||||||
|
}
|
||||||
|
|
||||||
|
// nsComponentManager::RegisterComponent(kAllocatorCID, NULL, NULL,
|
||||||
|
// XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||||
|
|
||||||
|
nsComponentManager::RegisterComponent(kAllocatorCID, NULL, "allocator",
|
||||||
|
XPCOM_DLL, PR_TRUE, PR_TRUE);
|
||||||
|
|
||||||
|
nsComponentManager::RegisterComponent(kGenericFactoryCID, NULL, NULL,
|
||||||
|
XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||||
|
}
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
FILE *gOutFile = NULL;
|
||||||
|
FILE *gErrFile = NULL;
|
||||||
|
|
||||||
|
static void
|
||||||
|
my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||||
|
{
|
||||||
|
printf(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
uintN i, n;
|
||||||
|
JSString *str;
|
||||||
|
|
||||||
|
for (i = n = 0; i < argc; i++) {
|
||||||
|
str = JS_ValueToString(cx, argv[i]);
|
||||||
|
if (!str)
|
||||||
|
return JS_FALSE;
|
||||||
|
fprintf(gOutFile, "%s%s", i ? " " : "", JS_GetStringBytes(str));
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
if (n)
|
||||||
|
fputc('\n', gOutFile);
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
Load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
uintN i;
|
||||||
|
JSString *str;
|
||||||
|
const char *filename;
|
||||||
|
JSScript *script;
|
||||||
|
JSBool ok;
|
||||||
|
jsval result;
|
||||||
|
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
str = JS_ValueToString(cx, argv[i]);
|
||||||
|
if (!str)
|
||||||
|
return JS_FALSE;
|
||||||
|
argv[i] = STRING_TO_JSVAL(str);
|
||||||
|
filename = JS_GetStringBytes(str);
|
||||||
|
script = JS_CompileFile(cx, obj, filename);
|
||||||
|
if (!script)
|
||||||
|
ok = JS_FALSE;
|
||||||
|
else {
|
||||||
|
ok = JS_ExecuteScript(cx, obj, script, &result);
|
||||||
|
JS_DestroyScript(cx, script);
|
||||||
|
}
|
||||||
|
if (!ok)
|
||||||
|
return JS_FALSE;
|
||||||
|
}
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
Version(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
if (argc > 0 && JSVAL_IS_INT(argv[0]))
|
||||||
|
*rval = INT_TO_JSVAL(JS_SetVersion(cx, JSVersion(JSVAL_TO_INT(argv[0]))));
|
||||||
|
else
|
||||||
|
*rval = INT_TO_JSVAL(JS_GetVersion(cx));
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
BuildDate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
fprintf(gOutFile, "built on %s at %s\n", __DATE__, __TIME__);
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSBool
|
||||||
|
Quit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
#ifdef LIVECONNECT
|
||||||
|
JSJ_SimpleShutdown();
|
||||||
|
#endif
|
||||||
|
exit(0);
|
||||||
|
return JS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSFunctionSpec glob_functions[] = {
|
||||||
|
{"print", Print, 0},
|
||||||
|
{"load", Load, 1},
|
||||||
|
{"quit", Quit, 0},
|
||||||
|
{"version", Version, 1},
|
||||||
|
{"build", BuildDate, 0},
|
||||||
|
{0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static JSClass global_class = {
|
||||||
|
"global", 0,
|
||||||
|
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||||
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
||||||
|
};
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
Process(JSContext *cx, JSObject *obj, char *filename)
|
||||||
|
{
|
||||||
|
JSTokenStream *ts;
|
||||||
|
JSCodeGenerator cg;
|
||||||
|
JSBool ok;
|
||||||
|
JSScript *script;
|
||||||
|
jsval result;
|
||||||
|
JSString *str;
|
||||||
|
|
||||||
|
ts = js_NewFileTokenStream(cx, filename, stdin);
|
||||||
|
if (!ts)
|
||||||
|
goto out;
|
||||||
|
#ifdef JSDEBUGGER
|
||||||
|
if (!filename)
|
||||||
|
ts->filename = "typein";
|
||||||
|
#endif
|
||||||
|
if (isatty(fileno(ts->file))) {
|
||||||
|
ts->flags |= TSF_INTERACTIVE;
|
||||||
|
} else {
|
||||||
|
/* Support the UNIX #! shell hack; gobble the first line if it starts
|
||||||
|
* with '#'. TODO - this isn't quite compatible with sharp variables,
|
||||||
|
* as a legal js program (using sharp variables) might start with '#'.
|
||||||
|
* But that would require multi-character lookahead.
|
||||||
|
*/
|
||||||
|
int ch = fgetc(ts->file);
|
||||||
|
if (ch == '#') {
|
||||||
|
while((ch = fgetc(ts->file)) != EOF) {
|
||||||
|
if(ch == '\n' || ch == '\r')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ungetc(ch, ts->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
js_InitCodeGenerator(cx, &cg, ts->filename, ts->lineno, ts->principals);
|
||||||
|
do {
|
||||||
|
if (ts->flags & TSF_INTERACTIVE)
|
||||||
|
fprintf(gOutFile, "js> ");
|
||||||
|
ok = js_CompileTokenStream(cx, obj, ts, &cg);
|
||||||
|
if (ts->flags & TSF_ERROR) {
|
||||||
|
ts->flags &= ~TSF_ERROR;
|
||||||
|
CLEAR_PUSHBACK(ts);
|
||||||
|
ok = JS_TRUE;
|
||||||
|
}
|
||||||
|
} while (ok && !(ts->flags & TSF_EOF) && CG_OFFSET(&cg) == 0);
|
||||||
|
if (ok) {
|
||||||
|
/* Clear any pending exception from previous failed compiles. */
|
||||||
|
JS_ClearPendingException(cx);
|
||||||
|
|
||||||
|
script = js_NewScriptFromCG(cx, &cg, NULL);
|
||||||
|
if (script) {
|
||||||
|
JSErrorReporter older;
|
||||||
|
|
||||||
|
ok = JS_ExecuteScript(cx, obj, script, &result);
|
||||||
|
if (ok &&
|
||||||
|
(ts->flags & TSF_INTERACTIVE) &&
|
||||||
|
result != JSVAL_VOID) {
|
||||||
|
/*
|
||||||
|
* If JS_ValueToString generates an error, suppress
|
||||||
|
* the report and print the exception below.
|
||||||
|
*/
|
||||||
|
older = JS_SetErrorReporter(cx, NULL);
|
||||||
|
str = JS_ValueToString(cx, result);
|
||||||
|
JS_SetErrorReporter(cx, older);
|
||||||
|
|
||||||
|
if (str)
|
||||||
|
fprintf(gOutFile, "%s\n", JS_GetStringBytes(str));
|
||||||
|
else
|
||||||
|
ok = JS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if JS_HAS_ERROR_EXCEPTIONS
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
* Require that any time we return failure, an exception has
|
||||||
|
* been set.
|
||||||
|
*/
|
||||||
|
JS_ASSERT(ok || JS_IsExceptionPending(cx));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Also that any time an exception has been set, we've
|
||||||
|
* returned failure.
|
||||||
|
*/
|
||||||
|
JS_ASSERT(!JS_IsExceptionPending(cx) || !ok);
|
||||||
|
#endif
|
||||||
|
#endif /* JS_HAS_ERROR_EXCEPTIONS */
|
||||||
|
JS_DestroyScript(cx, script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cg.firstLine = ts->lineno;
|
||||||
|
js_FinishCodeGenerator(cx, &cg);
|
||||||
|
RESET_TOKENBUF(ts);
|
||||||
|
} while (!(ts->flags & TSF_EOF));
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (ts)
|
||||||
|
(void) js_CloseTokenStream(cx, ts);
|
||||||
|
JS_FreeArenaPool(&cx->codePool);
|
||||||
|
JS_FreeArenaPool(&cx->tempPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
fprintf(gErrFile, "%s\n", JS_GetImplementationVersion());
|
||||||
|
fprintf(gErrFile, "usage: js [-w] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int reportWarnings;
|
||||||
|
|
||||||
|
static int
|
||||||
|
ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *filename = NULL;
|
||||||
|
jsint length;
|
||||||
|
jsval *vector;
|
||||||
|
jsval *p;
|
||||||
|
JSObject *argsObj;
|
||||||
|
JSBool isInteractive = JS_TRUE;
|
||||||
|
|
||||||
|
for (i=0; i < argc; i++) {
|
||||||
|
if (argv[i][0] == '-') {
|
||||||
|
switch (argv[i][1]) {
|
||||||
|
case 'v':
|
||||||
|
if (i+1 == argc) {
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
JS_SetVersion(cx, JSVersion(atoi(argv[i+1])));
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
reportWarnings++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
if (i+1 == argc) {
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
filename = argv[i+1];
|
||||||
|
/* "-f -" means read from stdin */
|
||||||
|
if (filename[0] == '-' && filename[1] == '\0')
|
||||||
|
filename = NULL;
|
||||||
|
Process(cx, obj, filename);
|
||||||
|
filename = NULL;
|
||||||
|
/* XXX: js -f foo.js should interpret foo.js and then
|
||||||
|
* drop into interactive mode, but that breaks test
|
||||||
|
* harness. Just execute foo.js for now.
|
||||||
|
*/
|
||||||
|
isInteractive = JS_FALSE;
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filename = argv[i++];
|
||||||
|
isInteractive = JS_FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
length = argc - i;
|
||||||
|
vector = (jsval*) JS_malloc(cx, length * sizeof(jsval));
|
||||||
|
p = vector;
|
||||||
|
|
||||||
|
if (vector == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
while (i < argc) {
|
||||||
|
JSString *str = JS_NewStringCopyZ(cx, argv[i]);
|
||||||
|
if (str == NULL)
|
||||||
|
return 1;
|
||||||
|
*p++ = STRING_TO_JSVAL(str);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
argsObj = JS_NewArrayObject(cx, length, vector);
|
||||||
|
JS_free(cx, vector);
|
||||||
|
if (argsObj == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!JS_DefineProperty(cx, obj, "arguments",
|
||||||
|
OBJECT_TO_JSVAL(argsObj), NULL, NULL, 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (filename || isInteractive)
|
||||||
|
Process(cx, obj, filename);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
JSRuntime *rt;
|
||||||
|
JSContext *jscontext;
|
||||||
|
JSObject *glob;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
gErrFile = stderr;
|
||||||
|
gOutFile = stdout;
|
||||||
|
|
||||||
|
SetupRegistry();
|
||||||
|
|
||||||
|
rt = JS_NewRuntime(8L * 1024L * 1024L);
|
||||||
|
if (!rt)
|
||||||
|
return 1;
|
||||||
|
jscontext = JS_NewContext(rt, 8192);
|
||||||
|
if (!jscontext)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
JS_SetErrorReporter(jscontext, my_ErrorReporter);
|
||||||
|
|
||||||
|
nsIXPConnect* xpc = XPC_GetXPConnect();
|
||||||
|
if(!xpc)
|
||||||
|
{
|
||||||
|
printf("XPC_GetXPConnect() returned NULL!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glob = JS_NewObject(jscontext, &global_class, NULL, NULL);
|
||||||
|
if (!glob)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!JS_InitStandardClasses(jscontext, glob))
|
||||||
|
return 1;
|
||||||
|
if (!JS_DefineFunctions(jscontext, glob, glob_functions))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
xpc->InitJSContext(jscontext, glob, JS_TRUE);
|
||||||
|
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
result = ProcessArgs(jscontext, glob, argv, argc);
|
||||||
|
|
||||||
|
NS_RELEASE(xpc);
|
||||||
|
JS_DestroyContext(jscontext);
|
||||||
|
JS_DestroyRuntime(rt);
|
||||||
|
JS_ShutDown();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
#include "jsatom.h"
|
||||||
|
#ifdef DEBUG
|
||||||
|
int
|
||||||
|
DumpAtom(JSHashEntry *he, int i, void *arg)
|
||||||
|
{
|
||||||
|
FILE *fp = (FILE *)arg;
|
||||||
|
JSAtom *atom = (JSAtom *)he;
|
||||||
|
|
||||||
|
fprintf(fp, "%3d %08x %5lu ",
|
||||||
|
i, (uintN)he->keyHash, (unsigned long)atom->number);
|
||||||
|
if (ATOM_IS_STRING(atom))
|
||||||
|
fprintf(fp, "\"%s\"\n", ATOM_BYTES(atom));
|
||||||
|
else if (ATOM_IS_INT(atom))
|
||||||
|
fprintf(fp, "%ld\n", (long)ATOM_TO_INT(atom));
|
||||||
|
else
|
||||||
|
fprintf(fp, "%.16g\n", *ATOM_TO_DOUBLE(atom));
|
||||||
|
return HT_ENUMERATE_NEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
DumpSymbol(JSHashEntry *he, int i, void *arg)
|
||||||
|
{
|
||||||
|
FILE *fp = (FILE *)arg;
|
||||||
|
JSSymbol *sym = (JSSymbol *)he;
|
||||||
|
|
||||||
|
fprintf(fp, "%3d %08x", i, (uintN)he->keyHash);
|
||||||
|
if (JSVAL_IS_INT(sym_id(sym)))
|
||||||
|
fprintf(fp, " [%ld]\n", (long)JSVAL_TO_INT(sym_id(sym)));
|
||||||
|
else
|
||||||
|
fprintf(fp, " \"%s\"\n", ATOM_BYTES(sym_atom(sym)));
|
||||||
|
return HT_ENUMERATE_NEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* These are callable from gdb. */
|
||||||
|
JS_BEGIN_EXTERN_C
|
||||||
|
void Dsym(JSSymbol *sym) { if (sym) DumpSymbol(&sym->entry, 0, gErrFile); }
|
||||||
|
void Datom(JSAtom *atom) { if (atom) DumpAtom(&atom->entry, 0, gErrFile); }
|
||||||
|
void Dobj(nsISupports* p, int depth) {if(p)XPC_DUMP(p,depth);}
|
||||||
|
void Dxpc(int depth) {Dobj(XPC_GetXPConnect(), depth);}
|
||||||
|
JS_END_EXTERN_C
|
||||||
|
#endif
|
|
@ -29,6 +29,8 @@
|
||||||
static NS_DEFINE_IID(kXPConnectIID, NS_IXPCONNECT_IID);
|
static NS_DEFINE_IID(kXPConnectIID, NS_IXPCONNECT_IID);
|
||||||
NS_IMPL_ISUPPORTS(nsXPConnect, kXPConnectIID)
|
NS_IMPL_ISUPPORTS(nsXPConnect, kXPConnectIID)
|
||||||
|
|
||||||
|
const char* XPC_COMPONENTS_STR = "Components";
|
||||||
|
|
||||||
nsXPConnect* nsXPConnect::mSelf = NULL;
|
nsXPConnect* nsXPConnect::mSelf = NULL;
|
||||||
|
|
||||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||||
|
@ -192,18 +194,24 @@ nsXPConnect::~nsXPConnect()
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXPConnect::InitJSContext(JSContext* aJSContext,
|
nsXPConnect::InitJSContext(JSContext* aJSContext,
|
||||||
JSObject* aGlobalJSObj)
|
JSObject* aGlobalJSObj,
|
||||||
|
JSBool AddComponentsObject)
|
||||||
{
|
{
|
||||||
if(aJSContext)
|
if(!aJSContext)
|
||||||
{
|
{
|
||||||
if(!aGlobalJSObj)
|
XPC_LOG_ERROR(("nsXPConnect::InitJSContext failed with null pointer"));
|
||||||
aGlobalJSObj = JS_GetGlobalObject(aJSContext);
|
return NS_ERROR_NULL_POINTER;
|
||||||
if(aGlobalJSObj &&
|
}
|
||||||
!mContextMap->Find(aJSContext) &&
|
|
||||||
NewContext(aJSContext, aGlobalJSObj))
|
if(!aGlobalJSObj)
|
||||||
{
|
aGlobalJSObj = JS_GetGlobalObject(aJSContext);
|
||||||
return NS_OK;
|
if(aGlobalJSObj &&
|
||||||
}
|
!mContextMap->Find(aJSContext) &&
|
||||||
|
NewContext(aJSContext, aGlobalJSObj)&&
|
||||||
|
(!AddComponentsObject ||
|
||||||
|
NS_SUCCEEDED(AddNewComponentsObject(aJSContext, aGlobalJSObj))))
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
XPC_LOG_ERROR(("nsXPConnect::InitJSContext failed"));
|
XPC_LOG_ERROR(("nsXPConnect::InitJSContext failed"));
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -213,6 +221,7 @@ NS_IMETHODIMP
|
||||||
nsXPConnect::InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
nsXPConnect::InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
||||||
nsISupports* aCOMObj,
|
nsISupports* aCOMObj,
|
||||||
REFNSIID aIID,
|
REFNSIID aIID,
|
||||||
|
JSBool AddComponentsObject,
|
||||||
nsIXPConnectWrappedNative** aWrapper)
|
nsIXPConnectWrappedNative** aWrapper)
|
||||||
{
|
{
|
||||||
nsXPCWrappedNative* wrapper = NULL;
|
nsXPCWrappedNative* wrapper = NULL;
|
||||||
|
@ -224,7 +233,9 @@ nsXPConnect::InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
||||||
if(wrapper)
|
if(wrapper)
|
||||||
{
|
{
|
||||||
if(JS_InitStandardClasses(aJSContext, wrapper->GetJSObject()) &&
|
if(JS_InitStandardClasses(aJSContext, wrapper->GetJSObject()) &&
|
||||||
xpcc->Init(wrapper->GetJSObject()))
|
xpcc->Init(wrapper->GetJSObject()) &&
|
||||||
|
(!AddComponentsObject ||
|
||||||
|
NS_SUCCEEDED(AddNewComponentsObject(aJSContext, NULL))))
|
||||||
{
|
{
|
||||||
*aWrapper = wrapper;
|
*aWrapper = wrapper;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -243,6 +254,49 @@ nsXPConnect::InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsXPConnect::AddNewComponentsObject(JSContext* aJSContext,
|
||||||
|
JSObject* aGlobalJSObj)
|
||||||
|
{
|
||||||
|
JSBool success;
|
||||||
|
|
||||||
|
if(!aJSContext)
|
||||||
|
{
|
||||||
|
XPC_LOG_ERROR(("nsXPConnect::AddNewComponentsObject failed with null pointer"));
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!aGlobalJSObj && !(aGlobalJSObj = JS_GetGlobalObject(aJSContext)))
|
||||||
|
{
|
||||||
|
XPC_LOG_ERROR(("nsXPConnect::AddNewComponentsObject failed - no global object"));
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIXPCComponents* comp = XPC_GetXPConnectComponentsObject();
|
||||||
|
if(!comp)
|
||||||
|
{
|
||||||
|
XPC_LOG_ERROR(("nsXPConnect::AddNewComponentsObject failed - could create component object"));
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIXPConnectWrappedNative* comp_wrapper;
|
||||||
|
if(NS_FAILED(WrapNative(aJSContext, comp,
|
||||||
|
nsIXPCComponents::GetIID(), &comp_wrapper)))
|
||||||
|
{
|
||||||
|
XPC_LOG_ERROR(("nsXPConnect::AddNewComponentsObject failed - could not build wrapper"));
|
||||||
|
NS_RELEASE(comp);
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
JSObject* comp_jsobj;
|
||||||
|
comp_wrapper->GetJSObject(&comp_jsobj);
|
||||||
|
jsval comp_jsval = OBJECT_TO_JSVAL(comp_jsobj);
|
||||||
|
success = JS_SetProperty(aJSContext, aGlobalJSObj,
|
||||||
|
"Components", &comp_jsval);
|
||||||
|
NS_RELEASE(comp_wrapper);
|
||||||
|
NS_RELEASE(comp);
|
||||||
|
return success ? NS_OK : NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
XPCContext*
|
XPCContext*
|
||||||
nsXPConnect::NewContext(JSContext* cx, JSObject* global,
|
nsXPConnect::NewContext(JSContext* cx, JSObject* global,
|
||||||
JSBool doInit /*= JS_TRUE*/)
|
JSBool doInit /*= JS_TRUE*/)
|
||||||
|
|
|
@ -409,7 +409,7 @@ nsJSCID::toString(char **_retval)
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSCID::newInstance(nsISupports **_retval)
|
nsJSCID::createInstance(nsISupports **_retval)
|
||||||
{
|
{
|
||||||
if(!_retval)
|
if(!_retval)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
@ -423,6 +423,26 @@ nsJSCID::newInstance(nsISupports **_retval)
|
||||||
(void**) _retval);
|
(void**) _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX this does not yet address the issue of using the SM to release
|
||||||
|
// XXX this does not yet address the issue of security protections
|
||||||
|
// XXX we'll need to make createInstance and getService dynamic to
|
||||||
|
// support both of these issues
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsJSCID::getService(nsISupports **_retval)
|
||||||
|
{
|
||||||
|
if(!_retval)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
*_retval = NULL;
|
||||||
|
if(mID.Equals(GetInvalidIID()))
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
return nsServiceManager::GetService(mID,
|
||||||
|
nsISupports::GetIID(),
|
||||||
|
_retval, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
// additional utilities...
|
// additional utilities...
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@
|
||||||
#include "xpcjsid.h"
|
#include "xpcjsid.h"
|
||||||
#include "prlong.h"
|
#include "prlong.h"
|
||||||
|
|
||||||
extern const char* XPC_VAL_STR; // 'value' property name for out params
|
extern const char* XPC_VAL_STR; // 'value' property name for out params
|
||||||
|
extern const char* XPC_COMPONENTS_STR; // 'Components' property name
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
|
@ -54,13 +55,18 @@ class nsXPConnect : public nsIXPConnect
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
NS_IMETHOD InitJSContext(JSContext* aJSContext,
|
NS_IMETHOD InitJSContext(JSContext* aJSContext,
|
||||||
JSObject* aGlobalJSObj);
|
JSObject* aGlobalJSObj,
|
||||||
|
JSBool AddComponentsObject);
|
||||||
|
|
||||||
NS_IMETHOD InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
NS_IMETHOD InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
|
||||||
nsISupports* aCOMObj,
|
nsISupports* aCOMObj,
|
||||||
REFNSIID aIID,
|
REFNSIID aIID,
|
||||||
|
JSBool AddComponentsObject,
|
||||||
nsIXPConnectWrappedNative** aWrapper);
|
nsIXPConnectWrappedNative** aWrapper);
|
||||||
|
|
||||||
|
NS_IMETHOD AddNewComponentsObject(JSContext* aJSContext,
|
||||||
|
JSObject* aGlobalJSObj);
|
||||||
|
|
||||||
NS_IMETHOD WrapNative(JSContext* aJSContext,
|
NS_IMETHOD WrapNative(JSContext* aJSContext,
|
||||||
nsISupports* aCOMObj,
|
nsISupports* aCOMObj,
|
||||||
REFNSIID aIID,
|
REFNSIID aIID,
|
||||||
|
@ -530,6 +536,7 @@ class nsXPCWrappedNative : public nsIXPConnectWrappedNative
|
||||||
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
|
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
|
||||||
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
|
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
|
||||||
NS_IMETHOD DebugDump(int depth);
|
NS_IMETHOD DebugDump(int depth);
|
||||||
|
NS_IMETHOD SetFinalizeListener(nsIXPConnectFinalizeListener* aListener);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static nsXPCWrappedNative* GetNewOrUsedWrapper(XPCContext* xpcc,
|
static nsXPCWrappedNative* GetNewOrUsedWrapper(XPCContext* xpcc,
|
||||||
|
@ -564,6 +571,7 @@ private:
|
||||||
nsIXPCScriptable* mDynamicScriptable; // only set in root!
|
nsIXPCScriptable* mDynamicScriptable; // only set in root!
|
||||||
nsXPCWrappedNative* mRoot;
|
nsXPCWrappedNative* mRoot;
|
||||||
nsXPCWrappedNative* mNext;
|
nsXPCWrappedNative* mNext;
|
||||||
|
nsIXPConnectFinalizeListener* mFinalizeListener;
|
||||||
};
|
};
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
@ -670,8 +678,11 @@ public:
|
||||||
/* boolean init (in string idString); */
|
/* boolean init (in string idString); */
|
||||||
NS_IMETHOD init(const char *idString, PRBool *_retval);
|
NS_IMETHOD init(const char *idString, PRBool *_retval);
|
||||||
|
|
||||||
/* nsISupports newInstance (); */
|
/* nsISupports createInstance (); */
|
||||||
NS_IMETHOD newInstance(nsISupports **_retval);
|
NS_IMETHOD createInstance(nsISupports **_retval);
|
||||||
|
|
||||||
|
/* nsISupports getService (); */
|
||||||
|
NS_IMETHOD getService(nsISupports **_retval);
|
||||||
|
|
||||||
/* string toString (); */
|
/* string toString (); */
|
||||||
NS_IMETHOD toString(char **_retval);
|
NS_IMETHOD toString(char **_retval);
|
||||||
|
|
|
@ -93,7 +93,7 @@ XPCJSThrower::ThrowBadResultException(JSContext* cx,
|
||||||
|
|
||||||
format = mFormats[XPCJSError::NATIVE_RETURNED_FAILURE].format;
|
format = mFormats[XPCJSError::NATIVE_RETURNED_FAILURE].format;
|
||||||
|
|
||||||
sz = JS_smprintf("%s %x", format, result);
|
sz = JS_smprintf("%s 0x%x", format, result);
|
||||||
|
|
||||||
if(sz && mVerbose)
|
if(sz && mVerbose)
|
||||||
Verbosify(cx, clazz, desc, &sz, PR_TRUE);
|
Verbosify(cx, clazz, desc, &sz, PR_TRUE);
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public License
|
|
||||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
||||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
||||||
* http://www.mozilla.org/NPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
||||||
* for the specific language governing rights and limitations under the
|
|
||||||
* NPL.
|
|
||||||
*
|
|
||||||
* The Initial Developer of this code under the NPL is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
||||||
* Reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Module local methods to use 'standard' interfaces in other modules. */
|
|
||||||
|
|
||||||
#include "xpcprivate.h"
|
|
||||||
|
|
||||||
// all these methods are class statics
|
|
||||||
|
|
||||||
nsIAllocator* XPCMem::Allocator()
|
|
||||||
{
|
|
||||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
|
||||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
|
||||||
static nsIAllocator* al = NULL;
|
|
||||||
if(!al)
|
|
||||||
nsServiceManager::GetService(kAllocatorCID, kIAllocatorIID,
|
|
||||||
(nsISupports **)&al);
|
|
||||||
NS_ASSERTION(al, "failed to get Allocator!");
|
|
||||||
return al;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* XPCMem::Alloc(PRUint32 size)
|
|
||||||
{return Allocator()->Alloc(size);}
|
|
||||||
|
|
||||||
void* XPCMem::Realloc(void* ptr, PRUint32 size)
|
|
||||||
{return Allocator()->Realloc(ptr, size);}
|
|
||||||
|
|
||||||
void XPCMem::Free(void* ptr)
|
|
||||||
{Allocator()->Free(ptr);}
|
|
||||||
|
|
||||||
void XPCMem::HeapMinimize()
|
|
||||||
{Allocator()->HeapMinimize();}
|
|
||||||
|
|
||||||
void* XPCMem::Clone(const void* ptr, PRUint32 size)
|
|
||||||
{
|
|
||||||
if(!ptr) return NULL;
|
|
||||||
void* p = Allocator()->Alloc(size);
|
|
||||||
if(p) memcpy(p, ptr, size);
|
|
||||||
return p;
|
|
||||||
}
|
|
|
@ -201,8 +201,8 @@ nsXPCWrappedNative::nsXPCWrappedNative(nsISupports* aObj,
|
||||||
mClass(aClass),
|
mClass(aClass),
|
||||||
mDynamicScriptable(NULL),
|
mDynamicScriptable(NULL),
|
||||||
mRoot(root ? root : this),
|
mRoot(root ? root : this),
|
||||||
mNext(NULL)
|
mNext(NULL),
|
||||||
|
mFinalizeListener(NULL)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(mObj, "bad object to wrap");
|
NS_PRECONDITION(mObj, "bad object to wrap");
|
||||||
NS_PRECONDITION(mClass, "bad class for wrapper");
|
NS_PRECONDITION(mClass, "bad class for wrapper");
|
||||||
|
@ -272,6 +272,12 @@ nsXPCWrappedNative::~nsXPCWrappedNative()
|
||||||
NS_RELEASE(mDynamicScriptable);
|
NS_RELEASE(mDynamicScriptable);
|
||||||
if(mClass)
|
if(mClass)
|
||||||
NS_RELEASE(mClass);
|
NS_RELEASE(mClass);
|
||||||
|
if(mFinalizeListener)
|
||||||
|
{
|
||||||
|
if(mObj)
|
||||||
|
mFinalizeListener->AboutToRelease(mObj);
|
||||||
|
NS_RELEASE(mFinalizeListener);
|
||||||
|
}
|
||||||
if(mObj)
|
if(mObj)
|
||||||
NS_RELEASE(mObj);
|
NS_RELEASE(mObj);
|
||||||
}
|
}
|
||||||
|
@ -369,6 +375,22 @@ nsXPCWrappedNative::GetIID(nsIID** iid)
|
||||||
return *iid ? NS_OK : NS_ERROR_UNEXPECTED;
|
return *iid ? NS_OK : NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsXPCWrappedNative::SetFinalizeListener(nsIXPConnectFinalizeListener* aListener)
|
||||||
|
{
|
||||||
|
if(mFinalizeListener && aListener)
|
||||||
|
{
|
||||||
|
NS_ASSERTION(0,"tried to set two FinalizeListeners on a wrapper");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
if(mFinalizeListener)
|
||||||
|
NS_RELEASE(mFinalizeListener);
|
||||||
|
mFinalizeListener = aListener;
|
||||||
|
if(mFinalizeListener)
|
||||||
|
NS_ADDREF(mFinalizeListener);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXPCWrappedNative::DebugDump(int depth)
|
nsXPCWrappedNative::DebugDump(int depth)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1204,11 +1204,13 @@ JSBool
|
||||||
nsXPCWrappedNativeClass::InitForContext(XPCContext* xpcc)
|
nsXPCWrappedNativeClass::InitForContext(XPCContext* xpcc)
|
||||||
{
|
{
|
||||||
// XXX do we really want this class init'd this way? access to ctor?
|
// XXX do we really want this class init'd this way? access to ctor?
|
||||||
|
/* NO
|
||||||
if (!JS_InitClass(xpcc->GetJSContext(), xpcc->GetGlobalObject(),
|
if (!JS_InitClass(xpcc->GetJSContext(), xpcc->GetGlobalObject(),
|
||||||
0, &WrappedNative_class, 0, 0,
|
0, &WrappedNative_class, 0, 0,
|
||||||
0, 0,
|
0, 0,
|
||||||
0, 0))
|
0, 0))
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
|
*/
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ topsrcdir = @top_srcdir@
|
||||||
VPATH = @srcdir@
|
VPATH = @srcdir@
|
||||||
srcdir = @srcdir@
|
srcdir = @srcdir@
|
||||||
|
|
||||||
|
DIRS = components
|
||||||
|
|
||||||
include $(DEPTH)/config/autoconf.mk
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
MODULE = TestXPC
|
MODULE = TestXPC
|
||||||
|
@ -51,7 +53,7 @@ LIBS = \
|
||||||
|
|
||||||
# PROGS = $(OBJDIR)/TestXPC
|
# PROGS = $(OBJDIR)/TestXPC
|
||||||
|
|
||||||
TEST_FILES = testxpc.js
|
TEST_FILES = testxpc.js xpctest_echo.js
|
||||||
|
|
||||||
# TARGETS= $(PROGS)
|
# TARGETS= $(PROGS)
|
||||||
|
|
||||||
|
|
|
@ -522,8 +522,9 @@ int main()
|
||||||
if (!JS_DefineFunctions(jscontext, glob, glob_functions))
|
if (!JS_DefineFunctions(jscontext, glob, glob_functions))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
xpc->InitJSContext(jscontext, glob);
|
xpc->InitJSContext(jscontext, glob, JS_TRUE);
|
||||||
|
|
||||||
|
#if 0
|
||||||
nsIXPCComponents* comp = XPC_GetXPConnectComponentsObject();
|
nsIXPCComponents* comp = XPC_GetXPConnectComponentsObject();
|
||||||
if(!comp)
|
if(!comp)
|
||||||
{
|
{
|
||||||
|
@ -543,7 +544,7 @@ int main()
|
||||||
JS_SetProperty(jscontext, glob, "Components", &comp_jsval);
|
JS_SetProperty(jscontext, glob, "Components", &comp_jsval);
|
||||||
NS_RELEASE(comp_wrapper);
|
NS_RELEASE(comp_wrapper);
|
||||||
NS_RELEASE(comp);
|
NS_RELEASE(comp);
|
||||||
|
#endif
|
||||||
|
|
||||||
char* txt[] = {
|
char* txt[] = {
|
||||||
"load('simpletest.js');",
|
"load('simpletest.js');",
|
||||||
|
@ -578,12 +579,12 @@ int main()
|
||||||
*/
|
*/
|
||||||
// new code where global object is a wrapped xpcom object
|
// new code where global object is a wrapped xpcom object
|
||||||
if(NS_SUCCEEDED(xpc->InitJSContextWithNewWrappedGlobal(
|
if(NS_SUCCEEDED(xpc->InitJSContextWithNewWrappedGlobal(
|
||||||
jscontext, foo, nsITestXPCFoo::GetIID(), &wrapper)))
|
jscontext, foo, nsITestXPCFoo::GetIID(), JS_TRUE, &wrapper)))
|
||||||
{
|
{
|
||||||
wrapper->GetJSObject(&glob);
|
wrapper->GetJSObject(&glob);
|
||||||
JS_DefineFunctions(jscontext, glob, glob_functions);
|
JS_DefineFunctions(jscontext, glob, glob_functions);
|
||||||
|
|
||||||
|
#if 0
|
||||||
nsIXPCComponents* comp = XPC_GetXPConnectComponentsObject();
|
nsIXPCComponents* comp = XPC_GetXPConnectComponentsObject();
|
||||||
if(!comp)
|
if(!comp)
|
||||||
{
|
{
|
||||||
|
@ -603,7 +604,7 @@ int main()
|
||||||
JS_SetProperty(jscontext, glob, "Components", &comp_jsval);
|
JS_SetProperty(jscontext, glob, "Components", &comp_jsval);
|
||||||
NS_RELEASE(comp_wrapper);
|
NS_RELEASE(comp_wrapper);
|
||||||
NS_RELEASE(comp);
|
NS_RELEASE(comp);
|
||||||
|
#endif
|
||||||
|
|
||||||
nsTestXPCFoo* fool = new nsTestXPCFoo();
|
nsTestXPCFoo* fool = new nsTestXPCFoo();
|
||||||
xpc->WrapNative(jscontext, fool, nsITestXPCFoo2::GetIID(), &fool_wrapper);
|
xpc->WrapNative(jscontext, fool, nsITestXPCFoo2::GetIID(), &fool_wrapper);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Makefile
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!gmake
|
||||||
|
#
|
||||||
|
# The contents of this file are subject to the Netscape Public License
|
||||||
|
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
# http://www.mozilla.org/NPL/
|
||||||
|
#
|
||||||
|
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
# for the specific language governing rights and limitations under the
|
||||||
|
# NPL.
|
||||||
|
#
|
||||||
|
# The Initial Developer of this code under the NPL is Netscape
|
||||||
|
# Communications Corporation. Portions created by Netscape are
|
||||||
|
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
# Reserved.
|
||||||
|
#
|
||||||
|
|
||||||
|
DEPTH=../../../../..
|
||||||
|
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/config.mk
|
||||||
|
|
||||||
|
LIBRARY_NAME=xpctest
|
||||||
|
MODULE=xpctest
|
||||||
|
|
||||||
|
CPPSRCS= \
|
||||||
|
xpctest_echo.cpp \
|
||||||
|
xpctest_echo.cpp \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!nmake
|
||||||
|
#
|
||||||
|
# The contents of this file are subject to the Netscape Public License
|
||||||
|
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
# http://www.mozilla.org/NPL/
|
||||||
|
#
|
||||||
|
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
# for the specific language governing rights and limitations under the
|
||||||
|
# NPL.
|
||||||
|
#
|
||||||
|
# The Initial Developer of this code under the NPL is Netscape
|
||||||
|
# Communications Corporation. Portions created by Netscape are
|
||||||
|
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
# Reserved.
|
||||||
|
|
||||||
|
DEPTH=..\..\..\..\..
|
||||||
|
IGNORE_MANIFEST=1
|
||||||
|
|
||||||
|
MAKE_OBJ_TYPE = DLL
|
||||||
|
DLLNAME = xpctest
|
||||||
|
DLL =.\$(OBJDIR)\$(DLLNAME).dll
|
||||||
|
|
||||||
|
MODULE=xpconnect
|
||||||
|
REQUIRES=xpcom js libxpt xptinfo xptcall
|
||||||
|
|
||||||
|
DEFINES=-DWIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
|
OBJS= \
|
||||||
|
.\$(OBJDIR)\xpctest_echo.obj \
|
||||||
|
.\$(OBJDIR)\xpctest_module.obj \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
LINCS=-I$(PUBLIC)\xpconnect -I$(PUBLIC)\xpcom -I$(PUBLIC)\js \
|
||||||
|
-I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo \
|
||||||
|
-I$(PUBLIC)\xptcall -I$(PUBLIC)\xpconnect
|
||||||
|
|
||||||
|
LCFLAGS = \
|
||||||
|
$(LCFLAGS) \
|
||||||
|
$(DEFINES) \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
LLIBS= $(LIBNSPR) \
|
||||||
|
$(DIST)\lib\js$(MOZ_BITS)$(VERSION_NUMBER).lib \
|
||||||
|
$(DIST)\lib\xpcom$(MOZ_BITS).lib \
|
||||||
|
$(DIST)\lib\xptinfo$(MOZ_BITS).lib \
|
||||||
|
$(DIST)\lib\xptcall$(MOZ_BITS).lib \
|
||||||
|
$(DIST)\lib\xpc$(MOZ_BITS)$(VERSION_NUMBER).lib \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include <$(DEPTH)\config\rules.mak>
|
||||||
|
|
||||||
|
install:: $(DLL)
|
||||||
|
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||||
|
# $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||||
|
|
||||||
|
clobber::
|
||||||
|
# rm -f $(DIST)\lib\$(DLLNAME).lib
|
||||||
|
rm -f $(DIST)\bin\$(DLLNAME).dll
|
|
@ -0,0 +1,282 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* implement nsIEcho for testing. */
|
||||||
|
|
||||||
|
#include "xpctest_private.h"
|
||||||
|
|
||||||
|
class xpctestEcho : public nsIEcho
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_IMETHOD SetReceiver(nsIEcho* aReceiver);
|
||||||
|
NS_IMETHOD SendOneString(const char* str);
|
||||||
|
NS_IMETHOD In2OutOneInt(int input, int* output);
|
||||||
|
NS_IMETHOD In2OutAddTwoInts(int input1,
|
||||||
|
int input2,
|
||||||
|
int* output1,
|
||||||
|
int* output2,
|
||||||
|
int* result);
|
||||||
|
NS_IMETHOD In2OutOneString(const char* input, char** output);
|
||||||
|
NS_IMETHOD SimpleCallNoEcho();
|
||||||
|
NS_IMETHOD SendManyTypes(PRUint8 p1,
|
||||||
|
PRInt16 p2,
|
||||||
|
PRInt32 p3,
|
||||||
|
PRInt64 p4,
|
||||||
|
PRUint8 p5,
|
||||||
|
PRUint16 p6,
|
||||||
|
PRUint32 p7,
|
||||||
|
PRUint64 p8,
|
||||||
|
float p9,
|
||||||
|
double p10,
|
||||||
|
PRBool p11,
|
||||||
|
char p12,
|
||||||
|
PRUint16 p13,
|
||||||
|
nsID* p14,
|
||||||
|
const char* p15,
|
||||||
|
const PRUnichar* p16);
|
||||||
|
NS_IMETHOD SendInOutManyTypes(PRUint8* p1,
|
||||||
|
PRInt16* p2,
|
||||||
|
PRInt32* p3,
|
||||||
|
PRInt64* p4,
|
||||||
|
PRUint8* p5,
|
||||||
|
PRUint16* p6,
|
||||||
|
PRUint32* p7,
|
||||||
|
PRUint64* p8,
|
||||||
|
float* p9,
|
||||||
|
double* p10,
|
||||||
|
PRBool* p11,
|
||||||
|
char* p12,
|
||||||
|
PRUint16* p13,
|
||||||
|
nsID** p14,
|
||||||
|
char** p15,
|
||||||
|
PRUint16** p16);
|
||||||
|
NS_IMETHOD MethodWithNative(int p1, void* p2);
|
||||||
|
|
||||||
|
NS_IMETHOD ReturnCode(int code);
|
||||||
|
|
||||||
|
NS_IMETHOD FailInJSTest(int fail);
|
||||||
|
|
||||||
|
/* void SharedTest ([shared, retval] out string str); */
|
||||||
|
NS_IMETHOD SharedString(char **str);
|
||||||
|
|
||||||
|
/* void ReturnCode_NS_OK (); */
|
||||||
|
NS_IMETHOD ReturnCode_NS_OK();
|
||||||
|
|
||||||
|
/* void ReturnCode_NS_COMFALSE (); */
|
||||||
|
NS_IMETHOD ReturnCode_NS_COMFALSE();
|
||||||
|
|
||||||
|
/* void ReturnCode_NS_ERROR_NULL_POINTER (); */
|
||||||
|
NS_IMETHOD ReturnCode_NS_ERROR_NULL_POINTER();
|
||||||
|
|
||||||
|
/* void ReturnCode_NS_ERROR_UNEXPECTED (); */
|
||||||
|
NS_IMETHOD ReturnCode_NS_ERROR_UNEXPECTED();
|
||||||
|
|
||||||
|
/* void ReturnCode_NS_ERROR_OUT_OF_MEMORY (); */
|
||||||
|
NS_IMETHOD ReturnCode_NS_ERROR_OUT_OF_MEMORY();
|
||||||
|
|
||||||
|
|
||||||
|
xpctestEcho();
|
||||||
|
private:
|
||||||
|
nsIEcho* mReceiver;
|
||||||
|
};
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kxpctestEchoIID, NS_IECHO_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(xpctestEcho, kxpctestEchoIID);
|
||||||
|
|
||||||
|
xpctestEcho::xpctestEcho()
|
||||||
|
: mReceiver(NULL)
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP xpctestEcho::SetReceiver(nsIEcho* aReceiver)
|
||||||
|
{
|
||||||
|
if(mReceiver)
|
||||||
|
NS_RELEASE(mReceiver);
|
||||||
|
mReceiver = aReceiver;
|
||||||
|
if(mReceiver)
|
||||||
|
NS_ADDREF(mReceiver);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP xpctestEcho::SendOneString(const char* str)
|
||||||
|
{
|
||||||
|
if(mReceiver)
|
||||||
|
return mReceiver->SendOneString(str);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP xpctestEcho::In2OutOneInt(int input, int* output)
|
||||||
|
{
|
||||||
|
*output = input;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP xpctestEcho::In2OutAddTwoInts(int input1,
|
||||||
|
int input2,
|
||||||
|
int* output1,
|
||||||
|
int* output2,
|
||||||
|
int* result)
|
||||||
|
{
|
||||||
|
*output1 = input1;
|
||||||
|
*output2 = input2;
|
||||||
|
*result = input1+input2;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP xpctestEcho::In2OutOneString(const char* input, char** output)
|
||||||
|
{
|
||||||
|
char* p;
|
||||||
|
int len;
|
||||||
|
if(input && output &&
|
||||||
|
(NULL != (p = (char*)nsAllocator::Alloc(len=strlen(input)+1))))
|
||||||
|
{
|
||||||
|
memcpy(p, input, len);
|
||||||
|
*output = p;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if(output)
|
||||||
|
*output = NULL;
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP xpctestEcho::SimpleCallNoEcho()
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::SendManyTypes(PRUint8 p1,
|
||||||
|
PRInt16 p2,
|
||||||
|
PRInt32 p3,
|
||||||
|
PRInt64 p4,
|
||||||
|
PRUint8 p5,
|
||||||
|
PRUint16 p6,
|
||||||
|
PRUint32 p7,
|
||||||
|
PRUint64 p8,
|
||||||
|
float p9,
|
||||||
|
double p10,
|
||||||
|
PRBool p11,
|
||||||
|
char p12,
|
||||||
|
PRUint16 p13,
|
||||||
|
nsID* p14,
|
||||||
|
const char* p15,
|
||||||
|
const PRUnichar* p16)
|
||||||
|
{
|
||||||
|
if(mReceiver)
|
||||||
|
return mReceiver->SendManyTypes(p1, p2, p3, p4, p5, p6, p7, p8, p9,
|
||||||
|
p10, p11, p12, p13, p14, p15, p16);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::SendInOutManyTypes(PRUint8* p1,
|
||||||
|
PRInt16* p2,
|
||||||
|
PRInt32* p3,
|
||||||
|
PRInt64* p4,
|
||||||
|
PRUint8* p5,
|
||||||
|
PRUint16* p6,
|
||||||
|
PRUint32* p7,
|
||||||
|
PRUint64* p8,
|
||||||
|
float* p9,
|
||||||
|
double* p10,
|
||||||
|
PRBool* p11,
|
||||||
|
char* p12,
|
||||||
|
PRUint16* p13,
|
||||||
|
nsID** p14,
|
||||||
|
char** p15,
|
||||||
|
PRUint16** p16)
|
||||||
|
{
|
||||||
|
if(mReceiver)
|
||||||
|
return mReceiver->SendInOutManyTypes(p1, p2, p3, p4, p5, p6, p7, p8, p9,
|
||||||
|
p10, p11, p12, p13, p14, p15, p16);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::MethodWithNative(int p1, void* p2)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::ReturnCode(int code)
|
||||||
|
{
|
||||||
|
return (nsresult) code;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::FailInJSTest(int fail)
|
||||||
|
{
|
||||||
|
if(mReceiver)
|
||||||
|
return mReceiver->FailInJSTest(fail);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::SharedString(char **str)
|
||||||
|
{
|
||||||
|
*str = "a static string";
|
||||||
|
/*
|
||||||
|
// to do non-shared we clone the string:
|
||||||
|
char buf[] = "a static string";
|
||||||
|
int len;
|
||||||
|
*str = (char*)nsAllocator::Alloc(len=strlen(buf)+1);
|
||||||
|
memcpy(*str, buf, len);
|
||||||
|
*/
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::ReturnCode_NS_OK()
|
||||||
|
{return NS_OK;}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::ReturnCode_NS_COMFALSE()
|
||||||
|
{return NS_COMFALSE;}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::ReturnCode_NS_ERROR_NULL_POINTER()
|
||||||
|
{return NS_ERROR_NULL_POINTER;}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::ReturnCode_NS_ERROR_UNEXPECTED()
|
||||||
|
{return NS_ERROR_UNEXPECTED;}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctestEcho::ReturnCode_NS_ERROR_OUT_OF_MEMORY()
|
||||||
|
{return NS_ERROR_OUT_OF_MEMORY;}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
// static
|
||||||
|
NS_IMETHODIMP
|
||||||
|
xpctest::ConstructEcho(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
NS_ASSERTION(aOuter == nsnull, "no aggregation");
|
||||||
|
xpctestEcho* obj = new xpctestEcho();
|
||||||
|
rv = obj->QueryInterface(aIID, aResult);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
|
||||||
|
NS_RELEASE(obj);
|
||||||
|
return rv;
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* module registration and factory code. */
|
||||||
|
|
||||||
|
#include "xpctest_private.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||||
|
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
|
||||||
|
|
||||||
|
extern "C" PR_IMPLEMENT(nsresult)
|
||||||
|
NSGetFactory(nsISupports* aServMgr,
|
||||||
|
const nsCID &aClass,
|
||||||
|
const char *aClassName,
|
||||||
|
const char *aProgID,
|
||||||
|
nsIFactory **aFactory)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
NS_ASSERTION(aFactory != nsnull, "bad factory pointer");
|
||||||
|
|
||||||
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||||
|
aServMgr, kComponentManagerCID, &rv);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
nsIGenericFactory* factory;
|
||||||
|
rv = compMgr->CreateInstance(kGenericFactoryCID, nsnull,
|
||||||
|
nsIGenericFactory::GetIID(),
|
||||||
|
(void**)&factory);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
// add more factories as 'if else's below...
|
||||||
|
|
||||||
|
if(aClass.Equals(xpctest::GetEchoCID()))
|
||||||
|
rv = factory->SetConstructor(xpctest::ConstructEcho);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ASSERTION(0, "incorrectly registered");
|
||||||
|
rv = NS_ERROR_NO_INTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
delete factory;
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
NS_ADDREF(factory);
|
||||||
|
*aFactory = factory;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" PR_IMPLEMENT(nsresult)
|
||||||
|
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
printf("registering xpctest\n");
|
||||||
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||||
|
aServMgr, kComponentManagerCID, &rv);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = compMgr->RegisterComponent(xpctest::GetEchoCID(),
|
||||||
|
"nsEcho", "nsEcho", aPath,
|
||||||
|
PR_TRUE, PR_TRUE);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" PR_IMPLEMENT(nsresult)
|
||||||
|
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
|
||||||
|
aServMgr, kComponentManagerCID, &rv);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = compMgr->UnregisterComponent(xpctest::GetEchoCID(), aPath);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* local header for xpconnect tests components */
|
||||||
|
|
||||||
|
#ifndef xpctest_private_h___
|
||||||
|
#define xpctest_private_h___
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsIFactory.h"
|
||||||
|
#include "nsIAllocator.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
#include "nsIGenericFactory.h"
|
||||||
|
#include "nscore.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "xpctest.h"
|
||||||
|
|
||||||
|
// {ED132C20-EED1-11d2-BAA4-00805F8A5DD7}
|
||||||
|
#define NS_ECHO_CID \
|
||||||
|
{ 0xed132c20, 0xeed1, 0x11d2, \
|
||||||
|
{ 0xba, 0xa4, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
|
||||||
|
|
||||||
|
// 'namespace' class
|
||||||
|
class xpctest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const nsID& GetEchoCID() {static nsID cid = NS_ECHO_CID; return cid;}
|
||||||
|
static NS_METHOD ConstructEcho(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||||
|
private:
|
||||||
|
xpctest(); // not implemented
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* xpctest_private_h___ */
|
|
@ -19,10 +19,12 @@ DEPTH=..\..\..\..
|
||||||
|
|
||||||
IGNORE_MANIFEST=1
|
IGNORE_MANIFEST=1
|
||||||
|
|
||||||
|
DIRS = components
|
||||||
|
|
||||||
MAKE_OBJ_TYPE = EXE
|
MAKE_OBJ_TYPE = EXE
|
||||||
PROG1 = .\$(OBJDIR)\TestXPC.exe
|
PROG1 = .\$(OBJDIR)\TestXPC.exe
|
||||||
PROGRAMS = $(PROG1)
|
PROGRAMS = $(PROG1)
|
||||||
TESTCASES = testxpc.js simpletest.js
|
TESTCASES = testxpc.js simpletest.js xpctest_echo.js
|
||||||
|
|
||||||
LCFLAGS=-DUSE_NSREG -DWIN32_LEAN_AND_MEAN -DJS_THREADSAFE -DJSFILE
|
LCFLAGS=-DUSE_NSREG -DWIN32_LEAN_AND_MEAN -DJS_THREADSAFE -DJSFILE
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ print("equality test "+ (id1.equals(id2) ? "passed" : "failed"));
|
||||||
|
|
||||||
function nsID(str)
|
function nsID(str)
|
||||||
{
|
{
|
||||||
var id = Components.classes.nsIID.newInstance();
|
var id = Components.classes.nsIID.createInstance();
|
||||||
id = id.QueryInterface(Components.interfaces.nsIJSID);
|
id = id.QueryInterface(Components.interfaces.nsIJSID);
|
||||||
id.init(str);
|
id.init(str);
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
function nsID(str)
|
function nsID(str)
|
||||||
{
|
{
|
||||||
var id = Components.classes.nsIID.newInstance();
|
var id = Components.classes.nsIID.createInstance();
|
||||||
id = id.QueryInterface(Components.interfaces.nsIJSIID);
|
id = id.QueryInterface(Components.interfaces.nsIJSIID);
|
||||||
id.init(str);
|
id.init(str);
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -0,0 +1,501 @@
|
||||||
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* xpconnect testing using the nsIEcho interface. */
|
||||||
|
|
||||||
|
function nsNativeEcho()
|
||||||
|
{
|
||||||
|
var obj = Components.classes.nsEcho.createInstance();
|
||||||
|
obj = obj.QueryInterface(Components.interfaces.nsIEcho);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
function nsID(str)
|
||||||
|
{
|
||||||
|
var id = Components.classes.nsIID.createInstance();
|
||||||
|
id = id.QueryInterface(Components.interfaces.nsIJSIID);
|
||||||
|
id.init(str);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
|
||||||
|
var NS_ITESTXPC_FOO_IID = new nsID("{159E36D0-991E-11d2-AC3F-00C09300144B}");
|
||||||
|
|
||||||
|
print();
|
||||||
|
print("Components = "+Components);
|
||||||
|
print("Components properties:");
|
||||||
|
for(i in Components)
|
||||||
|
print(" Components."+i+" = "+Components[i]);
|
||||||
|
|
||||||
|
print();
|
||||||
|
/***************************************************************************/
|
||||||
|
print(".......................................");
|
||||||
|
print("echo tests...");
|
||||||
|
|
||||||
|
var echo = new nsNativeEcho;
|
||||||
|
|
||||||
|
var receiver = new Object();
|
||||||
|
receiver.SetReceiver = function() {};
|
||||||
|
receiver.SendOneString = function(str) {receiver_results[0] = str;};
|
||||||
|
receiver.SendManyTypes = function()
|
||||||
|
{
|
||||||
|
for(var i = 0; i < arguments.length; i++)
|
||||||
|
receiver_results[i] = arguments[i];
|
||||||
|
};
|
||||||
|
|
||||||
|
echo.SetReceiver(receiver);
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// SendOneString
|
||||||
|
|
||||||
|
var test_string = "some string";
|
||||||
|
var receiver_results = new Object();
|
||||||
|
echo.SendOneString(test_string);
|
||||||
|
print("SendOneString - "+(
|
||||||
|
receiver_results[0] == test_string
|
||||||
|
? "passed" : "failed"));
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// In2OutOneInt
|
||||||
|
|
||||||
|
print("In2OutOneInt - "+(
|
||||||
|
echo.In2OutOneInt(102) == 102
|
||||||
|
? "passed" : "failed"));
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// In2OutAddTwoInts
|
||||||
|
|
||||||
|
var in_out_results1 = new Object();
|
||||||
|
var in_out_results2 = new Object();
|
||||||
|
var in_out_results =
|
||||||
|
echo.In2OutAddTwoInts(123, 55, in_out_results1, in_out_results2);
|
||||||
|
print("In2OutAddTwoInts - "+(
|
||||||
|
in_out_results1.value == 123 &&
|
||||||
|
in_out_results2.value == 55 &&
|
||||||
|
in_out_results == 178
|
||||||
|
? "passed" : "failed"));
|
||||||
|
|
||||||
|
var test_string2 = "some other string";
|
||||||
|
print("In2OutOneString - "+(
|
||||||
|
echo.In2OutOneString(test_string2) == test_string2 &&
|
||||||
|
echo.In2OutOneString(echo.In2OutOneString(test_string2)) == test_string2
|
||||||
|
? "passed" : "failed"));
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// SendManyTypes
|
||||||
|
|
||||||
|
var receiver_results = new Object();
|
||||||
|
var send_params = [1,-2,-3,-102020,2,4,6,1023,1.5,2.000008,true,'a','b',NS_ITESTXPC_FOO_IID,"a string","another string"];
|
||||||
|
echo.SendManyTypes(send_params[0],
|
||||||
|
send_params[1],
|
||||||
|
send_params[2],
|
||||||
|
send_params[3],
|
||||||
|
send_params[4],
|
||||||
|
send_params[5],
|
||||||
|
send_params[6],
|
||||||
|
send_params[7],
|
||||||
|
send_params[8],
|
||||||
|
send_params[9],
|
||||||
|
send_params[10],
|
||||||
|
send_params[11],
|
||||||
|
send_params[12],
|
||||||
|
send_params[13],
|
||||||
|
send_params[14],
|
||||||
|
send_params[15]);
|
||||||
|
|
||||||
|
var all_ok = true;
|
||||||
|
for(i = 0; i < 16; i++) {
|
||||||
|
if(((""+receiver_results[i]).toLowerCase()) !=
|
||||||
|
((""+send_params[i]).toLowerCase())) {
|
||||||
|
if(all_ok)
|
||||||
|
print("SendManyTypes - failed...");
|
||||||
|
all_ok = false;
|
||||||
|
print(" param number "+i+" diff: "+send_params[i]+" -> "+receiver_results[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(all_ok)
|
||||||
|
print("SendManyTypes - passed");
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// SendInOutManyTypes
|
||||||
|
|
||||||
|
var receiver_results = new Object();
|
||||||
|
var send_params = [1,-2,-3,-102020,2,4,6,1023,1.5,2.000008,true,'a','b',NS_ITESTXPC_FOO_IID,"a string","another string"];
|
||||||
|
var resend_params = [2,-3,-7,-10220,18,14,16,123,2.5,8.000008,false,'z','l',NS_ISUPPORTS_IID,"foo string","yet another string"];
|
||||||
|
|
||||||
|
receiver.SendInOutManyTypes = function()
|
||||||
|
{
|
||||||
|
for(var i = 0; i < arguments.length; i++) {
|
||||||
|
receiver_results[i] = arguments[i].value;
|
||||||
|
arguments[i].value = resend_params[i];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var inout_params = [{value:send_params[0] },
|
||||||
|
{value:send_params[1] },
|
||||||
|
{value:send_params[2] },
|
||||||
|
{value:send_params[3] },
|
||||||
|
{value:send_params[4] },
|
||||||
|
{value:send_params[5] },
|
||||||
|
{value:send_params[6] },
|
||||||
|
{value:send_params[7] },
|
||||||
|
{value:send_params[8] },
|
||||||
|
{value:send_params[9] },
|
||||||
|
{value:send_params[10]},
|
||||||
|
{value:send_params[11]},
|
||||||
|
{value:send_params[12]},
|
||||||
|
{value:send_params[13]},
|
||||||
|
{value:send_params[14]},
|
||||||
|
{value:send_params[15]}];
|
||||||
|
|
||||||
|
echo.SendInOutManyTypes(inout_params[0] ,
|
||||||
|
inout_params[1] ,
|
||||||
|
inout_params[2] ,
|
||||||
|
inout_params[3] ,
|
||||||
|
inout_params[4] ,
|
||||||
|
inout_params[5] ,
|
||||||
|
inout_params[6] ,
|
||||||
|
inout_params[7] ,
|
||||||
|
inout_params[8] ,
|
||||||
|
inout_params[9] ,
|
||||||
|
inout_params[10],
|
||||||
|
inout_params[11],
|
||||||
|
inout_params[12],
|
||||||
|
inout_params[13],
|
||||||
|
inout_params[14],
|
||||||
|
inout_params[15]);
|
||||||
|
|
||||||
|
var all_ok = true;
|
||||||
|
for(i = 0; i < 16; i++) {
|
||||||
|
if(((""+receiver_results[i]).toLowerCase()) !=
|
||||||
|
((""+send_params[i]).toLowerCase())) {
|
||||||
|
if(all_ok)
|
||||||
|
print("SendInOutManyTypes - failed...");
|
||||||
|
all_ok = false;
|
||||||
|
print(" sent param number "+i+" diff: "+send_params[i]+" -> "+receiver_results[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < 16; i++) {
|
||||||
|
if(((""+resend_params[i]).toLowerCase()) !=
|
||||||
|
((""+inout_params[i].value).toLowerCase())) {
|
||||||
|
if(all_ok)
|
||||||
|
print("SendInOutManyTypes - failed...");
|
||||||
|
all_ok = false;
|
||||||
|
print(" resent param number "+i+" diff: "+resend_params[i]+" -> "+inout_params[i].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(all_ok)
|
||||||
|
print("SendInOutManyTypes - passed");
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// check exceptions on xpcom error code
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.ReturnCode(0);
|
||||||
|
print("ReturnCode(0) - passed");
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
print("ReturnCode(0) exception text: "+e+" - failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.ReturnCode(-1);
|
||||||
|
print("ReturnCode(-1) - failed");
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
// print("ReturnCode(-1) exception text: "+e+" - passed");
|
||||||
|
print("ReturnCode(-1) - passed");
|
||||||
|
}
|
||||||
|
|
||||||
|
var all_ok = true;
|
||||||
|
|
||||||
|
echo.ReturnCode_NS_OK()
|
||||||
|
if(Components.RESULT_NS_OK != Components.lastResult) {
|
||||||
|
all_ok = false;
|
||||||
|
print("expected: RESULT_NS_OK = "+Components.RESULT_NS_OK+" got: "+Components.lastResult);
|
||||||
|
print(Components.lastResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo.ReturnCode_NS_COMFALSE()
|
||||||
|
if(Components.RESULT_NS_COMFALSE != Components.lastResult) {
|
||||||
|
all_ok = false;
|
||||||
|
print("expected: RESULT_NS_COMFALSE = "+Components.RESULT_NS_COMFALSE+" got: "+Components.lastResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.ReturnCode_NS_ERROR_NULL_POINTER()
|
||||||
|
all_ok = false;
|
||||||
|
} catch(e) {
|
||||||
|
if(Components.RESULT_NS_ERROR_NULL_POINTER != Components.lastResult) {
|
||||||
|
all_ok = false;
|
||||||
|
print("expected: RESULT_NS_ERROR_NULL_POINTER = "+Components.RESULT_NS_ERROR_NULL_POINTER+" got: "+Components.lastResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.ReturnCode_NS_ERROR_UNEXPECTED()
|
||||||
|
all_ok = false;
|
||||||
|
} catch(e) {
|
||||||
|
if(Components.RESULT_NS_ERROR_UNEXPECTED != Components.lastResult) {
|
||||||
|
all_ok = false;
|
||||||
|
print("expected: RESULT_NS_ERROR_UNEXPECTED = "+Components.RESULT_NS_ERROR_UNEXPECTED+" got: "+Components.lastResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.ReturnCode_NS_ERROR_OUT_OF_MEMORY()
|
||||||
|
all_ok = false;
|
||||||
|
} catch(e) {
|
||||||
|
if(Components.RESULT_NS_ERROR_OUT_OF_MEMORY != Components.lastResult) {
|
||||||
|
all_ok = false;
|
||||||
|
print("expected: RESULT_NS_ERROR_OUT_OF_MEMORY = "+Components.RESULT_NS_ERROR_OUT_OF_MEMORY+" got: "+Components.lastResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Components.lastResult test - "+ (all_ok ? "passed" : "failed") );
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// check exceptions on too few args
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.ReturnCode(); // supposed to have one arg
|
||||||
|
print("Too few args test - failed");
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
// print("Too few args test -- exception text: "+e+" - passed");
|
||||||
|
print("Too few args test - passed");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// check exceptions on can't convert
|
||||||
|
|
||||||
|
// XXX this is bad test since null is now convertable.
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
echo.SetReceiver(null);
|
||||||
|
// print("Can't convert arg to Native ("+out+")- failed");
|
||||||
|
print("Can't convert arg to Native - failed");
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
// print("Can't convert arg to Native ("+e+") - passed");
|
||||||
|
print("Can't convert arg to Native - passed");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
////////////////////
|
||||||
|
// FailInJSTest
|
||||||
|
|
||||||
|
var receiver3 = new Object();
|
||||||
|
receiver3.SetReceiver = function() {};
|
||||||
|
receiver3.FailInJSTest = function(fail) {if(fail)throw("");};
|
||||||
|
echo.SetReceiver(receiver3);
|
||||||
|
|
||||||
|
var all_ok = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
echo.FailInJSTest(false);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
print("FailInJSTest - failed");
|
||||||
|
all_ok = false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
echo.FailInJSTest(true);
|
||||||
|
print("FailInJSTest - failed");
|
||||||
|
all_ok = false;
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if(all_ok)
|
||||||
|
print("FailInJSTest - passed");
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// nsID tests...
|
||||||
|
|
||||||
|
function idTest(name, iid, same)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
var idFromName = new nsID(name);
|
||||||
|
var idFromIID = new nsID(iid);
|
||||||
|
|
||||||
|
if(!idFromName.valid || !idFromIID.valid) {
|
||||||
|
return (same && idFromName.valid == idFromIID.valid) ||
|
||||||
|
(!same && idFromName.valid != idFromIID.valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(same != idFromName.equals(idFromIID) ||
|
||||||
|
same != idFromIID.equals(idFromName)) {
|
||||||
|
print("iid equals test failed for "+name+" "+iid);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nameNormalized = name.toLowerCase();
|
||||||
|
iidNormalized = iid.toLowerCase();
|
||||||
|
|
||||||
|
idFromName_NameNormalized = idFromName.name ?
|
||||||
|
idFromName.name.toLowerCase() :
|
||||||
|
idFromName.name;
|
||||||
|
|
||||||
|
idFromIID_NameNormalized = idFromIID.name ?
|
||||||
|
idFromIID.name.toLowerCase() :
|
||||||
|
idFromIID.name;
|
||||||
|
|
||||||
|
idFromName_StringNormalized = idFromName.number ?
|
||||||
|
idFromName.number.toLowerCase() :
|
||||||
|
idFromName.number;
|
||||||
|
|
||||||
|
idFromIID_StringNormalized = idFromIID.number ?
|
||||||
|
idFromIID.number.toLowerCase() :
|
||||||
|
idFromIID.number;
|
||||||
|
|
||||||
|
if(idFromName_NameNormalized != nameNormalized ||
|
||||||
|
same != (idFromIID_NameNormalized == nameNormalized)) {
|
||||||
|
print("iid toName test failed for "+name+" "+iid);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(idFromIID_StringNormalized != iidNormalized ||
|
||||||
|
same != (idFromName_StringNormalized == iidNormalized)) {
|
||||||
|
print("iid toString test failed for "+name+" "+iid);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!idFromName.equals(new nsID(idFromName)) ||
|
||||||
|
!idFromIID.equals(new nsID(idFromIID))) {
|
||||||
|
print("new id from id test failed for "+name+" "+iid);
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
var all_ok = true;
|
||||||
|
// these 4 should be valid and the same
|
||||||
|
all_ok = idTest("nsISupports", "{00000000-0000-0000-c000-000000000046}", true) && all_ok;
|
||||||
|
all_ok = idTest("nsITestXPCFoo", "{159E36D0-991E-11d2-AC3F-00C09300144B}", true) && all_ok;
|
||||||
|
all_ok = idTest("nsITestXPCFoo2","{5F9D20C0-9B6B-11d2-9FFE-000064657374}", true) && all_ok;
|
||||||
|
all_ok = idTest("nsIEcho", "{CD2F2F40-C5D9-11d2-9838-006008962422}", true) && all_ok;
|
||||||
|
// intentional mismatches
|
||||||
|
all_ok = idTest("nsISupports", "{CD2F2F40-C5D9-11d2-9838-006008962422}", false) && all_ok;
|
||||||
|
all_ok = idTest("nsITestXPCFoo", "{00000000-0000-0000-c000-000000000046}", false) && all_ok;
|
||||||
|
// intentional bad name
|
||||||
|
all_ok = idTest("bogus", "{CD2F2F40-C5D9-11d2-9838-006008962422}", false) && all_ok;
|
||||||
|
// intentional bad iid
|
||||||
|
all_ok = idTest("nsISupports", "{XXXXXXXX-C5D9-11d2-9838-006008962422}", false) && all_ok;
|
||||||
|
// intentional bad name AND iid
|
||||||
|
all_ok = idTest("bogus", "{XXXXXXXX-C5D9-11d2-9838-006008962422}", true) && all_ok;
|
||||||
|
|
||||||
|
print("nsID tests - "+(all_ok ? "passed" : "failed"));
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
all_ok = echo.SharedString() == "a static string";
|
||||||
|
print("[shared] test - "+(all_ok ? "passed" : "failed"));
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
// Components object test...
|
||||||
|
// print(".......................................");
|
||||||
|
|
||||||
|
// print("Components = "+Components);
|
||||||
|
// print("Components.interfaces = "+Components.interfaces);
|
||||||
|
// print("Components.interfaces.nsISupports = "+Components.interfaces.nsISupports);
|
||||||
|
// print("Components.interfaces.nsISupports.name = "+Components.interfaces.nsISupports.name);
|
||||||
|
// print("Components.interfaces.nsISupports.number = "+Components.interfaces.nsISupports.number);
|
||||||
|
//
|
||||||
|
// print("Components.interfaces.nsIEcho.number = "+Components.interfaces.nsIEcho.number);
|
||||||
|
// print("Components.interfaces['{CD2F2F40-C5D9-11d2-9838-006008962422}'] = "+Components.interfaces['{CD2F2F40-C5D9-11d2-9838-006008962422}']);
|
||||||
|
// print("Components.interfaces['{CD2F2F40-C5D9-11d2-9838-006008962422}'].name = "+Components.interfaces['{CD2F2F40-C5D9-11d2-9838-006008962422}'].name);
|
||||||
|
//
|
||||||
|
// print("Components.classes = "+Components.classes);
|
||||||
|
// print("Components.classes.nsIID = "+Components.classes.nsIID);
|
||||||
|
// print("Components.classes.nsCID = "+Components.classes.nsCID);
|
||||||
|
// print("Components.classes.nsCID.name = "+Components.classes.nsCID.name);
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
print(".......................................");
|
||||||
|
print("simple speed tests...");
|
||||||
|
|
||||||
|
var iterations = 1000;
|
||||||
|
|
||||||
|
var receiver2 = new Object();
|
||||||
|
receiver2.SetReceiver = function() {};
|
||||||
|
receiver2.SendOneString = function(str) {/*print(str);*/};
|
||||||
|
|
||||||
|
var echoJS = new Object();
|
||||||
|
echoJS.SetReceiver = function(r) {this.r = r;};
|
||||||
|
echoJS.SendOneString = function(str) {if(this.r)this.r.SendOneString(str)};
|
||||||
|
echoJS.SimpleCallNoEcho = function(){}
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
print("\nEcho.SimpleCallNoEcho (just makes call with no params and no callback)");
|
||||||
|
var start_time = new Date().getTime()/1000;
|
||||||
|
echoJS.SetReceiver(receiver2);
|
||||||
|
for(i = 0; i < iterations; i++)
|
||||||
|
echoJS.SimpleCallNoEcho();
|
||||||
|
var end_time = new Date().getTime()/1000;
|
||||||
|
var interval = parseInt(100*(end_time - start_time),10)/100;
|
||||||
|
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
|
||||||
|
|
||||||
|
var start_time = new Date().getTime()/1000;
|
||||||
|
echo.SetReceiver(receiver2);
|
||||||
|
for(i = 0; i < iterations; i++)
|
||||||
|
echo.SimpleCallNoEcho();
|
||||||
|
var end_time = new Date().getTime()/1000;
|
||||||
|
var interval = parseInt(100*(end_time - start_time),10)/100;
|
||||||
|
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
|
||||||
|
|
||||||
|
/*********************************************/
|
||||||
|
|
||||||
|
print("\nEcho.SendOneString (calls a callback that does a call)");
|
||||||
|
var start_time = new Date().getTime()/1000;
|
||||||
|
echoJS.SetReceiver(receiver2);
|
||||||
|
for(i = 0; i < iterations; i++)
|
||||||
|
echoJS.SendOneString("foo");
|
||||||
|
var end_time = new Date().getTime()/1000;
|
||||||
|
var interval = parseInt(100*(end_time - start_time),10)/100;
|
||||||
|
print("JS control did "+iterations+" iterations in "+interval+ " seconds.");
|
||||||
|
|
||||||
|
var start_time = new Date().getTime()/1000;
|
||||||
|
echo.SetReceiver(receiver2);
|
||||||
|
for(i = 0; i < iterations; i++)
|
||||||
|
echo.SendOneString("foo");
|
||||||
|
var end_time = new Date().getTime()/1000;
|
||||||
|
var interval = parseInt(100*(end_time - start_time),10)/100;
|
||||||
|
print("XPConnect did "+iterations+" iterations in "+interval+ " seconds.");
|
||||||
|
|
||||||
|
print(".......................................");
|
||||||
|
|
||||||
|
if(0){
|
||||||
|
print();
|
||||||
|
print("this = "+this);
|
||||||
|
print("global object properties:");
|
||||||
|
for(i in this)
|
||||||
|
print(" this."+i+" = "+ (typeof(this[i])!="function"? this[i] : "[function]"));
|
||||||
|
|
||||||
|
print();
|
||||||
|
}
|
||||||
|
|
||||||
|
echoJS.SetReceiver(null);
|
||||||
|
echo.SetReceiver(null);
|
||||||
|
|
Двоичные данные
js/src/xpconnect/typelib/nsISupports.xpt
Двоичные данные
js/src/xpconnect/typelib/nsISupports.xpt
Двоичный файл не отображается.
Двоичные данные
js/src/xpconnect/typelib/xpccomponents.xpt
Двоичные данные
js/src/xpconnect/typelib/xpccomponents.xpt
Двоичный файл не отображается.
Двоичные данные
js/src/xpconnect/typelib/xpcjsid.xpt
Двоичные данные
js/src/xpconnect/typelib/xpcjsid.xpt
Двоичный файл не отображается.
Двоичные данные
js/src/xpconnect/typelib/xpctest.xpt
Двоичные данные
js/src/xpconnect/typelib/xpctest.xpt
Двоичный файл не отображается.
Загрузка…
Ссылка в новой задаче