зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 605672 (Fix reason for invalid scope assertion). r=jst, a=blocker.
This commit is contained in:
Родитель
0e6ed3b062
Коммит
0e1be10fa8
|
@ -6090,16 +6090,15 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
|
||||||
PRBool sameDocument = oldDocument == this;
|
PRBool sameDocument = oldDocument == this;
|
||||||
|
|
||||||
JSContext *cx = nsnull;
|
JSContext *cx = nsnull;
|
||||||
JSObject *oldScope = adoptedNode->GetWrapper();
|
|
||||||
JSObject *newScope = nsnull;
|
JSObject *newScope = nsnull;
|
||||||
if (oldScope && !sameDocument) {
|
if (!sameDocument) {
|
||||||
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
|
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMArray<nsINode> nodesWithProperties;
|
nsCOMArray<nsINode> nodesWithProperties;
|
||||||
rv = nsNodeUtils::Adopt(adoptedNode, sameDocument ? nsnull : mNodeInfoManager,
|
rv = nsNodeUtils::Adopt(adoptedNode, sameDocument ? nsnull : mNodeInfoManager,
|
||||||
cx, oldScope, newScope, nodesWithProperties);
|
cx, newScope, nodesWithProperties);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
// Disconnect all nodes from their parents, since some have the old document
|
// Disconnect all nodes from their parents, since some have the old document
|
||||||
// as their ownerDocument and some have this as their ownerDocument.
|
// as their ownerDocument and some have this as their ownerDocument.
|
||||||
|
|
|
@ -446,15 +446,14 @@ nsNodeUtils::CloneNodeImpl(nsINode *aNode, PRBool aDeep,
|
||||||
nsresult
|
nsresult
|
||||||
nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
||||||
nsNodeInfoManager *aNewNodeInfoManager,
|
nsNodeInfoManager *aNewNodeInfoManager,
|
||||||
JSContext *aCx, JSObject *aOldScope,
|
JSContext *aCx, JSObject *aNewScope,
|
||||||
JSObject *aNewScope,
|
|
||||||
nsCOMArray<nsINode> &aNodesWithProperties,
|
nsCOMArray<nsINode> &aNodesWithProperties,
|
||||||
nsINode *aParent, nsINode **aResult)
|
nsINode *aParent, nsINode **aResult)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aCx,
|
NS_PRECONDITION((!aClone && aNewNodeInfoManager) || !aCx,
|
||||||
"If cloning or not getting a new nodeinfo we shouldn't "
|
"If cloning or not getting a new nodeinfo we shouldn't "
|
||||||
"rewrap");
|
"rewrap");
|
||||||
NS_PRECONDITION(!aCx || (aOldScope && aNewScope), "Must have scopes");
|
NS_PRECONDITION(!aCx || aNewScope, "Must have new scope");
|
||||||
NS_PRECONDITION(!aParent || aNode->IsNodeOfType(nsINode::eCONTENT),
|
NS_PRECONDITION(!aParent || aNode->IsNodeOfType(nsINode::eCONTENT),
|
||||||
"Can't insert document or attribute nodes into a parent");
|
"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).
|
// attributes and children).
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (aCx) {
|
JSObject *wrapper;
|
||||||
|
if (aCx && (wrapper = aNode->GetWrapper())) {
|
||||||
rv = xpc_MorphSlimWrapper(aCx, aNode);
|
rv = xpc_MorphSlimWrapper(aCx, aNode);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
@ -584,11 +584,9 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
||||||
elem->RecompileScriptEventListeners();
|
elem->RecompileScriptEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aCx) {
|
if (aCx && wrapper) {
|
||||||
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
||||||
if (xpc) {
|
if (xpc) {
|
||||||
nsWrapperCache *cache;
|
|
||||||
CallQueryInterface(aNode, &cache);
|
|
||||||
JSObject *preservedWrapper = nsnull;
|
JSObject *preservedWrapper = nsnull;
|
||||||
|
|
||||||
// If reparenting moves us to a new compartment, preserving causes
|
// 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.
|
// 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
|
// We use a JSObject stack copy of the wrapper to protect it from GC
|
||||||
// under ReparentWrappedNativeIfFound.
|
// under ReparentWrappedNativeIfFound.
|
||||||
if (cache && cache->PreservingWrapper()) {
|
if (aNode->PreservingWrapper()) {
|
||||||
preservedWrapper = cache->GetWrapper();
|
preservedWrapper = wrapper;
|
||||||
nsContentUtils::ReleaseWrapper(aNode, cache);
|
nsContentUtils::ReleaseWrapper(aNode, aNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper;
|
nsCOMPtr<nsIXPConnectJSObjectHolder> oldWrapper;
|
||||||
rv = xpc->ReparentWrappedNativeIfFound(aCx, aOldScope, aNewScope, aNode,
|
rv = xpc->ReparentWrappedNativeIfFound(aCx, wrapper, aNewScope, aNode,
|
||||||
getter_AddRefs(oldWrapper));
|
getter_AddRefs(oldWrapper));
|
||||||
|
|
||||||
if (preservedWrapper) {
|
if (preservedWrapper) {
|
||||||
nsContentUtils::PreserveWrapper(aNode, cache);
|
nsContentUtils::PreserveWrapper(aNode, aNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
@ -650,8 +648,8 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
||||||
for (i = 0; i < length; ++i) {
|
for (i = 0; i < length; ++i) {
|
||||||
nsCOMPtr<nsINode> child;
|
nsCOMPtr<nsINode> child;
|
||||||
rv = CloneAndAdopt(aNode->GetChildAt(i), aClone, PR_TRUE, nodeInfoManager,
|
rv = CloneAndAdopt(aNode->GetChildAt(i), aClone, PR_TRUE, nodeInfoManager,
|
||||||
aCx, aOldScope, aNewScope, aNodesWithProperties,
|
aCx, aNewScope, aNodesWithProperties, clone,
|
||||||
clone, getter_AddRefs(child));
|
getter_AddRefs(child));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ public:
|
||||||
nsIDOMNode **aResult)
|
nsIDOMNode **aResult)
|
||||||
{
|
{
|
||||||
return CloneAndAdopt(aNode, PR_TRUE, aDeep, aNewNodeInfoManager, nsnull,
|
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
|
* @param aCx Context to use for reparenting the wrappers, or null if no
|
||||||
* reparenting should be done. Must be null if aNewNodeInfoManager
|
* reparenting should be done. Must be null if aNewNodeInfoManager
|
||||||
* is null.
|
* 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 aNewScope New scope for the wrappers. May be null if aCx is null.
|
||||||
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
||||||
* descendants) with properties.
|
* descendants) with properties.
|
||||||
*/
|
*/
|
||||||
static nsresult Adopt(nsINode *aNode, nsNodeInfoManager *aNewNodeInfoManager,
|
static nsresult Adopt(nsINode *aNode, nsNodeInfoManager *aNewNodeInfoManager,
|
||||||
JSContext *aCx, JSObject *aOldScope,
|
JSContext *aCx, JSObject *aNewScope,
|
||||||
JSObject *aNewScope,
|
|
||||||
nsCOMArray<nsINode> &aNodesWithProperties)
|
nsCOMArray<nsINode> &aNodesWithProperties)
|
||||||
{
|
{
|
||||||
nsresult rv = CloneAndAdopt(aNode, PR_FALSE, PR_TRUE, aNewNodeInfoManager,
|
nsresult rv = CloneAndAdopt(aNode, PR_FALSE, PR_TRUE, aNewNodeInfoManager,
|
||||||
aCx, aOldScope, aNewScope, aNodesWithProperties,
|
aCx, aNewScope, aNodesWithProperties,
|
||||||
nsnull);
|
nsnull);
|
||||||
|
|
||||||
nsMutationGuard::DidMutate();
|
nsMutationGuard::DidMutate();
|
||||||
|
@ -279,7 +277,6 @@ private:
|
||||||
* @param aCx Context to use for reparenting the wrappers, or null if no
|
* @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
|
* reparenting should be done. Must be null if aClone is PR_TRUE or
|
||||||
* if aNewNodeInfoManager is 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 aNewScope New scope for the wrappers. May be null if aCx is null.
|
||||||
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
* @param aNodesWithProperties All nodes (from amongst aNode and its
|
||||||
* descendants) with properties. If aClone is
|
* descendants) with properties. If aClone is
|
||||||
|
@ -290,8 +287,7 @@ private:
|
||||||
*/
|
*/
|
||||||
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
||||||
nsNodeInfoManager *aNewNodeInfoManager,
|
nsNodeInfoManager *aNewNodeInfoManager,
|
||||||
JSContext *aCx, JSObject *aOldScope,
|
JSContext *aCx, JSObject *aNewScope,
|
||||||
JSObject *aNewScope,
|
|
||||||
nsCOMArray<nsINode> &aNodesWithProperties,
|
nsCOMArray<nsINode> &aNodesWithProperties,
|
||||||
nsIDOMNode **aResult)
|
nsIDOMNode **aResult)
|
||||||
{
|
{
|
||||||
|
@ -301,7 +297,7 @@ private:
|
||||||
|
|
||||||
nsCOMPtr<nsINode> clone;
|
nsCOMPtr<nsINode> clone;
|
||||||
nsresult rv = CloneAndAdopt(aNode, aClone, aDeep, aNewNodeInfoManager,
|
nsresult rv = CloneAndAdopt(aNode, aClone, aDeep, aNewNodeInfoManager,
|
||||||
aCx, aOldScope, aNewScope, aNodesWithProperties,
|
aCx, aNewScope, aNodesWithProperties,
|
||||||
nsnull, getter_AddRefs(clone));
|
nsnull, getter_AddRefs(clone));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
@ -319,8 +315,7 @@ private:
|
||||||
*/
|
*/
|
||||||
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
static nsresult CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
|
||||||
nsNodeInfoManager *aNewNodeInfoManager,
|
nsNodeInfoManager *aNewNodeInfoManager,
|
||||||
JSContext *aCx, JSObject *aOldScope,
|
JSContext *aCx, JSObject *aNewScope,
|
||||||
JSObject *aNewScope,
|
|
||||||
nsCOMArray<nsINode> &aNodesWithProperties,
|
nsCOMArray<nsINode> &aNodesWithProperties,
|
||||||
nsINode *aParent, nsINode **aResult);
|
nsINode *aParent, nsINode **aResult);
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче