WebCore/ChangeLog

 12010-05-02 Yael Aharon <yael.aharon@nokia.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Use HTML5 number parsing in HTMLProgressElement
 6 https://bugs.webkit.org/show_bug.cgi?id=38434
 7
 8 Use parseToDoubleForNumberType instead of toDouble.
 9 Throw an exception when the number is NaN or Infinity.
 10
 11 * html/HTMLProgressElement.cpp:
 12 (WebCore::HTMLProgressElement::value):
 13 (WebCore::HTMLProgressElement::setValue):
 14 (WebCore::HTMLProgressElement::max):
 15 (WebCore::HTMLProgressElement::setMax):
 16 * html/HTMLProgressElement.h:
 17 * html/HTMLProgressElement.idl:
 18
1192010-05-02 Jarkko Sakkinen <jarkko.j.sakkinen@gmail.com>
220
321 Reviewed by Eric Seidel.
58653

WebCore/html/HTMLProgressElement.cpp

2626#include "FormDataList.h"
2727#include "HTMLFormElement.h"
2828#include "HTMLNames.h"
 29#include "HTMLParser.h"
2930#include "MappedAttribute.h"
3031#include "RenderProgress.h"
3132#include <wtf/StdLibExtras.h>

@@void HTMLProgressElement::parseMappedAtt
7172double HTMLProgressElement::value() const
7273{
7374 const AtomicString& valueString = getAttribute(valueAttr);
74  bool ok;
75  double value = valueString.toDouble(&ok);
 75 double value;
 76 bool ok = parseToDoubleForNumberType(valueString, &value);
7677 if (!ok || value < 0)
7778 return valueString.isNull() ? 1 : 0;
7879 return (value > max()) ? max() : value;
7980}
8081
81 void HTMLProgressElement::setValue(double value)
 82void HTMLProgressElement::setValue(double value, ExceptionCode& ec)
8283{
 84 if (isnan(value) || !isfinite(value)) {
 85 ec = NOT_SUPPORTED_ERR;
 86 return;
 87 }
8388 setAttribute(valueAttr, String::number(value >= 0 ? value : 0));
8489}
8590
8691double HTMLProgressElement::max() const
8792{
88  bool ok;
89  double max = getAttribute(maxAttr).toDouble(&ok);
 93 double max;
 94 bool ok = parseToDoubleForNumberType(getAttribute(maxAttr), &max);
9095 if (!ok || max <= 0)
9196 return 1;
9297 return max;
9398}
9499
95 void HTMLProgressElement::setMax(double max)
 100void HTMLProgressElement::setMax(double max, ExceptionCode& ec)
96101{
 102 if (isnan(max) || !isfinite(max)) {
 103 ec = NOT_SUPPORTED_ERR;
 104 return;
 105 }
97106 setAttribute(maxAttr, String::number(max > 0 ? max : 1));
98107}
99108
58635

WebCore/html/HTMLProgressElement.h

@@public:
3131 static PassRefPtr<HTMLProgressElement> create(const QualifiedName&, Document*, HTMLFormElement* = 0);
3232
3333 double value() const;
34  void setValue(double);
 34 void setValue(double, ExceptionCode&);
3535
3636 double max() const;
37  void setMax(double);
 37 void setMax(double, ExceptionCode&);
3838
3939 double position() const;
4040
58635

WebCore/html/HTMLProgressElement.idl

@@module html {
2121 interface [
2222 Conditional=PROGRESS_TAG
2323 ] HTMLProgressElement : HTMLElement {
24  attribute double value;
25  attribute double max;
 24 attribute double value
 25 setter raises(DOMException);
 26 attribute double max
 27 setter raises(DOMException);
2628 readonly attribute double position;
2729 readonly attribute HTMLFormElement form;
2830 };
58635

LayoutTests/ChangeLog

 12010-05-02 Yael Aharon <yael.aharon@nokia.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Use HTML5 number parsing in HTMLProgressElement
 6 https://bugs.webkit.org/show_bug.cgi?id=38434
 7
 8 * fast/dom/HTMLProgressElement/script-tests/set-progress-properties.js:
 9 * fast/dom/HTMLProgressElement/set-progress-properties-expected.txt:
 10
1112010-05-02 Marcus Bulach <bulach@chromium.org>
212
313 Reviewed by Jeremy Orlow.
58653

LayoutTests/fast/dom/HTMLProgressElement/set-progress-properties-expected.txt

@@Set value bigger than max
1515PASS p.value is 100
1616PASS p.max is 100
1717PASS p.position is 1
18 Set invalid value
19 PASS p.value is 0
20 PASS p.max is 100
21 PASS p.position is 0
22 Set invalid max
23 PASS p.value is 1
24 PASS p.max is 1
25 PASS p.position is 1
 18Set invalid value, should throw
 19NOT_SUPPORTED_ERR: DOM Exception 9
 20Set invalid max, should throw
 21NOT_SUPPORTED_ERR: DOM Exception 9
 22Set max to Infinity, should throw
 23NOT_SUPPORTED_ERR: DOM Exception 9
 24Set value to Nan, should throw
 25NOT_SUPPORTED_ERR: DOM Exception 9
2626Set value to null and max to 0
2727PASS p.value is 0
2828PASS p.max is 1
58635

LayoutTests/fast/dom/HTMLProgressElement/script-tests/set-progress-properties.js

@@shouldBe("p.value", "100");
2121shouldBe("p.max", "100");
2222shouldBe("p.position", "1");
2323
24 debug("Set invalid value");
 24debug("Set invalid value, should throw");
 25try {
2526p.value = "200A";
26 p.max = 100;
27 shouldBe("p.value", "0");
28 shouldBe("p.max", "100");
29 shouldBe("p.position", "0");
 27} catch (e) {
 28debug(e.message);
 29}
3030
31 debug("Set invalid max");
32 p.value = "20";
 31debug("Set invalid max, should throw");
 32try {
3333p.max = "max";
34 shouldBe("p.value", "1");
35 shouldBe("p.max", "1");
36 shouldBe("p.position", "1");
 34} catch (e) {
 35debug(e.message);
 36}
 37
 38debug("Set max to Infinity, should throw");
 39try {
 40p.max = Infinity;
 41} catch (e) {
 42debug(e.message);
 43}
 44
 45debug("Set value to Nan, should throw");
 46try {
 47p.value = NaN;
 48} catch (e) {
 49debug(e.message);
 50}
3751
3852debug("Set value to null and max to 0");
3953p.value = null;
58635