Followup fix for bug 605672 (Fix reason for invalid scope assertion). r=jst, a=blocker.

This commit is contained in:
Peter Van der Beken 2010-12-03 15:20:57 -08:00
parent 44964980b2
commit 778af83d66
3 changed files with 20 additions and 28 deletions

View File

@ -6082,16 +6082,15 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
PRBool sameDocument = oldDocument == this;
JSContext *cx = nsnull;
JSObject *oldScope = adoptedNode->GetWrapper();
JSObject *newScope = nsnull;
if (oldScope && !sameDocument) {
if (!sameDocument) {
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMArray<nsINode> nodesWithProperties;
rv = nsNodeUtils::Adopt(adoptedNode, sameDocument ? nsnull : mNodeInfoManager,
cx, oldScope, newScope, nodesWithProperties);
cx, newScope, nodesWithProperties);
if (NS_FAILED(rv)) {
// Disconnect all nodes from their parents, since some have the old document
// as their ownerDocument and some have this as their ownerDocument.

View File

@ -444,15 +444,14 @@ nsNodeUtils::CloneNodeImpl(nsINode *aNode, PRBool aDeep, nsIDOMNode **aResult)
nsresult
nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
JSContext *aCx, JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsINode **aResult)
{
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aCx,
"If cloning or not getting a new nodeinfo we shouldn't "
"rewrap");
NS_PRECONDITION(!aCx || (aOldScope && aNewScope), "Must have scopes");
NS_PRECONDITION(!aCx || aNewScope, "Must have new scope");
NS_PRECONDITION(!aParent || aNode->IsNodeOfType(nsINode::eCONTENT),
"Can't insert document or attribute nodes into a parent");
@ -463,7 +462,8 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
// attributes and children).
nsresult rv;
if (aCx) {
JSObject *wrapper;
if (aCx && (wrapper = aNode->GetWrapper())) {
rv = xpc_MorphSlimWrapper(aCx, aNode);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -582,11 +582,9 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
elem->RecompileScriptEventListeners();
}
if (aCx) {
if (aCx && wrapper) {
nsIXPConnect *xpc = nsContentUtils::XPConnect();
if (xpc) {
nsWrapperCache *cache;
CallQueryInterface(aNode, &cache);
JSObject *preservedWrapper = nsnull;
// If reparenting moves us to a new compartment, preserving causes
@ -594,17 +592,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
// reparenting so we're sure to have the right JS object preserved.
// We use a JSObject stack copy of the wrapper to protect it from GC
// under ReparentWrappedNativeIfFound.
if (cache && cache->PreservingWrapper()) {
preservedWrapper = cache->GetWrapper();
nsContentUtils::ReleaseWrapper(aNode, cache);
if (aNode->PreservingWrapper()) {
preservedWrapper = wrapper;
nsContentUtils::ReleaseWrapper(aNode, aNode);
}
nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper;
rv = xpc->ReparentWrappedNativeIfFound(aCx, aOldScope, aNewScope, aNode,
rv = xpc->ReparentWrappedNativeIfFound(aCx, wrapper, aNewScope, aNode,
getter_AddRefs(oldWrapper));
if (preservedWrapper) {
nsContentUtils::PreserveWrapper(aNode, cache);
nsContentUtils::PreserveWrapper(aNode, aNode);
}
if (NS_FAILED(rv)) {
@ -648,8 +646,8 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
for (i = 0; i < length; ++i) {
nsCOMPtr<nsINode> child;
rv = CloneAndAdopt(aNode->GetChildAt(i), aClone, PR_TRUE, nodeInfoManager,
aCx, aOldScope, aNewScope, aNodesWithProperties,
clone, getter_AddRefs(child));
aCx, aNewScope, aNodesWithProperties, clone,
getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
}
}

View File

@ -172,7 +172,7 @@ public:
nsIDOMNode **aResult)
{
return CloneAndAdopt(aNode, PR_TRUE, aDeep, aNewNodeInfoManager, nsnull,
nsnull, nsnull, aNodesWithProperties, aResult);
nsnull, aNodesWithProperties, aResult);
}
/**
@ -190,18 +190,16 @@ public:
* @param aCx Context to use for reparenting the wrappers, or null if no
* reparenting should be done. Must be null if aNewNodeInfoManager
* is null.
* @param aOldScope Old scope for the wrappers. May be null if aCx is null.
* @param aNewScope New scope for the wrappers. May be null if aCx is null.
* @param aNodesWithProperties All nodes (from amongst aNode and its
* descendants) with properties.
*/
static nsresult Adopt(nsINode *aNode, nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
JSContext *aCx, JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties)
{
nsresult rv = CloneAndAdopt(aNode, PR_FALSE, PR_TRUE, aNewNodeInfoManager,
aCx, aOldScope, aNewScope, aNodesWithProperties,
aCx, aNewScope, aNodesWithProperties,
nsnull);
nsMutationGuard::DidMutate();
@ -277,7 +275,6 @@ private:
* @param aCx Context to use for reparenting the wrappers, or null if no
* reparenting should be done. Must be null if aClone is PR_TRUE or
* if aNewNodeInfoManager is null.
* @param aOldScope Old scope for the wrappers. May be null if aCx is null.
* @param aNewScope New scope for the wrappers. May be null if aCx is null.
* @param aNodesWithProperties All nodes (from amongst aNode and its
* descendants) with properties. If aClone is
@ -288,8 +285,7 @@ private:
*/
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
JSContext *aCx, JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsIDOMNode **aResult)
{
@ -299,7 +295,7 @@ private:
nsCOMPtr<nsINode> clone;
nsresult rv = CloneAndAdopt(aNode, aClone, aDeep, aNewNodeInfoManager,
aCx, aOldScope, aNewScope, aNodesWithProperties,
aCx, aNewScope, aNodesWithProperties,
nsnull, getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
@ -317,8 +313,7 @@ private:
*/
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
nsNodeInfoManager *aNewNodeInfoManager,
JSContext *aCx, JSObject *aOldScope,
JSObject *aNewScope,
JSContext *aCx, JSObject *aNewScope,
nsCOMArray<nsINode> &aNodesWithProperties,
nsINode *aParent, nsINode **aResult);
};