Skip to content

Commit 5314f2f

Browse files
committed
WIP
1 parent 0ed7572 commit 5314f2f

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

compiler/tests-jsoo/test_weak.ml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(* Js_of_ocaml tests
2+
* http://www.ocsigen.org/js_of_ocaml/
3+
* Copyright (C) 2024 Hugo Heuzard
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, with linking exception;
8+
* either version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18+
*)
19+
20+
let%expect_test _ =
21+
let k1 = Some 2 in
22+
let k2 = Some 3 in
23+
let k3 = Some 4 in
24+
let d = k1, k2, k3 in
25+
let e = Ephemeron.Kn.make [| k1; k2; k3 |] d in
26+
(match Ephemeron.Kn.query e [| k1; k2; k3 |] with
27+
| None -> print_endline "none"
28+
| Some d' ->
29+
assert (d = d');
30+
print_endline "found");
31+
[%expect {| found |}]
32+
33+
let%expect_test _ =
34+
let module K = struct
35+
type t = int option
36+
37+
let equal (a : t) (b : t) = a = b
38+
39+
let hash (x : t) = Hashtbl.hash x
40+
end in
41+
let module T = Ephemeron.Kn.Make (K) in
42+
let f y =
43+
let k1 = Some 2 in
44+
let k2 = Some 3 in
45+
let k3 = Some y in
46+
let d = k1, k2, k3 in
47+
let t = T.create 10 in
48+
T.add t [| k1; k2; k3 |] d;
49+
T.add t [| k2; k3; k1 |] d;
50+
T.add t [| k3; k1; k2 |] d;
51+
match T.find_opt t [| k1; k2; k3 |] with
52+
| None -> print_endline "none"
53+
| Some d' ->
54+
assert (d = d');
55+
print_endline "found"
56+
in
57+
f 3;
58+
f 2;
59+
[%expect {|
60+
found
61+
found
62+
|}]

runtime/weak.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function caml_ephe_get_data_copy(x) {
207207
//Requires: caml_ephe_data_offset, caml_ephe_key_offset
208208
//Requires: caml_ephe_none
209209
function caml_ephe_set_data(x, data) {
210-
for (var i = x.length - 1; i >= caml_ephe_key_offset; i --) {
210+
for (var i = x.length - 1; i >= caml_ephe_key_offset; i--) {
211211
var k = x[i];
212212
if (k === caml_ephe_none) continue;
213213
if (!(globalThis.WeakRef && k instanceof globalThis.WeakRef)) continue;

0 commit comments

Comments
 (0)