Skip to content

Commit

Permalink
Remove <input>._parsedValue
Browse files Browse the repository at this point in the history
It is not a concept in the spec, and the call sites were awkward with it
anyway.
  • Loading branch information
TimothyGu authored and domenic committed Feb 1, 2020
1 parent ac497bb commit 7597537
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions lib/jsdom/living/nodes/HTMLInputElement-impl.js
Expand Up @@ -478,8 +478,8 @@ class HTMLInputElementImpl extends HTMLElementImpl {
return NaN;
}

const parsedValue = this._parsedValue;
return typeof parsedValue === "number" ? parsedValue : NaN;
const parsedValue = this._convertStringToNumber(this._value);
return parsedValue !== null ? parsedValue : NaN;
}

set valueAsNumber(v) {
Expand Down Expand Up @@ -566,7 +566,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
return;
}

this.valueAsNumber = value;
this._value = this._convertNumberToString(value);
}

stepDown(n = 1) {
Expand Down Expand Up @@ -833,23 +833,12 @@ class HTMLInputElementImpl extends HTMLElementImpl {
return null;
}

get _parsedValue() {
if (this._convertStringToNumber !== undefined) {
return this._convertStringToNumber(this._value);
}
return this._value;
}

get _parsedValueIsNumber() {
if (this._convertStringToNumber === undefined) {
return false;
}
return typeof this._parsedValue === "number";
}

// https://html.spec.whatwg.org/multipage/input.html#concept-input-step
get _allowedValueStep() {
const attr = this._getAttributeIfApplies("step");
if (!this._contentAttributeApplies("step")) {
return null;
}
const attr = this.getAttributeNS(null, "step");
if (attr === null) {
return this._defaultStep * this._stepScaleFactor;
}
Expand Down Expand Up @@ -972,7 +961,8 @@ class HTMLInputElementImpl extends HTMLElementImpl {
// than the minimum, the element is simultaneously suffering from an underflow and suffering
// from an overflow.
const reversedRangeSufferingOverUnderflow = () => {
return this._parsedValueIsNumber && this._parsedValue > this._maximum && this._parsedValue < this._minimum;
const parsedValue = this._convertStringToNumber(this._value);
return parsedValue !== null && parsedValue > this._maximum && parsedValue < this._minimum;
};

const state = {
Expand Down Expand Up @@ -1041,8 +1031,11 @@ class HTMLInputElementImpl extends HTMLElementImpl {
// range, and the result of applying the algorithm to convert a string to a number to the
// string given by the element's value is a number, and the number obtained from that
// algorithm is more than the maximum, the element is suffering from an overflow.
if (this._maximum !== null && this._parsedValueIsNumber && this._parsedValue > this._maximum) {
return true;
if (this._maximum !== null) {
const parsedValue = this._convertStringToNumber(this._value);
if (parsedValue !== null && parsedValue > this._maximum) {
return true;
}
}
return false;
},
Expand All @@ -1057,8 +1050,11 @@ class HTMLInputElementImpl extends HTMLElementImpl {
// range, and the result of applying the algorithm to convert a string to a number to the
// string given by the element's value is a number, and the number obtained from that
// algorithm is less than the minimum, the element is suffering from an underflow.
if (this._minimum !== null && this._parsedValueIsNumber && this._parsedValue < this._minimum) {
return true;
if (this._minimum !== null) {
const parsedValue = this._convertStringToNumber(this._value);
if (parsedValue !== null && parsedValue < this._minimum) {
return true;
}
}
return false;
},
Expand Down Expand Up @@ -1093,12 +1089,8 @@ class HTMLInputElementImpl extends HTMLElementImpl {
if (allowedValueStep === null) {
return false;
}
if (!this._parsedValueIsNumber) {
return false;
}

const number = this._parsedValue;
return !this._isStepAligned(number);
const number = this._convertStringToNumber(this._value);
return number !== null && !this._isStepAligned(number);
},

// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#suffering-from-a-type-mismatch
Expand Down

0 comments on commit 7597537

Please sign in to comment.