Repository navigation
fix(webapi): protect native records with private types - #404
jderochervlk wants to merge 9 commits into
Conversation
Upgrade the compiler baseline before continuing the private-record migration in #404. ReScript 13.0.0-alpha.7 includes rescript-lang/rescript#9125, which rejects coercion from another type into a private record—the loophole reproduced on alpha.5 in #403. Pin the development compiler and raise the minimum peer version to alpha.7, update the lockfile and installation guidance, and reject the former alpha.5 baseline in packed-consumer checks. Add a regression for forged Response coercion alongside positive coverage for native construction, direct field reads, outward coercion, and the existing File-to-Blob helper. This does not introduce package-wide native-record privacy. The upgrade also requires a concrete typed-array operation in the ImageData fixture and support for the compiler's new documentation parameter/type schema. Preserve rendered signatures and type links, including callbacks, tuples, and generic parameters. The changes across 40 existing ReScript files are the new compiler's formatting output. Alpha.7 no longer supports native compilation on Intel Macs (`darwin-x64`); the migration notes and project status call out that compatibility break. Refs #403. This is the prerequisite branch for #404, not the private-record migration itself.
|
Updated through Local validation passed on Node 26: An independent source review identified readonly-property setters, a WaveShaper typed-array mismatch, the missing template empty-string state, inherited conversion gaps, and lost throwing annotations. Those concrete findings were corrected and covered by the subsequent local checks. This is not independent approval of all later edits or a package-wide soundness guarantee. The main remaining public-functor policy blocker was reproduced separately against the packed alpha.7 package: module Receiver = {type t = {getRootNode: unit => string}}
module FakeNode = WebAPI.Node.Impl(Receiver)
let forged: WebAPI.Node.t =
FakeNode.getRootNode({getRootNode: () => "not a node"})This compiles without unsafe casts, raw JavaScript, consumer externals, or |
Private-record migration for #403, updated with current main and ReScript 13.0.0-alpha.7 from #414. Native records retain direct field reads, use typed setters for supported mutation, and reject ordinary record construction, updates, and structural coercion into private types. Caller-owned options, initializers, and callback dictionaries remain constructible.
The branch now specializes native identity upcasts on concrete receiver modules rather than exposing arbitrary-receiver identity casts from public
Implfunctors. Existing inheritedasNode,asElement, event, file, SVG, and audio conversion helpers remain available on concrete modules. Stream reader/writer and rendering-context placeholders have abstract identities; performance entry lists are ordinary arrays of native entries, andNodeFilteris a caller-owned callback dictionary.Additional boundary fixes make Canvas-style and intersection-root downcasts checked option results, give media-key access a concrete result type, and model omitted MessageEvent data as nullable. Public media, DOM-node, and geometry setters cover audited write paths. Review fixes preserve the template shadow-mode empty string, require native Float32Array values for WaveShaper curves, remove setters for readonly output/textarea type properties, restore concrete base conversions for Attr/CDATA/ProcessingInstruction, and preserve annotated throwing setter behavior. The docs renderer also preserves callback-type links in record fields.
The checked inventory covers 294 public modules and records private backings/views, abstract identities, public setter routes, constructible exceptions, and remaining modeling gaps. Packed-consumer regressions cover construction/coercion rejection, removed generic identity routes, checked conversions, concrete inherited helpers, and warning-free setters. Native browser workflows exercise the changed boundaries.
Why this remains a draft
This is not yet a package-wide native-instance soundness guarantee. Independent review and an alpha.7 compiler/runtime probe confirmed that public generic
Implmethods can still return a fabricated native value from a caller-owned receiver, even after their identity upcasts are removed. Resolving that requires hiding/constraining generic binding functors or explicitly treating their instantiation as trusted FFI outside the guarantee.Other explicit gaps remain:
The inventory and project-status documentation list these limitations. Passing declaration checks does not prove every exported binding sound. This PR remains draft pending those scope decisions and follow-up work; it does not close #403 automatically.
Refs #403.