Skip to content
Open
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
26 changes: 25 additions & 1 deletion abort/abort.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
///
/// Returns a value of type `T`. However, this function never actually returns a
/// value as it always causes a panic.
#cfg(not(target="native"))
#cfg(not(any(target="native", target="js")))
pub fn[T] abort(msg : String) -> T {
let _ = msg
panic_impl()
Expand All @@ -50,5 +50,29 @@ pub fn[T] abort(msg : String) -> T {
panic_impl()
}

///|
/// Aborts the program with an error message. Always causes a panic, regardless
/// of the message provided.
///
/// Parameters:
///
/// * `message` : A string containing the error message to be displayed when
/// aborting.
///
/// Returns a value of type `T`. However, this function never actually returns a
/// value as it always causes a panic.
#cfg(target="js")
pub fn[T] abort(msg : String) -> T {
panic_with_msg(msg)
// This line is unreachable, but it still needs to exist to satisfy the
// return type and force the compiler to generate $PanicError.
panic_impl()
}

///|
#cfg(target="js")
extern "js" fn panic_with_msg(msg : String) -> Unit =
#|(msg) => { throw new $PanicError(msg); }

///|
fn[T] panic_impl() -> T = "%panic"
Loading