зеркало из https://github.com/mozilla/pjs.git
Outerize |this| always. bug 418069, r/sr=jst/brendan a=beltzner
This commit is contained in:
Родитель
6d7eab4c3f
Коммит
4867a6b528
|
@ -6294,8 +6294,8 @@ NS_IMETHODIMP
|
|||
nsWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
||||
JSObject * obj, JSObject * *_retval)
|
||||
{
|
||||
nsGlobalWindow *win =
|
||||
nsGlobalWindow::FromWrapper(wrapper)->GetOuterWindowInternal();
|
||||
nsGlobalWindow *origWin = nsGlobalWindow::FromWrapper(wrapper);
|
||||
nsGlobalWindow *win = origWin->GetOuterWindowInternal();
|
||||
|
||||
if (!win) {
|
||||
// If we no longer have an outer window. No code should ever be
|
||||
|
@ -6311,22 +6311,37 @@ nsWindowSH::OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
|||
|
||||
// Return the outer window.
|
||||
|
||||
// FIXME bug 420372: Our window should always have a JS object here. It
|
||||
// doesn't because of nsJSContext::FindXPCNativeWrapperClass.
|
||||
nsresult rv;
|
||||
if (win->IsChromeWindow()) {
|
||||
// Chrome windows don't get XOW wrapping.
|
||||
*_retval = win->GetGlobalJSObject();
|
||||
JSObject *outerObj = win->GetGlobalJSObject();
|
||||
if (!outerObj) {
|
||||
NS_ASSERTION(origWin->IsOuterWindow(), "What window is this?");
|
||||
*_retval = obj;
|
||||
} else {
|
||||
*_retval = outerObj;
|
||||
}
|
||||
|
||||
rv = NS_OK;
|
||||
} else {
|
||||
JSObject *winObj = win->GetGlobalJSObject();
|
||||
JSObject *scope = JS_GetScopeChain(cx);
|
||||
if (!scope) {
|
||||
*_retval = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
if (!winObj) {
|
||||
NS_ASSERTION(origWin->IsOuterWindow(), "What window is this?");
|
||||
*_retval = obj;
|
||||
rv = NS_OK;
|
||||
} else {
|
||||
JSObject *scope = JS_GetScopeChain(cx);
|
||||
if (!scope) {
|
||||
*_retval = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
scope = ::JS_GetGlobalForObject(cx, scope);
|
||||
jsval v;
|
||||
rv = sXPConnect->GetXOWForObject(cx, scope, winObj, &v);
|
||||
*_retval = NS_SUCCEEDED(rv) ? JSVAL_TO_OBJECT(v) : nsnull;
|
||||
}
|
||||
scope = ::JS_GetGlobalForObject(cx, scope);
|
||||
jsval v;
|
||||
rv = sXPConnect->GetXOWForObject(cx, scope, winObj, &v);
|
||||
*_retval = NS_SUCCEEDED(rv) ? JSVAL_TO_OBJECT(v) : nsnull;
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -7655,7 +7670,7 @@ nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
nsIDOMDocument* currentDoc = win->GetExtantDocument();
|
||||
|
||||
if (SameCOMIdentity(doc, currentDoc)) {
|
||||
jsval winVal, docVal;
|
||||
jsval winVal;
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = WrapNative(cx, obj, win, NS_GET_IID(nsIDOMWindow), &winVal,
|
||||
|
|
|
@ -949,13 +949,9 @@ ComputeGlobalThis(JSContext *cx, JSBool lazy, jsval *argv)
|
|||
thisp = parent;
|
||||
}
|
||||
|
||||
clasp = OBJ_GET_CLASS(cx, thisp);
|
||||
if (clasp->flags & JSCLASS_IS_EXTENDED) {
|
||||
JSExtendedClass *xclasp = (JSExtendedClass *) clasp;
|
||||
if (xclasp->outerObject && !(thisp = xclasp->outerObject(cx, thisp)))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OBJ_TO_OUTER_OBJECT(cx, thisp);
|
||||
if (!thisp)
|
||||
return NULL;
|
||||
argv[-1] = OBJECT_TO_JSVAL(thisp);
|
||||
return thisp;
|
||||
}
|
||||
|
@ -981,6 +977,9 @@ ComputeThis(JSContext *cx, JSBool lazy, jsval *argv)
|
|||
if (!thisp)
|
||||
return NULL;
|
||||
}
|
||||
OBJ_TO_OUTER_OBJECT(cx, thisp);
|
||||
if (!thisp)
|
||||
return NULL;
|
||||
argv[-1] = OBJECT_TO_JSVAL(thisp);
|
||||
}
|
||||
return thisp;
|
||||
|
|
|
@ -110,6 +110,16 @@ struct JSObjectMap {
|
|||
} \
|
||||
JS_END_MACRO
|
||||
|
||||
#define OBJ_TO_OUTER_OBJECT(cx,obj) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \
|
||||
if (clasp_->flags & JSCLASS_IS_EXTENDED) { \
|
||||
JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \
|
||||
if (xclasp_->outerObject) \
|
||||
obj = xclasp_->outerObject(cx, obj); \
|
||||
} \
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_INITIAL_NSLOTS 6
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче