rm dupavlue and freevalue

This commit is contained in:
2026-02-25 09:41:27 -06:00
parent 3d87fdeb5f
commit 20376aa5e4
8 changed files with 34 additions and 109 deletions

View File

@@ -49,12 +49,6 @@ transform *make_transform()
}
void transform_free(JSRuntime *rt, transform *t) {
// JS_FreeValueRT(rt,t->self);
JS_FreeValueRT(rt,t->change_hook);
JS_FreeValueRT(rt,t->jsparent);
for (int i = 0; i < arrlen(t->jschildren); i++)
JS_FreeValueRT(rt,t->jschildren[i]);
arrfree(t->jschildren);
arrfree(t->children);
free(t);
@@ -79,8 +73,7 @@ void transform_clean(JSContext *js, transform *t)
}
if (!JS_IsNull(t->change_hook)) {
JSValue ret = JS_Call(js, t->change_hook, JS_DupValue(js,t->self), 0, NULL);
JS_FreeValue(js,ret);
JSValue ret = JS_Call(js, t->change_hook, t->self, 0, NULL);
}
}
@@ -188,22 +181,21 @@ QJSCLASSMARK_EXTERN(transform,)
static JSValue js_transform_get_change_hook(JSContext *js, JSValueConst self)
{
transform *t = js2transform(js,self);
return JS_DupValue(js,t->change_hook);
return t->change_hook;
}
static JSValue js_transform_set_change_hook(JSContext *js, JSValueConst self, JSValue v)
{
transform *t = js2transform(js,self);
if (!JS_IsNull(v) && !JS_IsFunction(v)) return JS_ThrowReferenceError(js, "Hook must be a function.");
JS_FreeValue(js,t->change_hook);
t->change_hook = JS_DupValue(js,v);
t->change_hook = v;
return JS_NULL;
}
static JSValue js_transform_get_parent(JSContext *js, JSValueConst self)
{
transform *t = js2transform(js,self);
if (t->parent) return JS_DupValue(js,t->jsparent);
if (t->parent) return t->jsparent;
return JS_NULL;
}
@@ -220,7 +212,6 @@ static JSValue js_transform_set_parent(JSContext *js, JSValueConst self, JSValue
if (t->parent) {
transform *cur_parent = t->parent;
JS_FreeValue(js,t->jsparent);
t->jsparent = JS_NULL;
for (int i = 0; i < arrlen(cur_parent->children); i++) {
@@ -232,7 +223,6 @@ static JSValue js_transform_set_parent(JSContext *js, JSValueConst self, JSValue
for (int i = 0; i < arrlen(cur_parent->jschildren); i++) {
if (JS_StrictEq(js,cur_parent->jschildren[i],self)) {
JS_FreeValue(js,cur_parent->jschildren[i]);
arrdelswap(cur_parent->jschildren,i);
break;
}
@@ -240,11 +230,11 @@ static JSValue js_transform_set_parent(JSContext *js, JSValueConst self, JSValue
}
t->parent = p;
t->jsparent = JS_DupValue(js,v);
t->jsparent = v;
if (p) {
arrput(p->children, t);
JSValue child = JS_DupValue(js,self);
JSValue child = self;
arrput(p->jschildren,child);
}
@@ -347,7 +337,7 @@ JSC_CCALL(transform_children,
JS_FRAME(js);
JS_ROOT(arr, JS_NewArray(js));
for (int i = 0; i < arrlen(t->jschildren); i++)
JS_SetPropertyNumber(js,arr.val,i,JS_DupValue(js,t->jschildren[i]));
JS_SetPropertyNumber(js,arr.val,i,t->jschildren[i]);
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame);
ret = arr.val;
)