@@ -29,8 +29,9 @@ let s x =
2929 return " undefined"
3030 if (typeof x === " function" )
3131 return " function#" + x.length + " #" + x.l
32- if (x.toString) return x.toString() ;
33- return " other"
32+ if (x.toString() == " [object Arguments]" )
33+ return " (Arguments: " + Array. prototype.slice.call(x).toString() + " )" ;
34+ return x.toString()
3435})
3536| }
3637 in
@@ -146,7 +147,7 @@ let%expect_test "wrap_callback_strict" =
146147 (Js.Unsafe. callback_with_arity 2 cb3)
147148 {| (function(f){ return f(1 ,2 ,3 ) }) | };
148149 [% expect {|
149- Result : other | }];
150+ Result : function# 1 # 1 | }];
150151 call_and_log
151152 (Js.Unsafe. callback_with_arity 2 cb3)
152153 ~cont: (fun g -> g 4 )
@@ -163,7 +164,7 @@ let%expect_test "wrap_callback_strict" =
163164 Result : 0 | }];
164165 call_and_log (Js.Unsafe. callback_with_arity 2 cb3) {| (function(f){ return f(1 ,2 ) }) | };
165166 [% expect {|
166- Result : other | }]
167+ Result : function# 1 # 1 | }]
167168
168169let % expect_test " wrap_callback_strict" =
169170 call_and_log
@@ -290,7 +291,7 @@ let%expect_test "wrap_meth_callback_strict" =
290291 (Js.Unsafe. meth_callback_with_arity 2 cb4)
291292 {| (function(f){ return f.apply(" this" ,[1 ,2 ,3 ]) }) | };
292293 [% expect {|
293- Result : other | }];
294+ Result : function# 1 # 1 | }];
294295 call_and_log
295296 (Js.Unsafe. meth_callback_with_arity 2 cb4)
296297 ~cont: (fun g -> g 4 )
@@ -308,7 +309,7 @@ let%expect_test "wrap_meth_callback_strict" =
308309 call_and_log
309310 (Js.Unsafe. meth_callback_with_arity 2 cb4)
310311 {| (function(f){ return f.apply(" this" ,[1 ,2 ]) }) | };
311- [% expect {| Result : other | }]
312+ [% expect {| Result : function# 1 # 1 | }]
312313
313314let % expect_test " wrap_meth_callback_strict" =
314315 call_and_log
@@ -353,15 +354,13 @@ let%expect_test "partial application, extra arguments set to undefined" =
353354let % expect_test _ =
354355 call_and_log cb3 ~cont: (fun g -> g 1 ) {| (function(f){ return f }) | };
355356 [% expect {|
356- Result : other | }]
357+ Result : function# 2 # 2 | }]
357358
358- (*
359359let % expect_test _ =
360360 call_and_log cb3 ~cont: (fun g -> g 1 2 3 4 ) {| (function(f){ return f }) | };
361361 [% expect {|
362362 got 1 , 2 , 3 , done
363363 Result : 0 | }]
364- *)
365364
366365let % expect_test _ =
367366 let f cb =
@@ -370,25 +369,22 @@ let%expect_test _ =
370369 | _ -> Printf. printf " Error: unknown"
371370 in
372371 f cb5;
373- [% expect {| Result : other | }];
372+ [% expect {| Result : function# 1 # 1 | }];
374373 f cb4;
375374 [% expect {|
376375 got 1 , 1 , 2 , 3 , done
377376 Result : 0 | }];
378- ()
379- (* f cb3;
380- [%expect {|
381- got 1, 1, 2, done
382- Result: 0 |}]
383- *)
377+ f cb3;
378+ [% expect {|
379+ got 1 , 1 , 2 , done
380+ Result : 0 | }]
384381
385382let % expect_test _ =
386383 let f cb =
387384 try call_and_log (cb 1 2 3 ) {| (function(f){ return f }) | } with
388385 | Invalid_argument s | Failure s -> Printf. printf " Error: %s" s
389386 | _ -> Printf. printf " Error: unknown"
390387 in
391- (*
392388 f (Obj. magic cb1);
393389 [% expect {|
394390 got 1 , done
@@ -397,21 +393,20 @@ let%expect_test _ =
397393 [% expect {|
398394 got 1 , 2 , done
399395 Result : 0 | }];
400- *)
401396 f (Obj. magic cb3);
402397 [% expect {|
403398 got 1 , 2 , 3 , done
404399 Result : 0 | }];
405400 f (Obj. magic cb4);
406401 [% expect {|
407- Result : other | }];
402+ Result : function# 1 # 1 | }];
408403 f (Obj. magic cb5);
409404 [% expect {|
410- Result : other | }]
405+ Result : function# 2 # 2 | }]
411406
412407let % expect_test _ =
413408 let open Js_of_ocaml in
414- let f = Js. wrap_callback (fun s -> print_endline ( Js. to_string s) ) in
409+ let f = Js. wrap_callback (fun s -> print_endline s ) in
415410 Js. export " f" f;
416411 let () =
417412 Js.Unsafe. fun_call
0 commit comments