Bug 223536 - Exposing XPConnect jsval <-> nsIVariant to conversion functionality. r=dbradley, sr=jst
git-svn-id: svn://10.0.0.236/trunk@155434 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
cbc875baaf
commit
f87ebb5a14
@ -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 JSToVariant(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 JSToVariant (in JSContextPtr ctx, in JSVal value); */
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::JSToVariant(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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user