diff options
Diffstat (limited to 'src/js/jserror.nim')
-rw-r--r-- | src/js/jserror.nim | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/js/jserror.nim b/src/js/jserror.nim new file mode 100644 index 00000000..b4101830 --- /dev/null +++ b/src/js/jserror.nim @@ -0,0 +1,59 @@ +import types/opt + +type + JSError* = ref object of RootObj + e*: JSErrorEnum + message*: string + + JSErrorEnum* = enum + # QuickJS internal errors + jeEvalError = "EvalError" + jeRangeError = "RangeError" + jeReferenceError = "ReferenceError" + jeSyntaxError = "SyntaxError" + jeTypeError = "TypeError" + jeURIError = "URIError" + jeInternalError = "InternalError" + jeAggregateError = "AggregateError" + # Chawan errors + jeDOMException = "DOMException" + + JSResult*[T] = Result[T, JSError] + +const QuickJSErrors* = [ + jeEvalError, + jeRangeError, + jeReferenceError, + jeSyntaxError, + jeTypeError, + jeURIError, + jeInternalError, + jeAggregateError +] + +proc newEvalError*(message: string): JSError = + return JSError(e: jeEvalError, message: message) + +proc newRangeError*(message: string): JSError = + return JSError(e: jeRangeError, message: message) + +proc newReferenceError*(message: string): JSError = + return JSError(e: jeReferenceError, message: message) + +proc newSyntaxError*(message: string): JSError = + return JSError(e: jeSyntaxError, message: message) + +proc newTypeError*(message: string): JSError = + return JSError(e: jeTypeError, message: message) + +proc newURIError*(message: string): JSError = + return JSError(e: jeURIError, message: message) + +proc newInternalError*(message: string): JSError = + return JSError(e: jeInternalError, message: message) + +proc newAggregateError*(message: string): JSError = + return JSError(e: jeAggregateError, message: message) + +template errTypeError*(message: string): untyped = + err(newTypeError(message)) |