Skip to content

Commit 74e4a5e

Browse files
hyperpolymathclaude
andcommitted
fix: eliminate all Obj.magic dangerous patterns across monorepo
Replace every Obj.magic usage with type-safe FFI external bindings: - verisimdb/Registry.res: Obj.magic(exn) -> Exn.asJsExn typed conversion - quandledb/Api.res: Obj.magic(resp) -> typed @get/@send Fetch bindings - lithoglyph/Grid.res: Obj.magic for focus/select/clientX -> @send/@get externals - lithoglyph/App.res: Obj.magic(event) -> typed addEventListener binding Proof closure audit found 0 dangerous patterns in Lean/Idris2 proof files (all hits were comments or keyword table string literals). The 5 actual Obj.magic usages were all in ReScript DOM/Fetch FFI boundaries, now replaced with proper typed external declarations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 52aab49 commit 74e4a5e

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

lithoglyph/glyphbase/ui/src/App.res

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
open Types
44

5+
// Type-safe DOM event listener bindings (eliminates Obj.magic)
6+
@val external addKeydownListener: (string, Dom.keyboardEvent => unit) => unit = "document.addEventListener"
7+
@val external removeKeydownListener: (string, Dom.keyboardEvent => unit) => unit = "document.removeEventListener"
8+
59
// Demo data for development
610
let demoTable: table = {
711
id: "tbl_demo",
@@ -905,15 +909,12 @@ let make = () => {
905909
}
906910
}
907911

908-
let handleKeyDownAny: Dom.event => unit = event => {
909-
handleKeyDown(Obj.magic(event))
910-
}
911-
912-
%raw(`document.addEventListener("keydown", handleKeyDownAny)`)
912+
// Type-safe keydown listener via external binding (no Obj.magic)
913+
addKeydownListener("keydown", handleKeyDown)
913914

914915
Some(
915916
() => {
916-
%raw(`document.removeEventListener("keydown", handleKeyDownAny)`)
917+
removeKeydownListener("keydown", handleKeyDown)
917918
},
918919
)
919920
})

lithoglyph/glyphbase/ui/src/components/Grid.res

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
open Types
55

6+
// Type-safe DOM FFI bindings (eliminates Obj.magic)
7+
@send external focus: Dom.element => unit = "focus"
8+
@send external select: Dom.element => unit = "select"
9+
@get external clientX: Dom.mouseEvent => int = "clientX"
10+
611
// Helper to convert cellValue to editable string
712
let cellValueToString = (value: cellValue): string => {
813
switch value {
@@ -62,9 +67,9 @@ module EditableInput = {
6267
React.useEffect0(() => {
6368
switch inputRef.current->Nullable.toOption {
6469
| Some(el) => {
65-
let domEl = el->Obj.magic
66-
domEl["focus"]()
67-
domEl["select"]()
70+
// Type-safe DOM calls via external bindings (no Obj.magic)
71+
el->focus
72+
el->select
6873
}
6974
| None => ()
7075
}
@@ -357,7 +362,8 @@ module HeaderCell = {
357362
React.useEffect1(() => {
358363
if isResizing {
359364
let handleMouseMove = (e: Dom.mouseEvent) => {
360-
let clientX = e->Obj.magic->Dict.get("clientX")->Option.getOr(0.0)->Float.toInt
365+
// Type-safe clientX via external binding (no Obj.magic)
366+
let clientX = e->clientX
361367
let delta = clientX - startXRef.current
362368
let calculatedWidth = startWidthRef.current + delta
363369
let newWidth = if calculatedWidth < 50 {

quandledb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 0a20355311e6ddb28c8abcb77939d6a1fcd9774b
1+
Subproject commit ce4490a500176cdde33e4296821cf217e3ed552e

verisimdb/src/registry/Registry.res

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,14 @@ let replicateHexad = async (
411411
Error("Source store returned " ++ Belt.Int.toString(Fetch.Response.status(response)))
412412
}
413413
} catch {
414-
| exn => Error("Failed to fetch from source: " ++ Js.Exn.message(Obj.magic(exn))->Belt.Option.getWithDefault("unknown"))
414+
| exn => {
415+
// Type-safe exception message extraction (no Obj.magic)
416+
let msg = switch Exn.asJsExn(exn) {
417+
| Some(jsExn) => Js.Exn.message(jsExn)->Belt.Option.getWithDefault("unknown")
418+
| None => Exn.message(exn)->Option.getOr("unknown")
419+
}
420+
Error("Failed to fetch from source: " ++ msg)
421+
}
415422
}
416423

417424
switch fetchResult {

0 commit comments

Comments
 (0)