зеркало из https://github.com/mozilla/pjs.git
Make sure to hold on to our JS wrapper after wrapping it so it doesn't get
GC'ed out from under us. Bug 307279, r=jst, sr=brendan
This commit is contained in:
Родитель
046c62d43f
Коммит
c6971b938d
|
@ -1327,8 +1327,11 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
|
|||
// static
|
||||
nsresult
|
||||
nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
|
||||
const nsIID& aIID, jsval *vp)
|
||||
const nsIID& aIID, jsval *vp,
|
||||
nsIXPConnectJSObjectHolder **aHolder)
|
||||
{
|
||||
*aHolder = nsnull;
|
||||
|
||||
if (!native) {
|
||||
*vp = JSVAL_NULL;
|
||||
|
||||
|
@ -1347,6 +1350,7 @@ nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
holder.swap(*aHolder);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -1368,8 +1372,9 @@ nsDOMClassInfo::ThrowJSException(JSContext *cx, nsresult aResult)
|
|||
rv = xm->GetExceptionFromProvider(aResult, 0, getter_AddRefs(exception));
|
||||
|
||||
jsval jv;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, ::JS_GetGlobalObject(cx), exception,
|
||||
NS_GET_IID(nsIException), &jv);
|
||||
NS_GET_IID(nsIException), &jv, getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
JS_SetPendingException(cx, jv);
|
||||
|
||||
|
@ -3818,7 +3823,9 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
|
|||
|
||||
if (result) {
|
||||
jsval v;
|
||||
nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), &v);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), &v,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(jsstr),
|
||||
|
@ -3999,8 +4006,10 @@ nsWindowSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
|
||||
nsGlobalWindow *frameWin = (nsGlobalWindow *)frame.get();
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, frameWin->GetGlobalJSObject(), frame,
|
||||
NS_GET_IID(nsIDOMWindow), vp);
|
||||
NS_GET_IID(nsIDOMWindow), vp,
|
||||
getter_AddRefs(holder));
|
||||
}
|
||||
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
|
@ -4134,7 +4143,9 @@ nsWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
rv = location->SetHref(nsDependentJSString(val));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp,
|
||||
getter_AddRefs(holder));
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
|
||||
|
@ -4331,8 +4342,9 @@ BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = nsDOMGenericSH::WrapNative(cx, obj, native, NS_GET_IID(nsISupports),
|
||||
rval);
|
||||
rval, getter_AddRefs(holder));
|
||||
|
||||
return NS_SUCCEEDED(rv) ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
|
@ -5389,6 +5401,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
|||
|
||||
jsval prop_val; // Property value.
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(native));
|
||||
if (owner) {
|
||||
nsIScriptContext *context = nsJSUtils::GetStaticScriptContext(cx, obj);
|
||||
|
@ -5411,7 +5424,8 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
|||
scope = aWin->GetGlobalJSObject();
|
||||
}
|
||||
|
||||
rv = WrapNative(cx, scope, native, NS_GET_IID(nsISupports), &prop_val);
|
||||
rv = WrapNative(cx, scope, native, NS_GET_IID(nsISupports), &prop_val,
|
||||
getter_AddRefs(holder));
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -5649,8 +5663,10 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
wrapper->GetJSObject(&wrapperObj);
|
||||
|
||||
jsval v;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, wrapperObj, child_win,
|
||||
NS_GET_IID(nsIDOMWindowInternal), &v);
|
||||
NS_GET_IID(nsIDOMWindowInternal), &v,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Script is accessing a child frame and this access can
|
||||
|
@ -5760,7 +5776,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
}
|
||||
|
||||
jsval v;
|
||||
rv = WrapNative(cx, scope, location, NS_GET_IID(nsIDOMLocation), &v);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, scope, location, NS_GET_IID(nsIDOMLocation), &v,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool doSecurityCheckInAddProperty = sDoSecurityCheckInAddProperty;
|
||||
|
@ -5808,7 +5826,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
jsval v;
|
||||
rv = WrapNative(cx, obj, navigator, NS_GET_IID(nsIDOMNavigator), &v);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, navigator, NS_GET_IID(nsIDOMNavigator), &v,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str),
|
||||
|
@ -5828,11 +5848,14 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
jsval v;
|
||||
rv = WrapNative(cx, obj, document, NS_GET_IID(nsIDOMDocument), &v);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, document, NS_GET_IID(nsIDOMDocument), &v,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// The PostCreate hook for the document will handle defining the
|
||||
// property *objp = obj;
|
||||
// property
|
||||
*objp = obj;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -6122,8 +6145,10 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
|||
// globalObj for now...
|
||||
|
||||
jsval v;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = WrapNative(cx, globalObj, native_parent,
|
||||
NS_GET_IID(nsISupports), &v);
|
||||
NS_GET_IID(nsISupports), &v,
|
||||
getter_AddRefs(holder));
|
||||
|
||||
*parentObj = JSVAL_TO_OBJECT(v);
|
||||
|
||||
|
@ -6599,7 +6624,9 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (array_item) {
|
||||
rv = WrapNative(cx, obj, array_item, NS_GET_IID(nsISupports), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, array_item, NS_GET_IID(nsISupports), vp,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
|
@ -6637,7 +6664,9 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (item) {
|
||||
rv = WrapNative(cx, obj, item, NS_GET_IID(nsISupports), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, item, NS_GET_IID(nsISupports), vp,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
|
@ -6736,8 +6765,10 @@ nsContentListSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
|
|||
}
|
||||
|
||||
jsval v;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = WrapNative(cx, globalObj, native_parent,
|
||||
NS_GET_IID(nsISupports), &v);
|
||||
NS_GET_IID(nsISupports), &v,
|
||||
getter_AddRefs(holder));
|
||||
|
||||
*parentObj = JSVAL_TO_OBJECT(v);
|
||||
|
||||
|
@ -6897,7 +6928,9 @@ nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
|
||||
jsval v;
|
||||
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), &v);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), &v,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool doSecurityCheckInAddProperty = sDoSecurityCheckInAddProperty;
|
||||
|
@ -7005,7 +7038,9 @@ nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
rv = location->SetHref(nsDependentJSString(val));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp,
|
||||
getter_AddRefs(holder));
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
}
|
||||
|
@ -7049,7 +7084,9 @@ nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
if (SameCOMIdentity(doc, currentDoc)) {
|
||||
jsval winVal;
|
||||
|
||||
nsresult rv = WrapNative(cx, obj, win, NS_GET_IID(nsIDOMWindow), &winVal);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = WrapNative(cx, obj, win, NS_GET_IID(nsIDOMWindow), &winVal,
|
||||
getter_AddRefs(holder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(doc_str, "document");
|
||||
|
@ -7150,7 +7187,9 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, JSObject *obj, uintN argc,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
rv = WrapNative(cx, obj, retval, NS_GET_IID(nsIDOMDocument), rval);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, retval, NS_GET_IID(nsIDOMDocument), rval,
|
||||
getter_AddRefs(holder));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to wrap native!");
|
||||
|
||||
return NS_SUCCEEDED(rv);
|
||||
|
@ -7223,8 +7262,10 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx, JSObject *obj,
|
|||
|
||||
rv |= domdoc->GetElementsByTagName(NS_LITERAL_STRING("*"), nodeList);
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv |= nsDOMClassInfo::WrapNative(cx, obj, *nodeList,
|
||||
NS_GET_IID(nsISupports), &collection);
|
||||
NS_GET_IID(nsISupports), &collection,
|
||||
getter_AddRefs(holder));
|
||||
|
||||
// ... and store it in our reserved slot.
|
||||
if (!JS_SetReservedSlot(cx, obj, 0, collection)) {
|
||||
|
@ -7340,8 +7381,9 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSObject *obj,
|
|||
}
|
||||
|
||||
if (result) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = nsDOMClassInfo::WrapNative(cx, obj, result, NS_GET_IID(nsISupports),
|
||||
vp);
|
||||
vp, getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
|
||||
|
@ -7606,8 +7648,10 @@ nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSObject *obj,
|
|||
|
||||
if (tags) {
|
||||
jsval v;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = nsDOMClassInfo::WrapNative(cx, obj, tags,
|
||||
NS_GET_IID(nsISupports), &v);
|
||||
NS_GET_IID(nsISupports), &v,
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) {
|
||||
nsDOMClassInfo::ThrowJSException(cx, rv);
|
||||
|
||||
|
@ -7767,7 +7811,9 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (result) {
|
||||
rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp,
|
||||
getter_AddRefs(holder));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
|
@ -7906,7 +7952,9 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
if (result) {
|
||||
// Wrap result, result can be either an element or a list of
|
||||
// elements
|
||||
nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = WrapNative(cx, obj, result, NS_GET_IID(nsISupports), vp,
|
||||
getter_AddRefs(holder));
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
}
|
||||
|
@ -7921,7 +7969,9 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
form->GetElementAt(n, getter_AddRefs(control));
|
||||
|
||||
if (control) {
|
||||
nsresult rv = WrapNative(cx, obj, control, NS_GET_IID(nsISupports), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = WrapNative(cx, obj, control, NS_GET_IID(nsISupports), vp,
|
||||
getter_AddRefs(holder));
|
||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
}
|
||||
|
@ -8026,7 +8076,9 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
|||
|
||||
options->Item(n, getter_AddRefs(node));
|
||||
|
||||
rv = WrapNative(cx, obj, node, NS_GET_IID(nsIDOMNode), vp);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, node, NS_GET_IID(nsIDOMNode), vp,
|
||||
getter_AddRefs(holder));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = NS_SUCCESS_I_DID_SOMETHING;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче