Skip to content

SSO short strings report .length in bytes, not UTF-16 code units #10191

Description

@proggeramlug

Found while extending the element-shape loop clone (#10185). For a short-string (SSO) immediate, .length returns the byte count, not the UTF-16 code-unit count:

console.log(JSON.parse('{"a":"é"}').a.length);   // node: 1   perry: 2
console.log("é".length);                          // check the literal path too

It is a Perry-wide convention rather than one site: string/char_ops.rs and property_get/generic_dispatch.rs both compute the SSO length from bytes, and #10185's clone reproduces it deliberately so the clone agrees with the path it clones. Heap strings carry utf16_len and are correct. Fixing it means the SSO decode has to count UTF-16 units (or SSO admission has to be restricted to ASCII), and every site above changes together; a gap test with a non-ASCII short string should pin it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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