Build environment: macOS 26.5.2
Moddable SDK version:
- Installed via jsvu, so there is no SDK source tree /
git describe.
- Engine reports:
XS 17.9.1, slot 32 bytes, ID 4 bytes
Target device: desktop (host xs)
Description
String.raw obtains its literal segment count with LengthOfArrayLike, which applies ToLength and clamps the value into the range 0 to 2**53 - 1.
XS truncates it to a 32-bit integer instead, so a length of Infinity becomes 0 and takes the "return the empty String" path without reading any segment.
Steps to Reproduce
$ xst -e 'var raw = { length: Infinity }; Object.defineProperty(raw, "0", { get() { throw new Error("reached index 0"); } }); print(JSON.stringify(String.raw.call(0, { raw })));'
""
Expected behavior
The clamped segment count is 2**53 - 1, so the loop reads index 0 and the getter's Error propagates.
For comparison, V8 (15.4.18):
$ v8 -e 'var raw = { length: Infinity }; Object.defineProperty(raw, "0", { get() { throw new Error("reached index 0"); } }); print(JSON.stringify(String.raw.call(0, { raw })));'
Error: reached index 0
Other information
The truncation is directly observable. A length of 2**32 + 3 wraps to 3 and produces exactly three segments, and a length of 2**31 becomes negative and yields the empty string:
$ xst -e 'print(String.raw.call(0, { raw: { length: Math.pow(2, 32) + 3 } }))'
undefinedundefinedundefined
$ xst -e 'print(JSON.stringify(String.raw.call(0, { raw: { length: Math.pow(2, 31) } })))'
""
Build environment: macOS 26.5.2
Moddable SDK version:
git describe.XS 17.9.1, slot 32 bytes, ID 4 bytesTarget device: desktop (host
xs)Description
String.rawobtains its literal segment count withLengthOfArrayLike, which appliesToLengthand clamps the value into the range0to2**53 - 1.XS truncates it to a 32-bit integer instead, so a length of
Infinitybecomes0and takes the "return the empty String" path without reading any segment.Steps to Reproduce
Expected behavior
The clamped segment count is
2**53 - 1, so the loop reads index0and the getter'sErrorpropagates.For comparison, V8 (15.4.18):
$ v8 -e 'var raw = { length: Infinity }; Object.defineProperty(raw, "0", { get() { throw new Error("reached index 0"); } }); print(JSON.stringify(String.raw.call(0, { raw })));' Error: reached index 0Other information
The truncation is directly observable. A length of
2**32 + 3wraps to3and produces exactly three segments, and a length of2**31becomes negative and yields the empty string: