Skip to content

Commit 6982cbc

Browse files
committed
Using raise instead of JS.throw
1 parent 0557c58 commit 6982cbc

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
defmodule ElixirScript.Test.Assertions do
22
def assert(value) do
33
if !value do
4-
ElixirScript.JS.throw(%ElixirScript.Test.AssertionError{
5-
message: "failed"
6-
})
4+
raise ElixirScript.Test.AssertionError, message: "failed"
75
end
86
end
97
end

src/javascript/lib/core/erlang_compat/erlang.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,19 +478,25 @@ function _throw(term) {
478478
}
479479

480480
function error(reason) {
481+
let theError = null;
482+
481483
if (reason instanceof Map && reason.has(Symbol.for('__exception__'))) {
482484
let name = Symbol.keyFor(reason.get(Symbol.for('__struct__')).__MODULE__);
483485
name = name
484486
.split('.')
485487
.slice(1)
486488
.join('.');
487489
const message = reason.get(Symbol.for('message'));
488-
throw new Error(`** (${name}) ${message}`);
490+
theError = new Error(`** (${name}) ${message}`);
489491
} else if (is_binary(reason)) {
490-
throw new Error(`** (RuntimeError) ${reason}`);
492+
theError = new Error(`** (RuntimeError) ${reason}`);
491493
} else {
492-
throw new Error(`** (ErlangError) Erlang Error ${reason.toString()}`);
494+
theError = new Error(`** (ErlangError) Erlang Error ${reason.toString()}`);
493495
}
496+
497+
theError.__reason = reason;
498+
499+
throw theError;
494500
}
495501

496502
function exit(...args) {

0 commit comments

Comments
 (0)