github.com/primecitizens/pcz/std@v0.2.1/core/assert/throw_js.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 //go:build js && wasm 5 6 package assert 7 8 import ( 9 "github.com/primecitizens/pcz/std/core/assert/bindings" 10 jsbindings "github.com/primecitizens/pcz/std/ffi/js/bindings" 11 ) 12 13 // Throw triggers a fatal error that dumps a stack trace and exits. 14 // 15 //go:nosplit 16 func Throw(s ...string) { 17 switch len(s) { 18 case 0: 19 bindings.Append("fatal", " ", "error") 20 case 1: 21 bindings.Append("fatal", " ", "error", ":", " ", s[0]) 22 default: 23 bindings.Append("fatal", " ", "error", ":") 24 for _, s := range s { 25 bindings.Append(" ", s) 26 } 27 } 28 29 jsbindings.Exit(1) 30 bindings.Throw() 31 }