Bug 937461. Make cloneNode/importNode "deep" arg default to false, since the spec changed on us. r=sicking

This commit is contained in:
Boris Zbarsky 2013-12-20 14:28:17 -05:00
Родитель af85370b7e
Коммит c388b489bd
12 изменённых файлов: 17 добавлений и 46 удалений

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

@ -38,6 +38,4 @@ DEPRECATED_OPERATION(UseOfCaptureEvents)
DEPRECATED_OPERATION(UseOfReleaseEvents)
DEPRECATED_OPERATION(UseOfDOM3LoadMethod)
DEPRECATED_OPERATION(ShowModalDialog)
DEPRECATED_OPERATION(UnsafeCloneNode)
DEPRECATED_OPERATION(UnsafeImportNode)
DEPRECATED_OPERATION(Window_Content)

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

@ -2016,15 +2016,6 @@ public:
mozilla::ErrorResult& rv) const;
already_AddRefed<nsINode>
ImportNode(nsINode& aNode, bool aDeep, mozilla::ErrorResult& rv) const;
already_AddRefed<nsINode>
ImportNode(nsINode& aNode, mozilla::ErrorResult& rv)
{
if (aNode.HasChildNodes()) {
// Flag it as an error, not a warning, to make people actually notice.
WarnOnceAbout(eUnsafeImportNode, true);
}
return ImportNode(aNode, true, rv);
}
nsINode* AdoptNode(nsINode& aNode, mozilla::ErrorResult& rv);
already_AddRefed<nsDOMEvent> CreateEvent(const nsAString& aEventType,
mozilla::ErrorResult& rv) const;

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

@ -1546,7 +1546,6 @@ public:
return ReplaceOrInsertBefore(true, &aNode, &aChild, aError);
}
nsINode* RemoveChild(nsINode& aChild, mozilla::ErrorResult& aError);
already_AddRefed<nsINode> CloneNode(mozilla::ErrorResult& aError);
already_AddRefed<nsINode> CloneNode(bool aDeep, mozilla::ErrorResult& aError);
bool IsEqualNode(nsINode* aNode);
void GetNamespaceURI(nsAString& aNamespaceURI) const

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

@ -2624,17 +2624,6 @@ nsINode::CloneNode(bool aDeep, ErrorResult& aError)
return result.forget();
}
already_AddRefed<nsINode>
nsINode::CloneNode(mozilla::ErrorResult& aError)
{
if (HasChildNodes()) {
// Flag it as an error, not a warning, to make people actually notice.
OwnerDoc()->WarnOnceAbout(nsIDocument::eUnsafeCloneNode, true);
}
return CloneNode(true, aError);
}
nsDOMAttributeMap*
nsINode::GetAttributes()
{

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

@ -41,11 +41,11 @@
// Test Node.cloneNode when no arguments are given
clonedNode = hasChildren.cloneNode();
is(clonedNode.hasChildNodes(), true, "Node.cloneNode with true " +
"default on a node with children clones the child nodes.");
is(clonedNode.hasChildNodes(), false, "Node.cloneNode with false " +
"default on a node with children does not clone the child nodes.");
clonedNode = noChildren.cloneNode();
is(clonedNode.hasChildNodes(), false, "Node.cloneNode with true " +
is(clonedNode.hasChildNodes(), false, "Node.cloneNode with false " +
"default on a node without children doesn't clone child nodes." );
SimpleTest.finish();

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

@ -17,16 +17,22 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=882541
var div2;
div2 = div.cloneNode();
is(div2.childNodes.length, 1, "cloneNode() should do a deep clone");
is(div2.childNodes.length, 0, "cloneNode() should do a shallow clone");
div2 = div.cloneNode(undefined);
is(div2.childNodes.length, 0, "cloneNode(undefined) should do a shallow clone");
div2 = div.cloneNode(true);
is(div2.childNodes.length, 1, "cloneNode(true) should do a deep clone");
div2 = document.importNode(div);
is(div2.childNodes.length, 1, "importNode(node) should do a deep import");
is(div2.childNodes.length, 0, "importNode(node) should do a deep import");
div2 = document.importNode(div, undefined);
is(div2.childNodes.length, 0, "cloneNode(undefined) should do a shallow import");
is(div2.childNodes.length, 0, "importNode(undefined) should do a shallow import");
div2 = document.importNode(div, true);
is(div2.childNodes.length, 1, "importNode(true) should do a deep import");
</script>
</head>

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

@ -16,7 +16,7 @@ test(function() {
assert_equals(div.ownerDocument, doc);
assert_equals(div.firstChild.ownerDocument, doc);
assert_equals(newDiv.ownerDocument, document);
assert_equals(newDiv.firstChild.ownerDocument, document);
assert_equals(newDiv.firstChild, null);
}, "No 'deep' argument.")
test(function() {
var doc = document.implementation.createHTMLDocument("Title");

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

@ -142,9 +142,5 @@ UseOfReleaseEventsWarning=Use of releaseEvents() is deprecated. To upgrade your
UseOfDOM3LoadMethodWarning=Use of document.load() is deprecated. To upgrade your code, use the DOM XMLHttpRequest object. For more help https://developer.mozilla.org/en/XMLHttpRequest
# LOCALIZATION NOTE: Do not translate "window.showModalDialog()" or "window.open()"
ShowModalDialogWarning=Use of window.showModalDialog() is deprecated. Use window.open() instead. For more help https://developer.mozilla.org/en-US/docs/Web/API/Window.open
# LOCALIZATION NOTE: Do not translate "cloneNode()"
UnsafeCloneNodeWarning=The behavior of cloneNode() with no boolean argument is about to change from doing a deep clone to doing a shallow clone. Make sure to pass an explicit boolean argument to keep your current behavior.
# LOCALIZATION NOTE: Do not translate "importNode()"
UnsafeImportNodeWarning=The behavior of importNode() with no boolean argument is about to change from doing a deep clone to doing a shallow clone. Make sure to pass an explicit boolean argument to keep your current behavior.
# LOCALIZATION NOTE: Do not translate "window._content" or "window.content"
Window_ContentWarning=window._content is deprecated. Please use window.content instead.

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

@ -23,8 +23,8 @@ var d = document.createElement("div");
d.innerHTML = "<span>hello </span><span>world</span>";
var imported = document.importNode(d);
is(imported.childNodes.length, 2, "Should have cloned child nodes!");
is(imported.textContent, "hello world", "Should have cloned text!");
is(imported.childNodes.length, 0, "Should not have cloned child nodes with no deep arg!");
is(imported.textContent, "", "Should not have cloned text with no deep arg!");
imported = document.importNode(d, true);
is(imported.childNodes.length, 2, "Should have cloned child nodes!");

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

@ -66,9 +66,7 @@ interface Document : Node {
ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
[Throws]
Node importNode(Node node, boolean deep);
[Throws]
Node importNode(Node node);
Node importNode(Node node, optional boolean deep = false);
[Throws]
Node adoptNode(Node node);

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

@ -69,9 +69,7 @@ interface Node : EventTarget {
void normalize();
[Throws]
Node cloneNode();
[Throws]
Node cloneNode(boolean deep);
Node cloneNode(optional boolean deep = false);
[Pure]
boolean isEqualNode(Node? node);

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

@ -142,9 +142,5 @@ UseOfReleaseEventsWarning=Use of releaseEvents() is deprecated. To upgrade your
UseOfDOM3LoadMethodWarning=Use of document.load() is deprecated. To upgrade your code, use the DOM XMLHttpRequest object. For more help https://developer.mozilla.org/en/XMLHttpRequest
# LOCALIZATION NOTE: Do not translate "window.showModalDialog()" or "window.open()"
ShowModalDialogWarning=Use of window.showModalDialog() is deprecated. Use window.open() instead. For more help https://developer.mozilla.org/en-US/docs/Web/API/Window.open
# LOCALIZATION NOTE: Do not translate "cloneNode()"
UnsafeCloneNodeWarning=The behavior of cloneNode() with no boolean argument is about to change from doing a deep clone to doing a shallow clone. Make sure to pass an explicit boolean argument to keep your current behavior.
# LOCALIZATION NOTE: Do not translate "importNode()"
UnsafeImportNodeWarning=The behavior of importNode() with no boolean argument is about to change from doing a deep clone to doing a shallow clone. Make sure to pass an explicit boolean argument to keep your current behavior.
# LOCALIZATION NOTE: Do not translate "window._content" or "window.content"
Window_ContentWarning=window._content is deprecated. Please use window.content instead.