Skip to content

XS: String.raw truncates the raw object's length to 32 bits #1685

Description

@d01c2

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) } })))'
""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions