aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-02-05 19:14:16 +0100
committerbptato <nincsnevem662@gmail.com>2023-02-05 19:14:16 +0100
commit9742a2b41d374b4eaea44c1c2d715bf704d752af (patch)
tree9868c388e45dc25b89e360515df3eb8a9a9ab5fe
parent21178cc60e1d4ba3a6780c5691b9cfb5e7908aa8 (diff)
downloadchawan-9742a2b41d374b4eaea44c1c2d715bf704d752af.tar.gz
quickjs: make JSValue distinct on 32-bit
-rw-r--r--src/bindings/quickjs.nim6
-rw-r--r--src/js/javascript.nim3
2 files changed, 7 insertions, 2 deletions
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim
index 2d37a789..648abfb2 100644
--- a/src/bindings/quickjs.nim
+++ b/src/bindings/quickjs.nim
@@ -47,10 +47,10 @@ const ## all tags with a reference count are negative
when sizeof(int) < sizeof(int64):
{.passC: "-DJS_NAN_BOXING".}
type
- JSValue* {.importc, header: qjsheader.} = uint64
+ JSValue* {.importc, header: qjsheader.} = distinct uint64
template JS_VALUE_GET_TAG*(v: untyped): int32 =
- cast[int32](v shr 32)
+ cast[int32](cast[uint64](v) shr 32)
template JS_VALUE_GET_PTR*(v: untyped): pointer =
cast[pointer](v)
@@ -60,6 +60,8 @@ when sizeof(int) < sizeof(int64):
template JS_MKPTR*(t, p: untyped): JSValue =
JSValue((cast[uint64](t) shl 32) or cast[uint](p))
+
+ proc `==`*(a, b: JSValue): bool {.borrow.}
else:
type
JSValueUnion* {.importc, header: qjsheader, union.} = object
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index f13305c7..f3193199 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -56,6 +56,9 @@ export
JS_GetGlobalObject, JS_FreeValue, JS_IsException, JS_GetPropertyStr,
JS_IsFunction, JS_NewCFunctionData, JS_Call, JS_DupValue
+when sizeof(int) < sizeof(int64):
+ export quickjs.`==`
+
type
JSContextOpaque* = ref object
creg: Table[string, JSClassID]