diff options
author | bptato <nincsnevem662@gmail.com> | 2024-05-04 21:52:48 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-05-04 21:56:12 +0200 |
commit | 698b6002528750a7af0a0df9ccac8e05d6b923c8 (patch) | |
tree | 4d0bcf804f94af90087d2132d6c2ae93d999dd4b /src/js | |
parent | 731f88183946a17888282c98ae60ecc58c98d96c (diff) | |
download | chawan-698b6002528750a7af0a0df9ccac8e05d6b923c8.tar.gz |
js: move fromJS_or_return nil check to JSError toJS
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/javascript.nim | 4 | ||||
-rw-r--r-- | src/js/tojs.nim | 7 |
2 files changed, 4 insertions, 7 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim index 44c7ef06..57baff45 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -548,8 +548,6 @@ template fromJS_or_return*(t, ctx, val: untyped): untyped = ( let x = fromJS[t](ctx, val) if x.isErr: - if x.error == nil: - return JS_EXCEPTION return toJS(ctx, x.error) x.get ) @@ -558,8 +556,6 @@ template fromJSP_or_return*(t, ctx, val: untyped): untyped = ( let x = fromJSP[t](ctx, val) if x.isErr: - if x.error == nil: - return JS_EXCEPTION return toJS(ctx, x.error) x.get ) diff --git a/src/js/tojs.nim b/src/js/tojs.nim index ea6f35f2..bf2af7cc 100644 --- a/src/js/tojs.nim +++ b/src/js/tojs.nim @@ -210,9 +210,8 @@ proc toJS[T, E](ctx: JSContext; opt: Result[T, E]): JSValue = return JS_UNDEFINED else: when not (E is void): - let res = toJS(ctx, opt.error) - if not JS_IsNull(res): - return JS_Throw(ctx, res) + if opt.error != nil: + return JS_Throw(ctx, toJS(ctx, opt.error)) return JS_EXCEPTION proc toJS(ctx: JSContext; s: seq): JSValue = @@ -376,6 +375,8 @@ proc toJS[T, E](ctx: JSContext; promise: Promise[Result[T, E]]): JSValue = return jsPromise proc toJS*(ctx: JSContext; err: JSError): JSValue = + if err == nil: + return JS_EXCEPTION if err.e notin QuickJSErrors: return toJSRefObj(ctx, err) var msg = toJS(ctx, err.message) |