Bug 223536 - Exposing XPConnect jsval <-> nsIVariant to conversion functionality

r=dbradley, sr=jst
This commit is contained in:
BradleyJunk%cinci.rr.com 2004-04-19 20:05:39 +00:00
Родитель c46426b646
Коммит a093a5222d
2 изменённых файлов: 50 добавлений и 0 удалений

Просмотреть файл

@ -23,6 +23,7 @@
*
* Contributor(s):
* John Bandhauer <jband@netscape.com> (original author)
* Nate Nielsen <nielsen@memberwebs.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -48,6 +49,7 @@
#include "nsIInterfaceInfo.idl"
#include "nsIInterfaceInfoManager.idl"
#include "nsIExceptionService.idl"
#include "nsIVariant.idl"
%{ C++
#include "jspubtd.h"
@ -592,4 +594,7 @@ interface nsIXPConnect : nsISupports
attribute PRBool deferReleasesUntilAfterGarbageCollection;
void releaseJSContext(in JSContextPtr aJSContext, in PRBool noGC);
JSVal variantToJS(in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value);
nsIVariant variantFromJS(in JSContextPtr ctx, in JSVal value);
};

Просмотреть файл

@ -24,6 +24,7 @@
* Contributor(s):
* John Bandhauer <jband@netscape.com> (original author)
* Pierre Phaneuf <pp@ludusdesign.com>
* Nate Nielsen <nielsen@memberwebs.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -1212,6 +1213,50 @@ nsXPConnect::DebugDumpEvalInJSStackFrame(PRUint32 aFrameNumber, const char *aSou
return NS_OK;
}
/* JSVal variantToJS (in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value); */
NS_IMETHODIMP
nsXPConnect::VariantToJS(JSContext* ctx, JSObject* scope, nsIVariant* value, jsval* _retval)
{
NS_PRECONDITION(ctx, "bad param");
NS_PRECONDITION(scope, "bad param");
NS_PRECONDITION(value, "bad param");
NS_PRECONDITION(_retval, "bad param");
XPCCallContext ccx(NATIVE_CALLER, ctx);
if(!ccx.IsValid())
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
if(!XPCVariant::VariantDataToJS(ccx, value, scope, &rv, _retval))
{
if(NS_FAILED(rv))
return rv;
return NS_ERROR_FAILURE;
}
return NS_OK;
}
/* nsIVariant variantFromJS (in JSContextPtr ctx, in JSVal value); */
NS_IMETHODIMP
nsXPConnect::VariantFromJS(JSContext* ctx, jsval value, nsIVariant** _retval)
{
NS_PRECONDITION(ctx, "bad param");
NS_PRECONDITION(value, "bad param");
NS_PRECONDITION(_retval, "bad param");
XPCCallContext ccx(NATIVE_CALLER, ctx);
if(!ccx.IsValid())
return NS_ERROR_FAILURE;
*_retval = XPCVariant::newVariant(ccx, value);
if(!(*_retval))
return NS_ERROR_FAILURE;
return NS_OK;
}
#ifdef DEBUG
/* These are here to be callable from a debugger */
JS_BEGIN_EXTERN_C