From 86f4c56507bc94d03e7d94be6ede884b9e7b5358 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 8 May 2024 18:39:27 +0200 Subject: js: refactor * prefix to-be-separated modules with js * remove dynstreams dependency * untangle from EmptyPromise * move typeptr into tojs --- src/js/jserror.nim | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/js/jserror.nim (limited to 'src/js/jserror.nim') 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)) -- cgit 1.4.1-2-gfad0