about summary refs log tree commit diff stats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-01-24 12:54:36 +0100
committerbptato <nincsnevem662@gmail.com>2024-01-24 12:54:36 +0100
commitb69d0cd7e7bbde418c4bbb6d50f6c4270d1edf0f (patch)
tree7f4d5ae137e87c5b401d7b24490b5656a3c899d1 /src/js
parentfe2d01b8d6d569bf8855979ab0e83ae03b62eb73 (diff)
downloadchawan-b69d0cd7e7bbde418c4bbb6d50f6c4270d1edf0f.tar.gz
js: define toStringTag properly
Diffstat (limited to 'src/js')
-rw-r--r--src/js/javascript.nim6
-rw-r--r--src/js/tojs.nim9
2 files changed, 12 insertions, 3 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 7bcfb42c..4179f78b 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -261,9 +261,9 @@ func newJSClass*(ctx: JSContext, cdef: JSClassDefConst, tname: string,
   if cdef.exotic != nil and cdef.exotic.get_own_property != nil:
     let val = JS_DupValue(ctx, ctxOpaque.Array_prototype_values)
     doAssert JS_SetProperty(ctx, proto, ctxOpaque.sym_refs[ITERATOR], val) == 1
-  let toStringTag = ctxOpaque.sym_refs[TO_STRING_TAG]
-  let news = JS_NewString(ctx, cdef.class_name)
-  doAssert JS_SetProperty(ctx, proto, toStringTag, news) == 1
+  let news = JS_NewAtomString(ctx, cdef.class_name)
+  doAssert not JS_IsException(news)
+  ctx.definePropertyC(proto, ctxOpaque.sym_refs[TO_STRING_TAG], news)
   JS_SetClassProto(ctx, result, proto)
   ctx.addClassUnforgeable(proto, result, parent, unforgeable)
   if asglobal:
diff --git a/src/js/tojs.nim b/src/js/tojs.nim
index 2936ba28..c79d1bf2 100644
--- a/src/js/tojs.nim
+++ b/src/js/tojs.nim
@@ -105,6 +105,15 @@ makeToJSP(Result)
 makeToJSP(JSValue)
 makeToJSP(JSDict)
 
+proc defineProperty(ctx: JSContext, this: JSValue, name: JSAtom,
+    prop: JSValue, flags = cint(0)) =
+  if JS_DefinePropertyValue(ctx, this, name, prop, flags) <= 0:
+    raise newException(Defect, "Failed to define property string")
+
+proc definePropertyC*(ctx: JSContext, this: JSValue, name: JSAtom,
+    prop: JSValue) =
+  ctx.defineProperty(this, name, prop, JS_PROP_CONFIGURABLE)
+
 proc defineProperty(ctx: JSContext, this: JSValue, name: string,
     prop: JSValue, flags = cint(0)) =
   if JS_DefinePropertyValueStr(ctx, this, cstring(name), prop, flags) <= 0: