use of typelibs via xptinfo working with test program on win32. Untested on Linux. typelib generation not yet integrated into the make system

This commit is contained in:
jband%netscape.com 1999-03-14 06:07:21 +00:00
parent dde0d8023b
commit 5aad447b54
26 changed files with 552 additions and 1337 deletions

View File

@ -49,17 +49,15 @@ CPPSRCS= \
xpcwrappedjsclass.cpp \
xpcwrappednative.cpp \
xpcwrappednativeclass.cpp \
xpt_cpp.cpp \
$(NULL)
EXPORTS = \
nsIInterfaceInfo.h \
nsIInterfaceInfoManager.h \
nsIXPCScriptable.h \
nsIXPConnect.h \
xpccomponents.h \
xpcjsid.h \
xpclog.h \
xpctest.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

View File

@ -1,2 +1,9 @@
xpidl -w -m header -o ..\xpccomponents xpccomponents.idl
xpidl -w -m header -o ..\xpcjsid xpcjsid.idl
xpidl -w -m header -o ..\xpcjsid xpcjsid.idl
xpidl -w -m header -o ..\xpctest xpctest.idl
xpidl -w -m typelib -o x:\raptor\mozilla\dist\win32_d.obj\bin\xpccomponents xpccomponents.idl
xpidl -w -m typelib -o x:\raptor\mozilla\dist\win32_d.obj\bin\xpcjsid xpcjsid.idl
xpidl -w -m typelib -o x:\raptor\mozilla\dist\win32_d.obj\bin\nsISupports nsISupports.idl
xpidl -w -m typelib -o x:\raptor\mozilla\dist\win32_d.obj\bin\xpctest xpctest.idl
set XPTDIR=x:\raptor\mozilla\dist\win32_d.obj\bin

View File

@ -1,6 +1,46 @@
/* -*- Mode: IDL; tab-width: 4; 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.
*/
/* XXX completely bogus declaration */
%{C++
#include "nsDebug.h"
#include "nsTraceRefcnt.h"
#include "nsIID.h"
%}
/* #include "nsID.idl" */
%{C++
#include "nsError.h"
[object,uuid(00000000-0000-0000-c000-000000000046)]
#include "nsISupportsUtils.h"
%}
native nsQIResult(void *);
native voidStar(void*);
native voidStarRef(void**);
native nsIIDRef(REFNSIID);
typedef unsigned long nsrefcnt;
[
object,
uuid(00000000-0000-0000-c000-000000000046)
]
interface nsISupports {
void QueryInterface(in nsIIDRef uuid, [iid_is(uuid),retval] out nsQIResult result);
[notxpcom] nsrefcnt AddRef();
[notxpcom] nsrefcnt Release();
};

View File

@ -32,6 +32,8 @@ interface nsIJSID : nsISupports
boolean equals(in nsIJSID other);
boolean init(in string idString);
string toString();
};
[uuid(e08dcda0-d651-11d2-9843-006008962422)]

View File

@ -0,0 +1,68 @@
#include "nsISupports.idl"
/* XXX should be built in */
native nsID(nsID *);
[uuid(159E36D0-991E-11d2-AC3F-00C09300144B)]
interface nsITestXPCFoo : nsISupports {
long Test(in long p1, in long p2);
void Test2();
};
[uuid(5F9D20C0-9B6B-11d2-9FFE-000064657374)]
interface nsITestXPCFoo2 : nsITestXPCFoo {
};
[uuid(CD2F2F40-C5D9-11d2-9838-006008962422)]
interface nsIEcho : nsISupports {
void SetReciever(in nsIEcho aReciever);
void SendOneString(in string str);
long In2OutOneInt(in long input);
long In2OutAddTwoInts(in long input1, in long input2,
out long output1, out long output2);
string In2OutOneString(in string input);
void SimpleCallNoEcho();
void SendManyTypes(in octet p1,
in short p2,
in long p3,
in long long p4,
in octet p5,
in unsigned short p6,
in unsigned long p7,
in unsigned long long p8,
in float p9,
in double p10,
in boolean p11,
in char p12,
in wchar p13,
in nsID p14,
in string p15,
in wstring p16);
void SendInOutManyTypes(inout octet p1,
inout short p2,
inout long p3,
inout long long p4,
inout octet p5,
inout unsigned short p6,
inout unsigned long p7,
inout unsigned long long p8,
inout float p9,
inout double p10,
inout boolean p11,
inout char p12,
inout wchar p13,
inout nsID p14,
inout string p15,
inout wstring p16);
void MethodWithNative(in long p1, in voidStar p2);
void ReturnCode(in long code);
void FailInJSTest(in long fail);
};

View File

@ -50,20 +50,19 @@ OBJS= \
.\$(OBJDIR)\xpcwrappedjsclass.obj \
.\$(OBJDIR)\xpcwrappednative.obj \
.\$(OBJDIR)\xpcwrappednativeclass.obj \
.\$(OBJDIR)\xpt_cpp.obj \
$(NULL)
EXPORTS = \
nsIInterfaceInfo.h \
nsIInterfaceInfoManager.h \
nsIXPCScriptable.h \
nsIXPConnect.h \
xpccomponents.h \
xpcjsid.h \
xpclog.h \
xpctest.h \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LCFLAGS = \
$(LCFLAGS) \
@ -74,6 +73,7 @@ LLIBS= $(LIBNSPR) \
$(MD_LIBRARY) \
$(DIST)\lib\js$(MOZ_BITS)$(VERSION_NUMBER).lib \
$(DIST)\lib\xpcom$(MOZ_BITS).lib \
$(DIST)\lib\xptinfo$(MOZ_BITS).lib \
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib

View File

@ -21,7 +21,7 @@ include <$(DEPTH)\config\config.mak>
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPC_API -DJS_THREADSAFE -DDEBUG
LINCS=-I..\.. -I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt
-I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LCFLAGS = \
$(LCFLAGS) \

View File

@ -1,149 +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.
*/
/* The nsIInterfaceInfo xpcom public declaration. */
#ifndef nsIInterfaceInfo_h___
#define nsIInterfaceInfo_h___
#include "nsISupports.h"
// forward declaration of non-XPCOM types
class nsXPTMethodInfo;
class nsXPTConstant;
// {215DBE04-94A7-11d2-BA58-00805F8A5DD7}
#define NS_IINTERFACEINFO_IID \
{ 0x215dbe04, 0x94a7, 0x11d2, \
{ 0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class nsIInterfaceInfo : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_IID)
NS_IMETHOD GetName(char** name) = 0; // returns IAllocatator alloc'd copy
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
NS_IMETHOD GetParent(nsIInterfaceInfo** parent) = 0;
// these include counts of parents
NS_IMETHOD GetMethodCount(uint16* count) = 0;
NS_IMETHOD GetConstantCount(uint16* count) = 0;
// These include methods and constants of parents.
// There do *not* make copies ***explicit bending of XPCOM rules***
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info) = 0;
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant) = 0;
};
/***************************************************************************/
/***************************************************************************/
// XXX this is here just for testing - pulled from XPConnect...
// it can go away after nsIInterfaceInfos are being built from typelibs
#include "xpccomponents.h"
#include "xpcjsid.h"
// {159E36D0-991E-11d2-AC3F-00C09300144B}
#define NS_ITESTXPC_FOO_IID \
{ 0x159e36d0, 0x991e, 0x11d2, \
{ 0xac, 0x3f, 0x0, 0xc0, 0x93, 0x0, 0x14, 0x4b } }
class nsITestXPCFoo : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITESTXPC_FOO_IID)
NS_IMETHOD Test(int p1, int p2, int* retval) = 0;
NS_IMETHOD Test2() = 0;
};
// {5F9D20C0-9B6B-11d2-9FFE-000064657374}
#define NS_ITESTXPC_FOO2_IID \
{ 0x5f9d20c0, 0x9b6b, 0x11d2, \
{ 0x9f, 0xfe, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
class nsITestXPCFoo2 : public nsITestXPCFoo
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITESTXPC_FOO2_IID)
};
// {CD2F2F40-C5D9-11d2-9838-006008962422}
#define NS_IECHO_IID \
{ 0xcd2f2f40, 0xc5d9, 0x11d2, \
{ 0x98, 0x38, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
class nsIEcho : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IECHO_IID)
NS_IMETHOD SetReciever(nsIEcho* aReciever) = 0 ;
NS_IMETHOD SendOneString(const char* str) = 0 ;
NS_IMETHOD In2OutOneInt(int input, int* output) = 0 ;
NS_IMETHOD In2OutAddTwoInts(int input1,
int input2,
int* output1,
int* output2,
int* result) = 0 ;
NS_IMETHOD In2OutOneString(const char* input, char** output) = 0 ;
NS_IMETHOD SimpleCallNoEcho() = 0 ;
NS_IMETHOD SendManyTypes(int8 p1,
int16 p2,
int32 p3,
int64 p4,
uint8 p5,
uint16 p6,
uint32 p7,
uint64 p8,
float p9,
double p10,
PRBool p11,
char p12,
uint16 p13,
nsID* p14,
char* p15,
uint16* p16) = 0;
NS_IMETHOD SendInOutManyTypes(int8* p1,
int16* p2,
int32* p3,
int64* p4,
uint8* p5,
uint16* p6,
uint32* p7,
uint64* p8,
float* p9,
double* p10,
PRBool* p11,
char* p12,
uint16* p13,
nsID** p14,
char** p15,
uint16** p16) = 0;
NS_IMETHOD MethodWithNative(int p1, void* p2) = 0;
NS_IMETHOD ReturnCode(int code) = 0;
NS_IMETHOD FailInJSTest(int fail) = 0;
};
/***************************************************************************/
/***************************************************************************/
#endif /* nsIInterfaceInfo_h___ */

View File

@ -1,69 +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.
*/
/* The nsIInterfaceInfoManager xpcom public declaration. */
#ifndef nsIInterfaceInfoManager_h___
#define nsIInterfaceInfoManager_h___
#include "nsIInterfaceInfo.h"
// This should be implemented as a Service
// {8B161900-BE2B-11d2-9831-006008962422}
#define NS_IINTERFACEINFO_MANAGER_IID \
{ 0x8b161900, 0xbe2b, 0x11d2, \
{ 0x98, 0x31, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
class nsIInterfaceInfoManager : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_MANAGER_IID)
// nsIInformationInfo management services
NS_IMETHOD GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info) = 0;
NS_IMETHOD GetInfoForName(const char* name, nsIInterfaceInfo** info) = 0;
// name <-> IID mapping services
// NOTE: these return IAllocatator alloc'd copies of the data
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid) = 0;
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name) = 0;
// XXX other methods?
};
/***************************************************************************/
// XXX XXX Remove this block and switch XPC_PUBLIC_API to XPT_PUBLIC_API
// when this code is moved to libxpt
#include "jsapi.h"
#ifdef EXPORT_XPC_API
#define XPC_PUBLIC_API(t) JS_EXPORT_API(t)
#else
#define XPC_PUBLIC_API(t) JS_IMPORT_API(t)
#endif
/***************************************************************************/
JS_BEGIN_EXTERN_C
// XXX remove this and use ServiceManager instead
XPC_PUBLIC_API(nsIInterfaceInfoManager*)
XPT_GetInterfaceInfoManager();
JS_END_EXTERN_C
#endif /* nsIInterfaceInfoManager_h___ */

View File

@ -25,8 +25,10 @@
#include "jsapi.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "xptinfo.h"
#include "xpccomponents.h"
#include "xpcjsid.h"
/*
* The linkage of XPC API functions differs depending on whether the file is

View File

@ -170,7 +170,7 @@ nsXPConnect::nsXPConnect()
(nsISupports **)&mAllocator);
// XXX later this will be a service
mInterfaceInfoManager = XPT_GetInterfaceInfoManager();
mInterfaceInfoManager = XPTI_GetInterfaceInfoManager();
mThrower = new XPCJSThrower(JS_TRUE);
}

View File

@ -29,6 +29,10 @@
#include "nsIComponentManager.h"
#include "jsapi.h"
#include "xpclog.h"
#include "nscore.h"
#include "xpctest.h"
#include "nsIAllocator.h"
@ -172,38 +176,38 @@ public:
int* result);
NS_IMETHOD In2OutOneString(const char* input, char** output);
NS_IMETHOD SimpleCallNoEcho();
NS_IMETHOD SendManyTypes(int8 p1,
int16 p2,
int32 p3,
int64 p4,
uint8 p5,
uint16 p6,
uint32 p7,
uint64 p8,
float p9,
double p10,
PRBool p11,
char p12,
uint16 p13,
nsID* p14,
char* p15,
uint16* p16);
NS_IMETHOD SendInOutManyTypes(int8* p1,
int16* p2,
int32* p3,
int64* p4,
uint8* p5,
uint16* p6,
uint32* p7,
uint64* p8,
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,
uint16* p13,
PRUint16* p13,
nsID** p14,
char** p15,
uint16** p16);
PRUint16** p16);
NS_IMETHOD MethodWithNative(int p1, void* p2);
NS_IMETHOD ReturnCode(int code);
@ -286,22 +290,22 @@ NS_IMETHODIMP MyEcho::SimpleCallNoEcho()
}
NS_IMETHODIMP
MyEcho::SendManyTypes(int8 p1,
int16 p2,
int32 p3,
int64 p4,
uint8 p5,
uint16 p6,
uint32 p7,
uint64 p8,
float p9,
double p10,
PRBool p11,
char p12,
uint16 p13,
nsID* p14,
char* p15,
uint16* p16)
MyEcho::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(mReciever)
return mReciever->SendManyTypes(p1, p2, p3, p4, p5, p6, p7, p8, p9,
@ -310,22 +314,22 @@ MyEcho::SendManyTypes(int8 p1,
}
NS_IMETHODIMP
MyEcho::SendInOutManyTypes(int8* p1,
int16* p2,
int32* p3,
int64* p4,
uint8* p5,
uint16* p6,
uint32* p7,
uint64* p8,
MyEcho::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,
uint16* p13,
PRUint16* p13,
nsID** p14,
char** p15,
uint16** p16)
PRUint16** p16)
{
if(mReciever)
return mReciever->SendInOutManyTypes(p1, p2, p3, p4, p5, p6, p7, p8, p9,
@ -452,7 +456,8 @@ int main()
return 1;
}
/*
#if 0
// old code where global object was plain object
glob = JS_NewObject(jscontext, &global_class, NULL, NULL);
if (!glob)
@ -464,7 +469,40 @@ int main()
return 1;
xpc->InitJSContext(jscontext, glob);
*/
nsIXPCComponents* comp = XPC_GetXPConnectComponentsObject();
if(!comp)
{
printf("failed to create Components native object");
return 1;
}
nsIXPConnectWrappedNative* comp_wrapper;
if(NS_FAILED(xpc->WrapNative(jscontext, comp,
nsIXPCComponents::GetIID(), &comp_wrapper)))
{
printf("failed to build wrapper for Components native object");
return 1;
}
JSObject* comp_jsobj;
comp_wrapper->GetJSObject(&comp_jsobj);
jsval comp_jsval = OBJECT_TO_JSVAL(comp_jsobj);
JS_SetProperty(jscontext, glob, "Components", &comp_jsval);
NS_RELEASE(comp_wrapper);
NS_RELEASE(comp);
char* txt[] = {
"load('simpletest.js');",
0,
};
jsval rval;
for(char** p = txt; *p; p++)
JS_EvaluateScript(jscontext, glob, *p, strlen(*p), "builtin", 1, &rval);
XPC_DUMP(xpc, 20);
#else
nsTestXPCFoo* foo = new nsTestXPCFoo();
@ -623,6 +661,8 @@ int main()
// XPC_LOG_ALWAYS((""));
XPC_DUMP(xpc, 3);
#endif
NS_RELEASE(xpc);
JS_DestroyContext(jscontext);

View File

@ -22,7 +22,7 @@ IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\TestXPC.exe
PROGRAMS = $(PROG1)
TESTCASES = testxpc.js
TESTCASES = testxpc.js simpletest.js
LCFLAGS=-DUSE_NSREG -DJSFILE
@ -30,7 +30,8 @@ DEFINES=-DWIN32_LEAN_AND_MEAN -DJS_THREADSAFE
REQUIRES=xpcom js xpconnect
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect -I$(PUBLIC)\raptor
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect \
-I$(PUBLIC)\raptor -I$(PUBLIC)\xptinfo
LLIBS= \
$(DIST)\lib\xpcom32.lib \

View File

@ -0,0 +1,46 @@
print("Components.interfaces.nsIJSID = " +
Components.interfaces.nsIJSID);
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.nsISupports.id = " +
Components.interfaces.nsISupports.id);
print("Components.interfaces.nsISupports.valid = " +
Components.interfaces.nsISupports.valid);
var id1 = Components.interfaces.nsISupports;
var id2 = Components.interfaces.nsISupports;
var id3 = Components.interfaces.nsISupports.id;
print("identity test "+ (id1 == id2 ? "passed" : "failed"));
print("non-identity test "+ (id1 != id3 ? "passed" : "failed"));
print("equality test "+ (id1.equals(id2) ? "passed" : "failed"));
function nsID(str)
{
var id = Components.classes.nsIID.newInstance();
id = id.QueryInterface(Components.interfaces.nsIJSID);
id.init(str);
return id;
}
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
print("NS_ISUPPORTS_IID = " + NS_ISUPPORTS_IID);

View File

@ -3,7 +3,7 @@
function nsID(str)
{
var id = Components.classes.nsIID.newInstance();
id = id.QueryInterface(Components.interfaces.nsIID);
id = id.QueryInterface(Components.interfaces.nsIJSIID);
id.init(str);
return id;
}
@ -11,6 +11,7 @@ function nsID(str)
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
var NS_ITESTXPC_FOO_IID = new nsID("{159E36D0-991E-11d2-AC3F-00C09300144B}");
var baz = foo.QueryInterface(NS_ITESTXPC_FOO_IID);
print("baz = "+baz);
print("distinct wrapper test "+ (foo != baz ? "passed" : "failed"));
@ -113,7 +114,7 @@ print("In2OutOneString - "+(
// SendManyTypes
var reciever_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 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],
@ -148,8 +149,8 @@ if(all_ok)
// SendInOutManyTypes
var reciever_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,12,14,16,123,2.5,8.000008,false,'z','l',NS_ISUPPORTS_IID,"foo string","yet another string"];
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"];
reciever.SendInOutManyTypes = function()
{

View File

@ -49,7 +49,9 @@ XPCContext::newXPCContext(JSContext* aJSContext,
xpcc->GetWrappedJSMap() &&
xpcc->GetWrappedNativeMap() &&
xpcc->GetWrappedJSClassMap() &&
xpcc->GetWrappedNativeClassMap())
xpcc->GetWrappedNativeClassMap() &&
xpcc->mConstuctorStrID &&
xpcc->mToStringStrID)
{
return xpcc;
}
@ -71,6 +73,12 @@ XPCContext::XPCContext(JSContext* aJSContext,
mWrappedNativeMap = Native2WrappedNativeMap::newMap(WrappedNativeMapSize);
mWrappedJSClassMap = IID2WrappedJSClassMap::newMap(WrappedJSClassMapSize);
mWrappedNativeClassMap = IID2WrappedNativeClassMap::newMap(WrappedNativeClassMapSize);
JS_ValueToId(aJSContext,
STRING_TO_JSVAL(JS_InternString(aJSContext, "constructor")),
&mConstuctorStrID);
JS_ValueToId(aJSContext,
STRING_TO_JSVAL(JS_InternString(aJSContext, "toString")),
&mToStringStrID);
}
XPCContext::~XPCContext()

View File

@ -260,7 +260,7 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
JSBool
XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
const nsXPTType& type,
nsIAllocator* al, const nsID* iid,
JSBool useAllocator, const nsID* iid,
uintN* pErr)
{
NS_PRECONDITION(d, "bad param");
@ -385,7 +385,7 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
return JS_FALSE;
case nsXPTType::T_IID:
{
NS_ASSERTION(al,"trying to convert a JSID to nsID without allocator");
NS_ASSERTION(useAllocator,"trying to convert a JSID to nsID without allocator");
JSObject* obj;
const nsID* pid=NULL;
@ -414,10 +414,10 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
{
return JS_FALSE;
}
if(al)
if(useAllocator)
{
int len = strlen(bytes)+1;
if(!(*((void**)d) = al->Alloc(len)))
if(!(*((void**)d) = XPCMem::Alloc(len)))
{
return JS_FALSE;
}
@ -439,10 +439,10 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
{
return JS_FALSE;
}
if(al)
if(useAllocator)
{
int byte_len = (JS_GetStringLength(str)+1)*sizeof(jschar);
if(!(*((void**)d) = al->Alloc(byte_len)))
if(!(*((void**)d) = XPCMem::Alloc(byte_len)))
{
// XXX should report error
return JS_FALSE;

View File

@ -23,84 +23,6 @@
/***************************************************************************/
// stuff used for both classes...
class IDForJSScriptable : public nsIXPCScriptable
{
public:
NS_DECL_ISUPPORTS;
XPC_DECLARE_IXPCSCRIPTABLE;
IDForJSScriptable();
virtual ~IDForJSScriptable();
};
IDForJSScriptable::IDForJSScriptable()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
IDForJSScriptable::~IDForJSScriptable() {}
static NS_DEFINE_IID(kIDForJSScriptableIID, NS_IXPCSCRIPTABLE_IID);
NS_IMPL_ISUPPORTS(IDForJSScriptable, kIDForJSScriptableIID);
XPC_IMPLEMENT_IGNORE_CREATE(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_LOOKUPPROPERTY(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_GETPROPERTY(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_SETPROPERTY(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(IDForJSScriptable);
//XPC_IMPLEMENT_IGNORE_DEFAULTVALUE(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_ENUMERATE(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_CHECKACCESS(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_CALL(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_CONSTRUCT(IDForJSScriptable);
XPC_IMPLEMENT_IGNORE_FINALIZE(IDForJSScriptable);
NS_IMETHODIMP
IDForJSScriptable::DefaultValue(JSContext *cx, JSObject *obj,
JSType type, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
JSBool success = JS_FALSE;
if(type == JSTYPE_STRING || type == JSTYPE_VOID)
{
nsIJSID* nsid;
if(NS_SUCCEEDED(wrapper->GetNative((nsISupports**)&nsid)))
{
char* str;
if(NS_SUCCEEDED(nsid->GetNumber(&str)))
{
JSString* jsstr = JS_NewStringCopyZ(cx, str);
XPCMem::Free(str);
if(jsstr)
{
*vp = STRING_TO_JSVAL(jsstr);
*retval = success = JS_TRUE;
}
}
NS_RELEASE(nsid);
if(success)
return NS_OK;
}
}
return arbitrary->DefaultValue(cx, obj, type, vp, wrapper, NULL, retval);
}
/****************************************************/
// we leak one of these over the lifetime of the process...
static IDForJSScriptable* GetSharedScriptable()
{
static IDForJSScriptable* scriptable = NULL;
if(!scriptable)
scriptable = new IDForJSScriptable;
return scriptable;
}
static const nsID& GetInvalidIID()
{
// {BB1F47B0-D137-11d2-9841-006008962422}
@ -127,12 +49,6 @@ nsJSIID::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXPCScriptable::GetIID())) {
IDForJSScriptable* scriptable = GetSharedScriptable();
*aInstancePtr = (void*) scriptable;
NS_ADDREF(scriptable);
return NS_OK;
}
*aInstancePtr = NULL;
return NS_NOINTERFACE;
}
@ -309,6 +225,12 @@ nsJSIID::init(const char *idString, PRBool *_retval)
return NS_OK;
}
NS_IMETHODIMP
nsJSIID::toString(char **_retval)
{
return GetName(_retval);
}
/***************************************************************************/
// nsJSCID
@ -325,12 +247,6 @@ nsJSCID::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXPCScriptable::GetIID())) {
IDForJSScriptable* scriptable = GetSharedScriptable();
*aInstancePtr = (void*) scriptable;
NS_ADDREF(scriptable);
return NS_OK;
}
*aInstancePtr = NULL;
return NS_NOINTERFACE;
}
@ -486,6 +402,12 @@ nsJSCID::init(const char *idString, PRBool *_retval)
return NS_OK;
}
NS_IMETHODIMP
nsJSCID::toString(char **_retval)
{
return GetName(_retval);
}
NS_IMETHODIMP
nsJSCID::newInstance(nsISupports **_retval)
{
@ -547,7 +469,8 @@ xpc_JSObjectToID(JSContext *cx, JSObject* obj)
nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(cx, obj);
if(wrapper)
{
if(wrapper->GetIID().Equals(nsIJSIID::GetIID()) ||
if(wrapper->GetIID().Equals(nsIJSID::GetIID()) ||
wrapper->GetIID().Equals(nsIJSIID::GetIID()) ||
wrapper->GetIID().Equals(nsIJSCID::GetIID()))
{
((nsIJSID*)wrapper->GetNative())->GetId(&id);

View File

@ -44,6 +44,9 @@ class nsIJSID : public nsISupports {
/* boolean init (in string idString); */
NS_IMETHOD init(const char *idString, PRBool *_retval) = 0;
/* string toString (); */
NS_IMETHOD toString(char **_retval) = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSID *priv);

View File

@ -117,14 +117,21 @@ public:
int WrappedJSClassMapSize,
int WrappedNativeClassMapSize);
JSContext* GetJSContext() {return mJSContext;}
JSObject* GetGlobalObject() {return mGlobalObj;}
nsXPConnect* GetXPConnect() {return mXPConnect;}
JSContext* GetJSContext() const {return mJSContext;}
JSObject* GetGlobalObject() const {return mGlobalObj;}
nsXPConnect* GetXPConnect() const {return mXPConnect;}
JSObject2WrappedJSMap* GetWrappedJSMap() {return mWrappedJSMap;}
Native2WrappedNativeMap* GetWrappedNativeMap() {return mWrappedNativeMap;}
IID2WrappedJSClassMap* GetWrappedJSClassMap() {return mWrappedJSClassMap;}
IID2WrappedNativeClassMap* GetWrappedNativeClassMap() {return mWrappedNativeClassMap;}
JSObject2WrappedJSMap* GetWrappedJSMap() const
{return mWrappedJSMap;}
Native2WrappedNativeMap* GetWrappedNativeMap() const
{return mWrappedNativeMap;}
IID2WrappedJSClassMap* GetWrappedJSClassMap() const
{return mWrappedJSClassMap;}
IID2WrappedNativeClassMap* GetWrappedNativeClassMap() const
{return mWrappedNativeClassMap;}
jsid GetConstructorStrID() const {return mConstuctorStrID;}
jsid GetToStringStrID() const {return mToStringStrID;}
JSBool Init(JSObject* aGlobalObj = NULL);
void DebugDump(int depth);
@ -146,6 +153,8 @@ private:
Native2WrappedNativeMap* mWrappedNativeMap;
IID2WrappedJSClassMap* mWrappedJSClassMap;
IID2WrappedNativeClassMap* mWrappedNativeClassMap;
jsid mConstuctorStrID;
jsid mToStringStrID;
};
/***************************************************************************/
@ -570,7 +579,7 @@ public:
static JSBool JSData2Native(JSContext* cx, void* d, jsval s,
const nsXPTType& type,
nsIAllocator* al, const nsID* iid,
JSBool useAllocator, const nsID* iid,
uintN* pErr);
private:
XPCConvert(); // not implemented
@ -619,6 +628,9 @@ public:
/* boolean init (in string idString); */
NS_IMETHOD init(const char *idString, PRBool *_retval);
/* string toString (); */
NS_IMETHOD toString(char **_retval);
nsJSIID();
virtual ~nsJSIID();
@ -663,6 +675,9 @@ public:
/* nsISupports newInstance (); */
NS_IMETHOD newInstance(nsISupports **_retval);
/* string toString (); */
NS_IMETHOD toString(char **_retval);
nsJSCID();
virtual ~nsJSCID();

116
js/src/xpconnect/xpctest.h Normal file
View File

@ -0,0 +1,116 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM xpctest.idl
*/
#ifndef __gen_xpctest_h__
#define __gen_xpctest_h__
#include "nsISupports.h" /* interface nsISupports */
#ifdef XPIDL_JS_STUBS
#include "jsapi.h"
#endif
/* starting interface nsITestXPCFoo */
/* {159E36D0-991E-11d2-AC3F-00C09300144B} */
#define NS_ITESTXPCFOO_IID_STR "159E36D0-991E-11d2-AC3F-00C09300144B"
#define NS_ITESTXPCFOO_IID \
{0x159E36D0, 0x991E, 0x11d2, \
{ 0xAC, 0x3F, 0x00, 0xC0, 0x93, 0x00, 0x14, 0x4B }}
class nsITestXPCFoo : public nsISupports {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_ITESTXPCFOO_IID;
return iid;
}
/* long Test (in long p1, in long p2); */
NS_IMETHOD Test(PRInt32 p1, PRInt32 p2, PRInt32 *_retval) = 0;
/* void Test2 (); */
NS_IMETHOD Test2() = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsITestXPCFoo *priv);
#endif
};
/* starting interface nsITestXPCFoo2 */
/* {5F9D20C0-9B6B-11d2-9FFE-000064657374} */
#define NS_ITESTXPCFOO2_IID_STR "5F9D20C0-9B6B-11d2-9FFE-000064657374"
#define NS_ITESTXPCFOO2_IID \
{0x5F9D20C0, 0x9B6B, 0x11d2, \
{ 0x9F, 0xFE, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74 }}
class nsITestXPCFoo2 : public nsITestXPCFoo {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_ITESTXPCFOO2_IID;
return iid;
}
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsITestXPCFoo2 *priv);
#endif
};
/* starting interface nsIEcho */
/* {CD2F2F40-C5D9-11d2-9838-006008962422} */
#define NS_IECHO_IID_STR "CD2F2F40-C5D9-11d2-9838-006008962422"
#define NS_IECHO_IID \
{0xCD2F2F40, 0xC5D9, 0x11d2, \
{ 0x98, 0x38, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
class nsIEcho : public nsISupports {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_IECHO_IID;
return iid;
}
/* void SetReciever (in nsIEcho aReciever); */
NS_IMETHOD SetReciever(nsIEcho *aReciever) = 0;
/* void SendOneString (in string str); */
NS_IMETHOD SendOneString(const char *str) = 0;
/* long In2OutOneInt (in long input); */
NS_IMETHOD In2OutOneInt(PRInt32 input, PRInt32 *_retval) = 0;
/* long In2OutAddTwoInts (in long input1, in long input2, out long output1, out long output2); */
NS_IMETHOD In2OutAddTwoInts(PRInt32 input1, PRInt32 input2, PRInt32 *output1, PRInt32 *output2, PRInt32 *_retval) = 0;
/* string In2OutOneString (in string input); */
NS_IMETHOD In2OutOneString(const char *input, char **_retval) = 0;
/* void SimpleCallNoEcho (); */
NS_IMETHOD SimpleCallNoEcho() = 0;
/* void SendManyTypes (in octet p1, in short p2, in long p3, in long long p4, in octet p5, in unsigned short p6, in unsigned long p7, in unsigned long long p8, in float p9, in double p10, in boolean p11, in char p12, in wchar p13, in nsID p14, in string p15, in wstring p16); */
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) = 0;
/* void SendInOutManyTypes (inout octet p1, inout short p2, inout long p3, inout long long p4, inout octet p5, inout unsigned short p6, inout unsigned long p7, inout unsigned long long p8, inout float p9, inout double p10, inout boolean p11, inout char p12, inout wchar p13, inout nsID p14, inout string p15, inout wstring 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, PRUnichar **p16) = 0;
/* void MethodWithNative (in long p1, in voidStar p2); */
NS_IMETHOD MethodWithNative(PRInt32 p1, void* p2) = 0;
/* void ReturnCode (in long code); */
NS_IMETHOD ReturnCode(PRInt32 code) = 0;
/* void FailInJSTest (in long fail); */
NS_IMETHOD FailInJSTest(PRInt32 fail) = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIEcho *priv);
#endif
};
#endif /* __gen_xpctest_h__ */

View File

@ -48,6 +48,7 @@ void XPCMem::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;

View File

@ -282,17 +282,15 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
JSErrorReporter older;
JSBool success;
JSContext* cx = GetJSContext();
nsIAllocator* al = NULL;
JSBool InConversionsDone = JS_FALSE;
nsID* conditional_iid = NULL;
JSBool iidIsOwned = JS_FALSE;
// XXX ASSUMES that retval is last arg.
paramCount = info->GetParamCount();
argc = paramCount -
(paramCount && info->GetParam(paramCount-1).IsRetval() ? 1 : 0);
if(!(al = nsXPConnect::GetAllocator()))
goto pre_call_clean_up;
if(!IsReflectable(methodIndex))
goto pre_call_clean_up;
@ -311,7 +309,6 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
// build the args
for(i = 0; i < argc; i++)
{
const nsID* conditional_iid = NULL;
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
jsval val;
@ -327,8 +324,12 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
if(type.TagPart() == nsXPTType::T_INTERFACE)
{
if(!(conditional_iid = param.GetInterfaceIID()))
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(&param, &conditional_iid)))
{
goto pre_call_clean_up;
}
iidIsOwned = JS_TRUE;
}
else if(type.TagPart() == nsXPTType::T_INTERFACE_IS)
{
@ -351,6 +352,15 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
{
goto pre_call_clean_up;
}
if(conditional_iid)
{
if(iidIsOwned)
{
XPCMem::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = NULL;
}
}
if(param.IsOut())
@ -399,15 +409,25 @@ pre_call_clean_up:
else
{
void** pp;
if((NULL != (pp = (void**) params[i].val.p)) && NULL != *pp && al)
if((NULL != (pp = (void**) params[i].val.p)) && NULL != *pp)
{
if(param.IsIn())
al->Free(*pp);
XPCMem::Free(*pp);
*pp = NULL;
}
}
}
if(conditional_iid)
{
if(iidIsOwned)
{
XPCMem::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = NULL;
}
if(!InConversionsDone)
goto done;
@ -435,8 +455,7 @@ pre_call_clean_up:
if(param.IsOut())
{
jsval val;
nsIAllocator* conditional_al = NULL;
const nsID* conditional_iid = NULL;
JSBool useAllocator = JS_FALSE;
const nsXPTType& type = param.GetType();
nsXPCMiniVariant* pv;
@ -451,8 +470,12 @@ pre_call_clean_up:
if(type.TagPart() == nsXPTType::T_INTERFACE)
{
if(!(conditional_iid = param.GetInterfaceIID()))
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(&param, &conditional_iid)))
{
break;
}
iidIsOwned = JS_TRUE;
}
else if(type.TagPart() == nsXPTType::T_INTERFACE_IS)
{
@ -464,11 +487,21 @@ pre_call_clean_up:
break;
}
else if(type.IsPointer())
conditional_al = al;
useAllocator = JS_TRUE;
if(!XPCConvert::JSData2Native(cx, &pv->val, val, type,
conditional_al, conditional_iid, NULL))
useAllocator, conditional_iid, NULL))
break;
if(conditional_iid)
{
if(iidIsOwned)
{
XPCMem::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = NULL;
}
}
}
@ -476,7 +509,7 @@ pre_call_clean_up:
// to cleanup any junk that *did* get converted.
if(i != paramCount)
{
// XXX major spagetti!
// XXX major spaghetti!
InConversionsDone = JS_FALSE;
goto pre_call_clean_up;
}
@ -486,8 +519,10 @@ pre_call_clean_up:
done:
if(argv && argv != argsBuffer)
delete [] argv;
if(al)
NS_RELEASE(al);
if(conditional_iid && iidIsOwned)
XPCMem::Free((void*)conditional_iid);
return retval;
}
@ -524,14 +559,10 @@ nsXPCWrappedJSClass::DebugDump(int depth)
XPC_LOG_ALWAYS(("nsXPCWrappedJSClass @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
char* name;
nsIAllocator* al;
mInfo->GetName(&name);
XPC_LOG_ALWAYS(("interface name is %s", name));
if(name && NULL != (al = nsXPConnect::GetAllocator()))
{
al->Free(name);
NS_RELEASE(al);
}
if(name)
XPCMem::Free(name);
char * iid = mIID.ToString();
XPC_LOG_ALWAYS(("IID number is %s", iid));
delete iid;

View File

@ -239,10 +239,31 @@ WrappedNative_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
case JSTYPE_VOID:
case JSTYPE_STRING:
// XXX perhaps more expressive toString?
*vp = STRING_TO_JSVAL(
JS_NewStringCopyZ(cx, wrapper->GetClass()->GetInterfaceName()));
return JS_TRUE;
{
nsXPCWrappedNativeClass* clazz = wrapper->GetClass();
NS_ASSERTION(clazz,"wrapper without class");
const XPCNativeMemberDescriptor* desc =
clazz->LookupMemberByID(clazz->GetXPCContext()->GetToStringStrID());
if(desc && desc->IsMethod())
{
if(!clazz->CallWrappedMethod(cx, wrapper, desc,
JS_FALSE, 0, NULL, vp))
return JS_FALSE;
if(JSVAL_IS_PRIMITIVE(*vp))
return JS_TRUE;
}
// else...
char* sz = JS_smprintf("[xpconnect wrapped %s]",
wrapper->GetClass()->GetInterfaceName());
if(sz)
{
*vp = STRING_TO_JSVAL(JS_NewString(cx, sz, strlen(sz)));
return JS_TRUE;
}
JS_ReportOutOfMemory(cx);
return JS_FALSE;
}
case JSTYPE_NUMBER:
*vp = JSVAL_ONE;
@ -360,19 +381,11 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
jsval src;
uint8 vtblIndex;
nsresult invokeResult;
nsIAllocator* al = NULL;
const nsID* conditional_iid = NULL;
JSBool iidIsOwned = JS_TRUE;
nsID* conditional_iid = NULL;
uintN err;
*vp = JSVAL_NULL;
if(!(al = nsXPConnect::GetAllocator()))
{
ThrowException(XPCJSError::UNEXPECTED, cx, desc);
goto done;
}
// make sure we have what we need
if(isAttributeSet)
@ -416,7 +429,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
// iterate through the params doing conversions
for(i = 0; i < paramCount; i++)
{
nsIAllocator* conditional_al = NULL;
JSBool useAllocator = JS_FALSE;
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
@ -448,7 +461,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
// in the future there may be a param flag indicating 'shared'
if(type.IsPointer())
{
conditional_al = al;
useAllocator = JS_TRUE;
dp->flags |= nsXPCVariant::VAL_IS_OWNED;
}
}
@ -457,7 +470,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
src = argv[i];
if(type.IsPointer() && type.TagPart() == nsXPTType::T_IID)
{
conditional_al = al;
useAllocator = JS_TRUE;
dp->flags |= nsXPCVariant::VAL_IS_OWNED;
}
}
@ -466,13 +479,13 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
{
dp->flags |= nsXPCVariant::VAL_IS_IFACE;
if(!(conditional_iid = param.GetInterfaceIID()))
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(&param, &conditional_iid)))
{
ThrowBadParamException(XPCJSError::CANT_GET_PARAM_IFACE_INFO,
cx, desc, i);
goto done;
}
iidIsOwned = JS_FALSE;
}
else if(type.TagPart() == nsXPTType::T_INTERFACE_IS)
{
@ -483,7 +496,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
const nsXPTType& type = param.GetType();
if(!type.IsPointer() || type.TagPart() != nsXPTType::T_IID ||
!XPCConvert::JSData2Native(cx, &conditional_iid, argv[arg_num],
type, al, NULL, NULL))
type, JS_TRUE, NULL, NULL))
{
ThrowBadParamException(XPCJSError::CANT_GET_PARAM_IFACE_INFO,
cx, desc, i);
@ -492,17 +505,15 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
}
if(!XPCConvert::JSData2Native(cx, &dp->val, src, type,
conditional_al, conditional_iid, &err))
useAllocator, conditional_iid, &err))
{
ThrowBadParamException(err, cx, desc, i);
goto done;
}
if(conditional_iid)
{
if(iidIsOwned)
al->Free((void*)conditional_iid);
XPCMem::Free((void*)conditional_iid);
conditional_iid = NULL;
iidIsOwned = JS_TRUE;
}
}
@ -521,7 +532,6 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
{
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
const nsID* conditional_iid = NULL;
nsXPCVariant* dp = &dispatchParams[i];
if(param.IsOut())
@ -530,7 +540,8 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
if(type.TagPart() == nsXPTType::T_INTERFACE)
{
if(!(conditional_iid = param.GetInterfaceIID()))
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(&param, &conditional_iid)))
{
ThrowBadParamException(XPCJSError::CANT_GET_PARAM_IFACE_INFO,
cx, desc, i);
@ -543,7 +554,9 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
const nsXPTParamInfo& param = info->GetParam(arg_num);
const nsXPTType& type = param.GetType();
if(!type.IsPointer() || type.TagPart() != nsXPTType::T_IID ||
!(conditional_iid = (nsID*)dispatchParams[arg_num].val.p))
!(conditional_iid = (nsID*)
XPCMem::Clone(dispatchParams[arg_num].val.p,
sizeof(nsID))))
{
ThrowBadParamException(XPCJSError::CANT_GET_PARAM_IFACE_INFO,
cx, desc, i);
@ -571,6 +584,11 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
goto done;
}
}
if(conditional_iid)
{
XPCMem::Free((void*)conditional_iid);
conditional_iid = NULL;
}
}
}
retval = JS_TRUE;
@ -584,18 +602,16 @@ done:
void* p = dp->val.p;
if(!p)
continue;
if(dp->IsValOwned() && al)
al->Free(p);
if(dp->IsValOwned())
XPCMem::Free(p);
if(dp->IsValInterface())
((nsISupports*)p)->Release();
}
if(conditional_iid && iidIsOwned && al)
al->Free((void*)conditional_iid);
if(conditional_iid)
XPCMem::Free((void*)conditional_iid);
if(dispatchParams && dispatchParams != paramBuffer)
delete [] dispatchParams;
if(al)
NS_RELEASE(al);
return retval;
}
@ -662,7 +678,8 @@ WrappedNative_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
wrapper = (nsXPCWrappedNative*) JS_GetPrivate(cx, obj);
if(!wrapper)
{
if(isConstructorID(cx, id))
XPCContext* xpcc = nsXPConnect::GetContext(cx);
if(xpcc && id == xpcc->GetConstructorStrID())
{
// silently fail when looking for constructor property
*vp = JSVAL_VOID;

View File

@ -1,707 +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.
*/
/* InterfaceInfo support code - some temporary. */
#include <string.h>
#include <stdlib.h>
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
#include "xpt_struct.h"
#include "xpt_cpp.h"
// declare this in the .cpp file for now
class InterfaceInfoImpl : public nsIInterfaceInfo
{
NS_DECL_ISUPPORTS;
NS_IMETHOD GetName(char** name); // returns IAllocatator alloc'd copy
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
NS_IMETHOD GetParent(nsIInterfaceInfo** parent);
// these include counts of parents
NS_IMETHOD GetMethodCount(uint16* count);
NS_IMETHOD GetConstantCount(uint16* count);
// These include methods and constants of parents.
// There do *not* make copies ***explicit bending of XPCOM rules***
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info);
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
public:
InterfaceInfoImpl(XPTInterfaceDirectoryEntry* entry,
InterfaceInfoImpl* parent);
virtual ~InterfaceInfoImpl();
private:
XPTInterfaceDirectoryEntry* mEntry;
InterfaceInfoImpl* mParent;
uint16 mMethodBaseIndex;
uint16 mMethodCount;
uint16 mConstantBaseIndex;
uint16 mConstantCount;
};
// declare this in the .cpp file for now
class InterfaceInfoManagerImpl : public nsIInterfaceInfoManager
{
NS_DECL_ISUPPORTS;
// nsIInformationInfo management services
NS_IMETHOD GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info);
NS_IMETHOD GetInfoForName(const char* name, nsIInterfaceInfo** info);
// name <-> IID mapping services
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid);
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name);
public:
InterfaceInfoManagerImpl();
virtual ~InterfaceInfoManagerImpl();
static InterfaceInfoManagerImpl* GetInterfaceInfoManager();
static nsIAllocator* GetAllocator(InterfaceInfoManagerImpl* iim = NULL);
private:
PRBool BuildInterfaceForEntry(uint16 index);
private:
// bogus implementation...
InterfaceInfoImpl** mInfoArray;
nsIAllocator* mAllocator;
};
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
// hacked hardcoded simulation...
XPTParamDescriptor ResultParam[] = {
{XPT_PD_OUT, {TD_UINT32,0}}
};
/***************/
XPTParamDescriptor QueryInterfaceParams[2] = {
{XPT_PD_IN, {TD_PNSIID|XPT_TDP_POINTER|XPT_TDP_REFERENCE,0}},
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_IS_TYPE,0}}
};
XPTMethodDescriptor nsISupportsMethods[3] = {
{0, "QueryInterface", 2, QueryInterfaceParams, ResultParam},
{0, "AddRef", 0, NULL, ResultParam},
{0, "Release", 0, NULL, ResultParam}
};
XPTInterfaceDescriptor nsISupportsInterfaceDescriptor =
{NULL, 3, nsISupportsMethods, 0, NULL};
/***************/
XPTParamDescriptor TestParams[3] = {
{XPT_PD_IN, {TD_INT32,0}},
{XPT_PD_IN, {TD_INT32,0}},
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_UINT32,0}}
};
XPTMethodDescriptor nsITestXPCFooMethods[2] = {
{0, "Test", 3, TestParams, ResultParam},
{0, "Test2", 0, NULL, ResultParam}
};
XPTConstDescriptor nsITestXPCFooConstants[3] = {
{"five", {TD_INT32,0}, 5},
{"six", {TD_INT32,0}, 6},
{"seven", {TD_INT32,0}, 7}
};
XPTInterfaceDescriptor nsITestXPCFooInterfaceDescriptor =
{NULL, 2, nsITestXPCFooMethods, 3, nsITestXPCFooConstants};
XPTInterfaceDescriptor nsITestXPCFoo2InterfaceDescriptor =
{NULL, 0, NULL, 0, NULL};
/***************/
XPTParamDescriptor nsIEcho_SetRecieverParams[1] = {
{XPT_PD_IN, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}} // fixup index later
};
XPTParamDescriptor nsIEcho_SendOneStringParams[1] = {
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PSTRING,0}}
};
XPTParamDescriptor nsIEcho_In2OutOneIntParams[2] = {
{XPT_PD_IN, {TD_INT32,0}},
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_INT32,0}}
};
XPTParamDescriptor nsIEcho_In2OutAddTwoIntsParams[5] = {
{XPT_PD_IN, {TD_INT32,0}},
{XPT_PD_IN, {TD_INT32,0}},
{XPT_PD_OUT, {TD_INT32,0}},
{XPT_PD_OUT, {TD_INT32,0}},
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_INT32,0}}
};
XPTParamDescriptor nsIEcho_In2OutOneStringParams[2] = {
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PSTRING,0}},
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PSTRING,0}}
};
XPTParamDescriptor nsIEcho_SendManyTypesParams[16] = {
{XPT_PD_IN, {TD_INT8 ,0}},
{XPT_PD_IN, {TD_INT16 ,0}},
{XPT_PD_IN, {TD_INT32 ,0}},
{XPT_PD_IN, {TD_INT64 ,0}},
{XPT_PD_IN, {TD_UINT8 ,0}},
{XPT_PD_IN, {TD_UINT16 ,0}},
{XPT_PD_IN, {TD_UINT32 ,0}},
{XPT_PD_IN, {TD_UINT64 ,0}},
{XPT_PD_IN, {TD_FLOAT ,0}},
{XPT_PD_IN, {TD_DOUBLE ,0}},
{XPT_PD_IN, {TD_BOOL ,0}},
{XPT_PD_IN, {TD_CHAR ,0}},
{XPT_PD_IN, {TD_WCHAR ,0}},
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PNSIID ,0}},
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PSTRING ,0}},
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PWSTRING ,0}}
};
XPTParamDescriptor nsIEcho_SendInOutManyTypesParams[16] = {
{XPT_PD_IN|XPT_PD_OUT, {TD_INT8 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_INT16 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_INT32 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_INT64 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_UINT8 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_UINT16 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_UINT32 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_UINT64 ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_FLOAT ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_DOUBLE ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_BOOL ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_CHAR ,0}},
{XPT_PD_IN|XPT_PD_OUT, {TD_WCHAR ,0}},
{XPT_PD_IN|XPT_PD_OUT, {XPT_TDP_POINTER|TD_PNSIID ,0}},
{XPT_PD_IN|XPT_PD_OUT, {XPT_TDP_POINTER|TD_PSTRING ,0}},
{XPT_PD_IN|XPT_PD_OUT, {XPT_TDP_POINTER|TD_PWSTRING ,0}}
};
XPTParamDescriptor nsIEcho_MethodWithNativeParams[2] = {
{XPT_PD_IN, {TD_INT32,0}},
{XPT_PD_IN, {XPT_TDP_POINTER|TD_VOID,0}}
};
XPTParamDescriptor nsIEcho_ReturnCodeParams[1] = {
{XPT_PD_IN, {TD_INT32,0}}
};
XPTParamDescriptor nsIEcho_FailInJSTestParams[1] = {
{XPT_PD_IN, {TD_INT32,0}}
};
XPTMethodDescriptor nsIEchoMethods[11] = {
{0, "SetReciever", 1, nsIEcho_SetRecieverParams, ResultParam},
{0, "SendOneString", 1, nsIEcho_SendOneStringParams, ResultParam},
{0, "In2OutOneInt", 2, nsIEcho_In2OutOneIntParams, ResultParam},
{0, "In2OutAddTwoInts", 5, nsIEcho_In2OutAddTwoIntsParams, ResultParam},
{0, "In2OutOneString", 2, nsIEcho_In2OutOneStringParams, ResultParam},
{0, "SimpleCallNoEcho", 0, NULL, ResultParam},
{0, "SendManyTypes", 16, nsIEcho_SendManyTypesParams, ResultParam},
{0, "SendInOutManyTypes", 16, nsIEcho_SendInOutManyTypesParams, ResultParam},
{0, "MethodWithNative", 2, nsIEcho_MethodWithNativeParams, ResultParam},
{0, "ReturnCode", 1, nsIEcho_ReturnCodeParams, ResultParam},
{0, "FailInJSTest", 1, nsIEcho_FailInJSTestParams, ResultParam}
};
XPTInterfaceDescriptor nsIEchoInterfaceDescriptor =
{NULL, 11, nsIEchoMethods, 0, NULL};
/***************/
XPTParamDescriptor nsIXPCComponents_GetInterfacesParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}} // fixup index later
};
XPTParamDescriptor nsIXPCComponents_GetClassesParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}} // fixup index later
};
XPTMethodDescriptor nsIXPCComponentsMethods[2] = {
{XPT_MD_GETTER, "interfaces", 1, nsIXPCComponents_GetInterfacesParams, ResultParam},
{XPT_MD_GETTER, "classes", 1, nsIXPCComponents_GetClassesParams, ResultParam}
};
XPTInterfaceDescriptor nsIXPCComponentsInterfaceDescriptor =
{NULL, 2, nsIXPCComponentsMethods, 0, NULL};
/***************/
XPTInterfaceDescriptor nsIXPCInterfacesInterfaceDescriptor =
{NULL, 0, NULL, 0, NULL};
/***************/
XPTInterfaceDescriptor nsIXPCClassesInterfaceDescriptor =
{NULL, 0, NULL, 0, NULL};
/***************/
XPTParamDescriptor nsIJSID_GetNameParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PSTRING ,0}}
};
XPTParamDescriptor nsIJSID_GetNumberParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PSTRING ,0}}
};
XPTParamDescriptor nsIJSID_GetIdParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PNSIID ,0}}
};
XPTParamDescriptor nsIJSID_GetValidParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_BOOL ,0}}
};
XPTParamDescriptor nsIJSID_EqualsParams[2] = {
{XPT_PD_IN, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}}, // fixup index later
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_BOOL ,0}}
};
XPTParamDescriptor nsIJSID_InitParams[2] = {
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PSTRING ,0}},
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_BOOL ,0}}
};
XPTMethodDescriptor nsIJSIDMethods[6] = {
{XPT_MD_GETTER, "name", 1, nsIJSID_GetNameParams, ResultParam},
{XPT_MD_GETTER, "number", 1, nsIJSID_GetNumberParams, ResultParam},
{XPT_MD_GETTER, "id", 1, nsIJSID_GetIdParams, ResultParam},
{XPT_MD_GETTER, "valid", 1, nsIJSID_GetValidParams, ResultParam},
{0, "equals", 2, nsIJSID_EqualsParams, ResultParam},
{0, "init", 2, nsIJSID_InitParams, ResultParam}
};
XPTInterfaceDescriptor nsIJSIDInterfaceDescriptor =
{NULL, 6, nsIJSIDMethods, 0, NULL};
/***************/
XPTInterfaceDescriptor nsIJSIIDInterfaceDescriptor =
{NULL, 0, NULL, 0, NULL};
/***************/
XPTParamDescriptor nsIJSCID_NewInstanceParams[1] = {
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}}// fixup index later
};
XPTMethodDescriptor nsIJSCIDMethods[1] = {
{0, "newInstance", 1, nsIJSCID_NewInstanceParams, ResultParam}
};
XPTInterfaceDescriptor nsIJSCIDInterfaceDescriptor =
{NULL, 1, nsIJSCIDMethods, 0, NULL};
/***************/
XPTInterfaceDirectoryEntry InterfaceDirectoryEntryTable[] = {
{NS_ISUPPORTS_IID, "nsISupports", "", &nsISupportsInterfaceDescriptor},
{NS_ITESTXPC_FOO_IID, "nsITestXPCFoo", "", &nsITestXPCFooInterfaceDescriptor},
{NS_ITESTXPC_FOO2_IID, "nsITestXPCFoo2", "", &nsITestXPCFoo2InterfaceDescriptor},
{NS_IECHO_IID, "nsIEcho", "", &nsIEchoInterfaceDescriptor},
{NS_IXPCCOMPONENTS_IID,"nsIXPCComponents","", &nsIXPCComponentsInterfaceDescriptor},
{NS_IXPCINTERFACES_IID,"nsIXPCInterfaces","", &nsIXPCInterfacesInterfaceDescriptor},
{NS_IXPCCLASSES_IID, "nsIXPCClasses", "", &nsIXPCClassesInterfaceDescriptor},
{NS_IJSID_IID, "nsID", "", &nsIJSIDInterfaceDescriptor},
{NS_IJSIID_IID, "nsIID", "", &nsIJSIIDInterfaceDescriptor},
{NS_IJSCID_IID, "nsCID", "", &nsIJSCIDInterfaceDescriptor},
};
/***************/
#define ENTRY_COUNT (sizeof(InterfaceDirectoryEntryTable)/sizeof(InterfaceDirectoryEntryTable[0]))
#define TABLE_INDEX(p) ((p)-InterfaceDirectoryEntryTable)
static void BogusTableInit()
{
// NOTE: reference are all off by 1 - '0' means 'none'
nsISupportsInterfaceDescriptor.parent_interface = 0;
nsITestXPCFooInterfaceDescriptor.parent_interface = 1;
nsITestXPCFoo2InterfaceDescriptor.parent_interface = 2;
nsIEchoInterfaceDescriptor.parent_interface = 1;
nsIXPCComponentsInterfaceDescriptor.parent_interface = 1;
nsIXPCInterfacesInterfaceDescriptor.parent_interface = 1;
nsIXPCClassesInterfaceDescriptor.parent_interface = 1;
nsIJSIDInterfaceDescriptor.parent_interface = 1;
nsIJSIIDInterfaceDescriptor.parent_interface = 8;
nsIJSCIDInterfaceDescriptor.parent_interface = 8;
nsIEcho_SetRecieverParams[0].type.type.interface = 4;
nsIXPCComponents_GetInterfacesParams[0].type.type.interface = 6;
nsIXPCComponents_GetClassesParams[0].type.type.interface = 7;
nsIJSID_EqualsParams[0].type.type.interface = 8;
nsIJSCID_NewInstanceParams[0].type.type.interface = 1;
}
/***************************************************************************/
/***************************************************************************/
nsIInterfaceInfo*
nsXPTParamInfo::GetInterface() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
nsIInterfaceInfoManager* mgr;
if(!(mgr = InterfaceInfoManagerImpl::GetInterfaceInfoManager()))
return NULL;
nsIInterfaceInfo* info;
// not optimal!
mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface-1].iid,
&info);
NS_RELEASE(mgr);
return info;
}
const nsIID*
nsXPTParamInfo::GetInterfaceIID() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
return &InterfaceDirectoryEntryTable[type.type.interface-1].iid;
}
/***************************************************************************/
// VERY simple implementations...
static NS_DEFINE_IID(kInterfaceInfoManagerIID, NS_IINTERFACEINFO_MANAGER_IID);
NS_IMPL_ISUPPORTS(InterfaceInfoManagerImpl, kInterfaceInfoManagerIID)
XPC_PUBLIC_API(nsIInterfaceInfoManager*)
XPT_GetInterfaceInfoManager()
{
return InterfaceInfoManagerImpl::GetInterfaceInfoManager();
}
// static
InterfaceInfoManagerImpl*
InterfaceInfoManagerImpl::GetInterfaceInfoManager()
{
static InterfaceInfoManagerImpl* impl = NULL;
if(!impl)
{
impl = new InterfaceInfoManagerImpl();
// XXX ought to check for properly formed impl here..
}
if(impl)
NS_ADDREF(impl);
return impl;
}
// static
nsIAllocator*
InterfaceInfoManagerImpl::GetAllocator(InterfaceInfoManagerImpl* iim /*= NULL*/)
{
nsIAllocator* al;
InterfaceInfoManagerImpl* iiml = iim;
if(!iiml && !(iiml = GetInterfaceInfoManager()))
return NULL;
if(NULL != (al = iiml->mAllocator))
NS_ADDREF(al);
if(!iim)
NS_RELEASE(iiml);
return al;
}
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
InterfaceInfoManagerImpl::InterfaceInfoManagerImpl()
: mInfoArray(NULL),
mAllocator(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
BogusTableInit();
mInfoArray = (InterfaceInfoImpl**) calloc(ENTRY_COUNT,sizeof(void*));
nsServiceManager::GetService(kAllocatorCID,
kIAllocatorIID,
(nsISupports **)&mAllocator);
}
InterfaceInfoManagerImpl::~InterfaceInfoManagerImpl()
{
// let the singleton leak
}
PRBool
InterfaceInfoManagerImpl::BuildInterfaceForEntry(uint16 i)
{
uint16 parent_index =
InterfaceDirectoryEntryTable[i].interface_descriptor->parent_interface;
if(parent_index)
{
if(!mInfoArray[parent_index-1] && ! BuildInterfaceForEntry(parent_index-1))
return PR_FALSE;
mInfoArray[i] = new InterfaceInfoImpl(&InterfaceDirectoryEntryTable[i],
mInfoArray[parent_index-1]);
}
else
{
mInfoArray[i] = new InterfaceInfoImpl(&InterfaceDirectoryEntryTable[i],
NULL);
}
return (PRBool) mInfoArray[i];
}
NS_IMETHODIMP
InterfaceInfoManagerImpl::GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info)
{
for(unsigned int i = 0; i < ENTRY_COUNT;i++)
{
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
if(iid->Equals(entry->iid))
{
if(!mInfoArray[i] && !BuildInterfaceForEntry(i))
break;
*info = mInfoArray[i];
NS_ADDREF(*info);
return NS_OK;
}
}
*info = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
InterfaceInfoManagerImpl::GetInfoForName(const char* name, nsIInterfaceInfo** info)
{
for(unsigned int i = 0; i < ENTRY_COUNT;i++)
{
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
if(!strcmp(name, entry->name))
{
if(!mInfoArray[i] && !BuildInterfaceForEntry(i))
break;
*info = mInfoArray[i];
NS_ADDREF(*info);
return NS_OK;
}
}
*info = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
InterfaceInfoManagerImpl::GetIIDForName(const char* name, nsIID** iid)
{
for(unsigned int i = 0; i < ENTRY_COUNT;i++)
{
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
if(!strcmp(name, entry->name))
{
nsIID* p;
if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID))))
break;
memcpy(p, &entry->iid, sizeof(nsIID));
*iid = p;
return NS_OK;
}
}
*iid = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
InterfaceInfoManagerImpl::GetNameForIID(const nsIID* iid, char** name)
{
for(unsigned int i = 0; i < ENTRY_COUNT;i++)
{
XPTInterfaceDirectoryEntry* entry = &InterfaceDirectoryEntryTable[i];
if(iid->Equals(entry->iid))
{
char* p;
int len = strlen(entry->name)+1;
if(!(p = (char*)mAllocator->Alloc(len)))
break;
memcpy(p, entry->name, len);
*name = p;
return NS_OK;
}
}
*name = NULL;
return NS_ERROR_FAILURE;
}
/***************************************************************************/
static NS_DEFINE_IID(kInterfaceInfoIID, NS_IINTERFACEINFO_IID);
NS_IMPL_ISUPPORTS(InterfaceInfoImpl, kInterfaceInfoIID)
InterfaceInfoImpl::InterfaceInfoImpl(XPTInterfaceDirectoryEntry* entry,
InterfaceInfoImpl* parent)
: mEntry(entry),
mParent(parent)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
if(mParent)
NS_ADDREF(mParent);
if(mParent)
{
mMethodBaseIndex = mParent->mMethodBaseIndex + mParent->mMethodCount;
mConstantBaseIndex = mParent->mConstantBaseIndex + mParent->mConstantCount;
}
else
mMethodBaseIndex = mConstantBaseIndex = 0;
mMethodCount = mEntry->interface_descriptor->num_methods;
mConstantCount = mEntry->interface_descriptor->num_constants;
}
InterfaceInfoImpl::~InterfaceInfoImpl()
{
if(mParent)
NS_RELEASE(mParent);
}
NS_IMETHODIMP
InterfaceInfoImpl::GetName(char** name)
{
NS_PRECONDITION(name, "bad param");
nsIAllocator* allocator;
if(NULL != (allocator = InterfaceInfoManagerImpl::GetAllocator()))
{
int len = strlen(mEntry->name)+1;
char* p = (char*)allocator->Alloc(len);
NS_RELEASE(allocator);
if(p)
{
memcpy(p, mEntry->name, len);
*name = p;
return NS_OK;
}
}
*name = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
InterfaceInfoImpl::GetIID(nsIID** iid)
{
NS_PRECONDITION(iid, "bad param");
nsIAllocator* allocator;
if(NULL != (allocator = InterfaceInfoManagerImpl::GetAllocator()))
{
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
NS_RELEASE(allocator);
if(p)
{
memcpy(p, &mEntry->iid, sizeof(nsIID));
*iid = p;
return NS_OK;
}
}
*iid = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
InterfaceInfoImpl::GetParent(nsIInterfaceInfo** parent)
{
NS_PRECONDITION(parent, "bad param");
if(mParent)
{
NS_ADDREF(mParent);
*parent = mParent;
return NS_OK;
}
*parent = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
InterfaceInfoImpl::GetMethodCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mMethodBaseIndex + mMethodCount;
return NS_OK;
}
NS_IMETHODIMP
InterfaceInfoImpl::GetConstantCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mConstantBaseIndex + mConstantCount;
return NS_OK;
}
NS_IMETHODIMP
InterfaceInfoImpl::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
{
NS_PRECONDITION(info, "bad param");
if(index < mMethodBaseIndex)
return mParent->GetMethodInfo(index, info);
if(index >= mMethodBaseIndex + mMethodCount)
{
NS_PRECONDITION(0, "bad param");
*info = NULL;
return NS_ERROR_INVALID_ARG;
}
// else...
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
&mEntry->interface_descriptor->method_descriptors[index-mMethodBaseIndex]);
return NS_OK;
}
NS_IMETHODIMP
InterfaceInfoImpl::GetConstant(uint16 index, const nsXPTConstant** constant)
{
NS_PRECONDITION(constant, "bad param");
if(index < mConstantBaseIndex)
return mParent->GetConstant(index, constant);
if(index >= mConstantBaseIndex + mConstantCount)
{
NS_PRECONDITION(0, "bad param");
*constant = NULL;
return NS_ERROR_INVALID_ARG;
}
// else...
*constant = NS_REINTERPRET_CAST(nsXPTConstant*,
&mEntry->interface_descriptor->const_descriptors[index-mConstantBaseIndex]);
return NS_OK;
}

View File

@ -1,179 +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.
*/
/* The InterfaceInfo support public stuff. */
#ifndef xpt_cpp_h___
#define xpt_cpp_h___
#include "xpt_struct.h"
// Everything here is dependent upon - and sensitive to changes in -
// xpcom/libxpt/xpt_struct.h!
class nsXPTType : public XPTTypeDescriptorPrefix
{
// NO DATA - this a flyweight wrapper
public:
nsXPTType()
{} // random contents
nsXPTType(const XPTTypeDescriptorPrefix& prefix)
{*(XPTTypeDescriptorPrefix*)this = prefix;}
nsXPTType(const uint8& prefix)
{*(uint8*)this = prefix;}
nsXPTType& operator=(uint8 val)
{flags = val; return *this;}
operator uint8() const
{return flags;}
JSBool IsPointer() const
{return (JSBool) (XPT_TDP_IS_POINTER(flags));}
JSBool IsUniquePointer() const
{return (JSBool) (XPT_TDP_IS_UNIQUE_POINTER(flags));}
JSBool IsReference() const
{return (JSBool) (XPT_TDP_IS_REFERENCE(flags));}
JSBool IsArithmetic() const // terminology from Harbison/Steele
{return flags <= T_WCHAR;}
JSBool IsInterfacePointer() const
{return (JSBool) (TagPart() == T_INTERFACE ||
TagPart() == T_INTERFACE_IS);}
uint8 TagPart() const
{return (uint8) (flags & XPT_TDP_TAGMASK);}
enum
{
T_I8 = TD_INT8 ,
T_I16 = TD_INT16 ,
T_I32 = TD_INT32 ,
T_I64 = TD_INT64 ,
T_U8 = TD_UINT8 ,
T_U16 = TD_UINT16 ,
T_U32 = TD_UINT32 ,
T_U64 = TD_UINT64 ,
T_FLOAT = TD_FLOAT ,
T_DOUBLE = TD_DOUBLE ,
T_BOOL = TD_BOOL ,
T_CHAR = TD_CHAR ,
T_WCHAR = TD_WCHAR ,
T_VOID = TD_VOID ,
T_IID = TD_PNSIID ,
T_BSTR = TD_PBSTR ,
T_CHAR_STR = TD_PSTRING ,
T_WCHAR_STR = TD_PWSTRING ,
T_INTERFACE = TD_INTERFACE_TYPE ,
T_INTERFACE_IS = TD_INTERFACE_IS_TYPE
};
// NO DATA - this a flyweight wrapper
};
class nsXPTParamInfo : public XPTParamDescriptor
{
// NO DATA - this a flyweight wrapper
public:
nsXPTParamInfo(const XPTParamDescriptor& desc)
{*(XPTParamDescriptor*)this = desc;}
JSBool IsIn() const {return (JSBool) (XPT_PD_IS_IN(flags));}
JSBool IsOut() const {return (JSBool) (XPT_PD_IS_OUT(flags));}
JSBool IsRetval() const {return (JSBool) (XPT_PD_IS_RETVAL(flags));}
const nsXPTType GetType() const {return type.prefix;}
uint8 GetInterfaceIsArgNumber() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE_IS,"not an interface_is");
return type.type.argnum;
}
// This is not inlined, it is more involved!
// If XPTInterfaceDirectoryEntry references remain indexes, then it
// may be necessary to pass in a param here indicating which typelib
// - or at least XPTInterfaceDirectoryEntry - this particular param
// is associated with so that we can find the table this index indexes
// and then find the referenced XPTInterfaceDirectoryEntry so that we can
// find (or build) the appropriate nsIInterfaceInfo. Simple :)
nsIInterfaceInfo* GetInterface() const ;
// a *little* simpler than the above
const nsIID* GetInterfaceIID() const ;
private:
nsXPTParamInfo(); // no implementation
// NO DATA - this a flyweight wrapper
};
class nsXPTMethodInfo : public XPTMethodDescriptor
{
// NO DATA - this a flyweight wrapper
public:
nsXPTMethodInfo(const XPTMethodDescriptor& desc)
{*(XPTMethodDescriptor*)this = desc;}
JSBool IsGetter() const {return (JSBool) (XPT_MD_IS_GETTER(flags) );}
JSBool IsSetter() const {return (JSBool) (XPT_MD_IS_SETTER(flags) );}
JSBool IsVarArgs() const {return (JSBool) (XPT_MD_IS_VARARGS(flags));}
JSBool IsConstructor() const {return (JSBool) (XPT_MD_IS_CTOR(flags) );}
JSBool IsHidden() const {return (JSBool) (XPT_MD_IS_HIDDEN(flags) );}
const char* GetName() const {return name;}
uint8 GetParamCount() const {return num_args;}
const nsXPTParamInfo GetParam(uint8 index) const
{
NS_PRECONDITION(index < GetParamCount(),"bad arg");
return params[index];
}
const nsXPTParamInfo GetResult() const
{return *result;}
private:
nsXPTMethodInfo(); // no implementation
// NO DATA - this a flyweight wrapper
};
// forward declaration
struct nsXPCMiniVariant;
class nsXPTConstant : public XPTConstDescriptor
{
// NO DATA - this a flyweight wrapper
public:
nsXPTConstant(const XPTConstDescriptor& desc)
{*(XPTConstDescriptor*)this = desc;}
const char* GetName() const
{return name;}
const nsXPTType GetType() const
{return type.prefix;}
// XXX this is ugly
const nsXPCMiniVariant* GetValue() const
{return (nsXPCMiniVariant*) &value;}
private:
nsXPTConstant(); // no implementation
// NO DATA - this a flyweight wrapper
};
#endif /* xpt_cpp_h___ */