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 17:43:32 +01:00
Родитель 0e6ed3b062
Коммит 0e1be10fa8
3 изменённых файлов: 20 добавлений и 28 удалений

Просмотреть файл

@ -6090,16 +6090,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.

Просмотреть файл

@ -446,15 +446,14 @@ nsNodeUtils::CloneNodeImpl(nsINode *aNode, PRBool aDeep,
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");
@ -465,7 +464,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);
}
@ -584,11 +584,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
@ -596,17 +594,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)) {
@ -650,8 +648,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);
}
}

Просмотреть файл

@ -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();
@ -279,7 +277,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
@ -290,8 +287,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)
{
@ -301,7 +297,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);
@ -319,8 +315,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);
};