Skip to content

Commit d50aab2

Browse files
author
Hongbo Zhang
committed
fix global exception compilation
1 parent 940119d commit d50aab2

9 files changed

+109
-7
lines changed

jscomp/lam_util.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ let sort_dag_args param_args =
5656

5757

5858
let add_required_module (x : Ident.t) (meta : Lam_stats.meta) =
59-
meta.required_modules <- Lam_module_ident.of_ml x :: meta.required_modules
59+
if not @@ Ident.is_predef_exn x then
60+
meta.required_modules <- Lam_module_ident.of_ml x :: meta.required_modules
6061

6162
let add_required_modules ( x : Ident.t list) (meta : Lam_stats.meta) =
62-
meta.required_modules <- List.map (fun x -> Lam_module_ident.of_ml x) x
63-
@ meta.required_modules
63+
let required_modules =
64+
Ext_list.filter_map
65+
(fun x ->
66+
if Ident.is_predef_exn x then
67+
None
68+
else Some ( Lam_module_ident.of_ml x)) x
69+
@ meta.required_modules in
70+
meta.required_modules <- required_modules
6471

6572
(* Apply a substitution to a lambda-term.
6673
Assumes that the bound variables of the lambda-term do not

jscomp/test/.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ for_loop_test.cmo : mt.cmo ../stdlib/list.cmi ../stdlib/array.cmi
8888
for_loop_test.cmx : mt.cmx ../stdlib/list.cmx ../stdlib/array.cmx
8989
for_side_effect_test.cmo : mt.cmo
9090
for_side_effect_test.cmx : mt.cmx
91+
global_exception_regression_test.cmo : mt.cmo
92+
global_exception_regression_test.cmx : mt.cmx
9193
google_closure_test.cmo : test_google_closure.cmo mt.cmo
9294
google_closure_test.cmx : test_google_closure.cmx mt.cmx
9395
hashtbl_test.cmo : mt.cmo ../stdlib/list.cmi ../stdlib/hashtbl.cmi \
@@ -444,6 +446,8 @@ for_loop_test.cmo : mt.cmo ../stdlib/list.cmi ../stdlib/array.cmi
444446
for_loop_test.cmj : mt.cmj ../stdlib/list.cmj ../stdlib/array.cmj
445447
for_side_effect_test.cmo : mt.cmo
446448
for_side_effect_test.cmj : mt.cmj
449+
global_exception_regression_test.cmo : mt.cmo
450+
global_exception_regression_test.cmj : mt.cmj
447451
google_closure_test.cmo : test_google_closure.cmo mt.cmo
448452
google_closure_test.cmj : test_google_closure.cmj mt.cmj
449453
hashtbl_test.cmo : mt.cmo ../stdlib/list.cmi ../stdlib/hashtbl.cmi \
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export var v: any ;
2+
export var u: any ;
3+
export var s: any ;
4+
export var suites: any ;
5+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Generated CODE, PLEASE EDIT WITH CARE
2+
'use strict';
3+
4+
var Caml_exceptions = require("../runtime/caml_exceptions");
5+
var Mt = require("./mt");
6+
7+
var v = Caml_exceptions.Not_found;
8+
9+
var u = Caml_exceptions.Not_found;
10+
11+
var s = Caml_exceptions.End_of_file;
12+
13+
var suites_001 = [
14+
/* tuple */0,
15+
"not_found_equal",
16+
function () {
17+
return [
18+
/* Eq */0,
19+
u,
20+
v
21+
];
22+
}
23+
];
24+
25+
var suites_002 = [
26+
/* :: */0,
27+
[
28+
/* tuple */0,
29+
"not_found_not_equal_end_of_file",
30+
function () {
31+
return [
32+
/* Neq */1,
33+
u,
34+
s
35+
];
36+
}
37+
],
38+
/* [] */0
39+
];
40+
41+
var suites = [
42+
/* :: */0,
43+
suites_001,
44+
suites_002
45+
];
46+
47+
Mt.from_pair_suites("global_exception_regression_test.ml", suites);
48+
49+
exports.v = v;
50+
exports.u = u;
51+
exports.s = s;
52+
exports.suites = suites;
53+
/* Not a pure module */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
let v = Not_found
3+
4+
5+
let u = Not_found
6+
let s = End_of_file
7+
let suites = Mt.[
8+
"not_found_equal", (fun _ -> Eq(u,v));
9+
"not_found_not_equal_end_of_file", (fun _ -> Neq(u,s))
10+
]
11+
12+
;; Mt.from_pair_suites __FILE__ suites

jscomp/test/mt.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export var assert_equal: (prim : any, prim : any) => any ;
2+
export var assert_notequal: (prim : any, prim : any) => any ;
23
export var from_suites: (name : any, suite : any) => any ;
34
export var from_pair_suites: (name : any, suites : any) => any ;
45

jscomp/test/mt.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ function assert_equal(prim, prim$1) {
88
return Assert.deepEqual(prim, prim$1);
99
}
1010

11+
function assert_notequal(prim, prim$1) {
12+
return Assert.notDeepEqual(prim, prim$1);
13+
}
14+
1115
function from_suites(name, suite) {
1216
return describe(name, function () {
1317
return List.iter(function (param) {
@@ -22,13 +26,19 @@ function from_pair_suites(name, suites) {
2226
var code = param[2];
2327
return it(param[1], function () {
2428
var match = code(/* () */0);
25-
return Assert.deepEqual(match[1], match[2]);
29+
if (match[0]) {
30+
return Assert.notDeepEqual(match[1], match[2]);
31+
}
32+
else {
33+
return Assert.deepEqual(match[1], match[2]);
34+
}
2635
});
2736
}, suites);
2837
});
2938
}
3039

3140
exports.assert_equal = assert_equal;
41+
exports.assert_notequal = assert_notequal;
3242
exports.from_suites = from_suites;
3343
exports.from_pair_suites = from_pair_suites;
3444
/* assert Not a pure module */

jscomp/test/mt.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ external eq : 'a -> 'a -> unit = ""
1010
[@@js.call "deepEqual"]
1111
[@@js.module "assert"]
1212

13+
external neq : 'a -> 'a -> unit = ""
14+
[@@js.call "notDeepEqual"]
15+
[@@js.module "assert"]
16+
1317
(* external dump : 'a array -> unit = "js_dump" [@@js.splice] *)
1418

1519
external dump : 'a array -> unit = "" [@@js.call "console.log"] [@@js.splice]
@@ -18,6 +22,7 @@ external dump : 'a array -> unit = "" [@@js.call "console.log"] [@@js.splice]
1822
*)
1923

2024
let assert_equal = eq
25+
let assert_notequal = neq
2126
(* assert -- raises an AssertionError which mocha handls better
2227
*)
2328
let from_suites name (suite : (string * ('a -> unit)) list) =
@@ -26,12 +31,16 @@ let from_suites name (suite : (string * ('a -> unit)) list) =
2631

2732
type _ eq =
2833
| Eq : 'a *'a -> _ eq
29-
34+
| Neq : 'a * 'a -> _ eq
3035

3136
type 'a pair_suites = (string * (unit -> 'a eq)) list
3237
let from_pair_suites name (suites : 'a pair_suites) =
3338
describe name (fun _ ->
3439
List.iter (fun (name, code) ->
35-
it name (fun _ -> let (Eq (a,b)) = code () in assert_equal a b)
40+
it name (fun _ ->
41+
match code () with
42+
| Eq(a,b) -> assert_equal a b
43+
| Neq(a,b) -> assert_notequal a b
44+
)
3645
) suites
3746
)

jscomp/test/test.mllib

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ ari_regress_test
155155
record_with_test
156156
complex_if_test
157157
module_parameter_test
158-
regression_print
158+
regression_print
159+
global_exception_regression_test

0 commit comments

Comments
 (0)