Skip to content

Commit 48bf644

Browse files
authored
fix(webapi): correct binding nullability and exception contracts [Codex] (#349)
## Summary - Corrects nullability and optionality across affected Web API bindings. - Adds `@throws(JsExn)` where synchronous browser APIs can raise exceptions. - Models `HTMLElement.hidden` with the semantic states `Visible`, `Hidden`, and `HiddenUntilFound`, without a raw coercion API. - Updates compile-time fixtures for the corrected contracts. ## `HTMLElement.hidden` The getter and setter use the same semantic type: ```rescript element->HTMLElement.setHidden(HTMLElement.Hidden) element->HTMLElement.setHidden(HTMLElement.HiddenUntilFound) element->HTMLElement.setHidden(HTMLElement.Visible) switch element->HTMLElement.hidden { | HTMLElement.Visible => "visible" | HTMLElement.Hidden => "hidden" | HTMLElement.HiddenUntilFound => "hidden until found" } ``` Because `setHidden` is an `@set` external, these calls emit direct property assignments such as `element.hidden = true`. An earlier version also exposed `hiddenInput` and `setHiddenRaw` to mirror every Web IDL setter input. Those were removed because numbers, arbitrary strings, `null`, and `undefined` only invoke coercion and do not represent additional states. The binding intentionally restricts writes to the three useful outcomes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden) and the [HTML Standard](https://html.spec.whatwg.org/multipage/interaction.html#dom-hidden).
1 parent 0f8ec44 commit 48bf644

153 files changed

Lines changed: 711 additions & 549 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/animation/Animation.res‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ external cancel: t => unit = "cancel"
8787
/**
8888
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Animation/finish)
8989
*/
90-
@send
90+
@throws(JsExn) @send
9191
external finish: t => unit = "finish"
9292

9393
/**
@@ -99,7 +99,7 @@ external play: t => unit = "play"
9999
/**
100100
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Animation/pause)
101101
*/
102-
@send
102+
@throws(JsExn) @send
103103
external pause: t => unit = "pause"
104104

105105
/**
@@ -138,12 +138,12 @@ type iterationCompositeOperation =
138138
type keyframeEffectOptions = {
139139
...AnimationEffect.effectTiming,
140140
mutable composite?: compositeOperation,
141-
mutable pseudoElement?: Null.t<string>,
141+
mutable pseudoElement?: Nullable.t<string>,
142142
mutable iterationComposite?: iterationCompositeOperation,
143143
}
144144

145145
type keyframeAnimationOptions = {
146146
...keyframeEffectOptions,
147147
mutable id?: string,
148-
mutable timeline?: Null.t<animationTimeline>,
148+
mutable timeline?: Nullable.t<animationTimeline>,
149149
}

‎src/animation/AnimationEffect.res‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ type getAnimationsOptions = {mutable subtree?: bool}
3232

3333
type computedEffectTiming = {
3434
...effectTiming,
35-
mutable progress?: Null.t<float>,
36-
mutable currentIteration?: Null.t<float>,
35+
mutable progress?: Nullable.t<float>,
36+
mutable currentIteration?: Nullable.t<float>,
3737
mutable startTime?: float,
3838
mutable endTime?: float,
3939
mutable activeDuration?: float,
40-
mutable localTime?: Null.t<float>,
40+
mutable localTime?: Nullable.t<float>,
4141
}
4242

4343
type optionalEffectTiming = {
@@ -67,5 +67,5 @@ external getComputedTiming: t => computedEffectTiming = "getComputedTiming"
6767
/**
6868
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/AnimationEffect/updateTiming)
6969
*/
70-
@send
70+
@throws(JsExn) @send
7171
external updateTiming: (t, ~timing: optionalEffectTiming=?) => unit = "updateTiming"

‎src/canvas/CanvasGradient.res‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Adds a color stop with the given color to the gradient at the given offset. 0.0
44
Throws an "IndexSizeError" DOMException if the offset is out of range. Throws a "SyntaxError" DOMException if the color cannot be parsed.
55
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasGradient/addColorStop)
66
*/
7-
@send
7+
@throws(JsExn) @send
88
external addColorStop: (CanvasTypes.canvasGradient, ~offset: float, ~color: string) => unit =
99
"addColorStop"
1010

0 commit comments

Comments
 (0)