Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw Js Erros constructor EvalError, RangeError, etc #6931

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions jscomp/others/js_exn.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,47 @@ external asJsExn: exn => option<t> = "?as_js_exn"

type error
@new external makeError: string => error = "Error"

external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension"

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

let raiseError = str => raise((Obj.magic((makeError(str): error)): exn))
let throw: exn => 'a = %raw("function (exn) {
throw exn;
}")

let raiseError = str => throw((Obj.magic((makeError(str): error)): exn))

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

let raiseEvalError = str => raise((Obj.magic((makeEvalError(str): eval_error)): exn))
let raiseEvalError = str => throw((Obj.magic((makeEvalError(str): eval_error)): exn))

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

let raiseRangeError = str => raise((Obj.magic((makeRangeError(str): range_error)): exn))
let raiseRangeError = str => throw((Obj.magic((makeRangeError(str): range_error)): exn))

type reference_error

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

let raiseReferenceError = str => raise(Obj.magic(makeReferenceError(str)))
let raiseReferenceError = str => throw(Obj.magic(makeReferenceError(str)))

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

let raiseSyntaxError = str => raise(Obj.magic(makeSyntaxError(str)))
let raiseSyntaxError = str => throw(Obj.magic(makeSyntaxError(str)))

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

let raiseTypeError = str => raise(Obj.magic(makeTypeError(str)))
let raiseTypeError = str => throw(Obj.magic(makeTypeError(str)))

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

let raiseUriError = str => raise(Obj.magic(makeURIError(str)))
let raiseUriError = str => throw(Obj.magic(makeURIError(str)))

/* TODO add predicate to tell which error is which " */

Expand Down
4 changes: 1 addition & 3 deletions jscomp/test/js_exception_catch_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 11 additions & 21 deletions lib/es6/js_exn.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@



let $$throw = (function (exn) {
throw exn;
});

function raiseError(str) {
throw new Error(new Error(str).RE_EXN_ID, {
cause: new Error(str)
});
return $$throw(new Error(str));
}

function raiseEvalError(str) {
throw new Error(new EvalError(str).RE_EXN_ID, {
cause: new EvalError(str)
});
return $$throw(new EvalError(str));
}

function raiseRangeError(str) {
throw new Error(new RangeError(str).RE_EXN_ID, {
cause: new RangeError(str)
});
return $$throw(new RangeError(str));
}

function raiseReferenceError(str) {
throw new Error(new ReferenceError(str).RE_EXN_ID, {
cause: new ReferenceError(str)
});
return $$throw(new ReferenceError(str));
}

function raiseSyntaxError(str) {
throw new Error(new SyntaxError(str).RE_EXN_ID, {
cause: new SyntaxError(str)
});
return $$throw(new SyntaxError(str));
}

function raiseTypeError(str) {
throw new Error(new TypeError(str).RE_EXN_ID, {
cause: new TypeError(str)
});
return $$throw(new TypeError(str));
}

function raiseUriError(str) {
throw new Error(new URIError(str).RE_EXN_ID, {
cause: new URIError(str)
});
return $$throw(new URIError(str));
}

let $$Error$1 = "JsError";
Expand Down
6 changes: 3 additions & 3 deletions lib/es6/js_null.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@


import * as Js_exn from "./js_exn.js";
import * as Caml_option from "./caml_option.js";

function test(x) {
Expand All @@ -9,10 +10,9 @@ function test(x) {
function getExn(f) {
if (f !== null) {
return f;
} else {
return Js_exn.raiseError("Js.Null.getExn");
}
throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, {
cause: new Error("Js.Null.getExn")
});
}

function bind(x, f) {
Expand Down
6 changes: 3 additions & 3 deletions lib/es6/js_option.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@


import * as Js_exn from "./js_exn.js";
import * as Caml_option from "./caml_option.js";

function some(x) {
Expand All @@ -25,10 +26,9 @@ function isNone(x) {
function getExn(x) {
if (x !== undefined) {
return Caml_option.valFromOption(x);
} else {
return Js_exn.raiseError("getExn");
}
throw new Error(new Error("getExn").RE_EXN_ID, {
cause: new Error("getExn")
});
}

function equal(eq, a, b) {
Expand Down
6 changes: 3 additions & 3 deletions lib/es6/js_undefined.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@


import * as Js_exn from "./js_exn.js";
import * as Caml_option from "./caml_option.js";

function test(x) {
Expand All @@ -13,10 +14,9 @@ function testAny(x) {
function getExn(f) {
if (f !== undefined) {
return f;
} else {
return Js_exn.raiseError("Js.Undefined.getExn");
}
throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, {
cause: new Error("Js.Undefined.getExn")
});
}

function bind(x, f) {
Expand Down
32 changes: 11 additions & 21 deletions lib/js/js_exn.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
'use strict';


let $$throw = (function (exn) {
throw exn;
});

function raiseError(str) {
throw new Error(new Error(str).RE_EXN_ID, {
cause: new Error(str)
});
return $$throw(new Error(str));
}

function raiseEvalError(str) {
throw new Error(new EvalError(str).RE_EXN_ID, {
cause: new EvalError(str)
});
return $$throw(new EvalError(str));
}

function raiseRangeError(str) {
throw new Error(new RangeError(str).RE_EXN_ID, {
cause: new RangeError(str)
});
return $$throw(new RangeError(str));
}

function raiseReferenceError(str) {
throw new Error(new ReferenceError(str).RE_EXN_ID, {
cause: new ReferenceError(str)
});
return $$throw(new ReferenceError(str));
}

function raiseSyntaxError(str) {
throw new Error(new SyntaxError(str).RE_EXN_ID, {
cause: new SyntaxError(str)
});
return $$throw(new SyntaxError(str));
}

function raiseTypeError(str) {
throw new Error(new TypeError(str).RE_EXN_ID, {
cause: new TypeError(str)
});
return $$throw(new TypeError(str));
}

function raiseUriError(str) {
throw new Error(new URIError(str).RE_EXN_ID, {
cause: new URIError(str)
});
return $$throw(new URIError(str));
}

let $$Error$1 = "JsError";
Expand Down
6 changes: 3 additions & 3 deletions lib/js/js_null.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

let Js_exn = require("./js_exn.js");
let Caml_option = require("./caml_option.js");

function test(x) {
Expand All @@ -9,10 +10,9 @@ function test(x) {
function getExn(f) {
if (f !== null) {
return f;
} else {
return Js_exn.raiseError("Js.Null.getExn");
}
throw new Error(new Error("Js.Null.getExn").RE_EXN_ID, {
cause: new Error("Js.Null.getExn")
});
}

function bind(x, f) {
Expand Down
6 changes: 3 additions & 3 deletions lib/js/js_option.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

let Js_exn = require("./js_exn.js");
let Caml_option = require("./caml_option.js");

function some(x) {
Expand All @@ -25,10 +26,9 @@ function isNone(x) {
function getExn(x) {
if (x !== undefined) {
return Caml_option.valFromOption(x);
} else {
return Js_exn.raiseError("getExn");
}
throw new Error(new Error("getExn").RE_EXN_ID, {
cause: new Error("getExn")
});
}

function equal(eq, a, b) {
Expand Down
6 changes: 3 additions & 3 deletions lib/js/js_undefined.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

let Js_exn = require("./js_exn.js");
let Caml_option = require("./caml_option.js");

function test(x) {
Expand All @@ -13,10 +14,9 @@ function testAny(x) {
function getExn(f) {
if (f !== undefined) {
return f;
} else {
return Js_exn.raiseError("Js.Undefined.getExn");
}
throw new Error(new Error("Js.Undefined.getExn").RE_EXN_ID, {
cause: new Error("Js.Undefined.getExn")
});
}

function bind(x, f) {
Expand Down