зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
80c99ff08f
Коммит
44036ffa6b
|
@ -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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче