aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-01-11 19:39:56 +0100
committerbptato <nincsnevem662@gmail.com>2024-01-11 19:39:56 +0100
commitb7570a38b70059fbb9a3fb3d32df153ad5f9706f (patch)
tree0bcb774fd862afa92944268636d11d3b08f0cd7b /src
parent091764fd976831e0b6d86f4e364dceb4e9c1114f (diff)
downloadchawan-b7570a38b70059fbb9a3fb3d32df153ad5f9706f.tar.gz
Use errDOMException template everywhere
Diffstat (limited to 'src')
-rw-r--r--src/css/cssparser.nim14
-rw-r--r--src/img/path.nim12
-rw-r--r--src/js/base64.nim8
-rw-r--r--src/xhr/formdata.nim8
-rw-r--r--src/xhr/xmlhttprequest.nim6
5 files changed, 24 insertions, 24 deletions
diff --git a/src/css/cssparser.nim b/src/css/cssparser.nim
index 6f4f666a..88b41eab 100644
--- a/src/css/cssparser.nim
+++ b/src/css/cssparser.nim
@@ -730,7 +730,7 @@ proc parseRule(state: var CSSParseState): DOMResult[CSSRule] =
while state.has() and state.peek() == CSS_WHITESPACE_TOKEN:
discard state.consume()
if not state.has():
- return err(newDOMException("Unexpected EOF", "SyntaxError"))
+ return errDOMException("Unexpected EOF", "SyntaxError")
var res: CSSRule
if state.peek() == CSS_AT_KEYWORD_TOKEN:
@@ -740,12 +740,12 @@ proc parseRule(state: var CSSParseState): DOMResult[CSSRule] =
if q.isSome:
res = q.get
else:
- return err(newDOMException("No qualified rule found!", "SyntaxError"))
+ return errDOMException("No qualified rule found!", "SyntaxError")
while state.has() and state.peek() == CSS_WHITESPACE_TOKEN:
discard state.consume()
if state.has():
- return err(newDOMException("EOF not reached", "SyntaxError"))
+ return errDOMException("EOF not reached", "SyntaxError")
return ok(res)
proc parseRule*(inputStream: Stream): DOMResult[CSSRule] =
@@ -758,13 +758,13 @@ proc parseDeclaration(state: var CSSParseState): DOMResult[CSSDeclaration] =
discard state.consume()
if not state.has() or state.peek() != CSS_IDENT_TOKEN:
- return err(newDOMException("No ident token found", "SyntaxError"))
+ return errDOMException("No ident token found", "SyntaxError")
let d = state.consumeDeclaration()
if d.isSome:
return ok(d.get)
- return err(newDOMException("No declaration found", "SyntaxError"))
+ return errDOMException("No declaration found", "SyntaxError")
proc parseDeclaration*(inputStream: Stream): DOMResult[CSSDeclaration] =
var state = CSSParseState()
@@ -802,14 +802,14 @@ proc parseComponentValue(state: var CSSParseState):
while state.has() and state.peek() == CSS_WHITESPACE_TOKEN:
discard state.consume()
if not state.has():
- return err(newDOMException("Unexpected EOF", "SyntaxError"))
+ return errDOMException("Unexpected EOF", "SyntaxError")
let res = state.consumeComponentValue()
while state.has() and state.peek() == CSS_WHITESPACE_TOKEN:
discard state.consume()
if state.has():
- return err(newDOMException("EOF not reached", "SyntaxError"))
+ return errDOMException("EOF not reached", "SyntaxError")
return ok(res)
proc parseComponentValue*(inputStream: Stream): DOMResult[CSSComponentValue] =
diff --git a/src/img/path.nim b/src/img/path.nim
index a1ef9cb7..61c71888 100644
--- a/src/img/path.nim
+++ b/src/img/path.nim
@@ -305,8 +305,8 @@ proc arcTo*(path: Path, x1, y1, x2, y2, radius: float64): Err[DOMException] =
if classify(v) in {fcInf, fcNegInf, fcNan}:
return ok()
if radius < 0:
- return err(newDOMException("Expected positive radius, but got negative",
- "IndexSizeError"))
+ return errDOMException("Expected positive radius, but got negative",
+ "IndexSizeError")
path.ensureSubpath(x1, y1)
#TODO this should be transformed by the inverse of the transformation matrix
let v0 = path.subpaths[^1].points[^1]
@@ -352,8 +352,8 @@ proc arc*(path: Path, x, y, radius, startAngle, endAngle: float64,
if classify(v) in {fcInf, fcNegInf, fcNan}:
return ok()
if radius < 0:
- return err(newDOMException("Expected positive radius, but got negative",
- "IndexSizeError"))
+ return errDOMException("Expected positive radius, but got negative",
+ "IndexSizeError")
let o = Vector2D(x: x, y: y)
var s = resolveEllipsePoint(o, startAngle, radius, radius, 0)
var e = resolveEllipsePoint(o, endAngle, radius, radius, 0)
@@ -374,8 +374,8 @@ proc ellipse*(path: Path, x, y, radiusX, radiusY, rotation, startAngle,
if classify(v) in {fcInf, fcNegInf, fcNan}:
return ok()
if radiusX < 0 or radiusY < 0:
- return err(newDOMException("Expected positive radius, but got negative",
- "IndexSizeError"))
+ return errDOMException("Expected positive radius, but got negative",
+ "IndexSizeError")
let o = Vector2D(x: x, y: y)
var s = resolveEllipsePoint(o, startAngle, radiusX, radiusY, rotation)
var e = resolveEllipsePoint(o, endAngle, radiusX, radiusY, rotation)
diff --git a/src/js/base64.nim b/src/js/base64.nim
index f72131c3..c9375c13 100644
--- a/src/js/base64.nim
+++ b/src/js/base64.nim
@@ -14,13 +14,13 @@ proc atob*(data: string): DOMResult[NarrowString] =
let ds = NarrowString(base64.decode(data))
return ok(ds)
except ValueError:
- return err(newDOMException("Invalid character in string",
- "InvalidCharacterError"))
+ return errDOMException("Invalid character in string",
+ "InvalidCharacterError")
proc btoa*(data: JSString): DOMResult[string] =
if JS_IsStringWideChar(data):
- return err(newDOMException("Invalid character in string",
- "InvalidCharacterError"))
+ return errDOMException("Invalid character in string",
+ "InvalidCharacterError")
let len = int(JS_GetStringLength(data))
if len == 0:
return ok("")
diff --git a/src/xhr/formdata.nim b/src/xhr/formdata.nim
index 98c96b54..e5cc5aa0 100644
--- a/src/xhr/formdata.nim
+++ b/src/xhr/formdata.nim
@@ -32,11 +32,11 @@ proc newFormData*(form: HTMLFormElement = nil,
if form != nil:
if submitter != nil:
if not submitter.isSubmitButton():
- return err(newDOMException("Submitter must be a submit button",
- "InvalidStateError"))
+ return errDOMException("Submitter must be a submit button",
+ "InvalidStateError")
if FormAssociatedElement(submitter).form != form:
- return err(newDOMException("Submitter's form owner is not form",
- "InvalidStateError"))
+ return errDOMException("Submitter's form owner is not form",
+ "InvalidStateError")
this.entries = constructEntryList(form, submitter).get(@[])
return ok(this)
diff --git a/src/xhr/xmlhttprequest.nim b/src/xhr/xmlhttprequest.nim
index 38576b2b..7b1d535f 100644
--- a/src/xhr/xmlhttprequest.nim
+++ b/src/xhr/xmlhttprequest.nim
@@ -74,16 +74,16 @@ proc parseMethod(s: string): DOMResult[HttpMethod] =
of "post": ok(HTTP_POST)
of "put": ok(HTTP_PUT)
of "connect", "trace", "track":
- err(newDOMException("Forbidden method", "SecurityError"))
+ errDOMException("Forbidden method", "SecurityError")
else:
- err(newDOMException("Invalid method", "SyntaxError"))
+ errDOMException("Invalid method", "SyntaxError")
proc open(this: XMLHttpRequest, httpMethod, url: string): Err[DOMException]
{.jsfunc.} =
let httpMethod = ?parseMethod(httpMethod)
let x = parseURL(url)
if x.isNone:
- return err(newDOMException("Invalid URL", "SyntaxError"))
+ return errDOMException("Invalid URL", "SyntaxError")
let parsedURL = x.get
#TODO async, username, password arguments
let async = true