Skip to content

Commit 8b661e3

Browse files
feat: enable abort for non-wasm backend
1 parent 64ccb0c commit 8b661e3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

abort/abort.mbt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,34 @@
2323
///
2424
/// Returns a value of type `T`. However, this function never actually returns a
2525
/// value as it always causes a panic.
26+
#cfg(any(target="wasm", target="wasm-gc"))
2627
pub fn[T] abort(msg : String) -> T {
2728
let _ = msg
2829
panic_impl()
2930
}
3031

32+
///|
33+
#cfg(target="js")
34+
pub fn[T] abort(msg : String) -> T {
35+
console_error(msg)
36+
panic_impl()
37+
}
38+
39+
///|
40+
#cfg(target="js")
41+
extern "js" fn console_error(msg : String) =
42+
#|console.error
43+
44+
///|
45+
#cfg(target="native")
46+
fn println(s : String) -> Unit = "%println"
47+
48+
///|
49+
#cfg(target="native")
50+
pub fn[T] abort(msg : String) -> T {
51+
println(msg)
52+
panic_impl()
53+
}
54+
3155
///|
3256
fn[T] panic_impl() -> T = "%panic"

0 commit comments

Comments
 (0)