Skip to content

Temporal, Uint8ClampedArray, Float16Array, SharedArrayBuffer, DataView, DisposableStack, FinalizationRegistry - #108

Merged
ASDAlexander77 merged 6 commits into
mainfrom
missing-globals
Nov 19, 2026
Merged

ASDAlexander77 merged 6 commits into
mainfrom
missing-globals

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Adds the missing globals, using MDN's Global Objects as the reference. JSON already existed. One commit per group:

  • Uint8ClampedArray, Float16Array: one class, ConvertingTypedArray<S>, with TypedArray's methods over a number element. Clamped writes go into 0..255 and round half to even. Float16 converts binary16 in TypeScript, because LLVM's f16 conversions call __truncsfhf2 and __extendhfsf2, which the MSVC runtime lacks.
  • SharedArrayBuffer, DataView, Math.f16round: DataView covers every width, both endiannesses, and views that follow a resizable or growable buffer's length. A growable SharedArrayBuffer allocates maxByteLength up front, so grow() never moves its bytes. ArrayBuffer is now declared in lib.d.ts; before this no program could name it. With that it follows JS: resizable only when given maxByteLength, byteLength, and transfer(newByteLength) honours the length. Under -mm=own a DataView keeps its buffer (@keeps).
  • DisposableStack, SuppressedError, ReferenceError: use, adopt, defer, move, dispose, and using. Two failures become a SuppressedError. Under own, defer and adopt of a copied value work; use of an object does not.
  • FinalizationRegistry<H, T>: built on the compiler's WeakRef, so it needs no runtime change and works under gc, own and none (not rc). There is no event loop, so callbacks run at the registry's next register, unregister or cleanupSome. The test runners gain a // not rc tag.
  • Temporal (ISO calendar part): Duration, Instant, PlainDate, PlainTime, PlainDateTime, Now. Not included: ZonedDateTime, time zones, other calendars, options bags. with is spelled _with, as on Array.

Things worth knowing

  • A program calls a lib.ts class's methods by vtable slot, taken from the member order in lib.d.ts. Private methods count too, so each class lists its declared members first. check_declarations.ps1 does not catch a wrong order: DataView returned garbage until I fixed it.
  • Compiler quirks found along the way (not fixed here):
    • unary minus on a float 0 gives +0; the library uses x * -1 instead
    • a bare getter used as a statement is never evaluated
    • multiplying a bigint by an int constant is done in 32 bits

Testing

  • New tests for every class. Release builds pass under gc (exe and JIT), rc, none and own on Windows x64; wasm32 release rc builds.
  • Debug builds were not run locally (the local debug runtime is stale), so CI is the first debug run.

🤖 Generated with Claude Code

ASDAlexander77 and others added 6 commits November 19, 2026 17:11
Uint8ClampedArray clamps a number written to it into 0..255 and rounds half to
even, where Uint8Array wraps. Float16Array keeps IEEE 754 binary16 bits,
converted in TypeScript: LLVM lowers an f16 conversion to __truncsfhf2 and
__extendhfsf2, which the MSVC runtime does not have. Both are one class,
ConvertingTypedArray<S>, with TypedArray's methods over a number element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DataView reads and writes every width JavaScript has (Int8 to Float64,
Float16, BigInt64) at any byte offset of an ArrayBuffer or SharedArrayBuffer,
big-endian unless littleEndian. A view made without a length follows a
resizable buffer. A growable SharedArrayBuffer takes maxByteLength bytes up
front, so grow() never moves them under another thread. Math.f16round.

ArrayBuffer was in lib.ts but not in lib.d.ts, so no program could name it.
Declaring it brings it to JavaScript's rules: resizable only with a
maxByteLength, resize checks it, byteLength, and transfer(newByteLength)
honours the length.

A program calls a lib.ts class's methods by vtable slot, taken from lib.d.ts
order, so each class lists its declared members first and its private ones
after. Under -mm=own a DataView keeps its buffer (@keeps), as Response keeps
its headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DisposableStack disposes its resources last added first, by `using` or
dispose(), with use, adopt, defer, move and disposed. A resource that throws
does not stop the rest; two failures make a SuppressedError holding both. A
disposed stack takes nothing more (ReferenceError). [Symbol.dispose]() is the
method named dispose here, so the class has dispose() alone.

Under -mm=own, defer() and adopt() of a copied value compile; use() of an
object, which keeps it and gives it back, does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… rc"

FinalizationRegistry<H, T> calls its callback with the held value of each
target that has gone: freed by the collector (gc), given up by its owner (own),
or never (none). There is no event loop, and the collector cannot run
TypeScript mid-allocation, so callbacks run at the registry's next use:
register(), unregister() or cleanupSome() (the TC39 proposal's). Targets and
unregister tokens are held weakly. No runtime change: it is built on WeakRef,
so it has WeakRef's models, gc, own and none.

tests.ps1 and tests.sh skip a test whose first line starts with "// not rc"
under -mm=rc, as they skip "// not own" under -mm=own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ISO 8601 calendar's part of Temporal, with from (ISO 8601 text), compare,
add, subtract, until, since, equals, toString and toJSON, and _with for with.
Spans are kept as seconds plus nanoseconds, exact past the 104 days a number
of nanoseconds holds. Not here: ZonedDateTime, PlainYearMonth, PlainMonthDay,
time zones other than UTC and the present system offset, other calendars, and
options bags. Instant.epochNanoseconds is a 64-bit bigint (years 1677-2262).

README lists the classes added on this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t again

A class inside `declare namespace` without its own `declare` had its ..new and
..instanceOf defined in every program as well as in the library: a debug link
failed with duplicate symbols on every test (release dropped them).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant