diff options
Diffstat (limited to 'src/html/script.nim')
-rw-r--r-- | src/html/script.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/html/script.nim b/src/html/script.nim index 8d1816ff..b465eb7e 100644 --- a/src/html/script.nim +++ b/src/html/script.nim @@ -1,4 +1,5 @@ import monoucha/javascript +import monoucha/jsopaque import monoucha/quickjs import types/referrer import types/url @@ -147,3 +148,15 @@ func uninitIfNull*(val: JSValue): JSValue = if JS_IsNull(val): return JS_UNINITIALIZED return val + +proc defineConsts*(ctx: JSContext; classid: JSClassID; consts: typedesc[enum]) = + let proto = JS_GetClassProto(ctx, classid) + let ctorProto = JS_GetPrototype(ctx, ctx.getOpaque().ctors[classid]) + #TODO it should be enough to define on the proto only, but apparently + # it isn't... + for e in consts: + let s = $e + ctx.definePropertyE(proto, s, uint16(e)) + ctx.definePropertyE(ctorProto, s, uint16(e)) + JS_FreeValue(ctx, ctorProto) + JS_FreeValue(ctx, proto) |