about summary refs log tree commit diff stats
path: root/src
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 /src
parent21178cc60e1d4ba3a6780c5691b9cfb5e7908aa8 (diff)
downloadchawan-9742a2b41d374b4eaea44c1c2d715bf704d752af.tar.gz
quickjs: make JSValue distinct on 32-bit
Diffstat (limited to 'src')
-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]
a id='n181' href='#n181'>181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292