diff --git a/datastream.c b/datastream.c index 226706db..1cb327d6 100644 --- a/datastream.c +++ b/datastream.c @@ -90,9 +90,8 @@ static void render_frame(plm_t *mpeg, plm_frame_t *frame, void *d) { JSValue s[1]; s[0] = surfData.val; - JSValue cb = JS_DupValue(ds->js,ds->callback); + JSValue cb = ds->callback; JSValue cret = JS_Call(ds->js, cb, JS_NULL, 1, s); - JS_FreeValue(ds->js,cb); JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame); free(rgb); // TODO: raise exception diff --git a/geometry.c b/geometry.c index b95c7949..d72def22 100644 --- a/geometry.c +++ b/geometry.c @@ -514,7 +514,6 @@ static BufferCheckResult get_or_extend_buffer( res.size = old_size; return res; } - JS_FreeValue(js, old_buf); } } // If we reach here, we need a new buffer @@ -605,18 +604,15 @@ JSC_CCALL(geometry_tilemap_to_data, if (!JS_IsNull(pos_x_val)) { JS_ToFloat64(js, &pos_x, pos_x_val); } - JS_FreeValue(js, pos_x_val); JSValue pos_y_val = JS_GetPropertyStr(js, tilemap_obj, "pos_y"); if (!JS_IsNull(pos_y_val)) { JS_ToFloat64(js, &pos_y, pos_y_val); } - JS_FreeValue(js, pos_y_val); JSValue tiles_array = JS_GetPropertyStr(js, tilemap_obj, "tiles"); if (!JS_IsArray(tiles_array)) { - JS_FreeValue(js, tiles_array); - return JS_ThrowTypeError(js, "tilemap.tiles must be an array"); + return JS_ThrowTypeError(js, "tilemap.tiles must be an array"); } // Count tiles @@ -631,15 +627,12 @@ JSC_CCALL(geometry_tilemap_to_data, if (!JS_IsNull(tile) && !JS_IsNull(tile)) { tile_count++; } - JS_FreeValue(js, tile); } } - JS_FreeValue(js, col); } if (tile_count == 0) { - JS_FreeValue(js, tiles_array); - return JS_NewObject(js); + return JS_NewObject(js); } // Allocate buffers - 4 vertices per tile @@ -697,7 +690,6 @@ JSC_CCALL(geometry_tilemap_to_data, default_color.g = color.g; default_color.b = color.b; default_color.a = color.a; - JS_FreeValue(js, color_val); } } @@ -716,13 +708,10 @@ JSC_CCALL(geometry_tilemap_to_data, vertex_idx += 4; } - JS_FreeValue(js, tile); } } - JS_FreeValue(js, col); } - JS_FreeValue(js, tiles_array); // Create result object with blob data JS_FRAME(js); @@ -819,9 +808,7 @@ JSC_CCALL(geometry_sprites_to_data, if (!JS_IsNull(texture_width)) { JS_ToFloat64(js, &width, texture_width); } - JS_FreeValue(js, texture_width); } - JS_FreeValue(js, width_val); JSValue height_val = JS_GetPropertyStr(js, sprite, "height"); if (!JS_IsNull(height_val)) { @@ -832,21 +819,17 @@ JSC_CCALL(geometry_sprites_to_data, if (!JS_IsNull(texture_height)) { JS_ToFloat64(js, &height, texture_height); } - JS_FreeValue(js, texture_height); } - JS_FreeValue(js, height_val); JSValue anchor_x_val = JS_GetPropertyStr(js, sprite, "anchor_x"); if (!JS_IsNull(anchor_x_val)) { JS_ToFloat64(js, &anchor_x, anchor_x_val); } - JS_FreeValue(js, anchor_x_val); JSValue anchor_y_val = JS_GetPropertyStr(js, sprite, "anchor_y"); if (!JS_IsNull(anchor_y_val)) { JS_ToFloat64(js, &anchor_y, anchor_y_val); } - JS_FreeValue(js, anchor_y_val); HMM_Vec2 pos = js2vec2(js, pos_val); @@ -888,9 +871,7 @@ JSC_CCALL(geometry_sprites_to_data, if (!JS_IsNull(texture_height)) { JS_ToFloat64(js, &tex_height, texture_height); } - JS_FreeValue(js, texture_width); - JS_FreeValue(js, texture_height); - + // The rect contains pixel coordinates, normalize them float u0 = uv_rect.x / tex_width; float v0 = uv_rect.y / tex_height; @@ -902,7 +883,6 @@ JSC_CCALL(geometry_sprites_to_data, uv_data[base + 2] = u1; uv_data[base + 3] = v1; // bottom-right uv_data[base + 4] = u0; uv_data[base + 5] = v0; // top-left uv_data[base + 6] = u1; uv_data[base + 7] = v0; // top-right - JS_FreeValue(js, rect_val); } else { // Default UVs (0-1) uv_data[base + 0] = 0.0f; uv_data[base + 1] = 1.0f; @@ -942,11 +922,6 @@ JSC_CCALL(geometry_sprites_to_data, index_data[index_idx++] = base_idx + 2; vertex_idx += 4; - - JS_FreeValue(js, pos_val); - JS_FreeValue(js, texture_val); - JS_FreeValue(js, color_val); - JS_FreeValue(js, sprite); } // Create result object with blob data @@ -998,10 +973,6 @@ JSC_CCALL(geometry_transform_xy_blob, JS_ToFloat64(js, &e, e_val); JS_ToFloat64(js, &f, f_val); - JS_FreeValue(js, a_val); - JS_FreeValue(js, c_val); - JS_FreeValue(js, e_val); - JS_FreeValue(js, f_val); // Get blob data size_t xy_size; @@ -1053,7 +1024,6 @@ JSC_CCALL(geometry_array_blob, for (int i = 0; i < len; i++) { JSValue val = JS_GetPropertyNumber(js,arr,i); data[i] = js2number(js, val); - JS_FreeValue(js,val); } return js_new_blob_stoned_copy(js, data, sizeof(float)*len); @@ -1220,15 +1190,6 @@ JSC_CCALL(geometry_sprite_vertices, c = js2color(js, c_val); } - JS_FreeValue(js, x_val); - JS_FreeValue(js, y_val); - JS_FreeValue(js, w_val); - JS_FreeValue(js, h_val); - JS_FreeValue(js, u0_val); - JS_FreeValue(js, v0_val); - JS_FreeValue(js, u1_val); - JS_FreeValue(js, v1_val); - JS_FreeValue(js, c_val); // 4 vertices * 8 floats per vertex (x, y, u, v, r, g, b, a) float vertex_data[4 * 8]; diff --git a/imgui.cpp b/imgui.cpp index 95583c80..aa437498 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -42,8 +42,6 @@ static inline ImVec2 js2imvec2(JSContext *js, JSValue v) JSValue y = JS_GetPropertyNumber(js, v, 1); JS_ToFloat64(js, &dx, x); JS_ToFloat64(js, &dy, y); - JS_FreeValue(js, x); - JS_FreeValue(js, y); c.x = dx; c.y = dy; return c; @@ -61,10 +59,7 @@ static inline ImVec4 js2imvec4(JSContext *js, JSValue v) JS_ToFloat64(js, &dy, y); JS_ToFloat64(js, &dz, z); JS_ToFloat64(js, &dw, w); - JS_FreeValue(js, x); - JS_FreeValue(js, y); - JS_FreeValue(js, z); - JS_FreeValue(js, w); + c.x = dx; c.y = dy; c.z = dz; @@ -142,7 +137,7 @@ JSC_SSCALL(imgui_textinput, if (strcmp(buffer, str2)) ret = JS_NewString(js,buffer); else - ret = JS_DupValue(js,argv[1]); + ret = argv[1]; ) JSC_SSCALL(imgui_textbox, @@ -156,7 +151,7 @@ JSC_SSCALL(imgui_textbox, if (strcmp(buffer, str2)) ret = JS_NewString(js,buffer); else - ret = JS_DupValue(js,argv[1]); + ret = argv[1]; ) JSC_SCALL(imgui_combo, @@ -181,7 +176,6 @@ JSC_SCALL(imgui_combo, for (int i = 0; i < item_count; i++) { JSValue item = JS_GetPropertyNumber(js, argv[2], i); items[i] = JS_ToCString(js, item); - JS_FreeValue(js, item); } // If preview_str is set, find its index @@ -198,7 +192,7 @@ JSC_SCALL(imgui_combo, ret = JS_NewString(js, items[current_item]); } else { if (preview_str) { - ret = JS_DupValue(js, argv[1]); + ret = argv[1]; } else { ret = JS_NewString(js, items[current_item]); } @@ -222,12 +216,12 @@ JSC_SCALL(imgui_combo, } ret = JS_NewString(js, p); } else { - ret = JS_DupValue(js, argv[1]); + ret = argv[1]; } JS_FreeCString(js, items_str); } else { - ret = JS_DupValue(js, argv[1]); + ret = argv[1]; } if (preview_str) { @@ -258,7 +252,6 @@ JSC_SCALL(imgui_slider, double d; JS_ToFloat64(js, &d, val); a[i] = (float)d; - JS_FreeValue(js, val); } switch(n) { @@ -299,7 +292,6 @@ JSC_SCALL(imgui_intslider, double d; JS_ToFloat64(js, &d, val); a[i] = (int)d; - JS_FreeValue(js, val); } switch(n) { @@ -451,8 +443,6 @@ JSC_SCALL(imgui_table, send[0] = JS_NewInt32(js,spec->ColumnIndex); send[1] = JS_NewBool(js,spec->SortDirection == ImGuiSortDirection_Ascending); JS_Call(js, argv[3], JS_NULL, 2, send); - JS_FreeValue(js, send[0]); - JS_FreeValue(js, send[1]); } sort_specs->SpecsDirty = false; } @@ -795,11 +785,10 @@ JSC_CCALL(imgui_axisfmt, int y = num_to_yaxis(js2number(js, argv[0])); if (!JS_IsNull(axis_fmts[y])) { - JS_FreeValue(js, axis_fmts[y]); axis_fmts[y] = JS_NULL; } - axis_fmts[y] = JS_DupValue(js,argv[1]); + axis_fmts[y] = argv[1]; ImPlot::SetupAxisFormat(y, (ImPlotFormatter)jsformatter, (void*)(axis_fmts+y)); ) @@ -832,7 +821,6 @@ JSC_CCALL(imgui_startnode, ab[1] = JS_NewInt32(js,end_attr); JS_Call(js,argv[1], JS_NULL, 2, ab); - for (int i = 0; i < 2; i++) JS_FreeValue(js, ab[i]); } int node_id; @@ -840,7 +828,6 @@ JSC_CCALL(imgui_startnode, { JSValue a = JS_NewInt32(js,node_id); JS_Call(js, argv[2], JS_NULL, 1,&a); - JS_FreeValue(js,a); } int link_id; @@ -848,7 +835,6 @@ JSC_CCALL(imgui_startnode, { JSValue a = JS_NewInt32(js,link_id); JS_Call(js, argv[3], JS_NULL, 1,&a); - JS_FreeValue(js,a); } ) diff --git a/layout.c b/layout.c index 33c37a3e..e11c5b7d 100644 --- a/layout.c +++ b/layout.c @@ -94,7 +94,7 @@ JSValue js_##DIR = JS_GetPropertyStr(js, argv[1], #DIR); \ if (!JS_IsNull(js_##DIR)) { \ JS_ToFloat64(js, &margins[MARGIN], js_##DIR); \ if (isnan(margins[MARGIN])) margins[MARGIN] = 0; \ - JS_FreeValue(js, js_##DIR); \ + \ }\ static JSValue js_layout_set_margins(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) diff --git a/math.c b/math.c index 126d230d..1bde098d 100644 --- a/math.c +++ b/math.c @@ -12,7 +12,6 @@ static double js_getnum_uint32(JSContext *js, JSValue v, unsigned int i) { JSValue val = JS_GetPropertyNumber(js,v,i); double ret = js2number(js, val); - JS_FreeValue(js,val); return ret; } diff --git a/prosperon.c b/prosperon.c index 01816a10..d5db78d4 100644 --- a/prosperon.c +++ b/prosperon.c @@ -17,7 +17,6 @@ colorf js2color(JSContext *js,JSValue v) { color.b = js2number(js,c[2]); color.a = JS_IsNull(c[3]) ? 1.0 : js2number(js,c[3]); - for (int i = 0; i < 4; i++) JS_FreeValue(js,c[i]); } else if (JS_IsObject(v)) { JS_GETPROP(js, color.r, v, r, number) JS_GETPROP(js, color.g, v, g, number) @@ -45,8 +44,8 @@ HMM_Vec2 js2vec2(JSContext *js,JSValue v) // Check if it's an array if (JS_IsArray(v)) { - { JSValue val = JS_GetPropertyNumber(js,v,0); v2.X = js2number(js, val); JS_FreeValue(js,val); } - { JSValue val = JS_GetPropertyNumber(js,v,1); v2.Y = js2number(js, val); JS_FreeValue(js,val); } + { JSValue val = JS_GetPropertyNumber(js,v,0); v2.X = js2number(js, val); } + { JSValue val = JS_GetPropertyNumber(js,v,1); v2.Y = js2number(js, val); } } else { // Try to get x,y properties from object JSValue x_val = JS_GetPropertyStr(js, v, "x"); @@ -55,8 +54,6 @@ HMM_Vec2 js2vec2(JSContext *js,JSValue v) v2.X = js2number(js, x_val); v2.Y = js2number(js, y_val); - JS_FreeValue(js, x_val); - JS_FreeValue(js, y_val); } return v2; @@ -65,9 +62,9 @@ HMM_Vec2 js2vec2(JSContext *js,JSValue v) HMM_Vec3 js2vec3(JSContext *js,JSValue v) { HMM_Vec3 v3; - { JSValue val = JS_GetPropertyNumber(js, v,0); v3.x = js2number(js, val); JS_FreeValue(js,val); } - { JSValue val = JS_GetPropertyNumber(js, v,1); v3.y = js2number(js, val); JS_FreeValue(js,val); } - { JSValue val = JS_GetPropertyNumber(js, v,2); v3.z = js2number(js, val); JS_FreeValue(js,val); } + { JSValue val = JS_GetPropertyNumber(js, v,0); v3.x = js2number(js, val); } + { JSValue val = JS_GetPropertyNumber(js, v,1); v3.y = js2number(js, val); } + { JSValue val = JS_GetPropertyNumber(js, v,2); v3.z = js2number(js, val); } return v3; } @@ -129,7 +126,7 @@ HMM_Vec4 js2vec4(JSContext *js, JSValue v) { HMM_Vec4 v4; for (int i = 0; i < 4; i++) - { JSValue val = JS_GetPropertyNumber(js, v,i); v4.e[i] = js2number(js, val); JS_FreeValue(js,val); } + { JSValue val = JS_GetPropertyNumber(js, v,i); v4.e[i] = js2number(js, val); } return v4; } @@ -144,7 +141,7 @@ double arr_vec_length(JSContext *js,JSValue v) double sum = 0; for (int i = 0; i < len; i++) - { JSValue val = JS_GetPropertyNumber(js, v, i); double num = js2number(js, val); JS_FreeValue(js,val); sum += pow(num, 2); } + { JSValue val = JS_GetPropertyNumber(js, v, i); double num = js2number(js, val); sum += pow(num, 2); } return sqrt(sum); } @@ -171,7 +168,6 @@ HMM_Vec2 *js2cpvec2arr(JSContext *js,JSValue v) { for (int i = 0; i < n; i++) { JSValue ii = JS_GetPropertyNumber(js,v,i); arr[i] = js2vec2(js,ii); - JS_FreeValue(js,ii); } return arr; diff --git a/sprite.c b/sprite.c index dd0741b0..81dafd38 100644 --- a/sprite.c +++ b/sprite.c @@ -26,7 +26,6 @@ sprite *make_sprite(void) void sprite_free(JSRuntime *rt, sprite *sprite) { - JS_FreeValueRT(rt,sprite->image); free(sprite); } @@ -65,9 +64,7 @@ JSC_CCALL(sprite_set_affine, JSC_CCALL(sprite_set_image, sprite *sp = js2sprite(js,self); - if (!JS_IsNull(sp->image)) - JS_FreeValue(js,sp->image); - sp->image = JS_DupValue(js, argv[0]); + sp->image = argv[0]; ) JSC_CCALL(sprite_set, @@ -77,32 +74,29 @@ JSC_CCALL(sprite_set, JSValue val; val = JS_GetPropertyStr(js, argv[0], "pos"); - if (!JS_IsNull(val)) { sp->pos = js2vec2(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->pos = js2vec2(js, val); } val = JS_GetPropertyStr(js, argv[0], "center"); - if (!JS_IsNull(val)) { sp->center = js2vec2(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->center = js2vec2(js, val); } val = JS_GetPropertyStr(js, argv[0], "skew"); - if (!JS_IsNull(val)) { sp->skew = js2vec2(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->skew = js2vec2(js, val); } val = JS_GetPropertyStr(js, argv[0], "scale"); - if (!JS_IsNull(val)) { sp->scale = js2vec2(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->scale = js2vec2(js, val); } val = JS_GetPropertyStr(js, argv[0], "rotation"); - if (!JS_IsNull(val)) { sp->rotation = js2number(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->rotation = js2number(js, val); } val = JS_GetPropertyStr(js, argv[0], "layer"); - if (!JS_IsNull(val)) { sp->layer = js2number(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->layer = js2number(js, val); } val = JS_GetPropertyStr(js, argv[0], "color"); - if (!JS_IsNull(val)) { sp->color = js2color(js, val); JS_FreeValue(js, val); } + if (!JS_IsNull(val)) { sp->color = js2color(js, val); } val = JS_GetPropertyStr(js, argv[0], "image"); if (!JS_IsNull(val) && !JS_IsNull(val)) { - if (!JS_IsNull(sp->image)) JS_FreeValue(js, sp->image); sp->image = val; // Transfer ownership - } else { - JS_FreeValue(js, val); } ) diff --git a/transform.c b/transform.c index 86c4f2cf..e9e2c0c2 100644 --- a/transform.c +++ b/transform.c @@ -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; )