Skip to content

[js-api] fromCharCodeArray polyfill treats the end index as a count #2342

Done

Description

@hopefuel

Hi, I noticed a mismatch between the test polyfill on main and the specified builtin.

The builtin takes (array, start, end) and reads [start, end). The polyfill instead treats the third argument as a count and reads [start, start + count).

To reproduce, save the following as repro.js in the repository root and run d8 repro.js with a GC-capable d8:

load("test/js-api/wasm-module-builder.js");
load("test/js-api/js-string/polyfill.js");

const array = helperExports.createArrayMutI16(4);
for (let i = 0; i < 4; i++) {
  helperExports.arraySet(array, i, 65 + i);
}
print(polyfillImports.fromCharCodeArray(array, 1, 2));
// Observed: BC
// Expected: B

For this array containing ABCD, I observed:

start end argument Expected Observed polyfill result
0 4 "ABCD" "ABCD"
1 2 "B" "BC"
1 1 "" "B"
3 4 "D" WebAssembly.RuntimeError
2 1 WebAssembly.RuntimeError "C"

I reproduced these polyfill results both directly and through an ordinary Wasm import, using unchanged upstream files. Environment: locally built d8 15.4.80.20, Ubuntu 24.04. I did not test the native builtin or run the full WPT suite.

The existing comparison uses (array, 0, length), where an end index and a count coincide, so it does not distinguish these conventions.

Would it make sense to align the polyfill with the specified [start, end) contract and extend the tests to cover nonzero starts, empty ranges, and reversed ranges?

Activity

  1. changed the title [-]fromCharCodeArray polyfill treats the end index as a count[/-] [+][js-api] fromCharCodeArray polyfill treats the end index as a count[/+] on Nov 23, 2026
  2. eqrion commented on Nov 24, 2026

    @eqrion
    Collaborator

    Thanks for the report, this should be fixed in #2348 now.

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

Metadata

Metadata

Assignees

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