Backout merge, a=backout

This commit is contained in:
Johnny Stenback 2010-12-02 23:36:23 -08:00
commit 3d42f123d1
4 changed files with 51 additions and 37 deletions

View File

@ -192,18 +192,20 @@ public:
static nsresult Init();
/**
* Get a scope from aNewDocument. Also get a context through the scope of one
* of the documents, from the stack or the safe context.
* 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.
*
* @param aOldDocument The document to try to get a context from. May be null.
* @param aOldDocument The document to get aOldScope from.
* @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 GetContextAndScope(nsIDocument *aOldDocument,
nsIDocument *aNewDocument,
JSContext **aCx, JSObject **aNewScope);
static nsresult GetContextAndScopes(nsIDocument *aOldDocument,
nsIDocument *aNewDocument,
JSContext **aCx, JSObject **aOldScope,
JSObject **aNewScope);
/**
* When a document's scope changes (e.g., from document.open(), call this

View File

@ -1371,17 +1371,22 @@ nsContentUtils::InProlog(nsINode *aNode)
}
static JSContext *
GetContextFromDocument(nsIDocument *aDocument)
GetContextFromDocument(nsIDocument *aDocument, JSObject** aGlobalObject)
{
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 scope...
// No context left in the old scope...
return nsnull;
}
@ -1391,27 +1396,39 @@ GetContextFromDocument(nsIDocument *aDocument)
// static
nsresult
nsContentUtils::GetContextAndScope(nsIDocument *aOldDocument,
nsIDocument *aNewDocument, JSContext **aCx,
JSObject **aNewScope)
nsContentUtils::GetContextAndScopes(nsIDocument *aOldDocument,
nsIDocument *aNewDocument, JSContext **aCx,
JSObject **aOldScope, JSObject **aNewScope)
{
*aCx = nsnull;
*aOldScope = nsnull;
*aNewScope = nsnull;
JSObject *newScope = aNewDocument->GetWrapper();
JSObject *global;
if (!newScope) {
nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject();
if (!newSGO || !(global = newSGO->GetGlobalJSObject())) {
return NS_OK;
}
JSObject *newScope = nsnull;
nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject();
if (!newSGO || !(newScope = newSGO->GetGlobalJSObject())) {
return NS_OK;
}
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_INITIALIZED);
JSContext *cx = aOldDocument ? GetContextFromDocument(aOldDocument) : nsnull;
// 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;
}
if (!cx) {
cx = GetContextFromDocument(aNewDocument);
JSObject *dummy;
cx = GetContextFromDocument(aNewDocument, &dummy);
if (!cx) {
// No context reachable from the old or new document, use the
@ -1433,15 +1450,8 @@ nsContentUtils::GetContextAndScope(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;

View File

@ -268,15 +268,16 @@ nsDOMDocumentType::BindToTree(nsIDocument *aDocument, nsIContent *aParent,
mNodeInfo.swap(newNodeInfo);
JSObject *oldScope = GetWrapper();
if (oldScope) {
nsCOMPtr<nsIDocument> oldOwnerDoc =
do_QueryInterface(nsContentUtils::GetDocumentFromContext());
nsIDocument *newOwnerDoc = nimgr->GetDocument();
if (oldOwnerDoc && newOwnerDoc) {
nsIXPConnect *xpc = nsContentUtils::XPConnect();
JSContext *cx = nsnull;
JSObject *newScope = nsnull;
nsresult rv = nsContentUtils::GetContextAndScope(nsnull,
nimgr->GetDocument(),
&cx, &newScope);
JSObject *oldScope = nsnull, *newScope = nsnull;
nsresult rv = nsContentUtils::GetContextAndScopes(oldOwnerDoc, newOwnerDoc, &cx,
&oldScope, &newScope);
if (cx && xpc) {
nsISupports *node = NS_ISUPPORTS_CAST(nsIContent*, this);
nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper;

View File

@ -6082,10 +6082,11 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
PRBool sameDocument = oldDocument == this;
JSContext *cx = nsnull;
JSObject *oldScope = adoptedNode->GetWrapper();
JSObject *oldScope = nsnull;
JSObject *newScope = nsnull;
if (oldScope && !sameDocument) {
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
if (!sameDocument && oldDocument) {
rv = nsContentUtils::GetContextAndScopes(oldDocument, this, &cx, &oldScope,
&newScope);
NS_ENSURE_SUCCESS(rv, rv);
}