Skip to content

Commit 3ea3fbc

Browse files
committed
polish
1 parent 18fcf85 commit 3ea3fbc

File tree

12 files changed

+76
-105
lines changed

12 files changed

+76
-105
lines changed

jscomp/others/js_exn.res

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,59 @@ external asJsExn: exn => option<t> = "?as_js_exn"
3434
@get external name: t => option<string> = "name"
3535
@get external fileName: t => option<string> = "fileName"
3636

37+
type error
38+
@new external makeError: string => error = "Error"
39+
3740
external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension"
3841

3942
external anyToExnInternal: 'a => exn = "#wrap_exn"
4043

41-
%%raw("
42-
function raiseThrow(exn) {
43-
throw exn
44-
}
45-
")
44+
let throw: exn => 'a = %raw("function (exn) {
45+
throw exn;
46+
}")
4647

47-
external raiseThrow: exn => 'a = "raiseThrow"
48+
let raiseError = str => throw((Obj.magic((makeError(str): error)): exn))
4849

4950
type eval_error
5051
@new external makeEvalError: string => eval_error = "EvalError"
5152

52-
let raiseEvalError = str => raiseThrow((Obj.magic((makeEvalError(str): eval_error)): exn))
53+
let raiseEvalError = str => throw((Obj.magic((makeEvalError(str): eval_error)): exn))
5354

5455
type range_error
5556
@new external makeRangeError: string => range_error = "RangeError"
5657

57-
let raiseRangeError = str => raiseThrow((Obj.magic((makeRangeError(str): range_error)): exn))
58+
let raiseRangeError = str => throw((Obj.magic((makeRangeError(str): range_error)): exn))
5859

5960
type reference_error
6061

6162
@new external makeReferenceError: string => reference_error = "ReferenceError"
6263

63-
let raiseReferenceError = str => raiseThrow(Obj.magic(makeReferenceError(str)))
64+
let raiseReferenceError = str => throw(Obj.magic(makeReferenceError(str)))
6465

6566
type syntax_error
6667
@new external makeSyntaxError: string => syntax_error = "SyntaxError"
6768

68-
let raiseSyntaxError = str => raiseThrow(Obj.magic(makeSyntaxError(str)))
69+
let raiseSyntaxError = str => throw(Obj.magic(makeSyntaxError(str)))
6970

7071
type type_error
7172
@new external makeTypeError: string => type_error = "TypeError"
7273

73-
let raiseTypeError = str => raiseThrow(Obj.magic(makeTypeError(str)))
74+
let raiseTypeError = str => throw(Obj.magic(makeTypeError(str)))
7475

7576
type uri_error
7677
@new external makeURIError: string => uri_error = "URIError"
7778

78-
let raiseUriError = str => raiseThrow(Obj.magic(makeURIError(str)))
79+
let raiseUriError = str => throw(Obj.magic(makeURIError(str)))
80+
81+
/* TODO add predicate to tell which error is which " */
82+
83+
/*
84+
exception EvalError of error
85+
exception RangeError of error
86+
exception ReferenceError of error
87+
exception SyntaxError of error
88+
exception TypeError of error
7989
80-
let raiseError = str => raise(Failure(str))
90+
The URIError object represents an error when a global URI handling function was used in a wrong way.
91+
exception URIError of error
92+
*/

jscomp/test/custom_error_test.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/exception_value_test.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/js_exception_catch_test.js

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/es6/js_exn.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11

22

33

4-
function raiseThrow(exn) {
5-
throw exn
4+
let $$throw = (function (exn) {
5+
throw exn;
6+
});
7+
8+
function raiseError(str) {
9+
return $$throw(new Error(str));
610
}
7-
;
811

912
function raiseEvalError(str) {
10-
return raiseThrow(new EvalError(str));
13+
return $$throw(new EvalError(str));
1114
}
1215

1316
function raiseRangeError(str) {
14-
return raiseThrow(new RangeError(str));
17+
return $$throw(new RangeError(str));
1518
}
1619

1720
function raiseReferenceError(str) {
18-
return raiseThrow(new ReferenceError(str));
21+
return $$throw(new ReferenceError(str));
1922
}
2023

2124
function raiseSyntaxError(str) {
22-
return raiseThrow(new SyntaxError(str));
25+
return $$throw(new SyntaxError(str));
2326
}
2427

2528
function raiseTypeError(str) {
26-
return raiseThrow(new TypeError(str));
29+
return $$throw(new TypeError(str));
2730
}
2831

2932
function raiseUriError(str) {
30-
return raiseThrow(new URIError(str));
31-
}
32-
33-
function raiseError(str) {
34-
throw new Error("Failure", {
35-
cause: {
36-
RE_EXN_ID: "Failure",
37-
_1: str
38-
}
39-
});
33+
return $$throw(new URIError(str));
4034
}
4135

42-
let $$Error = "JsError";
36+
let $$Error$1 = "JsError";
4337

4438
export {
45-
$$Error,
39+
$$Error$1 as $$Error,
4640
raiseError,
4741
raiseEvalError,
4842
raiseRangeError,
@@ -51,4 +45,4 @@ export {
5145
raiseTypeError,
5246
raiseUriError,
5347
}
54-
/* Not a pure module */
48+
/* No side effect */

lib/es6/js_null.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ function test(x) {
1010
function getExn(f) {
1111
if (f !== null) {
1212
return f;
13+
} else {
14+
return Js_exn.raiseError("Js.Null.getExn");
1315
}
14-
throw new Error("Failure", {
15-
cause: {
16-
RE_EXN_ID: "Failure",
17-
_1: "Js.Null.getExn"
18-
}
19-
});
2016
}
2117

2218
function bind(x, f) {
@@ -52,4 +48,4 @@ export {
5248
fromOption,
5349
from_opt,
5450
}
55-
/* Js_exn Not a pure module */
51+
/* No side effect */

lib/es6/js_option.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ function isNone(x) {
2626
function getExn(x) {
2727
if (x !== undefined) {
2828
return Caml_option.valFromOption(x);
29+
} else {
30+
return Js_exn.raiseError("getExn");
2931
}
30-
throw new Error("Failure", {
31-
cause: {
32-
RE_EXN_ID: "Failure",
33-
_1: "getExn"
34-
}
35-
});
3632
}
3733

3834
function equal(eq, a, b) {
@@ -106,4 +102,4 @@ export {
106102
filter,
107103
firstSome,
108104
}
109-
/* Js_exn Not a pure module */
105+
/* No side effect */

lib/es6/js_undefined.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ function testAny(x) {
1414
function getExn(f) {
1515
if (f !== undefined) {
1616
return f;
17+
} else {
18+
return Js_exn.raiseError("Js.Undefined.getExn");
1719
}
18-
throw new Error("Failure", {
19-
cause: {
20-
RE_EXN_ID: "Failure",
21-
_1: "Js.Undefined.getExn"
22-
}
23-
});
2420
}
2521

2622
function bind(x, f) {
@@ -55,4 +51,4 @@ export {
5551
fromOption,
5652
from_opt,
5753
}
58-
/* Js_exn Not a pure module */
54+
/* No side effect */

lib/js/js_exn.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,46 @@
11
'use strict';
22

33

4-
function raiseThrow(exn) {
5-
throw exn
4+
let $$throw = (function (exn) {
5+
throw exn;
6+
});
7+
8+
function raiseError(str) {
9+
return $$throw(new Error(str));
610
}
7-
;
811

912
function raiseEvalError(str) {
10-
return raiseThrow(new EvalError(str));
13+
return $$throw(new EvalError(str));
1114
}
1215

1316
function raiseRangeError(str) {
14-
return raiseThrow(new RangeError(str));
17+
return $$throw(new RangeError(str));
1518
}
1619

1720
function raiseReferenceError(str) {
18-
return raiseThrow(new ReferenceError(str));
21+
return $$throw(new ReferenceError(str));
1922
}
2023

2124
function raiseSyntaxError(str) {
22-
return raiseThrow(new SyntaxError(str));
25+
return $$throw(new SyntaxError(str));
2326
}
2427

2528
function raiseTypeError(str) {
26-
return raiseThrow(new TypeError(str));
29+
return $$throw(new TypeError(str));
2730
}
2831

2932
function raiseUriError(str) {
30-
return raiseThrow(new URIError(str));
31-
}
32-
33-
function raiseError(str) {
34-
throw new Error("Failure", {
35-
cause: {
36-
RE_EXN_ID: "Failure",
37-
_1: str
38-
}
39-
});
33+
return $$throw(new URIError(str));
4034
}
4135

42-
let $$Error = "JsError";
36+
let $$Error$1 = "JsError";
4337

44-
exports.$$Error = $$Error;
38+
exports.$$Error = $$Error$1;
4539
exports.raiseError = raiseError;
4640
exports.raiseEvalError = raiseEvalError;
4741
exports.raiseRangeError = raiseRangeError;
4842
exports.raiseReferenceError = raiseReferenceError;
4943
exports.raiseSyntaxError = raiseSyntaxError;
5044
exports.raiseTypeError = raiseTypeError;
5145
exports.raiseUriError = raiseUriError;
52-
/* Not a pure module */
46+
/* No side effect */

lib/js/js_null.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ function test(x) {
1010
function getExn(f) {
1111
if (f !== null) {
1212
return f;
13+
} else {
14+
return Js_exn.raiseError("Js.Null.getExn");
1315
}
14-
throw new Error("Failure", {
15-
cause: {
16-
RE_EXN_ID: "Failure",
17-
_1: "Js.Null.getExn"
18-
}
19-
});
2016
}
2117

2218
function bind(x, f) {
@@ -50,4 +46,4 @@ exports.bind = bind;
5046
exports.iter = iter;
5147
exports.fromOption = fromOption;
5248
exports.from_opt = from_opt;
53-
/* Js_exn Not a pure module */
49+
/* No side effect */

lib/js/js_option.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ function isNone(x) {
2626
function getExn(x) {
2727
if (x !== undefined) {
2828
return Caml_option.valFromOption(x);
29+
} else {
30+
return Js_exn.raiseError("getExn");
2931
}
30-
throw new Error("Failure", {
31-
cause: {
32-
RE_EXN_ID: "Failure",
33-
_1: "getExn"
34-
}
35-
});
3632
}
3733

3834
function equal(eq, a, b) {
@@ -105,4 +101,4 @@ exports.default = $$default;
105101
exports.__esModule = true;
106102
exports.filter = filter;
107103
exports.firstSome = firstSome;
108-
/* Js_exn Not a pure module */
104+
/* No side effect */

lib/js/js_undefined.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ function testAny(x) {
1414
function getExn(f) {
1515
if (f !== undefined) {
1616
return f;
17+
} else {
18+
return Js_exn.raiseError("Js.Undefined.getExn");
1719
}
18-
throw new Error("Failure", {
19-
cause: {
20-
RE_EXN_ID: "Failure",
21-
_1: "Js.Undefined.getExn"
22-
}
23-
});
2420
}
2521

2622
function bind(x, f) {
@@ -53,4 +49,4 @@ exports.bind = bind;
5349
exports.iter = iter;
5450
exports.fromOption = fromOption;
5551
exports.from_opt = from_opt;
56-
/* Js_exn Not a pure module */
52+
/* No side effect */

0 commit comments

Comments
 (0)