aboutsummaryrefslogtreecommitdiffstats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-01 16:03:14 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-01 16:03:14 +0100
commit8b8f2cbba10f50ae51e09fd08b58500b98346b8e (patch)
treebab1838d2ba82980d61b6b7c16fe86b2deeb6d05 /src/html
parent81c89e6de45c704d319e01ff1e641e3066705c9a (diff)
downloadchawan-8b8f2cbba10f50ae51e09fd08b58500b98346b8e.tar.gz
dom: handle exceptions in module script
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 11a91ef1..94e3fef0 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -5179,12 +5179,18 @@ proc fetchDescendantsAndLink(element: HTMLScriptElement; script: Script;
window.logException(script.baseURL)
return
ctx.setImportMeta(script.record, true)
- #TODO I think record can be a promise with TLA, and then this doesn't
- # work at all
let res = JS_EvalFunction(ctx, script.record)
if JS_IsException(res):
window.logException(script.baseURL)
return
+ var p: Promise[JSValue]
+ if ctx.fromJS(res, p).isSome:
+ p.then(proc(res: JSValue) =
+ if JS_IsException(res):
+ window.logException(script.baseURL)
+ )
+ else:
+ window.logException(script.baseURL)
JS_FreeValue(ctx, res)
#TODO settings object
@@ -5282,16 +5288,13 @@ proc execute*(element: HTMLScriptElement) =
let window = document.window
if window != nil and window.jsctx != nil:
let script = element.scriptResult.script
- let urls = script.baseURL.serialize(excludepassword = true)
let ctx = window.jsctx
if JS_IsException(script.record):
- window.console.error("Exception in document", urls,
- ctx.getExceptionMsg())
+ window.logException(script.baseURL)
else:
let ret = ctx.evalFunction(script.record)
if JS_IsException(ret):
- window.console.error("Exception in document", urls,
- ctx.getExceptionMsg())
+ window.logException(script.baseURL)
JS_FreeValue(ctx, ret)
document.currentScript = oldCurrentScript
else: discard #TODO