@@ -29,8 +29,9 @@ let s x =
29
29
return " undefined"
30
30
if (typeof x === " function" )
31
31
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()
34
35
})
35
36
| }
36
37
in
@@ -146,7 +147,7 @@ let%expect_test "wrap_callback_strict" =
146
147
(Js.Unsafe. callback_with_arity 2 cb3)
147
148
{| (function(f){ return f(1 ,2 ,3 ) }) | };
148
149
[% expect {|
149
- Result : other | }];
150
+ Result : function# 1 # 1 | }];
150
151
call_and_log
151
152
(Js.Unsafe. callback_with_arity 2 cb3)
152
153
~cont: (fun g -> g 4 )
@@ -163,7 +164,7 @@ let%expect_test "wrap_callback_strict" =
163
164
Result : 0 | }];
164
165
call_and_log (Js.Unsafe. callback_with_arity 2 cb3) {| (function(f){ return f(1 ,2 ) }) | };
165
166
[% expect {|
166
- Result : other | }]
167
+ Result : function# 1 # 1 | }]
167
168
168
169
let % expect_test " wrap_callback_strict" =
169
170
call_and_log
@@ -290,7 +291,7 @@ let%expect_test "wrap_meth_callback_strict" =
290
291
(Js.Unsafe. meth_callback_with_arity 2 cb4)
291
292
{| (function(f){ return f.apply(" this" ,[1 ,2 ,3 ]) }) | };
292
293
[% expect {|
293
- Result : other | }];
294
+ Result : function# 1 # 1 | }];
294
295
call_and_log
295
296
(Js.Unsafe. meth_callback_with_arity 2 cb4)
296
297
~cont: (fun g -> g 4 )
@@ -308,7 +309,7 @@ let%expect_test "wrap_meth_callback_strict" =
308
309
call_and_log
309
310
(Js.Unsafe. meth_callback_with_arity 2 cb4)
310
311
{| (function(f){ return f.apply(" this" ,[1 ,2 ]) }) | };
311
- [% expect {| Result : other | }]
312
+ [% expect {| Result : function# 1 # 1 | }]
312
313
313
314
let % expect_test " wrap_meth_callback_strict" =
314
315
call_and_log
@@ -353,15 +354,13 @@ let%expect_test "partial application, extra arguments set to undefined" =
353
354
let % expect_test _ =
354
355
call_and_log cb3 ~cont: (fun g -> g 1 ) {| (function(f){ return f }) | };
355
356
[% expect {|
356
- Result : other | }]
357
+ Result : function# 2 # 2 | }]
357
358
358
- (*
359
359
let % expect_test _ =
360
360
call_and_log cb3 ~cont: (fun g -> g 1 2 3 4 ) {| (function(f){ return f }) | };
361
361
[% expect {|
362
362
got 1 , 2 , 3 , done
363
363
Result : 0 | }]
364
- *)
365
364
366
365
let % expect_test _ =
367
366
let f cb =
@@ -370,25 +369,22 @@ let%expect_test _ =
370
369
| _ -> Printf. printf " Error: unknown"
371
370
in
372
371
f cb5;
373
- [% expect {| Result : other | }];
372
+ [% expect {| Result : function# 1 # 1 | }];
374
373
f cb4;
375
374
[% expect {|
376
375
got 1 , 1 , 2 , 3 , done
377
376
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 | }]
384
381
385
382
let % expect_test _ =
386
383
let f cb =
387
384
try call_and_log (cb 1 2 3 ) {| (function(f){ return f }) | } with
388
385
| Invalid_argument s | Failure s -> Printf. printf " Error: %s" s
389
386
| _ -> Printf. printf " Error: unknown"
390
387
in
391
- (*
392
388
f (Obj. magic cb1);
393
389
[% expect {|
394
390
got 1 , done
@@ -397,21 +393,20 @@ let%expect_test _ =
397
393
[% expect {|
398
394
got 1 , 2 , done
399
395
Result : 0 | }];
400
- *)
401
396
f (Obj. magic cb3);
402
397
[% expect {|
403
398
got 1 , 2 , 3 , done
404
399
Result : 0 | }];
405
400
f (Obj. magic cb4);
406
401
[% expect {|
407
- Result : other | }];
402
+ Result : function# 1 # 1 | }];
408
403
f (Obj. magic cb5);
409
404
[% expect {|
410
- Result : other | }]
405
+ Result : function# 2 # 2 | }]
411
406
412
407
let % expect_test _ =
413
408
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
415
410
Js. export " f" f;
416
411
let () =
417
412
Js.Unsafe. fun_call
0 commit comments