Skip to content

Commit 83e7bb5

Browse files
authored
Merge pull request #636 from bloomberg/fix_gpr_627
remove Js_config.is_browser hack, no longer needed for playground
2 parents a2ceb9c + c478799 commit 83e7bb5

File tree

11 files changed

+82
-143
lines changed

11 files changed

+82
-143
lines changed

jscomp/lam_compile_group.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ let lambda_as_module
422422
(lam : Lambda.lambda) =
423423
begin
424424
Js_config.set_current_file filename ;
425-
Js_config.iset_debug_file "jsoo_485_test.ml";
425+
Js_config.iset_debug_file "jsoo_400_test.ml";
426426
let lambda_output = compile ~filename output_prefix false env sigs lam in
427427
let (//) = Filename.concat in
428428
let basename =

jscomp/stdlib/pervasives.ml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,3 @@ let exit retcode =
489489

490490
let _ = register_named_value "Pervasives.do_at_exit" do_at_exit
491491

492-
493-
(** TEMPORARY CHANGES FOR PLAYGROUND, SHOULD BE REMOVED LATER *)
494-
495-
(** internal types for FFI, these types are not used by normal users *)
496-
type (-'obj, +'a) js_meth_callback
497-
type (-'arg, + 'result) js_meth
498-
type (-'arg, + 'result) js_fn (** Js uncurried function *)
499-
500-
501-
(** Types for JS objects *)
502-
type +'a js_t (** Js object type *)
503-
504-
type js_re

jscomp/stdlib/pervasives.mli

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,14 +1091,3 @@ val unsafe_really_input : in_channel -> bytes -> int -> int -> unit
10911091

10921092
val do_at_exit : unit -> unit
10931093

1094-
(** TEMPORARY CHANGES FOR PLAYGROUND, SHOULD BE REMOVED LATER *)
1095-
1096-
type (-'obj, +'a) js_meth_callback
1097-
type (-'arg, + 'result) js_meth
1098-
type (-'arg, + 'result) js_fn (** Js uncurried function *)
1099-
1100-
1101-
(** Types for JS objects *)
1102-
type +'a js_t (** Js object type *)
1103-
1104-
type js_re (* Js re type*)

jscomp/syntax/ast_comb.ml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,17 @@ let tuple_type_pair ?loc kind arity =
6565

6666

6767

68-
let js_obj_type_id () =
69-
if Js_config.is_browser () then
70-
Ast_literal.Lid.pervasives_js_obj
71-
else Ast_literal.Lid.js_obj
68+
let js_obj_type_id =
69+
Ast_literal.Lid.js_obj
7270

73-
let re_id () =
74-
if Js_config.is_browser () then
75-
Ast_literal.Lid.pervasives_re_id
76-
else
77-
Ast_literal.Lid.js_re_id
71+
let re_id =
72+
Ast_literal.Lid.js_re_id
7873

7974
let to_js_type loc x =
80-
Typ.constr ~loc {txt = js_obj_type_id (); loc} [x]
75+
Typ.constr ~loc {txt = js_obj_type_id; loc} [x]
8176

8277
let to_js_re_type loc =
83-
Typ.constr ~loc { txt = re_id (); loc} []
78+
Typ.constr ~loc { txt = re_id ; loc} []
8479

8580
let to_js_undefined_type loc x =
8681
Typ.constr ~loc

jscomp/syntax/ast_literal.ml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,23 @@
2424

2525
open Ast_helper
2626

27-
let pervasives = "Pervasives"
27+
2828
module Lid = struct
2929
type t = Longident.t
3030
let val_unit : t = Lident "()"
3131
let type_unit : t = Lident "unit"
3232
let type_string : t = Lident "string"
3333
(* TODO should be renamed in to {!Js.fn} *)
3434
(* TODO should be moved into {!Js.t} Later *)
35-
36-
37-
3835
let js_fn = Longident.Ldot (Lident "Js", "fn")
39-
let pervasives_fn = Longident.Ldot (Lident pervasives, "js_fn")
40-
4136
let js_meth = Longident.Ldot (Lident "Js", "meth")
42-
let pervasives_meth = Longident.Ldot (Lident pervasives, "js_meth")
43-
44-
4537
let js_meth_callback = Longident.Ldot (Lident "Js", "meth_callback")
46-
let pervasives_meth_callback = Longident.Ldot (Lident pervasives, "js_meth_callback")
47-
4838
let js_obj = Longident.Ldot (Lident "Js", "t")
49-
let pervasives_js_obj = Longident.Ldot (Lident pervasives, "js_t")
50-
51-
let ignore_id = Longident.Ldot (Lident pervasives, "ignore")
52-
39+
let ignore_id = Longident.Ldot (Lident "Pervasives", "ignore")
5340
let js_null = Longident.Ldot (Lident "Js", "null")
5441
let js_undefined = Longident.Ldot (Lident "Js", "undefined")
5542
let js_null_undefined = Longident.Ldot (Lident "Js", "null_undefined")
56-
57-
let pervasives_js_null =
58-
Longident.Ldot (Lident pervasives, "js_null")
59-
let pervasives_js_undefined =
60-
Longident.Ldot (Lident pervasives, "js_undefined")
61-
62-
let pervasives_js_null_undefined =
63-
Longident.Ldot (Lident pervasives, "null_undefined")
64-
65-
let pervasives_re_id = Longident.Ldot (Lident pervasives, "js_re")
6643
let js_re_id = Longident.Ldot (Lident "Js_re", "t")
67-
6844
let js_unsafe = Longident.Lident "Js_unsafe"
6945
end
7046

jscomp/syntax/ast_literal.mli

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,16 @@ module Lid : sig
2828
type t = Longident.t
2929
val val_unit : t
3030
val type_unit : t
31-
val pervasives_js_obj : t
32-
3331
val js_fn : t
34-
val pervasives_fn : t
35-
3632
val js_meth : t
37-
val pervasives_meth : t
38-
39-
val pervasives_meth_callback : t
4033
val js_meth_callback : t
4134
val js_obj : t
4235

4336
val ignore_id : t
4437
val js_null : t
4538
val js_undefined : t
4639
val js_null_undefined : t
47-
48-
val pervasives_js_undefined : t
49-
50-
val pervasives_re_id : t
5140
val js_re_id : t
52-
5341
val js_unsafe : t
5442
end
5543

jscomp/syntax/ast_util.ml

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,14 @@ type uncurry_type_gen =
3737
Parsetree.core_type ->
3838
Parsetree.core_type) cxt
3939

40-
let uncurry_type_id () =
41-
if Js_config.is_browser () then
42-
Ast_literal.Lid.pervasives_fn
43-
else
44-
Ast_literal.Lid.js_fn
40+
let uncurry_type_id =
41+
Ast_literal.Lid.js_fn
4542

46-
let method_id () =
47-
if Js_config.is_browser () then
48-
Ast_literal.Lid.pervasives_meth
49-
else
50-
Ast_literal.Lid.js_meth
43+
let method_id =
44+
Ast_literal.Lid.js_meth
5145

52-
let method_call_back_id () =
53-
if Js_config.is_browser () then
54-
Ast_literal.Lid.pervasives_meth_callback
55-
else
56-
Ast_literal.Lid.js_meth_callback
46+
let method_call_back_id =
47+
Ast_literal.Lid.js_meth_callback
5748

5849
let arity_lit = "Arity_"
5950

@@ -72,14 +63,14 @@ let generic_lift txt loc args result =
7263
Typ.constr ~loc {txt ; loc} xs
7364

7465
let lift_curry_type loc =
75-
generic_lift ( uncurry_type_id ()) loc
66+
generic_lift uncurry_type_id loc
7667

7768
let lift_method_type loc =
78-
generic_lift (method_id ()) loc
69+
generic_lift method_id loc
7970

8071
let lift_js_method_callback loc
8172
=
82-
generic_lift (method_call_back_id ()) loc
73+
generic_lift method_call_back_id loc
8374
(** Note that currently there is no way to consume [Js.meth_callback]
8475
so it is fine to encode it with a freedom,
8576
but we need make it better for error message.
@@ -99,24 +90,12 @@ let arrow = Typ.arrow
9990

10091

10192
let js_property loc obj name =
102-
if Js_config.is_browser () then
103-
let downgrade ~loc () =
104-
let var = Typ.var ~loc "a" in
105-
Ast_comb.arrow_no_label ~loc
106-
(Ast_comb.to_js_type loc var) var
107-
in
108-
Ast_external.local_extern_cont loc
109-
~pval_prim:[Literals.js_unsafe_downgrade]
110-
~pval_type:(downgrade ~loc ())
111-
~local_fun_name:"cast"
112-
(fun down -> Exp.send ~loc (Exp.apply ~loc down ["", obj]) name )
113-
else
114-
Parsetree.Pexp_send
115-
((Exp.apply ~loc
116-
(Exp.ident ~loc
117-
{loc;
118-
txt = Ldot (Ast_literal.Lid.js_unsafe, Literals.js_unsafe_downgrade)})
119-
["",obj]), name)
93+
Parsetree.Pexp_send
94+
((Exp.apply ~loc
95+
(Exp.ident ~loc
96+
{loc;
97+
txt = Ldot (Ast_literal.Lid.js_unsafe, Literals.js_unsafe_downgrade)})
98+
["",obj]), name)
12099

121100
(* TODO:
122101
have a final checking for property arities
@@ -144,7 +123,7 @@ let generic_apply kind loc
144123
0, cb loc obj, []
145124
| _ ->
146125
len, cb loc obj, args in
147-
if not (Js_config.is_browser ()) && arity < 10 then
126+
if arity < 10 then
148127
let txt =
149128
match kind with
150129
| `Fn | `PropertyFn ->
@@ -267,7 +246,7 @@ let generic_to_uncurry_exp kind loc (self : Ast_mapper.mapper) pat body
267246
| _ -> len
268247
end
269248
| `Method_callback -> len in
270-
if arity < 10 && not (Js_config.is_browser ()) then
249+
if arity < 10 then
271250
let txt =
272251
match kind with
273252
| `Fn ->
@@ -301,17 +280,9 @@ let to_method_callback =
301280

302281
let handle_debugger loc payload =
303282
if Ast_payload.as_empty_structure payload then
304-
if Js_config.is_browser () then
305-
let predef_unit_type = Ast_literal.type_unit ~loc () in
306-
let pval_prim = [Literals.js_debugger] in
307-
Ast_external.create_local_external loc
308-
~pval_prim
309-
~pval_type:(arrow "" predef_unit_type predef_unit_type)
310-
[("", Ast_literal.val_unit ~loc ())]
311-
else
312-
Parsetree.Pexp_apply
313-
(Exp.ident {txt = Ldot(Ast_literal.Lid.js_unsafe, Literals.js_debugger ); loc},
314-
["", Ast_literal.val_unit ~loc ()])
283+
Parsetree.Pexp_apply
284+
(Exp.ident {txt = Ldot(Ast_literal.Lid.js_unsafe, Literals.js_debugger ); loc},
285+
["", Ast_literal.val_unit ~loc ()])
315286
else Location.raise_errorf ~loc "bs.raw can only be applied to a string"
316287

317288

@@ -322,16 +293,8 @@ let handle_raw loc payload =
322293
"bs.raw can only be applied to a string "
323294

324295
| Some exp ->
325-
let pval_prim = [Literals.js_pure_expr] in
326296
let pexp_desc =
327-
if Js_config.is_browser () then
328-
Ast_external.create_local_external loc
329-
~pval_prim
330-
~pval_type:(arrow ""
331-
(Ast_literal.type_string ~loc ())
332-
(Ast_literal.type_any ~loc ()) )
333-
["",exp]
334-
else Parsetree.Pexp_apply (
297+
Parsetree.Pexp_apply (
335298
Exp.ident {loc;
336299
txt =
337300
Ldot (Ast_literal.Lid.js_unsafe,
@@ -350,16 +313,7 @@ let handle_raw_structure loc payload =
350313
| Some exp
351314
->
352315
let pexp_desc =
353-
if Js_config.is_browser () then
354-
let pval_prim = [Literals.js_pure_stmt] in
355-
Ast_external.create_local_external loc
356-
~pval_prim
357-
~pval_type:(arrow ""
358-
(Ast_literal.type_string ~loc ())
359-
(Ast_literal.type_any ~loc ()))
360-
["",exp]
361-
else
362-
Parsetree.Pexp_apply(
316+
Parsetree.Pexp_apply(
363317
Exp.ident {txt = Ldot (Ast_literal.Lid.js_unsafe, Literals.js_pure_stmt); loc},
364318
["",exp]) in
365319
Ast_helper.Str.eval

jscomp/test/.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ js_obj_test.cmj : mt.cmi
334334
js_obj_test.cmx : mt.cmx
335335
js_val.cmj :
336336
js_val.cmx :
337+
jsoo_400_test.cmj : ../stdlib/string.cmi mt.cmi
338+
jsoo_400_test.cmx : ../stdlib/string.cmx mt.cmx
337339
jsoo_485.cmj :
338340
jsoo_485.cmx :
339341
jsoo_485_test.cmj :
@@ -1090,6 +1092,8 @@ js_obj_test.cmo : mt.cmi
10901092
js_obj_test.cmj : mt.cmj
10911093
js_val.cmo :
10921094
js_val.cmj :
1095+
jsoo_400_test.cmo : ../stdlib/string.cmi mt.cmi
1096+
jsoo_400_test.cmj : ../stdlib/string.cmj mt.cmj
10931097
jsoo_485.cmo :
10941098
jsoo_485.cmj :
10951099
jsoo_485_test.cmo :

jscomp/test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ OTHERS := a test_ari test_export2 test_internalOO test_obj_simple_ffi test_scope
5959
optional_ffi_test poly_variant_test \
6060
bs_rest_test infer_type_test fs_test module_as_function\
6161
test_case_set test_mutliple string_bound_get_test inline_string_test\
62-
ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test
62+
ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test jsoo_400_test
6363

6464

6565
SOURCE_LIST := js_dyn $(OTHERS)

jscomp/test/jsoo_400_test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var Mt = require("./mt");
4+
var Caml_int32 = require("../../lib/js/caml_int32");
5+
var Block = require("../../lib/js/block");
6+
7+
function u() {
8+
var exit = 0;
9+
var n;
10+
try {
11+
n = 3;
12+
exit = 1;
13+
}
14+
catch (exn){
15+
return 42;
16+
}
17+
if (exit === 1) {
18+
return Caml_int32.div(3, 0);
19+
}
20+
21+
}
22+
23+
Mt.from_pair_suites("jsoo_400_test.ml", /* :: */[
24+
/* tuple */[
25+
'File "jsoo_400_test.ml", line 8, characters 3-10',
26+
function () {
27+
return /* ThrowAny */Block.__(3, [function () {
28+
u(/* () */0);
29+
return /* () */0;
30+
}]);
31+
}
32+
],
33+
/* [] */0
34+
]);
35+
36+
exports.u = u;
37+
/* Not a pure module */

0 commit comments

Comments
 (0)