Skip to content

Commit

Permalink
runtime(Js.{Map,Set,WeakMap,WeakSet}): port @mel.send externals to …
Browse files Browse the repository at this point in the history
…use `@mel.this` (#1306)
  • Loading branch information
anmonteiro authored Jan 20, 2025
1 parent d063b90 commit 64ee24e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
16 changes: 10 additions & 6 deletions jscomp/runtime/js_map.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,24 @@ external make : unit -> ('k, 'v) t = "Map" [@@mel.new]
external fromArray : ('k * 'v) array -> ('k, 'v) t = "Map" [@@mel.new]
external toArray : ('k, 'v) t -> ('k * 'v) array = "from" [@@mel.scope "Array"]
external size : ('k, 'v) t -> int = "size" [@@mel.get]
external has : ('k, 'v) t -> key:'k -> bool = "has" [@@mel.send]
external has : key:'k -> (('k, 'v) t[@mel.this]) -> bool = "has" [@@mel.send]

external get : ('k, 'v) t -> key:'k -> 'v option = "get"
external get : key:'k -> (('k, 'v) t[@mel.this]) -> 'v option = "get"
[@@mel.send] [@@mel.return { undefined_to_opt }]

external set : ('k, 'v) t -> key:'k -> value:'v -> ('k, 'v) t = "set"
external set : key:'k -> value:'v -> (('k, 'v) t[@mel.this]) -> ('k, 'v) t
= "set"
[@@mel.send]

external clear : ('k, 'v) t -> unit = "clear" [@@mel.send]
external delete : ('k, 'v) t -> key:'k -> bool = "delete" [@@mel.send]

external delete : key:'k -> (('k, 'v) t[@mel.this]) -> bool = "delete"
[@@mel.send]

external forEach :
f:(('v -> 'k -> ('k, 'v) t -> unit)[@mel.uncurry]) -> ('k, 'v) t -> unit
= "forEach"
f:(('v -> 'k -> ('k, 'v) t -> unit)[@mel.uncurry]) ->
(('k, 'v) t[@mel.this]) ->
unit = "forEach"
[@@mel.send]

external keys : ('k, 'v) t -> 'k Js.iterator = "keys" [@@mel.send]
Expand Down
36 changes: 21 additions & 15 deletions jscomp/runtime/js_set.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,35 @@ external make : unit -> 'a t = "Set" [@@mel.new]
external fromArray : 'a array -> 'a t = "Set" [@@mel.new]
external toArray : 'a t -> 'a array = "Array.from"
external size : 'a t -> int = "size" [@@mel.get]
external add : value:'a -> 'a t -> 'a t = "add" [@@mel.send]
external add : value:'a -> ('a t[@mel.this]) -> 'a t = "add" [@@mel.send]
external clear : 'a t -> unit = "clear" [@@mel.send]
external delete : value:'a -> 'a t -> bool = "delete" [@@mel.send]
external forEach : f:('a -> unit) -> 'a t -> unit = "forEach" [@@mel.send]
external has : value:'a -> 'a t -> bool = "has" [@@mel.send]
external delete : value:'a -> ('a t[@mel.this]) -> bool = "delete" [@@mel.send]

external forEach : f:('a -> unit) -> ('a t[@mel.this]) -> unit = "forEach"
[@@mel.send]

external has : value:'a -> ('a t[@mel.this]) -> bool = "has" [@@mel.send]
external values : 'a t -> 'a Js.iterator = "values" [@@mel.send]
external entries : 'a t -> ('a * 'a) Js.iterator = "entries" [@@mel.send]

(*
external difference : other:'a t -> 'a t = "difference" [@@mel.send.pipe: 'a t]
external difference : other:'a t -> ('a t[@mel.this]) -> 'a t = "difference" [@@mel.send]
external intersection : other:'a t -> 'a t = "intersection"
[@@mel.send.pipe: 'a t]
external intersection : other:'a t -> ('a t[@mel.this]) -> 'a t = "intersection"
[@@mel.send]
external isDisjointFrom : other:'a t -> bool = "isDisjointFrom"
[@@mel.send.pipe: 'a t]
external isDisjointFrom : other:'a t -> ('a t[@mel.this]) -> bool = "isDisjointFrom"
[@@mel.send]
external isSubsetOf : other:'a t -> bool = "isSubsetOf" [@@mel.send.pipe: 'a t]
external isSubsetOf : other:'a t -> ('a t[@mel.this]) -> bool = "isSubsetOf"
[@@mel.send]
external isSupersetOf : other:'a t -> bool = "isSupersetOf"
[@@mel.send.pipe: 'a t]
external isSupersetOf : other:'a t -> ('a t[@mel.this]) -> bool = "isSupersetOf"
[@@mel.send]
external symmetricDifference : other:'a t -> 'a t = "symmetricDifference"
[@@mel.send.pipe: 'a t]
external symmetricDifference : other:'a t -> ('a t[@mel.this]) -> 'a t = "symmetricDifference"
[@@mel.send]
external union : other:'a t -> 'a t = "union" [@@mel.send.pipe: 'a t] *)
external union : other:'a t -> ('a t[@mel.this]) -> 'a t = "union"
[@@mel.send]
*)
14 changes: 10 additions & 4 deletions jscomp/runtime/js_weakmap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
type ('k, 'v) t

external make : unit -> ('k, 'v) t = "WeakMap" [@@mel.new]
external get : key:'k Js.dict -> ('k, 'v) t -> 'v option = "get" [@@mel.send]
external has : key:'k Js.dict -> ('k, 'v) t -> bool = "has" [@@mel.send]

external set : key:'k Js.dict -> value:'v -> ('k, 'v) t -> ('k, 'v) t = "set"
external get : key:'k Js.dict -> (('k, 'v) t[@mel.this]) -> 'v option = "get"
[@@mel.send]

external delete : key:'k Js.dict -> ('k, 'v) t -> bool = "delete" [@@mel.send]
external has : key:'k Js.dict -> (('k, 'v) t[@mel.this]) -> bool = "has"
[@@mel.send]

external set :
key:'k Js.dict -> value:'v -> (('k, 'v) t[@mel.this]) -> ('k, 'v) t = "set"
[@@mel.send]

external delete : key:'k Js.dict -> (('k, 'v) t[@mel.this]) -> bool = "delete"
[@@mel.send]
12 changes: 9 additions & 3 deletions jscomp/runtime/js_weakset.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
type 'a t

external make : unit -> 'a t = "WeakSet" [@@mel.new]
external add : value:'a Js.dict -> 'a t -> 'a t = "add" [@@mel.send]
external delete : value:'a Js.dict -> 'a t -> bool = "delete" [@@mel.send]
external has : value:'a Js.dict -> 'a t -> bool = "has" [@@mel.send]

external add : value:'a Js.dict -> ('a t[@mel.this]) -> 'a t = "add"
[@@mel.send]

external delete : value:'a Js.dict -> ('a t[@mel.this]) -> bool = "delete"
[@@mel.send]

external has : value:'a Js.dict -> ('a t[@mel.this]) -> bool = "has"
[@@mel.send]

0 comments on commit 64ee24e

Please sign in to comment.