diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-24 03:55:48 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-24 03:55:48 +0100 |
commit | b1e2a9ce0c996de83b161a21d4e6ebb188a74699 (patch) | |
tree | 0b351dfaa41b81e94a8fe4a79174d5bac422da53 /src/js | |
parent | 2d038b2158ff59dc79f7eb741468fdced1fa4759 (diff) | |
download | chawan-b1e2a9ce0c996de83b161a21d4e6ebb188a74699.tar.gz |
dom: print parse errors to console
instead of trying to evaluate exceptions...
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/javascript.nim | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim index d208ffad..2327660d 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -195,20 +195,22 @@ proc setGlobal*[T](ctx: JSContext, global: JSValue, obj: T) = proc setInterruptHandler*(rt: JSRuntime, cb: JSInterruptHandler, opaque: pointer = nil) = JS_SetInterruptHandler(rt, cb, opaque) -proc writeException*(ctx: JSContext, s: Stream) = +proc getExceptionStr*(ctx: JSContext): string = + result = "" let ex = JS_GetException(ctx) let str = fromJS[string](ctx, ex) if str.isSome: - s.write(str.get & '\n') + result &= str.get & '\n' let stack = JS_GetPropertyStr(ctx, ex, cstring("stack")); if not JS_IsUndefined(stack): - let str = fromJS[string](ctx, stack) - if str.isSome: - s.write(str.get) - s.flush() + result &= fromJS[string](ctx, stack).get("") JS_FreeValue(ctx, stack) JS_FreeValue(ctx, ex) +proc writeException*(ctx: JSContext, s: Stream) = + s.write(ctx.getExceptionStr()) + s.flush() + proc runJSJobs*(rt: JSRuntime, err: Stream) = while JS_IsJobPending(rt): var ctx: JSContext |