diff --git a/clipboard.c b/clipboard.c index bdc0065..1f2969e 100644 --- a/clipboard.c +++ b/clipboard.c @@ -70,7 +70,8 @@ JSC_CCALL(clipboard_get_mime_types, JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); for (size_t i = 0; i < count; i++) { - JS_SetPropertyNumber(js, arr, i, JS_NewString(js, types[i])); + JSValue s = JS_NewString(js, types[i]); + JS_SetPropertyNumber(js, arr, i, s); } SDL_free(types); JS_RETURN(arr); diff --git a/gpu.c b/gpu.c index 42bf46a..470c6f0 100644 --- a/gpu.c +++ b/gpu.c @@ -882,12 +882,13 @@ JSC_CCALL(gpu_shader_format, JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); int i = 0; - if (fmt & SDL_GPU_SHADERFORMAT_PRIVATE) JS_SetPropertyNumber(js, arr, i++, JS_NewString(js, ".private")); - if (fmt & SDL_GPU_SHADERFORMAT_SPIRV) JS_SetPropertyNumber(js, arr, i++, JS_NewString(js, "spv")); - if (fmt & SDL_GPU_SHADERFORMAT_DXBC) JS_SetPropertyNumber(js, arr, i++, JS_NewString(js, "dxbc")); - if (fmt & SDL_GPU_SHADERFORMAT_DXIL) JS_SetPropertyNumber(js, arr, i++, JS_NewString(js, "dxil")); - if (fmt & SDL_GPU_SHADERFORMAT_MSL) JS_SetPropertyNumber(js, arr, i++, JS_NewString(js, "msl")); - if (fmt & SDL_GPU_SHADERFORMAT_METALLIB) JS_SetPropertyNumber(js, arr, i++, JS_NewString(js, "metallib")); + JSValue tmp; + if (fmt & SDL_GPU_SHADERFORMAT_PRIVATE) { tmp = JS_NewString(js, ".private"); JS_SetPropertyNumber(js, arr, i++, tmp); } + if (fmt & SDL_GPU_SHADERFORMAT_SPIRV) { tmp = JS_NewString(js, "spv"); JS_SetPropertyNumber(js, arr, i++, tmp); } + if (fmt & SDL_GPU_SHADERFORMAT_DXBC) { tmp = JS_NewString(js, "dxbc"); JS_SetPropertyNumber(js, arr, i++, tmp); } + if (fmt & SDL_GPU_SHADERFORMAT_DXIL) { tmp = JS_NewString(js, "dxil"); JS_SetPropertyNumber(js, arr, i++, tmp); } + if (fmt & SDL_GPU_SHADERFORMAT_MSL) { tmp = JS_NewString(js, "msl"); JS_SetPropertyNumber(js, arr, i++, tmp); } + if (fmt & SDL_GPU_SHADERFORMAT_METALLIB) { tmp = JS_NewString(js, "metallib"); JS_SetPropertyNumber(js, arr, i++, tmp); } JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame); ret = arr; ) @@ -1804,16 +1805,25 @@ CELL_USE_INIT( JS_LOCAL(ret, JS_NewObject(js)); // Create GPU constructor - JS_SetPropertyStr(js, ret, "gpu", JS_NewCFunction2(js, js_gpu_constructor, "gpu", 1, JS_CFUNC_generic, 0)); + JSValue fn; + fn = JS_NewCFunction2(js, js_gpu_constructor, "gpu", 1, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "gpu", fn); // Add GPU object constructors - JS_SetPropertyStr(js, ret, "sampler", JS_NewCFunction2(js, js_gpu_sampler_constructor, "sampler", 2, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ret, "shader", JS_NewCFunction2(js, js_gpu_shader_constructor, "shader", 2, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ret, "graphics_pipeline", JS_NewCFunction2(js, js_gpu_graphics_pipeline_constructor, "graphics_pipeline", 2, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ret, "compute_pipeline", JS_NewCFunction2(js, js_gpu_compute_pipeline_constructor, "compute_pipeline", 2, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ret, "buffer", JS_NewCFunction2(js, js_gpu_buffer_constructor, "buffer", 2, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ret, "transfer_buffer", JS_NewCFunction2(js, js_gpu_transfer_buffer_constructor, "transfer_buffer", 2, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ret, "texture", JS_NewCFunction2(js, js_gpu_texture_constructor, "texture", 2, JS_CFUNC_generic, 0)); + fn = JS_NewCFunction2(js, js_gpu_sampler_constructor, "sampler", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "sampler", fn); + fn = JS_NewCFunction2(js, js_gpu_shader_constructor, "shader", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "shader", fn); + fn = JS_NewCFunction2(js, js_gpu_graphics_pipeline_constructor, "graphics_pipeline", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "graphics_pipeline", fn); + fn = JS_NewCFunction2(js, js_gpu_compute_pipeline_constructor, "compute_pipeline", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "compute_pipeline", fn); + fn = JS_NewCFunction2(js, js_gpu_buffer_constructor, "buffer", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "buffer", fn); + fn = JS_NewCFunction2(js, js_gpu_transfer_buffer_constructor, "transfer_buffer", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "transfer_buffer", fn); + fn = JS_NewCFunction2(js, js_gpu_texture_constructor, "texture", 2, JS_CFUNC_generic, 0); + JS_SetPropertyStr(js, ret, "texture", fn); JS_RETURN(ret); )