Bug 882541 part 4. Treat undefined as missing for optional WebIDL arguments. r=khuey,ms2ger

This commit is contained in:
Boris Zbarsky 2013-10-11 12:28:24 -04:00
parent 156b3eac57
commit 4eb56cc9c3
23 changed files with 119 additions and 55 deletions

View File

@ -646,6 +646,10 @@ public:
already_AddRefed<DOMRectList> GetClientRects();
already_AddRefed<DOMRect> GetBoundingClientRect();
void ScrollIntoView()
{
ScrollIntoView(true);
}
void ScrollIntoView(bool aTop);
int32_t ScrollTop()
{

View File

@ -2001,6 +2001,11 @@ 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) const
{
return ImportNode(aNode, true, rv);
}
nsINode* AdoptNode(nsINode& aNode, mozilla::ErrorResult& rv);
already_AddRefed<nsDOMEvent> CreateEvent(const nsAString& aEventType,
mozilla::ErrorResult& rv) const;

View File

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

View File

@ -282,6 +282,13 @@ public:
uint16_t ReadyState();
// request
void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
{
Open(aMethod, aUrl, true,
mozilla::dom::Optional<nsAString>(),
mozilla::dom::Optional<nsAString>(),
aRv);
}
void Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
const mozilla::dom::Optional<nsAString>& aUser,
const mozilla::dom::Optional<nsAString>& aPassword,

View File

@ -27,11 +27,15 @@ function checkDoc(title, expectedtitle, normalizedtitle) {
is(doc.doctype.internalSubset, null, "internalSubset should be null!");
isElement(doc.documentElement, "html");
isElement(doc.documentElement.firstChild, "head");
is(doc.documentElement.firstChild.childNodes.length, 1);
isElement(doc.documentElement.firstChild.firstChild, "title");
// Doesn't always work out in WebKit.
ok(doc.documentElement.firstChild.firstChild.firstChild, "Need a text node.");
is(doc.documentElement.firstChild.firstChild.firstChild.data, expectedtitle);
if (title !== undefined) {
is(doc.documentElement.firstChild.childNodes.length, 1);
isElement(doc.documentElement.firstChild.firstChild, "title");
// Doesn't always work out in WebKit.
ok(doc.documentElement.firstChild.firstChild.firstChild, "Need a text node.");
is(doc.documentElement.firstChild.firstChild.firstChild.data, expectedtitle);
} else {
is(doc.documentElement.firstChild.childNodes.length, 0);
}
isElement(doc.documentElement.lastChild, "body");
is(doc.documentElement.lastChild.childNodes.length, 0);
((!title || title.indexOf("\f") === -1) ? is : todo_is)
@ -41,7 +45,7 @@ function checkDoc(title, expectedtitle, normalizedtitle) {
}
checkDoc("", "", "");
checkDoc(null, "null", "null");
checkDoc(undefined, "undefined", "undefined");
checkDoc(undefined, "", "");
checkDoc("foo bar baz", "foo bar baz", "foo bar baz");
checkDoc("foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz");
checkDoc("foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz");

View File

@ -3348,9 +3348,6 @@ for (uint32_t i = 0; i < length; ++i) {
"Default": "eStringify",
"EmptyString": "eEmpty",
"Null": "eNull",
# For Missing it doesn't matter what we use here, since we'll never
# call ConvertJSValueToString on undefined in that case.
"Missing": "eStringify"
}
if type.nullable():
# For nullable strings null becomes a null string.
@ -3870,11 +3867,8 @@ class CGArgumentConverter(CGThing):
"args[${index}]"
).substitute(replacer)
self.replacementVariables["mutableVal"] = self.replacementVariables["val"]
if argument.treatUndefinedAs == "Missing":
haveValueCheck = "args.hasDefined(${index})"
else:
haveValueCheck = "${index} < args.length()"
haveValueCheck = string.Template(haveValueCheck).substitute(replacer)
haveValueCheck = string.Template(
"args.hasDefined(${index})").substitute(replacer)
self.replacementVariables["haveValue"] = haveValueCheck
self.descriptorProvider = descriptorProvider
if self.argument.optional and not self.argument.defaultValue:

View File

@ -401,12 +401,7 @@ class IDLObjectWithIdentifier(IDLObject):
if isDictionaryMember:
raise WebIDLError("[TreatUndefinedAs] is not allowed for "
"dictionary members", [self.location])
if value == 'Missing':
if not isOptional:
raise WebIDLError("[TreatUndefinedAs=Missing] is only "
"allowed on optional arguments",
[self.location])
elif value == 'Null':
if value == 'Null':
if not self.type.isDOMString():
raise WebIDLError("[TreatUndefinedAs=Null] is only "
"allowed on arguments or "
@ -426,8 +421,8 @@ class IDLObjectWithIdentifier(IDLObject):
[self.location])
else:
raise WebIDLError("[TreatUndefinedAs] must take the "
"identifiers EmptyString or Null or "
"Missing", [self.location])
"identifiers EmptyString or Null",
[self.location])
self.treatUndefinedAs = value
else:
unhandledAttrs.append(attr)

View File

@ -161,9 +161,9 @@ public:
void PassByte(int8_t);
int8_t ReceiveByte();
void PassOptionalByte(const Optional<int8_t>&);
void PassOptionalUndefinedMissingByte(const Optional<int8_t>&);
void PassOptionalByteBeforeRequired(const Optional<int8_t>&, int8_t);
void PassOptionalByteWithDefault(int8_t);
void PassOptionalUndefinedMissingByteWithDefault(int8_t);
void PassOptionalByteWithDefaultBeforeRequired(int8_t, int8_t);
void PassNullableByte(const Nullable<int8_t>&);
void PassOptionalNullableByte(const Optional< Nullable<int8_t> >&);
void PassVariadicByte(const Sequence<int8_t>&);
@ -410,9 +410,7 @@ public:
void PassString(const nsAString&);
void PassNullableString(const nsAString&);
void PassOptionalString(const Optional<nsAString>&);
void PassOptionalUndefinedMissingString(const Optional<nsAString>&);
void PassOptionalStringWithDefaultValue(const nsAString&);
void PassOptionalUndefinedMissingStringWithDefaultValue(const nsAString&);
void PassOptionalNullableString(const Optional<nsAString>&);
void PassOptionalNullableStringWithDefaultValue(const nsAString&);
void PassVariadicString(const Sequence<nsString>&);

View File

@ -118,9 +118,9 @@ interface TestInterface {
void passByte(byte arg);
byte receiveByte();
void passOptionalByte(optional byte arg);
void passOptionalUndefinedMissingByte([TreatUndefinedAs=Missing] optional byte arg);
void passOptionalByteBeforeRequired(optional byte arg1, byte arg2);
void passOptionalByteWithDefault(optional byte arg = 0);
void passOptionalUndefinedMissingByteWithDefault([TreatUndefinedAs=Missing] optional byte arg = 0);
void passOptionalByteWithDefaultBeforeRequired(optional byte arg1 = 0, byte arg2);
void passNullableByte(byte? arg);
void passOptionalNullableByte(optional byte? arg);
void passVariadicByte(byte... arg);
@ -365,9 +365,7 @@ interface TestInterface {
void passString(DOMString arg);
void passNullableString(DOMString? arg);
void passOptionalString(optional DOMString arg);
void passOptionalUndefinedMissingString([TreatUndefinedAs=Missing] optional DOMString arg);
void passOptionalStringWithDefaultValue(optional DOMString arg = "abc");
void passOptionalUndefinedMissingStringWithDefaultValue([TreatUndefinedAs=Missing] optional DOMString arg = "abc");
void passOptionalNullableString(optional DOMString? arg);
void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null);
void passVariadicString(DOMString... arg);

View File

@ -23,9 +23,9 @@ interface TestExampleInterface {
void passByte(byte arg);
byte receiveByte();
void passOptionalByte(optional byte arg);
void passOptionalUndefinedMissingByte([TreatUndefinedAs=Missing] optional byte arg);
void passOptionalByteBeforeRequired(optional byte arg1, byte arg2);
void passOptionalByteWithDefault(optional byte arg = 0);
void passOptionalUndefinedMissingByteWithDefault([TreatUndefinedAs=Missing] optional byte arg = 0);
void passOptionalByteWithDefaultBeforeRequired(optional byte arg1 = 0, byte arg2);
void passNullableByte(byte? arg);
void passOptionalNullableByte(optional byte? arg);
void passVariadicByte(byte... arg);
@ -263,9 +263,7 @@ interface TestExampleInterface {
void passString(DOMString arg);
void passNullableString(DOMString? arg);
void passOptionalString(optional DOMString arg);
void passOptionalUndefinedMissingString([TreatUndefinedAs=Missing] optional DOMString arg);
void passOptionalStringWithDefaultValue(optional DOMString arg = "abc");
void passOptionalUndefinedMissingStringWithDefaultValue([TreatUndefinedAs=Missing] optional DOMString arg = "abc");
void passOptionalNullableString(optional DOMString? arg);
void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null);
void passVariadicString(DOMString... arg);

View File

@ -35,9 +35,9 @@ interface TestJSImplInterface {
void passByte(byte arg);
byte receiveByte();
void passOptionalByte(optional byte arg);
void passOptionalUndefinedMissingByte([TreatUndefinedAs=Missing] optional byte arg);
void passOptionalByteBeforeRequired(optional byte arg1, byte arg2);
void passOptionalByteWithDefault(optional byte arg = 0);
void passOptionalUndefinedMissingByteWithDefault([TreatUndefinedAs=Missing] optional byte arg = 0);
void passOptionalByteWithDefaultBeforeRequired(optional byte arg1 = 0, byte arg2);
void passNullableByte(byte? arg);
void passOptionalNullableByte(optional byte? arg);
void passVariadicByte(byte... arg);
@ -285,9 +285,7 @@ interface TestJSImplInterface {
void passString(DOMString arg);
void passNullableString(DOMString? arg);
void passOptionalString(optional DOMString arg);
void passOptionalUndefinedMissingString([TreatUndefinedAs=Missing] optional DOMString arg);
void passOptionalStringWithDefaultValue(optional DOMString arg = "abc");
void passOptionalUndefinedMissingStringWithDefaultValue([TreatUndefinedAs=Missing] optional DOMString arg = "abc");
void passOptionalNullableString(optional DOMString? arg);
void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null);
void passVariadicString(DOMString... arg);

View File

@ -16,6 +16,7 @@ support-files =
[test_bug788369.html]
[test_bug852846.html]
[test_bug862092.html]
[test_cloneAndImportNode.html]
[test_defineProperty.html]
[test_enums.html]
[test_exceptionThrowing.html]

View File

@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=882541
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 882541</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 882541 **/
var div = document.createElement("div");
div.appendChild(document.createElement("span"));
var div2;
div2 = div.cloneNode();
is(div2.childNodes.length, 1, "cloneNode() should do a deep clone");
div2 = div.cloneNode(undefined);
is(div2.childNodes.length, 0, "cloneNode(undefined) should do a shallow clone");
div2 = document.importNode(div);
is(div2.childNodes.length, 1, "importNode(node) should do a deep import");
div2 = document.importNode(div, undefined);
is(div2.childNodes.length, 0, "cloneNode(undefined) should do a shallow import");
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=882541">Mozilla Bug 882541</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View File

@ -18,17 +18,21 @@ function checkDoc(title, expectedtitle, normalizedtitle) {
assert_equals(doc.doctype.systemId, "")
assert_equals(doc.documentElement.localName, "html")
assert_equals(doc.documentElement.firstChild.localName, "head")
assert_equals(doc.documentElement.firstChild.childNodes.length, 1)
assert_equals(doc.documentElement.firstChild.firstChild.localName, "title")
assert_equals(doc.documentElement.firstChild.firstChild.firstChild.data,
expectedtitle)
if (title !== undefined) {
assert_equals(doc.documentElement.firstChild.childNodes.length, 1)
assert_equals(doc.documentElement.firstChild.firstChild.localName, "title")
assert_equals(doc.documentElement.firstChild.firstChild.firstChild.data,
expectedtitle)
} else {
assert_equals(doc.documentElement.firstChild.childNodes.length, 0)
}
assert_equals(doc.documentElement.lastChild.localName, "body")
assert_equals(doc.documentElement.lastChild.childNodes.length, 0)
})
}
checkDoc("", "", "")
checkDoc(null, "null", "null")
checkDoc(undefined, "undefined", "undefined")
checkDoc(undefined, "", "")
checkDoc("foo bar baz", "foo bar baz", "foo bar baz")
checkDoc("foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz")
checkDoc("foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz")

View File

@ -12,7 +12,7 @@ function checkDoc(title, expectedtitle, normalizedtitle) {
}
checkDoc("", "", "")
checkDoc(null, "null", "null")
checkDoc(undefined, "undefined", "undefined")
checkDoc(undefined, "", "")
checkDoc("foo bar baz", "foo bar baz", "foo bar baz")
checkDoc("foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz")
checkDoc("foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz")

View File

@ -73,7 +73,7 @@ interface CanvasRenderingContext2D {
// path API (see also CanvasPathMethods)
void beginPath();
void fill([TreatUndefinedAs=Missing] optional CanvasWindingRule winding = "nonzero");
void fill(optional CanvasWindingRule winding = "nonzero");
// NOT IMPLEMENTED void fill(Path path);
void stroke();
// NOT IMPLEMENTED void stroke(Path path);
@ -83,10 +83,10 @@ interface CanvasRenderingContext2D {
// NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, Element element);
// NOT IMPLEMENTED void scrollPathIntoView();
// NOT IMPLEMENTED void scrollPathIntoView(Path path);
void clip([TreatUndefinedAs=Missing] optional CanvasWindingRule winding = "nonzero");
void clip(optional CanvasWindingRule winding = "nonzero");
// NOT IMPLEMENTED void clip(Path path);
// NOT IMPLEMENTED void resetClip();
boolean isPointInPath(unrestricted double x, unrestricted double y, [TreatUndefinedAs=Missing] optional CanvasWindingRule winding = "nonzero");
boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
// NOT IMPLEMENTED boolean isPointInPath(Path path, unrestricted double x, unrestricted double y);
boolean isPointInStroke(double x, double y);

View File

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

View File

@ -141,7 +141,8 @@ partial interface Element {
DOMRect getBoundingClientRect();
// scrolling
void scrollIntoView(optional boolean top = true);
void scrollIntoView();
void scrollIntoView(boolean top);
// None of the CSSOM attributes are [Pure], because they flush
attribute long scrollTop; // scroll on setting
attribute long scrollLeft; // scroll on setting

View File

@ -68,7 +68,9 @@ interface Node : EventTarget {
void normalize();
[Throws]
Node cloneNode(optional boolean deep = true);
Node cloneNode();
[Throws]
Node cloneNode(boolean deep);
boolean isEqualNode(Node? node);
const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01;

View File

@ -28,9 +28,9 @@ interface Promise {
static Promise reject(any value);
[NewObject]
Promise then([TreatUndefinedAs=Missing] optional AnyCallback fulfillCallback,
[TreatUndefinedAs=Missing] optional AnyCallback rejectCallback);
Promise then(optional AnyCallback fulfillCallback,
optional AnyCallback rejectCallback);
[NewObject]
Promise catch([TreatUndefinedAs=Missing] optional AnyCallback rejectCallback);
Promise catch(optional AnyCallback rejectCallback);
};

View File

@ -71,7 +71,9 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
// request
[Throws]
void open(ByteString method, DOMString url, optional boolean async = true,
void open(ByteString method, DOMString url);
[Throws]
void open(ByteString method, DOMString url, boolean async,
optional DOMString? user, optional DOMString? password);
[Throws]
void setRequestHeader(ByteString header, ByteString value);

View File

@ -121,6 +121,11 @@ public:
return mStateData.mReadyState;
}
void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
{
Open(aMethod, aUrl, true, Optional<nsAString>(),
Optional<nsAString>(), aRv);
}
void
Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
const Optional<nsAString>& aUser, const Optional<nsAString>& aPassword,

View File

@ -52,7 +52,7 @@ function run_test()
// Test sync XHR sending
cu.evalInSandbox('var createXHR = ' + createXHR.toString(), sb);
var res = cu.evalInSandbox('var sync = createXHR("4444/simple"); sync.send(null); sync', sb);
checkResults(res);
do_check_true(checkResults(res));
// negative test sync XHR sending (to ensure that the xhr do not have chrome caps, see bug 779821)
try {