зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
b9a17146b8
Коммит
06796df9d0
|
@ -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))
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
xpidl -w -m header -o ..\xpccomponents xpccomponents.idl
|
||||
xpidl -w -m header -o ..\xpcjsid xpcjsid.idl
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
@ -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
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
#!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
|
||||
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
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
LIBRARY_NAME = xpcmd
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\xpcinvoke.obj \
|
||||
.\$(OBJDIR)\xpcstubs.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
#!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)\TestXPC.exe
|
||||
PROGRAMS = $(PROG1)
|
||||
TESTCASES = testxpc.js
|
||||
|
||||
LCFLAGS=-DUSE_NSREG -DJSFILE
|
||||
|
||||
DEFINES=-DWIN32_LEAN_AND_MEAN -DJS_THREADSAFE
|
||||
|
||||
REQUIRES=xpcom js xpconnect
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect -I$(PUBLIC)\raptor
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\js3250.lib \
|
||||
$(DIST)\lib\xpc3250.lib \
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(PROGRAMS)
|
||||
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
|
||||
-for %p in ($(TESTCASES)) 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$(PBDFILE)
|
||||
-Fe.\$(OBJDIR)\
|
||||
-Fo.\$(OBJDIR)\
|
||||
$(CURDIR)$(*B).cpp
|
||||
<<KEEP
|
||||
|
||||
$(PROG1): $(OBJDIR) TestXPC.cpp
|
|
@ -1,450 +0,0 @@
|
|||
// tests...
|
||||
|
||||
function nsID(str)
|
||||
{
|
||||
var id = Components.classes.nsIID.newInstance();
|
||||
id = id.QueryInterface(Components.interfaces.nsIID);
|
||||
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}");
|
||||
|
||||
var baz = foo.QueryInterface(NS_ITESTXPC_FOO_IID);
|
||||
print("baz = "+baz);
|
||||
print("distinct wrapper test "+ (foo != baz ? "passed" : "failed"));
|
||||
var baz2 = foo.QueryInterface(NS_ITESTXPC_FOO_IID);
|
||||
print("shared wrapper test "+ (baz == baz2 ? "passed" : "failed"));
|
||||
print("root wrapper identity test "+
|
||||
(foo.QueryInterface(NS_ISUPPORTS_IID) ==
|
||||
baz.QueryInterface(NS_ISUPPORTS_IID) ?
|
||||
"passed" : "failed"));
|
||||
|
||||
print("foo = "+foo);
|
||||
foo.toString = new Function("return 'foo toString called';")
|
||||
foo.toStr = new Function("return 'foo toStr called';")
|
||||
print("foo = "+foo);
|
||||
print("foo.toString() = "+foo.toString());
|
||||
print("foo.toStr() = "+foo.toStr());
|
||||
print("foo.five = "+ foo.five);
|
||||
print("foo.six = "+ foo.six);
|
||||
print("foo.bogus = "+ foo.bogus);
|
||||
print("setting bogus explicitly to '5'...");
|
||||
foo.bogus = 5;
|
||||
print("foo.bogus = "+ foo.bogus);
|
||||
print("foo.Test(10,20) returned: "+foo.Test(10,20));
|
||||
|
||||
function _Test(p1, p2)
|
||||
{
|
||||
print("test called in JS with p1 = "+p1+" and p2 = "+p2);
|
||||
return p1+p2;
|
||||
}
|
||||
|
||||
function _QI(iid)
|
||||
{
|
||||
print("QueryInterface called in JS with iid = "+iid);
|
||||
return this;
|
||||
}
|
||||
|
||||
print("creating bar");
|
||||
bar = new Object();
|
||||
bar.Test = _Test;
|
||||
bar.QueryInterface = _QI;
|
||||
// this 'bar' object is accessed from native code after this script is run
|
||||
|
||||
print("foo properties:");
|
||||
for(i in foo)
|
||||
print(" foo."+i+" = "+foo[i]);
|
||||
|
||||
/***************************************************************************/
|
||||
print(".......................................");
|
||||
print("echo tests...");
|
||||
|
||||
var reciever = new Object();
|
||||
reciever.SetReciever = function() {};
|
||||
reciever.SendOneString = function(str) {reciever_results[0] = str;};
|
||||
reciever.SendManyTypes = function()
|
||||
{
|
||||
for(var i = 0; i < arguments.length; i++)
|
||||
reciever_results[i] = arguments[i];
|
||||
};
|
||||
|
||||
echo.SetReciever(reciever);
|
||||
|
||||
////////////////////
|
||||
// SendOneString
|
||||
|
||||
var test_string = "some string";
|
||||
var reciever_results = new Object();
|
||||
echo.SendOneString(test_string);
|
||||
print("SendOneString - "+(
|
||||
reciever_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 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"];
|
||||
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(((""+reciever_results[i]).toLowerCase()) !=
|
||||
((""+send_params[i]).toLowerCase())) {
|
||||
if(all_ok)
|
||||
print("SendManyTypes - failed...");
|
||||
all_ok = false;
|
||||
print(" param number "+i+" diff: "+send_params[i]+" -> "+reciever_results[i])
|
||||
}
|
||||
}
|
||||
if(all_ok)
|
||||
print("SendManyTypes - passed");
|
||||
|
||||
////////////////////
|
||||
// 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"];
|
||||
|
||||
reciever.SendInOutManyTypes = function()
|
||||
{
|
||||
for(var i = 0; i < arguments.length; i++) {
|
||||
reciever_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(((""+reciever_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]+" -> "+reciever_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");
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// 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.SetReciever(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 reciever3 = new Object();
|
||||
reciever3.SetReciever = function() {};
|
||||
reciever3.FailInJSTest = function(fail) {if(fail)throw("");};
|
||||
echo.SetReciever(reciever3);
|
||||
|
||||
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"));
|
||||
|
||||
/***************************************************************************/
|
||||
// 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 reciever2 = new Object();
|
||||
reciever2.SetReciever = function() {};
|
||||
reciever2.SendOneString = function(str) {/*print(str);*/};
|
||||
|
||||
var echoJS = new Object();
|
||||
echoJS.SetReciever = 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.SetReciever(reciever2);
|
||||
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.SetReciever(reciever2);
|
||||
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.SetReciever(reciever2);
|
||||
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.SetReciever(reciever2);
|
||||
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(".......................................");
|
||||
|
||||
echoJS.SetReciever(null);
|
||||
echo.SetReciever(null);
|
|
@ -1,188 +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.
|
||||
*/
|
||||
|
||||
/* Per JSContext object. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
// static
|
||||
XPCContext*
|
||||
XPCContext::newXPCContext(JSContext* aJSContext,
|
||||
JSObject* aGlobalObj,
|
||||
int WrappedJSMapSize,
|
||||
int WrappedNativeMapSize,
|
||||
int WrappedJSClassMapSize,
|
||||
int WrappedNativeClassMapSize)
|
||||
{
|
||||
XPCContext* xpcc;
|
||||
|
||||
NS_PRECONDITION(aJSContext,"bad param");
|
||||
NS_PRECONDITION(WrappedJSMapSize,"bad param");
|
||||
NS_PRECONDITION(WrappedNativeMapSize,"bad param");
|
||||
NS_PRECONDITION(WrappedJSClassMapSize,"bad param");
|
||||
NS_PRECONDITION(WrappedNativeClassMapSize,"bad param");
|
||||
|
||||
xpcc = new XPCContext(aJSContext,
|
||||
aGlobalObj,
|
||||
WrappedJSMapSize,
|
||||
WrappedNativeMapSize,
|
||||
WrappedJSClassMapSize,
|
||||
WrappedNativeClassMapSize);
|
||||
|
||||
if(xpcc &&
|
||||
xpcc->GetXPConnect() &&
|
||||
xpcc->GetWrappedJSMap() &&
|
||||
xpcc->GetWrappedNativeMap() &&
|
||||
xpcc->GetWrappedJSClassMap() &&
|
||||
xpcc->GetWrappedNativeClassMap())
|
||||
{
|
||||
return xpcc;
|
||||
}
|
||||
delete xpcc;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XPCContext::XPCContext(JSContext* aJSContext,
|
||||
JSObject* aGlobalObj,
|
||||
int WrappedJSMapSize,
|
||||
int WrappedNativeMapSize,
|
||||
int WrappedJSClassMapSize,
|
||||
int WrappedNativeClassMapSize)
|
||||
{
|
||||
mXPConnect = nsXPConnect::GetXPConnect();
|
||||
mJSContext = aJSContext;
|
||||
mGlobalObj = aGlobalObj;
|
||||
mWrappedJSMap = JSObject2WrappedJSMap::newMap(WrappedJSMapSize);
|
||||
mWrappedNativeMap = Native2WrappedNativeMap::newMap(WrappedNativeMapSize);
|
||||
mWrappedJSClassMap = IID2WrappedJSClassMap::newMap(WrappedJSClassMapSize);
|
||||
mWrappedNativeClassMap = IID2WrappedNativeClassMap::newMap(WrappedNativeClassMapSize);
|
||||
}
|
||||
|
||||
XPCContext::~XPCContext()
|
||||
{
|
||||
if(mXPConnect)
|
||||
NS_RELEASE(mXPConnect);
|
||||
if(mWrappedJSMap)
|
||||
delete mWrappedJSMap;
|
||||
if(mWrappedNativeMap)
|
||||
delete mWrappedNativeMap;
|
||||
if(mWrappedJSClassMap)
|
||||
delete mWrappedJSClassMap;
|
||||
if(mWrappedNativeClassMap)
|
||||
delete mWrappedNativeClassMap;
|
||||
}
|
||||
|
||||
JSBool
|
||||
XPCContext::Init(JSObject* aGlobalObj /*= NULL*/)
|
||||
{
|
||||
if(aGlobalObj)
|
||||
mGlobalObj = aGlobalObj;
|
||||
return /* xpc_InitIDClass(this) && */
|
||||
nsXPCWrappedJSClass::InitForContext(this) &&
|
||||
nsXPCWrappedNativeClass::InitForContext(this);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
JS_STATIC_DLL_CALLBACK(intN)
|
||||
WrappedNativeClassMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
((nsXPCWrappedNativeClass*)he->value)->DebugDump(*(int*)arg);
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
JS_STATIC_DLL_CALLBACK(intN)
|
||||
WrappedJSClassMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
((nsXPCWrappedJSClass*)he->value)->DebugDump(*(int*)arg);
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
JS_STATIC_DLL_CALLBACK(intN)
|
||||
WrappedNativeMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
((nsXPCWrappedNative*)he->value)->DebugDump(*(int*)arg);
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
JS_STATIC_DLL_CALLBACK(intN)
|
||||
WrappedJSMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
((nsXPCWrappedJS*)he->value)->DebugDump(*(int*)arg);
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
XPCContext::DebugDump(int depth)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
depth--;
|
||||
XPC_LOG_ALWAYS(("XPCContext @ %x", this));
|
||||
XPC_LOG_INDENT();
|
||||
XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext));
|
||||
XPC_LOG_ALWAYS(("mGlobalObj @ %x", mGlobalObj));
|
||||
XPC_LOG_ALWAYS(("mWrappedNativeClassMap @ %x with %d classes", \
|
||||
mWrappedNativeClassMap, \
|
||||
mWrappedNativeClassMap ? mWrappedNativeClassMap->Count() : 0));
|
||||
XPC_LOG_ALWAYS(("mWrappedJSClassMap @ %x with %d classes", \
|
||||
mWrappedJSClassMap, \
|
||||
mWrappedJSClassMap ? mWrappedJSClassMap->Count() : 0));
|
||||
XPC_LOG_ALWAYS(("mWrappedNativeMap @ %x with %d wrappers", \
|
||||
mWrappedNativeMap, \
|
||||
mWrappedNativeMap ? mWrappedNativeMap->Count() : 0));
|
||||
XPC_LOG_ALWAYS(("mWrappedJSMap @ %x with %d wrappers", \
|
||||
mWrappedJSMap, \
|
||||
mWrappedJSMap ? mWrappedJSMap->Count() : 0));
|
||||
|
||||
if(depth && mWrappedNativeClassMap && mWrappedNativeClassMap->Count())
|
||||
{
|
||||
XPC_LOG_ALWAYS(("The %d WrappedNativeClasses...",\
|
||||
mWrappedNativeClassMap->Count()));
|
||||
XPC_LOG_INDENT();
|
||||
mWrappedNativeClassMap->Enumerate(WrappedNativeClassMapDumpEnumerator, &depth);
|
||||
XPC_LOG_OUTDENT();
|
||||
}
|
||||
|
||||
if(depth && mWrappedJSClassMap && mWrappedJSClassMap->Count())
|
||||
{
|
||||
XPC_LOG_ALWAYS(("The %d WrappedJSClasses...",\
|
||||
mWrappedJSClassMap->Count()));
|
||||
XPC_LOG_INDENT();
|
||||
mWrappedJSClassMap->Enumerate(WrappedJSClassMapDumpEnumerator, &depth);
|
||||
XPC_LOG_OUTDENT();
|
||||
}
|
||||
|
||||
if(depth && mWrappedNativeMap && mWrappedNativeMap->Count())
|
||||
{
|
||||
XPC_LOG_ALWAYS(("The %d WrappedNatives...",\
|
||||
mWrappedNativeMap->Count()));
|
||||
XPC_LOG_INDENT();
|
||||
mWrappedNativeMap->Enumerate(WrappedNativeMapDumpEnumerator, &depth);
|
||||
XPC_LOG_OUTDENT();
|
||||
}
|
||||
|
||||
if(depth && mWrappedJSMap && mWrappedJSMap->Count())
|
||||
{
|
||||
XPC_LOG_ALWAYS(("The %d WrappedJSs...",\
|
||||
mWrappedJSMap->Count()));
|
||||
XPC_LOG_INDENT();
|
||||
mWrappedJSMap->Enumerate(WrappedJSMapDumpEnumerator, &depth);
|
||||
XPC_LOG_OUTDENT();
|
||||
}
|
||||
|
||||
XPC_LOG_OUTDENT();
|
||||
#endif
|
||||
}
|
|
@ -1,512 +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.
|
||||
*/
|
||||
|
||||
/* Data conversion between native and JavaScript types. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
/*
|
||||
* This is a table driven scheme to determine if the types of the params of the
|
||||
* given method exclude that method from being reflected via XPConnect.
|
||||
*
|
||||
* The table can be appended and modified as requirements change. However...
|
||||
*
|
||||
* The table ASSUMES that all the type idenetifiers are contiguous starting
|
||||
* at ZERO. And, it also ASSUMES that the additional criteria of whether or
|
||||
* not a give type is reflectable are its use as a pointer and/or 'out' type.
|
||||
*
|
||||
* The table has a row for each type and columns for the combinations of
|
||||
* that type being used as a pointer type and/or as an 'out' param.
|
||||
*/
|
||||
|
||||
#define XPC_MK_BIT(p,o) (1 << (((p)?1:0)+((o)?2:0)))
|
||||
#define XPC_IS_REFLECTABLE(f, p, o) ((f) & XPC_MK_BIT((p),(o)))
|
||||
#define XPC_MK_FLAG(np_no,p_no,np_o,p_o) \
|
||||
((uint8)((np_no) | ((p_no) << 1) | ((np_o) << 2) | ((p_o) << 3)))
|
||||
|
||||
/***********************************************************/
|
||||
#define XPC_FLAG_COUNT nsXPTType::T_INTERFACE_IS+1
|
||||
|
||||
/* '1' means 'reflectable'. '0' means 'not reflectable'. */
|
||||
static uint8 xpc_reflectable_flags[XPC_FLAG_COUNT] = {
|
||||
/* 'p' stands for 'pointer' and 'o' stands for 'out' */
|
||||
/* !p&!o, p&!o, !p&o, p&o */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_I8 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_I16 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_I32 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_I64 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_U8 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_U16 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_U32 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_U64 */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_FLOAT */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_DOUBLE */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_BOOL */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_CHAR */
|
||||
XPC_MK_FLAG( 1 , 1 , 1 , 0 ), /* T_WCHAR */
|
||||
XPC_MK_FLAG( 0 , 0 , 0 , 0 ), /* T_VOID */
|
||||
XPC_MK_FLAG( 0 , 1 , 0 , 1 ), /* T_IID */
|
||||
XPC_MK_FLAG( 0 , 0 , 0 , 0 ), /* T_BSTR */
|
||||
XPC_MK_FLAG( 0 , 1 , 0 , 1 ), /* T_CHAR_STR */
|
||||
XPC_MK_FLAG( 0 , 1 , 0 , 1 ), /* T_WCHAR_STR */
|
||||
XPC_MK_FLAG( 0 , 1 , 0 , 1 ), /* T_INTERFACE */
|
||||
XPC_MK_FLAG( 0 , 1 , 0 , 1 ) /* T_INTERFACE_IS */
|
||||
};
|
||||
/***********************************************************/
|
||||
|
||||
// static
|
||||
JSBool
|
||||
XPCConvert::IsMethodReflectable(const nsXPTMethodInfo& info)
|
||||
{
|
||||
if(info.IsHidden())
|
||||
return JS_FALSE;
|
||||
|
||||
for(int i = info.GetParamCount()-1; i >= 0; i--)
|
||||
{
|
||||
const nsXPTParamInfo& param = info.GetParam(i);
|
||||
const nsXPTType& type = param.GetType();
|
||||
|
||||
uint8 base_type = type.TagPart();
|
||||
NS_ASSERTION(base_type < XPC_FLAG_COUNT, "BAD TYPE");
|
||||
|
||||
if(!XPC_IS_REFLECTABLE(xpc_reflectable_flags[base_type],
|
||||
type.IsPointer(), param.IsOut()))
|
||||
return JS_FALSE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define JAM_DOUBLE(cx,v,d) (d=JS_NewDouble(cx,(jsdouble)v),DOUBLE_TO_JSVAL(d))
|
||||
#define FIT_32(cx,i,d) (INT_FITS_IN_JSVAL(i)?INT_TO_JSVAL(i):JAM_DOUBLE(cx,i,d))
|
||||
// Win32 can't handle uint64 to double conversion
|
||||
#define JAM_DOUBLE_U64(cx,v,d) JAM_DOUBLE(cx,((int64)v),d)
|
||||
|
||||
// static
|
||||
JSBool
|
||||
XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
|
||||
const nsXPTType& type, const nsID* iid,
|
||||
uintN* pErr)
|
||||
{
|
||||
NS_PRECONDITION(s, "bad param");
|
||||
NS_PRECONDITION(d, "bad param");
|
||||
|
||||
jsdouble* dbl;
|
||||
|
||||
if(pErr)
|
||||
*pErr = XPCJSError::BAD_CONVERT_NATIVE;
|
||||
|
||||
switch(type.TagPart())
|
||||
{
|
||||
case nsXPTType::T_I8 : *d = INT_TO_JSVAL((int32)*((int8*)s)); break;
|
||||
case nsXPTType::T_I16 : *d = INT_TO_JSVAL((int32)*((int16*)s)); break;
|
||||
case nsXPTType::T_I32 : *d = FIT_32(cx,*((int32*)s),dbl); break;
|
||||
case nsXPTType::T_I64 : *d = JAM_DOUBLE(cx,*((int64*)s),dbl); break;
|
||||
case nsXPTType::T_U8 : *d = INT_TO_JSVAL((int32)*((uint8*)s)); break;
|
||||
case nsXPTType::T_U16 : *d = INT_TO_JSVAL((int32)*((uint16*)s)); break;
|
||||
case nsXPTType::T_U32 : *d = FIT_32(cx,*((uint32*)s),dbl); break;
|
||||
case nsXPTType::T_U64 : *d = JAM_DOUBLE_U64(cx,*((uint64*)s),dbl); break;
|
||||
case nsXPTType::T_FLOAT : *d = JAM_DOUBLE(cx,*((float*)s),dbl); break;
|
||||
case nsXPTType::T_DOUBLE: *d = JAM_DOUBLE(cx,*((double*)s),dbl); break;
|
||||
case nsXPTType::T_BOOL : *d = *((PRBool*)s)?JSVAL_TRUE:JSVAL_FALSE; break;
|
||||
case nsXPTType::T_CHAR :
|
||||
{
|
||||
char* p = (char*)s;
|
||||
if(!p)
|
||||
return JS_FALSE;
|
||||
JSString* str;
|
||||
if(!(str = JS_NewStringCopyN(cx, p, 1)))
|
||||
return JS_FALSE;
|
||||
*d = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_WCHAR :
|
||||
{
|
||||
jschar* p = (jschar*)s;
|
||||
if(!p)
|
||||
return JS_FALSE;
|
||||
JSString* str;
|
||||
if(!(str = JS_NewUCStringCopyN(cx, p, 1)))
|
||||
return JS_FALSE;
|
||||
*d = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if(!type.IsPointer())
|
||||
{
|
||||
XPC_LOG_ERROR(("XPCConvert::NativeData2JS : unsupported type"));
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// set the default result
|
||||
*d = JSVAL_NULL;
|
||||
|
||||
switch(type.TagPart())
|
||||
{
|
||||
case nsXPTType::T_VOID:
|
||||
// XXX implement void* ?
|
||||
XPC_LOG_ERROR(("XPCConvert::NativeData2JS : void* params not supported"));
|
||||
return JS_FALSE;
|
||||
|
||||
case nsXPTType::T_IID:
|
||||
{
|
||||
nsID* iid = *((nsID**)s);
|
||||
if(!iid)
|
||||
return JS_FALSE;
|
||||
JSObject* obj;
|
||||
if(!(obj = xpc_NewIIDObject(cx, *iid)))
|
||||
return JS_FALSE;
|
||||
*d = OBJECT_TO_JSVAL(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
case nsXPTType::T_BSTR:
|
||||
// XXX implement BSTR ?
|
||||
XPC_LOG_ERROR(("XPCConvert::NativeData2JS : BSTR params not supported"));
|
||||
return JS_FALSE;
|
||||
|
||||
case nsXPTType::T_CHAR_STR:
|
||||
{
|
||||
char* p = *((char**)s);
|
||||
if(!p)
|
||||
return JS_FALSE;
|
||||
JSString* str;
|
||||
if(!(str = JS_NewStringCopyZ(cx, p)))
|
||||
return JS_FALSE;
|
||||
*d = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
}
|
||||
|
||||
case nsXPTType::T_WCHAR_STR:
|
||||
{
|
||||
jschar* p = *((jschar**)s);
|
||||
if(!p)
|
||||
return JS_FALSE;
|
||||
JSString* str;
|
||||
if(!(str = JS_NewUCStringCopyZ(cx, p)))
|
||||
return JS_FALSE;
|
||||
*d = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
}
|
||||
|
||||
case nsXPTType::T_INTERFACE:
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
{
|
||||
nsISupports* iface = *((nsISupports**)s);
|
||||
if(!iface)
|
||||
{
|
||||
*d = JSVAL_NULL;
|
||||
break;
|
||||
}
|
||||
JSObject* aJSObj;
|
||||
// is this a wrapped JS object?
|
||||
if(nsXPCWrappedJSClass::IsWrappedJS(iface))
|
||||
{
|
||||
nsIXPConnectWrappedJSMethods* methods;
|
||||
if(NS_SUCCEEDED(iface->QueryInterface(
|
||||
nsIXPConnectWrappedJSMethods::GetIID(),
|
||||
(void**)&methods)) &&
|
||||
NS_SUCCEEDED(methods->GetJSObject(&aJSObj)))
|
||||
{
|
||||
NS_RELEASE(methods);
|
||||
*d = OBJECT_TO_JSVAL(aJSObj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we need to build a wrapper
|
||||
nsXPCWrappedNative* wrapper=NULL;
|
||||
XPCContext* xpcc;
|
||||
if(!iid || !(xpcc = nsXPConnect::GetContext(cx)) ||
|
||||
!(wrapper = nsXPCWrappedNative::GetNewOrUsedWrapper(xpcc,
|
||||
iface, *iid)))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
aJSObj = wrapper->GetJSObject();
|
||||
NS_RELEASE(wrapper);
|
||||
if(aJSObj)
|
||||
*d = OBJECT_TO_JSVAL(aJSObj);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
NS_ASSERTION(0, "bad type");
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
// static
|
||||
JSBool
|
||||
XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
|
||||
const nsXPTType& type,
|
||||
nsIAllocator* al, const nsID* iid,
|
||||
uintN* pErr)
|
||||
{
|
||||
NS_PRECONDITION(d, "bad param");
|
||||
|
||||
int32 ti;
|
||||
uint32 tu;
|
||||
jsdouble td;
|
||||
|
||||
if(pErr)
|
||||
*pErr = XPCJSError::BAD_CONVERT_JS;
|
||||
|
||||
switch(type.TagPart())
|
||||
{
|
||||
case nsXPTType::T_I8 :
|
||||
if(!JS_ValueToECMAInt32(cx, s, &ti))
|
||||
return JS_FALSE;
|
||||
*((int8*)d) = (int8) ti;
|
||||
break;
|
||||
case nsXPTType::T_I16 :
|
||||
if(!JS_ValueToECMAInt32(cx, s, &ti))
|
||||
return JS_FALSE;
|
||||
*((int16*)d) = (int16) ti;
|
||||
break;
|
||||
case nsXPTType::T_I32 :
|
||||
if(!JS_ValueToECMAInt32(cx, s, (int32*)d))
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case nsXPTType::T_I64 :
|
||||
if(JSVAL_IS_INT(s))
|
||||
{
|
||||
if(!JS_ValueToECMAInt32(cx, s, &ti))
|
||||
return JS_FALSE;
|
||||
*((int64*)d) = (int64) ti;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!JS_ValueToNumber(cx, s, &td))
|
||||
return JS_FALSE;
|
||||
*((int64*)d) = (int64) td;
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_U8 :
|
||||
if(!JS_ValueToECMAUint32(cx, s, &tu))
|
||||
return JS_FALSE;
|
||||
*((uint8*)d) = (uint8) tu;
|
||||
break;
|
||||
case nsXPTType::T_U16 :
|
||||
if(!JS_ValueToECMAUint32(cx, s, &tu))
|
||||
return JS_FALSE;
|
||||
*((uint16*)d) = (uint16) tu;
|
||||
break;
|
||||
case nsXPTType::T_U32 :
|
||||
if(!JS_ValueToECMAUint32(cx, s, (uint32*)d))
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case nsXPTType::T_U64 :
|
||||
if(JSVAL_IS_INT(s))
|
||||
{
|
||||
if(!JS_ValueToECMAUint32(cx, s, &tu))
|
||||
return JS_FALSE;
|
||||
*((uint64*)d) = (uint64) tu;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!JS_ValueToNumber(cx, s, &td))
|
||||
return JS_FALSE;
|
||||
// XXX Win32 can't handle double to uint64 directly
|
||||
*((uint64*)d) = (uint64)((int64) td);
|
||||
}
|
||||
break;
|
||||
case nsXPTType::T_FLOAT :
|
||||
if(!JS_ValueToNumber(cx, s, &td))
|
||||
return JS_FALSE;
|
||||
*((float*)d) = (float) td;
|
||||
break;
|
||||
case nsXPTType::T_DOUBLE :
|
||||
if(!JS_ValueToNumber(cx, s, (double*)d))
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case nsXPTType::T_BOOL :
|
||||
if(!JS_ValueToBoolean(cx, s, (PRBool*)d))
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case nsXPTType::T_CHAR :
|
||||
{
|
||||
char* bytes=NULL;
|
||||
JSString* str;
|
||||
|
||||
if(!(str = JS_ValueToString(cx, s))||
|
||||
!(bytes = JS_GetStringBytes(str)))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
*((char*)d) = bytes[0];
|
||||
break;
|
||||
}
|
||||
case nsXPTType::T_WCHAR :
|
||||
{
|
||||
jschar* chars=NULL;
|
||||
JSString* str;
|
||||
if(!(str = JS_ValueToString(cx, s))||
|
||||
!(chars = JS_GetStringChars(str)))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
*((uint16*)d) = (uint16) chars[0];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if(!type.IsPointer())
|
||||
{
|
||||
NS_ASSERTION(0,"unsupported type");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
switch(type.TagPart())
|
||||
{
|
||||
case nsXPTType::T_VOID:
|
||||
// XXX implement void* ?
|
||||
XPC_LOG_ERROR(("XPCConvert::JSData2Native : void* params not supported"));
|
||||
NS_ASSERTION(0,"void* params not supported");
|
||||
return JS_FALSE;
|
||||
case nsXPTType::T_IID:
|
||||
{
|
||||
NS_ASSERTION(al,"trying to convert a JSID to nsID without allocator");
|
||||
|
||||
JSObject* obj;
|
||||
const nsID* pid=NULL;
|
||||
if(!JSVAL_IS_OBJECT(s) ||
|
||||
(!(obj = JSVAL_TO_OBJECT(s))) ||
|
||||
(!(pid = xpc_JSObjectToID(cx, obj))))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
*((const nsID**)d) = pid;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
case nsXPTType::T_BSTR:
|
||||
// XXX implement BSTR
|
||||
XPC_LOG_ERROR(("XPCConvert::JSData2Native : BSTR params not supported"));
|
||||
return JS_FALSE;
|
||||
|
||||
case nsXPTType::T_CHAR_STR:
|
||||
{
|
||||
char* bytes=NULL;
|
||||
JSString* str;
|
||||
|
||||
if(!(str = JS_ValueToString(cx, s))||
|
||||
!(bytes = JS_GetStringBytes(str)))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
if(al)
|
||||
{
|
||||
int len = strlen(bytes)+1;
|
||||
if(!(*((void**)d) = al->Alloc(len)))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
memcpy(*((void**)d), bytes, len);
|
||||
}
|
||||
else
|
||||
*((char**)d) = bytes;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
case nsXPTType::T_WCHAR_STR:
|
||||
{
|
||||
jschar* chars=NULL;
|
||||
JSString* str;
|
||||
|
||||
if(!(str = JS_ValueToString(cx, s))||
|
||||
!(chars = JS_GetStringChars(str)))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
if(al)
|
||||
{
|
||||
int byte_len = (JS_GetStringLength(str)+1)*sizeof(jschar);
|
||||
if(!(*((void**)d) = al->Alloc(byte_len)))
|
||||
{
|
||||
// XXX should report error
|
||||
return JS_FALSE;
|
||||
}
|
||||
memcpy(*((void**)d), chars, byte_len);
|
||||
}
|
||||
else
|
||||
*((jschar**)d) = chars;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
case nsXPTType::T_INTERFACE:
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
{
|
||||
NS_ASSERTION(iid,"can't do interface conversions without iid");
|
||||
JSObject* obj;
|
||||
nsISupports* iface = NULL;
|
||||
|
||||
if(JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s))
|
||||
{
|
||||
*((nsISupports**)d) = NULL;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
// only wrap JSObjects
|
||||
if(!JSVAL_IS_OBJECT(s) ||
|
||||
(!(obj = JSVAL_TO_OBJECT(s))))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// is this really a native xpcom object with a wrapper?
|
||||
nsXPCWrappedNative* wrapper;
|
||||
if(NULL != (wrapper =
|
||||
nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(cx,obj)))
|
||||
{
|
||||
iface = wrapper->GetNative();
|
||||
// is the underlying object the right interface?
|
||||
if(wrapper->GetIID().Equals(*iid))
|
||||
NS_ADDREF(iface);
|
||||
else
|
||||
iface->QueryInterface(*iid, (void**)&iface);
|
||||
}
|
||||
else
|
||||
{
|
||||
// lets try to build a wrapper around the JSObject
|
||||
XPCContext* xpcc;
|
||||
if(NULL != (xpcc = nsXPConnect::GetContext(cx)))
|
||||
iface = nsXPCWrappedJS::GetNewOrUsedWrapper(xpcc, obj, *iid);
|
||||
}
|
||||
if(iface)
|
||||
{
|
||||
// one AddRef has already been done
|
||||
*((nsISupports**)d) = iface;
|
||||
return JS_TRUE;
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
default:
|
||||
NS_ASSERTION(0, "bad type");
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
|
@ -1,560 +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.
|
||||
*/
|
||||
|
||||
/* An xpcom implmentation of the JavaScript nsIID and nsCID objects. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
/***************************************************************************/
|
||||
// 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}
|
||||
static nsID invalid = {0xbb1f47b0, 0xd137, 0x11d2,
|
||||
{0x98, 0x41, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22}};
|
||||
return invalid;
|
||||
}
|
||||
|
||||
static char* gNoString = "";
|
||||
|
||||
/***************************************************************************/
|
||||
// nsJSIID
|
||||
|
||||
nsresult
|
||||
nsJSIID::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsISupports::GetIID()) ||
|
||||
aIID.Equals(nsIJSID::GetIID()) ||
|
||||
aIID.Equals(nsIJSIID::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsJSIID)
|
||||
NS_IMPL_RELEASE(nsJSIID)
|
||||
|
||||
nsJSIID::nsJSIID()
|
||||
: mID(GetInvalidIID()), mNumber(gNoString), mName(gNoString)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF_THIS();
|
||||
};
|
||||
|
||||
nsJSIID::~nsJSIID()
|
||||
{
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
}
|
||||
|
||||
void nsJSIID::reset()
|
||||
{
|
||||
mID = GetInvalidIID();
|
||||
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
|
||||
mNumber = mName = NULL;
|
||||
}
|
||||
|
||||
//static
|
||||
nsJSIID*
|
||||
nsJSIID::NewID(const char* str)
|
||||
{
|
||||
PRBool success;
|
||||
nsJSIID* idObj = new nsJSIID();
|
||||
if(!idObj)
|
||||
return NULL;
|
||||
|
||||
if(NS_FAILED(idObj->init(str, &success)) || !success)
|
||||
{
|
||||
delete idObj;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return idObj;
|
||||
}
|
||||
|
||||
void
|
||||
nsJSIID::setName(const char* name)
|
||||
{
|
||||
int len = strlen(name)+1;
|
||||
mName = new char[len];
|
||||
if(mName)
|
||||
memcpy(mName, name, len);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetName(char * *aName)
|
||||
{
|
||||
if(!mName)
|
||||
{
|
||||
nsIInterfaceInfoManager* iim;
|
||||
if(NULL != (iim = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
char* name;
|
||||
if(NS_SUCCEEDED(iim->GetNameForIID(&mID, &name)) && name)
|
||||
{
|
||||
setName(name);
|
||||
XPCMem::Free(name);
|
||||
}
|
||||
NS_RELEASE(iim);
|
||||
}
|
||||
if(!mName)
|
||||
mName = gNoString;
|
||||
}
|
||||
|
||||
*aName = (char*) XPCMem::Clone(mName, strlen(mName)+1);
|
||||
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetNumber(char * *aNumber)
|
||||
{
|
||||
if(!mNumber)
|
||||
{
|
||||
if(!(mNumber = mID.ToString()))
|
||||
mNumber = gNoString;
|
||||
}
|
||||
|
||||
*aNumber = (char*) XPCMem::Clone(mNumber, strlen(mNumber)+1);
|
||||
return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetId(nsID* *aId)
|
||||
{
|
||||
*aId = (nsID*) XPCMem::Clone(&mID, sizeof(nsID));
|
||||
return *aId ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetValid(PRBool *aValid)
|
||||
{
|
||||
*aValid = !mID.Equals(GetInvalidIID());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::equals(nsIJSID *other, PRBool *_retval)
|
||||
{
|
||||
if(!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = PR_FALSE;
|
||||
|
||||
if(mID.Equals(GetInvalidIID()))
|
||||
return NS_OK;
|
||||
|
||||
nsID* otherID;
|
||||
if(NS_SUCCEEDED(other->GetId(&otherID)))
|
||||
{
|
||||
*_retval = mID.Equals(*otherID);
|
||||
XPCMem::Free(otherID);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::init(const char *idString, PRBool *_retval)
|
||||
{
|
||||
if(!_retval || !idString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool success = PR_FALSE;
|
||||
|
||||
if(strlen(idString) && mID.Equals(GetInvalidIID()))
|
||||
{
|
||||
reset();
|
||||
|
||||
if(idString[0] == '{')
|
||||
{
|
||||
nsID id;
|
||||
if(id.Parse((char*)idString))
|
||||
{
|
||||
mID = id;
|
||||
success = PR_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsIInterfaceInfoManager* iim;
|
||||
if(NULL != (iim = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
nsID* pid;
|
||||
if(NS_SUCCEEDED(iim->GetIIDForName(idString, &pid)) && pid)
|
||||
{
|
||||
mID = *pid;
|
||||
setName(idString);
|
||||
success = PR_TRUE;
|
||||
XPCMem::Free(pid);
|
||||
}
|
||||
NS_RELEASE(iim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*_retval = success;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
// nsJSCID
|
||||
|
||||
nsresult
|
||||
nsJSCID::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsISupports::GetIID()) ||
|
||||
aIID.Equals(nsIJSID::GetIID()) ||
|
||||
aIID.Equals(nsIJSCID::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsJSCID)
|
||||
NS_IMPL_RELEASE(nsJSCID)
|
||||
|
||||
nsJSCID::nsJSCID()
|
||||
: mID(GetInvalidIID()), mNumber(gNoString), mName(gNoString)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF_THIS();
|
||||
};
|
||||
|
||||
nsJSCID::~nsJSCID()
|
||||
{
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
}
|
||||
|
||||
void nsJSCID::reset()
|
||||
{
|
||||
mID = GetInvalidIID();
|
||||
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
|
||||
mNumber = mName = NULL;
|
||||
}
|
||||
|
||||
//static
|
||||
nsJSCID*
|
||||
nsJSCID::NewID(const char* str)
|
||||
{
|
||||
PRBool success;
|
||||
nsJSCID* idObj = new nsJSCID();
|
||||
if(!idObj)
|
||||
return NULL;
|
||||
|
||||
if(NS_FAILED(idObj->init(str, &success)) || !success)
|
||||
{
|
||||
delete idObj;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return idObj;
|
||||
}
|
||||
|
||||
void
|
||||
nsJSCID::setName(const char* name)
|
||||
{
|
||||
int len = strlen(name)+1;
|
||||
mName = new char[len];
|
||||
if(mName)
|
||||
memcpy(mName, name, len);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetName(char * *aName)
|
||||
{
|
||||
if(!mName)
|
||||
mName = gNoString;
|
||||
*aName = (char*) XPCMem::Clone(mName, strlen(mName)+1);
|
||||
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetNumber(char * *aNumber)
|
||||
{
|
||||
if(!mNumber)
|
||||
{
|
||||
if(!(mNumber = mID.ToString()))
|
||||
mNumber = gNoString;
|
||||
}
|
||||
|
||||
*aNumber = (char*) XPCMem::Clone(mNumber, strlen(mNumber)+1);
|
||||
return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetId(nsID* *aId)
|
||||
{
|
||||
*aId = (nsID*) XPCMem::Clone(&mID, sizeof(nsID));
|
||||
return *aId ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetValid(PRBool *aValid)
|
||||
{
|
||||
*aValid = !mID.Equals(GetInvalidIID());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::equals(nsIJSID *other, PRBool *_retval)
|
||||
{
|
||||
if(!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = PR_FALSE;
|
||||
|
||||
if(mID.Equals(GetInvalidIID()))
|
||||
return NS_OK;
|
||||
|
||||
nsID* otherID;
|
||||
if(NS_SUCCEEDED(other->GetId(&otherID)))
|
||||
{
|
||||
*_retval = mID.Equals(*otherID);
|
||||
XPCMem::Free(otherID);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::init(const char *idString, PRBool *_retval)
|
||||
{
|
||||
if(!_retval || !idString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool success = PR_FALSE;
|
||||
|
||||
if(strlen(idString) && mID.Equals(GetInvalidIID()))
|
||||
{
|
||||
reset();
|
||||
|
||||
if(idString[0] == '{')
|
||||
{
|
||||
nsID id;
|
||||
if(id.Parse((char*)idString))
|
||||
{
|
||||
mID = id;
|
||||
success = PR_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCID cid;
|
||||
if(NS_SUCCEEDED(nsComponentManager::ProgIDToCLSID(idString, &cid)))
|
||||
{
|
||||
mID = cid;
|
||||
setName(idString);
|
||||
success = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*_retval = success;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::newInstance(nsISupports **_retval)
|
||||
{
|
||||
if(!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = NULL;
|
||||
if(mID.Equals(GetInvalidIID()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return nsComponentManager::CreateInstance(mID, NULL,
|
||||
nsISupports::GetIID(),
|
||||
(void**) _retval);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
// additional utilities...
|
||||
|
||||
JSObject *
|
||||
xpc_NewIIDObject(JSContext *cx, const nsID& aID)
|
||||
{
|
||||
JSObject *obj = NULL;
|
||||
|
||||
char* idString = aID.ToString();
|
||||
if(idString)
|
||||
{
|
||||
nsJSIID* iid = nsJSIID::NewID(idString);
|
||||
delete [] idString;
|
||||
if(iid)
|
||||
{
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if(xpc)
|
||||
{
|
||||
nsIXPConnectWrappedNative* nsid_wrapper;
|
||||
if(NS_SUCCEEDED(xpc->WrapNative(cx, iid,
|
||||
nsIJSIID::GetIID(),
|
||||
&nsid_wrapper)))
|
||||
{
|
||||
nsid_wrapper->GetJSObject(&obj);
|
||||
NS_RELEASE(nsid_wrapper);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
}
|
||||
NS_RELEASE(iid);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
nsID*
|
||||
xpc_JSObjectToID(JSContext *cx, JSObject* obj)
|
||||
{
|
||||
nsID* id = NULL;
|
||||
if(!cx || !obj)
|
||||
return NULL;
|
||||
|
||||
// NOTE: this call does NOT addref
|
||||
nsXPCWrappedNative* wrapper =
|
||||
nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(cx, obj);
|
||||
if(wrapper)
|
||||
{
|
||||
if(wrapper->GetIID().Equals(nsIJSIID::GetIID()) ||
|
||||
wrapper->GetIID().Equals(nsIJSCID::GetIID()))
|
||||
{
|
||||
((nsIJSID*)wrapper->GetNative())->GetId(&id);
|
||||
}
|
||||
}
|
||||
// XXX it would be nice to try to construct one from an object that can be
|
||||
// converted into a string.
|
||||
return id;
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* DO NOT EDIT. THIS FILE IS GENERATED FROM xpcjsid.idl
|
||||
*/
|
||||
|
||||
#ifndef __gen_xpcjsid_h__
|
||||
#define __gen_xpcjsid_h__
|
||||
|
||||
#include "nsISupports.h" /* interface nsISupports */
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
#include "jsapi.h"
|
||||
#endif
|
||||
|
||||
/* starting interface nsIJSID */
|
||||
|
||||
/* {C86AE131-D101-11d2-9841-006008962422} */
|
||||
#define NS_IJSID_IID_STR "C86AE131-D101-11d2-9841-006008962422"
|
||||
#define NS_IJSID_IID \
|
||||
{0xC86AE131, 0xD101, 0x11d2, \
|
||||
{ 0x98, 0x41, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
|
||||
|
||||
class nsIJSID : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_IJSID_IID;
|
||||
return iid;
|
||||
}
|
||||
|
||||
/* readonly attribute string name; */
|
||||
NS_IMETHOD GetName(char * *aName) = 0;
|
||||
|
||||
/* readonly attribute string number; */
|
||||
NS_IMETHOD GetNumber(char * *aNumber) = 0;
|
||||
|
||||
/* readonly attribute nsID id; */
|
||||
NS_IMETHOD GetId(nsID* *aId) = 0;
|
||||
|
||||
/* readonly attribute boolean valid; */
|
||||
NS_IMETHOD GetValid(PRBool *aValid) = 0;
|
||||
|
||||
/* boolean equals (in nsIJSID other); */
|
||||
NS_IMETHOD equals(nsIJSID *other, PRBool *_retval) = 0;
|
||||
|
||||
/* boolean init (in string idString); */
|
||||
NS_IMETHOD init(const char *idString, PRBool *_retval) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSID *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface nsIJSIID */
|
||||
|
||||
/* {e08dcda0-d651-11d2-9843-006008962422} */
|
||||
#define NS_IJSIID_IID_STR "e08dcda0-d651-11d2-9843-006008962422"
|
||||
#define NS_IJSIID_IID \
|
||||
{0xe08dcda0, 0xd651, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
|
||||
|
||||
class nsIJSIID : public nsIJSID {
|
||||
public:
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_IJSIID_IID;
|
||||
return iid;
|
||||
}
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSIID *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface nsIJSCID */
|
||||
|
||||
/* {e3a24a60-d651-11d2-9843-006008962422} */
|
||||
#define NS_IJSCID_IID_STR "e3a24a60-d651-11d2-9843-006008962422"
|
||||
#define NS_IJSCID_IID \
|
||||
{0xe3a24a60, 0xd651, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
|
||||
|
||||
class nsIJSCID : public nsIJSID {
|
||||
public:
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_IJSCID_IID;
|
||||
return iid;
|
||||
}
|
||||
|
||||
/* nsISupports newInstance (); */
|
||||
NS_IMETHOD newInstance(nsISupports **_retval) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSCID *priv);
|
||||
#endif
|
||||
};
|
||||
/********************************************************/
|
||||
// {1D17BFF0-D58D-11d2-9843-006008962422}
|
||||
#define NS_JS_IID_CID \
|
||||
{ 0x1d17bff0, 0xd58d, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
|
||||
// {8628BFA0-D652-11d2-9843-006008962422}
|
||||
#define NS_JS_CID_CID \
|
||||
{ 0x8628bfa0, 0xd652, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
|
||||
|
||||
|
||||
#endif /* __gen_xpcjsid_h__ */
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -1,54 +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)
|
||||
{
|
||||
void* p = Allocator()->Alloc(size);
|
||||
if(p) memcpy(p, ptr, size);
|
||||
return p;
|
||||
}
|
|
@ -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(¶m, &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(¶m, &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;
|
||||
|
|
|
@ -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(¶m, &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(¶m, &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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче