diff --git a/CHANGELOG.md b/CHANGELOG.md index c4fc0986a1f7..8548f2498f70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -175,3 +175,5 @@ - Add experimental Node worker resource limits with per-VM managed-heap termination, nursery and stack sizing, and effective-limit reporting using the pinned OpenClaw WebKit. Code-range limits remain reporting-only. Adapts [oven-sh/bun#32896](https://github.com/oven-sh/bun/pull/32896). Thanks @robobun! - Preserve importing AsyncLocalStorage contexts across module-loader hooks, static and dynamic dependencies, top-level await, shared imports, and errors with the pinned OpenClaw WebKit; add Node-comparable loader regressions. Related to [oven-sh/bun#37933](https://github.com/oven-sh/bun/pull/37933). Thanks @robobun! + +- Fix Intl.Segments.containing() at both halves of surrogate pairs with the pinned OpenClaw WebKit; cover grapheme, word, and sentence boundaries in both lookup directions. Ports [oven-sh/WebKit#753](https://github.com/oven-sh/WebKit/pull/753). Thanks @robobun! diff --git a/docs/runtime/nodejs-compat.mdx b/docs/runtime/nodejs-compat.mdx index fba34f9dfd30..e40acc304f7b 100644 --- a/docs/runtime/nodejs-compat.mdx +++ b/docs/runtime/nodejs-compat.mdx @@ -21,6 +21,8 @@ The OpenClaw fork reports missing runtime imports without downloading npm packag `CallSite.getLineNumber()` and `getColumnNumber()` return one-based positions, or `null` when a frame has no source position. Stack strings include column 1 and use the same constructor positions as CallSites, pointing to the `new` keyword, including across line breaks and in `node:vm` scripts. Some expression positions still differ from Node.js because JavaScriptCore and Bun's transpiler select different syntax locations. +`Intl.Segments.containing()` respects surrogate-pair boundaries for grapheme, word, and sentence segmentation with the pinned OpenClaw WebKit. + ### [`node:assert`](https://nodejs.org/api/assert.html) ๐ŸŸข Fully implemented. Legacy-mode `deepEqual` uses `Bun.deepEquals` semantics rather than Node's loose `==` comparison, and function-valued or `printf`-style `message` arguments are not formatted. diff --git a/test/js/web/intl/intl.test.ts b/test/js/web/intl/intl.test.ts index 37f0c8fae4d1..4945836a8ef1 100644 --- a/test/js/web/intl/intl.test.ts +++ b/test/js/web/intl/intl.test.ts @@ -238,6 +238,31 @@ describe.skipIf(isWindows).concurrent("locale variables in the environment", () // --------------------------------------------------------------------------- describe("Intl.Segmenter", () => { + test.each(["grapheme", "word", "sentence"] as const)( + "containing agrees with iteration at surrogate boundaries: %s", + granularity => { + const inputs = ["a๐Ÿ˜€b", "Hello, world! ๐Ÿ‘๐Ÿฝ x", "a๐Ÿ‡ฏ๐Ÿ‡ตb", "a๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆb", "Hi. ๐Ÿ‘ Bye.", "๐Ÿ‘๐Ÿฝ", "x\ud83d", "abc"]; + for (const input of inputs) { + const segments = new Intl.Segmenter("en", { granularity }).segment(input); + const expected = Array.from(segments); + for (const direction of [1, -1]) { + for ( + let index = direction > 0 ? 0 : input.length - 1; + index >= 0 && index < input.length; + index += direction + ) { + const result = expected.find( + segment => segment.index <= index && index < segment.index + segment.segment.length, + ); + expect(segments.containing(index)).toEqual(result); + } + } + expect(segments.containing(-1)).toBeUndefined(); + expect(segments.containing(input.length)).toBeUndefined(); + } + }, + ); + const seg = (loc: string, g: Intl.SegmenterOptions["granularity"], s: string) => [...new Intl.Segmenter(loc, { granularity: g }).segment(s)].map(x => x.segment);