diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-21 19:10:01 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-21 19:10:30 +0200 |
commit | 31b359224632fd4e3c2aac667483ed249121efaa (patch) | |
tree | 95ea234aed2d4bc06c00257c2d3dff8657c78002 /src/js | |
parent | be777fc6bda37ff16afb2238f5192a5076a67188 (diff) | |
download | chawan-31b359224632fd4e3c2aac667483ed249121efaa.tar.gz |
js: override default toString tag of global
Some JS modules use this to check if they are running in a browser.
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/javascript.nim | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim index f2f72979..8a1a0794 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -286,7 +286,8 @@ func newJSClass*(ctx: JSContext; cdef: JSClassDefConst; tname: string; doAssert JS_SetProperty(ctx, proto, ctxOpaque.sym_refs[ITERATOR], val) == 1 let news = JS_NewAtomString(ctx, cdef.class_name) doAssert not JS_IsException(news) - ctx.definePropertyC(proto, ctxOpaque.sym_refs[TO_STRING_TAG], news) + ctx.definePropertyC(proto, ctxOpaque.sym_refs[TO_STRING_TAG], + JS_DupValue(ctx, news)) JS_SetClassProto(ctx, result, proto) ctx.addClassUnforgeable(proto, result, parent, unforgeable) if asglobal: @@ -294,6 +295,8 @@ func newJSClass*(ctx: JSContext; cdef: JSClassDefConst; tname: string; assert ctxOpaque.gclaz == "" ctxOpaque.gclaz = tname ctxOpaque.gparent = parent + ctx.definePropertyC(global, ctxOpaque.sym_refs[TO_STRING_TAG], + JS_DupValue(ctx, news)) if JS_SetPrototype(ctx, global, proto) != 1: raise newException(Defect, "Failed to set global prototype: " & $cdef.class_name) @@ -301,6 +304,7 @@ func newJSClass*(ctx: JSContext; cdef: JSClassDefConst; tname: string; ctxOpaque.unforgeable.withValue(result, uf): JS_SetPropertyFunctionList(ctx, global, addr uf[][0], cint(uf[].len)) JS_FreeValue(ctx, global) + JS_FreeValue(ctx, news) let jctor = ctx.newJSCFunction($cdef.class_name, ctor, 0, JS_CFUNC_constructor) if staticfuns.len > 0: |