Bug 826305 - Makes .valueAsDate assignment throw if a not a Date nor null is passed. Passing null reset the value. r=bz

This commit is contained in:
Mounir Lamouri 2013-01-07 15:20:18 +00:00
Родитель 80c99ff08f
Коммит 44036ffa6b
2 изменённых файлов: 25 добавлений и 1 удалений

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

@ -1325,9 +1325,15 @@ nsHTMLInputElement::SetValueAsDate(JSContext* aCtx, const jsval& aDate)
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
if (aDate.isNullOrUndefined()) {
return SetValue(EmptyString());
}
// TODO: return TypeError when HTMLInputElement is converted to WebIDL, see
// bug 826302.
if (!aDate.isObject() || !JS_ObjectIsDate(aCtx, &aDate.toObject())) {
SetValue(EmptyString());
return NS_OK;
return NS_ERROR_INVALID_ARG;
}
JSObject& date = aDate.toObject();

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

@ -189,9 +189,27 @@ function checkSet()
+ data[1]);
}
element.value = "test";
element.valueAsDate = null;
is(element.value, "", "valueAsDate should set the value to the empty string");
element.value = "test";
element.valueAsDate = undefined;
is(element.value, "", "valueAsDate should set the value to the empty string");
var illegalValues = [
"foobar", 42, {}, function() { return 42; }, function() { return Date(); }
];
for (value of illegalValues) {
try {
var caught = false;
element.valueAsDate = value;
} catch(e) {
caught = true;
}
ok(caught, "Assigning " + value + " to .valueAsDate should throw");
}
}
function checkWithBustedPrototype()