diff options
author | bptato <nincsnevem662@gmail.com> | 2024-08-02 00:29:45 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-08-02 00:44:19 +0200 |
commit | 8f88e5f05b76dd9b16ba91c9e28f07bd1549ae93 (patch) | |
tree | af65e0743bc92a0dd312b0f0f09b36ec8fa14d70 /src/js | |
parent | 22625453ef3275adab3a47990c242dc92397b02b (diff) | |
download | chawan-8f88e5f05b76dd9b16ba91c9e28f07bd1549ae93.tar.gz |
cssvalues, twtstr, mediaquery: refactor & fixes
* cssvalues, twtstr: unify enum parsing code paths, parse enums by bisearch instead of hash tables * mediaquery: refactor (long overdue), fix range comparison syntax parsing, make ident comparisons case-insensitive (as they should be)
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/domexception.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/js/domexception.nim b/src/js/domexception.nim index 68e313e9..1fab7ed9 100644 --- a/src/js/domexception.nim +++ b/src/js/domexception.nim @@ -28,18 +28,24 @@ const NamesTable = { "TimeoutError": 23u16, "InvalidNodeTypeError": 24u16, "DataCloneError": 25u16 -}.toTable() +} type DOMException* = ref object of JSError name* {.jsget.}: string + code {.jsget.}: uint16 DOMResult*[T] = Result[T, DOMException] jsDestructor(DOMException) proc newDOMException*(message = ""; name = "Error"): DOMException {.jsctor.} = - return DOMException(e: jeDOMException, name: name, message: message) + let ex = DOMException(e: jeDOMException, name: name, message: message) + for it in NamesTable: + if it[0] == name: + ex.code = it[1] + break + return ex template errDOMException*(message, name: string): untyped = err(newDOMException(message, name)) @@ -47,8 +53,5 @@ template errDOMException*(message, name: string): untyped = func message0(this: DOMException): string {.jsfget: "message".} = return this.message -func code(this: DOMException): uint16 {.jsfget.} = - return NamesTable.getOrDefault(this.name, 0u16) - proc addDOMExceptionModule*(ctx: JSContext) = ctx.registerType(DOMException, JS_CLASS_ERROR, errid = opt(jeDOMException)) |