From 8b8f2cbba10f50ae51e09fd08b58500b98346b8e Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 1 Feb 2025 16:03:14 +0100 Subject: dom: handle exceptions in module script --- src/html/dom.nim | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/html') 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 -- cgit