Skip to content

Commit 86d7160

Browse files
ajkleineqrion
authored andcommitted
Add intoCharCodeArray
1 parent e6462a6 commit 86d7160

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

document/js-api/index.bs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,15 @@ The <dfn abstract-op lt="FromCharCode">FromCharCode(|v|)</dfn> abstract operatio
18231823

18241824
</div>
18251825

1826+
<div algorithm>
1827+
1828+
The <dfn abstract-op lt="CharCodeAt ">CharCodeAt(|string|, |index|)</dfn> abstract operation, when invoked, performs the following steps:
1829+
1830+
1. Assert: |index| is of type [=i32=].
1831+
1. Return [=!=] [$Call$]([=String.prototype.charCodeAt=], |string|, « [=ToJSValue=](|index|) »).
1832+
1833+
</div>
1834+
18261835
<h4 id="js-string-cast">cast</h4>
18271836

18281837
The |funcType| of this builtin is `(func (param externref) (result externref))`.
@@ -1876,7 +1885,31 @@ When this builtin is invoked with parameters |array|, |start|, and |end|, the fo
18761885

18771886
<h4 id="js-string-intoCharCodeArray">intoCharCodeArray</h4>
18781887

1879-
TODO
1888+
The |funcType| of this builtin is `(func (param externref (ref null (array (mut i16))) i32) (result i32))`.
1889+
1890+
Note: This function only takes a mutable i16 array defined in its own recursion group.
1891+
If this is an issue for toolchains, we can look into how to relax the function type
1892+
while still maintaining good performance.
1893+
1894+
<div algorithm="js-string-intoCharCodeArray">
1895+
When this builtin is invoked with parameters |string|, |array|, and |start|, the following steps must be run:
1896+
1897+
1. If |array| is null
1898+
1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
1899+
1. Let |string| be [=?=] [$UnwrapString$](|string|).
1900+
1. Let |stringLength| be the [=string/length=] of |string|.
1901+
1. Let |arrayLength| be the number of elements in |array|.
1902+
1. If |start| + |length| > |arrayLength|
1903+
1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
1904+
1. Let |i| be 0.
1905+
1. While |i| < |stringLength|:
1906+
1. Let |charCode| be [$CharCodeAt$](|string|, |i|).
1907+
1. Set the element at index |start| + |i| in |array| to [=ToWebAssemblyValue=](|charCode|).
1908+
1. Set |i| to |i| + 1.
1909+
1. Return |stringLength|.
1910+
1911+
</div>
1912+
18801913

18811914
<h4 id="js-string-fromCharCode">fromCharCode</h4>
18821915

@@ -1913,7 +1946,7 @@ When this builtin is invoked with parameters |string| and |index|, the following
19131946
1. Let |length| be the [=string/length=] of |string|.
19141947
1. If |index| >= |length|
19151948
1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
1916-
1. Return [=!=] [$Call$]([=String.prototype.charCodeAt=], |string|, « [=ToJSValue=](|index|) »).
1949+
1. Return [$CharCodeAt$](|string|, |index|).
19171950

19181951
</div>
19191952

0 commit comments

Comments
 (0)