Bug 956455, part 2 - Remove holder argument from WrapNativeToJSVal nsDOMClassInfo. r=smaug

This commit is contained in:
Andrew McCreight 2014-01-06 11:54:43 -08:00
parent bd11c4fff8
commit 155249efc8

View File

@ -606,11 +606,9 @@ IdToString(JSContext *cx, jsid id)
static inline nsresult
WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
nsWrapperCache *cache, const nsIID* aIID, JS::MutableHandle<JS::Value> vp,
nsIXPConnectJSObjectHolder** aHolder, bool aAllowWrapping)
bool aAllowWrapping)
{
if (!native) {
NS_ASSERTION(!aHolder || !*aHolder, "*aHolder should be null!");
vp.setNull();
return NS_OK;
@ -624,42 +622,30 @@ WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
return nsDOMClassInfo::XPConnect()->WrapNativeToJSVal(cx, scope, native,
cache, aIID,
aAllowWrapping, vp.address(),
aHolder);
nullptr);
}
static inline nsresult
WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
const nsIID* aIID, bool aAllowWrapping, JS::MutableHandle<JS::Value> vp,
// If non-null aHolder will keep the jsval alive
// while there's a ref to it
nsIXPConnectJSObjectHolder** aHolder = nullptr)
const nsIID* aIID, bool aAllowWrapping, JS::MutableHandle<JS::Value> vp)
{
return WrapNative(cx, scope, native, nullptr, aIID, vp, aHolder,
aAllowWrapping);
return WrapNative(cx, scope, native, nullptr, aIID, vp, aAllowWrapping);
}
// Same as the WrapNative above, but use these if aIID is nsISupports' IID.
static inline nsresult
WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
bool aAllowWrapping, JS::MutableHandle<JS::Value> vp,
// If non-null aHolder will keep the jsval alive
// while there's a ref to it
nsIXPConnectJSObjectHolder** aHolder = nullptr)
bool aAllowWrapping, JS::MutableHandle<JS::Value> vp)
{
return WrapNative(cx, scope, native, nullptr, nullptr, vp, aHolder,
aAllowWrapping);
return WrapNative(cx, scope, native, nullptr, nullptr, vp, aAllowWrapping);
}
static inline nsresult
WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
nsWrapperCache *cache, bool aAllowWrapping,
JS::MutableHandle<JS::Value> vp,
// If non-null aHolder will keep the jsval alive
// while there's a ref to it
nsIXPConnectJSObjectHolder** aHolder = nullptr)
JS::MutableHandle<JS::Value> vp)
{
return WrapNative(cx, scope, native, cache, nullptr, vp, aHolder,
aAllowWrapping);
return WrapNative(cx, scope, native, cache, nullptr, vp, aAllowWrapping);
}
// Helper to handle torn-down inner windows.
@ -2154,10 +2140,9 @@ BaseStubConstructor(nsIWeakReference* aWeakOwner,
JS::AutoValueVector argv(cx);
argv.resize(argc);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsCOMPtr<nsIDOMWindow> currentWin(do_GetInterface(currentInner));
rv = WrapNative(cx, obj, currentWin, &NS_GET_IID(nsIDOMWindow),
true, argv.handleAt(0), getter_AddRefs(holder));
true, argv.handleAt(0));
if (!JS_WrapValue(cx, argv.handleAt(0)))
return NS_ERROR_FAILURE;
@ -2743,11 +2728,10 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
getter_AddRefs(constructor));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
JS::Rooted<JS::Value> v(cx);
rv = WrapNative(cx, obj, constructor, &NS_GET_IID(nsIDOMDOMConstructor),
false, &v, getter_AddRefs(holder));
false, &v);
NS_ENSURE_SUCCESS(rv, rv);
if (install) {
@ -2755,8 +2739,7 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
NS_ENSURE_SUCCESS(rv, rv);
}
JS::Rooted<JSObject*> class_obj(cx, holder->GetJSObject());
NS_ASSERTION(class_obj, "The return value lied");
JS::Rooted<JSObject*> class_obj(cx, &v.toObject());
const nsIID *primary_iid = &NS_GET_IID(nsISupports);
@ -3026,17 +3009,15 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
getter_AddRefs(constructor));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
JS::Rooted<JS::Value> v(cx);
rv = WrapNative(cx, obj, constructor, &NS_GET_IID(nsIDOMDOMConstructor),
false, &v, getter_AddRefs(holder));
false, &v);
NS_ENSURE_SUCCESS(rv, rv);
rv = constructor->Install(cx, obj, v);
NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JSObject*> class_obj(cx, holder->GetJSObject());
NS_ASSERTION(class_obj, "The return value lied");
JS::Rooted<JSObject*> class_obj(cx, &v.toObject());
// ... and define the constants from the DOM interface on that
// constructor object.
@ -3129,15 +3110,14 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> val(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, obj, constructor, &NS_GET_IID(nsIDOMDOMConstructor),
false, &val, getter_AddRefs(holder));
false, &val);
NS_ENSURE_SUCCESS(rv, rv);
rv = constructor->Install(cx, obj, val);
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(holder->GetJSObject(), "Why didn't we get a JSObject?");
NS_ASSERTION(val.isObject(), "Why didn't we get a JSObject?");
*did_resolve = true;
@ -3161,7 +3141,6 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
JS::Rooted<JS::Value> prop_val(cx, JS::UndefinedValue()); // Property value.
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
if (gpi) {
rv = gpi->Init(aWin, prop_val.address());
@ -3180,8 +3159,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
scope = aWin->GetGlobalJSObject();
}
rv = WrapNative(cx, scope, native, true, &prop_val,
getter_AddRefs(holder));
rv = WrapNative(cx, scope, native, true, &prop_val);
}
NS_ENSURE_SUCCESS(rv, rv);
@ -3244,10 +3222,8 @@ LocationSetterGuts(JSContext *cx, JSObject *obj, JS::MutableHandle<JS::Value> vp
// We have to wrap location into vp before null-checking location, to
// avoid assigning the wrong thing into the slot.
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, JS::CurrentGlobalOrNull(cx), location,
&NS_GET_IID(nsIDOMLocation), true, vp,
getter_AddRefs(holder));
&NS_GET_IID(nsIDOMLocation), true, vp);
NS_ENSURE_SUCCESS(rv, rv);
if (!location) {
@ -3468,10 +3444,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// Make sure we wrap the location object in the window's scope.
JS::Rooted<JSObject*> scope(cx, wrapper->GetJSObject());
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
JS::Rooted<JS::Value> v(cx);
rv = WrapNative(cx, scope, location, &NS_GET_IID(nsIDOMLocation), true,
&v, getter_AddRefs(holder));
rv = WrapNative(cx, scope, location, &NS_GET_IID(nsIDOMLocation), true, &v);
NS_ENSURE_SUCCESS(rv, rv);
bool ok = JS_WrapValue(cx, &v) &&
@ -3494,9 +3468,7 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> v(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, obj, top, &NS_GET_IID(nsIDOMWindow), true,
&v, getter_AddRefs(holder));
rv = WrapNative(cx, obj, top, &NS_GET_IID(nsIDOMWindow), true, &v);
NS_ENSURE_SUCCESS(rv, rv);
// Hold on to the top window object as a global property so we
@ -3523,10 +3495,8 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
if (!(flags & JSRESOLVE_ASSIGNING) && sDocument_id == id) {
nsCOMPtr<nsIDocument> document = win->GetDoc();
JS::Rooted<JS::Value> v(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, JS::CurrentGlobalOrNull(cx), document, document,
&NS_GET_IID(nsIDOMDocument), &v, getter_AddRefs(holder),
false);
&NS_GET_IID(nsIDOMDocument), &v, false);
NS_ENSURE_SUCCESS(rv, rv);
// nsIDocument::WrapObject will handle defining the property.
@ -3933,10 +3903,9 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx,
rv = NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult tmp = WrapNative(cx, JS::CurrentGlobalOrNull(cx),
static_cast<nsINodeList*>(list), list, false,
&collection, getter_AddRefs(holder));
&collection);
if (NS_FAILED(tmp)) {
rv = tmp;
}