Commit 4c80e1b 1 parent 70aac7f commit 4c80e1b Copy full SHA for 4c80e1b
File tree 4 files changed +54
-10
lines changed
4 files changed +54
-10
lines changed Original file line number Diff line number Diff line change @@ -1159,8 +1159,6 @@ let _ =
1159
1159
register_tern_prim " caml_array_unsafe_set" (fun cx cy cz _ ->
1160
1160
J. EBin (J. Eq , Mlvalue.Array. field cx cy, cz));
1161
1161
register_un_prim " caml_alloc_dummy" `Pure (fun _ _ -> J. array [] );
1162
- register_un_prim " caml_obj_dup" ~need_loc: true `Mutable (fun cx loc ->
1163
- J. call (J. dot cx (Utf8_string. of_string_exn " slice" )) [] loc);
1164
1162
register_un_prim " caml_int_of_float" `Pure (fun cx _loc -> to_int cx);
1165
1163
register_un_math_prim " caml_abs_float" " abs" ;
1166
1164
register_un_math_prim " caml_acos_float" " acos" ;
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ let%expect_test "is_int" =
45
45
(* https://github.com/ocsigen/js_of_ocaml/issues/666 *)
46
46
(* https://github.com/ocsigen/js_of_ocaml/pull/725 *)
47
47
48
- let % expect_test " dup" =
48
+ let % expect_test " dup string/bytes " =
49
49
let magic = " abcd" in
50
50
let js_string_enabled =
51
51
match Sys. backend_type with
@@ -71,6 +71,55 @@ let%expect_test "dup" =
71
71
true
72
72
| }]
73
73
74
+ let % expect_test " dup tuple" =
75
+ let x = (1 , " a" , 2.1 ) in
76
+ let x' = Obj. obj (Obj. dup (Obj. repr x)) in
77
+ print_bool (x = x');
78
+ print_bool (x != x');
79
+ [% expect {|
80
+ true
81
+ true
82
+ | }]
83
+
84
+ let % expect_test " dup numbers" =
85
+ let js =
86
+ match Sys. backend_type with
87
+ | Other "js_of_ocaml" -> true
88
+ | _ -> false
89
+ in
90
+ let x = 2.1 in
91
+ let x' = Obj. obj (Obj. dup (Obj. repr x)) in
92
+ print_bool (x = x');
93
+ print_bool ((not js) = (x != x'));
94
+ [% expect {|
95
+ true
96
+ true
97
+ | }];
98
+ let x = 21L in
99
+ let x' = Obj. obj (Obj. dup (Obj. repr x)) in
100
+ print_bool (x = x');
101
+ print_bool (x != x');
102
+ [% expect {|
103
+ true
104
+ true
105
+ | }];
106
+ let x = 21l in
107
+ let x' = Obj. obj (Obj. dup (Obj. repr x)) in
108
+ print_bool (x = x');
109
+ print_bool ((not js) = (x != x'));
110
+ [% expect {|
111
+ true
112
+ true
113
+ | }];
114
+ let x = 21n in
115
+ let x' = Obj. obj (Obj. dup (Obj. repr x)) in
116
+ print_bool (x = x');
117
+ print_bool ((not js) = (x != x'));
118
+ [% expect {|
119
+ true
120
+ true
121
+ | }]
122
+
74
123
let % expect_test " sameness" =
75
124
(* FIXME: Jsoo returns the wrong opposite result for cases below.
76
125
Would be fixed by GH#1410 *)
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class MlInt64 {
30
30
this . caml_custom = "_j" ;
31
31
}
32
32
33
- copy ( ) {
33
+ slice ( ) {
34
34
return new MlInt64 ( this . lo , this . mi , this . hi ) ;
35
35
}
36
36
@@ -179,8 +179,8 @@ class MlInt64 {
179
179
180
180
udivmod ( x ) {
181
181
var offset = 0 ;
182
- var modulus = this . copy ( ) ;
183
- var divisor = x . copy ( ) ;
182
+ var modulus = this . slice ( ) ;
183
+ var divisor = x . slice ( ) ;
184
184
var quotient = new MlInt64 ( 0 , 0 , 0 ) ;
185
185
while ( modulus . ucompare ( divisor ) > 0 ) {
186
186
offset ++ ;
Original file line number Diff line number Diff line change @@ -81,10 +81,7 @@ function caml_obj_with_tag(tag, x) {
81
81
82
82
//Provides: caml_obj_dup mutable (mutable)
83
83
function caml_obj_dup ( x ) {
84
- var l = x . length ;
85
- var a = new Array ( l ) ;
86
- for ( var i = 0 ; i < l ; i ++ ) a [ i ] = x [ i ] ;
87
- return a ;
84
+ return typeof x === "number" ?x :x . slice ( ) ;
88
85
}
89
86
90
87
//Provides: caml_obj_truncate (mutable, const)
You can’t perform that action at this time.
0 commit comments