mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-31 19:10:36 +00:00
adding Components object. Got rid of jsapi based nsID object and replaced it with reflected xpcom objects for IID and CID. adapted to xpt_struct changes. added allocator static helpers to the module. starting to use nsIComponentManager. fixed scriptable stuff. and on and on
This commit is contained in:
parent
ad63f394aa
commit
401f011bce
@ -34,26 +34,31 @@ MODULE=xpconnect
|
||||
CFLAGS += -DJSFILE -DJS_THREADSAFE
|
||||
|
||||
CPPSRCS= \
|
||||
xpt_cpp.cpp \
|
||||
nsXPConnect.cpp \
|
||||
xpcarbitrary.cpp \
|
||||
xpccomponents.cpp \
|
||||
xpccontext.cpp \
|
||||
xpcconvert.cpp \
|
||||
xpcjsid.cpp \
|
||||
xpclog.cpp \
|
||||
xpcmaps.cpp \
|
||||
xpcnsid.cpp \
|
||||
xpcmodule.cpp \
|
||||
xpcthrower.cpp \
|
||||
xpcutil.cpp \
|
||||
xpcwrappedjs.cpp \
|
||||
xpcwrappedjsclass.cpp \
|
||||
xpcwrappednative.cpp \
|
||||
xpcwrappednativeclass.cpp \
|
||||
xpt_cpp.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIXPCScriptable.h \
|
||||
nsIInterfaceInfo.h \
|
||||
nsIInterfaceInfoManager.h \
|
||||
nsIXPCScriptable.h \
|
||||
nsIXPConnect.h \
|
||||
xpccomponents.h \
|
||||
xpcjsid.h \
|
||||
xpclog.h \
|
||||
$(NULL)
|
||||
|
||||
|
2
js/src/xpconnect/idl/mk.bat
Executable file
2
js/src/xpconnect/idl/mk.bat
Executable file
@ -0,0 +1,2 @@
|
||||
xpidl -w -m header -o ..\xpccomponents xpccomponents.idl
|
||||
xpidl -w -m header -o ..\xpcjsid xpcjsid.idl
|
6
js/src/xpconnect/idl/nsISupports.idl
Normal file
6
js/src/xpconnect/idl/nsISupports.idl
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
/* XXX completely bogus declaration */
|
||||
|
||||
[object,uuid(00000000-0000-0000-c000-000000000046)]
|
||||
interface nsISupports {
|
||||
};
|
36
js/src/xpconnect/idl/xpccomponents.idl
Normal file
36
js/src/xpconnect/idl/xpccomponents.idl
Normal 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;
|
||||
};
|
65
js/src/xpconnect/idl/xpcjsid.idl
Normal file
65
js/src/xpconnect/idl/xpcjsid.idl
Normal file
@ -0,0 +1,65 @@
|
||||
/* -*- 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);
|
||||
};
|
||||
|
||||
[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 } }
|
||||
%}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,26 +35,31 @@ MD_LIBRARY = .\md\win32\$(OBJDIR)\xpcmd.lib
|
||||
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPC_API -DJS_THREADSAFE
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\xpt_cpp.obj \
|
||||
.\$(OBJDIR)\nsXPConnect.obj \
|
||||
.\$(OBJDIR)\xpclog.obj \
|
||||
.\$(OBJDIR)\xpcarbitrary.obj \
|
||||
.\$(OBJDIR)\xpccomponents.obj \
|
||||
.\$(OBJDIR)\xpccontext.obj \
|
||||
.\$(OBJDIR)\xpcconvert.obj \
|
||||
.\$(OBJDIR)\xpcjsid.obj \
|
||||
.\$(OBJDIR)\xpclog.obj \
|
||||
.\$(OBJDIR)\xpcmaps.obj \
|
||||
.\$(OBJDIR)\xpcnsid.obj \
|
||||
.\$(OBJDIR)\xpcmodule.obj \
|
||||
.\$(OBJDIR)\xpcthrower.obj \
|
||||
.\$(OBJDIR)\xpcutil.obj \
|
||||
.\$(OBJDIR)\xpcwrappedjs.obj \
|
||||
.\$(OBJDIR)\xpcwrappedjsclass.obj \
|
||||
.\$(OBJDIR)\xpcwrappednative.obj \
|
||||
.\$(OBJDIR)\xpcwrappednativeclass.obj \
|
||||
.\$(OBJDIR)\xpt_cpp.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIXPCScriptable.h \
|
||||
nsIInterfaceInfo.h \
|
||||
nsIInterfaceInfoManager.h \
|
||||
nsIXPCScriptable.h \
|
||||
nsIXPConnect.h \
|
||||
xpccomponents.h \
|
||||
xpcjsid.h \
|
||||
xpclog.h \
|
||||
$(NULL)
|
||||
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
// XXX this is here just for testing - pulled from XPConnect...
|
||||
// it can go away after nsIInterfaceInfos are being built from typelibs
|
||||
|
||||
#include "xpccomponents.h"
|
||||
#include "xpcjsid.h"
|
||||
|
||||
// {159E36D0-991E-11d2-AC3F-00C09300144B}
|
||||
#define NS_ITESTXPC_FOO_IID \
|
||||
{ 0x159e36d0, 0x991e, 0x11d2, \
|
||||
|
@ -24,6 +24,43 @@
|
||||
#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
|
||||
@ -250,22 +287,160 @@ public:
|
||||
nsIXPCScriptable* arbitrary) \
|
||||
{return arbitrary->Finalize(cx, obj, wrapper, NULL);}
|
||||
|
||||
#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) \
|
||||
/***************************************************************************/
|
||||
|
||||
#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) \
|
||||
{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
|
||||
@ -274,6 +449,33 @@ public:
|
||||
//};
|
||||
//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___ */
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
#include "xpccomponents.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
|
||||
@ -79,6 +81,7 @@ public:
|
||||
|
||||
class nsIXPConnectWrappedJS : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_JS_IID)
|
||||
// no methods allowed since this has a shared vtbl!
|
||||
//
|
||||
@ -152,6 +155,9 @@ JS_BEGIN_EXTERN_C
|
||||
XPC_PUBLIC_API(nsIXPConnect*)
|
||||
XPC_GetXPConnect();
|
||||
|
||||
XPC_PUBLIC_API(nsIXPCComponents*)
|
||||
XPC_GetXPConnectComponentsObject();
|
||||
|
||||
#ifdef DEBUG
|
||||
XPC_PUBLIC_API(void)
|
||||
XPC_Dump(nsISupports* p, int depth);
|
||||
|
@ -121,6 +121,34 @@ nsXPConnect::GetJSThrower(nsXPConnect* xpc /*= NULL */)
|
||||
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),
|
||||
@ -131,6 +159,8 @@ nsXPConnect::nsXPConnect()
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
xpc_RegisterSelf();
|
||||
|
||||
nsXPCWrappedNativeClass::OneTimeInit();
|
||||
mContextMap = JSContext2XPCContextMap::newMap(CONTEXT_MAP_SIZE);
|
||||
mArbitraryScriptable = new nsXPCArbitraryScriptable();
|
||||
@ -301,6 +331,7 @@ nsXPConnect::GetWrappedNativeOfJSObject(JSContext* aJSContext,
|
||||
|
||||
if(!(*aWrapper = nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(aJSContext,aJSObj)))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
NS_ADDREF(*aWrapper);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "jsapi.h"
|
||||
#include "xpclog.h"
|
||||
|
||||
@ -490,6 +491,28 @@ int main()
|
||||
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);
|
||||
|
||||
|
@ -1,4 +1,12 @@
|
||||
// test case...
|
||||
// tests...
|
||||
|
||||
function nsID(str)
|
||||
{
|
||||
var id = Components.classes.nsIID.newInstance();
|
||||
id = id.QueryInterface(Components.interfaces.nsIID);
|
||||
id.init(str);
|
||||
return id;
|
||||
}
|
||||
|
||||
var NS_ISUPPORTS_IID = new nsID("{00000000-0000-0000-c000-000000000046}");
|
||||
var NS_ITESTXPC_FOO_IID = new nsID("{159E36D0-991E-11d2-AC3F-00C09300144B}");
|
||||
@ -293,9 +301,9 @@ function idTest(name, iid, same)
|
||||
var idFromName = new nsID(name);
|
||||
var idFromIID = new nsID(iid);
|
||||
|
||||
if(!idFromName.isValid() || !idFromIID.isValid()) {
|
||||
return (same && idFromName.isValid() == idFromIID.isValid()) ||
|
||||
(!same && idFromName.isValid() != idFromIID.isValid());
|
||||
if(!idFromName.valid || !idFromIID.valid) {
|
||||
return (same && idFromName.valid == idFromIID.valid) ||
|
||||
(!same && idFromName.valid != idFromIID.valid);
|
||||
}
|
||||
|
||||
if(same != idFromName.equals(idFromIID) ||
|
||||
@ -307,21 +315,21 @@ function idTest(name, iid, same)
|
||||
nameNormalized = name.toLowerCase();
|
||||
iidNormalized = iid.toLowerCase();
|
||||
|
||||
idFromName_NameNormalized = idFromName.toName() ?
|
||||
idFromName.toName().toLowerCase() :
|
||||
idFromName.toName();
|
||||
idFromName_NameNormalized = idFromName.name ?
|
||||
idFromName.name.toLowerCase() :
|
||||
idFromName.name;
|
||||
|
||||
idFromIID_NameNormalized = idFromIID.toName() ?
|
||||
idFromIID.toName().toLowerCase() :
|
||||
idFromIID.toName();
|
||||
idFromIID_NameNormalized = idFromIID.name ?
|
||||
idFromIID.name.toLowerCase() :
|
||||
idFromIID.name;
|
||||
|
||||
idFromName_StringNormalized = idFromName.toString() ?
|
||||
idFromName.toString().toLowerCase() :
|
||||
idFromName.toString();
|
||||
idFromName_StringNormalized = idFromName.number ?
|
||||
idFromName.number.toLowerCase() :
|
||||
idFromName.number;
|
||||
|
||||
idFromIID_StringNormalized = idFromIID.toString() ?
|
||||
idFromIID.toString().toLowerCase() :
|
||||
idFromIID.toString();
|
||||
idFromIID_StringNormalized = idFromIID.number ?
|
||||
idFromIID.number.toLowerCase() :
|
||||
idFromIID.number;
|
||||
|
||||
if(idFromName_NameNormalized != nameNormalized ||
|
||||
same != (idFromIID_NameNormalized == nameNormalized)) {
|
||||
@ -362,6 +370,25 @@ all_ok = idTest("bogus", "{XXXXXXXX-C5D9-11d2-9838-006008962422}", true)
|
||||
|
||||
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(".......................................");
|
||||
|
370
js/src/xpconnect/xpccomponents.cpp
Normal file
370
js/src/xpconnect/xpccomponents.cpp
Normal 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();
|
||||
}
|
||||
|
83
js/src/xpconnect/xpccomponents.h
Normal file
83
js/src/xpconnect/xpccomponents.h
Normal 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__ */
|
@ -92,7 +92,7 @@ XPCContext::Init(JSObject* aGlobalObj /*= NULL*/)
|
||||
{
|
||||
if(aGlobalObj)
|
||||
mGlobalObj = aGlobalObj;
|
||||
return xpc_InitIDClass(this) &&
|
||||
return /* xpc_InitIDClass(this) && */
|
||||
nsXPCWrappedJSClass::InitForContext(this) &&
|
||||
nsXPCWrappedNativeClass::InitForContext(this);
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
|
||||
if(!iid)
|
||||
return JS_FALSE;
|
||||
JSObject* obj;
|
||||
if(!(obj = xpc_NewIDObject(cx, *iid)))
|
||||
if(!(obj = xpc_NewIIDObject(cx, *iid)))
|
||||
return JS_FALSE;
|
||||
*d = OBJECT_TO_JSVAL(obj);
|
||||
break;
|
||||
@ -385,6 +385,8 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
|
||||
return JS_FALSE;
|
||||
case nsXPTType::T_IID:
|
||||
{
|
||||
NS_ASSERTION(al,"trying to convert a JSID to nsID without allocator");
|
||||
|
||||
JSObject* obj;
|
||||
const nsID* pid=NULL;
|
||||
if(!JSVAL_IS_OBJECT(s) ||
|
||||
@ -393,17 +395,7 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
if(al)
|
||||
{
|
||||
if(!(*((void**)d) = al->Alloc(sizeof(nsID))))
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
memcpy(*((void**)d), pid, sizeof(nsID));
|
||||
}
|
||||
else
|
||||
*((const nsID**)d) = pid;
|
||||
|
||||
*((const nsID**)d) = pid;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
560
js/src/xpconnect/xpcjsid.cpp
Normal file
560
js/src/xpconnect/xpcjsid.cpp
Normal file
@ -0,0 +1,560 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* An xpcom implmentation of the JavaScript nsIID and nsCID objects. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
/***************************************************************************/
|
||||
// stuff used for both classes...
|
||||
|
||||
class IDForJSScriptable : public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS;
|
||||
XPC_DECLARE_IXPCSCRIPTABLE;
|
||||
IDForJSScriptable();
|
||||
virtual ~IDForJSScriptable();
|
||||
};
|
||||
|
||||
IDForJSScriptable::IDForJSScriptable()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
IDForJSScriptable::~IDForJSScriptable() {}
|
||||
|
||||
static NS_DEFINE_IID(kIDForJSScriptableIID, NS_IXPCSCRIPTABLE_IID);
|
||||
NS_IMPL_ISUPPORTS(IDForJSScriptable, kIDForJSScriptableIID);
|
||||
|
||||
XPC_IMPLEMENT_IGNORE_CREATE(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_LOOKUPPROPERTY(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_GETPROPERTY(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_SETPROPERTY(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(IDForJSScriptable);
|
||||
//XPC_IMPLEMENT_IGNORE_DEFAULTVALUE(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_ENUMERATE(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_CHECKACCESS(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_CALL(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_CONSTRUCT(IDForJSScriptable);
|
||||
XPC_IMPLEMENT_IGNORE_FINALIZE(IDForJSScriptable);
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDForJSScriptable::DefaultValue(JSContext *cx, JSObject *obj,
|
||||
JSType type, jsval *vp,
|
||||
nsIXPConnectWrappedNative* wrapper,
|
||||
nsIXPCScriptable* arbitrary,
|
||||
JSBool* retval)
|
||||
{
|
||||
JSBool success = JS_FALSE;
|
||||
if(type == JSTYPE_STRING || type == JSTYPE_VOID)
|
||||
{
|
||||
nsIJSID* nsid;
|
||||
if(NS_SUCCEEDED(wrapper->GetNative((nsISupports**)&nsid)))
|
||||
{
|
||||
char* str;
|
||||
if(NS_SUCCEEDED(nsid->GetNumber(&str)))
|
||||
{
|
||||
JSString* jsstr = JS_NewStringCopyZ(cx, str);
|
||||
XPCMem::Free(str);
|
||||
if(jsstr)
|
||||
{
|
||||
*vp = STRING_TO_JSVAL(jsstr);
|
||||
*retval = success = JS_TRUE;
|
||||
}
|
||||
}
|
||||
NS_RELEASE(nsid);
|
||||
if(success)
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return arbitrary->DefaultValue(cx, obj, type, vp, wrapper, NULL, retval);
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
|
||||
// we leak one of these over the lifetime of the process...
|
||||
static IDForJSScriptable* GetSharedScriptable()
|
||||
{
|
||||
static IDForJSScriptable* scriptable = NULL;
|
||||
if(!scriptable)
|
||||
scriptable = new IDForJSScriptable;
|
||||
return scriptable;
|
||||
}
|
||||
|
||||
static const nsID& GetInvalidIID()
|
||||
{
|
||||
// {BB1F47B0-D137-11d2-9841-006008962422}
|
||||
static nsID invalid = {0xbb1f47b0, 0xd137, 0x11d2,
|
||||
{0x98, 0x41, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22}};
|
||||
return invalid;
|
||||
}
|
||||
|
||||
static char* gNoString = "";
|
||||
|
||||
/***************************************************************************/
|
||||
// nsJSIID
|
||||
|
||||
nsresult
|
||||
nsJSIID::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsISupports::GetIID()) ||
|
||||
aIID.Equals(nsIJSID::GetIID()) ||
|
||||
aIID.Equals(nsIJSIID::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIXPCScriptable::GetIID())) {
|
||||
IDForJSScriptable* scriptable = GetSharedScriptable();
|
||||
*aInstancePtr = (void*) scriptable;
|
||||
NS_ADDREF(scriptable);
|
||||
return NS_OK;
|
||||
}
|
||||
*aInstancePtr = NULL;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsJSIID)
|
||||
NS_IMPL_RELEASE(nsJSIID)
|
||||
|
||||
nsJSIID::nsJSIID()
|
||||
: mID(GetInvalidIID()), mNumber(gNoString), mName(gNoString)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF_THIS();
|
||||
};
|
||||
|
||||
nsJSIID::~nsJSIID()
|
||||
{
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
}
|
||||
|
||||
void nsJSIID::reset()
|
||||
{
|
||||
mID = GetInvalidIID();
|
||||
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
|
||||
mNumber = mName = NULL;
|
||||
}
|
||||
|
||||
//static
|
||||
nsJSIID*
|
||||
nsJSIID::NewID(const char* str)
|
||||
{
|
||||
PRBool success;
|
||||
nsJSIID* idObj = new nsJSIID();
|
||||
if(!idObj)
|
||||
return NULL;
|
||||
|
||||
if(NS_FAILED(idObj->init(str, &success)) || !success)
|
||||
{
|
||||
delete idObj;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return idObj;
|
||||
}
|
||||
|
||||
void
|
||||
nsJSIID::setName(const char* name)
|
||||
{
|
||||
int len = strlen(name)+1;
|
||||
mName = new char[len];
|
||||
if(mName)
|
||||
memcpy(mName, name, len);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetName(char * *aName)
|
||||
{
|
||||
if(!mName)
|
||||
{
|
||||
nsIInterfaceInfoManager* iim;
|
||||
if(NULL != (iim = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
char* name;
|
||||
if(NS_SUCCEEDED(iim->GetNameForIID(&mID, &name)) && name)
|
||||
{
|
||||
setName(name);
|
||||
XPCMem::Free(name);
|
||||
}
|
||||
NS_RELEASE(iim);
|
||||
}
|
||||
if(!mName)
|
||||
mName = gNoString;
|
||||
}
|
||||
|
||||
*aName = (char*) XPCMem::Clone(mName, strlen(mName)+1);
|
||||
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetNumber(char * *aNumber)
|
||||
{
|
||||
if(!mNumber)
|
||||
{
|
||||
if(!(mNumber = mID.ToString()))
|
||||
mNumber = gNoString;
|
||||
}
|
||||
|
||||
*aNumber = (char*) XPCMem::Clone(mNumber, strlen(mNumber)+1);
|
||||
return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetId(nsID* *aId)
|
||||
{
|
||||
*aId = (nsID*) XPCMem::Clone(&mID, sizeof(nsID));
|
||||
return *aId ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::GetValid(PRBool *aValid)
|
||||
{
|
||||
*aValid = !mID.Equals(GetInvalidIID());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::equals(nsIJSID *other, PRBool *_retval)
|
||||
{
|
||||
if(!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = PR_FALSE;
|
||||
|
||||
if(mID.Equals(GetInvalidIID()))
|
||||
return NS_OK;
|
||||
|
||||
nsID* otherID;
|
||||
if(NS_SUCCEEDED(other->GetId(&otherID)))
|
||||
{
|
||||
*_retval = mID.Equals(*otherID);
|
||||
XPCMem::Free(otherID);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSIID::init(const char *idString, PRBool *_retval)
|
||||
{
|
||||
if(!_retval || !idString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool success = PR_FALSE;
|
||||
|
||||
if(strlen(idString) && mID.Equals(GetInvalidIID()))
|
||||
{
|
||||
reset();
|
||||
|
||||
if(idString[0] == '{')
|
||||
{
|
||||
nsID id;
|
||||
if(id.Parse((char*)idString))
|
||||
{
|
||||
mID = id;
|
||||
success = PR_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsIInterfaceInfoManager* iim;
|
||||
if(NULL != (iim = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
nsID* pid;
|
||||
if(NS_SUCCEEDED(iim->GetIIDForName(idString, &pid)) && pid)
|
||||
{
|
||||
mID = *pid;
|
||||
setName(idString);
|
||||
success = PR_TRUE;
|
||||
XPCMem::Free(pid);
|
||||
}
|
||||
NS_RELEASE(iim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*_retval = success;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
// nsJSCID
|
||||
|
||||
nsresult
|
||||
nsJSCID::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsISupports::GetIID()) ||
|
||||
aIID.Equals(nsIJSID::GetIID()) ||
|
||||
aIID.Equals(nsIJSCID::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIXPCScriptable::GetIID())) {
|
||||
IDForJSScriptable* scriptable = GetSharedScriptable();
|
||||
*aInstancePtr = (void*) scriptable;
|
||||
NS_ADDREF(scriptable);
|
||||
return NS_OK;
|
||||
}
|
||||
*aInstancePtr = NULL;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsJSCID)
|
||||
NS_IMPL_RELEASE(nsJSCID)
|
||||
|
||||
nsJSCID::nsJSCID()
|
||||
: mID(GetInvalidIID()), mNumber(gNoString), mName(gNoString)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF_THIS();
|
||||
};
|
||||
|
||||
nsJSCID::~nsJSCID()
|
||||
{
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
}
|
||||
|
||||
void nsJSCID::reset()
|
||||
{
|
||||
mID = GetInvalidIID();
|
||||
|
||||
if(mNumber && mNumber != gNoString)
|
||||
delete [] mNumber;
|
||||
if(mName && mName != gNoString)
|
||||
delete [] mName;
|
||||
|
||||
mNumber = mName = NULL;
|
||||
}
|
||||
|
||||
//static
|
||||
nsJSCID*
|
||||
nsJSCID::NewID(const char* str)
|
||||
{
|
||||
PRBool success;
|
||||
nsJSCID* idObj = new nsJSCID();
|
||||
if(!idObj)
|
||||
return NULL;
|
||||
|
||||
if(NS_FAILED(idObj->init(str, &success)) || !success)
|
||||
{
|
||||
delete idObj;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return idObj;
|
||||
}
|
||||
|
||||
void
|
||||
nsJSCID::setName(const char* name)
|
||||
{
|
||||
int len = strlen(name)+1;
|
||||
mName = new char[len];
|
||||
if(mName)
|
||||
memcpy(mName, name, len);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetName(char * *aName)
|
||||
{
|
||||
if(!mName)
|
||||
mName = gNoString;
|
||||
*aName = (char*) XPCMem::Clone(mName, strlen(mName)+1);
|
||||
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetNumber(char * *aNumber)
|
||||
{
|
||||
if(!mNumber)
|
||||
{
|
||||
if(!(mNumber = mID.ToString()))
|
||||
mNumber = gNoString;
|
||||
}
|
||||
|
||||
*aNumber = (char*) XPCMem::Clone(mNumber, strlen(mNumber)+1);
|
||||
return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetId(nsID* *aId)
|
||||
{
|
||||
*aId = (nsID*) XPCMem::Clone(&mID, sizeof(nsID));
|
||||
return *aId ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::GetValid(PRBool *aValid)
|
||||
{
|
||||
*aValid = !mID.Equals(GetInvalidIID());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::equals(nsIJSID *other, PRBool *_retval)
|
||||
{
|
||||
if(!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = PR_FALSE;
|
||||
|
||||
if(mID.Equals(GetInvalidIID()))
|
||||
return NS_OK;
|
||||
|
||||
nsID* otherID;
|
||||
if(NS_SUCCEEDED(other->GetId(&otherID)))
|
||||
{
|
||||
*_retval = mID.Equals(*otherID);
|
||||
XPCMem::Free(otherID);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::init(const char *idString, PRBool *_retval)
|
||||
{
|
||||
if(!_retval || !idString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool success = PR_FALSE;
|
||||
|
||||
if(strlen(idString) && mID.Equals(GetInvalidIID()))
|
||||
{
|
||||
reset();
|
||||
|
||||
if(idString[0] == '{')
|
||||
{
|
||||
nsID id;
|
||||
if(id.Parse((char*)idString))
|
||||
{
|
||||
mID = id;
|
||||
success = PR_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCID cid;
|
||||
if(NS_SUCCEEDED(nsComponentManager::ProgIDToCLSID(idString, &cid)))
|
||||
{
|
||||
mID = cid;
|
||||
setName(idString);
|
||||
success = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*_retval = success;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSCID::newInstance(nsISupports **_retval)
|
||||
{
|
||||
if(!_retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*_retval = NULL;
|
||||
if(mID.Equals(GetInvalidIID()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return nsComponentManager::CreateInstance(mID, NULL,
|
||||
nsISupports::GetIID(),
|
||||
(void**) _retval);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
// additional utilities...
|
||||
|
||||
JSObject *
|
||||
xpc_NewIIDObject(JSContext *cx, const nsID& aID)
|
||||
{
|
||||
JSObject *obj = NULL;
|
||||
|
||||
char* idString = aID.ToString();
|
||||
if(idString)
|
||||
{
|
||||
nsJSIID* iid = nsJSIID::NewID(idString);
|
||||
delete [] idString;
|
||||
if(iid)
|
||||
{
|
||||
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
|
||||
if(xpc)
|
||||
{
|
||||
nsIXPConnectWrappedNative* nsid_wrapper;
|
||||
if(NS_SUCCEEDED(xpc->WrapNative(cx, iid,
|
||||
nsIJSIID::GetIID(),
|
||||
&nsid_wrapper)))
|
||||
{
|
||||
nsid_wrapper->GetJSObject(&obj);
|
||||
NS_RELEASE(nsid_wrapper);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
}
|
||||
NS_RELEASE(iid);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
nsID*
|
||||
xpc_JSObjectToID(JSContext *cx, JSObject* obj)
|
||||
{
|
||||
nsID* id = NULL;
|
||||
if(!cx || !obj)
|
||||
return NULL;
|
||||
|
||||
// NOTE: this call does NOT addref
|
||||
nsXPCWrappedNative* wrapper =
|
||||
nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(cx, obj);
|
||||
if(wrapper)
|
||||
{
|
||||
if(wrapper->GetIID().Equals(nsIJSIID::GetIID()) ||
|
||||
wrapper->GetIID().Equals(nsIJSCID::GetIID()))
|
||||
{
|
||||
((nsIJSID*)wrapper->GetNative())->GetId(&id);
|
||||
}
|
||||
}
|
||||
// XXX it would be nice to try to construct one from an object that can be
|
||||
// converted into a string.
|
||||
return id;
|
||||
}
|
||||
|
108
js/src/xpconnect/xpcjsid.h
Normal file
108
js/src/xpconnect/xpcjsid.h
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* DO NOT EDIT. THIS FILE IS GENERATED FROM xpcjsid.idl
|
||||
*/
|
||||
|
||||
#ifndef __gen_xpcjsid_h__
|
||||
#define __gen_xpcjsid_h__
|
||||
|
||||
#include "nsISupports.h" /* interface nsISupports */
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
#include "jsapi.h"
|
||||
#endif
|
||||
|
||||
/* starting interface nsIJSID */
|
||||
|
||||
/* {C86AE131-D101-11d2-9841-006008962422} */
|
||||
#define NS_IJSID_IID_STR "C86AE131-D101-11d2-9841-006008962422"
|
||||
#define NS_IJSID_IID \
|
||||
{0xC86AE131, 0xD101, 0x11d2, \
|
||||
{ 0x98, 0x41, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
|
||||
|
||||
class nsIJSID : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_IJSID_IID;
|
||||
return iid;
|
||||
}
|
||||
|
||||
/* readonly attribute string name; */
|
||||
NS_IMETHOD GetName(char * *aName) = 0;
|
||||
|
||||
/* readonly attribute string number; */
|
||||
NS_IMETHOD GetNumber(char * *aNumber) = 0;
|
||||
|
||||
/* readonly attribute nsID id; */
|
||||
NS_IMETHOD GetId(nsID* *aId) = 0;
|
||||
|
||||
/* readonly attribute boolean valid; */
|
||||
NS_IMETHOD GetValid(PRBool *aValid) = 0;
|
||||
|
||||
/* boolean equals (in nsIJSID other); */
|
||||
NS_IMETHOD equals(nsIJSID *other, PRBool *_retval) = 0;
|
||||
|
||||
/* boolean init (in string idString); */
|
||||
NS_IMETHOD init(const char *idString, PRBool *_retval) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSID *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface nsIJSIID */
|
||||
|
||||
/* {e08dcda0-d651-11d2-9843-006008962422} */
|
||||
#define NS_IJSIID_IID_STR "e08dcda0-d651-11d2-9843-006008962422"
|
||||
#define NS_IJSIID_IID \
|
||||
{0xe08dcda0, 0xd651, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
|
||||
|
||||
class nsIJSIID : public nsIJSID {
|
||||
public:
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_IJSIID_IID;
|
||||
return iid;
|
||||
}
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSIID *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface nsIJSCID */
|
||||
|
||||
/* {e3a24a60-d651-11d2-9843-006008962422} */
|
||||
#define NS_IJSCID_IID_STR "e3a24a60-d651-11d2-9843-006008962422"
|
||||
#define NS_IJSCID_IID \
|
||||
{0xe3a24a60, 0xd651, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x00, 0x60, 0x08, 0x96, 0x24, 0x22 }}
|
||||
|
||||
class nsIJSCID : public nsIJSID {
|
||||
public:
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_IJSCID_IID;
|
||||
return iid;
|
||||
}
|
||||
|
||||
/* nsISupports newInstance (); */
|
||||
NS_IMETHOD newInstance(nsISupports **_retval) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIJSCID *priv);
|
||||
#endif
|
||||
};
|
||||
/********************************************************/
|
||||
// {1D17BFF0-D58D-11d2-9843-006008962422}
|
||||
#define NS_JS_IID_CID \
|
||||
{ 0x1d17bff0, 0xd58d, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
|
||||
// {8628BFA0-D652-11d2-9843-006008962422}
|
||||
#define NS_JS_CID_CID \
|
||||
{ 0x8628bfa0, 0xd652, 0x11d2, \
|
||||
{ 0x98, 0x43, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
|
||||
|
||||
|
||||
#endif /* __gen_xpcjsid_h__ */
|
204
js/src/xpconnect/xpcmodule.cpp
Normal file
204
js/src/xpconnect/xpcmodule.cpp
Normal 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);
|
||||
}
|
@ -1,363 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Implement the nsID JavaScript class. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
// IDData hold the private data
|
||||
class IDData
|
||||
{
|
||||
public:
|
||||
static IDData* NewIDData(JSContext *cx, const nsID& id);
|
||||
static IDData* NewIDData(JSContext *cx, const IDData& data);
|
||||
static IDData* NewIDData(JSContext *cx, JSString* str);
|
||||
static void DeleteIDData(JSContext *cx, IDData* data);
|
||||
|
||||
void GetNameString(JSContext *cx, jsval *rval);
|
||||
void GetIDString(JSContext *cx, jsval *rval);
|
||||
const nsID& GetID() const {return mID;}
|
||||
JSBool Equals(const IDData& r);
|
||||
|
||||
IDData(); // not implemented
|
||||
~IDData(); // no virtual functions
|
||||
private:
|
||||
IDData(JSContext *cx, const nsID& aID,
|
||||
JSString* aIDString, JSString* aNameString);
|
||||
private:
|
||||
static JSString* gNoString;
|
||||
nsID mID;
|
||||
JSString* mIDString;
|
||||
JSString* mNameString;
|
||||
};
|
||||
|
||||
/* static */ JSString* IDData::gNoString = (JSString*)"";
|
||||
|
||||
IDData::IDData(JSContext *cx, const nsID& aID,
|
||||
JSString* aIDString, JSString* aNameString)
|
||||
: mID(aID), mIDString(aIDString), mNameString(aNameString)
|
||||
{
|
||||
if(mNameString && mNameString != gNoString)
|
||||
JS_AddRoot(cx, &mNameString);
|
||||
|
||||
if(mIDString && mIDString != gNoString)
|
||||
JS_AddRoot(cx, &mIDString);
|
||||
}
|
||||
|
||||
// static
|
||||
IDData*
|
||||
IDData::NewIDData(JSContext *cx, const nsID& id)
|
||||
{
|
||||
return new IDData(cx, id, NULL, NULL);
|
||||
}
|
||||
|
||||
// static
|
||||
IDData*
|
||||
IDData::NewIDData(JSContext *cx, const IDData& data)
|
||||
{
|
||||
return new IDData(cx, data.mID, data.mIDString, data.mNameString);
|
||||
}
|
||||
|
||||
// static
|
||||
IDData*
|
||||
IDData::NewIDData(JSContext *cx, JSString* str)
|
||||
{
|
||||
char* bytes;
|
||||
if(!str || !JS_GetStringLength(str) || !(bytes = JS_GetStringBytes(str)))
|
||||
return NULL;
|
||||
|
||||
nsID id;
|
||||
if(bytes[0] == '{')
|
||||
if(id.Parse(bytes))
|
||||
return new IDData(cx, id, JS_NewStringCopyZ(cx, bytes), NULL);
|
||||
|
||||
nsIInterfaceInfoManager* iim;
|
||||
if(!(iim = nsXPConnect::GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
|
||||
IDData* data = NULL;
|
||||
nsID* pid;
|
||||
|
||||
if(NS_SUCCEEDED(iim->GetIIDForName(bytes, &pid)) && pid)
|
||||
{
|
||||
data = new IDData(cx, *pid, NULL, JS_NewStringCopyZ(cx, bytes));
|
||||
|
||||
nsIAllocator* al = nsXPConnect::GetAllocator();
|
||||
if(al)
|
||||
{
|
||||
al->Free(pid);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(iim);
|
||||
return data;
|
||||
}
|
||||
|
||||
IDData::~IDData() {}
|
||||
|
||||
// static
|
||||
void
|
||||
IDData::DeleteIDData(JSContext *cx, IDData* data)
|
||||
{
|
||||
NS_PRECONDITION(cx, "bad JSContext");
|
||||
NS_PRECONDITION(data, "bad IDData");
|
||||
|
||||
if(data->mNameString && data->mNameString != gNoString)
|
||||
JS_RemoveRoot(cx, &data->mNameString);
|
||||
|
||||
if(data->mIDString && data->mIDString != gNoString)
|
||||
JS_RemoveRoot(cx, &data->mIDString);
|
||||
|
||||
delete data;
|
||||
}
|
||||
|
||||
void
|
||||
IDData::GetIDString(JSContext *cx, jsval *rval)
|
||||
{
|
||||
if(!mIDString)
|
||||
{
|
||||
char* str = mID.ToString();
|
||||
if(str)
|
||||
{
|
||||
if(NULL != (mIDString = JS_NewStringCopyZ(cx, str)))
|
||||
JS_AddRoot(cx, &mIDString);
|
||||
delete [] str;
|
||||
}
|
||||
if(!mIDString)
|
||||
mIDString = gNoString;
|
||||
}
|
||||
if(mIDString == gNoString)
|
||||
*rval = JSVAL_NULL;
|
||||
else
|
||||
*rval = STRING_TO_JSVAL(mIDString);
|
||||
}
|
||||
|
||||
void
|
||||
IDData::GetNameString(JSContext *cx, jsval *rval)
|
||||
{
|
||||
if(!mNameString)
|
||||
{
|
||||
nsIInterfaceInfoManager* iim;
|
||||
if(NULL != (iim = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
char* name;
|
||||
if(NS_SUCCEEDED(iim->GetNameForIID(&mID, &name)) && name)
|
||||
{
|
||||
if(NULL != (mNameString = JS_NewStringCopyZ(cx, name)))
|
||||
JS_AddRoot(cx, &mNameString);
|
||||
nsIAllocator* al = nsXPConnect::GetAllocator();
|
||||
if(al)
|
||||
{
|
||||
al->Free(name);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(iim);
|
||||
}
|
||||
if(!mNameString)
|
||||
mNameString = gNoString;
|
||||
}
|
||||
if(mNameString == gNoString)
|
||||
*rval = JSVAL_NULL;
|
||||
else
|
||||
*rval = STRING_TO_JSVAL(mNameString);
|
||||
}
|
||||
|
||||
JSBool
|
||||
IDData::Equals(const IDData& r)
|
||||
{
|
||||
return (JSBool) mID.Equals(r.mID);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(void)
|
||||
nsID_finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
IDData* data = (IDData*) JS_GetPrivate(cx, obj);
|
||||
if(data)
|
||||
IDData::DeleteIDData(cx, data);
|
||||
}
|
||||
|
||||
static JSClass nsID_class = {
|
||||
"nsID",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, nsID_finalize
|
||||
};
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsID_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
IDData* data=NULL;
|
||||
|
||||
if(JS_InstanceOf(cx, obj, &nsID_class, NULL) &&
|
||||
NULL != (data = (IDData*) JS_GetPrivate(cx, obj)))
|
||||
data->GetIDString(cx, rval);
|
||||
else
|
||||
*rval = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsID_toName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
IDData* data=NULL;
|
||||
|
||||
if(JS_InstanceOf(cx, obj, &nsID_class, NULL) &&
|
||||
NULL != (data = (IDData*) JS_GetPrivate(cx, obj)))
|
||||
data->GetNameString(cx, rval);
|
||||
else
|
||||
*rval = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsID_isValid(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
IDData* data=NULL;
|
||||
|
||||
if(JS_InstanceOf(cx, obj, &nsID_class, NULL) &&
|
||||
NULL != (data = (IDData*) JS_GetPrivate(cx, obj)))
|
||||
*rval = JSVAL_TRUE;
|
||||
else
|
||||
*rval = JSVAL_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsID_equals(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
JSObject *obj2;
|
||||
IDData* data1=NULL;
|
||||
IDData* data2=NULL;
|
||||
|
||||
if(!JS_InstanceOf(cx, obj, &nsID_class, NULL) ||
|
||||
!argc || !JSVAL_IS_OBJECT(argv[0]) ||
|
||||
!(obj2 = JSVAL_TO_OBJECT(argv[0])) ||
|
||||
!JS_InstanceOf(cx, obj2, &nsID_class, NULL) ||
|
||||
!(data1 = (IDData*) JS_GetPrivate(cx, obj)) ||
|
||||
!(data2 = (IDData*) JS_GetPrivate(cx, obj2)))
|
||||
*rval = JSVAL_FALSE;
|
||||
else
|
||||
*rval = data1->Equals(*data2) ? JSVAL_TRUE : JSVAL_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec nsID_methods[] = {
|
||||
{"toString", nsID_toString, 0},
|
||||
{"toName", nsID_toName, 0},
|
||||
{"isValid", nsID_isValid, 0},
|
||||
{"equals", nsID_equals, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
nsID_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
IDData* data = NULL;
|
||||
JSString* str;
|
||||
|
||||
if(argc == 0)
|
||||
{
|
||||
JS_ReportError(cx, "nsID has no constructor that takes zero arguments");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if(JSVAL_IS_OBJECT(argv[0]) &&
|
||||
JS_InstanceOf(cx, JSVAL_TO_OBJECT(argv[0]), &nsID_class, NULL))
|
||||
{
|
||||
IDData* src = (IDData*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(argv[0]));
|
||||
if(src)
|
||||
data = IDData::NewIDData(cx, *src);
|
||||
}
|
||||
else if(NULL != (str = JS_ValueToString(cx, argv[0])))
|
||||
{
|
||||
data = IDData::NewIDData(cx, str);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* It does not work to return a null value from a ctor. Having the private set
|
||||
* to null is THE indication that this object is not valid.
|
||||
*
|
||||
if(!data)
|
||||
{
|
||||
// JS_ReportError(cx, "could not constuct nsID");
|
||||
*rval = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
}
|
||||
*/
|
||||
if(!JS_IsConstructing(cx))
|
||||
{
|
||||
obj = JS_NewObject(cx, &nsID_class, NULL, NULL);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
*rval = OBJECT_TO_JSVAL(obj);
|
||||
}
|
||||
|
||||
JS_SetPrivate(cx, obj, data);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
xpc_InitIDClass(XPCContext* xpcc)
|
||||
{
|
||||
if (!JS_InitClass(xpcc->GetJSContext(), xpcc->GetGlobalObject(),
|
||||
NULL, &nsID_class, nsID_ctor, 1, NULL, nsID_methods, NULL, NULL))
|
||||
return JS_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
xpc_NewIDObject(JSContext *cx, const nsID& aID)
|
||||
{
|
||||
JSObject *obj;
|
||||
|
||||
IDData* data = IDData::NewIDData(cx, aID);
|
||||
if(! data)
|
||||
return NULL;
|
||||
|
||||
obj = JS_NewObject(cx, &nsID_class, NULL, NULL);
|
||||
if(obj)
|
||||
JS_SetPrivate(cx, obj, data);
|
||||
else
|
||||
IDData::DeleteIDData(cx, data);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
const nsID*
|
||||
xpc_JSObjectToID(JSContext *cx, JSObject* obj)
|
||||
{
|
||||
if(!cx || !obj)
|
||||
return NULL;
|
||||
|
||||
if(JS_InstanceOf(cx, obj, &nsID_class, NULL))
|
||||
{
|
||||
IDData* data = (IDData*) JS_GetPrivate(cx, obj);
|
||||
if(data)
|
||||
return &data->GetID();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
// XXX it would be nice to construct one from an object that can be
|
||||
// converted into a string. BUT since we return a const & we need to
|
||||
// have some storage space for the iid and that get complicated...
|
||||
return NULL;
|
||||
}
|
@ -26,6 +26,7 @@
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
@ -38,6 +39,8 @@
|
||||
#include "xpcforwards.h"
|
||||
#include "xpcvariant.h"
|
||||
#include "xpclog.h"
|
||||
#include "xpccomponents.h"
|
||||
#include "xpcjsid.h"
|
||||
|
||||
extern const char* XPC_VAL_STR; // 'value' property name for out params
|
||||
|
||||
@ -79,6 +82,7 @@ public:
|
||||
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;}
|
||||
@ -208,6 +212,7 @@ private:
|
||||
|
||||
class nsIXPCWrappedJSClass : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_JS_CLASS_IID)
|
||||
NS_IMETHOD DebugDump(int depth) = 0;
|
||||
};
|
||||
@ -370,6 +375,7 @@ public:
|
||||
|
||||
class nsIXPCWrappedNativeClass : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_NATIVE_CLASS_IID)
|
||||
NS_IMETHOD DebugDump(int depth) = 0;
|
||||
};
|
||||
@ -549,18 +555,6 @@ public:
|
||||
nsXPCArbitraryScriptable();
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// nsID JavaScript class functions
|
||||
|
||||
JSBool
|
||||
xpc_InitIDClass(XPCContext* xpcc);
|
||||
|
||||
JSObject*
|
||||
xpc_NewIDObject(JSContext *cx, const nsID& aID);
|
||||
|
||||
const nsID*
|
||||
xpc_JSObjectToID(JSContext *cx, JSObject* obj);
|
||||
|
||||
/***************************************************************************/
|
||||
// data convertion
|
||||
|
||||
@ -583,12 +577,149 @@ private:
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// 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);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// platform specific method invoker
|
||||
nsresult
|
||||
xpc_InvokeNativeMethod(void* that, PRUint32 index,
|
||||
uint32 paramCount, nsXPCVariant* params);
|
||||
|
||||
/***************************************************************************/
|
||||
// module level stuff
|
||||
|
||||
void
|
||||
xpc_RegisterSelf();
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// the include of declarations of the maps comes last because they have
|
||||
|
54
js/src/xpconnect/xpcutil.cpp
Normal file
54
js/src/xpconnect/xpcutil.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Module local methods to use 'standard' interfaces in other modules. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
// all these methods are class statics
|
||||
|
||||
nsIAllocator* XPCMem::Allocator()
|
||||
{
|
||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||
static nsIAllocator* al = NULL;
|
||||
if(!al)
|
||||
nsServiceManager::GetService(kAllocatorCID, kIAllocatorIID,
|
||||
(nsISupports **)&al);
|
||||
NS_ASSERTION(al, "failed to get Allocator!");
|
||||
return al;
|
||||
}
|
||||
|
||||
void* XPCMem::Alloc(PRUint32 size)
|
||||
{return Allocator()->Alloc(size);}
|
||||
|
||||
void* XPCMem::Realloc(void* ptr, PRUint32 size)
|
||||
{return Allocator()->Realloc(ptr, size);}
|
||||
|
||||
void XPCMem::Free(void* ptr)
|
||||
{Allocator()->Free(ptr);}
|
||||
|
||||
void XPCMem::HeapMinimize()
|
||||
{Allocator()->HeapMinimize();}
|
||||
|
||||
void* XPCMem::Clone(const void* ptr, PRUint32 size)
|
||||
{
|
||||
void* p = Allocator()->Alloc(size);
|
||||
if(p) memcpy(p, ptr, size);
|
||||
return p;
|
||||
}
|
@ -310,20 +310,8 @@ nsXPCWrappedJSMethods::GetIID(nsIID** iid)
|
||||
NS_PRECONDITION(mWrapper, "bad state");
|
||||
NS_PRECONDITION(iid, "bad param");
|
||||
|
||||
nsIAllocator* al;
|
||||
if(NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
void* p = al->Alloc(sizeof(nsIID));
|
||||
NS_RELEASE(al);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &mWrapper->GetIID(), sizeof(nsIID));
|
||||
*iid = (nsIID*)p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
*iid = NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
*iid = (nsIID*) XPCMem::Clone(&mWrapper->GetIID(), sizeof(nsIID));
|
||||
return *iid ? NS_OK : NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
@ -352,14 +340,10 @@ nsXPCWrappedJS::DebugDump(int depth)
|
||||
XPC_LOG_ALWAYS(("%s wrapper around JSObject @ %x", \
|
||||
isRoot ? "ROOT":"non-root", mJSObj));
|
||||
char* name;
|
||||
nsIAllocator* al;
|
||||
GetClass()->GetInterfaceInfo()->GetName(&name);
|
||||
XPC_LOG_ALWAYS(("interface name is %s", name));
|
||||
if(name && NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
al->Free(name);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
if(name)
|
||||
XPCMem::Free(name);
|
||||
char * iid = GetClass()->GetIID().ToString();
|
||||
XPC_LOG_ALWAYS(("IID number is %s", iid));
|
||||
delete iid;
|
||||
|
@ -53,9 +53,12 @@ nsXPCWrappedJSClass::GetNewOrUsedClass(XPCContext* xpcc,
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
clazz = new nsXPCWrappedJSClass(xpcc, aIID, info);
|
||||
if(!clazz->mDescriptors)
|
||||
NS_RELEASE(clazz); // sets clazz to NULL
|
||||
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);
|
||||
@ -153,7 +156,7 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(JSObject* jsobj, REFNSIID aIID
|
||||
JSBool success = JS_FALSE;
|
||||
|
||||
// id = CreateIIDJSObject(aIID);
|
||||
id = xpc_NewIDObject(cx, aIID);
|
||||
id = xpc_NewIIDObject(cx, aIID);
|
||||
|
||||
if(id)
|
||||
{
|
||||
|
@ -348,20 +348,8 @@ nsXPCWrappedNative::GetIID(nsIID** iid)
|
||||
{
|
||||
NS_PRECONDITION(iid, "bad param");
|
||||
|
||||
nsIAllocator* al;
|
||||
if(NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
void* p = al->Alloc(sizeof(nsIID));
|
||||
NS_RELEASE(al);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &GetIID(), sizeof(nsIID));
|
||||
*iid = (nsIID*)p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
*iid = NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
*iid = (nsIID*) XPCMem::Clone(&GetIID(), sizeof(nsIID));
|
||||
return *iid ? NS_OK : NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -58,9 +58,12 @@ nsXPCWrappedNativeClass::GetNewOrUsedClass(XPCContext* xpcc,
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
clazz = new nsXPCWrappedNativeClass(xpcc, aIID, info);
|
||||
if(-1 == clazz->mMemberCount) // -1 means 'failed to init'
|
||||
NS_RELEASE(clazz); // NULLs out 'clazz'
|
||||
if(nsXPConnect::IsISupportsDescendent(info))
|
||||
{
|
||||
clazz = new nsXPCWrappedNativeClass(xpcc, aIID, info);
|
||||
if(-1 == clazz->mMemberCount) // -1 means 'failed to init'
|
||||
NS_RELEASE(clazz); // NULLs out 'clazz'
|
||||
}
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
@ -93,14 +96,7 @@ nsXPCWrappedNativeClass::~nsXPCWrappedNativeClass()
|
||||
mXPCContext->GetWrappedNativeClassMap()->Remove(this);
|
||||
DestroyMemberDescriptors();
|
||||
if(mName)
|
||||
{
|
||||
nsIAllocator* al;
|
||||
if(NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
al->Free(mName);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
}
|
||||
XPCMem::Free(mName);
|
||||
NS_RELEASE(mInfo);
|
||||
}
|
||||
|
||||
@ -140,6 +136,10 @@ nsXPCWrappedNativeClass::BuildMemberDescriptors()
|
||||
if(NS_FAILED(mInfo->GetMethodInfo(i, &info)))
|
||||
return JS_FALSE;
|
||||
|
||||
// don't reflect Addref or Release
|
||||
if(i == 1 || i == 2)
|
||||
continue;
|
||||
|
||||
if(!XPCConvert::IsMethodReflectable(*info))
|
||||
continue;
|
||||
|
||||
@ -361,6 +361,8 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
uint8 vtblIndex;
|
||||
nsresult invokeResult;
|
||||
nsIAllocator* al = NULL;
|
||||
const nsID* conditional_iid = NULL;
|
||||
JSBool iidIsOwned = JS_TRUE;
|
||||
uintN err;
|
||||
|
||||
*vp = JSVAL_NULL;
|
||||
@ -415,7 +417,6 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
for(i = 0; i < paramCount; i++)
|
||||
{
|
||||
nsIAllocator* conditional_al = NULL;
|
||||
const nsID* conditional_iid = NULL;
|
||||
const nsXPTParamInfo& param = info->GetParam(i);
|
||||
const nsXPTType& type = param.GetType();
|
||||
|
||||
@ -444,7 +445,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
if(!param.IsIn())
|
||||
continue;
|
||||
|
||||
// in the future there may be a param flag indicating 'stingy'
|
||||
// in the future there may be a param flag indicating 'shared'
|
||||
if(type.IsPointer())
|
||||
{
|
||||
conditional_al = al;
|
||||
@ -454,6 +455,11 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
else
|
||||
{
|
||||
src = argv[i];
|
||||
if(type.IsPointer() && type.TagPart() == nsXPTType::T_IID)
|
||||
{
|
||||
conditional_al = al;
|
||||
dp->flags |= nsXPCVariant::VAL_IS_OWNED;
|
||||
}
|
||||
}
|
||||
|
||||
if(type.TagPart() == nsXPTType::T_INTERFACE)
|
||||
@ -466,6 +472,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
cx, desc, i);
|
||||
goto done;
|
||||
}
|
||||
iidIsOwned = JS_FALSE;
|
||||
}
|
||||
else if(type.TagPart() == nsXPTType::T_INTERFACE_IS)
|
||||
{
|
||||
@ -476,7 +483,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
const nsXPTType& type = param.GetType();
|
||||
if(!type.IsPointer() || type.TagPart() != nsXPTType::T_IID ||
|
||||
!XPCConvert::JSData2Native(cx, &conditional_iid, argv[arg_num],
|
||||
type, NULL, NULL, NULL))
|
||||
type, al, NULL, NULL))
|
||||
{
|
||||
ThrowBadParamException(XPCJSError::CANT_GET_PARAM_IFACE_INFO,
|
||||
cx, desc, i);
|
||||
@ -490,6 +497,13 @@ nsXPCWrappedNativeClass::CallWrappedMethod(JSContext* cx,
|
||||
ThrowBadParamException(err, cx, desc, i);
|
||||
goto done;
|
||||
}
|
||||
if(conditional_iid)
|
||||
{
|
||||
if(iidIsOwned)
|
||||
al->Free((void*)conditional_iid);
|
||||
conditional_iid = NULL;
|
||||
iidIsOwned = JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// do the invoke
|
||||
@ -575,6 +589,8 @@ done:
|
||||
if(dp->IsValInterface())
|
||||
((nsISupports*)p)->Release();
|
||||
}
|
||||
if(conditional_iid && iidIsOwned && al)
|
||||
al->Free((void*)conditional_iid);
|
||||
|
||||
if(dispatchParams && dispatchParams != paramBuffer)
|
||||
delete [] dispatchParams;
|
||||
|
@ -238,11 +238,103 @@ XPTInterfaceDescriptor nsIEchoInterfaceDescriptor =
|
||||
|
||||
/***************/
|
||||
|
||||
XPTParamDescriptor nsIXPCComponents_GetInterfacesParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}} // fixup index later
|
||||
};
|
||||
|
||||
XPTParamDescriptor nsIXPCComponents_GetClassesParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}} // fixup index later
|
||||
};
|
||||
|
||||
XPTMethodDescriptor nsIXPCComponentsMethods[2] = {
|
||||
{XPT_MD_GETTER, "interfaces", 1, nsIXPCComponents_GetInterfacesParams, ResultParam},
|
||||
{XPT_MD_GETTER, "classes", 1, nsIXPCComponents_GetClassesParams, ResultParam}
|
||||
};
|
||||
|
||||
XPTInterfaceDescriptor nsIXPCComponentsInterfaceDescriptor =
|
||||
{NULL, 2, nsIXPCComponentsMethods, 0, NULL};
|
||||
|
||||
/***************/
|
||||
|
||||
XPTInterfaceDescriptor nsIXPCInterfacesInterfaceDescriptor =
|
||||
{NULL, 0, NULL, 0, NULL};
|
||||
|
||||
/***************/
|
||||
|
||||
XPTInterfaceDescriptor nsIXPCClassesInterfaceDescriptor =
|
||||
{NULL, 0, NULL, 0, NULL};
|
||||
|
||||
/***************/
|
||||
|
||||
XPTParamDescriptor nsIJSID_GetNameParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PSTRING ,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor nsIJSID_GetNumberParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PSTRING ,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor nsIJSID_GetIdParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_PNSIID ,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor nsIJSID_GetValidParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_BOOL ,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor nsIJSID_EqualsParams[2] = {
|
||||
{XPT_PD_IN, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}}, // fixup index later
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_BOOL ,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor nsIJSID_InitParams[2] = {
|
||||
{XPT_PD_IN, {XPT_TDP_POINTER|TD_PSTRING ,0}},
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_BOOL ,0}}
|
||||
};
|
||||
|
||||
XPTMethodDescriptor nsIJSIDMethods[6] = {
|
||||
{XPT_MD_GETTER, "name", 1, nsIJSID_GetNameParams, ResultParam},
|
||||
{XPT_MD_GETTER, "number", 1, nsIJSID_GetNumberParams, ResultParam},
|
||||
{XPT_MD_GETTER, "id", 1, nsIJSID_GetIdParams, ResultParam},
|
||||
{XPT_MD_GETTER, "valid", 1, nsIJSID_GetValidParams, ResultParam},
|
||||
{0, "equals", 2, nsIJSID_EqualsParams, ResultParam},
|
||||
{0, "init", 2, nsIJSID_InitParams, ResultParam}
|
||||
};
|
||||
|
||||
XPTInterfaceDescriptor nsIJSIDInterfaceDescriptor =
|
||||
{NULL, 6, nsIJSIDMethods, 0, NULL};
|
||||
|
||||
/***************/
|
||||
|
||||
XPTInterfaceDescriptor nsIJSIIDInterfaceDescriptor =
|
||||
{NULL, 0, NULL, 0, NULL};
|
||||
|
||||
/***************/
|
||||
|
||||
XPTParamDescriptor nsIJSCID_NewInstanceParams[1] = {
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {XPT_TDP_POINTER|TD_INTERFACE_TYPE,0}}// fixup index later
|
||||
};
|
||||
|
||||
XPTMethodDescriptor nsIJSCIDMethods[1] = {
|
||||
{0, "newInstance", 1, nsIJSCID_NewInstanceParams, ResultParam}
|
||||
};
|
||||
|
||||
XPTInterfaceDescriptor nsIJSCIDInterfaceDescriptor =
|
||||
{NULL, 1, nsIJSCIDMethods, 0, NULL};
|
||||
|
||||
/***************/
|
||||
|
||||
XPTInterfaceDirectoryEntry InterfaceDirectoryEntryTable[] = {
|
||||
{NS_ISUPPORTS_IID, "nsISupports", "", &nsISupportsInterfaceDescriptor},
|
||||
{NS_ITESTXPC_FOO_IID, "nsITestXPCFoo", "", &nsITestXPCFooInterfaceDescriptor},
|
||||
{NS_ITESTXPC_FOO2_IID, "nsITestXPCFoo2","", &nsITestXPCFoo2InterfaceDescriptor},
|
||||
{NS_IECHO_IID, "nsIEcho", "", &nsIEchoInterfaceDescriptor}
|
||||
{NS_ISUPPORTS_IID, "nsISupports", "", &nsISupportsInterfaceDescriptor},
|
||||
{NS_ITESTXPC_FOO_IID, "nsITestXPCFoo", "", &nsITestXPCFooInterfaceDescriptor},
|
||||
{NS_ITESTXPC_FOO2_IID, "nsITestXPCFoo2", "", &nsITestXPCFoo2InterfaceDescriptor},
|
||||
{NS_IECHO_IID, "nsIEcho", "", &nsIEchoInterfaceDescriptor},
|
||||
{NS_IXPCCOMPONENTS_IID,"nsIXPCComponents","", &nsIXPCComponentsInterfaceDescriptor},
|
||||
{NS_IXPCINTERFACES_IID,"nsIXPCInterfaces","", &nsIXPCInterfacesInterfaceDescriptor},
|
||||
{NS_IXPCCLASSES_IID, "nsIXPCClasses", "", &nsIXPCClassesInterfaceDescriptor},
|
||||
{NS_IJSID_IID, "nsID", "", &nsIJSIDInterfaceDescriptor},
|
||||
{NS_IJSIID_IID, "nsIID", "", &nsIJSIIDInterfaceDescriptor},
|
||||
{NS_IJSCID_IID, "nsCID", "", &nsIJSCIDInterfaceDescriptor},
|
||||
};
|
||||
|
||||
/***************/
|
||||
@ -252,16 +344,23 @@ XPTInterfaceDirectoryEntry InterfaceDirectoryEntryTable[] = {
|
||||
|
||||
static void BogusTableInit()
|
||||
{
|
||||
nsITestXPCFooInterfaceDescriptor.parent_interface =
|
||||
&InterfaceDirectoryEntryTable[0];
|
||||
// NOTE: reference are all off by 1 - '0' means 'none'
|
||||
nsISupportsInterfaceDescriptor.parent_interface = 0;
|
||||
nsITestXPCFooInterfaceDescriptor.parent_interface = 1;
|
||||
nsITestXPCFoo2InterfaceDescriptor.parent_interface = 2;
|
||||
nsIEchoInterfaceDescriptor.parent_interface = 1;
|
||||
nsIXPCComponentsInterfaceDescriptor.parent_interface = 1;
|
||||
nsIXPCInterfacesInterfaceDescriptor.parent_interface = 1;
|
||||
nsIXPCClassesInterfaceDescriptor.parent_interface = 1;
|
||||
nsIJSIDInterfaceDescriptor.parent_interface = 1;
|
||||
nsIJSIIDInterfaceDescriptor.parent_interface = 8;
|
||||
nsIJSCIDInterfaceDescriptor.parent_interface = 8;
|
||||
|
||||
nsITestXPCFoo2InterfaceDescriptor.parent_interface =
|
||||
&InterfaceDirectoryEntryTable[1];
|
||||
|
||||
nsIEchoInterfaceDescriptor.parent_interface =
|
||||
&InterfaceDirectoryEntryTable[0];
|
||||
|
||||
nsIEcho_SetRecieverParams[0].type.type.interface = 3; // fixup index
|
||||
nsIEcho_SetRecieverParams[0].type.type.interface = 4;
|
||||
nsIXPCComponents_GetInterfacesParams[0].type.type.interface = 6;
|
||||
nsIXPCComponents_GetClassesParams[0].type.type.interface = 7;
|
||||
nsIJSID_EqualsParams[0].type.type.interface = 8;
|
||||
nsIJSCID_NewInstanceParams[0].type.type.interface = 1;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
@ -278,7 +377,7 @@ nsXPTParamInfo::GetInterface() const
|
||||
|
||||
nsIInterfaceInfo* info;
|
||||
// not optimal!
|
||||
mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface].iid,
|
||||
mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface-1].iid,
|
||||
&info);
|
||||
NS_RELEASE(mgr);
|
||||
return info;
|
||||
@ -288,7 +387,7 @@ const nsIID*
|
||||
nsXPTParamInfo::GetInterfaceIID() const
|
||||
{
|
||||
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE,"not an interface");
|
||||
return &InterfaceDirectoryEntryTable[type.type.interface].iid;
|
||||
return &InterfaceDirectoryEntryTable[type.type.interface-1].iid;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
@ -362,19 +461,21 @@ InterfaceInfoManagerImpl::~InterfaceInfoManagerImpl()
|
||||
PRBool
|
||||
InterfaceInfoManagerImpl::BuildInterfaceForEntry(uint16 i)
|
||||
{
|
||||
XPTInterfaceDirectoryEntry *parent_interface =
|
||||
uint16 parent_index =
|
||||
InterfaceDirectoryEntryTable[i].interface_descriptor->parent_interface;
|
||||
uint16 parent_index = 0;
|
||||
|
||||
if(parent_interface)
|
||||
if(parent_index)
|
||||
{
|
||||
parent_index = TABLE_INDEX(parent_interface);
|
||||
if(!mInfoArray[parent_index] && ! BuildInterfaceForEntry(parent_index))
|
||||
if(!mInfoArray[parent_index-1] && ! BuildInterfaceForEntry(parent_index-1))
|
||||
return PR_FALSE;
|
||||
mInfoArray[i] = new InterfaceInfoImpl(&InterfaceDirectoryEntryTable[i],
|
||||
mInfoArray[parent_index-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
mInfoArray[i] = new InterfaceInfoImpl(&InterfaceDirectoryEntryTable[i],
|
||||
NULL);
|
||||
}
|
||||
mInfoArray[i] = new InterfaceInfoImpl(&InterfaceDirectoryEntryTable[i],
|
||||
parent_interface ?
|
||||
mInfoArray[parent_index] : NULL);
|
||||
return (PRBool) mInfoArray[i];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user