Skip to content

Strings: retain StringData through String construction #779

Description

@chrisbbreuer

Parents: #473, #480
Related: #666, #777

Problem

The global String function always converts its result to canonical WTF-8 bytes and constructs a new StringCell. When the argument is already a String primitive, or object coercion produces one, ECMAScript ToString already has the exact immutable result Value. Re-encoding and rewrapping it adds avoidable allocation; with active flat Latin-1 storage it also adds an avoidable physical-to-canonical transcode.

new String(value) repeats the same string allocation before allocating the required wrapper object. The zero-argument path also allocates an empty StringCell despite the engine static empty-string value.

Scope

  • Retain the exact StringData Value for primitive string inputs and object coercions that produce strings.
  • Reuse the static empty string for the zero-argument call and construction paths.
  • Preserve String(symbol) descriptive-string behavior and the new String(symbol) TypeError.
  • Preserve constructor prototype and wrapper String exotic semantics.
  • Add allocation-exact witnesses for called and constructed flat Latin-1 paths.

No-workaround rules

  • No storage forcing, hidden canonical copy, replacement characters, special input cache, or weakened WTF-8 validation.
  • No stacks, queues, jobs, Promise, Worker, or Map/Set iterator changes.

Acceptance

  • Called String returns the existing StringData cell when ToString already yields one.
  • Constructed String boxes that exact StringData cell and allocates only the required wrapper.
  • Empty and Symbol semantics remain exact.
  • Focused normal/TSan units, relevant Test262 accounting, and the full unit gate pass without regressions.

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