Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Custom event loop implementation for Bun's runtime requirements
```

### When a test fails, and after an upstream sync
`JSTests/`, `LayoutTests/js` and the PerformanceTests collections are upstream's tests, and this fork has changed 124 of them. `JSTests/BUN-TEST-DIFFERENCES.md` lists every one by reason: the behaviors the fork has on purpose (with the fork code behind each and the files whose expectations follow it), the tests narrowed to the modes or builds they can pass in, and the ones skipped with `TODO(bun)` for a known gap. Read it before changing a test's expectation or skipping one: a failure that matches an entry there means the test is what to change; one that matches none is a regression in the engine. Its last section is the procedure for sorting a new failure. When a test is changed, add it to that file, and put a `// Bun:` or `// TODO(bun):` comment on the changed line saying what upstream expects. `JSTests/CLAUDE.md` and `JSTests/README.md` are upstream's files: leave them as they are.
`JSTests/`, `LayoutTests/js` and the PerformanceTests collections are upstream's tests, and this fork has changed 125 of them. `JSTests/BUN-TEST-DIFFERENCES.md` lists every one by reason: the behaviors the fork has on purpose (with the fork code behind each and the files whose expectations follow it), the tests narrowed to the modes or builds they can pass in, and the ones skipped with `TODO(bun)` for a known gap. Read it before changing a test's expectation or skipping one: a failure that matches an entry there means the test is what to change; one that matches none is a regression in the engine. Its last section is the procedure for sorting a new failure. When a test is changed, add it to that file, and put a `// Bun:` or `// TODO(bun):` comment on the changed line saying what upstream expects. `JSTests/CLAUDE.md` and `JSTests/README.md` are upstream's files: leave them as they are.

## Development Tips

Expand Down
41 changes: 38 additions & 3 deletions JSTests/BUN-TEST-DIFFERENCES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Where this fork's tests differ from upstream's, and why

`JSTests/`, `LayoutTests/js` and the PerformanceTests collections are upstream's tests. This fork changes 124 of them and
`JSTests/`, `LayoutTests/js` and the PerformanceTests collections are upstream's tests. This fork changes 125 of them and
three runner scripts. Every change is listed here by the reason for it, so that after an upstream sync a failing test can
be sorted into one of three piles:

1. **The fork behaves differently on purpose.** Update the expectation. Sections A1–A9 list every such behavior, how to
1. **The fork behaves differently on purpose.** Update the expectation. Sections A1–A10 list every such behavior, how to
recognize it in a failure, and the fork code that causes it. If a failure matches one of these and the fork code is
still there, the test is the thing to change.
2. **The test cannot pass in a mode or build we run.** Skip it in that mode only, with the reason. Section B.
Expand Down Expand Up @@ -114,6 +114,40 @@ Rules for an edit to an upstream test:
- Fork code: `DecoderStringTable::jsStringFor` (`runtime/CachedTypes.h:132`): loading a cache interns nothing.
- File: `stress/jsstring-definitely-atom-bit.js`: `$skipModes << "bytecode-cache"`. The other modes run it unchanged.

### A10. `Intl.DateTimeFormat` prints ICU's own era and year before the epoch of an islamic or the coptic calendar

- Upstream replaces ICU's text in `format()` and `formatToParts()`, and so in `formatRange()` of two Numbers or Dates
that print as one date (that arm calls `format()`). It does not in `formatRangeToParts()`, in `formatRange()` of
Temporal values, or in a true range. For `islamic-civil`, `islamic-tbla` and `islamic-umalqura` the era becomes the
English `Before Hijra` and the year becomes 1 − year, and for `coptic` the era `Anno Martyrum` is added
(`proposalEraOverrideString`, `ICU4C-WORKAROUND: rdar://182953351`; upstream's commits are 318428@main
(99473681ff5e), 318847@main (b2ec9a4586ee) and 319172@main (171864159318)). That makes test262's
`formatToParts/era.js` pass.
- The fork removes the override. In these four calendars the methods print one text for one date, in the formatter's
language and in the era width that was asked for. For a Number or a Date it is the text V8 prints on the same ICU.
With the override one formatter gave two texts for one date, and the first hours of 1 AH were
`Muh. 1, 0 Before Hijra`. `@js-temporal/polyfill` 0.5.1 reads its calendar fields from `formatToParts()`: with the
override `Temporal.PlainYearMonth.from("0622-07-25[u-ca=islamic-civil]")` did not return (1.4 GB after 10 s).
- Fork code: the `#pragma GCC poison` at the top of `runtime/IntlDateTimeFormat.cpp`. It is the one line that
`git grep -nE 'EraOverride|proposalEraOverride|flippedEraOverrideYear|formatWithEraOverride|182953351' -- Source/JavaScriptCore`
prints. Anything more is the override, back from a merge: take it out again, callers included, and leave the tests as
they are.
- At a sync, a conflict in `runtime/IntlDateTimeFormat.cpp` whose fork side is empty resolves to the fork side, and a
call that upstream added to the override goes with it. This holds until the ICU that Bun bundles selects these eras
itself, also if upstream only gates its override on a version of ICU.
- Recognize: the test expects `Before Hijra` or `Anno Martyrum` and a year counted back from 1, and gets ICU's
`Anno Hegirae` / `AH` (for coptic, no era) and ICU's year: `1 Before Hijra` → `0 Anno Hegirae`, `333 Before Hijra` →
`-332 Anno Hegirae`, `85 Anno Martyrum` → `85 `.
- Files: `stress/intl-datetimeformat.js`, 12 expectations. test262's
`test/intl402/DateTimeFormat/prototype/formatToParts/era.js` fails: the era of ISO 600 and the era of ISO 2025 are one
text. No job runs test262, so its entries in `test262/expectations-linux.yaml` (made by
`Tools/Scripts/test262-runner --save`) and in `test262/expectations.yaml` (the same entry, not run on a Mac) are
for a run by hand. V8 and SpiderMonkey skip that file. ICU has no era before the Hijra (ICU-23327) and still has
two coptic eras (ICU-23277).
- The section ends when the bundled ICU selects these eras: `stress/intl-datetimeformat.js` then fails on the lanes
with the bundled ICU. Take upstream's expectations again, and remove the two test262 entries and the pragma.
`stress/bun-intl-datetimeformat-pre-epoch-era-one-text.js` holds before and after that.

---

## B. The test cannot pass in a mode or build we run: narrowed, not changed
Expand Down Expand Up @@ -180,6 +214,7 @@ Not upstream's: a sync neither brings nor changes them. Most are named `stress/b
| `stress/bun-object-assign-calls-indexed-setters-on-the-chain.js` | `Object.assign()` stores with `[[Set]]` on its fast path too: an indexed setter on the target's prototype chain is called, and a read-only element there refuses the store |
| `stress/bun-arrays-become-prototypes-below-immutable-prototypes.js` | with `Object.prototype` and `Array.prototype` immutable and a setter under an index on a class prototype, an array or an object with elements that becomes a prototype keeps the storage it has; reads, stores and changes of length on it and through its heirs answer as the language says |
| `stress/bun-weak-map-and-set-shrunk-before-eden-collection.js` | the buffer of a `WeakMap` or `WeakSet` counts in the heap's size as it is behind a collection (`WeakMapImpl::reconcileWeakReferencesAtGCEnd`; upstream counts it as the last visit found it), but an eden collection never leaves that size below what the collection before it left: a buffer that shrank stops counting at the next full collection |
| `stress/bun-intl-datetimeformat-pre-epoch-era-one-text.js` | for a date before the epoch of an islamic or the coptic calendar, `format()`, `formatToParts()`, `formatRange()` and `formatRangeToParts()` of one `Intl.DateTimeFormat` print one text, for a Number, a Date and the Temporal types; every instant of one day prints one date; each end of a range has the year that the date has alone (A10) |
| the last block of `stress/regexp-test-sticky-first-char-filter.js` (the file is upstream's; nothing of upstream's text changes) | the first-character filter of a sticky `test()` comes from the first sets of the alternatives (`yarr/YarrFirstFollowSets.*`): behind a leading lookbehind, forward reference or lookahead, and in groups nested more than eight deep, a byte that passes the filter still reaches the matcher |

`jsc` cannot compile a program ahead of time by itself (the compiler's input comes from the front end, in Bun's repository), so
Expand All @@ -189,7 +224,7 @@ the programs that test ahead-of-time compilation are in Bun's `test/aot`.

## E. After a sync: a failing test, step by step

1. Does the difference match A1–A9 exactly (same text, same shape)? Check that the fork code named there is still in the
1. Does the difference match A1–A10 exactly (same text, same shape)? Check that the fork code named there is still in the
tree, then update the expectation with a `// Bun:` comment and add the file to its list here.
2. Does it fail only in one mode or only with ASan, for a reason in the test and not the engine (it counts JIT compiles,
depends on allocation never failing, needs more than 300 s)? Narrow it as in B.
Expand Down
112 changes: 112 additions & 0 deletions JSTests/stress/bun-intl-datetimeformat-pre-epoch-era-one-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//@ requireOptions("--useTemporal=1")
// Bun: not upstream's. This fork has no era override for a date before the epoch of an islamic-* or the coptic calendar
// (BUN-TEST-DIFFERENCES.md, "Intl.DateTimeFormat prints ICU's own era and year"): every method of one
// Intl.DateTimeFormat prints ICU's own era and year. Upstream's override changes what format() and formatToParts()
// print, and so formatRange() of two Numbers or Dates that print as one date. It does not change formatRangeToParts(),
// formatRange() of Temporal values, or a true range.
// The checks compare the methods with each other and name no era text, so they hold for every version of ICU.

function expect(label, got, want)
{
if (got !== want)
throw new Error(`${label}: expected ${JSON.stringify(want)}, got ${JSON.stringify(got)}`);
}

function join(parts)
{
return parts.map(part => part.value).join("");
}

function yearOf(parts, source)
{
const part = parts.find(part => part.type === "year" && (!source || part.source === source));
return part && part.value;
}

const msPerHour = 3600000;
const msPerDay = 24 * msPerHour;

const calendars = ["islamic-civil", "islamic-tbla", "islamic-umalqura", "coptic"];
const locales = ["en", "sv", "ar", "ja"];
const shapes = [
{ era: "long", year: "numeric", month: "short", day: "numeric" },
{ era: "short", year: "numeric", month: "short", day: "numeric" },
{ era: "narrow", year: "numeric", month: "short", day: "numeric" },
// No era option: the CLDR patterns of these calendars have an era field next to a year.
{ year: "numeric", month: "short", day: "numeric" },
{ dateStyle: "full" },
];
// Before the epoch of each calendar: ISO 284 for coptic, ISO 622 for islamic-*.
const isoDates = ["-000400-01-15", "0200-01-01", "0283-08-01"];

function valuesFor(isoDate, calendar)
{
const plainDate = Temporal.PlainDate.from(isoDate);
const epochMilliseconds = plainDate.toZonedDateTime("UTC").epochMilliseconds;
return [
["Number", epochMilliseconds],
["Date", new Date(epochMilliseconds)],
["Instant", Temporal.Instant.fromEpochMilliseconds(epochMilliseconds)],
["PlainDate", plainDate.withCalendar(calendar)],
["PlainDateTime", plainDate.toPlainDateTime("12:00").withCalendar(calendar)],
["PlainYearMonth", plainDate.withCalendar(calendar).toPlainYearMonth()],
];
}

let checked = 0;
for (const calendar of calendars) {
for (const locale of locales) {
for (const shape of shapes) {
const format = new Intl.DateTimeFormat(locale, { calendar, timeZone: "UTC", ...shape });
const label = `${locale} ${calendar} ${JSON.stringify(shape)}`;

// One value, four methods, one text.
for (const isoDate of isoDates) {
for (const [kind, value] of valuesFor(isoDate, calendar)) {
const text = format.format(value);
const rangeParts = format.formatRangeToParts(value, value);
expect(`${label} ${kind} ${isoDate} formatToParts`, join(format.formatToParts(value)), text);
expect(`${label} ${kind} ${isoDate} formatRange`, format.formatRange(value, value), text);
expect(`${label} ${kind} ${isoDate} formatRangeToParts`, join(rangeParts), text);
for (const part of rangeParts)
expect(`${label} ${kind} ${isoDate} source of the ${part.type} part`, part.source, "shared");
++checked;
}
}

// Each end of a true range has the year that formatToParts() gives that date.
const start = Temporal.PlainDate.from(isoDates[0]).toZonedDateTime("UTC").epochMilliseconds;
const end = start + 366 * msPerDay;
const rangeParts = format.formatRangeToParts(start, end);
expect(`${label} range, year of the start`, yearOf(rangeParts, "startRange"), yearOf(format.formatToParts(start)));
expect(`${label} range, year of the end`, yearOf(rangeParts, "endRange"), yearOf(format.formatToParts(end)));
}
}
}
expect("values checked", checked, calendars.length * locales.length * shapes.length * isoDates.length * 6);

// Every instant of one day in the formatter's time zone prints the same date, on the days around the epoch too.
// A range of two such instants is that one date, in either order.
const epochs = [
["islamic-civil", Date.UTC(622, 6, 19)],
["islamic-umalqura", Date.UTC(622, 6, 19)],
["islamic-tbla", Date.UTC(622, 6, 18)],
["coptic", Date.UTC(284, 7, 29)],
];
for (const [calendar, epoch] of epochs) {
for (const shape of shapes) {
const format = new Intl.DateTimeFormat("en", { calendar, timeZone: "UTC", ...shape });
const texts = new Set;
for (let day = -2; day <= 1; ++day) {
const midnight = epoch + day * msPerDay;
const text = format.format(midnight);
const label = `${calendar} ${JSON.stringify(shape)} day ${day}`;
for (let hour = 1; hour < 24; ++hour)
expect(`${label} hour ${hour}`, format.format(midnight + hour * msPerHour), text);
expect(`${label} range`, format.formatRange(midnight + 3 * msPerHour, midnight + 12 * msPerHour), text);
expect(`${label} reversed range`, format.formatRange(midnight + 12 * msPerHour, midnight + 3 * msPerHour), text);
texts.add(text);
}
expect(`${calendar} ${JSON.stringify(shape)} dates of four days`, texts.size, 4);
}
}
Loading
Loading