Skip to content

Commit a3c7562

Browse files
ajkleineqrion
authored andcommitted
Add equals and compare
1 parent 86d7160 commit a3c7562

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

document/js-api/index.bs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
6262
text: 𝔽; url: #𝔽
6363
text: ℤ; url: #ℤ
6464
text: SameValue; url: sec-samevalue
65+
text: IsStrictlyEqual; url: sec-isstrictlyequal
66+
text: IsLessThan; url: sec-islessthan
6567
text: String.fromCharCode; url: sec-string.fromcharcode
6668
text: String.fromCodePoint; url: sec-string.fromcodepoint
6769
text: String.prototype.charCodeAt; url: sec-string.prototype.charcodeat
@@ -2007,11 +2009,41 @@ When this builtin is invoked with parameters |string|, |start|, and |end|, the f
20072009

20082010
<h4 id="js-string-equals">equals</h4>
20092011

2010-
TODO
2012+
The |funcType| of this builtin is `(func (param externref externref) (result i32))`.
2013+
2014+
Note: Explicitly allow null strings to be compared for equality as that is meaningful.
2015+
2016+
<div algorithm="js-string-equals">
2017+
2018+
When this builtin is invoked with parameters |first| and |second|, the following steps must be run:
2019+
2020+
1. If |first| is not null and [=Type=](|first|) is not [=String=]
2021+
1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
2022+
1. If |second| is not null and [=Type=](|second|) is not [=String=]
2023+
1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
2024+
1. If [=!=] [=IsStrictlyEqual=](|first|, |second|) is true
2025+
1. Return 1.
2026+
1. Return 0.
2027+
2028+
</div>
20112029

20122030
<h4 id="js-string-compare">compare</h4>
20132031

2014-
TODO
2032+
The |funcType| of this builtin is `(func (param externref externref) (result i32))`.
2033+
2034+
<div algorithm="js-string-compare">
2035+
2036+
When this builtin is invoked with parameters |first| and |second|, the following steps must be run:
2037+
2038+
1. Let |first| be [=?=] [$UnwrapString$](|first|).
2039+
1. Let |second| be [=?=] [$UnwrapString$](|second|).
2040+
1. If [=!=] [=IsStrictlyEqual=](|first|, |second|) is true
2041+
1. Return 0.
2042+
1. If [=!=] [=IsLessThan=](|first|, |second|, true) is true
2043+
1. Return -1.
2044+
1. Return 1.
2045+
2046+
</div>
20152047

20162048
<h2 id="errors">Error Condition Mappings to JavaScript</h2>
20172049

0 commit comments

Comments
 (0)