diff options
author | bptato <nincsnevem662@gmail.com> | 2023-08-30 19:45:21 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-08-30 19:45:21 +0200 |
commit | 8b78543eeb81aa40e1562bd702ccf38c6538547f (patch) | |
tree | 4a95de24d07a89eb097a92e89e93c1acd88d8a4e /src/js/fromjs.nim | |
parent | 47383328e1a861401fd52505642f98fa3524a895 (diff) | |
download | chawan-8b78543eeb81aa40e1562bd702ccf38c6538547f.tar.gz |
javascript: fix fromJSFunction, simplify setOpaque
* fromJSFunction: dup the value, so that it cannot go out of context. * setOpaque no longer calls GC_ref, so no need for it to be generic instead of just taking a pointer.
Diffstat (limited to 'src/js/fromjs.nim')
-rw-r--r-- | src/js/fromjs.nim | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/js/fromjs.nim b/src/js/fromjs.nim index 9c356da0..c7e27110 100644 --- a/src/js/fromjs.nim +++ b/src/js/fromjs.nim @@ -267,12 +267,14 @@ proc fromJSTable[A, B](ctx: JSContext, val: JSValue): JSResult[Table[A, B]] = #TODO varargs proc fromJSFunction1*[T, U](ctx: JSContext, val: JSValue): proc(x: U): JSResult[T] = + let dupval = JS_DupValue(ctx, JS_DupValue(ctx, val)) # save return proc(x: U): JSResult[T] = var arg1 = toJS(ctx, x) #TODO exceptions? - let ret = JS_Call(ctx, val, JS_UNDEFINED, 1, addr arg1) + let ret = JS_Call(ctx, dupval, JS_UNDEFINED, 1, addr arg1) when T isnot void: result = fromJS[T](ctx, ret) + JS_FreeValue(ctx, dupval) JS_FreeValue(ctx, ret) proc isErrType(rt: NimNode): bool = |