mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 605672. Fix reason for invalid scope assertion. r=jst@mozilla.com, a=blocker.
This commit is contained in:
parent
906eb73d10
commit
e5ba6a8e5b
@ -192,20 +192,18 @@ public:
|
||||
static nsresult Init();
|
||||
|
||||
/**
|
||||
* Get a scope from aOldDocument and one from aNewDocument. Also get a
|
||||
* context through one of the scopes, from the stack or the safe context.
|
||||
* Get a scope from aNewDocument. Also get a context through the scope of one
|
||||
* of the documents, from the stack or the safe context.
|
||||
*
|
||||
* @param aOldDocument The document to get aOldScope from.
|
||||
* @param aOldDocument The document to try to get a context from. May be null.
|
||||
* @param aNewDocument The document to get aNewScope from.
|
||||
* @param aCx [out] Context gotten through one of the scopes, from the stack
|
||||
* or the safe context.
|
||||
* @param aOldScope [out] Scope gotten from aOldDocument.
|
||||
* @param aNewScope [out] Scope gotten from aNewDocument.
|
||||
*/
|
||||
static nsresult GetContextAndScopes(nsIDocument *aOldDocument,
|
||||
nsIDocument *aNewDocument,
|
||||
JSContext **aCx, JSObject **aOldScope,
|
||||
JSObject **aNewScope);
|
||||
static nsresult GetContextAndScope(nsIDocument *aOldDocument,
|
||||
nsIDocument *aNewDocument,
|
||||
JSContext **aCx, JSObject **aNewScope);
|
||||
|
||||
/**
|
||||
* When a document's scope changes (e.g., from document.open(), call this
|
||||
|
@ -1371,22 +1371,17 @@ nsContentUtils::InProlog(nsINode *aNode)
|
||||
}
|
||||
|
||||
static JSContext *
|
||||
GetContextFromDocument(nsIDocument *aDocument, JSObject** aGlobalObject)
|
||||
GetContextFromDocument(nsIDocument *aDocument)
|
||||
{
|
||||
nsIScriptGlobalObject *sgo = aDocument->GetScopeObject();
|
||||
if (!sgo) {
|
||||
// No script global, no context.
|
||||
|
||||
*aGlobalObject = nsnull;
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
*aGlobalObject = sgo->GetGlobalJSObject();
|
||||
|
||||
nsIScriptContext *scx = sgo->GetContext();
|
||||
if (!scx) {
|
||||
// No context left in the old scope...
|
||||
// No context left in the scope...
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
@ -1396,39 +1391,27 @@ GetContextFromDocument(nsIDocument *aDocument, JSObject** aGlobalObject)
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsContentUtils::GetContextAndScopes(nsIDocument *aOldDocument,
|
||||
nsIDocument *aNewDocument, JSContext **aCx,
|
||||
JSObject **aOldScope, JSObject **aNewScope)
|
||||
nsContentUtils::GetContextAndScope(nsIDocument *aOldDocument,
|
||||
nsIDocument *aNewDocument, JSContext **aCx,
|
||||
JSObject **aNewScope)
|
||||
{
|
||||
*aCx = nsnull;
|
||||
*aOldScope = nsnull;
|
||||
*aNewScope = nsnull;
|
||||
|
||||
JSObject *newScope = nsnull;
|
||||
nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject();
|
||||
if (!newSGO || !(newScope = newSGO->GetGlobalJSObject())) {
|
||||
return NS_OK;
|
||||
JSObject *newScope = aNewDocument->GetWrapper();
|
||||
JSObject *global;
|
||||
if (!newScope) {
|
||||
nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject();
|
||||
if (!newSGO || !(global = newSGO->GetGlobalJSObject())) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
// Make sure to get our hands on the right scope object, since
|
||||
// GetWrappedNativeOfNativeObject doesn't call PreCreate and hence won't get
|
||||
// the right scope if we pass in something bogus. The right scope lives on
|
||||
// the script global of the old document.
|
||||
// XXXbz note that if GetWrappedNativeOfNativeObject did call PreCreate it
|
||||
// would get the wrong scope (that of the _new_ document), so we should be
|
||||
// glad it doesn't!
|
||||
JSObject *oldScope = nsnull;
|
||||
JSContext *cx = GetContextFromDocument(aOldDocument, &oldScope);
|
||||
|
||||
if (!oldScope) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JSContext *cx = aOldDocument ? GetContextFromDocument(aOldDocument) : nsnull;
|
||||
if (!cx) {
|
||||
JSObject *dummy;
|
||||
cx = GetContextFromDocument(aNewDocument, &dummy);
|
||||
cx = GetContextFromDocument(aNewDocument);
|
||||
|
||||
if (!cx) {
|
||||
// No context reachable from the old or new document, use the
|
||||
@ -1450,8 +1433,15 @@ nsContentUtils::GetContextAndScopes(nsIDocument *aOldDocument,
|
||||
}
|
||||
}
|
||||
|
||||
if (!newScope && cx) {
|
||||
jsval v;
|
||||
nsresult rv = WrapNative(cx, global, aNewDocument, aNewDocument, &v);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
newScope = JSVAL_TO_OBJECT(v);
|
||||
}
|
||||
|
||||
*aCx = cx;
|
||||
*aOldScope = oldScope;
|
||||
*aNewScope = newScope;
|
||||
|
||||
return NS_OK;
|
||||
|
@ -268,16 +268,15 @@ nsDOMDocumentType::BindToTree(nsIDocument *aDocument, nsIContent *aParent,
|
||||
|
||||
mNodeInfo.swap(newNodeInfo);
|
||||
|
||||
nsCOMPtr<nsIDocument> oldOwnerDoc =
|
||||
do_QueryInterface(nsContentUtils::GetDocumentFromContext());
|
||||
nsIDocument *newOwnerDoc = nimgr->GetDocument();
|
||||
if (oldOwnerDoc && newOwnerDoc) {
|
||||
JSObject *oldScope = GetWrapper();
|
||||
if (oldScope) {
|
||||
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
||||
|
||||
JSContext *cx = nsnull;
|
||||
JSObject *oldScope = nsnull, *newScope = nsnull;
|
||||
nsresult rv = nsContentUtils::GetContextAndScopes(oldOwnerDoc, newOwnerDoc, &cx,
|
||||
&oldScope, &newScope);
|
||||
JSObject *newScope = nsnull;
|
||||
nsresult rv = nsContentUtils::GetContextAndScope(nsnull,
|
||||
nimgr->GetDocument(),
|
||||
&cx, &newScope);
|
||||
if (cx && xpc) {
|
||||
nsISupports *node = NS_ISUPPORTS_CAST(nsIContent*, this);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper;
|
||||
|
@ -6082,11 +6082,10 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
|
||||
PRBool sameDocument = oldDocument == this;
|
||||
|
||||
JSContext *cx = nsnull;
|
||||
JSObject *oldScope = nsnull;
|
||||
JSObject *oldScope = adoptedNode->GetWrapper();
|
||||
JSObject *newScope = nsnull;
|
||||
if (!sameDocument && oldDocument) {
|
||||
rv = nsContentUtils::GetContextAndScopes(oldDocument, this, &cx, &oldScope,
|
||||
&newScope);
|
||||
if (oldScope && !sameDocument) {
|
||||
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user