about summary refs log tree commit diff stats
path: root/src/js/jserror.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-08 18:39:27 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-08 18:39:27 +0200
commit86f4c56507bc94d03e7d94be6ede884b9e7b5358 (patch)
tree929ce32ada67e8b1d57787d8e6d038fa603fc31e /src/js/jserror.nim
parent5c891488423aa7ccbef2fb4332ff6cb4e3c05154 (diff)
downloadchawan-86f4c56507bc94d03e7d94be6ede884b9e7b5358.tar.gz
js: refactor
* prefix to-be-separated modules with js
* remove dynstreams dependency
* untangle from EmptyPromise
* move typeptr into tojs
Diffstat (limited to 'src/js/jserror.nim')
-rw-r--r--src/js/jserror.nim59
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))