aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-30 17:36:53 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-30 17:40:21 +0200
commit29cf3549a62878cc1315da5cf3e93891173e2d4d (patch)
tree3b74bd8fb5643d3cf09053546192fec94cdc987c /src/js
parentb4cbdb8e1eb8af2a55d6a5b22316d59c87612578 (diff)
downloadchawan-29cf3549a62878cc1315da5cf3e93891173e2d4d.tar.gz
Fix GCC 14 compilation
TODO: find the exact flags we need instead of -fpermissive. See also: https://todo.sr.ht/~bptato/chawan/12 https://forum.nim-lang.org/t/11587
Diffstat (limited to 'src/js')
-rw-r--r--src/js/tojs.nim37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/js/tojs.nim b/src/js/tojs.nim
index 7697ea4a..59109884 100644
--- a/src/js/tojs.nim
+++ b/src/js/tojs.nim
@@ -106,6 +106,15 @@ proc defineProperty(ctx: JSContext; this: JSValue; name: JSAtom;
if JS_DefinePropertyValue(ctx, this, name, prop, flags) <= 0:
raise newException(Defect, "Failed to define property string")
+proc defineProperty(ctx: JSContext; this, name, prop: JSValue;
+ flags = cint(0)) =
+ let atom = JS_ValueToAtom(ctx, prop);
+ JS_FreeValue(ctx, prop);
+ if unlikely(atom == JS_ATOM_NULL):
+ raise newException(Defect, "Failed to define property string")
+ ctx.defineProperty(this, atom, prop, flags)
+ JS_FreeAtom(ctx, atom);
+
proc definePropertyC*(ctx: JSContext; this: JSValue; name: JSAtom;
prop: JSValue) =
ctx.defineProperty(this, name, prop, JS_PROP_CONFIGURABLE)
@@ -195,7 +204,7 @@ proc toJS*(ctx: JSContext; opt: Option): JSValue =
return toJS(ctx, opt.get)
return JS_NULL
-proc toJS[T, E](ctx: JSContext; opt: Result[T, E]): JSValue =
+proc toJS*[T, E](ctx: JSContext; opt: Result[T, E]): JSValue =
if opt.isSome:
when not (T is void):
return toJS(ctx, opt.get)
@@ -207,16 +216,15 @@ proc toJS[T, E](ctx: JSContext; opt: Result[T, E]): JSValue =
return JS_Throw(ctx, toJS(ctx, opt.error))
return JS_EXCEPTION
-proc toJS(ctx: JSContext; s: seq): JSValue =
+proc toJS*(ctx: JSContext; s: seq): JSValue =
let a = JS_NewArray(ctx)
if not JS_IsException(a):
- for i in 0..s.high:
- let j = toJS(ctx, s[i])
- if JS_IsException(j):
- return j
- if JS_DefinePropertyValueInt64(ctx, a, int64(i), j,
- JS_PROP_C_W_E or JS_PROP_THROW) < 0:
- return JS_EXCEPTION
+ for i, x in s:
+ let val = toJS(ctx, x)
+ if JS_IsException(val):
+ return val
+ ctx.defineProperty(a, JS_NewInt64(ctx, int64(i)), val,
+ JS_PROP_C_W_E or JS_PROP_THROW)
return a
proc toJS*[T](ctx: JSContext; s: set[T]): JSValue =
@@ -237,12 +245,11 @@ proc toJS(ctx: JSContext; t: tuple): JSValue =
if not JS_IsException(a):
var i = 0
for f in t.fields:
- let j = toJS(ctx, f)
- if JS_IsException(j):
- return j
- if JS_DefinePropertyValueInt64(ctx, a, int64(i), j,
- JS_PROP_C_W_E or JS_PROP_THROW) < 0:
- return JS_EXCEPTION
+ let val = toJS(ctx, f)
+ if JS_IsException(val):
+ return val
+ ctx.defineProperty(a, JS_NewInt64(ctx, int64(i)), val,
+ JS_PROP_C_W_E or JS_PROP_THROW)
inc i
return a