Bug 705320 - Use IDL for xpcIJSWeakReference.get; r=bholley

This commit is contained in:
Ms2ger 2011-11-26 11:32:03 +01:00
parent 9713252f34
commit 7ff45c8468
2 changed files with 28 additions and 44 deletions

View File

@ -36,7 +36,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
[scriptable, uuid(5b776cd4-952b-45a2-b363-84e99e8fe608)] [scriptable, uuid(75767928-ecb1-4e6c-9f55-c118b297fcef)]
interface xpcIJSWeakReference : nsISupports interface xpcIJSWeakReference : nsISupports
{ {
/** /**
@ -45,5 +45,5 @@ interface xpcIJSWeakReference : nsISupports
* Returns the referenced JS object or null if the JS object has * Returns the referenced JS object or null if the JS object has
* been garbage collected. * been garbage collected.
*/ */
void /* JSObject */ get(); [implicit_jscontext] jsval get();
}; };

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -93,50 +93,34 @@ nsresult xpcJSWeakReference::Init()
} }
NS_IMETHODIMP NS_IMETHODIMP
xpcJSWeakReference::Get() xpcJSWeakReference::Get(JSContext* aCx, JS::Value* aRetval)
{ {
nsresult rv; *aRetval = JSVAL_NULL;
nsXPConnect* xpc = nsXPConnect::GetXPConnect(); if (!mWrappedJSObject) {
if (!xpc) return NS_OK;
return NS_ERROR_UNEXPECTED;
nsAXPCNativeCallContext* cc = nsnull;
rv = xpc->GetCurrentNativeCallContext(&cc);
NS_ENSURE_SUCCESS(rv, rv);
JSContext *cx;
cc->GetJSContext(&cx);
if (!cx)
return NS_ERROR_UNEXPECTED;
jsval *retval = nsnull;
cc->GetRetValPtr(&retval);
if (!retval)
return NS_ERROR_UNEXPECTED;
*retval = JSVAL_NULL;
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj;
if (mWrappedJSObject &&
NS_SUCCEEDED(mWrappedJSObject->QueryReferent(NS_GET_IID(nsIXPConnectWrappedJS), getter_AddRefs(wrappedObj))) &&
wrappedObj) {
JSObject *obj;
wrappedObj->GetJSObject(&obj);
if (obj) {
// Most users of XPCWrappedJS don't need to worry about
// re-wrapping because things are implicitly rewrapped by
// xpcconvert. However, because we're doing this directly
// through the native call context, we need to call
// JS_WrapObject().
if (!JS_WrapObject(cx, &obj)) {
return NS_ERROR_FAILURE;
}
*retval = OBJECT_TO_JSVAL(obj);
}
} }
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryReferent(mWrappedJSObject);
if (!wrappedObj) {
return NS_OK;
}
JSObject *obj;
wrappedObj->GetJSObject(&obj);
if (!obj) {
return NS_OK;
}
// Most users of XPCWrappedJS don't need to worry about
// re-wrapping because things are implicitly rewrapped by
// xpcconvert. However, because we're doing this directly
// through the native call context, we need to call
// JS_WrapObject().
if (!JS_WrapObject(aCx, &obj)) {
return NS_ERROR_FAILURE;
}
*aRetval = OBJECT_TO_JSVAL(obj);
return NS_OK; return NS_OK;
} }