Skip to content
Merged
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
5 changes: 1 addition & 4 deletions src/jsc/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c
JSC::Options::useAsyncStackTrace() = true;
JSC::Options::useExplicitResourceManagement() = true;
JSC::Options::useImportDefer() = true;
// Upstream enabled Temporal by default; keep it off in Bun until
// the remaining integration work lands. BUN_JSC_useTemporal=1
// re-enables it for opt-in testing.
JSC::Options::useTemporal() = false;
JSC::Options::useTemporal() = true;
// Upstream enabled Wasm Memory64 by default (0d0080ea539d); keep
// it off in Bun while upstream stabilises it.
// BUN_JSC_useWasmMemory64=1 re-enables it for opt-in testing.
Expand Down
20 changes: 10 additions & 10 deletions test/js/bun/jsc/temporal-global.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";

// Upstream WebKit enabled Temporal by default; Bun overrides useTemporal to
// false in ZigGlobalObject.cpp until the remaining integration work lands.
// BUN_JSC_useTemporal=1 re-enables it for opt-in testing.
test("Temporal is not exposed by default", async () => {
// Temporal ships enabled by default. BUN_JSC_useTemporal=0 is the opt-out;
// the BUN_JSC_* environment overrides are applied after the defaults block
// in ZigGlobalObject.cpp, so it can still turn the global back off.
test.concurrent("Temporal is exposed by default", async () => {
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", `process.stdout.write(typeof Temporal)`],
cmd: [bunExe(), "-e", `process.stdout.write(typeof Temporal + " " + typeof Temporal.Now.instant)`],
env: { ...bunEnv, BUN_JSC_useTemporal: undefined },
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout, stderr, exitCode }).toEqual({ stdout: "undefined", stderr: expect.any(String), exitCode: 0 });
expect({ stdout, stderr, exitCode }).toEqual({ stdout: "object function", stderr: expect.any(String), exitCode: 0 });
});

test("Temporal is exposed when BUN_JSC_useTemporal=1", async () => {
test.concurrent("BUN_JSC_useTemporal=0 disables Temporal", async () => {
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", `process.stdout.write(typeof Temporal + " " + typeof Temporal.Now.instant)`],
env: { ...bunEnv, BUN_JSC_useTemporal: "1" },
cmd: [bunExe(), "-e", `process.stdout.write(typeof Temporal)`],
env: { ...bunEnv, BUN_JSC_useTemporal: "0" },
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout, stderr, exitCode }).toEqual({ stdout: "object function", stderr: expect.any(String), exitCode: 0 });
expect({ stdout, stderr, exitCode }).toEqual({ stdout: "undefined", stderr: expect.any(String), exitCode: 0 });
});
88 changes: 88 additions & 0 deletions test/js/web/temporal/temporal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { describe, expect, test } from "bun:test";

// https://github.com/oven-sh/bun/issues/15853
// The default-on/opt-out subprocess tests live in
// test/js/bun/jsc/temporal-global.test.ts next to the other JSC option tests.
describe.concurrent("Temporal global", () => {
test("is installed with the spec property attributes", () => {
expect(Object.getOwnPropertyDescriptor(globalThis, "Temporal")).toMatchObject({
writable: true,
enumerable: false,
configurable: true,
});
});

test("exposes all nine namespaces", () => {
expect(Object.getOwnPropertyNames(Temporal).sort()).toEqual([
"Duration",
"Instant",
"Now",
"PlainDate",
"PlainDateTime",
"PlainMonthDay",
"PlainTime",
"PlainYearMonth",
"ZonedDateTime",
]);
expect(Temporal[Symbol.toStringTag]).toBe("Temporal");
});
});

describe("Temporal core operations", () => {
test("Temporal.Now", () => {
expect(Temporal.Now.instant()).toBeInstanceOf(Temporal.Instant);
expect(Temporal.Now.plainDateISO()).toBeInstanceOf(Temporal.PlainDate);
expect(Temporal.Now.plainDateTimeISO()).toBeInstanceOf(Temporal.PlainDateTime);
expect(Temporal.Now.plainTimeISO()).toBeInstanceOf(Temporal.PlainTime);
expect(Temporal.Now.zonedDateTimeISO()).toBeInstanceOf(Temporal.ZonedDateTime);
expect(typeof Temporal.Now.timeZoneId()).toBe("string");
});

test("parsing, arithmetic, and formatting round-trip", () => {
const d = Temporal.PlainDate.from("2024-06-15");
expect(d.add({ months: 1, days: 20 }).toString()).toBe("2024-08-04");
expect(d.since("2023-01-01", { largestUnit: "month" }).toString()).toBe("P17M14D");

const i = Temporal.Instant.from("2024-06-15T12:34:56.789Z");
expect(i.epochMilliseconds).toBe(1718454896789);
expect(i.round({ smallestUnit: "minute" }).toString()).toBe("2024-06-15T12:35:00Z");

const z = Temporal.ZonedDateTime.from("2024-06-15T12:34:56-04:00[America/New_York]");
expect(z.toString()).toBe("2024-06-15T12:34:56-04:00[America/New_York]");
expect(z.withTimeZone("Asia/Tokyo").toString()).toBe("2024-06-16T01:34:56+09:00[Asia/Tokyo]");

expect(Temporal.Duration.from({ hours: 36, minutes: 30 }).round({ largestUnit: "day" }).toString()).toBe(
"P1DT12H30M",
);
});

test("DST disambiguation", () => {
// 2024-03-10 02:30 does not exist in America/New_York (spring-forward gap).
const gap = Temporal.PlainDateTime.from("2024-03-10T02:30:00");
expect(gap.toZonedDateTime("America/New_York", { disambiguation: "earlier" }).toString()).toBe(
"2024-03-10T01:30:00-05:00[America/New_York]",
);
expect(gap.toZonedDateTime("America/New_York", { disambiguation: "later" }).toString()).toBe(
"2024-03-10T03:30:00-04:00[America/New_York]",
);
expect(() => gap.toZonedDateTime("America/New_York", { disambiguation: "reject" })).toThrow(RangeError);
});

test("Date.prototype.toTemporalInstant", () => {
const date = new Date("2024-06-15T12:34:56.789Z");
const instant = date.toTemporalInstant();
expect(instant).toBeInstanceOf(Temporal.Instant);
expect(instant.epochMilliseconds).toBe(date.getTime());
});

test("Intl.DateTimeFormat formats Temporal objects", () => {
const d = Temporal.PlainDate.from("2024-06-15");
expect(new Intl.DateTimeFormat("en-US").format(d)).toBe("6/15/2024");
expect(d.toLocaleString("en-US")).toBe("6/15/2024");
});

test("structuredClone rejects Temporal objects", () => {
expect(() => structuredClone(Temporal.PlainDate.from("2024-06-15"))).toThrow(DOMException);
expect(() => structuredClone(Temporal.Instant.from("2024-06-15T00:00Z"))).toThrow(DOMException);
});
});
9 changes: 8 additions & 1 deletion test/leaksan.supp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ leak:JSC::stringProtoFuncReplaceUsingRegExp
leak:WebCore::parseTypeAndSubtype
leak:runtime.node.util.parse_args.parseArgs
leak:JSC::IntlDateTimeFormat::initializeDateTimeFormat
leak:JSC::TemporalCore::withTimeZone
leak:WebCore__DOMURL__fileSystemPath
leak:runtime.node.node_fs_watcher.FSWatcher.Arguments.fromJS
leak:jsc.web_worker.create
Expand Down Expand Up @@ -129,3 +128,11 @@ leak:bun_runtime::cli::multi_run::run
# NAPI weak finalizers which enqueue Box<NapiFinalizerTask> into the event
# loop; the loop is already exiting so they never drain.
leak:napi_internal_enqueue_finalizer
# test/js/web/temporal/temporal.test.ts
# TemporalCore::withTimeZone keeps up to 8 open UCalendars in a process-
# lifetime LazyNeverDestroyed TinyLRUCache, one per time zone ID; LRU
# eviction ucal_closes them. The TimeZoneCacheEntry that owns each UCalendar
# is WTF_MAKE_TZONE_ALLOCATED (bmalloc), which LSAN does not scan as a root
# region, so the libc-allocated UCalendar it holds is reported as a direct
# leak even though it is reachable and bounded.
leak:TemporalCore::withTimeZone
Comment thread
robobun marked this conversation as resolved.
Resolved