from type |functype| and execution steps |steps|, perform the following steps:
+ To
from type |funcType| and execution steps |steps|, perform the following steps:
1. Let |stored settings| be the
.
1. Let |hostfunc| be a [=host function=] which executes |steps| when called.
@@ -1769,8 +1777,8 @@ To
with name |builtinSetName|, perform the
1. Let |builtins| be the result of [=get the builtins for a builtin set=] |builtinSetName|
1. Let |exportsObject| be [=!=] [$OrdinaryObjectCreate$](null).
1. If |externtype| is of the form [=external-type/func=]
,
-1. [=list/iterate|For each=] (|name|, |funcType|, |algorithm|) of |builtins|,
- 1. Let |funcaddr| be the result fo [=create a builtin function=] with |funcType| and |algorithm|
+1. [=list/iterate|For each=] (|name|, |funcType|, |steps|) of |builtins|,
+ 1. Let |funcaddr| be the result fo [=create a builtin function=] with |funcType| and |steps|
1. Let |func| be the result of creating [=a new Exported Function=] from |funcaddr|.
1. Let |value| be |func|.
1. Let |status| be [=!=] [$CreateDataProperty$](|exportsObject|, |name|, |value|).
@@ -1797,28 +1805,245 @@ To
with |import|, enabled builtins |b
String builtins adapt the interface of the String builtin object. The import name for this set is `wasm:js-string`.
-
+
Abstract operations
+
-The unwrapString(|v|) method, when invoked, performs the following steps:
+The UnwrapString(|v|) abstract operation, when invoked, performs the following steps:
-1. If [=Type=](|v|) is not String
+1. If [=Type=](|v|) is not [=String=]
1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
1. Return |v|
+
+
+The FromCharCode(|v|) abstract operation, when invoked, performs the following steps:
+
+1. Assert: |v| is of type [=i32=].
+1. Return [=!=] [$Call$]([=String.fromCharCode=], undefined, « [=ToJSValue=](|v|) »).
+
+
+
+
+
+The CharCodeAt(|string|, |index|) abstract operation, when invoked, performs the following steps:
+
+1. Assert: |index| is of type [=i32=].
+1. Return [=!=] [$Call$]([=String.prototype.charCodeAt=], |string|, « [=ToJSValue=](|index|) »).
+
+
+
+
cast
+
+The |funcType| of this builtin is `(func (param externref) (result externref))`.
+
+
+When this builtin is invoked with parameter |v|, the following steps must be run:
+
+1. Return [=?=] [$UnwrapString$](|v|)
+
+
+
+
test
+
+The |funcType| of this builtin is `(func (param externref) (result i32))`.
+
+
+When this builtin is invoked with parameter |v|, the following steps must be run:
+
+1. If [=Type=](|v|) is not [=String=]
+ 1. Return 0
+1. Return 1
+
+
+
+
fromCharCodeArray
+
+The |funcType| of this builtin is `(func (param (ref null (array (mut i16))) i32 i32) (result externref))`.
+
+Note: This function only takes a mutable i16 array defined in its own recursion group.
+If this is an issue for toolchains, we can look into how to relax the function type
+while still maintaining good performance.
+
+
+When this builtin is invoked with parameters |array|, |start|, and |end|, the following steps must be run:
+
+1. If |array| is null
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Let |length| be the number of elements in |array|.
+1. If |start| > |end| or |end| > |length|
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Let |result| be the empty string.
+1. Let |i| be |start|.
+1. While |i| < |end|:
+ 1. Let |charCode| be the value of the element stored at index |i| in |array|.
+ 1. Let |charCodeString| be [$FromCharCode$](|charCode|).
+ 1. Let |result| be the concatenation of |result| and |charCodeString|.
+ 1. Set |i| to |i| + 1.
+1. Return |result|.
+
+
+
+
intoCharCodeArray
+
+The |funcType| of this builtin is `(func (param externref (ref null (array (mut i16))) i32) (result i32))`.
+
+Note: This function only takes a mutable i16 array defined in its own recursion group.
+If this is an issue for toolchains, we can look into how to relax the function type
+while still maintaining good performance.
+
+
+When this builtin is invoked with parameters |string|, |array|, and |start|, the following steps must be run:
+
+1. If |array| is null
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Let |string| be [=?=] [$UnwrapString$](|string|).
+1. Let |stringLength| be the [=string/length=] of |string|.
+1. Let |arrayLength| be the number of elements in |array|.
+1. If |start| + |length| > |arrayLength|
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Let |i| be 0.
+1. While |i| < |stringLength|:
+ 1. Let |charCode| be [$CharCodeAt$](|string|, |i|).
+ 1. Set the element at index |start| + |i| in |array| to [=ToWebAssemblyValue=](|charCode|).
+ 1. Set |i| to |i| + 1.
+1. Return |stringLength|.
+
+
+
+
+
fromCharCode
+
+The |funcType| of this builtin is `(func (param i32) (result externref))`.
+
+
+When this builtin is invoked with parameter |v|, the following steps must be run:
+
+1. Return [$FromCharCode$](|v|).
+
+
+
+
fromCodePoint
+
+The |funcType| of this builtin is `(func (param i32) (result externref))`.
+
+
+When this builtin is invoked with parameter |v|, the following steps must be run:
+
+1. If |v| > 0x10ffff
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Return [=!=] [$Call$]([=String.fromCodePoint=], undefined, « [=ToJSValue=](|v|) »).
+
+
+
charCodeAt
The type of this function is `(func (param externref i32) (result i32))`.
-When this builtin is invoked, the following steps must be run:
+When this builtin is invoked with parameters |string| and |index|, the following steps must be run:
+
+1. Let |string| be [=?=] [$UnwrapString$](|string|).
+1. Let |length| be the [=string/length=] of |string|.
+1. If |index| >= |length|
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Return [$CharCodeAt$](|string|, |index|).
+
+
+
+
codePointAt
+
+The type of this function is `(func (param externref i32) (result i32))`.
+
+
+When this builtin is invoked with parameters |string| and |index|, the following steps must be run:
+
+1. Let |string| be [=?=] [$UnwrapString$](|string|).
+1. Let |length| be the [=string/length=] of |string|.
+1. If |index| >= |length|
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. Return [=!=] [$Call$]([=String.prototype.codePointAt=], |string|, « [=ToJSValue=](|index|) »).
+
+
+
+
length
+
+The |funcType| of this builtin is `(func (param externref) (result i32))`.
+
+
+When this builtin is invoked with parameter |v|, the following steps must be run:
+
+1. Let |string| be [=?=] [$UnwrapString$](|v|).
+1. Return the [=string/length=] of |string|.
+
+
-1. Let |string| be [$unwrapString$](param0)
-1. TODO
+
concat
+
+The |funcType| of this builtin is `(func (param externref externref) (result externref))`.
+
+
+When this builtin is invoked with parameters |first| and |second|, the following steps must be run:
+
+1. Let |first| be [=?=] [$UnwrapString$](|first|).
+1. Let |second| be [=?=] [$UnwrapString$](|second|).
+1. Return [=!=] [$Call$]([=String.prototype.concat=], |first|, « |second| »).
+
substring
+
+The |funcType| of this builtin is `(func (param externref i32 i32) (result externref))`.
+
+
+When this builtin is invoked with parameters |string|, |start|, and |end|, the following steps must be run:
+
+1. Let |string| be [=?=] [$UnwrapString$](|string|).
+1. Let |length| be the [=string/length=] of |string|.
+1. If |start| > |end| or |start| > |length|
+ 1. Return the empty string.
+1. Return [=!=] [$Call$]([=String.prototype.substring=], |string|, « [=ToJSValue=](|start|), [=ToJSValue=](|end|) »).
+
+
+
+
equals
+
+The |funcType| of this builtin is `(func (param externref externref) (result i32))`.
+
+Note: Explicitly allow null strings to be compared for equality as that is meaningful.
+
+
+
+When this builtin is invoked with parameters |first| and |second|, the following steps must be run:
+
+1. If |first| is not null and [=Type=](|first|) is not [=String=]
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. If |second| is not null and [=Type=](|second|) is not [=String=]
+ 1. Throw a {{RuntimeError}} exception. TODO: this needs to not be catchable, like a trap.
+1. If [=!=] [=IsStrictlyEqual=](|first|, |second|) is true
+ 1. Return 1.
+1. Return 0.
+
+
+
+
compare
+
+The |funcType| of this builtin is `(func (param externref externref) (result i32))`.
+
+
+
+When this builtin is invoked with parameters |first| and |second|, the following steps must be run:
+
+1. Let |first| be [=?=] [$UnwrapString$](|first|).
+1. Let |second| be [=?=] [$UnwrapString$](|second|).
+1. If [=!=] [=IsStrictlyEqual=](|first|, |second|) is true
+ 1. Return 0.
+1. If [=!=] [=IsLessThan=](|first|, |second|, true) is true
+ 1. Return -1.
+1. Return 1.
+
+
Error Condition Mappings to JavaScript