Skip to content

Commit c7d6d1c

Browse files
jmdyckljharb
authored andcommitted
Editorial: Recast "Abstract Equality Comparison" (#2378)
... as a proper abstract operation, named IsLooselyEqual.
1 parent 587adc0 commit c7d6d1c

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

spec.html

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5285,26 +5285,26 @@ <h1>IsLessThan ( _x_, _y_ [ , _LeftFirst_ ] )</h1>
52855285
</emu-note>
52865286
</emu-clause>
52875287

5288-
<emu-clause id="sec-abstract-equality-comparison" aoid="Abstract Equality Comparison">
5289-
<h1>Abstract Equality Comparison</h1>
5290-
<p>The comparison _x_ == _y_, where _x_ and _y_ are values, produces *true* or *false*. Such a comparison is performed as follows:</p>
5288+
<emu-clause id="sec-islooselyequal" aoid="IsLooselyEqual" oldids="sec-abstract-equality-comparison">
5289+
<h1>IsLooselyEqual ( _x_, _y_ )</h1>
5290+
<p>The abstract operation IsLooselyEqual takes arguments _x_ (an ECMAScript language value) and _y_ (an ECMAScript language value). It provides the semantics for the comparison _x_ == _y_, returning *true* or *false*. It performs the following steps when called:</p>
52915291
<emu-alg>
52925292
1. If Type(_x_) is the same as Type(_y_), then
52935293
1. Return the result of performing Strict Equality Comparison _x_ === _y_.
52945294
1. If _x_ is *null* and _y_ is *undefined*, return *true*.
52955295
1. If _x_ is *undefined* and _y_ is *null*, return *true*.
52965296
1. [id="step-abstract-equality-comparison-web-compat-insertion-point"] NOTE: This step is replaced in section <emu-xref href="#sec-IsHTMLDDA-internal-slot-aec"></emu-xref>.
5297-
1. If Type(_x_) is Number and Type(_y_) is String, return the result of the comparison _x_ == ! ToNumber(_y_).
5298-
1. If Type(_x_) is String and Type(_y_) is Number, return the result of the comparison ! ToNumber(_x_) == _y_.
5297+
1. If Type(_x_) is Number and Type(_y_) is String, return IsLooselyEqual(_x_, ! ToNumber(_y_)).
5298+
1. If Type(_x_) is String and Type(_y_) is Number, return IsLooselyEqual(! ToNumber(_x_), _y_).
52995299
1. If Type(_x_) is BigInt and Type(_y_) is String, then
53005300
1. Let _n_ be ! StringToBigInt(_y_).
53015301
1. If _n_ is *NaN*, return *false*.
5302-
1. Return the result of the comparison _x_ == _n_.
5303-
1. If Type(_x_) is String and Type(_y_) is BigInt, return the result of the comparison _y_ == _x_.
5304-
1. If Type(_x_) is Boolean, return the result of the comparison ! ToNumber(_x_) == _y_.
5305-
1. If Type(_y_) is Boolean, return the result of the comparison _x_ == ! ToNumber(_y_).
5306-
1. If Type(_x_) is either String, Number, BigInt, or Symbol and Type(_y_) is Object, return the result of the comparison _x_ == ? ToPrimitive(_y_).
5307-
1. If Type(_x_) is Object and Type(_y_) is either String, Number, BigInt, or Symbol, return the result of the comparison ? ToPrimitive(_x_) == _y_.
5302+
1. Return IsLooselyEqual(_x_, _n_).
5303+
1. If Type(_x_) is String and Type(_y_) is BigInt, return IsLooselyEqual(_y_, _x_).
5304+
1. If Type(_x_) is Boolean, return IsLooselyEqual(! ToNumber(_x_), _y_).
5305+
1. If Type(_y_) is Boolean, return IsLooselyEqual(_x_, ! ToNumber(_y_)).
5306+
1. If Type(_x_) is either String, Number, BigInt, or Symbol and Type(_y_) is Object, return IsLooselyEqual(_x_, ? ToPrimitive(_y_)).
5307+
1. If Type(_x_) is Object and Type(_y_) is either String, Number, BigInt, or Symbol, return IsLooselyEqual(? ToPrimitive(_x_), _y_).
53085308
1. If Type(_x_) is BigInt and Type(_y_) is Number, or if Type(_x_) is Number and Type(_y_) is BigInt, then
53095309
1. If _x_ or _y_ are any of *NaN*, *+&infin;*<sub>𝔽</sub>, or *-&infin;*<sub>𝔽</sub>, return *false*.
53105310
1. If ℝ(_x_) = ℝ(_y_), return *true*; otherwise return *false*.
@@ -17273,16 +17273,15 @@ <h1>Runtime Semantics: Evaluation</h1>
1727317273
1. Let _lval_ be ? GetValue(_lref_).
1727417274
1. Let _rref_ be the result of evaluating |RelationalExpression|.
1727517275
1. Let _rval_ be ? GetValue(_rref_).
17276-
1. Return the result of performing Abstract Equality Comparison _rval_ == _lval_.
17276+
1. Return IsLooselyEqual(_rval_, _lval_).
1727717277
</emu-alg>
1727817278
<emu-grammar>EqualityExpression : EqualityExpression `!=` RelationalExpression</emu-grammar>
1727917279
<emu-alg>
1728017280
1. Let _lref_ be the result of evaluating |EqualityExpression|.
1728117281
1. Let _lval_ be ? GetValue(_lref_).
1728217282
1. Let _rref_ be the result of evaluating |RelationalExpression|.
1728317283
1. Let _rval_ be ? GetValue(_rref_).
17284-
1. Let _r_ be the result of performing Abstract Equality Comparison _rval_ == _lval_.
17285-
1. ReturnIfAbrupt(_r_).
17284+
1. Let _r_ be ? IsLooselyEqual(_rval_, _lval_).
1728617285
1. If _r_ is *true*, return *false*. Otherwise, return *true*.
1728717286
</emu-alg>
1728817287
<emu-grammar>EqualityExpression : EqualityExpression `===` RelationalExpression</emu-grammar>
@@ -42987,7 +42986,7 @@ <h1>Initializers in ForIn Statement Heads</h1>
4298742986

4298842987
<emu-annex id="sec-IsHTMLDDA-internal-slot">
4298942988
<h1>The [[IsHTMLDDA]] Internal Slot</h1>
42990-
<p>An <dfn>[[IsHTMLDDA]] internal slot</dfn> may exist on host-defined objects. Objects with an [[IsHTMLDDA]] internal slot behave like *undefined* in the <emu-xref href="#sec-toboolean">ToBoolean</emu-xref> and <emu-xref href="#sec-abstract-equality-comparison">Abstract Equality Comparison</emu-xref> abstract operations and when used as an operand for the <emu-xref href="#sec-typeof-operator">`typeof` operator</emu-xref>.</p>
42989+
<p>An <dfn>[[IsHTMLDDA]] internal slot</dfn> may exist on host-defined objects. Objects with an [[IsHTMLDDA]] internal slot behave like *undefined* in the <emu-xref href="#sec-toboolean">ToBoolean</emu-xref> and IsLooselyEqual abstract operations and when used as an operand for the <emu-xref href="#sec-typeof-operator">`typeof` operator</emu-xref>.</p>
4299142990
<emu-note>
4299242991
<p>Objects with an [[IsHTMLDDA]] internal slot are never created by this specification. However, the <a href="https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-all"><code>document.all</code> object</a> in web browsers is a host-defined exotic object with this slot that exists for web compatibility purposes. There are no other known examples of this type of object and implementations should not create any with the exception of `document.all`.</p>
4299342992
</emu-note>
@@ -43002,8 +43001,8 @@ <h1>Changes to ToBoolean</h1>
4300243001
</emu-annex>
4300343002

4300443003
<emu-annex id="sec-IsHTMLDDA-internal-slot-aec">
43005-
<h1>Changes to Abstract Equality Comparison</h1>
43006-
<p>The following steps replace step <emu-xref href="#step-abstract-equality-comparison-web-compat-insertion-point"></emu-xref> of the <emu-xref href="#sec-abstract-equality-comparison">Abstract Equality Comparison</emu-xref> algorithm:</p>
43004+
<h1>Changes to IsLooselyEqual</h1>
43005+
<p>The following steps replace step <emu-xref href="#step-abstract-equality-comparison-web-compat-insertion-point"></emu-xref> of the IsLooselyEqual algorithm:</p>
4300743006
<emu-alg>
4300843007
1. If Type(_x_) is Object and _x_ has an [[IsHTMLDDA]] internal slot and _y_ is either *null* or *undefined*, return *true*.
4300943008
1. If _x_ is either *null* or *undefined* and Type(_y_) is Object and _y_ has an [[IsHTMLDDA]] internal slot, return *true*.

0 commit comments

Comments
 (0)