diff options
-rw-r--r-- | lib/monoucha0/monoucha/javascript.nim | 15 | ||||
-rw-r--r-- | test/js/jsget.html | 17 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/monoucha0/monoucha/javascript.nim b/lib/monoucha0/monoucha/javascript.nim index f6496e70..fc92ff29 100644 --- a/lib/monoucha0/monoucha/javascript.nim +++ b/lib/monoucha0/monoucha/javascript.nim @@ -1271,7 +1271,9 @@ proc registerGetters(stmts: NimNode; info: RegistryInfo; return JS_ThrowTypeError(ctx, "'%s' called on an object that is not an instance of %s", `fn`, `jsname`) - when typeof(arg_0.`node`) is object: + when arg0.`node` is JSValue: + return JS_DupValue(ctx, arg0.`node`) + elif arg_0.`node` is object: return toJSP(ctx, arg_0, arg_0.`node`) else: return toJS(ctx, arg_0.`node`) @@ -1293,8 +1295,7 @@ proc registerSetters(stmts: NimNode; info: RegistryInfo; let fn = op.name let id = ident($bfSetter & "_" & tname & "_" & fn) stmts.add(quote do: - proc `id`(ctx: JSContext; this: JSValue; val: JSValue): JSValue - {.cdecl.} = + proc `id`(ctx: JSContext; this, val: JSValue): JSValue {.cdecl.} = when `t` is object: var arg_0: ptr `t` else: @@ -1305,8 +1306,12 @@ proc registerSetters(stmts: NimNode; info: RegistryInfo; `jsname`) # We can't just set arg_0.`node` directly, or fromJS may damage it. var nodeVal: typeof(arg_0.`node`) - if ctx.fromJS(val, nodeVal).isNone: - return JS_EXCEPTION + when nodeVal is JSValue: + static: + error(".jsset is not supported on JSValue; use jsfset") + else: + if ctx.fromJS(val, nodeVal).isNone: + return JS_EXCEPTION arg_0.`node` = move(nodeVal) return JS_DupValue(ctx, val) ) diff --git a/test/js/jsget.html b/test/js/jsget.html new file mode 100644 index 00000000..004df995 --- /dev/null +++ b/test/js/jsget.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<title>Test if .jsget handles ownership correctly.</title> +<script> +let a = {}; +let x = new CustomEvent("hi", {detail: a}); +x.detail; +x.detail; +x.detail; +x.detail; +x.detail; +x.detail; +x.detail; +x.detail; +x.detail; +x.detail; +</script> +Success |