Skip to content
Permalink
Browse files
Use HTML5 number parsing in HTMLProgressElement
https://bugs.webkit.org/show_bug.cgi?id=38434

Reviewed by Darin Adler.

WebCore:

Use parseToDoubleForNumberType instead of toDouble.
Throw an exception when the number is NaN or Infinity.

* html/HTMLProgressElement.cpp:
(WebCore::HTMLProgressElement::value):
(WebCore::HTMLProgressElement::setValue):
(WebCore::HTMLProgressElement::max):
(WebCore::HTMLProgressElement::setMax):
* html/HTMLProgressElement.h:
* html/HTMLProgressElement.idl:

LayoutTests:

* fast/dom/HTMLProgressElement/script-tests/set-progress-properties.js:
* fast/dom/HTMLProgressElement/set-progress-properties-expected.txt:



Canonical link: https://commits.webkit.org/49942@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@58687 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Yael Aharon committed May 3, 2010
1 parent 559f4d7 commit eb992043b24e7499a6a976e6c26f6218d568321a
Showing 7 changed files with 78 additions and 30 deletions.
@@ -1,3 +1,13 @@
2010-05-03 Yael Aharon <yael.aharon@nokia.com>

Reviewed by Darin Adler.

Use HTML5 number parsing in HTMLProgressElement
https://bugs.webkit.org/show_bug.cgi?id=38434

* fast/dom/HTMLProgressElement/script-tests/set-progress-properties.js:
* fast/dom/HTMLProgressElement/set-progress-properties-expected.txt:

2010-05-03 Csaba Osztrogonác <ossy@webkit.org>

Unreviewed. Qt specific expected files added after r58675.
@@ -21,19 +21,17 @@ shouldBe("p.value", "100");
shouldBe("p.max", "100");
shouldBe("p.position", "1");

debug("Set invalid value");
p.value = "200A";
p.max = 100;
shouldBe("p.value", "0");
shouldBe("p.max", "100");
shouldBe("p.position", "0");
debug("Set invalid value, should throw");
shouldThrow('p.value = "200A";', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');

debug("Set invalid max");
p.value = "20";
p.max = "max";
shouldBe("p.value", "1");
shouldBe("p.max", "1");
shouldBe("p.position", "1");
debug("Set invalid max, should throw");
shouldThrow('p.max = "max";', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');

debug("Set max to Infinity, should throw");
shouldThrow('p.max = Infinity;', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');

debug("Set value to NaN, should throw");
shouldThrow('p.value = NaN;', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');

debug("Set value to null and max to 0");
p.value = null;
@@ -58,4 +56,11 @@ shouldBe("p.max", "1");
shouldBe("p.getAttribute('value')", "'ABC'");
shouldBe("p.getAttribute('max')", "'#'");

debug("Set value and max to numbers with leading spaces");
p.setAttribute("value", " 5");
p.setAttribute("max", " 10");
shouldBe("p.value", "0");
shouldBe("p.max", "1");
shouldBe("p.position", "0");

var successfullyParsed = true;
@@ -15,14 +15,14 @@ Set value bigger than max
PASS p.value is 100
PASS p.max is 100
PASS p.position is 1
Set invalid value
PASS p.value is 0
PASS p.max is 100
PASS p.position is 0
Set invalid max
PASS p.value is 1
PASS p.max is 1
PASS p.position is 1
Set invalid value, should throw
PASS p.value = "200A"; threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
Set invalid max, should throw
PASS p.max = "max"; threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
Set max to Infinity, should throw
PASS p.max = Infinity; threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
Set value to NaN, should throw
PASS p.value = NaN; threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
Set value to null and max to 0
PASS p.value is 0
PASS p.max is 1
@@ -37,6 +37,10 @@ PASS p.value is 0
PASS p.max is 1
PASS p.getAttribute('value') is 'ABC'
PASS p.getAttribute('max') is '#'
Set value and max to numbers with leading spaces
PASS p.value is 0
PASS p.max is 1
PASS p.position is 0
PASS successfullyParsed is true

TEST COMPLETE
@@ -1,3 +1,21 @@
2010-05-03 Yael Aharon <yael.aharon@nokia.com>

Reviewed by Darin Adler.

Use HTML5 number parsing in HTMLProgressElement
https://bugs.webkit.org/show_bug.cgi?id=38434

Use parseToDoubleForNumberType instead of toDouble.
Throw an exception when the number is NaN or Infinity.

* html/HTMLProgressElement.cpp:
(WebCore::HTMLProgressElement::value):
(WebCore::HTMLProgressElement::setValue):
(WebCore::HTMLProgressElement::max):
(WebCore::HTMLProgressElement::setMax):
* html/HTMLProgressElement.h:
* html/HTMLProgressElement.idl:

2010-05-03 Jens Alfke <snej@chromium.org>

Reviewed by Darin Fisher.
@@ -26,6 +26,7 @@
#include "FormDataList.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
#include "HTMLParser.h"
#include "MappedAttribute.h"
#include "RenderProgress.h"
#include <wtf/StdLibExtras.h>
@@ -71,29 +72,37 @@ void HTMLProgressElement::parseMappedAttribute(MappedAttribute* attribute)
double HTMLProgressElement::value() const
{
const AtomicString& valueString = getAttribute(valueAttr);
bool ok;
double value = valueString.toDouble(&ok);
double value;
bool ok = parseToDoubleForNumberType(valueString, &value);
if (!ok || value < 0)
return valueString.isNull() ? 1 : 0;
return (value > max()) ? max() : value;
}

void HTMLProgressElement::setValue(double value)
void HTMLProgressElement::setValue(double value, ExceptionCode& ec)
{
if (!isfinite(value)) {
ec = NOT_SUPPORTED_ERR;
return;
}
setAttribute(valueAttr, String::number(value >= 0 ? value : 0));
}

double HTMLProgressElement::max() const
{
bool ok;
double max = getAttribute(maxAttr).toDouble(&ok);
double max;
bool ok = parseToDoubleForNumberType(getAttribute(maxAttr), &max);
if (!ok || max <= 0)
return 1;
return max;
}

void HTMLProgressElement::setMax(double max)
void HTMLProgressElement::setMax(double max, ExceptionCode& ec)
{
if (!isfinite(max)) {
ec = NOT_SUPPORTED_ERR;
return;
}
setAttribute(maxAttr, String::number(max > 0 ? max : 1));
}

@@ -31,10 +31,10 @@ class HTMLProgressElement : public HTMLFormControlElement {
static PassRefPtr<HTMLProgressElement> create(const QualifiedName&, Document*, HTMLFormElement* = 0);

double value() const;
void setValue(double);
void setValue(double, ExceptionCode&);

double max() const;
void setMax(double);
void setMax(double, ExceptionCode&);

double position() const;

@@ -21,8 +21,10 @@ module html {
interface [
Conditional=PROGRESS_TAG
] HTMLProgressElement : HTMLElement {
attribute double value;
attribute double max;
attribute double value
setter raises(DOMException);
attribute double max
setter raises(DOMException);
readonly attribute double position;
readonly attribute HTMLFormElement form;
};

0 comments on commit eb99204

Please sign in to comment.