re-organized xpconnect tree struct. Main sources moved from xpconnect to xpconnect/src. md stuff moved to xpcom/libxpt/xptcall

This commit is contained in:
jband%netscape.com 1999-03-23 20:22:00 +00:00
parent 0086051131
commit ffe9fd990b
48 changed files with 9587 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Makefile
mk.bat
set_env.bat

12
js/src/xpconnect/idl/mk.bat Executable file
View File

@ -0,0 +1,12 @@
xpidl -w -m header -o ..\public\xpccomponents xpccomponents.idl
xpidl -w -m header -o ..\public\xpcjsid xpcjsid.idl
xpidl -w -m header -o ..\tests\xpctest xpctest.idl
xpidl -w -m typelib -o ..\typelib\xpccomponents xpccomponents.idl
xpidl -w -m typelib -o ..\typelib\xpcjsid xpcjsid.idl
xpidl -w -m typelib -o ..\typelib\nsISupports nsISupports.idl
xpidl -w -m typelib -o ..\typelib\xpctest xpctest.idl
rem set XPTDIR=x:\raptor\mozilla\js\src\xpconnect\typelib

View File

@ -0,0 +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.
*/
%{C++
#include "nsDebug.h"
#include "nsTraceRefcnt.h"
#include "nsIID.h"
%}
/* #include "nsID.idl" */
%{C++
#include "nsError.h"
#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

@ -0,0 +1,36 @@
/* -*- 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.
*/
#include "nsISupports.idl"
[uuid(4b62a640-d26c-11d2-9842-006008962422)]
interface nsIXPCInterfaces : nsISupports
{
};
[uuid(978ff520-d26c-11d2-9842-006008962422)]
interface nsIXPCClasses : nsISupports
{
};
[uuid(42624f80-d26c-11d2-9842-006008962422)]
interface nsIXPCComponents : nsISupports
{
readonly attribute nsIXPCInterfaces interfaces;
readonly attribute nsIXPCClasses classes;
};

View File

@ -0,0 +1,67 @@
/* -*- 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.
*/
#include "nsISupports.idl"
// XXX this ought to be builtin!
native nsID(nsID*);
[uuid(C86AE131-D101-11d2-9841-006008962422)]
interface nsIJSID : nsISupports
{
readonly attribute string name;
readonly attribute string number;
readonly attribute nsID id;
readonly attribute boolean valid;
boolean equals(in nsIJSID other);
boolean init(in string idString);
string toString();
};
[uuid(e08dcda0-d651-11d2-9843-006008962422)]
interface nsIJSIID : nsIJSID
{
};
[uuid(e3a24a60-d651-11d2-9843-006008962422)]
interface nsIJSCID : nsIJSID
{
nsISupports newInstance();
};
/* this goes into the C++ header verbatim. */
%{ C++
/********************************************************/
// {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 } }
%}

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

@ -0,0 +1,21 @@
#
# 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
DIRS=public src tests
include <$(DEPTH)\config\rules.mak>

View File

@ -0,0 +1,32 @@
#!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.
IGNORE_MANIFEST=1
DEPTH=..\..\..\..
EXPORTS = \
nsIXPConnect.h \
nsIXPCScriptable.h \
xpccomponents.h \
xpcjsid.h \
xpclog.h \
$(NULL)
MODULE = xpconnect
include <$(DEPTH)\config\rules.mak>

View File

@ -0,0 +1,483 @@
/* -*- 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.
*/
/* All the XPCScriptable public interfaces. */
#ifndef nsIXPCScriptable_h___
#define nsIXPCScriptable_h___
#include "nsIXPConnect.h"
#include "jsapi.h"
/*
* A preliminary document (written before implementation) explaining the ideas
* behind this interface can be can be found at:
* http://www.mozilla.org/scriptable/scriptable-proposal.html
*
* nsIXPCScriptable is an interface that an object being wrapped by XPConnect
* can expose to support dynamic properites. XPConnect will QueryInterface
* wrapped xpcom objects to find out if they expose this interface. If an object
* does support this interface then XPConnect will pass through calls from JS
* to the methods of the nsIXPCScriptable under certain circumstances. Calls are
* passed through when JS code attempts to access properties on the wrapper
* which are not declared as attributes or methods in the xpidl that defines the
* interface. Calls will also be passed through for operation not normally
* supported on wrapped xpcom objects; e.g. 'call' and 'construct'.
*
* The methods of nsIXPCScriptable map directly onto the JSObjectOps 'interface'
* of the JavaScript api. In addition to the params passed by JavaScript the
* methods are also passed a pointer to the current wrapper and a pointer to
* the default implementation of the methods called the 'arbitrary' object.
*
* The methods of nsIXPCScriptable can be implemented to override default
* behavior or the calls can be forwarded to the 'arbitrary' object. Macros
* are declared below to make it easy to imlement objects which forward some or
* all of the method calls to the 'arbitrary' object.
*
* nsIXPCScriptable is meant to be called by XPConnect only. All the
* methods of this interface take params which identify the wrapper and
* therefore from which the wrapped object can be found. The methods are in
* effect virtually 'static' methods. For simplicity's sake we've decided to
* break COM identiry rules for this interface and say that its QueryInterface
* need not follow the normal rules of returning the same object as the
* QueryInterface of the object which returns this interface. Thus, the same
* nsIXPCScriptable object could be used by multiple objects if that suits you.
* In fact the 'arbitrary' object passed to this interface by XPConnect in all
* the methods is a singleton in XPConnect.
*/
/***************************************************************************/
// forward declaration
class nsIXPCScriptable;
#define XPC_DECLARE_IXPCSCRIPTABLE \
public: \
NS_IMETHOD Create(JSContext *cx, JSObject *obj, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary) COND_PURE ; \
NS_IMETHOD LookupProperty(JSContext *cx, JSObject *obj, jsid id, \
JSObject **objp, JSProperty **propp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD DefineProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval value, \
JSPropertyOp getter, JSPropertyOp setter, \
uintN attrs, JSProperty **propp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD GetProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp,\
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD GetAttributes(JSContext *cx, JSObject *obj, jsid id, \
JSProperty *prop, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD SetAttributes(JSContext *cx, JSObject *obj, jsid id, \
JSProperty *prop, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD DeleteProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD DefaultValue(JSContext *cx, JSObject *obj, \
JSType type, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD Enumerate(JSContext *cx, JSObject *obj, \
JSIterateOp enum_op, \
jsval *statep, jsid *idp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD CheckAccess(JSContext *cx, JSObject *obj, jsid id, \
JSAccessMode mode, jsval *vp, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD Call(JSContext *cx, JSObject *obj, \
uintN argc, jsval *argv, \
jsval *rval, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD Construct(JSContext *cx, JSObject *obj, \
uintN argc, jsval *argv, \
jsval *rval, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) COND_PURE ; \
NS_IMETHOD Finalize(JSContext *cx, JSObject *obj, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary) COND_PURE /*;*/
// {8A9C85F0-BA3A-11d2-982D-006008962422}
#define NS_IXPCSCRIPTABLE_IID \
{ 0x8a9c85f0, 0xba3a, 0x11d2, \
{ 0x98, 0x2d, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
class nsIXPCScriptable : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCSCRIPTABLE_IID)
#define COND_PURE = 0
XPC_DECLARE_IXPCSCRIPTABLE;
#undef COND_PURE
#define COND_PURE
};
// macro test...
// XPC_DECLARE_IXPCSCRIPTABLE;
/***************************************************************************/
#define XPC_IMPLEMENT_FORWARD_CREATE(_class) \
NS_IMETHODIMP _class::Create(JSContext *cx, JSObject *obj, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary) \
{return arbitrary->Create(cx, obj, wrapper, NULL);}
#define XPC_IMPLEMENT_FORWARD_LOOKUPPROPERTY(_class) \
NS_IMETHODIMP _class::LookupProperty(JSContext *cx, JSObject *obj, \
jsid id, \
JSObject **objp, JSProperty **propp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->LookupProperty(cx, obj, id, objp, propp, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_DEFINEPROPERTY(_class) \
NS_IMETHODIMP _class::DefineProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval value, \
JSPropertyOp getter, JSPropertyOp setter, \
uintN attrs, JSProperty **propp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->DefineProperty(cx, obj, id, value, getter, setter, \
attrs, propp, wrapper, NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_GETPROPERTY(_class) \
NS_IMETHODIMP _class::GetProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->GetProperty(cx, obj, id, vp, wrapper, NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_SETPROPERTY(_class) \
NS_IMETHODIMP _class::SetProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->SetProperty(cx, obj, id, vp, wrapper, NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_GETATTRIBUTES(_class) \
NS_IMETHODIMP _class::GetAttributes(JSContext *cx, JSObject *obj, \
jsid id, \
JSProperty *prop, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->GetAttributes(cx, obj, id, prop, attrsp, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_SETATTRIBUTES(_class) \
NS_IMETHODIMP _class::SetAttributes(JSContext *cx, JSObject *obj, \
jsid id, \
JSProperty *prop, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->SetAttributes(cx, obj, id, prop, attrsp, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_DELETEPROPERTY(_class) \
NS_IMETHODIMP _class::DeleteProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->DeleteProperty(cx, obj, id, vp, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_DEFAULTVALUE(_class) \
NS_IMETHODIMP _class::DefaultValue(JSContext *cx, JSObject *obj, \
JSType type, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->DefaultValue(cx, obj, type, vp, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_ENUMERATE(_class) \
NS_IMETHODIMP _class::Enumerate(JSContext *cx, JSObject *obj, \
JSIterateOp enum_op, \
jsval *statep, jsid *idp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->Enumerate(cx, obj, enum_op, statep, idp, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_CHECKACCESS(_class) \
NS_IMETHODIMP _class::CheckAccess(JSContext *cx, JSObject *obj, \
jsid id, \
JSAccessMode mode, jsval *vp, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->CheckAccess(cx, obj, id, mode, vp, attrsp, \
wrapper, NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_CALL(_class) \
NS_IMETHODIMP _class::Call(JSContext *cx, JSObject *obj, \
uintN argc, jsval *argv, \
jsval *rval, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->Call(cx, obj, argc, argv, rval, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_CONSTRUCT(_class) \
NS_IMETHODIMP _class::Construct(JSContext *cx, JSObject *obj, \
uintN argc, jsval *argv, \
jsval *rval, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{return arbitrary->Construct(cx, obj, argc, argv, rval, wrapper, \
NULL, retval);}
#define XPC_IMPLEMENT_FORWARD_FINALIZE(_class) \
NS_IMETHODIMP _class::Finalize(JSContext *cx, JSObject *obj, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary) \
/* XPConnect does the finalization on the wrapper itself anyway */ \
{return arbitrary->Finalize(cx, obj, wrapper, NULL);}
/***************************************************************************/
#define XPC_IMPLEMENT_IGNORE_CREATE(_class) \
NS_IMETHODIMP _class::Create(JSContext *cx, JSObject *obj, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary) \
{return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_LOOKUPPROPERTY(_class) \
NS_IMETHODIMP _class::LookupProperty(JSContext *cx, JSObject *obj, \
jsid id, \
JSObject **objp, JSProperty **propp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*objp = NULL; *propp = NULL; *retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(_class) \
NS_IMETHODIMP _class::DefineProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval value, \
JSPropertyOp getter, JSPropertyOp setter, \
uintN attrs, JSProperty **propp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{if(propp)*propp = NULL; *retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_GETPROPERTY(_class) \
NS_IMETHODIMP _class::GetProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*vp = JSVAL_VOID; *retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_SETPROPERTY(_class) \
NS_IMETHODIMP _class::SetProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(_class) \
NS_IMETHODIMP _class::GetAttributes(JSContext *cx, JSObject *obj, \
jsid id, \
JSProperty *prop, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_FALSE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(_class) \
NS_IMETHODIMP _class::SetAttributes(JSContext *cx, JSObject *obj, \
jsid id, \
JSProperty *prop, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_FALSE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(_class) \
NS_IMETHODIMP _class::DeleteProperty(JSContext *cx, JSObject *obj, \
jsid id, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_DEFAULTVALUE(_class) \
NS_IMETHODIMP _class::DefaultValue(JSContext *cx, JSObject *obj, \
JSType type, jsval *vp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_ENUMERATE(_class) \
NS_IMETHODIMP _class::Enumerate(JSContext *cx, JSObject *obj, \
JSIterateOp enum_op, \
jsval *statep, jsid *idp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_FALSE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_CHECKACCESS(_class) \
NS_IMETHODIMP _class::CheckAccess(JSContext *cx, JSObject *obj, \
jsid id, \
JSAccessMode mode, jsval *vp, uintN *attrsp, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*retval = JS_FALSE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_CALL(_class) \
NS_IMETHODIMP _class::Call(JSContext *cx, JSObject *obj, \
uintN argc, jsval *argv, \
jsval *rval, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*rval = JSVAL_NULL; *retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_CONSTRUCT(_class) \
NS_IMETHODIMP _class::Construct(JSContext *cx, JSObject *obj, \
uintN argc, jsval *argv, \
jsval *rval, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary, \
JSBool* retval) \
{*rval = JSVAL_NULL; *retval = JS_TRUE; return NS_OK;}
#define XPC_IMPLEMENT_IGNORE_FINALIZE(_class) \
NS_IMETHODIMP _class::Finalize(JSContext *cx, JSObject *obj, \
nsIXPConnectWrappedNative* wrapper, \
nsIXPCScriptable* arbitrary) \
/* XPConnect does the finalization on the wrapper itself anyway */ \
{return NS_OK;}
/***************************************************************************/
#define XPC_IMPLEMENT_FORWARD_IXPCSCRIPTABLE(_class) \
XPC_IMPLEMENT_FORWARD_CREATE(_class) \
XPC_IMPLEMENT_FORWARD_LOOKUPPROPERTY(_class) \
XPC_IMPLEMENT_FORWARD_DEFINEPROPERTY(_class) \
XPC_IMPLEMENT_FORWARD_GETPROPERTY(_class) \
XPC_IMPLEMENT_FORWARD_SETPROPERTY(_class) \
XPC_IMPLEMENT_FORWARD_GETATTRIBUTES(_class) \
XPC_IMPLEMENT_FORWARD_SETATTRIBUTES(_class) \
XPC_IMPLEMENT_FORWARD_DELETEPROPERTY(_class) \
XPC_IMPLEMENT_FORWARD_DEFAULTVALUE(_class) \
XPC_IMPLEMENT_FORWARD_ENUMERATE(_class) \
XPC_IMPLEMENT_FORWARD_CHECKACCESS(_class) \
XPC_IMPLEMENT_FORWARD_CALL(_class) \
XPC_IMPLEMENT_FORWARD_CONSTRUCT(_class) \
XPC_IMPLEMENT_FORWARD_FINALIZE(_class)
#define XPC_IMPLEMENT_IGNORE_IXPCSCRIPTABLE(_class) \
XPC_IMPLEMENT_IGNORE_CREATE(_class) \
XPC_IMPLEMENT_IGNORE_LOOKUPPROPERTY(_class) \
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(_class) \
XPC_IMPLEMENT_IGNORE_GETPROPERTY(_class) \
XPC_IMPLEMENT_IGNORE_SETPROPERTY(_class) \
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(_class) \
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(_class) \
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(_class) \
XPC_IMPLEMENT_IGNORE_DEFAULTVALUE(_class) \
XPC_IMPLEMENT_IGNORE_ENUMERATE(_class) \
XPC_IMPLEMENT_IGNORE_CHECKACCESS(_class) \
XPC_IMPLEMENT_IGNORE_CALL(_class) \
XPC_IMPLEMENT_IGNORE_CONSTRUCT(_class) \
XPC_IMPLEMENT_IGNORE_FINALIZE(_class)
// macro test...
//class foo : public nsIXPCScriptable
//{
// XPC_DECLARE_IXPCSCRIPTABLE;
//};
//XPC_IMPLEMENT_FORWARD_IXPCSCRIPTABLE(foo)
/***************************************************************************/
/*
* A macro to make it easier to implement a simple Queryinterface that
* also deals with returning the scriptable interface object.
*/
#define NS_IMPL_QUERY_INTERFACE_SCRIPTABLE(_class, _scriptable) \
nsresult _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
{ \
if (NULL == aInstancePtr) { \
return NS_ERROR_NULL_POINTER; \
} \
if (aIID.Equals(nsISupports::GetIID()) || \
aIID.Equals(_class::GetIID())) { \
*aInstancePtr = (void*) this; \
NS_ADDREF_THIS(); \
return NS_OK; \
} \
if (aIID.Equals(nsIXPCScriptable::GetIID())) { \
*aInstancePtr = (void*) _scriptable; \
NS_ADDREF(_scriptable); \
return NS_OK; \
} \
*aInstancePtr = NULL; \
return NS_NOINTERFACE; \
}
/***************************************************************************/
#endif /* nsIXPCScriptable_h___ */

View File

@ -0,0 +1,167 @@
/* -*- 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.
*/
/* All the XPConnect public interfaces. */
#ifndef nsIXPConnect_h___
#define nsIXPConnect_h___
#include "nsISupports.h"
#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
* used within the XPC library or not. Any source file within the XPC
* library should define EXPORT_XPC_API whereas any client of the library
* should not.
*/
#ifdef EXPORT_XPC_API
#define XPC_PUBLIC_API(t) JS_EXPORT_API(t)
#define XPC_PUBLIC_DATA(t) JS_EXPORT_DATA(t)
#else
#define XPC_PUBLIC_API(t) JS_IMPORT_API(t)
#define XPC_PUBLIC_DATA(t) JS_IMPORT_DATA(t)
#endif
#define XPC_FRIEND_API(t) XPC_PUBLIC_API(t)
#define XPC_FRIEND_DATA(t) XPC_PUBLIC_DATA(t)
// XXX break these up into separate files?
// XXX declare them in XPIDL :)
/***************************************************************************/
// forward declarations...
class nsIXPCScriptable;
class nsIInterfaceInfo;
// {215DBE02-94A7-11d2-BA58-00805F8A5DD7}
#define NS_IXPCONNECT_WRAPPED_NATIVE_IID \
{ 0x215dbe02, 0x94a7, 0x11d2, \
{ 0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class nsIXPConnectWrappedNative : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_NATIVE_IID)
NS_IMETHOD GetDynamicScriptable(nsIXPCScriptable** p) = 0;
NS_IMETHOD GetArbitraryScriptable(nsIXPCScriptable** p) = 0;
NS_IMETHOD GetJSObject(JSObject** aJSObj) = 0;
NS_IMETHOD GetNative(nsISupports** aObj) = 0;
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
NS_IMETHOD DebugDump(int depth) = 0;
// XXX other methods?
};
/***************************************************************************/
// {215DBE03-94A7-11d2-BA58-00805F8A5DD7}
#define NS_IXPCONNECT_WRAPPED_JS_IID \
{ 0x215dbe03, 0x94a7, 0x11d2, \
{ 0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
// wrappers around JSObject are passed around as plain nsISupports pointers.
// To manipulate such a wrapper (as opposed to manipulating the wrapped
// JSObject via the wrapper) do a QueryInterface for the
// nsIXPConnectWrappedJSMethods interface
// i.e. 'nsIXPConnectWrappedJSMethods::GetIID()'
// and use the methods on that interface. (see below)
/******************************************/
// {BED52030-BCA6-11d2-BA79-00805F8A5DD7}
#define NS_IXPCONNECT_WRAPPED_JS_METHODS_IID \
{ 0xbed52030, 0xbca6, 0x11d2, \
{ 0xba, 0x79, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class nsIXPConnectWrappedJSMethods : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_JS_METHODS_IID)
NS_IMETHOD GetJSObject(JSObject** aJSObj) = 0;
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
NS_IMETHOD DebugDump(int depth) = 0;
// XXX other methods?
};
/***************************************************************************/
// {EFAE37B0-946D-11d2-BA58-00805F8A5DD7}
#define NS_IXPCONNECT_IID \
{ 0xefae37b0, 0x946d, 0x11d2, \
{0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7} }
class nsIXPConnect : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_IID)
NS_IMETHOD InitJSContext(JSContext* aJSContext,
JSObject* aGlobalJSObj) = 0;
NS_IMETHOD InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
nsISupports* aCOMObj,
REFNSIID aIID,
nsIXPConnectWrappedNative** aWrapper) = 0;
// XXX add 'AbandonJSContext' method and all that implies?
NS_IMETHOD WrapNative(JSContext* aJSContext,
nsISupports* aCOMObj,
REFNSIID aIID,
nsIXPConnectWrappedNative** aWrapper) = 0;
NS_IMETHOD WrapJS(JSContext* aJSContext,
JSObject* aJSObj,
REFNSIID aIID,
nsISupports** aWrapper) = 0;
NS_IMETHOD GetWrappedNativeOfJSObject(JSContext* aJSContext,
JSObject* aJSObj,
nsIXPConnectWrappedNative** aWrapper) = 0;
NS_IMETHOD DebugDump(int depth) = 0;
// XXX other methods?
};
JS_BEGIN_EXTERN_C
// XXX Add support for this to be a service?
XPC_PUBLIC_API(nsIXPConnect*)
XPC_GetXPConnect();
XPC_PUBLIC_API(nsIXPCComponents*)
XPC_GetXPConnectComponentsObject();
#ifdef DEBUG
XPC_PUBLIC_API(void)
XPC_Dump(nsISupports* p, int depth);
#define XPC_DUMP(x,d) XPC_Dump(x,d)
#else
#define XPC_DUMP(x,d) ((void)0)
#endif
JS_END_EXTERN_C
#endif /* nsIXPConnect_h___ */

View File

@ -0,0 +1,83 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM xpccomponents.idl
*/
#ifndef __gen_xpccomponents_h__
#define __gen_xpccomponents_h__
#include "nsISupports.h" /* interface nsISupports */
#ifdef XPIDL_JS_STUBS
#include "jsapi.h"
#endif
/* starting interface nsIXPCInterfaces */
/* {4b62a640-d26c-11d2-9842-006008962422} */
#define NS_IXPCINTERFACES_IID_STR "4b62a640-d26c-11d2-9842-006008962422"
#define NS_IXPCINTERFACES_IID \
{0x4b62a640, 0xd26c, 0x11d2, \
{ 0x98, 0x42, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
class nsIXPCInterfaces : public nsISupports {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_IXPCINTERFACES_IID;
return iid;
}
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIXPCInterfaces *priv);
#endif
};
/* starting interface nsIXPCClasses */
/* {978ff520-d26c-11d2-9842-006008962422} */
#define NS_IXPCCLASSES_IID_STR "978ff520-d26c-11d2-9842-006008962422"
#define NS_IXPCCLASSES_IID \
{0x978ff520, 0xd26c, 0x11d2, \
{ 0x98, 0x42, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
class nsIXPCClasses : public nsISupports {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_IXPCCLASSES_IID;
return iid;
}
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIXPCClasses *priv);
#endif
};
/* starting interface nsIXPCComponents */
/* {42624f80-d26c-11d2-9842-006008962422} */
#define NS_IXPCCOMPONENTS_IID_STR "42624f80-d26c-11d2-9842-006008962422"
#define NS_IXPCCOMPONENTS_IID \
{0x42624f80, 0xd26c, 0x11d2, \
{ 0x98, 0x42, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
class nsIXPCComponents : public nsISupports {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_IXPCCOMPONENTS_IID;
return iid;
}
/* readonly attribute nsIXPCInterfaces interfaces; */
NS_IMETHOD GetInterfaces(nsIXPCInterfaces * *aInterfaces) = 0;
/* readonly attribute nsIXPCClasses classes; */
NS_IMETHOD GetClasses(nsIXPCClasses * *aClasses) = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIXPCComponents *priv);
#endif
};
#endif /* __gen_xpccomponents_h__ */

View File

@ -0,0 +1,111 @@
/*
* 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;
/* 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);
#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__ */

View File

@ -0,0 +1,76 @@
/* -*- 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.
*/
/* Debug Logging support. */
#ifndef xpclog_h___
#define xpclog_h___
#include "nsIXPConnect.h"
#include "prtypes.h"
#include "prlog.h"
/*
* This uses prlog.h See prlog.h for environment settings for output.
* The module name used here is 'xpclog'. These environment settings
* should work...
*
* SET NSPR_LOG_MODULES=xpclog:5
* SET NSPR_LOG_FILE=logfile.txt
*
* usage:
* XPC_LOG_ERROR(("my comment number %d", 5)) // note the double parens
*
*/
#ifdef DEBUG
#define XPC_LOG_INTERNAL(number,_args) \
do{if(XPC_Log_Check(number)){XPC_Log_print _args;}}while(0)
#define XPC_LOG_ALWAYS(_args) XPC_LOG_INTERNAL(1,_args)
#define XPC_LOG_ERROR(_args) XPC_LOG_INTERNAL(2,_args)
#define XPC_LOG_WARNING(_args) XPC_LOG_INTERNAL(3,_args)
#define XPC_LOG_DEBUG(_args) XPC_LOG_INTERNAL(4,_args)
#define XPC_LOG_FLUSH() PR_LogFlush()
#define XPC_LOG_INDENT() XPC_Log_Indent()
#define XPC_LOG_OUTDENT() XPC_Log_Outdent()
#define XPC_LOG_CLEAR_INDENT() XPC_Log_Clear_Indent()
JS_BEGIN_EXTERN_C
XPC_PUBLIC_API(void) XPC_Log_print(const char *fmt, ...);
XPC_PUBLIC_API(PRBool) XPC_Log_Check(int i);
XPC_PUBLIC_API(void) XPC_Log_Indent();
XPC_PUBLIC_API(void) XPC_Log_Outdent();
XPC_PUBLIC_API(void) XPC_Log_Clear_Indent();
JS_END_EXTERN_C
#else
#define XPC_LOG_ALWAYS(_args) ((void)0)
#define XPC_LOG_ERROR(_args) ((void)0)
#define XPC_LOG_WARNING(_args) ((void)0)
#define XPC_LOG_DEBUG(_args) ((void)0)
#define XPC_LOG_FLUSH() ((void)0)
#define XPC_LOG_INDENT() ((void)0)
#define XPC_LOG_OUTDENT() ((void)0)
#define XPC_LOG_CLEAR_INDENT() ((void)0)
#endif
#endif /* xpclog_h___ */

View File

@ -0,0 +1,3 @@
Makefile
mk.bat
set_env.bat

View File

@ -0,0 +1,69 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
# DIRS = md
LIBRARY_NAME=xpconnect
MODULE=xpconnect
DEFINES += -DJSFILE -DJS_THREADSAFE
CPPSRCS= \
nsXPConnect.cpp \
xpcarbitrary.cpp \
xpccomponents.cpp \
xpccontext.cpp \
xpcconvert.cpp \
xpcjsid.cpp \
xpclog.cpp \
xpcmaps.cpp \
xpcmodule.cpp \
xpcthrower.cpp \
xpcutil.cpp \
xpcwrappedjs.cpp \
xpcwrappedjsclass.cpp \
xpcwrappednative.cpp \
xpcwrappednativeclass.cpp \
$(NULL)
EXPORTS = \
nsIXPCScriptable.h \
nsIXPConnect.h \
xpccomponents.h \
xpcjsid.h \
xpclog.h \
xpctest.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)
# MD_LIBRARY = md/unix/libxpcmd.a

View File

@ -0,0 +1,8 @@
/* jband - 01/03/99 - */
see http://www.mozilla.org/scriptable
This is an initial checkin of a *very* unfinished and not yet functional
implementation of XPConnect. This is not yet part of the Gecko build.
Pretty near everyone in the universe can ignore it for now.

60
js/src/xpconnect/src/TODO Normal file
View File

@ -0,0 +1,60 @@
/* jband - 02/20/99 - TODO and issues list */
**** TODO ****
- Docs
- list of required docs
- docs on source?
- namespaces
- xpidl work
- xptinfo work
- XPConnect work
- ports
- Mac!
- other
- xpidl work for marking pointer, const, reference, nsID
- 64bit ints on platforms w/o 'long long'
- re-org the source directory layout
- define 'JSFILE' by default in JS engines
- better api for Components object
- reimplement nsSJIID and nsJSCID using multiple inheritence
- nsJSCID getSerrvice method
- global namespace interface
- fix interface constant stuff
- XPCOnnect as a service
- auto reg stuff
- flattened component scheme
- xpidl extensions
- XPConnect support
- simple aggregatable interface for GetCID()
- 'shared'
- resolve the string issues
- work with embedders
- better exceptions (not just throw strings)
- work in JS engine to track more info when exceptions thrown so that
the uncaught exceptions will not be so mysterious (filename and lineno)
- better tests
- xpidl work and documents
- proto object per class?
- Param gc rooting?
- safer use of jsdoubles?
**** ISSUES ****
- Contexts\Runtimes\ScopeChain problems
- Constants for WrappedJS objects?
- Even for WrappedNatives the constants should (perhaps) be in the
(as yet not created) class proto object rather than props of each object?
This makes then overwritable?
- Ref counting for contexts?
- JSContext and JSRuntime life times and how that impacts XPConnect stuff
- wrappedJS stub stuff can't handle (non-xpcom) natives passed by value -
we need to know the object size to cleanup the stack!
- Listener interface for class and instance create/destroy?
- Issues with shutting down a context?

View File

@ -0,0 +1,80 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
DLLNAME = xpc$(MOZ_BITS)$(VERSION_NUMBER)
#PDBFILE = $(DLLNAME).pdb
#MAPFILE = $(DLLNAME).map
#RESFILE = xpc$(MOZ_BITS)$(VERSION_NUMBER).res
DLL =.\$(OBJDIR)\$(DLLNAME).dll
MODULE=xpconnect
REQUIRES=xpcom js libxpt xptinfo xptcall
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPC_API -DJS_THREADSAFE
OBJS= \
.\$(OBJDIR)\nsXPConnect.obj \
.\$(OBJDIR)\xpcarbitrary.obj \
.\$(OBJDIR)\xpccomponents.obj \
.\$(OBJDIR)\xpccontext.obj \
.\$(OBJDIR)\xpcconvert.obj \
.\$(OBJDIR)\xpcjsid.obj \
.\$(OBJDIR)\xpclog.obj \
.\$(OBJDIR)\xpcmaps.obj \
.\$(OBJDIR)\xpcmodule.obj \
.\$(OBJDIR)\xpcthrower.obj \
.\$(OBJDIR)\xpcutil.obj \
.\$(OBJDIR)\xpcwrappedjs.obj \
.\$(OBJDIR)\xpcwrappedjsclass.obj \
.\$(OBJDIR)\xpcwrappednative.obj \
.\$(OBJDIR)\xpcwrappednativeclass.obj \
$(NULL)
LINCS=-I$(PUBLIC)\xpconnect -I$(PUBLIC)\xpcom -I$(PUBLIC)\js \
-I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo \
-I$(PUBLIC)\xptcall
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LLIBS= $(LIBNSPR) \
$(DIST)\lib\js$(MOZ_BITS)$(VERSION_NUMBER).lib \
$(DIST)\lib\xpcom$(MOZ_BITS).lib \
$(DIST)\lib\xptinfo$(MOZ_BITS).lib \
$(DIST)\lib\xptcall$(MOZ_BITS).lib \
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
!endif
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(DLLNAME).lib
rm -f $(DIST)\bin\$(DLLNAME).dll

View File

@ -0,0 +1,444 @@
/* -*- 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.
*/
/* High level class and public functions implementation. */
#include "xpcprivate.h"
#define CONTEXT_MAP_SIZE 16
#define JS_MAP_SIZE 256
#define NATIVE_MAP_SIZE 256
#define JS_CLASS_MAP_SIZE 256
#define NATIVE_CLASS_MAP_SIZE 256
static NS_DEFINE_IID(kXPConnectIID, NS_IXPCONNECT_IID);
NS_IMPL_ISUPPORTS(nsXPConnect, kXPConnectIID)
nsXPConnect* nsXPConnect::mSelf = NULL;
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
// static
nsXPConnect*
nsXPConnect::GetXPConnect()
{
// XXX This pattern causes us to retain an extra ref on the singleton.
// XXX Should the singleton nsXpConnect object *ever* be deleted?
if(!mSelf)
{
mSelf = new nsXPConnect();
if(mSelf && (!mSelf->mContextMap ||
!mSelf->mAllocator ||
!mSelf->mArbitraryScriptable ||
!mSelf->mInterfaceInfoManager ||
!mSelf->mThrower))
NS_RELEASE(mSelf);
}
if(mSelf)
NS_ADDREF(mSelf);
return mSelf;
}
// static
nsIAllocator*
nsXPConnect::GetAllocator(nsXPConnect* xpc /*= NULL*/)
{
nsIAllocator* al;
nsXPConnect* xpcl = xpc;
if(!xpcl && !(xpcl = GetXPConnect()))
return NULL;
if(NULL != (al = xpcl->mAllocator))
NS_ADDREF(al);
if(!xpc)
NS_RELEASE(xpcl);
return al;
}
// static
nsIInterfaceInfoManager*
nsXPConnect::GetInterfaceInfoManager(nsXPConnect* xpc /*= NULL*/)
{
nsIInterfaceInfoManager* iim;
nsXPConnect* xpcl = xpc;
if(!xpcl && !(xpcl = GetXPConnect()))
return NULL;
if(NULL != (iim = xpcl->mInterfaceInfoManager))
NS_ADDREF(iim);
if(!xpc)
NS_RELEASE(xpcl);
return iim;
}
// static
XPCContext*
nsXPConnect::GetContext(JSContext* cx, nsXPConnect* xpc /*= NULL*/)
{
NS_PRECONDITION(cx,"bad param");
XPCContext* xpcc;
nsXPConnect* xpcl = xpc;
if(!xpcl && !(xpcl = GetXPConnect()))
return NULL;
xpcc = xpcl->mContextMap->Find(cx);
if(!xpcc)
xpcc = xpcl->NewContext(cx, JS_GetGlobalObject(cx));
if(!xpc)
NS_RELEASE(xpcl);
return xpcc;
}
// static
XPCJSThrower*
nsXPConnect::GetJSThrower(nsXPConnect* xpc /*= NULL */)
{
XPCJSThrower* thrower;
nsXPConnect* xpcl = xpc;
if(!xpcl && !(xpcl = GetXPConnect()))
return NULL;
thrower = xpcl->mThrower;
if(!xpc)
NS_RELEASE(xpcl);
return thrower;
}
// static
JSBool
nsXPConnect::IsISupportsDescendent(nsIInterfaceInfo* info)
{
if(!info)
return JS_FALSE;
nsIInterfaceInfo* oldest = info;
nsIInterfaceInfo* parent;
NS_ADDREF(oldest);
while(NS_SUCCEEDED(oldest->GetParent(&parent)))
{
NS_RELEASE(oldest);
oldest = parent;
}
JSBool retval = JS_FALSE;
nsID* iid;
if(NS_SUCCEEDED(oldest->GetIID(&iid)))
{
retval = iid->Equals(nsISupports::GetIID());
XPCMem::Free(iid);
}
NS_RELEASE(oldest);
return retval;
}
nsXPConnect::nsXPConnect()
: mContextMap(NULL),
mAllocator(NULL),
mArbitraryScriptable(NULL),
mInterfaceInfoManager(NULL),
mThrower(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
xpc_RegisterSelf();
nsXPCWrappedNativeClass::OneTimeInit();
mContextMap = JSContext2XPCContextMap::newMap(CONTEXT_MAP_SIZE);
mArbitraryScriptable = new nsXPCArbitraryScriptable();
nsServiceManager::GetService(kAllocatorCID,
kIAllocatorIID,
(nsISupports **)&mAllocator);
// XXX later this will be a service
mInterfaceInfoManager = XPTI_GetInterfaceInfoManager();
mThrower = new XPCJSThrower(JS_TRUE);
}
nsXPConnect::~nsXPConnect()
{
if(mContextMap)
delete mContextMap;
if(mAllocator)
nsServiceManager::ReleaseService(kAllocatorCID, mAllocator);
if(mArbitraryScriptable)
NS_RELEASE(mArbitraryScriptable);
// XXX later this will be a service
if(mInterfaceInfoManager)
NS_RELEASE(mInterfaceInfoManager);
if(mThrower)
delete mThrower;
mSelf = NULL;
}
NS_IMETHODIMP
nsXPConnect::InitJSContext(JSContext* aJSContext,
JSObject* aGlobalJSObj)
{
if(aJSContext)
{
if(!aGlobalJSObj)
aGlobalJSObj = JS_GetGlobalObject(aJSContext);
if(aGlobalJSObj &&
!mContextMap->Find(aJSContext) &&
NewContext(aJSContext, aGlobalJSObj))
{
return NS_OK;
}
}
XPC_LOG_ERROR(("nsXPConnect::InitJSContext failed"));
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXPConnect::InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
nsISupports* aCOMObj,
REFNSIID aIID,
nsIXPConnectWrappedNative** aWrapper)
{
nsXPCWrappedNative* wrapper = NULL;
XPCContext* xpcc = NULL;
if(!mContextMap->Find(aJSContext) &&
NULL != (xpcc = NewContext(aJSContext, NULL, JS_FALSE)))
{
wrapper = nsXPCWrappedNative::GetNewOrUsedWrapper(xpcc, aCOMObj, aIID);
if(wrapper)
{
if(JS_InitStandardClasses(aJSContext, wrapper->GetJSObject()) &&
xpcc->Init(wrapper->GetJSObject()))
{
*aWrapper = wrapper;
return NS_OK;
}
}
}
if(wrapper)
NS_RELEASE(wrapper);
if(xpcc)
{
mContextMap->Remove(xpcc);
delete xpcc;
}
XPC_LOG_ERROR(("nsXPConnect::InitJSContextWithNewWrappedGlobal failed"));
*aWrapper = NULL;
return NS_ERROR_FAILURE;
}
XPCContext*
nsXPConnect::NewContext(JSContext* cx, JSObject* global,
JSBool doInit /*= JS_TRUE*/)
{
XPCContext* xpcc;
NS_PRECONDITION(cx,"bad param");
NS_PRECONDITION(!mContextMap->Find(cx),"bad param");
xpcc = XPCContext::newXPCContext(cx, global,
JS_MAP_SIZE,
NATIVE_MAP_SIZE,
JS_CLASS_MAP_SIZE,
NATIVE_CLASS_MAP_SIZE);
if(doInit && xpcc && !xpcc->Init())
{
XPC_LOG_ERROR(("nsXPConnect::NewContext failed"));
delete xpcc;
xpcc = NULL;
}
if(xpcc)
mContextMap->Add(xpcc);
return xpcc;
}
NS_IMETHODIMP
nsXPConnect::WrapNative(JSContext* aJSContext,
nsISupports* aCOMObj,
REFNSIID aIID,
nsIXPConnectWrappedNative** aWrapper)
{
NS_PRECONDITION(aJSContext,"bad param");
NS_PRECONDITION(aCOMObj,"bad param");
NS_PRECONDITION(aWrapper,"bad param");
XPCContext* xpcc = nsXPConnect::GetContext(aJSContext, this);
if(xpcc)
{
nsXPCWrappedNative* wrapper =
nsXPCWrappedNative::GetNewOrUsedWrapper(xpcc, aCOMObj, aIID);
if(wrapper)
{
*aWrapper = wrapper;
return NS_OK;
}
}
XPC_LOG_ERROR(("nsXPConnect::WrapNative failed"));
*aWrapper = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXPConnect::WrapJS(JSContext* aJSContext,
JSObject* aJSObj,
REFNSIID aIID,
nsISupports** aWrapper)
{
NS_PRECONDITION(aJSContext,"bad param");
NS_PRECONDITION(aJSObj,"bad param");
NS_PRECONDITION(aWrapper,"bad param");
XPCContext* xpcc = nsXPConnect::GetContext(aJSContext, this);
if(xpcc)
{
nsXPCWrappedJS* wrapper =
nsXPCWrappedJS::GetNewOrUsedWrapper(xpcc, aJSObj, aIID);
if(wrapper)
{
*aWrapper = wrapper;
return NS_OK;
}
}
XPC_LOG_ERROR(("nsXPConnect::WrapJS failed"));
*aWrapper = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXPConnect::GetWrappedNativeOfJSObject(JSContext* aJSContext,
JSObject* aJSObj,
nsIXPConnectWrappedNative** aWrapper)
{
NS_PRECONDITION(aJSContext,"bad param");
NS_PRECONDITION(aJSObj,"bad param");
NS_PRECONDITION(aWrapper,"bad param");
if(!(*aWrapper = nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(aJSContext,aJSObj)))
return NS_ERROR_UNEXPECTED;
NS_ADDREF(*aWrapper);
return NS_OK;
}
// has to go somewhere...
nsXPCArbitraryScriptable::nsXPCArbitraryScriptable()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
#ifdef DEBUG
JS_STATIC_DLL_CALLBACK(intN)
ContextMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
{
((XPCContext*)he->value)->DebugDump(*(int*)arg);
return HT_ENUMERATE_NEXT;
}
#endif
NS_IMETHODIMP
nsXPConnect::DebugDump(int depth)
{
#ifdef DEBUG
depth-- ;
XPC_LOG_ALWAYS(("nsXPConnect @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mAllocator @ %x", mAllocator));
XPC_LOG_ALWAYS(("mArbitraryScriptable @ %x", mArbitraryScriptable));
XPC_LOG_ALWAYS(("mInterfaceInfoManager @ %x", mInterfaceInfoManager));
XPC_LOG_ALWAYS(("mContextMap @ %x with %d context(s)", \
mContextMap, mContextMap ? mContextMap->Count() : 0));
// iterate contexts...
if(depth && mContextMap && mContextMap->Count())
{
XPC_LOG_INDENT();
mContextMap->Enumerate(ContextMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
}
XPC_LOG_OUTDENT();
#endif
return NS_OK;
}
XPC_PUBLIC_API(nsIXPConnect*)
XPC_GetXPConnect()
{
// temp test...
// nsXPCWrappedJS* p = new nsXPCWrappedJS();
// p->Stub5();
return nsXPConnect::GetXPConnect();
}
#ifdef DEBUG
XPC_PUBLIC_API(void)
XPC_Dump(nsISupports* p, int depth)
{
if(!depth)
return;
if(!p)
{
XPC_LOG_ALWAYS(("*** Cound not dump object with NULL address"));
return;
}
nsIXPConnect* xpc;
nsIXPCWrappedNativeClass* wnc;
nsIXPCWrappedJSClass* wjsc;
nsIXPConnectWrappedNative* wn;
nsIXPConnectWrappedJSMethods* wjsm;
if(NS_SUCCEEDED(p->QueryInterface(nsIXPConnect::GetIID(),(void**)&xpc)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPConnect..."));
xpc->DebugDump(depth);
NS_RELEASE(xpc);
}
else if(NS_SUCCEEDED(p->QueryInterface(nsIXPCWrappedNativeClass::GetIID(),
(void**)&wnc)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedNativeClass..."));
wnc->DebugDump(depth);
NS_RELEASE(wnc);
}
else if(NS_SUCCEEDED(p->QueryInterface(nsIXPCWrappedJSClass::GetIID(),
(void**)&wjsc)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedJSClass..."));
wjsc->DebugDump(depth);
NS_RELEASE(wjsc);
}
else if(NS_SUCCEEDED(p->QueryInterface(nsIXPConnectWrappedNative::GetIID(),
(void**)&wn)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedNative..."));
wn->DebugDump(depth);
NS_RELEASE(wn);
}
else if(NS_SUCCEEDED(p->QueryInterface(nsIXPConnectWrappedJSMethods::GetIID(),
(void**)&wjsm)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedJSMethods..."));
wjsm->DebugDump(depth);
NS_RELEASE(wjsm);
}
else
XPC_LOG_ALWAYS(("*** Cound not dump the nsISupports @ %x", p));
}
#endif

View File

@ -0,0 +1,41 @@
/* -*- 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.
*/
/* Error Message definitions. */
/*
* The format here is the same as that in js/src/js.msg
* However, arguments are not supported. And, the error->exception
* mapping is not appropriate here. So, the arg count and exception id
* columns are left with zero values.
*
* Also, the idetifiers here are read in as members of an anonymous enum in
* the class XPCJSError rather than at the top level as in JS.
*/
MSG_DEF(NOT_AN_ERROR, 0, 0, 0, "<Error #0 is reserved>")
MSG_DEF(NOT_ENOUGH_ARGS, 1, 0, 0, "Not enough arguments")
MSG_DEF(NEED_OUT_OBJECT, 2, 0, 0, "'Out' argument must be an object")
MSG_DEF(CANT_SET_OUT_VAL, 3, 0, 0, "Can not set 'value' property of 'out' argument")
MSG_DEF(NATIVE_RETURNED_FAILURE, 4, 0, 0, "Component returned failure code:")
MSG_DEF(CANT_GET_INTERFACE_INFO, 5, 0, 0, "Can not find interface information")
MSG_DEF(CANT_GET_PARAM_IFACE_INFO,6, 0, 0, "Can not find interface information for parameter")
MSG_DEF(CANT_GET_METHOD_INFO, 7, 0, 0, "Can not find method information")
MSG_DEF(UNEXPECTED, 8, 0, 0, "Unexpected error in XPConnect")
MSG_DEF(BAD_CONVERT_JS, 9, 0, 0, "Could not convert JavaScript argument")
MSG_DEF(BAD_CONVERT_NATIVE, 10, 0, 0, "Could not convert Native argument")

View File

@ -0,0 +1,255 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implements nsXPCArbitraryScriptable */
#include "xpcprivate.h"
extern "C" JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
static NS_DEFINE_IID(kArbitraryScriptableIID, NS_IXPCSCRIPTABLE_IID);
NS_IMPL_ISUPPORTS(nsXPCArbitraryScriptable, kArbitraryScriptableIID)
#define REAL_WRAPPER(w) ((nsXPCWrappedNative*)(w))
NS_IMETHODIMP
nsXPCArbitraryScriptable::Create(JSContext *cx, JSObject *obj,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::LookupProperty(JSContext *cx, JSObject *obj, jsid id,
JSObject **objp, JSProperty **propp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.lookupProperty(cx, obj, id, objp, propp
#if defined JS_THREADSAFE && defined DEBUG
, "unknown file", 1
#endif
);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::DefineProperty(JSContext *cx, JSObject *obj,
jsid id, jsval value,
JSPropertyOp getter, JSPropertyOp setter,
uintN attrs, JSProperty **propp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.defineProperty(cx, obj, id, value, getter, setter,
attrs, propp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.getProperty(cx, obj, id, vp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::SetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.setProperty(cx, obj, id, vp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::GetAttributes(JSContext *cx, JSObject *obj, jsid id,
JSProperty *prop, uintN *attrsp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.getAttributes(cx, obj, id, prop, attrsp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::SetAttributes(JSContext *cx, JSObject *obj, jsid id,
JSProperty *prop, uintN *attrsp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.setAttributes(cx, obj, id, prop, attrsp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::DeleteProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.deleteProperty(cx, obj, id, vp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::DefaultValue(JSContext *cx, JSObject *obj,
JSType type, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.defaultValue(cx, obj, type, vp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::Enumerate(JSContext *cx, JSObject *obj,
JSIterateOp enum_op,
jsval *statep, jsid *idp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.enumerate(cx, obj, enum_op, statep, idp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::CheckAccess(JSContext *cx, JSObject *obj, jsid id,
JSAccessMode mode, jsval *vp, uintN *attrsp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.checkAccess(cx, obj, id, mode, vp, attrsp);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::Call(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv,
jsval *rval,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.call(cx, obj, argc, argv, rval);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::Construct(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv,
jsval *rval,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(retval, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
*retval = js_ObjectOps.construct(cx, obj, argc, argv, rval);
return NS_OK;
}
NS_IMETHODIMP
nsXPCArbitraryScriptable::Finalize(JSContext *cx, JSObject *obj,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary)
{
NS_PRECONDITION(wrapper, "bad param");
NS_PRECONDITION(cx, "bad param");
NS_PRECONDITION(obj, "bad param");
NS_PRECONDITION(obj==REAL_WRAPPER(wrapper)->GetJSObject(), "bad param");
/* XPConnect does the finalization on the wrapper itself anyway */
return NS_OK;
}

View File

@ -0,0 +1,370 @@
/* -*- 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 "Components" xpcom objects for JavaScript. */
#include "xpcprivate.h"
/***************************************************************************/
class InterfacesScriptable : public nsIXPCScriptable
{
public:
NS_DECL_ISUPPORTS;
XPC_DECLARE_IXPCSCRIPTABLE;
InterfacesScriptable();
virtual ~InterfacesScriptable();
private:
void CacheDynaProp(JSContext *cx, JSObject *obj, jsid id,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary);
};
/**********************************************/
InterfacesScriptable::InterfacesScriptable()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
InterfacesScriptable::~InterfacesScriptable() {}
static NS_DEFINE_IID(kInterfacesScriptableIID, NS_IXPCSCRIPTABLE_IID);
NS_IMPL_ISUPPORTS(InterfacesScriptable, kInterfacesScriptableIID);
XPC_IMPLEMENT_FORWARD_CREATE(InterfacesScriptable);
// XPC_IMPLEMENT_FORWARD_LOOKUPPROPERTY(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(InterfacesScriptable);
// XPC_IMPLEMENT_FORWARD_GETPROPERTY(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_SETPROPERTY(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(InterfacesScriptable);
XPC_IMPLEMENT_FORWARD_DEFAULTVALUE(InterfacesScriptable);
XPC_IMPLEMENT_FORWARD_ENUMERATE(InterfacesScriptable);
XPC_IMPLEMENT_FORWARD_CHECKACCESS(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_CALL(InterfacesScriptable);
XPC_IMPLEMENT_IGNORE_CONSTRUCT(InterfacesScriptable);
XPC_IMPLEMENT_FORWARD_FINALIZE(InterfacesScriptable);
NS_IMETHODIMP
InterfacesScriptable::LookupProperty(JSContext *cx, JSObject *obj,
jsid id,
JSObject **objp, JSProperty **propp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
if(NS_SUCCEEDED(arbitrary->LookupProperty(cx, obj, id, objp, propp, wrapper,
NULL, retval)) && *retval)
return NS_OK;
CacheDynaProp(cx, obj, id, wrapper, arbitrary);
return arbitrary->LookupProperty(cx, obj, id, objp, propp, wrapper,
NULL, retval);
}
NS_IMETHODIMP
InterfacesScriptable::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
if(NS_SUCCEEDED(arbitrary->GetProperty(cx, obj, id, vp, wrapper,
NULL, retval)) && *retval &&
*vp != JSVAL_VOID)
return NS_OK;
CacheDynaProp(cx, obj, id, wrapper, arbitrary);
return arbitrary->GetProperty(cx, obj, id, vp, wrapper, NULL, retval);
}
void
InterfacesScriptable::CacheDynaProp(JSContext *cx, JSObject *obj, jsid id,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary)
{
jsval idval;
const char* property_name = NULL;
if(JS_IdToValue(cx, id, &idval) && JSVAL_IS_STRING(idval) &&
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval))) != NULL)
{
nsJSIID* nsid = nsJSIID::NewID(property_name);
nsIXPConnectWrappedNative* nsid_wrapper;
if(nsid)
{
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if(xpc)
{
if(NS_SUCCEEDED(xpc->WrapNative(cx, nsid,
nsIJSIID::GetIID(),
&nsid_wrapper)))
{
JSObject* idobj;
if(NS_SUCCEEDED(nsid_wrapper->GetJSObject(&idobj)))
{
JSBool retval;
jsval val = OBJECT_TO_JSVAL(idobj);
arbitrary->SetProperty(cx, obj, id, &val, wrapper,
NULL, &retval);
}
NS_RELEASE(nsid_wrapper);
}
NS_RELEASE(xpc);
}
}
}
}
/***************************************************************************/
class nsXPCInterfaces : public nsIXPCInterfaces
{
public:
// all the interface method declarations...
NS_DECL_ISUPPORTS;
public:
nsXPCInterfaces();
virtual ~nsXPCInterfaces();
private:
InterfacesScriptable* mScriptable;
};
nsXPCInterfaces::nsXPCInterfaces()
{
NS_INIT_ISUPPORTS();
NS_ADDREF_THIS();
mScriptable = new InterfacesScriptable();
}
nsXPCInterfaces::~nsXPCInterfaces()
{
NS_RELEASE(mScriptable);
}
NS_IMPL_ADDREF(nsXPCInterfaces)
NS_IMPL_RELEASE(nsXPCInterfaces)
NS_IMPL_QUERY_INTERFACE_SCRIPTABLE(nsXPCInterfaces, mScriptable)
/***************************************************************************/
/***************************************************************************/
class ClassesScriptable : public nsIXPCScriptable
{
public:
NS_DECL_ISUPPORTS;
XPC_DECLARE_IXPCSCRIPTABLE;
ClassesScriptable();
virtual ~ClassesScriptable();
private:
void CacheDynaProp(JSContext *cx, JSObject *obj, jsid id,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary);
};
/**********************************************/
ClassesScriptable::ClassesScriptable()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
ClassesScriptable::~ClassesScriptable() {}
static NS_DEFINE_IID(kClassesScriptableIID, NS_IXPCCLASSES_IID);
NS_IMPL_ISUPPORTS(ClassesScriptable, kClassesScriptableIID);
XPC_IMPLEMENT_FORWARD_CREATE(ClassesScriptable);
// XPC_IMPLEMENT_FORWARD_LOOKUPPROPERTY(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(ClassesScriptable);
// XPC_IMPLEMENT_FORWARD_GETPROPERTY(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_SETPROPERTY(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(ClassesScriptable);
XPC_IMPLEMENT_FORWARD_DEFAULTVALUE(ClassesScriptable);
XPC_IMPLEMENT_FORWARD_ENUMERATE(ClassesScriptable);
XPC_IMPLEMENT_FORWARD_CHECKACCESS(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_CALL(ClassesScriptable);
XPC_IMPLEMENT_IGNORE_CONSTRUCT(ClassesScriptable);
XPC_IMPLEMENT_FORWARD_FINALIZE(ClassesScriptable);
NS_IMETHODIMP
ClassesScriptable::LookupProperty(JSContext *cx, JSObject *obj,
jsid id,
JSObject **objp, JSProperty **propp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
if(NS_SUCCEEDED(arbitrary->LookupProperty(cx, obj, id, objp, propp, wrapper,
NULL, retval)) && *retval)
return NS_OK;
CacheDynaProp(cx, obj, id, wrapper, arbitrary);
return arbitrary->LookupProperty(cx, obj, id, objp, propp, wrapper,
NULL, retval);
}
NS_IMETHODIMP
ClassesScriptable::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
if(NS_SUCCEEDED(arbitrary->GetProperty(cx, obj, id, vp, wrapper,
NULL, retval)) && *retval &&
*vp != JSVAL_VOID)
return NS_OK;
CacheDynaProp(cx, obj, id, wrapper, arbitrary);
return arbitrary->GetProperty(cx, obj, id, vp, wrapper, NULL, retval);
}
void
ClassesScriptable::CacheDynaProp(JSContext *cx, JSObject *obj, jsid id,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary)
{
jsval idval;
const char* property_name = NULL;
if(JS_IdToValue(cx, id, &idval) && JSVAL_IS_STRING(idval) &&
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval))) != NULL)
{
nsJSCID* nsid = nsJSCID::NewID(property_name);
nsIXPConnectWrappedNative* nsid_wrapper;
if(nsid)
{
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if(xpc)
{
if(NS_SUCCEEDED(xpc->WrapNative(cx, nsid,
nsIJSCID::GetIID(),
&nsid_wrapper)))
{
JSObject* idobj;
if(NS_SUCCEEDED(nsid_wrapper->GetJSObject(&idobj)))
{
JSBool retval;
jsval val = OBJECT_TO_JSVAL(idobj);
arbitrary->SetProperty(cx, obj, id, &val, wrapper,
NULL, &retval);
}
NS_RELEASE(nsid_wrapper);
}
NS_RELEASE(xpc);
}
}
}
}
/***************************************************************************/
class nsXPCClasses : public nsIXPCClasses
{
public:
// all the interface method declarations...
NS_DECL_ISUPPORTS;
public:
nsXPCClasses();
virtual ~nsXPCClasses();
private:
ClassesScriptable* mScriptable;
};
nsXPCClasses::nsXPCClasses()
{
NS_INIT_ISUPPORTS();
NS_ADDREF_THIS();
mScriptable = new ClassesScriptable();
}
nsXPCClasses::~nsXPCClasses()
{
NS_RELEASE(mScriptable);
}
NS_IMPL_ADDREF(nsXPCClasses)
NS_IMPL_RELEASE(nsXPCClasses)
NS_IMPL_QUERY_INTERFACE_SCRIPTABLE(nsXPCClasses, mScriptable)
/***************************************************************************/
/***************************************************************************/
static NS_DEFINE_IID(kComponentsIID, NS_IXPCCOMPONENTS_IID);
NS_IMPL_QUERY_INTERFACE(nsXPCComponents, kComponentsIID)
NS_IMPL_ADDREF(nsXPCComponents)
NS_IMPL_RELEASE(nsXPCComponents)
nsXPCComponents::nsXPCComponents()
{
NS_INIT_ISUPPORTS();
NS_ADDREF_THIS();
mInterfaces = new nsXPCInterfaces();
mClasses = new nsXPCClasses();
}
nsXPCComponents::~nsXPCComponents()
{
if(mInterfaces)
NS_RELEASE(mInterfaces);
if(mClasses)
NS_RELEASE(mClasses);
}
NS_IMETHODIMP
nsXPCComponents::GetInterfaces(nsIXPCInterfaces * *aInterfaces)
{
if(mInterfaces)
{
NS_ADDREF(mInterfaces);
*aInterfaces = mInterfaces;
return NS_OK;
}
*aInterfaces = NULL;
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsXPCComponents::GetClasses(nsIXPCClasses * *aClasses)
{
if(mClasses)
{
NS_ADDREF(mClasses);
*aClasses = mClasses;
return NS_OK;
}
*aClasses = NULL;
return NS_ERROR_UNEXPECTED;
}
/***************************************************************************/
XPC_PUBLIC_API(nsIXPCComponents*)
XPC_GetXPConnectComponentsObject()
{
return new nsXPCComponents();
}

View File

@ -0,0 +1,196 @@
/* -*- 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() &&
xpcc->mConstuctorStrID &&
xpcc->mToStringStrID)
{
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);
JS_ValueToId(aJSContext,
STRING_TO_JSVAL(JS_InternString(aJSContext, "constructor")),
&mConstuctorStrID);
JS_ValueToId(aJSContext,
STRING_TO_JSVAL(JS_InternString(aJSContext, "toString")),
&mToStringStrID);
}
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
}

View File

@ -0,0 +1,512 @@
/* -*- 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,
JSBool useAllocator, 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(useAllocator,"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(useAllocator)
{
int len = strlen(bytes)+1;
if(!(*((void**)d) = XPCMem::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(useAllocator)
{
int byte_len = (JS_GetStringLength(str)+1)*sizeof(jschar);
if(!(*((void**)d) = XPCMem::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;
}

View File

@ -0,0 +1,42 @@
/* -*- 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.
*/
/* Private forward declarations. */
#ifndef xpcforwards_h___
#define xpcforwards_h___
// forward declarations of interally used classes...
class XPCContext;
class nsXPConnect;
class JSObject2WrappedJSMap;
class Native2WrappedNativeMap;
class IID2WrappedJSClassMap;
class IID2WrappedNativeClassMap;
class JSContext2XPCContextMap;
class nsXPCWrappedJS;
class nsXPCWrappedNative;
class nsXPCWrappedJSClass;
class nsXPCWrappedNativeClass;
class nsXPCWrappedJSMethods;
class XPCJSThrower;
class XPCNativeMemberDescriptor;
#endif /* xpcforwards_h___ */

View File

@ -0,0 +1,483 @@
/* -*- 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...
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;
}
*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;
}
NS_IMETHODIMP
nsJSIID::toString(char **_retval)
{
return GetName(_retval);
}
/***************************************************************************/
// 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;
}
*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::toString(char **_retval)
{
return GetName(_retval);
}
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(nsIJSID::GetIID()) ||
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;
}

View File

@ -0,0 +1,95 @@
/* -*- 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.
*/
/* Debug Logging support. */
#include <stdarg.h>
#include <string.h>
#include "prprf.h"
#include "xpclog.h"
#ifdef DEBUG
#define SPACE_COUNT 200
#define LINE_LEN 200
#define INDENT_FACTOR 2
#define CAN_RUN (g_InitState == 1 || (g_InitState == 0 && Init()))
static char* g_Spaces;
static int g_InitState = 0;
static int g_Indent = 0;
static PRLogModuleInfo* g_LogMod = NULL;
static PRBool Init()
{
g_LogMod = PR_NewLogModule("xpclog");
g_Spaces = new char[SPACE_COUNT+1];
memset(g_Spaces, ' ', SPACE_COUNT);
g_Spaces[SPACE_COUNT] = 0;
if(!g_LogMod || !g_Spaces || !PR_LOG_TEST(g_LogMod,1))
{
g_InitState = -1;
return PR_FALSE;
}
g_InitState = 1;
return PR_TRUE;
}
XPC_PUBLIC_API(void)
XPC_Log_print(const char *fmt, ...)
{
va_list ap;
char line[LINE_LEN];
va_start(ap, fmt);
PR_vsnprintf(line, sizeof(line)-1, fmt, ap);
va_end(ap);
if(g_Indent)
PR_LogPrint("%s%s",g_Spaces+SPACE_COUNT-(INDENT_FACTOR*g_Indent),line);
else
PR_LogPrint("%s",line);
}
XPC_PUBLIC_API(PRBool)
XPC_Log_Check(int i)
{
return CAN_RUN && PR_LOG_TEST(g_LogMod,1);
}
XPC_PUBLIC_API(void)
XPC_Log_Indent()
{
if(INDENT_FACTOR*(++g_Indent) > SPACE_COUNT)
g_Indent-- ;
}
XPC_PUBLIC_API(void)
XPC_Log_Outdent()
{
if(--g_Indent < 0)
g_Indent++;
}
XPC_PUBLIC_API(void)
XPC_Log_Clear_Indent()
{
g_Indent = 0;
}
#endif

View File

@ -0,0 +1,187 @@
/* -*- 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.
*/
/* Private maps (hashtables). */
#include "xpcprivate.h"
/***************************************************************************/
// static shared...
JS_STATIC_DLL_CALLBACK(JSHashNumber)
hash_root(const void *key)
{
return ((JSHashNumber) key) >> 2; /* help lame MSVC1.5 on Win16 */
}
// XXX this is just the hacked String hash function, should do better...
JS_STATIC_DLL_CALLBACK(JSHashNumber)
hash_IID(const void *key)
{
JSHashNumber h;
const PRUint8 *s;
int i;
h = 0;
for (s = (const PRUint8 *)key, i = 0; i < 16; s++, i++)
h = (h >> 28) ^ (h << 4) ^ *s;
return h;
}
JS_STATIC_DLL_CALLBACK(intN)
compare_IIDs(const void *v1, const void *v2)
{
return ((const nsID*)v1)->Equals(*((const nsID*)v2));
}
/***************************************************************************/
// implement JSContext2XPCContextMap...
// static
JSContext2XPCContextMap*
JSContext2XPCContextMap::newMap(int size)
{
JSContext2XPCContextMap* map = new JSContext2XPCContextMap(size);
if(map && map->mHashtable)
return map;
delete map;
return NULL;
}
JSContext2XPCContextMap::JSContext2XPCContextMap(int size)
{
mHashtable = JS_NewHashTable(size, hash_root,
JS_CompareValues, JS_CompareValues,
NULL, NULL);
}
JSContext2XPCContextMap::~JSContext2XPCContextMap()
{
if(mHashtable)
JS_HashTableDestroy(mHashtable);
}
/***************************************************************************/
// implement JSObject2WrappedJSMap...
// static
JSObject2WrappedJSMap*
JSObject2WrappedJSMap::newMap(int size)
{
JSObject2WrappedJSMap* map = new JSObject2WrappedJSMap(size);
if(map && map->mHashtable)
return map;
delete map;
return NULL;
}
JSObject2WrappedJSMap::JSObject2WrappedJSMap(int size)
{
mHashtable = JS_NewHashTable(size, hash_root,
JS_CompareValues, JS_CompareValues,
NULL, NULL);
}
JSObject2WrappedJSMap::~JSObject2WrappedJSMap()
{
if(mHashtable)
JS_HashTableDestroy(mHashtable);
}
/***************************************************************************/
// implement Native2WrappedNativeMap...
// static
Native2WrappedNativeMap*
Native2WrappedNativeMap::newMap(int size)
{
Native2WrappedNativeMap* map = new Native2WrappedNativeMap(size);
if(map && map->mHashtable)
return map;
delete map;
return NULL;
}
Native2WrappedNativeMap::Native2WrappedNativeMap(int size)
{
mHashtable = JS_NewHashTable(size, hash_root,
JS_CompareValues, JS_CompareValues,
NULL, NULL);
}
Native2WrappedNativeMap::~Native2WrappedNativeMap()
{
if(mHashtable)
JS_HashTableDestroy(mHashtable);
}
/***************************************************************************/
// implement IID2WrappedJSClassMap...
// static
IID2WrappedJSClassMap*
IID2WrappedJSClassMap::newMap(int size)
{
IID2WrappedJSClassMap* map = new IID2WrappedJSClassMap(size);
if(map && map->mHashtable)
return map;
delete map;
return NULL;
}
IID2WrappedJSClassMap::IID2WrappedJSClassMap(int size)
{
mHashtable = JS_NewHashTable(size, hash_IID,
compare_IIDs, JS_CompareValues,
NULL, NULL);
}
IID2WrappedJSClassMap::~IID2WrappedJSClassMap()
{
if(mHashtable)
JS_HashTableDestroy(mHashtable);
}
/***************************************************************************/
// implement IID2WrappedJSClassMap...
// static
IID2WrappedNativeClassMap*
IID2WrappedNativeClassMap::newMap(int size)
{
IID2WrappedNativeClassMap* map = new IID2WrappedNativeClassMap(size);
if(map && map->mHashtable)
return map;
delete map;
return NULL;
}
IID2WrappedNativeClassMap::IID2WrappedNativeClassMap(int size)
{
mHashtable = JS_NewHashTable(size, hash_IID,
compare_IIDs, JS_CompareValues,
NULL, NULL);
}
IID2WrappedNativeClassMap::~IID2WrappedNativeClassMap()
{
if(mHashtable)
JS_HashTableDestroy(mHashtable);
}

View File

@ -0,0 +1,210 @@
/* -*- 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.
*/
/* Private maps (hashtables). */
#ifndef xpcmaps_h___
#define xpcmaps_h___
// Maps...
// no virtuals in the maps - all the common stuff inlined
// templates could be used to good effect here.
class JSContext2XPCContextMap
{
public:
static JSContext2XPCContextMap* newMap(int size);
inline XPCContext* Find(JSContext* cx)
{
NS_PRECONDITION(cx,"bad param");
return (XPCContext*) JS_HashTableLookup(mHashtable, cx);
}
inline void Add(XPCContext* xpcc)
{
NS_PRECONDITION(xpcc,"bad param");
JS_HashTableAdd(mHashtable, xpcc->GetJSContext(), xpcc);
}
inline void Remove(XPCContext* xpcc)
{
NS_PRECONDITION(xpcc,"bad param");
JS_HashTableRemove(mHashtable, xpcc->GetJSContext());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~JSContext2XPCContextMap();
private:
JSContext2XPCContextMap(); // no implementation
JSContext2XPCContextMap(int size);
private:
JSHashTable *mHashtable;
};
/*************************/
class JSObject2WrappedJSMap
{
public:
static JSObject2WrappedJSMap* newMap(int size);
inline nsXPCWrappedJS* Find(JSObject* Obj)
{
NS_PRECONDITION(Obj,"bad param");
return (nsXPCWrappedJS*) JS_HashTableLookup(mHashtable, Obj);
}
inline void Add(nsXPCWrappedJS* Wrapper)
{
NS_PRECONDITION(Wrapper,"bad param");
JS_HashTableAdd(mHashtable, Wrapper->GetJSObject(), Wrapper);
}
inline void Remove(nsXPCWrappedJS* Wrapper)
{
NS_PRECONDITION(Wrapper,"bad param");
JS_HashTableRemove(mHashtable, Wrapper->GetJSObject());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~JSObject2WrappedJSMap();
private:
JSObject2WrappedJSMap(); // no implementation
JSObject2WrappedJSMap(int size);
private:
JSHashTable *mHashtable;
};
/*************************/
class Native2WrappedNativeMap
{
public:
static Native2WrappedNativeMap* newMap(int size);
inline nsXPCWrappedNative* Find(nsISupports* Obj)
{
NS_PRECONDITION(Obj,"bad param");
return (nsXPCWrappedNative*) JS_HashTableLookup(mHashtable, Obj);
}
inline void Add(nsXPCWrappedNative* Wrapper)
{
NS_PRECONDITION(Wrapper,"bad param");
JS_HashTableAdd(mHashtable, Wrapper->GetNative(), Wrapper);
}
inline void Remove(nsXPCWrappedNative* Wrapper)
{
NS_PRECONDITION(Wrapper,"bad param");
JS_HashTableRemove(mHashtable, Wrapper->GetNative());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~Native2WrappedNativeMap();
private:
Native2WrappedNativeMap(); // no implementation
Native2WrappedNativeMap(int size);
private:
JSHashTable *mHashtable;
};
/*************************/
class IID2WrappedJSClassMap
{
public:
static IID2WrappedJSClassMap* newMap(int size);
inline nsXPCWrappedJSClass* Find(REFNSIID iid)
{
return (nsXPCWrappedJSClass*) JS_HashTableLookup(mHashtable, &iid);
}
inline void Add(nsXPCWrappedJSClass* Class)
{
NS_PRECONDITION(Class,"bad param");
JS_HashTableAdd(mHashtable, &Class->GetIID(), Class);
}
inline void Remove(nsXPCWrappedJSClass* Class)
{
NS_PRECONDITION(Class,"bad param");
JS_HashTableRemove(mHashtable, &Class->GetIID());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~IID2WrappedJSClassMap();
private:
IID2WrappedJSClassMap(); // no implementation
IID2WrappedJSClassMap(int size);
private:
JSHashTable *mHashtable;
};
/*************************/
class IID2WrappedNativeClassMap
{
public:
static IID2WrappedNativeClassMap* newMap(int size);
inline nsXPCWrappedNativeClass* Find(REFNSIID iid)
{
return (nsXPCWrappedNativeClass*) JS_HashTableLookup(mHashtable, &iid);
}
inline void Add(nsXPCWrappedNativeClass* Class)
{
NS_PRECONDITION(Class,"bad param");
JS_HashTableAdd(mHashtable, &Class->GetIID(), Class);
}
inline void Remove(nsXPCWrappedNativeClass* Class)
{
NS_PRECONDITION(Class,"bad param");
JS_HashTableRemove(mHashtable, &Class->GetIID());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~IID2WrappedNativeClassMap();
private:
IID2WrappedNativeClassMap(); // no implementation
IID2WrappedNativeClassMap(int size);
private:
JSHashTable *mHashtable;
};
#endif /* xpcmaps_h___ */

View File

@ -0,0 +1,204 @@
/* -*- 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 level methods. */
#include "xpcprivate.h"
/***************************************************************************/
class nsJSIIDFactory : public nsIFactory
{
public:
static REFNSCID GetCID() {static nsID cid = NS_JS_IID_CID; return cid;}
NS_DECL_ISUPPORTS;
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
nsJSIIDFactory();
virtual ~nsJSIIDFactory();
};
/********************************************/
static NS_DEFINE_IID(kJSIIDFactoryIID, NS_IFACTORY_IID);
NS_IMPL_ISUPPORTS(nsJSIIDFactory, kJSIIDFactoryIID);
NS_IMETHODIMP
nsJSIIDFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult)
{
if(!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = NULL;
if(aOuter)
return NS_ERROR_NO_INTERFACE;
if(aIID.Equals(nsISupports::GetIID()) ||
aIID.Equals(nsJSIID::GetIID()))
{
*aResult = new nsJSIID;
}
return *aResult ? NS_OK : NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsJSIIDFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
nsJSIIDFactory::nsJSIIDFactory()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
nsJSIIDFactory::~nsJSIIDFactory() {}
/***************************************************************************/
class nsJSCIDFactory : public nsIFactory
{
public:
static REFNSCID GetCID() {static nsID cid = NS_JS_CID_CID; return cid;}
NS_DECL_ISUPPORTS;
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
nsJSCIDFactory();
virtual ~nsJSCIDFactory();
};
/********************************************/
static NS_DEFINE_IID(kJSCIDFactoryIID, NS_IFACTORY_IID);
NS_IMPL_ISUPPORTS(nsJSCIDFactory, kJSCIDFactoryIID);
NS_IMETHODIMP
nsJSCIDFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult)
{
if(!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = NULL;
if(aOuter)
return NS_ERROR_NO_INTERFACE;
if(aIID.Equals(nsISupports::GetIID()) ||
aIID.Equals(nsJSCID::GetIID()))
{
*aResult = new nsJSCID;
}
return *aResult ? NS_OK : NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsJSCIDFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
nsJSCIDFactory::nsJSCIDFactory()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
nsJSCIDFactory::~nsJSCIDFactory() {}
/***************************************************************************/
#if defined(XP_MAC) && defined(MAC_STATIC)
extern "C" XPC_PUBLIC_API(nsresult)
NSGetFactory_XPCONNECT_DLL(nsISupports* servMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
#else
extern "C" XPC_PUBLIC_API(nsresult)
NSGetFactory(nsISupports* servMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
#endif
{
static nsJSIIDFactory iid_factory;
static nsJSCIDFactory cid_factory;
if(!aFactory)
return NS_ERROR_NULL_POINTER;
if(aClass.Equals(nsJSIIDFactory::GetCID()))
{
iid_factory.AddRef();
*aFactory = &iid_factory;
return NS_OK;
}
if(aClass.Equals(nsJSCIDFactory::GetCID()))
{
cid_factory.AddRef();
*aFactory = &cid_factory;
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
#ifdef XP_PC
#define XPCONNECT_DLL "xpc3250.dll"
#else
#ifdef XP_MAC
#define XPCONNECT_DLL "XPCONNECT_DLL"
#else
#define XPCONNECT_DLL "libxpconnect.so"
#endif
#endif
void
xpc_RegisterSelf()
{
nsComponentManager::RegisterComponent(nsJSIIDFactory::GetCID(),
"nsIJSIID",
"nsIID",
XPCONNECT_DLL,
PR_FALSE, PR_TRUE);
nsComponentManager::RegisterComponent(nsJSCIDFactory::GetCID(),
"nsIJSCID",
"nsCID",
XPCONNECT_DLL,
PR_FALSE, PR_TRUE);
}

View File

@ -0,0 +1,743 @@
/* -*- 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.
*/
/* All the XPConnect private declarations - only include locally. */
#ifndef xpcprivate_h___
#define xpcprivate_h___
#include <string.h>
#include <stdlib.h>
#include "nscore.h"
#include "nsISupports.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIAllocator.h"
#include "nsIXPConnect.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIXPCScriptable.h"
#include "xptcall.h"
#include "jsapi.h"
#include "jshash.h"
#include "jsprf.h"
#include "xpt_cpp.h"
#include "xpcforwards.h"
#include "xpclog.h"
#include "xpccomponents.h"
#include "xpcjsid.h"
extern const char* XPC_VAL_STR; // 'value' property name for out params
/***************************************************************************/
class nsXPConnect : public nsIXPConnect
{
// all the interface method declarations...
NS_DECL_ISUPPORTS;
NS_IMETHOD InitJSContext(JSContext* aJSContext,
JSObject* aGlobalJSObj);
NS_IMETHOD InitJSContextWithNewWrappedGlobal(JSContext* aJSContext,
nsISupports* aCOMObj,
REFNSIID aIID,
nsIXPConnectWrappedNative** aWrapper);
NS_IMETHOD WrapNative(JSContext* aJSContext,
nsISupports* aCOMObj,
REFNSIID aIID,
nsIXPConnectWrappedNative** aWrapper);
NS_IMETHOD WrapJS(JSContext* aJSContext,
JSObject* aJSObj,
REFNSIID aIID,
nsISupports** aWrapper);
NS_IMETHOD GetWrappedNativeOfJSObject(JSContext* aJSContext,
JSObject* aJSObj,
nsIXPConnectWrappedNative** aWrapper);
NS_IMETHOD DebugDump(int depth);
// non-interface implementation
public:
static nsXPConnect* GetXPConnect();
static nsIAllocator* GetAllocator(nsXPConnect* xpc = NULL);
static nsIInterfaceInfoManager* GetInterfaceInfoManager(nsXPConnect* xpc = NULL);
static XPCContext* GetContext(JSContext* cx, nsXPConnect* xpc = NULL);
static XPCJSThrower* GetJSThrower(nsXPConnect* xpc = NULL);
static JSBool IsISupportsDescendent(nsIInterfaceInfo* info);
JSContext2XPCContextMap* GetContextMap() {return mContextMap;}
nsIXPCScriptable* GetArbitraryScriptable() {return mArbitraryScriptable;}
virtual ~nsXPConnect();
private:
nsXPConnect();
XPCContext* NewContext(JSContext* cx, JSObject* global,
JSBool doInit = JS_TRUE);
private:
static nsXPConnect* mSelf;
JSContext2XPCContextMap* mContextMap;
nsIAllocator* mAllocator;
nsIXPCScriptable* mArbitraryScriptable;
nsIInterfaceInfoManager* mInterfaceInfoManager;
XPCJSThrower* mThrower;
};
/***************************************************************************/
// XPCContext is mostly a dumb class to hold JSContext specific data and
// maps that let us find wrappers created for the given JSContext.
// no virtuals
class XPCContext
{
public:
static XPCContext* newXPCContext(JSContext* aJSContext,
JSObject* aGlobalObj,
int WrappedJSMapSize,
int WrappedNativeMapSize,
int WrappedJSClassMapSize,
int WrappedNativeClassMapSize);
JSContext* GetJSContext() const {return mJSContext;}
JSObject* GetGlobalObject() const {return mGlobalObj;}
nsXPConnect* GetXPConnect() const {return mXPConnect;}
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);
virtual ~XPCContext();
private:
XPCContext(); // no implementation
XPCContext(JSContext* aJSContext,
JSObject* aGlobalObj,
int WrappedJSMapSize,
int WrappedNativeMapSize,
int WrappedJSClassMapSize,
int WrappedNativeClassMapSize);
private:
nsXPConnect* mXPConnect;
JSContext* mJSContext;
JSObject* mGlobalObj;
JSObject2WrappedJSMap* mWrappedJSMap;
Native2WrappedNativeMap* mWrappedNativeMap;
IID2WrappedJSClassMap* mWrappedJSClassMap;
IID2WrappedNativeClassMap* mWrappedNativeClassMap;
jsid mConstuctorStrID;
jsid mToStringStrID;
};
/***************************************************************************/
// code for throwing exceptions into JS
struct XPCJSErrorFormatString
{
const char *format;
/* uintN argCount; */
};
struct XPCJSError
{
enum {
#define MSG_DEF(name, number, count, exception, format) \
name = number,
#include "xpc.msg"
#undef MSG_DEF
LIMIT
};
};
class XPCJSThrower
{
public:
void ThrowBadResultException(JSContext* cx,
nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc,
nsresult result);
void ThrowBadParamException(uintN errNum,
JSContext* cx,
nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc,
uintN paramNum);
void ThrowException(uintN errNum,
JSContext* cx,
nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc);
XPCJSThrower(JSBool Verbose = JS_FALSE);
~XPCJSThrower();
private:
void Verbosify(nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc,
char** psz, PRBool own);
private:
static XPCJSErrorFormatString default_formats[XPCJSError::LIMIT+1];
XPCJSErrorFormatString* mFormats;
JSBool mVerbose;
};
/***************************************************************************/
// this interfaces exists so we can refcount nsXPCWrappedJSClass
// {2453EBA0-A9B8-11d2-BA64-00805F8A5DD7}
#define NS_IXPCONNECT_WRAPPED_JS_CLASS_IID \
{ 0x2453eba0, 0xa9b8, 0x11d2, \
{ 0xba, 0x64, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class nsIXPCWrappedJSClass : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_JS_CLASS_IID)
NS_IMETHOD DebugDump(int depth) = 0;
};
/*************************/
class nsXPCWrappedJSClass : public nsIXPCWrappedJSClass
{
// all the interface method declarations...
NS_DECL_ISUPPORTS;
NS_IMETHOD DebugDump(int depth);
public:
static nsXPCWrappedJSClass* GetNewOrUsedClass(XPCContext* xpcc,
REFNSIID aIID);
REFNSIID GetIID() const {return mIID;}
XPCContext* GetXPCContext() const {return mXPCContext;}
nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;}
static JSBool InitForContext(XPCContext* xpcc);
static JSBool IsWrappedJS(nsISupports* aPtr);
NS_IMETHOD DelegatedQueryInterface(nsXPCWrappedJS* self, REFNSIID aIID,
void** aInstancePtr);
JSObject* GetRootJSObject(JSObject* aJSObj);
NS_IMETHOD CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params);
virtual ~nsXPCWrappedJSClass();
private:
nsXPCWrappedJSClass(); // not implemented
nsXPCWrappedJSClass(XPCContext* xpcc, REFNSIID aIID,
nsIInterfaceInfo* aInfo);
JSContext* GetJSContext() const {return mXPCContext->GetJSContext();}
JSObject* CreateIIDJSObject(REFNSIID aIID);
JSObject* NewOutObject();
JSObject* CallQueryInterfaceOnJSObject(JSObject* jsobj, REFNSIID aIID);
JSBool IsReflectable(uint16 i) const
{return mDescriptors[i/32] & (1 << (i%32));}
void SetReflectable(uint16 i, JSBool b)
{if(b) mDescriptors[i/32] |= (1 << (i%32));
else mDescriptors[i/32] &= ~(1 << (i%32));}
private:
XPCContext* mXPCContext;
nsIInterfaceInfo* mInfo;
nsIID mIID;
uint32* mDescriptors;
};
/*************************/
class nsXPCWrappedJS : public nsXPTCStubBase
{
public:
NS_DECL_ISUPPORTS;
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params);
static nsXPCWrappedJS* GetNewOrUsedWrapper(XPCContext* xpcc,
JSObject* aJSObj,
REFNSIID aIID);
JSObject* GetJSObject() const {return mJSObj;}
nsXPCWrappedJSClass* GetClass() const {return mClass;}
REFNSIID GetIID() const {return GetClass()->GetIID();}
nsXPCWrappedJS* GetRootWrapper() const {return mRoot;}
void DebugDump(int depth);
virtual ~nsXPCWrappedJS();
private:
nsXPCWrappedJS(); // not implemented
nsXPCWrappedJS(JSObject* aJSObj,
nsXPCWrappedJSClass* aClass,
nsXPCWrappedJS* root);
nsXPCWrappedJS* Find(REFNSIID aIID);
private:
JSObject* mJSObj;
nsXPCWrappedJSClass* mClass;
nsXPCWrappedJSMethods* mMethods;
nsXPCWrappedJS* mRoot;
nsXPCWrappedJS* mNext;
};
class nsXPCWrappedJSMethods : public nsIXPConnectWrappedJSMethods
{
public:
NS_DECL_ISUPPORTS;
NS_IMETHOD GetJSObject(JSObject** aJSObj);
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
NS_IMETHOD DebugDump(int depth);
nsXPCWrappedJSMethods(nsXPCWrappedJS* aWrapper);
virtual ~nsXPCWrappedJSMethods();
// used in nsXPCWrappedJS::DebugDump
int GetRefCnt() const {return mRefCnt;}
private:
nsXPCWrappedJSMethods(); // not implemented
private:
nsXPCWrappedJS* mWrapper;
};
/***************************************************************************/
// nsXPCWrappedNativeClass maintains an array of these things
class XPCNativeMemberDescriptor
{
private:
enum {
// these are all bitwise flags!
NMD_CONSTANT = 0x0, // categories...
NMD_METHOD = 0x1,
NMD_ATTRIB_RO = 0x2,
NMD_ATTRIB_RW = 0x3,
NMD_CAT_MASK = 0x3, // & mask for the categories above
// any new bits start at 0x04
};
public:
JSObject* invokeFuncObj;
jsid id; /* hashed name for quick JS property lookup */
uintN index; /* in InterfaceInfo for const, method, and get */
uintN index2; /* in InterfaceInfo for set */
private:
uint16 flags;
public:
JSBool IsConstant() const {return (flags & NMD_CAT_MASK) == NMD_CONSTANT;}
JSBool IsMethod() const {return (flags & NMD_CAT_MASK) == NMD_METHOD;}
JSBool IsAttribute() const {return (JSBool)((flags & NMD_CAT_MASK) & NMD_ATTRIB_RO);}
JSBool IsWritableAttribute() const {return (flags & NMD_CAT_MASK) == NMD_ATTRIB_RW;}
JSBool IsReadOnlyAttribute() const {return (flags & NMD_CAT_MASK) == NMD_ATTRIB_RO;}
void SetConstant() {flags=(flags&~NMD_CAT_MASK)|NMD_CONSTANT;}
void SetMethod() {flags=(flags&~NMD_CAT_MASK)|NMD_METHOD;}
void SetReadOnlyAttribute() {flags=(flags&~NMD_CAT_MASK)|NMD_ATTRIB_RO;}
void SetWritableAttribute() {flags=(flags&~NMD_CAT_MASK)|NMD_ATTRIB_RW;}
XPCNativeMemberDescriptor();
};
/*************************/
// this interfaces exists just so we can refcount nsXPCWrappedNativeClass
// {C9E36280-954A-11d2-BA5A-00805F8A5DD7}
#define NS_IXPCONNECT_WRAPPED_NATIVE_CLASS_IID \
{ 0xc9e36280, 0x954a, 0x11d2, \
{ 0xba, 0x5a, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class nsIXPCWrappedNativeClass : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_NATIVE_CLASS_IID)
NS_IMETHOD DebugDump(int depth) = 0;
};
/*************************/
class nsXPCWrappedNativeClass : public nsIXPCWrappedNativeClass
{
// all the interface method declarations...
NS_DECL_ISUPPORTS;
NS_IMETHOD DebugDump(int depth);
public:
static nsXPCWrappedNativeClass* GetNewOrUsedClass(XPCContext* xpcc,
REFNSIID aIID);
REFNSIID GetIID() const {return mIID;}
const char* GetInterfaceName();
const char* GetMemberName(const XPCNativeMemberDescriptor* desc) const;
nsIInterfaceInfo* GetInterfaceInfo() const {return mInfo;}
XPCContext* GetXPCContext() const {return mXPCContext;}
JSContext* GetJSContext() const {return mXPCContext->GetJSContext();}
nsIXPCScriptable* GetArbitraryScriptable() const
{return GetXPCContext()->GetXPConnect()->GetArbitraryScriptable();}
static JSBool InitForContext(XPCContext* xpcc);
static JSBool OneTimeInit();
JSObject* NewInstanceJSObject(nsXPCWrappedNative* self);
static nsXPCWrappedNative* GetWrappedNativeOfJSObject(JSContext* cx,
JSObject* jsobj);
int GetMemberCount() const {return mMemberCount;}
const XPCNativeMemberDescriptor* GetMemberDescriptor(uint16 i) const
{
NS_PRECONDITION(i < mMemberCount,"bad index");
return &mDescriptors[i];
}
const XPCNativeMemberDescriptor* LookupMemberByID(jsid id) const;
JSBool GetConstantAsJSVal(JSContext* cx,
nsXPCWrappedNative* wrapper,
const XPCNativeMemberDescriptor* desc,
jsval* vp);
JSBool CallWrappedMethod(JSContext* cx,
nsXPCWrappedNative* wrapper,
const XPCNativeMemberDescriptor* desc,
JSBool isAttributeSet,
uintN argc, jsval *argv, jsval *vp);
JSBool GetAttributeAsJSVal(JSContext* cx,
nsXPCWrappedNative* wrapper,
const XPCNativeMemberDescriptor* desc,
jsval* vp)
{
return CallWrappedMethod(cx, wrapper, desc, JS_FALSE, 0, NULL, vp);
}
JSBool SetAttributeFromJSVal(JSContext* cx,
nsXPCWrappedNative* wrapper,
const XPCNativeMemberDescriptor* desc,
jsval* vp)
{
return CallWrappedMethod(cx, wrapper, desc, JS_TRUE, 1, vp, NULL);
}
JSObject* GetInvokeFunObj(const XPCNativeMemberDescriptor* desc);
JSBool DynamicEnumerate(nsXPCWrappedNative* wrapper,
nsIXPCScriptable* ds,
JSContext *cx, JSObject *obj,
JSIterateOp enum_op,
jsval *statep, jsid *idp);
JSBool StaticEnumerate(nsXPCWrappedNative* wrapper,
JSIterateOp enum_op,
jsval *statep, jsid *idp);
virtual ~nsXPCWrappedNativeClass();
private:
nsXPCWrappedNativeClass(); // not implemented
nsXPCWrappedNativeClass(XPCContext* xpcc, REFNSIID aIID,
nsIInterfaceInfo* aInfo);
void ThrowBadResultException(JSContext* cx,
const XPCNativeMemberDescriptor* desc,
nsresult result)
{nsXPConnect::GetJSThrower()->
ThrowBadResultException(cx, this, desc, result);}
void ThrowBadParamException(uintN errNum,
JSContext* cx,
const XPCNativeMemberDescriptor* desc,
uintN paramNum)
{nsXPConnect::GetJSThrower()->
ThrowBadParamException(errNum, cx, this, desc, paramNum);}
void ThrowException(uintN errNum,
JSContext* cx,
const XPCNativeMemberDescriptor* desc)
{nsXPConnect::GetJSThrower()->
ThrowException(errNum, cx, this, desc);}
JSBool BuildMemberDescriptors();
void DestroyMemberDescriptors();
private:
XPCContext* mXPCContext;
nsIID mIID;
char* mName;
nsIInterfaceInfo* mInfo;
int mMemberCount;
XPCNativeMemberDescriptor* mDescriptors;
};
/*************************/
class nsXPCWrappedNative : public nsIXPConnectWrappedNative
{
// all the interface method declarations...
NS_DECL_ISUPPORTS;
NS_IMETHOD GetDynamicScriptable(nsIXPCScriptable** p);
NS_IMETHOD GetArbitraryScriptable(nsIXPCScriptable** p);
NS_IMETHOD GetJSObject(JSObject** aJSObj);
NS_IMETHOD GetNative(nsISupports** aObj);
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
NS_IMETHOD DebugDump(int depth);
public:
static nsXPCWrappedNative* GetNewOrUsedWrapper(XPCContext* xpcc,
nsISupports* aObj,
REFNSIID aIID);
nsISupports* GetNative() const {return mObj;}
JSObject* GetJSObject() const {return mJSObj;}
nsXPCWrappedNativeClass* GetClass() const {return mClass;}
REFNSIID GetIID() const {return GetClass()->GetIID();}
nsIXPCScriptable* GetDynamicScriptable() const
{return mRoot->mDynamicScriptable;}
nsIXPCScriptable* GetArbitraryScriptable() const
{return GetClass()->GetArbitraryScriptable();}
void JSObjectFinalized(JSContext *cx, JSObject *obj);
virtual ~nsXPCWrappedNative();
private:
nsXPCWrappedNative(); // not implemented
nsXPCWrappedNative(nsISupports* aObj,
nsXPCWrappedNativeClass* aClass,
nsXPCWrappedNative* root);
nsXPCWrappedNative* Find(REFNSIID aIID);
private:
nsISupports* mObj;
JSObject* mJSObj;
nsXPCWrappedNativeClass* mClass;
nsIXPCScriptable* mDynamicScriptable; // only set in root!
nsXPCWrappedNative* mRoot;
nsXPCWrappedNative* mNext;
};
/***************************************************************************/
class nsXPCArbitraryScriptable : public nsIXPCScriptable
{
public:
// all the interface method declarations...
NS_DECL_ISUPPORTS;
XPC_DECLARE_IXPCSCRIPTABLE;
public:
nsXPCArbitraryScriptable();
};
/***************************************************************************/
// data convertion
// class here just for static methods
class XPCConvert
{
public:
static JSBool IsMethodReflectable(const nsXPTMethodInfo& info);
static JSBool NativeData2JS(JSContext* cx, jsval* d, const void* s,
const nsXPTType& type, const nsID* iid,
uintN* pErr);
static JSBool JSData2Native(JSContext* cx, void* d, jsval s,
const nsXPTType& type,
JSBool useAllocator, const nsID* iid,
uintN* pErr);
private:
XPCConvert(); // not implemented
};
/***************************************************************************/
// allocator access methods
// class here just for static methods
class XPCMem
{
public:
static void* Alloc(PRUint32 size);
static void* Realloc(void* ptr, PRUint32 size);
static void Free(void* ptr);
static void HeapMinimize();
static void* Clone(const void* ptr, PRUint32 size);
private:
XPCMem(); // not implemented
static nsIAllocator* Allocator();
};
/***************************************************************************/
// nsJSIID
class nsJSIID : public nsIJSIID
{
public:
NS_DECL_ISUPPORTS;
/* readonly attribute string name; */
NS_IMETHOD GetName(char * *aName);
/* readonly attribute string number; */
NS_IMETHOD GetNumber(char * *aNumber);
/* readonly attribute nsID id; */
NS_IMETHOD GetId(nsID* *aId);
/* readonly attribute boolean valid; */
NS_IMETHOD GetValid(PRBool *aValid);
/* boolean equals (in nsIJSID other); */
NS_IMETHOD equals(nsIJSID *other, PRBool *_retval);
/* boolean init (in string idString); */
NS_IMETHOD init(const char *idString, PRBool *_retval);
/* string toString (); */
NS_IMETHOD toString(char **_retval);
nsJSIID();
virtual ~nsJSIID();
static nsJSIID* NewID(const char* str);
private:
void reset();
void setName(const char* name);
private:
nsID mID;
char* mNumber;
char* mName;
};
/***************************************************************************/
// nsJSCID
class nsJSCID : public nsIJSCID
{
public:
NS_DECL_ISUPPORTS;
/* readonly attribute string name; */
NS_IMETHOD GetName(char * *aName);
/* readonly attribute string number; */
NS_IMETHOD GetNumber(char * *aNumber);
/* readonly attribute nsID id; */
NS_IMETHOD GetId(nsID* *aId);
/* readonly attribute boolean valid; */
NS_IMETHOD GetValid(PRBool *aValid);
/* boolean equals (in nsIJSID other); */
NS_IMETHOD equals(nsIJSID *other, PRBool *_retval);
/* boolean init (in string idString); */
NS_IMETHOD init(const char *idString, PRBool *_retval);
/* nsISupports newInstance (); */
NS_IMETHOD newInstance(nsISupports **_retval);
/* string toString (); */
NS_IMETHOD toString(char **_retval);
nsJSCID();
virtual ~nsJSCID();
static nsJSCID* NewID(const char* str);
private:
void reset();
void setName(const char* name);
private:
nsID mID;
char* mNumber;
char* mName;
};
JSObject*
xpc_NewIIDObject(JSContext *cx, const nsID& aID);
nsID*
xpc_JSObjectToID(JSContext *cx, JSObject* obj);
/***************************************************************************/
// 'Components' objects
class nsXPCInterfaces;
class nsXPCClasses;
class nsXPCComponents : public nsIXPCComponents
{
public:
NS_DECL_ISUPPORTS;
/* readonly attribute nsIXPCInterfaces interfaces; */
NS_IMETHOD GetInterfaces(nsIXPCInterfaces * *aInterfaces);
/* readonly attribute nsIXPCClasses classes; */
NS_IMETHOD GetClasses(nsIXPCClasses * *aClasses);
nsXPCComponents();
virtual ~nsXPCComponents();
private:
nsXPCInterfaces* mInterfaces;
nsXPCClasses* mClasses;
};
/***************************************************************************/
// module level stuff
void
xpc_RegisterSelf();
/***************************************************************************/
// the include of declarations of the maps comes last because they have
// inlines which call methods on classes above.
#include "xpcmaps.h"
#endif /* xpcprivate_h___ */

View File

@ -0,0 +1,142 @@
/* -*- 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.
*/
/* Code for throwing errors into JavaScript. */
#include "xpcprivate.h"
XPCJSErrorFormatString XPCJSThrower::default_formats[] = {
#define MSG_DEF(name, number, count, exception, format) \
{ format/*, count*/ } ,
#include "xpc.msg"
#undef MSG_DEF
{ NULL/*, 0*/ }
};
XPCJSThrower::XPCJSThrower(JSBool Verbose /*= JS_FALSE*/)
: mFormats(default_formats), mVerbose(Verbose) {}
XPCJSThrower::~XPCJSThrower() {}
void
XPCJSThrower::Verbosify(nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc,
char** psz, PRBool own)
{
char* sz = NULL;
if(clazz && desc)
sz = JS_smprintf("%s [%s.%s]",
*psz,
clazz->GetInterfaceName(),
clazz->GetMemberName(desc));
if(sz)
{
if(own)
JS_smprintf_free(*psz);
*psz = sz;
}
}
void
XPCJSThrower::ThrowBadResultException(JSContext* cx,
nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc,
nsresult result)
{
char* sz;
const char* format;
JSString* str = NULL;
format = mFormats[XPCJSError::NATIVE_RETURNED_FAILURE].format;
sz = JS_smprintf("%s %x", format, result);
if(sz && mVerbose)
Verbosify(clazz, desc, &sz, PR_TRUE);
if(sz)
{
str = JS_NewStringCopyZ(cx, sz);
JS_smprintf_free(sz);
}
if(str)
JS_SetPendingException(cx, STRING_TO_JSVAL(str));
else
JS_ReportOutOfMemory(cx);
}
void
XPCJSThrower::ThrowBadParamException(uintN errNum,
JSContext* cx,
nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc,
uintN paramNum)
{
char* sz;
const char* format;
JSString* str = NULL;
format = mFormats[errNum].format;
sz = JS_smprintf("%s arg %d", format, paramNum);
if(sz && mVerbose)
Verbosify(clazz, desc, &sz, PR_TRUE);
if(sz)
{
str = JS_NewStringCopyZ(cx, sz);
JS_smprintf_free(sz);
}
if(str)
JS_SetPendingException(cx, STRING_TO_JSVAL(str));
else
JS_ReportOutOfMemory(cx);
}
void
XPCJSThrower::ThrowException(uintN errNum,
JSContext* cx,
nsXPCWrappedNativeClass* clazz,
const XPCNativeMemberDescriptor* desc)
{
char* sz;
const char* format;
JSString* str = NULL;
format = mFormats[errNum].format;
sz = (char*) format;
if(sz && mVerbose)
Verbosify(clazz, desc, &sz, PR_FALSE);
if(sz)
{
str = JS_NewStringCopyZ(cx, sz);
if(sz != format)
JS_smprintf_free(sz);
}
if(str)
JS_SetPendingException(cx, STRING_TO_JSVAL(str));
else
JS_ReportOutOfMemory(cx);
}

View File

@ -0,0 +1,55 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Module local methods to use 'standard' interfaces in other modules. */
#include "xpcprivate.h"
// all these methods are class statics
nsIAllocator* XPCMem::Allocator()
{
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
static nsIAllocator* al = NULL;
if(!al)
nsServiceManager::GetService(kAllocatorCID, kIAllocatorIID,
(nsISupports **)&al);
NS_ASSERTION(al, "failed to get Allocator!");
return al;
}
void* XPCMem::Alloc(PRUint32 size)
{return Allocator()->Alloc(size);}
void* XPCMem::Realloc(void* ptr, PRUint32 size)
{return Allocator()->Realloc(ptr, size);}
void XPCMem::Free(void* ptr)
{Allocator()->Free(ptr);}
void XPCMem::HeapMinimize()
{Allocator()->HeapMinimize();}
void* XPCMem::Clone(const void* ptr, PRUint32 size)
{
if(!ptr) return NULL;
void* p = Allocator()->Alloc(size);
if(p) memcpy(p, ptr, size);
return p;
}

View File

@ -0,0 +1,393 @@
/* -*- 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.
*/
/* Class that wraps JS objects to appear as XPCOM objects. */
#include "xpcprivate.h"
// NOTE: much of the fancy footwork is done in xpcstubs.cpp
NS_IMETHODIMP
nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if(NULL == aInstancePtr)
{
NS_PRECONDITION(0, "null pointer");
return NS_ERROR_NULL_POINTER;
}
if(aIID.Equals(nsIXPConnectWrappedJSMethods::GetIID()))
{
if(!mMethods && !(mMethods = new nsXPCWrappedJSMethods(this)))
{
*aInstancePtr = NULL;
return NS_ERROR_OUT_OF_MEMORY;
}
// intentional second addref
NS_ADDREF(mMethods);
*aInstancePtr = (void*) mMethods;
return NS_OK;
}
return mClass->DelegatedQueryInterface(this, aIID, aInstancePtr);
}
// do chained ref counting
nsrefcnt
nsXPCWrappedJS::AddRef(void)
{
NS_PRECONDITION(mRoot, "bad root");
if(1 == ++mRefCnt && mRoot && mRoot != this)
NS_ADDREF(mRoot);
return mRefCnt;
}
nsrefcnt
nsXPCWrappedJS::Release(void)
{
NS_PRECONDITION(mRoot, "bad root");
NS_PRECONDITION(0 != mRefCnt, "dup release");
if(0 == --mRefCnt)
{
if(mRoot == this)
{
NS_DELETEXPCOM(this); // cascaded delete
}
else
{
mRoot->Release();
}
return 0;
}
return mRefCnt;
}
// static
nsXPCWrappedJS*
nsXPCWrappedJS::GetNewOrUsedWrapper(XPCContext* xpcc,
JSObject* aJSObj,
REFNSIID aIID)
{
JSObject2WrappedJSMap* map;
JSObject* rootJSObj;
nsXPCWrappedJS* root;
nsXPCWrappedJS* wrapper = NULL;
nsXPCWrappedJSClass* clazz = NULL;
NS_PRECONDITION(xpcc, "bad param");
NS_PRECONDITION(aJSObj, "bad param");
map = xpcc->GetWrappedJSMap();
if(!map)
{
NS_ASSERTION(map,"bad map");
return NULL;
}
clazz = nsXPCWrappedJSClass::GetNewOrUsedClass(xpcc, aIID);
if(!clazz)
return NULL;
// from here on we need to return through 'return_wrapper'
// always find the root JSObject
rootJSObj = clazz->GetRootJSObject(aJSObj);
if(!rootJSObj)
goto return_wrapper;
// look for the root wrapper
root = map->Find(rootJSObj);
if(root)
{
wrapper = root->Find(aIID);
if(wrapper)
{
NS_ADDREF(wrapper);
goto return_wrapper;
}
}
else
{
// build the root wrapper
if(rootJSObj == aJSObj)
{
// the root will do double duty as the interface wrapper
wrapper = root = new nsXPCWrappedJS(aJSObj, clazz, NULL);
if(root)
map->Add(root);
goto return_wrapper;
}
else
{
// just a root wrapper
nsXPCWrappedJSClass* rootClazz;
rootClazz = nsXPCWrappedJSClass::GetNewOrUsedClass(
xpcc, nsISupports::GetIID());
if(!rootClazz)
goto return_wrapper;
root = new nsXPCWrappedJS(rootJSObj, rootClazz, NULL);
NS_RELEASE(rootClazz);
if(!root)
goto return_wrapper;
map->Add(root);
}
}
// at this point we have a root and may need to build the specific wrapper
NS_ASSERTION(root,"bad root");
NS_ASSERTION(clazz,"bad clazz");
if(!wrapper)
{
wrapper = new nsXPCWrappedJS(aJSObj, clazz, root);
if(!wrapper)
goto return_wrapper;
}
wrapper->mNext = root->mNext;
root->mNext = wrapper;
return_wrapper:
if(clazz)
NS_RELEASE(clazz);
return wrapper;
}
#ifdef WIN32
#pragma warning(disable : 4355) // OK to pass "this" in member initializer
#endif
nsXPCWrappedJS::nsXPCWrappedJS(JSObject* aJSObj,
nsXPCWrappedJSClass* aClass,
nsXPCWrappedJS* root)
: mJSObj(aJSObj),
mClass(aClass),
mMethods(NULL),
mRoot(root ? root : this),
mNext(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
NS_ADDREF(aClass);
JS_AddRoot(mClass->GetXPCContext()->GetJSContext(), &mJSObj);
}
nsXPCWrappedJS::~nsXPCWrappedJS()
{
NS_PRECONDITION(0 == mRefCnt, "refcounting error");
if(mRoot == this && GetClass())
{
XPCContext* xpcc = GetClass()->GetXPCContext();
if(xpcc)
{
JSObject2WrappedJSMap* map;
map = xpcc->GetWrappedJSMap();
if(map)
map->Remove(this);
}
}
JS_RemoveRoot(mClass->GetXPCContext()->GetJSContext(), &mJSObj);
NS_RELEASE(mClass);
if(mMethods)
NS_RELEASE(mMethods);
if(mNext)
NS_DELETEXPCOM(mNext); // cascaded delete
}
nsXPCWrappedJS*
nsXPCWrappedJS::Find(REFNSIID aIID)
{
if(aIID.Equals(nsISupports::GetIID()))
return mRoot;
nsXPCWrappedJS* cur = mRoot;
do
{
if(aIID.Equals(GetIID()))
return cur;
} while(NULL != (cur = cur->mNext));
return NULL;
}
NS_IMETHODIMP
nsXPCWrappedJS::GetInterfaceInfo(nsIInterfaceInfo** info)
{
NS_ASSERTION(GetClass(), "wrapper without class");
NS_ASSERTION(GetClass()->GetInterfaceInfo(), "wrapper class without interface");
if(!(*info = GetClass()->GetInterfaceInfo()))
return NS_ERROR_UNEXPECTED;
NS_ADDREF(*info);
return NS_OK;
}
NS_IMETHODIMP
nsXPCWrappedJS::CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params)
{
return GetClass()->CallMethod(this, methodIndex, info, params);
}
/***************************************************************************/
NS_IMETHODIMP
nsXPCWrappedJSMethods::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
NS_PRECONDITION(mWrapper, "bad state");
return mWrapper->QueryInterface(aIID, aInstancePtr);
}
// maintain a weak link to the wrapper
nsrefcnt
nsXPCWrappedJSMethods::AddRef(void)
{
NS_PRECONDITION(mWrapper, "bad state");
if(2 == ++mRefCnt)
NS_ADDREF(mWrapper);
return mRefCnt;
}
nsrefcnt
nsXPCWrappedJSMethods::Release(void)
{
NS_PRECONDITION(mWrapper, "bad state");
if(0 == --mRefCnt)
{
NS_DELETEXPCOM(this);
return 0;
}
else if(1 == mRefCnt)
mWrapper->Release(); // do NOT zero out the ptr (weak ref)
return mRefCnt;
}
nsXPCWrappedJSMethods::nsXPCWrappedJSMethods(nsXPCWrappedJS* aWrapper)
: mWrapper(aWrapper)
{
NS_PRECONDITION(mWrapper, "bad param");
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
nsXPCWrappedJSMethods::~nsXPCWrappedJSMethods()
{
NS_ASSERTION(0 == mRefCnt, "recounting error");
}
/***************************************/
NS_IMETHODIMP
nsXPCWrappedJSMethods::GetJSObject(JSObject** aJSObj)
{
NS_PRECONDITION(mWrapper, "bad state");
NS_PRECONDITION(aJSObj,"bad param");
if(!(*aJSObj = mWrapper->GetJSObject()))
return NS_ERROR_UNEXPECTED;
return NS_OK;
}
NS_IMETHODIMP
nsXPCWrappedJSMethods::GetInterfaceInfo(nsIInterfaceInfo** info)
{
NS_PRECONDITION(mWrapper, "bad state");
NS_PRECONDITION(info, "bad param");
NS_PRECONDITION(mWrapper->GetClass(), "bad wrapper");
NS_PRECONDITION(mWrapper->GetClass()->GetInterfaceInfo(), "bad wrapper");
if(!(*info = mWrapper->GetClass()->GetInterfaceInfo()))
return NS_ERROR_UNEXPECTED;
NS_ADDREF(*info);
return NS_OK;
}
NS_IMETHODIMP
nsXPCWrappedJSMethods::GetIID(nsIID** iid)
{
NS_PRECONDITION(mWrapper, "bad state");
NS_PRECONDITION(iid, "bad param");
*iid = (nsIID*) XPCMem::Clone(&mWrapper->GetIID(), sizeof(nsIID));
return *iid ? NS_OK : NS_ERROR_UNEXPECTED;
}
/***************************************************************************/
NS_IMETHODIMP
nsXPCWrappedJSMethods::DebugDump(int depth)
{
#ifdef DEBUG
XPC_LOG_ALWAYS(("nsXPCWrappedJSMethods @ %x with mRefCnt = %d for...", \
this, mRefCnt));
XPC_LOG_INDENT();
mWrapper->DebugDump(depth);
XPC_LOG_OUTDENT();
#endif
return NS_OK;
}
void
nsXPCWrappedJS::DebugDump(int depth)
{
#ifdef DEBUG
XPC_LOG_ALWAYS(("nsXPCWrappedJS @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
PRBool isRoot = mRoot == this;
XPC_LOG_ALWAYS(("%s wrapper around JSObject @ %x", \
isRoot ? "ROOT":"non-root", mJSObj));
char* name;
GetClass()->GetInterfaceInfo()->GetName(&name);
XPC_LOG_ALWAYS(("interface name is %s", name));
if(name)
XPCMem::Free(name);
char * iid = GetClass()->GetIID().ToString();
XPC_LOG_ALWAYS(("IID number is %s", iid));
delete iid;
XPC_LOG_ALWAYS(("nsXPCWrappedJSClass @ %x", mClass));
if(mMethods)
XPC_LOG_ALWAYS(("mMethods @ %x with mRefCnt = %d", \
mMethods, mMethods->GetRefCnt()));
else
XPC_LOG_ALWAYS(("NO mMethods object"));
if(!isRoot)
XPC_LOG_OUTDENT();
if(mNext)
{
if(isRoot)
{
XPC_LOG_ALWAYS(("Additional wrappers for this object..."));
XPC_LOG_INDENT();
}
mNext->DebugDump(depth);
if(isRoot)
XPC_LOG_OUTDENT();
}
if(isRoot)
XPC_LOG_OUTDENT();
#endif
}

View File

@ -0,0 +1,602 @@
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xpcprivate.h"
static const char* XPC_QUERY_INTERFACE_STR = "QueryInterface";
static NS_DEFINE_IID(kWrappedJSClassIID, NS_IXPCONNECT_WRAPPED_JS_CLASS_IID);
NS_IMPL_ISUPPORTS(nsXPCWrappedJSClass, kWrappedJSClassIID)
static uint32 zero_methods_descriptor;
// static
nsXPCWrappedJSClass*
nsXPCWrappedJSClass::GetNewOrUsedClass(XPCContext* xpcc,
REFNSIID aIID)
{
IID2WrappedJSClassMap* map;
nsXPCWrappedJSClass* clazz = NULL;
NS_PRECONDITION(xpcc, "bad param");
map = xpcc->GetWrappedJSClassMap();
NS_ASSERTION(map,"bad map");
clazz = map->Find(aIID);
if(clazz)
{
NS_ADDREF(clazz);
}
else
{
nsIInterfaceInfoManager* iimgr;
if(NULL != (iimgr = nsXPConnect::GetInterfaceInfoManager()))
{
nsIInterfaceInfo* info;
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
{
if(nsXPConnect::IsISupportsDescendent(info))
{
clazz = new nsXPCWrappedJSClass(xpcc, aIID, info);
if(!clazz->mDescriptors)
NS_RELEASE(clazz); // sets clazz to NULL
}
NS_RELEASE(info);
}
NS_RELEASE(iimgr);
}
}
return clazz;
}
nsXPCWrappedJSClass::nsXPCWrappedJSClass(XPCContext* xpcc, REFNSIID aIID,
nsIInterfaceInfo* aInfo)
: mXPCContext(xpcc),
mInfo(aInfo),
mIID(aIID),
mDescriptors(NULL)
{
NS_ADDREF(mInfo);
NS_INIT_REFCNT();
NS_ADDREF_THIS();
mXPCContext->GetWrappedJSClassMap()->Add(this);
uint16 methodCount;
if(NS_SUCCEEDED(mInfo->GetMethodCount(&methodCount)))
{
if(methodCount)
{
int wordCount = (methodCount/32)+1;
if(NULL != (mDescriptors = new uint32[wordCount]))
{
int i;
// init flags to 0;
for(i = wordCount-1; i >= 0; i--)
mDescriptors[i] = 0;
for(i = 0; i < methodCount; i++)
{
const nsXPTMethodInfo* info;
if(NS_SUCCEEDED(mInfo->GetMethodInfo(i, &info)))
SetReflectable(i, XPCConvert::IsMethodReflectable(*info));
else
{
delete [] mDescriptors;
mDescriptors = NULL;
break;
}
}
}
}
else
{
mDescriptors = &zero_methods_descriptor;
}
}
}
nsXPCWrappedJSClass::~nsXPCWrappedJSClass()
{
if(mDescriptors && mDescriptors != &zero_methods_descriptor)
delete [] mDescriptors;
mXPCContext->GetWrappedJSClassMap()->Remove(this);
NS_RELEASE(mInfo);
}
/***************************************************************************/
// XXX for now IIDs are represented in JS as string objects containing strings
// of the form: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} (just like the nsID
// Parse and ToString methods use.
// XXX lots of room for optimization here!
// JSObject*
// nsXPCWrappedJSClass::CreateIIDJSObject(REFNSIID aIID)
// {
// JSObject* obj = NULL;
// char* str = aIID.ToString();
// if(str)
// {
// JSContext* cx = GetJSContext();
// JSString* jsstr = JS_InternString(cx, str);
// delete [] str;
// if(jsstr)
// JS_ValueToObject(cx, STRING_TO_JSVAL(jsstr), &obj);
// }
// return obj;
// }
JSObject*
nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSObject* jsobj, REFNSIID aIID)
{
JSContext* cx = GetJSContext();
JSObject* id;
jsval retval;
JSObject* retObj;
JSBool success = JS_FALSE;
// id = CreateIIDJSObject(aIID);
id = xpc_NewIIDObject(cx, aIID);
if(id)
{
JSErrorReporter older = JS_SetErrorReporter(cx, NULL);
jsval args[1] = {OBJECT_TO_JSVAL(id)};
success = JS_CallFunctionName(cx, jsobj, XPC_QUERY_INTERFACE_STR,
1, args, &retval);
if(success)
success = JS_ValueToObject(cx, retval, &retObj);
JS_SetErrorReporter(cx, older);
}
return success ? retObj : NULL;
}
/***************************************************************************/
// This 'WrappedJSIdentity' class and singleton allow us to figure out if
// any given nsISupports* is implemented by a WrappedJS object. This is done
// using a QueryInterface call on the interface pointer with our ID. If
// that call returns NS_OK and the pointer is to our singleton, then the
// interface must be implemented by a WrappedJS object. NOTE: the
// 'WrappedJSIdentity' object is not a real XPCOM object and should not be
// used for anything else (hence it is declared in this implementation file).
// {5C5C3BB0-A9BA-11d2-BA64-00805F8A5DD7}
#define NS_IXPCONNECT_WRAPPED_JS_IDENTITY_CLASS_IID \
{ 0x5c5c3bb0, 0xa9ba, 0x11d2, \
{ 0xba, 0x64, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class WrappedJSIdentity
{
// no instance methods...
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_JS_IDENTITY_CLASS_IID)
static void* GetSingleton()
{
static WrappedJSIdentity* singleton = NULL;
if(!singleton)
singleton = new WrappedJSIdentity();
return (void*) singleton;
}
};
/***************************************************************************/
// static
JSBool
nsXPCWrappedJSClass::IsWrappedJS(nsISupports* aPtr)
{
void* result;
NS_PRECONDITION(aPtr, "null pointer");
return aPtr &&
NS_OK == aPtr->QueryInterface(WrappedJSIdentity::GetIID(), &result) &&
result == WrappedJSIdentity::GetSingleton();
}
NS_IMETHODIMP
nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
REFNSIID aIID,
void** aInstancePtr)
{
if(aIID.Equals(nsISupports::GetIID()))
{
nsXPCWrappedJS* root = self->GetRootWrapper();
*aInstancePtr = (void*) root;
NS_ADDREF(root);
return NS_OK;
}
else if(aIID.Equals(self->GetIID()))
{
*aInstancePtr = (void*) self;
NS_ADDREF(self);
return NS_OK;
}
else if(aIID.Equals(WrappedJSIdentity::GetIID()))
{
*aInstancePtr = WrappedJSIdentity::GetSingleton();
return NS_OK;
}
else
{
JSObject* jsobj =
CallQueryInterfaceOnJSObject(self->GetJSObject(), aIID);
if(jsobj)
{
nsXPCWrappedJS* wrapper =
nsXPCWrappedJS::GetNewOrUsedWrapper(GetXPCContext(),
jsobj, aIID);
if(wrapper)
{
*aInstancePtr = (void*) wrapper;
return NS_OK;
}
}
}
*aInstancePtr = NULL;
return NS_NOINTERFACE;
}
JSObject*
nsXPCWrappedJSClass::GetRootJSObject(JSObject* aJSObj)
{
JSObject* result = CallQueryInterfaceOnJSObject(aJSObj, nsISupports::GetIID());
return result ? result : aJSObj;
}
NS_IMETHODIMP
nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params)
{
#define ARGS_BUFFER_COUNT 16
jsval argsBuffer[ARGS_BUFFER_COUNT];
jsval* argv = NULL;
uint8 i;
uint8 argc=0;
jsval result;
uint8 paramCount=0;
nsresult retval = NS_ERROR_FAILURE;
JSErrorReporter older;
JSBool success;
JSContext* cx = GetJSContext();
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(!IsReflectable(methodIndex))
goto pre_call_clean_up;
// setup argv
if(argc > ARGS_BUFFER_COUNT)
{
if(!(argv = new jsval[argc]))
{
retval = NS_ERROR_OUT_OF_MEMORY;
goto pre_call_clean_up;
}
}
else
argv = argsBuffer;
// build the args
for(i = 0; i < argc; i++)
{
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
jsval val;
if(param.IsIn())
{
nsXPTCMiniVariant* pv;
if(param.IsOut())
pv = (nsXPTCMiniVariant*) params[i].val.p;
else
pv = &params[i];
if(type.TagPart() == nsXPTType::T_INTERFACE)
{
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(&param, &conditional_iid)))
{
goto pre_call_clean_up;
}
iidIsOwned = JS_TRUE;
}
else if(type.TagPart() == nsXPTType::T_INTERFACE_IS)
{
uint8 arg_num = param.GetInterfaceIsArgNumber();
const nsXPTParamInfo& param = info->GetParam(arg_num);
const nsXPTType& type = param.GetType();
if(type.IsPointer() && type.TagPart() == nsXPTType::T_IID)
{
if(param.IsOut())
conditional_iid = *((nsID**)params[arg_num].val.p);
else
conditional_iid = (nsID*) params[arg_num].val.p;
}
if(!conditional_iid)
goto pre_call_clean_up;
}
if(!XPCConvert::NativeData2JS(cx, &val, &pv->val, type,
conditional_iid, NULL))
{
goto pre_call_clean_up;
}
if(conditional_iid)
{
if(iidIsOwned)
{
XPCMem::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = NULL;
}
}
if(param.IsOut())
{
// create an 'out' object
JSObject* obj = NewOutObject();
if(param.IsIn())
{
if(!JS_SetProperty(cx, obj, XPC_VAL_STR, &val))
goto pre_call_clean_up;
}
argv[i] = OBJECT_TO_JSVAL(obj);
}
else
argv[i] = val;
}
InConversionsDone = JS_TRUE;
pre_call_clean_up:
// clean up any 'out' params handed in
for(i = 0; i < paramCount; i++)
{
const nsXPTParamInfo& param = info->GetParam(i);
if(!param.IsOut())
continue;
const nsXPTType& type = param.GetType();
if(!type.IsPointer())
continue;
if(!params[i].val.p)
continue;
if(type.IsInterfacePointer())
{
if(param.IsIn())
{
nsISupports** pp;
if((NULL != (pp = (nsISupports**) params[i].val.p)) &&
NULL != *pp)
{
(*pp)->Release();
*pp = NULL;
}
}
}
else
{
void** pp;
if((NULL != (pp = (void**) params[i].val.p)) && NULL != *pp)
{
if(param.IsIn())
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;
// do the function call - set the error reporter aside - note exceptions
older = JS_SetErrorReporter(cx, NULL);
JS_ClearPendingException(cx);
success = JS_CallFunctionName(cx, wrapper->GetJSObject(), info->GetName(),
argc, argv, &result);
if(JS_IsExceptionPending(cx))
{
JS_ClearPendingException(cx);
success = JS_FALSE;
}
JS_SetErrorReporter(cx, older);
if(!success)
goto done;
// convert out args and result
// NOTE: this is the total number of native params, not just the args
for(i = 0; i < paramCount; i++)
{
const nsXPTParamInfo& param = info->GetParam(i);
if(param.IsOut())
{
jsval val;
JSBool useAllocator = JS_FALSE;
const nsXPTType& type = param.GetType();
nsXPTCMiniVariant* pv;
pv = (nsXPTCMiniVariant*) params[i].val.p;
if(param.IsRetval())
val = result;
else if(!JS_GetProperty(cx, JSVAL_TO_OBJECT(argv[i]), XPC_VAL_STR, &val))
break;
// setup allocator and/or iid
if(type.TagPart() == nsXPTType::T_INTERFACE)
{
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(&param, &conditional_iid)))
{
break;
}
iidIsOwned = JS_TRUE;
}
else if(type.TagPart() == nsXPTType::T_INTERFACE_IS)
{
uint8 arg_num = param.GetInterfaceIsArgNumber();
const nsXPTParamInfo& param = info->GetParam(arg_num);
const nsXPTType& type = param.GetType();
if(!type.IsPointer() || type.TagPart() != nsXPTType::T_IID ||
!(conditional_iid = *((nsID**)params[arg_num].val.p)))
break;
}
else if(type.IsPointer())
useAllocator = JS_TRUE;
if(!XPCConvert::JSData2Native(cx, &pv->val, val, type,
useAllocator, conditional_iid, NULL))
break;
if(conditional_iid)
{
if(iidIsOwned)
{
XPCMem::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = NULL;
}
}
}
// if we didn't manage all the result conversions then we have
// to cleanup any junk that *did* get converted.
if(i != paramCount)
{
// XXX major spaghetti!
InConversionsDone = JS_FALSE;
goto pre_call_clean_up;
}
retval = NS_OK;
done:
if(argv && argv != argsBuffer)
delete [] argv;
if(conditional_iid && iidIsOwned)
XPCMem::Free((void*)conditional_iid);
return retval;
}
static JSClass WrappedJSOutArg_class = {
"XPCOutArg", 0,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
// static
JSBool
nsXPCWrappedJSClass::InitForContext(XPCContext* xpcc)
{
if (!JS_InitClass(xpcc->GetJSContext(), xpcc->GetGlobalObject(),
0, &WrappedJSOutArg_class, 0, 0,
0, 0,
0, 0))
return JS_FALSE;
return JS_TRUE;
}
JSObject*
nsXPCWrappedJSClass::NewOutObject()
{
return JS_NewObject(GetJSContext(), &WrappedJSOutArg_class, NULL, NULL);
}
NS_IMETHODIMP
nsXPCWrappedJSClass::DebugDump(int depth)
{
#ifdef DEBUG
depth-- ;
XPC_LOG_ALWAYS(("nsXPCWrappedJSClass @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
char* name;
mInfo->GetName(&name);
XPC_LOG_ALWAYS(("interface name is %s", name));
if(name)
XPCMem::Free(name);
char * iid = mIID.ToString();
XPC_LOG_ALWAYS(("IID number is %s", iid));
delete iid;
XPC_LOG_ALWAYS(("InterfaceInfo @ %x", mInfo));
uint16 methodCount = 0;
if(depth)
{
uint16 i;
nsIInterfaceInfo* parent;
XPC_LOG_INDENT();
mInfo->GetParent(&parent);
XPC_LOG_ALWAYS(("parent @ %x", parent));
mInfo->GetMethodCount(&methodCount);
XPC_LOG_ALWAYS(("MethodCount = %d", methodCount));
mInfo->GetConstantCount(&i);
XPC_LOG_ALWAYS(("ConstantCount = %d", i));
XPC_LOG_OUTDENT();
}
XPC_LOG_ALWAYS(("mXPCContext @ %x", mXPCContext));
XPC_LOG_ALWAYS(("JSContext @ %x", GetJSContext()));
XPC_LOG_ALWAYS(("mDescriptors @ %x count = %d", mDescriptors, methodCount));
if(depth && mDescriptors && methodCount)
{
depth--;
XPC_LOG_INDENT();
for(uint16 i = 0; i < methodCount; i++)
{
XPC_LOG_ALWAYS(("Method %d is %s%s", \
i, IsReflectable(i) ? "":" NOT ","reflectable"));
}
XPC_LOG_OUTDENT();
depth++;
}
XPC_LOG_OUTDENT();
#endif
return NS_OK;
}

View File

@ -0,0 +1,411 @@
/* -*- 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.
*/
/* Class that wraps each native interface instance. */
#include "xpcprivate.h"
static NS_DEFINE_IID(kWrappedNativeIID, NS_IXPCONNECT_WRAPPED_NATIVE_IID);
NS_IMPL_QUERY_INTERFACE(nsXPCWrappedNative, kWrappedNativeIID)
// do chained ref counting
nsrefcnt
nsXPCWrappedNative::AddRef(void)
{
NS_PRECONDITION(mRoot, "bad root");
if(1 == ++mRefCnt && mRoot != this)
NS_ADDREF(mRoot);
else if(2 == mRefCnt)
JS_AddRoot(mClass->GetXPCContext()->GetJSContext(), &mJSObj);
// XPC_LOG_DEBUG(("+++ AddRef of %x with mJSObj %x and mRefCnt = %d",this,mJSObj, mRefCnt));
return mRefCnt;
}
nsrefcnt
nsXPCWrappedNative::Release(void)
{
NS_PRECONDITION(mRoot, "bad root");
NS_PRECONDITION(0 != mRefCnt, "dup release");
if(0 == --mRefCnt)
{
// XPC_LOG_DEBUG(("--- Delete of wrapper %x with mJSObj %x and mRefCnt = %d",this,mJSObj, mRefCnt));
NS_DELETEXPCOM(this); // also unlinks us from chain
return 0;
}
if(1 == mRefCnt)
{
// XPC_LOG_DEBUG(("--- Removing root of %x with mJSObj %x and mRefCnt = %d",this,mJSObj, mRefCnt));
JS_RemoveRoot(mClass->GetXPCContext()->GetJSContext(), &mJSObj);
}
// XPC_LOG_DEBUG(("--- Release of %x with mJSObj %x and mRefCnt = %d",this,mJSObj, mRefCnt));
return mRefCnt;
}
void
nsXPCWrappedNative::JSObjectFinalized(JSContext *cx, JSObject *obj)
{
NS_PRECONDITION(1 == mRefCnt, "bad JSObject finalization");
nsIXPCScriptable* ds;
if(NULL != (ds = GetDynamicScriptable()))
ds->Finalize(cx, obj, this, GetArbitraryScriptable());
// pass through to the real JSObject finalization code
JS_FinalizeStub(cx, obj);
mJSObj = NULL;
Release();
}
// static
nsXPCWrappedNative*
nsXPCWrappedNative::GetNewOrUsedWrapper(XPCContext* xpcc,
nsISupports* aObj,
REFNSIID aIID)
{
Native2WrappedNativeMap* map;
nsISupports* rootObj = NULL;
nsXPCWrappedNative* root;
nsXPCWrappedNative* wrapper = NULL;
nsXPCWrappedNativeClass* clazz = NULL;
NS_PRECONDITION(xpcc, "bad param");
NS_PRECONDITION(aObj, "bad param");
map = xpcc->GetWrappedNativeMap();
if(!map)
{
NS_ASSERTION(map,"bad map");
return NULL;
}
// always find the native root
if(NS_FAILED(aObj->QueryInterface(nsISupports::GetIID(), (void**)&rootObj)))
return NULL;
// look for the root wrapper
root = map->Find(rootObj);
if(root)
{
wrapper = root->Find(aIID);
if(wrapper)
{
NS_ADDREF(wrapper);
goto return_wrapper;
}
}
clazz = nsXPCWrappedNativeClass::GetNewOrUsedClass(xpcc, aIID);
if(!clazz)
goto return_wrapper;
// build the root wrapper
if(!root)
{
if(rootObj == aObj)
{
// the root will do double duty as the interface wrapper
wrapper = root = new nsXPCWrappedNative(aObj, clazz, NULL);
if(!wrapper)
goto return_wrapper;
if(!wrapper->mJSObj)
{
NS_RELEASE(wrapper); // sets wrapper to NULL
goto return_wrapper;
}
map->Add(root);
goto return_wrapper;
}
else
{
// just a root wrapper
nsXPCWrappedNativeClass* rootClazz;
rootClazz = nsXPCWrappedNativeClass::GetNewOrUsedClass(
xpcc, nsISupports::GetIID());
if(!rootClazz)
goto return_wrapper;
root = new nsXPCWrappedNative(rootObj, rootClazz, NULL);
NS_RELEASE(rootClazz);
if(!root)
goto return_wrapper;
if(!root->mJSObj)
{
NS_RELEASE(root); // sets root to NULL
goto return_wrapper;
}
map->Add(root);
}
}
// at this point we have a root and may need to build the specific wrapper
NS_ASSERTION(root,"bad root");
NS_ASSERTION(clazz,"bad clazz");
if(!wrapper)
{
wrapper = new nsXPCWrappedNative(aObj, clazz, root);
if(!wrapper)
goto return_wrapper;
if(!wrapper->mJSObj)
{
NS_RELEASE(wrapper); // sets wrapper to NULL
goto return_wrapper;
}
}
wrapper->mNext = root->mNext;
root->mNext = wrapper;
return_wrapper:
if(rootObj)
NS_RELEASE(rootObj);
if(clazz)
NS_RELEASE(clazz);
return wrapper;
}
#ifdef WIN32
#pragma warning(disable : 4355) // OK to pass "this" in member initializer
#endif
nsXPCWrappedNative::nsXPCWrappedNative(nsISupports* aObj,
nsXPCWrappedNativeClass* aClass,
nsXPCWrappedNative* root)
: mObj(aObj),
mJSObj(NULL),
mClass(aClass),
mDynamicScriptable(NULL),
mRoot(root ? root : this),
mNext(NULL)
{
NS_PRECONDITION(mObj, "bad object to wrap");
NS_PRECONDITION(mClass, "bad class for wrapper");
NS_INIT_REFCNT();
NS_ADDREF_THIS();
NS_ADDREF(aClass);
NS_ADDREF(aObj);
if(mRoot == this)
{
nsIXPCScriptable* ds;
if(NS_SUCCEEDED(mObj->QueryInterface(nsIXPCScriptable::GetIID(),
(void**)&ds)))
mDynamicScriptable = ds;
}
mJSObj = aClass->NewInstanceJSObject(this);
if(mJSObj)
{
// intentional second addref to be released when mJSObj is gc'd
NS_ADDREF_THIS();
nsIXPCScriptable* ds;
if(NULL != (ds = GetDynamicScriptable()))
ds->Create(GetClass()->GetXPCContext()->GetJSContext(),
GetJSObject(), this, GetArbitraryScriptable());
}
}
nsXPCWrappedNative::~nsXPCWrappedNative()
{
NS_PRECONDITION(0 == mRefCnt, "refcounting error");
NS_ASSERTION(mRoot, "wrapper without root deleted");
if(mRoot != this)
{
// unlink this wrapper
nsXPCWrappedNative* cur = mRoot;
while(1)
{
if(cur->mNext == this)
{
cur->mNext = mNext;
break;
}
cur = cur->mNext;
NS_ASSERTION(cur, "failed to find wrapper in its own chain");
}
// let the root go
NS_RELEASE(mRoot);
}
else
{
// remove this root wrapper from the map
NS_ASSERTION(!mNext, "root wrapper with non-empty chain being deleted");
nsXPCWrappedNativeClass* clazz;
XPCContext* xpcc;
Native2WrappedNativeMap* map;
if(NULL != (clazz = GetClass()) &&
NULL != (xpcc = clazz->GetXPCContext())&&
NULL != (map = xpcc->GetWrappedNativeMap()))
{
map->Remove(this);
}
}
if(mDynamicScriptable)
NS_RELEASE(mDynamicScriptable);
if(mClass)
NS_RELEASE(mClass);
if(mObj)
NS_RELEASE(mObj);
}
nsXPCWrappedNative*
nsXPCWrappedNative::Find(REFNSIID aIID)
{
if(aIID.Equals(nsISupports::GetIID()))
return mRoot;
nsXPCWrappedNative* cur = mRoot;
do
{
if(aIID.Equals(GetIID()))
return cur;
} while(NULL != (cur = cur->mNext));
return NULL;
}
/***************************************************************************/
NS_IMETHODIMP
nsXPCWrappedNative::GetArbitraryScriptable(nsIXPCScriptable** p)
{
NS_PRECONDITION(p, "bad param");
nsIXPCScriptable* s = GetArbitraryScriptable();
if(s)
{
NS_ADDREF(s);
*p = s;
return NS_OK;
}
// else...
*p = NULL;
return NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsXPCWrappedNative::GetDynamicScriptable(nsIXPCScriptable** p)
{
NS_PRECONDITION(p, "bad param");
nsIXPCScriptable* s = GetDynamicScriptable();
if(s)
{
NS_ADDREF(s);
*p = s;
return NS_OK;
}
// else...
*p = NULL;
return NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsXPCWrappedNative::GetJSObject(JSObject** aJSObj)
{
NS_PRECONDITION(aJSObj, "bad param");
NS_PRECONDITION(mJSObj, "bad wrapper");
if(!(*aJSObj = mJSObj))
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsXPCWrappedNative::GetNative(nsISupports** aObj)
{
NS_PRECONDITION(aObj, "bad param");
NS_PRECONDITION(mObj, "bad wrapper");
if(!(*aObj = mObj))
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mObj);
return NS_OK;
}
NS_IMETHODIMP
nsXPCWrappedNative::GetInterfaceInfo(nsIInterfaceInfo** info)
{
NS_PRECONDITION(info, "bad param");
NS_PRECONDITION(GetClass(), "bad wrapper");
NS_PRECONDITION(GetClass()->GetInterfaceInfo(), "bad wrapper");
if(!(*info = GetClass()->GetInterfaceInfo()))
return NS_ERROR_UNEXPECTED;
NS_ADDREF(*info);
return NS_OK;
}
NS_IMETHODIMP
nsXPCWrappedNative::GetIID(nsIID** iid)
{
NS_PRECONDITION(iid, "bad param");
*iid = (nsIID*) XPCMem::Clone(&GetIID(), sizeof(nsIID));
return *iid ? NS_OK : NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsXPCWrappedNative::DebugDump(int depth)
{
#ifdef DEBUG
depth-- ;
XPC_LOG_ALWAYS(("nsXPCWrappedNative @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
PRBool isRoot = mRoot == this;
XPC_LOG_ALWAYS(("%s wrapper around native @ %x", \
isRoot ? "ROOT":"non-root", mObj));
XPC_LOG_ALWAYS(("interface name is %s", GetClass()->GetInterfaceName()));
char * iid = GetClass()->GetIID().ToString();
XPC_LOG_ALWAYS(("IID number is %s", iid));
delete iid;
XPC_LOG_ALWAYS(("JSObject @ %x", mJSObj));
XPC_LOG_ALWAYS(("nsXPCWrappedNativeClass @ %x", mClass));
if(GetDynamicScriptable())
XPC_LOG_ALWAYS(("DynamicScriptable @ %x", GetDynamicScriptable()));
else
XPC_LOG_ALWAYS(("NO DynamicScriptable"));
if(!isRoot)
XPC_LOG_OUTDENT();
if(mNext)
{
if(isRoot)
{
XPC_LOG_ALWAYS(("Additional wrappers for this object..."));
XPC_LOG_INDENT();
}
mNext->DebugDump(depth);
if(isRoot)
XPC_LOG_OUTDENT();
}
if(isRoot)
XPC_LOG_OUTDENT();
#endif
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
Makefile
mk.bat
TestXPC

View File

@ -0,0 +1,71 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = TestXPC
CPPSRCS = \
TestXPC.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk
DEFINES += -DJS_THREADSAFE -DJSFILE
LDFLAGS = \
-L$(DIST)/bin \
-l$(MOZ_LIB_JS_PREFIX)js \
-lxpcom \
-lxpconnect \
-lxpt \
-lxptinfo \
-lxptcall \
-lxptcmd \
-lreg \
-l$(MOZ_LIB_UTIL_PREFIX)util \
$(NSPR_LIBS) \
$(NULL)
PROGS = $(OBJDIR)/TestXPC
TEST_FILES = testxpc.js
TARGETS= $(PROGS)
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(PUBLIC)/xpcom -I$(PUBLIC)/js -I$(PUBLIC)/xpconnect \
-I$(PUBLIC)/raptor
#$(PROGS): $(OBJS)
# @$(MAKE_OBJDIR)
# $(CC) -o $@ $(OBJS) $(LD_FLAGS) -L$(DIST)/lib $(LIBS) $(OS_LIBS)
export:: $(TARGETS)
$(INSTALL) $(PROGS) $(DIST)/bin
$(INSTALL) $(TEST_FILES) $(DIST)/bin
clobber::
rm -f $(DIST)/bin/TestXPC
rm -f $(PROGS) $(OBJS)

View File

@ -0,0 +1,716 @@
/* -*- 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.
*/
/* Tests for XPConnect - hacked together while deveolpment continues. */
#include <stdio.h>
#include "nsIXPConnect.h"
#include "nsIXPCScriptable.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIXPCScriptable.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "jsapi.h"
#include "xpclog.h"
#include "nscore.h"
#include "xpctest.h"
#include "nsIAllocator.h"
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
#ifdef XP_PC
#define XPCOM_DLL "xpcom32.dll"
#else
#ifdef XP_MAC
#define XPCOM_DLL "XPCOM_DLL"
#else
#define XPCOM_DLL "libxpcom.so"
#endif
#endif
static void RegAllocator()
{
nsComponentManager::RegisterComponent(kAllocatorCID, NULL, NULL, XPCOM_DLL,
PR_FALSE, PR_FALSE);
}
/***************************************************************************/
class MyScriptable : public nsIXPCScriptable
{
NS_DECL_ISUPPORTS;
XPC_DECLARE_IXPCSCRIPTABLE;
MyScriptable();
};
MyScriptable::MyScriptable()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
static NS_DEFINE_IID(kMyScriptableIID, NS_IXPCSCRIPTABLE_IID);
NS_IMPL_ISUPPORTS(MyScriptable, kMyScriptableIID);
// XPC_IMPLEMENT_FORWARD_IXPCSCRIPTABLE(MyScriptable);
XPC_IMPLEMENT_FORWARD_CREATE(MyScriptable);
XPC_IMPLEMENT_FORWARD_LOOKUPPROPERTY(MyScriptable);
XPC_IMPLEMENT_FORWARD_DEFINEPROPERTY(MyScriptable);
XPC_IMPLEMENT_FORWARD_GETPROPERTY(MyScriptable);
XPC_IMPLEMENT_FORWARD_SETPROPERTY(MyScriptable);
XPC_IMPLEMENT_FORWARD_GETATTRIBUTES(MyScriptable);
XPC_IMPLEMENT_FORWARD_SETATTRIBUTES(MyScriptable);
XPC_IMPLEMENT_FORWARD_DELETEPROPERTY(MyScriptable);
// XPC_IMPLEMENT_FORWARD_DEFAULTVALUE(MyScriptable);
XPC_IMPLEMENT_FORWARD_ENUMERATE(MyScriptable);
XPC_IMPLEMENT_FORWARD_CHECKACCESS(MyScriptable);
XPC_IMPLEMENT_FORWARD_CALL(MyScriptable);
XPC_IMPLEMENT_FORWARD_CONSTRUCT(MyScriptable);
XPC_IMPLEMENT_FORWARD_FINALIZE(MyScriptable);
NS_IMETHODIMP
MyScriptable::DefaultValue(JSContext *cx, JSObject *obj,
JSType type, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
if(type == JSTYPE_STRING || type == JSTYPE_VOID)
{
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, "obj with MyScriptable"));
*retval = JS_TRUE;
return NS_OK;
}
return arbitrary->DefaultValue(cx, obj, type, vp, wrapper, NULL, retval);
}
/***************************************************************************/
class nsTestXPCFoo : public nsITestXPCFoo2
{
NS_DECL_ISUPPORTS;
NS_IMETHOD Test(int p1, int p2, int* retval);
NS_IMETHOD Test2();
nsTestXPCFoo();
};
NS_IMETHODIMP nsTestXPCFoo::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(nsITestXPCFoo::GetIID()) ||
aIID.Equals(nsITestXPCFoo2::GetIID()) ||
aIID.Equals(nsISupports::GetIID())) {
*aInstancePtr = (void*) this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXPCScriptable::GetIID())) {
*aInstancePtr = (void*) new MyScriptable();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP nsTestXPCFoo::Test(int p1, int p2, int* retval)
{
printf("nsTestXPCFoo::Test called with p1 = %d and p2 = %d\n", p1, p2);
*retval = p1+p2;
return NS_OK;
}
NS_IMETHODIMP nsTestXPCFoo::Test2()
{
printf("nsTestXPCFoo::Test2 called\n");
return NS_OK;
}
NS_IMPL_ADDREF(nsTestXPCFoo)
NS_IMPL_RELEASE(nsTestXPCFoo)
nsTestXPCFoo::nsTestXPCFoo()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
/***************************************************************************/
class MyEcho : public nsIEcho
{
public:
NS_DECL_ISUPPORTS;
NS_IMETHOD SetReciever(nsIEcho* aReciever);
NS_IMETHOD SendOneString(const char* str);
NS_IMETHOD In2OutOneInt(int input, int* output);
NS_IMETHOD In2OutAddTwoInts(int input1,
int input2,
int* output1,
int* output2,
int* result);
NS_IMETHOD In2OutOneString(const char* input, char** output);
NS_IMETHOD SimpleCallNoEcho();
NS_IMETHOD SendManyTypes(PRUint8 p1,
PRInt16 p2,
PRInt32 p3,
PRInt64 p4,
PRUint8 p5,
PRUint16 p6,
PRUint32 p7,
PRUint64 p8,
float p9,
double p10,
PRBool p11,
char p12,
PRUint16 p13,
nsID* p14,
const char* p15,
const PRUnichar* p16);
NS_IMETHOD SendInOutManyTypes(PRUint8* p1,
PRInt16* p2,
PRInt32* p3,
PRInt64* p4,
PRUint8* p5,
PRUint16* p6,
PRUint32* p7,
PRUint64* p8,
float* p9,
double* p10,
PRBool* p11,
char* p12,
PRUint16* p13,
nsID** p14,
char** p15,
PRUint16** p16);
NS_IMETHOD MethodWithNative(int p1, void* p2);
NS_IMETHOD ReturnCode(int code);
NS_IMETHOD FailInJSTest(int fail);
MyEcho();
private:
nsIEcho* mReciever;
nsIAllocator* mAllocator;
};
static NS_DEFINE_IID(kMyEchoIID, NS_IECHO_IID);
NS_IMPL_ISUPPORTS(MyEcho, kMyEchoIID);
MyEcho::MyEcho()
: mReciever(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
nsServiceManager::GetService(kAllocatorCID,
kIAllocatorIID,
(nsISupports **)&mAllocator);
}
NS_IMETHODIMP MyEcho::SetReciever(nsIEcho* aReciever)
{
if(mReciever)
NS_RELEASE(mReciever);
mReciever = aReciever;
if(mReciever)
NS_ADDREF(mReciever);
return NS_OK;
}
NS_IMETHODIMP MyEcho::SendOneString(const char* str)
{
if(mReciever)
return mReciever->SendOneString(str);
return NS_OK;
}
NS_IMETHODIMP MyEcho::In2OutOneInt(int input, int* output)
{
*output = input;
return NS_OK;
}
NS_IMETHODIMP MyEcho::In2OutAddTwoInts(int input1,
int input2,
int* output1,
int* output2,
int* result)
{
*output1 = input1;
*output2 = input2;
*result = input1+input2;
return NS_OK;
}
NS_IMETHODIMP MyEcho::In2OutOneString(const char* input, char** output)
{
char* p;
int len;
if(input && output && mAllocator &&
(NULL != (p = (char*)mAllocator->Alloc(len=strlen(input)+1))))
{
memcpy(p, input, len);
*output = p;
return NS_OK;
}
if(output)
*output = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP MyEcho::SimpleCallNoEcho()
{
return NS_OK;
}
NS_IMETHODIMP
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,
p10, p11, p12, p13, p14, p15, p16);
return NS_OK;
}
NS_IMETHODIMP
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,
PRUint16* p13,
nsID** p14,
char** p15,
PRUint16** p16)
{
if(mReciever)
return mReciever->SendInOutManyTypes(p1, p2, p3, p4, p5, p6, p7, p8, p9,
p10, p11, p12, p13, p14, p15, p16);
return NS_OK;
}
NS_IMETHODIMP
MyEcho::MethodWithNative(int p1, void* p2)
{
return NS_OK;
}
NS_IMETHODIMP
MyEcho::ReturnCode(int code)
{
return (nsresult) code;
}
NS_IMETHODIMP
MyEcho::FailInJSTest(int fail)
{
if(mReciever)
return mReciever->FailInJSTest(fail);
return NS_OK;
}
/***************************************************************************/
FILE *gOutFile = NULL;
FILE *gErrFile = NULL;
static JSBool
Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
uintN i, n;
JSString *str;
for (i = n = 0; i < argc; i++) {
str = JS_ValueToString(cx, argv[i]);
if (!str)
return JS_FALSE;
fprintf(gOutFile, "%s%s", i ? " " : "", JS_GetStringBytes(str));
}
n++;
if (n)
fputc('\n', gOutFile);
return JS_TRUE;
}
static JSBool
Load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
uintN i;
JSString *str;
const char *filename;
JSScript *script;
JSBool ok;
jsval result;
for (i = 0; i < argc; i++) {
str = JS_ValueToString(cx, argv[i]);
if (!str)
return JS_FALSE;
argv[i] = STRING_TO_JSVAL(str);
filename = JS_GetStringBytes(str);
script = JS_CompileFile(cx, obj, filename);
if (!script)
ok = JS_FALSE;
else {
ok = JS_ExecuteScript(cx, obj, script, &result);
JS_DestroyScript(cx, script);
}
if (!ok)
return JS_FALSE;
}
return JS_TRUE;
}
static JSFunctionSpec glob_functions[] = {
{"print", Print, 0},
{"load", Load, 1},
{0}
};
static JSClass global_class = {
"global", 0,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static void
my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
{
printf(message);
}
extern "C" JS_FRIEND_DATA(FILE *) js_DumpGCHeap;
int main()
{
JSRuntime *rt;
JSContext *jscontext;
JSObject *glob;
gErrFile = stderr;
gOutFile = stdout;
RegAllocator();
rt = JS_NewRuntime(8L * 1024L * 1024L);
if (!rt)
return 1;
jscontext = JS_NewContext(rt, 8192);
if (!jscontext)
return 1;
JS_SetErrorReporter(jscontext, my_ErrorReporter);
nsIXPConnect* xpc = XPC_GetXPConnect();
if(!xpc)
{
printf("XPC_GetXPConnect() returned NULL!\n");
return 1;
}
#if 0
// old code where global object was plain object
glob = JS_NewObject(jscontext, &global_class, NULL, NULL);
if (!glob)
return 1;
if (!JS_InitStandardClasses(jscontext, glob))
return 1;
if (!JS_DefineFunctions(jscontext, glob, glob_functions))
return 1;
xpc->InitJSContext(jscontext, glob);
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();
// nsXPCVarient v[2];
// v[0].type = nsXPCType::T_I32; v[0].val.i32 = 1;
// v[1].type = nsXPCType::T_I32; v[1].val.i32 = 2;
// XPC_TestInvoke(foo, 3, 2, v);
// XPC_TestInvoke(foo, 4, 0, NULL);
nsIXPConnectWrappedNative* wrapper;
nsIXPConnectWrappedNative* wrapper2;
nsIXPConnectWrappedNative* fool_wrapper = NULL;
/*
if(NS_SUCCEEDED(xpc->WrapNative(jscontext, foo, nsITestXPCFoo::GetIID(), &wrapper)))
*/
// new code where global object is a wrapped xpcom object
if(NS_SUCCEEDED(xpc->InitJSContextWithNewWrappedGlobal(
jscontext, foo, nsITestXPCFoo::GetIID(), &wrapper)))
{
wrapper->GetJSObject(&glob);
JS_DefineFunctions(jscontext, glob, glob_functions);
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);
nsTestXPCFoo* fool = new nsTestXPCFoo();
xpc->WrapNative(jscontext, fool, nsITestXPCFoo2::GetIID(), &fool_wrapper);
if(NS_SUCCEEDED(xpc->WrapNative(jscontext, foo, nsITestXPCFoo2::GetIID(), &wrapper2)))
{
JSObject* js_obj;
nsISupports* com_obj;
jsval rval;
wrapper2->GetJSObject(&js_obj);
wrapper2->GetNative(&com_obj);
jsval v;
v = OBJECT_TO_JSVAL(js_obj);
JS_SetProperty(jscontext, glob, "foo", &v);
// add the reflected native echo object (sans error checking :)
nsIXPConnectWrappedNative* echo_wrapper;
JSObject* echo_jsobj;
jsval echo_jsval;
MyEcho* myEcho = new MyEcho();
xpc->WrapNative(jscontext, myEcho, nsIEcho::GetIID(), &echo_wrapper);
echo_wrapper->GetJSObject(&echo_jsobj);
echo_jsval = OBJECT_TO_JSVAL(echo_jsobj);
JS_SetProperty(jscontext, glob, "echo", &echo_jsval);
char* txt[] = {
"load('testxpc.js');",
0,
};
for(char** p = txt; *p; p++)
JS_EvaluateScript(jscontext, glob, *p, strlen(*p), "builtin", 1, &rval);
if(JS_GetProperty(jscontext, glob, "bar", &v) && JSVAL_IS_OBJECT(v))
{
JSObject* bar = JSVAL_TO_OBJECT(v);
nsISupports* wrapper3;
if(NS_SUCCEEDED(xpc->WrapJS(jscontext,
JSVAL_TO_OBJECT(v),
nsITestXPCFoo::GetIID(), &wrapper3)))
{
nsITestXPCFoo* ptr = (nsITestXPCFoo*)wrapper3;
int result;
JSObject* test_js_obj;
ptr->Test(11, 13, &result);
printf("call to ptr->Test returned %d\n", result);
nsIXPConnectWrappedJSMethods* methods;
wrapper3->QueryInterface(nsIXPConnectWrappedJSMethods::GetIID(),
(void**) &methods);
methods->GetJSObject(&test_js_obj);
printf("call to methods->GetJSObject() returned: %s\n",
test_js_obj == JSVAL_TO_OBJECT(v) ?
"expected result" : "WRONG RESULT" );
// dump to log test...
XPC_DUMP(xpc, 50);
NS_RELEASE(methods);
NS_RELEASE(wrapper3);
}
}
NS_RELEASE(com_obj);
NS_RELEASE(wrapper2);
NS_RELEASE(echo_wrapper);
NS_RELEASE(myEcho);
}
// NS_RELEASE(wrapper);
}
NS_RELEASE(foo);
// XXX things are still rooted to the global object in the test scripts...
// dump to log test...
// XPC_LOG_ALWAYS((""));
// XPC_LOG_ALWAYS(("after running release object..."));
// XPC_LOG_ALWAYS((""));
// XPC_DUMP(xpc, 3);
if(glob)
{
JS_DeleteProperty(jscontext, glob, "foo");
JS_DeleteProperty(jscontext, glob, "echo");
JS_DeleteProperty(jscontext, glob, "bar");
JS_DeleteProperty(jscontext, glob, "foo2");
JS_DeleteProperty(jscontext, glob, "baz");
JS_DeleteProperty(jscontext, glob, "baz2");
JS_DeleteProperty(jscontext, glob, "reciever");
JS_SetGlobalObject(jscontext, JS_NewObject(jscontext, &global_class, NULL, NULL));
}
NS_RELEASE(wrapper);
NS_RELEASE(fool_wrapper);
// js_DumpGCHeap = stdout;
// JS_GC(jscontext);
// printf("-----------------------\n");
// JS_GC(jscontext);
// dump to log test...
// XPC_LOG_ALWAYS((""));
// XPC_LOG_ALWAYS(("after running JS_GC..."));
// XPC_LOG_ALWAYS((""));
XPC_DUMP(xpc, 3);
#endif
NS_RELEASE(xpc);
JS_DestroyContext(jscontext);
JS_DestroyRuntime(rt);
JS_ShutDown();
return 0;
}
/***************************************************************************/
#include "jsatom.h"
#ifdef DEBUG
int
DumpAtom(JSHashEntry *he, int i, void *arg)
{
FILE *fp = (FILE *)arg;
JSAtom *atom = (JSAtom *)he;
fprintf(fp, "%3d %08x %5lu ",
i, (uintN)he->keyHash, (unsigned long)atom->number);
if (ATOM_IS_STRING(atom))
fprintf(fp, "\"%s\"\n", ATOM_BYTES(atom));
else if (ATOM_IS_INT(atom))
fprintf(fp, "%ld\n", (long)ATOM_TO_INT(atom));
else
fprintf(fp, "%.16g\n", *ATOM_TO_DOUBLE(atom));
return HT_ENUMERATE_NEXT;
}
int
DumpSymbol(JSHashEntry *he, int i, void *arg)
{
FILE *fp = (FILE *)arg;
JSSymbol *sym = (JSSymbol *)he;
fprintf(fp, "%3d %08x", i, (uintN)he->keyHash);
if (JSVAL_IS_INT(sym_id(sym)))
fprintf(fp, " [%ld]\n", (long)JSVAL_TO_INT(sym_id(sym)));
else
fprintf(fp, " \"%s\"\n", ATOM_BYTES(sym_atom(sym)));
return HT_ENUMERATE_NEXT;
}
/* These are callable from gdb. */
JS_BEGIN_EXTERN_C
void Dsym(JSSymbol *sym) { if (sym) DumpSymbol(&sym->entry, 0, gErrFile); }
void Datom(JSAtom *atom) { if (atom) DumpAtom(&atom->entry, 0, gErrFile); }
void Dobj(nsISupports* p, int depth) {if(p)XPC_DUMP(p,depth);}
void Dxpc(int depth) {Dobj(XPC_GetXPConnect(), depth);}
JS_END_EXTERN_C
#endif

View File

@ -0,0 +1,68 @@
#!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 simpletest.js
LCFLAGS=-DUSE_NSREG -DWIN32_LEAN_AND_MEAN -DJS_THREADSAFE -DJSFILE
REQUIRES=xpcom js xpconnect
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\xpconnect \
-I$(PUBLIC)\raptor -I$(PUBLIC)\xptinfo
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

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

@ -0,0 +1,451 @@
// tests...
function nsID(str)
{
var id = Components.classes.nsIID.newInstance();
id = id.QueryInterface(Components.interfaces.nsIJSIID);
id.init(str);
return id;
}
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
var NS_ITESTXPC_FOO_IID = new nsID("{159E36D0-991E-11d2-AC3F-00C09300144B}");
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,18,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);

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__ */

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.