diff --git a/audio.c b/audio.c index dd0d0fc..7841287 100644 --- a/audio.c +++ b/audio.c @@ -45,9 +45,12 @@ SDL_AudioSpec js2SDL_AudioSpec(JSContext *js, JSValue v) { JSValue SDL_AudioSpec2js(JSContext *js, SDL_AudioSpec spec) { JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - JS_SetPropertyStr(js, obj, "format", SDL_AudioFormat2js(js, spec.format)); - JS_SetPropertyStr(js, obj, "channels", JS_NewInt32(js, spec.channels)); - JS_SetPropertyStr(js, obj, "freq", JS_NewInt32(js, spec.freq)); + JSValue _fmt = SDL_AudioFormat2js(js, spec.format); + JS_SetPropertyStr(js, obj, "format", _fmt); + JSValue _ch = JS_NewInt32(js, spec.channels); + JS_SetPropertyStr(js, obj, "channels", _ch); + JSValue _freq = JS_NewInt32(js, spec.freq); + JS_SetPropertyStr(js, obj, "freq", _freq); JS_RETURN(obj); } @@ -58,7 +61,8 @@ JSValue js_get_audio_drivers(JSContext *js, JSValue self, int argc, JSValue *arg JS_LOCAL(arr, JS_NewArray(js)); for (int i = 0; i < count; i++) { const char *driver = SDL_GetAudioDriver(i); - JS_SetPropertyNumber(js, arr, i, JS_NewString(js, driver)); + JSValue _s = JS_NewString(js, driver); + JS_SetPropertyNumber(js, arr, i, _s); } JS_RETURN(arr); } @@ -74,7 +78,8 @@ JSValue js_get_audio_playback_devices(JSContext *js, JSValue self, int argc, JSV JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); for (int i = 0; devices[i]; i++) { - JS_SetPropertyNumber(js, arr, i, SDL_AudioDeviceID2js(js, devices[i])); + JSValue _id = SDL_AudioDeviceID2js(js, devices[i]); + JS_SetPropertyNumber(js, arr, i, _id); } SDL_free(devices); JS_RETURN(arr); @@ -86,7 +91,8 @@ JSValue js_get_audio_recording_devices(JSContext *js, JSValue self, int argc, JS JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); for (int i = 0; devices[i]; i++) { - JS_SetPropertyNumber(js, arr, i, SDL_AudioDeviceID2js(js, devices[i])); + JSValue _id = SDL_AudioDeviceID2js(js, devices[i]); + JS_SetPropertyNumber(js, arr, i, _id); } SDL_free(devices); JS_RETURN(arr); @@ -207,8 +213,10 @@ JSC_CCALL(audio_stream_get_format, } else { JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - JS_SetPropertyStr(js, obj, "src", SDL_AudioSpec2js(js, src)); - JS_SetPropertyStr(js, obj, "dst", SDL_AudioSpec2js(js, dst)); + JSValue _src = SDL_AudioSpec2js(js, src); + JS_SetPropertyStr(js, obj, "src", _src); + JSValue _dst = SDL_AudioSpec2js(js, dst); + JS_SetPropertyStr(js, obj, "dst", _dst); JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame); ret = obj; } @@ -326,8 +334,10 @@ JSValue js_load_wav(JSContext *js, JSValue self, int argc, JSValue *argv) { JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - JS_SetPropertyStr(js, obj, "spec", SDL_AudioSpec2js(js, spec)); - JS_SetPropertyStr(js, obj, "data", js_new_blob_stoned_copy(js, data, len)); + JSValue _spec = SDL_AudioSpec2js(js, spec); + JS_SetPropertyStr(js, obj, "spec", _spec); + JSValue _data = js_new_blob_stoned_copy(js, data, len); + JS_SetPropertyStr(js, obj, "data", _data); SDL_free(data); JS_RETURN(obj); } diff --git a/events.c b/events.c index 96d1c51..dc96342 100644 --- a/events.c +++ b/events.c @@ -153,8 +153,10 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - JS_SetPropertyStr(js, obj, "type", JS_NewString(js, event_type_to_string(event->type))); - JS_SetPropertyStr(js, obj, "timestamp", JS_NewInt64(js, event->common.timestamp)); + JSValue _type = JS_NewString(js, event_type_to_string(event->type)); + JS_SetPropertyStr(js, obj, "type", _type); + JSValue _ts = JS_NewInt64(js, event->common.timestamp); + JS_SetPropertyStr(js, obj, "timestamp", _ts); switch (event->type) { // Window events @@ -200,13 +202,15 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { // Text input case SDL_EVENT_TEXT_INPUT: JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->text.windowID)); - JS_SetPropertyStr(js, obj, "text", JS_NewString(js, event->text.text)); + { JSValue _v = JS_NewString(js, event->text.text); + JS_SetPropertyStr(js, obj, "text", _v); } break; // Text editing case SDL_EVENT_TEXT_EDITING: JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->edit.windowID)); - JS_SetPropertyStr(js, obj, "text", JS_NewString(js, event->edit.text)); + { JSValue _v = JS_NewString(js, event->edit.text); + JS_SetPropertyStr(js, obj, "text", _v); } JS_SetPropertyStr(js, obj, "start", JS_NewInt32(js, event->edit.start)); JS_SetPropertyStr(js, obj, "length", JS_NewInt32(js, event->edit.length)); break; @@ -216,10 +220,14 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->motion.windowID)); JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->motion.which)); JS_SetPropertyStr(js, obj, "state", JS_NewUint32(js, event->motion.state)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->motion.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->motion.y)); - JS_SetPropertyStr(js, obj, "xrel", JS_NewFloat64(js, event->motion.xrel)); - JS_SetPropertyStr(js, obj, "yrel", JS_NewFloat64(js, event->motion.yrel)); + { JSValue _v = JS_NewFloat64(js, event->motion.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->motion.y); + JS_SetPropertyStr(js, obj, "y", _v); } + { JSValue _v = JS_NewFloat64(js, event->motion.xrel); + JS_SetPropertyStr(js, obj, "xrel", _v); } + { JSValue _v = JS_NewFloat64(js, event->motion.yrel); + JS_SetPropertyStr(js, obj, "yrel", _v); } break; // Mouse button @@ -227,24 +235,32 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { case SDL_EVENT_MOUSE_BUTTON_UP: JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->button.windowID)); JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->button.which)); - JS_SetPropertyStr(js, obj, "button", JS_NewString(js, mouse_button_to_string(event->button.button))); + { JSValue _v = JS_NewString(js, mouse_button_to_string(event->button.button)); + JS_SetPropertyStr(js, obj, "button", _v); } JS_SetPropertyStr(js, obj, "button_num", JS_NewUint32(js, event->button.button)); JS_SetPropertyStr(js, obj, "down", JS_NewBool(js, event->button.down)); JS_SetPropertyStr(js, obj, "clicks", JS_NewUint32(js, event->button.clicks)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->button.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->button.y)); + { JSValue _v = JS_NewFloat64(js, event->button.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->button.y); + JS_SetPropertyStr(js, obj, "y", _v); } break; // Mouse wheel case SDL_EVENT_MOUSE_WHEEL: JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->wheel.windowID)); JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->wheel.which)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->wheel.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->wheel.y)); - JS_SetPropertyStr(js, obj, "direction", JS_NewString(js, - event->wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? "flipped" : "normal")); - JS_SetPropertyStr(js, obj, "mouse_x", JS_NewFloat64(js, event->wheel.mouse_x)); - JS_SetPropertyStr(js, obj, "mouse_y", JS_NewFloat64(js, event->wheel.mouse_y)); + { JSValue _v = JS_NewFloat64(js, event->wheel.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->wheel.y); + JS_SetPropertyStr(js, obj, "y", _v); } + { JSValue _v = JS_NewString(js, + event->wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? "flipped" : "normal"); + JS_SetPropertyStr(js, obj, "direction", _v); } + { JSValue _v = JS_NewFloat64(js, event->wheel.mouse_x); + JS_SetPropertyStr(js, obj, "mouse_x", _v); } + { JSValue _v = JS_NewFloat64(js, event->wheel.mouse_y); + JS_SetPropertyStr(js, obj, "mouse_y", _v); } break; // Joystick axis @@ -312,9 +328,12 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->gtouchpad.which)); JS_SetPropertyStr(js, obj, "touchpad", JS_NewInt32(js, event->gtouchpad.touchpad)); JS_SetPropertyStr(js, obj, "finger", JS_NewInt32(js, event->gtouchpad.finger)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->gtouchpad.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->gtouchpad.y)); - JS_SetPropertyStr(js, obj, "pressure", JS_NewFloat64(js, event->gtouchpad.pressure)); + { JSValue _v = JS_NewFloat64(js, event->gtouchpad.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->gtouchpad.y); + JS_SetPropertyStr(js, obj, "y", _v); } + { JSValue _v = JS_NewFloat64(js, event->gtouchpad.pressure); + JS_SetPropertyStr(js, obj, "pressure", _v); } break; // Gamepad sensor @@ -326,24 +345,33 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JSLocalRef data__lr = {.ptr = &data}; JS_PushLocalRef(_js_ctx, &data__lr); for (int i = 0; i < 3; i++) { - JS_SetPropertyNumber(js, data, i, JS_NewFloat64(js, event->gsensor.data[i])); + JSValue _v = JS_NewFloat64(js, event->gsensor.data[i]); + JS_SetPropertyNumber(js, data, i, _v); } JS_SetPropertyStr(js, obj, "data", data); } - JS_SetPropertyStr(js, obj, "sensor_timestamp", JS_NewInt64(js, event->gsensor.sensor_timestamp)); + { JSValue _v = JS_NewInt64(js, event->gsensor.sensor_timestamp); + JS_SetPropertyStr(js, obj, "sensor_timestamp", _v); } break; // Touch finger case SDL_EVENT_FINGER_DOWN: case SDL_EVENT_FINGER_UP: case SDL_EVENT_FINGER_MOTION: - JS_SetPropertyStr(js, obj, "touch_id", JS_NewInt64(js, event->tfinger.touchID)); - JS_SetPropertyStr(js, obj, "finger_id", JS_NewInt64(js, event->tfinger.fingerID)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->tfinger.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->tfinger.y)); - JS_SetPropertyStr(js, obj, "dx", JS_NewFloat64(js, event->tfinger.dx)); - JS_SetPropertyStr(js, obj, "dy", JS_NewFloat64(js, event->tfinger.dy)); - JS_SetPropertyStr(js, obj, "pressure", JS_NewFloat64(js, event->tfinger.pressure)); + { JSValue _v = JS_NewInt64(js, event->tfinger.touchID); + JS_SetPropertyStr(js, obj, "touch_id", _v); } + { JSValue _v = JS_NewInt64(js, event->tfinger.fingerID); + JS_SetPropertyStr(js, obj, "finger_id", _v); } + { JSValue _v = JS_NewFloat64(js, event->tfinger.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->tfinger.y); + JS_SetPropertyStr(js, obj, "y", _v); } + { JSValue _v = JS_NewFloat64(js, event->tfinger.dx); + JS_SetPropertyStr(js, obj, "dx", _v); } + { JSValue _v = JS_NewFloat64(js, event->tfinger.dy); + JS_SetPropertyStr(js, obj, "dy", _v); } + { JSValue _v = JS_NewFloat64(js, event->tfinger.pressure); + JS_SetPropertyStr(js, obj, "pressure", _v); } JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->tfinger.windowID)); break; @@ -351,18 +379,24 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { case SDL_EVENT_DROP_FILE: case SDL_EVENT_DROP_TEXT: JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->drop.windowID)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->drop.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->drop.y)); - if (event->drop.data) - JS_SetPropertyStr(js, obj, "data", JS_NewString(js, event->drop.data)); + { JSValue _v = JS_NewFloat64(js, event->drop.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->drop.y); + JS_SetPropertyStr(js, obj, "y", _v); } + if (event->drop.data) { + JSValue _v = JS_NewString(js, event->drop.data); + JS_SetPropertyStr(js, obj, "data", _v); + } break; case SDL_EVENT_DROP_BEGIN: case SDL_EVENT_DROP_COMPLETE: case SDL_EVENT_DROP_POSITION: JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->drop.windowID)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->drop.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->drop.y)); + { JSValue _v = JS_NewFloat64(js, event->drop.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->drop.y); + JS_SetPropertyStr(js, obj, "y", _v); } break; // Audio device @@ -381,11 +415,13 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JSLocalRef data__lr = {.ptr = &data}; JS_PushLocalRef(_js_ctx, &data__lr); for (int i = 0; i < 6; i++) { - JS_SetPropertyNumber(js, data, i, JS_NewFloat64(js, event->sensor.data[i])); + JSValue _v = JS_NewFloat64(js, event->sensor.data[i]); + JS_SetPropertyNumber(js, data, i, _v); } JS_SetPropertyStr(js, obj, "data", data); } - JS_SetPropertyStr(js, obj, "sensor_timestamp", JS_NewInt64(js, event->sensor.sensor_timestamp)); + { JSValue _v = JS_NewInt64(js, event->sensor.sensor_timestamp); + JS_SetPropertyStr(js, obj, "sensor_timestamp", _v); } break; // Pen events @@ -397,8 +433,10 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->pmotion.windowID)); JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->pmotion.which)); JS_SetPropertyStr(js, obj, "pen_state", JS_NewUint32(js, event->pmotion.pen_state)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->pmotion.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->pmotion.y)); + { JSValue _v = JS_NewFloat64(js, event->pmotion.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->pmotion.y); + JS_SetPropertyStr(js, obj, "y", _v); } break; case SDL_EVENT_PEN_BUTTON_DOWN: @@ -406,8 +444,10 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->pbutton.windowID)); JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->pbutton.which)); JS_SetPropertyStr(js, obj, "pen_state", JS_NewUint32(js, event->pbutton.pen_state)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->pbutton.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->pbutton.y)); + { JSValue _v = JS_NewFloat64(js, event->pbutton.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->pbutton.y); + JS_SetPropertyStr(js, obj, "y", _v); } JS_SetPropertyStr(js, obj, "button", JS_NewUint32(js, event->pbutton.button)); JS_SetPropertyStr(js, obj, "down", JS_NewBool(js, event->pbutton.down)); break; @@ -416,10 +456,13 @@ static JSValue event_to_js(JSContext *js, SDL_Event *event) { JS_SetPropertyStr(js, obj, "window_id", JS_NewUint32(js, event->paxis.windowID)); JS_SetPropertyStr(js, obj, "which", JS_NewUint32(js, event->paxis.which)); JS_SetPropertyStr(js, obj, "pen_state", JS_NewUint32(js, event->paxis.pen_state)); - JS_SetPropertyStr(js, obj, "x", JS_NewFloat64(js, event->paxis.x)); - JS_SetPropertyStr(js, obj, "y", JS_NewFloat64(js, event->paxis.y)); + { JSValue _v = JS_NewFloat64(js, event->paxis.x); + JS_SetPropertyStr(js, obj, "x", _v); } + { JSValue _v = JS_NewFloat64(js, event->paxis.y); + JS_SetPropertyStr(js, obj, "y", _v); } JS_SetPropertyStr(js, obj, "axis", JS_NewUint32(js, event->paxis.axis)); - JS_SetPropertyStr(js, obj, "value", JS_NewFloat64(js, event->paxis.value)); + { JSValue _v = JS_NewFloat64(js, event->paxis.value); + JS_SetPropertyStr(js, obj, "value", _v); } break; // Camera device diff --git a/gamepad.c b/gamepad.c index 1f7985a..afe7ae6 100644 --- a/gamepad.c +++ b/gamepad.c @@ -345,9 +345,12 @@ JSC_CCALL(gamepad_get_touchpad_finger, JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); JS_SetPropertyStr(js, result, "down", JS_NewBool(js, down)); - JS_SetPropertyStr(js, result, "x", JS_NewFloat64(js, x)); - JS_SetPropertyStr(js, result, "y", JS_NewFloat64(js, y)); - JS_SetPropertyStr(js, result, "pressure", JS_NewFloat64(js, pressure)); + JSValue _x = JS_NewFloat64(js, x); + JS_SetPropertyStr(js, result, "x", _x); + JSValue _y = JS_NewFloat64(js, y); + JS_SetPropertyStr(js, result, "y", _y); + JSValue _p = JS_NewFloat64(js, pressure); + JS_SetPropertyStr(js, result, "pressure", _p); JS_RETURN(result); ) @@ -391,7 +394,8 @@ JSC_CCALL(gamepad_get_sensor_data, JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); for (int i = 0; i < num_values; i++) { - JS_SetPropertyNumber(js, arr, i, JS_NewFloat64(js, data[i])); + JSValue _v = JS_NewFloat64(js, data[i]); + JS_SetPropertyNumber(js, arr, i, _v); } free(data); JS_RETURN(arr); @@ -440,7 +444,8 @@ JSC_CCALL(gamepad_get_power_info, JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "state", JS_NewString(js, state_str)); + JSValue _state = JS_NewString(js, state_str); + JS_SetPropertyStr(js, result, "state", _state); JS_SetPropertyStr(js, result, "percent", JS_NewInt32(js, percent)); JS_RETURN(result); ) diff --git a/hidapi.c b/hidapi.c index 33a58ae..7610774 100644 --- a/hidapi.c +++ b/hidapi.c @@ -24,8 +24,10 @@ static JSValue device_info_to_js(JSContext *js, SDL_hid_device_info *info) { JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - if (info->path) - JS_SetPropertyStr(js, obj, "path", JS_NewString(js, info->path)); + if (info->path) { + JSValue _v = JS_NewString(js, info->path); + JS_SetPropertyStr(js, obj, "path", _v); + } JS_SetPropertyStr(js, obj, "vendor_id", JS_NewUint32(js, info->vendor_id)); JS_SetPropertyStr(js, obj, "product_id", JS_NewUint32(js, info->product_id)); JS_SetPropertyStr(js, obj, "release_number", JS_NewUint32(js, info->release_number)); @@ -35,25 +37,29 @@ static JSValue device_info_to_js(JSContext *js, SDL_hid_device_info *info) { JS_SetPropertyStr(js, obj, "interface_class", JS_NewInt32(js, info->interface_class)); JS_SetPropertyStr(js, obj, "interface_subclass", JS_NewInt32(js, info->interface_subclass)); JS_SetPropertyStr(js, obj, "interface_protocol", JS_NewInt32(js, info->interface_protocol)); - JS_SetPropertyStr(js, obj, "bus_type", JS_NewString(js, bus_type_to_string(info->bus_type))); + JSValue _bus = JS_NewString(js, bus_type_to_string(info->bus_type)); + JS_SetPropertyStr(js, obj, "bus_type", _bus); if (info->serial_number) { char buf[256]; wcstombs(buf, info->serial_number, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; - JS_SetPropertyStr(js, obj, "serial_number", JS_NewString(js, buf)); + JSValue _v = JS_NewString(js, buf); + JS_SetPropertyStr(js, obj, "serial_number", _v); } if (info->manufacturer_string) { char buf[256]; wcstombs(buf, info->manufacturer_string, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; - JS_SetPropertyStr(js, obj, "manufacturer", JS_NewString(js, buf)); + JSValue _v = JS_NewString(js, buf); + JS_SetPropertyStr(js, obj, "manufacturer", _v); } if (info->product_string) { char buf[256]; wcstombs(buf, info->product_string, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; - JS_SetPropertyStr(js, obj, "product", JS_NewString(js, buf)); + JSValue _v = JS_NewString(js, buf); + JS_SetPropertyStr(js, obj, "product", _v); } JS_RETURN(obj); diff --git a/joystick.c b/joystick.c index b748225..5c013be 100644 --- a/joystick.c +++ b/joystick.c @@ -325,7 +325,8 @@ JSC_CCALL(joystick_get_power_info, JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "state", JS_NewString(js, state_str)); + JSValue _state = JS_NewString(js, state_str); + JS_SetPropertyStr(js, result, "state", _state); JS_SetPropertyStr(js, result, "percent", JS_NewInt32(js, percent)); JS_RETURN(result); ) diff --git a/mouse.c b/mouse.c index e9e4f98..5473190 100644 --- a/mouse.c +++ b/mouse.c @@ -36,8 +36,10 @@ JSC_CCALL(mouse_get_state, JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "x", JS_NewFloat64(js, x)); - JS_SetPropertyStr(js, result, "y", JS_NewFloat64(js, y)); + JSValue _x = JS_NewFloat64(js, x); + JS_SetPropertyStr(js, result, "x", _x); + JSValue _y = JS_NewFloat64(js, y); + JS_SetPropertyStr(js, result, "y", _y); JS_SetPropertyStr(js, result, "buttons", JS_NewUint32(js, buttons)); JS_RETURN(result); ) @@ -49,8 +51,10 @@ JSC_CCALL(mouse_get_global_state, JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "x", JS_NewFloat64(js, x)); - JS_SetPropertyStr(js, result, "y", JS_NewFloat64(js, y)); + JSValue _x = JS_NewFloat64(js, x); + JS_SetPropertyStr(js, result, "x", _x); + JSValue _y = JS_NewFloat64(js, y); + JS_SetPropertyStr(js, result, "y", _y); JS_SetPropertyStr(js, result, "buttons", JS_NewUint32(js, buttons)); JS_RETURN(result); ) @@ -62,8 +66,10 @@ JSC_CCALL(mouse_get_relative_state, JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "x", JS_NewFloat64(js, x)); - JS_SetPropertyStr(js, result, "y", JS_NewFloat64(js, y)); + JSValue _x = JS_NewFloat64(js, x); + JS_SetPropertyStr(js, result, "x", _x); + JSValue _y = JS_NewFloat64(js, y); + JS_SetPropertyStr(js, result, "y", _y); JS_SetPropertyStr(js, result, "buttons", JS_NewUint32(js, buttons)); JS_RETURN(result); ) diff --git a/sensor.c b/sensor.c index 2f3e1a5..fb2fede 100644 --- a/sensor.c +++ b/sensor.c @@ -108,7 +108,8 @@ JSC_CCALL(sensor_get_data, JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); for (int i = 0; i < num_values; i++) { - JS_SetPropertyNumber(js, arr, i, JS_NewFloat64(js, data[i])); + JSValue _v = JS_NewFloat64(js, data[i]); + JS_SetPropertyNumber(js, arr, i, _v); } free(data); JS_RETURN(arr); @@ -151,7 +152,8 @@ CELL_USE_INIT( JS_FRAME(js); JS_LOCAL(ret, JS_NewObject(js)); JS_SetPropertyFunctionList(js, ret, js_sensor_funcs, countof(js_sensor_funcs)); - JS_SetPropertyStr(js, ret, "STANDARD_GRAVITY", JS_NewFloat64(js, SDL_STANDARD_GRAVITY)); + JSValue _gravity = JS_NewFloat64(js, SDL_STANDARD_GRAVITY); + JS_SetPropertyStr(js, ret, "STANDARD_GRAVITY", _gravity); JS_RETURN(ret); ) diff --git a/surface.c b/surface.c index b33bb66..740f361 100644 --- a/surface.c +++ b/surface.c @@ -92,10 +92,14 @@ QJSCLASS(SDL_Surface,) JSValue make_surface(JSContext *js, SDL_Surface *s){ JS_FRAME(js); JS_LOCAL(ret, SDL_Surface2js(js,s)); - JS_SetPropertyStr(js, ret, "width", JS_NewInt32(js, s->w)); - JS_SetPropertyStr(js, ret, "height", JS_NewInt32(js, s->h)); - JS_SetPropertyStr(js, ret, "format", pixelformat2js(js, s->format)); - JS_SetPropertyStr(js, ret, "pitch", JS_NewFloat64(js, s->pitch)); + JSValue _w = JS_NewInt32(js, s->w); + JS_SetPropertyStr(js, ret, "width", _w); + JSValue _h = JS_NewInt32(js, s->h); + JS_SetPropertyStr(js, ret, "height", _h); + JSValue _fmt = pixelformat2js(js, s->format); + JS_SetPropertyStr(js, ret, "format", _fmt); + JSValue _pitch = JS_NewFloat64(js, s->pitch); + JS_SetPropertyStr(js, ret, "pitch", _pitch); JS_RETURN(JS_Stone(js, ret)); } @@ -232,10 +236,14 @@ JSC_CCALL(surface_toJSON, JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, surf->w)); - JS_SetPropertyStr(js, obj, "height", JS_NewInt32(js, surf->h)); - JS_SetPropertyStr(js, obj, "format", pixelformat2js(js, surf->format)); - JS_SetPropertyStr(js, obj, "pitch", JS_NewInt32(js, surf->pitch)); + JSValue _w = JS_NewInt32(js, surf->w); + JS_SetPropertyStr(js, obj, "width", _w); + JSValue _h = JS_NewInt32(js, surf->h); + JS_SetPropertyStr(js, obj, "height", _h); + JSValue _fmt = pixelformat2js(js, surf->format); + JS_SetPropertyStr(js, obj, "format", _fmt); + JSValue _pitch = JS_NewInt32(js, surf->pitch); + JS_SetPropertyStr(js, obj, "pitch", _pitch); int locked = 0; if (SDL_MUSTLOCK(surf)) { @@ -246,7 +254,8 @@ JSC_CCALL(surface_toJSON, } size_t byte_size = surf->pitch * surf->h; - JS_SetPropertyStr(js, obj, "pixels", js_new_blob_stoned_copy(js, surf->pixels, byte_size)); + JSValue _pixels = js_new_blob_stoned_copy(js, surf->pixels, byte_size); + JS_SetPropertyStr(js, obj, "pixels", _pixels); if (locked) SDL_UnlockSurface(surf); @@ -413,12 +422,17 @@ static JSValue compress_bc_common(JSContext *js, JSValueConst *argv, int argc, i // Create result object JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "width", JS_NewInt32(js, width)); - JS_SetPropertyStr(js, result, "height", JS_NewInt32(js, height)); - JS_SetPropertyStr(js, result, "format", JS_NewString(js, format_name)); - JS_SetPropertyStr(js, result, "pitch", JS_NewInt32(js, blocks_x * bytes_per_block)); + JSValue _w = JS_NewInt32(js, width); + JS_SetPropertyStr(js, result, "width", _w); + JSValue _h = JS_NewInt32(js, height); + JS_SetPropertyStr(js, result, "height", _h); + JSValue _fmt = JS_NewString(js, format_name); + JS_SetPropertyStr(js, result, "format", _fmt); + JSValue _pitch = JS_NewInt32(js, blocks_x * bytes_per_block); + JS_SetPropertyStr(js, result, "pitch", _pitch); - JS_SetPropertyStr(js, result, "pixels", js_new_blob_stoned_copy(js, output, output_size)); + JSValue _pixels = js_new_blob_stoned_copy(js, output, output_size); + JS_SetPropertyStr(js, result, "pixels", _pixels); free(output); JS_RETURN(result); @@ -582,12 +596,17 @@ static JSValue compress_bc_channels(JSContext *js, JSValueConst *argv, int argc, // Create result object JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "width", JS_NewInt32(js, width)); - JS_SetPropertyStr(js, result, "height", JS_NewInt32(js, height)); - JS_SetPropertyStr(js, result, "format", JS_NewString(js, format_name)); - JS_SetPropertyStr(js, result, "pitch", JS_NewInt32(js, blocks_x * bytes_per_block)); + JSValue _w = JS_NewInt32(js, width); + JS_SetPropertyStr(js, result, "width", _w); + JSValue _h = JS_NewInt32(js, height); + JS_SetPropertyStr(js, result, "height", _h); + JSValue _fmt = JS_NewString(js, format_name); + JS_SetPropertyStr(js, result, "format", _fmt); + JSValue _pitch = JS_NewInt32(js, blocks_x * bytes_per_block); + JS_SetPropertyStr(js, result, "pitch", _pitch); - JS_SetPropertyStr(js, result, "pixels", js_new_blob_stoned_copy(js, output, output_size)); + JSValue _pixels = js_new_blob_stoned_copy(js, output, output_size); + JS_SetPropertyStr(js, result, "pixels", _pixels); free(output); JS_RETURN(result); @@ -769,10 +788,14 @@ static JSValue surface_to_image(JSContext *js, SDL_Surface *surf) JS_FRAME(js); JS_LOCAL(obj, JS_NewObject(js)); - JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, surf->w)); - JS_SetPropertyStr(js, obj, "height", JS_NewInt32(js, surf->h)); - JS_SetPropertyStr(js, obj, "format", pixelformat2js(js, surf->format)); - JS_SetPropertyStr(js, obj, "pitch", JS_NewInt32(js, surf->pitch)); + JSValue _w = JS_NewInt32(js, surf->w); + JS_SetPropertyStr(js, obj, "width", _w); + JSValue _h = JS_NewInt32(js, surf->h); + JS_SetPropertyStr(js, obj, "height", _h); + JSValue _fmt = pixelformat2js(js, surf->format); + JS_SetPropertyStr(js, obj, "format", _fmt); + JSValue _pitch = JS_NewInt32(js, surf->pitch); + JS_SetPropertyStr(js, obj, "pitch", _pitch); int locked = 0; if (SDL_MUSTLOCK(surf)) { @@ -783,12 +806,14 @@ static JSValue surface_to_image(JSContext *js, SDL_Surface *surf) } size_t byte_size = surf->pitch * surf->h; - JS_SetPropertyStr(js, obj, "pixels", js_new_blob_stoned_copy(js, surf->pixels, byte_size)); + JSValue _pixels = js_new_blob_stoned_copy(js, surf->pixels, byte_size); + JS_SetPropertyStr(js, obj, "pixels", _pixels); if (locked) SDL_UnlockSurface(surf); - JS_SetPropertyStr(js, obj, "depth", JS_NewInt32(js, SDL_BITSPERPIXEL(surf->format))); + JSValue _depth = JS_NewInt32(js, SDL_BITSPERPIXEL(surf->format)); + JS_SetPropertyStr(js, obj, "depth", _depth); JS_SetPropertyStr(js, obj, "hdr", JS_FALSE); JS_RETURN(obj); @@ -1056,15 +1081,21 @@ JSC_CCALL(surface_convert_generic, // Create result image object JS_FRAME(js); JS_LOCAL(result, JS_NewObject(js)); - JS_SetPropertyStr(js, result, "width", JS_NewInt32(js, src_width)); - JS_SetPropertyStr(js, result, "height", JS_NewInt32(js, src_height)); - JS_SetPropertyStr(js, result, "format", pixelformat2js(js, dst_format)); - JS_SetPropertyStr(js, result, "pitch", JS_NewInt32(js, dst_pitch)); + JSValue _w = JS_NewInt32(js, src_width); + JS_SetPropertyStr(js, result, "width", _w); + JSValue _h = JS_NewInt32(js, src_height); + JS_SetPropertyStr(js, result, "height", _h); + JSValue _fmt = pixelformat2js(js, dst_format); + JS_SetPropertyStr(js, result, "format", _fmt); + JSValue _pitch = JS_NewInt32(js, dst_pitch); + JS_SetPropertyStr(js, result, "pitch", _pitch); - JS_SetPropertyStr(js, result, "pixels", js_new_blob_stoned_copy(js, dst_pixels, dst_size)); + JSValue _pixels = js_new_blob_stoned_copy(js, dst_pixels, dst_size); + JS_SetPropertyStr(js, result, "pixels", _pixels); free(dst_pixels); - JS_SetPropertyStr(js, result, "depth", JS_NewInt32(js, SDL_BITSPERPIXEL(dst_format))); + JSValue _depth = JS_NewInt32(js, SDL_BITSPERPIXEL(dst_format)); + JS_SetPropertyStr(js, result, "depth", _depth); JS_SetPropertyStr(js, result, "hdr", JS_FALSE); JS_RETURN(result); @@ -1076,16 +1107,26 @@ CELL_USE_INIT( JS_FRAME(js); JS_LOCAL(ctor, JS_NewCFunction2(js, js_surface_constructor, "surface", 1, JS_CFUNC_generic, 0)); - JS_SetPropertyStr(js, ctor, "convert", JS_NewCFunction(js, js_surface_convert_generic, "convert", 2)); - JS_SetPropertyStr(js, ctor, "compress_bc1", JS_NewCFunction(js, js_surface_compress_bc1, "compress_bc1", 2)); - JS_SetPropertyStr(js, ctor, "compress_bc3", JS_NewCFunction(js, js_surface_compress_bc3, "compress_bc3", 2)); - JS_SetPropertyStr(js, ctor, "compress_bc4", JS_NewCFunction(js, js_surface_compress_bc4, "compress_bc4", 1)); - JS_SetPropertyStr(js, ctor, "compress_bc5", JS_NewCFunction(js, js_surface_compress_bc5, "compress_bc5", 1)); - JS_SetPropertyStr(js, ctor, "scale", JS_NewCFunction(js, js_surface_scale_img, "scale", 2)); - JS_SetPropertyStr(js, ctor, "fill", JS_NewCFunction(js, js_surface_fill_img, "fill", 2)); - JS_SetPropertyStr(js, ctor, "rect", JS_NewCFunction(js, js_surface_rect_img, "rect", 3)); - JS_SetPropertyStr(js, ctor, "blit", JS_NewCFunction(js, js_surface_blit_img, "blit", 5)); - JS_SetPropertyStr(js, ctor, "dup", JS_NewCFunction(js, js_surface_dup_img, "dup", 1)); + JSValue _convert = JS_NewCFunction(js, js_surface_convert_generic, "convert", 2); + JS_SetPropertyStr(js, ctor, "convert", _convert); + JSValue _bc1 = JS_NewCFunction(js, js_surface_compress_bc1, "compress_bc1", 2); + JS_SetPropertyStr(js, ctor, "compress_bc1", _bc1); + JSValue _bc3 = JS_NewCFunction(js, js_surface_compress_bc3, "compress_bc3", 2); + JS_SetPropertyStr(js, ctor, "compress_bc3", _bc3); + JSValue _bc4 = JS_NewCFunction(js, js_surface_compress_bc4, "compress_bc4", 1); + JS_SetPropertyStr(js, ctor, "compress_bc4", _bc4); + JSValue _bc5 = JS_NewCFunction(js, js_surface_compress_bc5, "compress_bc5", 1); + JS_SetPropertyStr(js, ctor, "compress_bc5", _bc5); + JSValue _scale = JS_NewCFunction(js, js_surface_scale_img, "scale", 2); + JS_SetPropertyStr(js, ctor, "scale", _scale); + JSValue _fill = JS_NewCFunction(js, js_surface_fill_img, "fill", 2); + JS_SetPropertyStr(js, ctor, "fill", _fill); + JSValue _rect = JS_NewCFunction(js, js_surface_rect_img, "rect", 3); + JS_SetPropertyStr(js, ctor, "rect", _rect); + JSValue _blit = JS_NewCFunction(js, js_surface_blit_img, "blit", 5); + JS_SetPropertyStr(js, ctor, "blit", _blit); + JSValue _dup = JS_NewCFunction(js, js_surface_dup_img, "dup", 1); + JS_SetPropertyStr(js, ctor, "dup", _dup); JS_RETURN(ctor); ) \ No newline at end of file diff --git a/touch.c b/touch.c index 6e5f5a4..015e9bb 100644 --- a/touch.c +++ b/touch.c @@ -10,7 +10,8 @@ JSC_CCALL(touch_get_devices, JS_FRAME(js); JS_LOCAL(arr, JS_NewArray(js)); for (int i = 0; i < count; i++) { - JS_SetPropertyNumber(js, arr, i, JS_NewInt64(js, devices[i])); + JSValue _v = JS_NewInt64(js, devices[i]); + JS_SetPropertyNumber(js, arr, i, _v); } SDL_free(devices); JS_RETURN(arr); @@ -58,10 +59,14 @@ JSC_CCALL(touch_get_fingers, for (int i = 0; i < count; i++) { SDL_Finger *f = fingers[i]; finger = JS_NewObject(js); - JS_SetPropertyStr(js, finger, "id", JS_NewInt64(js, f->id)); - JS_SetPropertyStr(js, finger, "x", JS_NewFloat64(js, f->x)); - JS_SetPropertyStr(js, finger, "y", JS_NewFloat64(js, f->y)); - JS_SetPropertyStr(js, finger, "pressure", JS_NewFloat64(js, f->pressure)); + JSValue _id = JS_NewInt64(js, f->id); + JS_SetPropertyStr(js, finger, "id", _id); + JSValue _x = JS_NewFloat64(js, f->x); + JS_SetPropertyStr(js, finger, "x", _x); + JSValue _y = JS_NewFloat64(js, f->y); + JS_SetPropertyStr(js, finger, "y", _y); + JSValue _p = JS_NewFloat64(js, f->pressure); + JS_SetPropertyStr(js, finger, "pressure", _p); JS_SetPropertyNumber(js, arr, i, finger); } SDL_free(fingers); diff --git a/video.c b/video.c index 4cca900..b21be69 100644 --- a/video.c +++ b/video.c @@ -749,7 +749,8 @@ JSValue js_window_state(JSContext *js, JSValue self, int argc, JSValue *argv) // Title const char *title = SDL_GetWindowTitle(w); - JS_SetPropertyStr(js, ret, "title", JS_NewString(js, title ? title : "")); + JSValue _title = JS_NewString(js, title ? title : ""); + JS_SetPropertyStr(js, ret, "title", _title); // Size int width, height; @@ -785,7 +786,8 @@ JSValue js_window_state(JSContext *js, JSValue self, int argc, JSValue *argv) // Opacity float opacity = SDL_GetWindowOpacity(w); - JS_SetPropertyStr(js, ret, "opacity", JS_NewFloat64(js, opacity)); + JSValue _opacity = JS_NewFloat64(js, opacity); + JS_SetPropertyStr(js, ret, "opacity", _opacity); // Grabs JS_SetPropertyStr(js, ret, "mouseGrab", JS_NewBool(js, SDL_GetWindowMouseGrab(w))); @@ -804,8 +806,10 @@ JSValue js_window_state(JSContext *js, JSValue self, int argc, JSValue *argv) JS_SetPropertyStr(js, ret, "maximized", JS_NewBool(js, flags & SDL_WINDOW_MAXIMIZED)); // Display properties - JS_SetPropertyStr(js, ret, "displayScale", JS_NewFloat64(js, SDL_GetWindowDisplayScale(w))); - JS_SetPropertyStr(js, ret, "pixelDensity", JS_NewFloat64(js, SDL_GetWindowPixelDensity(w))); + JSValue _displayScale = JS_NewFloat64(js, SDL_GetWindowDisplayScale(w)); + JS_SetPropertyStr(js, ret, "displayScale", _displayScale); + JSValue _pixelDensity = JS_NewFloat64(js, SDL_GetWindowPixelDensity(w)); + JS_SetPropertyStr(js, ret, "pixelDensity", _pixelDensity); // Size in pixels int pixelW, pixelH; @@ -816,15 +820,17 @@ JSValue js_window_state(JSContext *js, JSValue self, int argc, JSValue *argv) JS_SetPropertyStr(js, ret, "sizeInPixels", pixelSizeObj); // Flags - JS_SetPropertyStr(js, ret, "flags", JS_NewInt64(js, flags)); + JSValue _flags = JS_NewInt64(js, flags); + JS_SetPropertyStr(js, ret, "flags", _flags); JS_SetPropertyStr(js, ret, "id", JS_NewUint32(js, SDL_GetWindowID(w))); // Parent SDL_Window *parent = SDL_GetWindowParent(w); - if (parent) - JS_SetPropertyStr(js, ret, "parent", SDL_Window2js(js, parent)); - else + if (parent) { + JSValue _parent = SDL_Window2js(js, parent); + JS_SetPropertyStr(js, ret, "parent", _parent); + } else JS_SetPropertyStr(js, ret, "parent", JS_NULL); JS_RETURN(ret); @@ -880,13 +886,16 @@ CELL_USE_INIT( JS_FRAME(js); JS_LOCAL(ret, JS_NewObject(js)); - JS_SetPropertyStr(js, ret, "window", QJSCLASSPREP_FUNCS_CTOR(SDL_Window, 1)); + JSValue _window = QJSCLASSPREP_FUNCS_CTOR(SDL_Window, 1); + JS_SetPropertyStr(js, ret, "window", _window); QJSCLASSPREP_NO_FUNCS(SDL_Cursor); // Add cursor functions - JS_SetPropertyStr(js, ret, "createCursor", JS_NewCFunction(js, js_sdl_create_cursor, "createCursor", 2)); - JS_SetPropertyStr(js, ret, "setCursor", JS_NewCFunction(js, js_sdl_set_cursor, "setCursor", 1)); + JSValue _createCursor = JS_NewCFunction(js, js_sdl_create_cursor, "createCursor", 2); + JS_SetPropertyStr(js, ret, "createCursor", _createCursor); + JSValue _setCursor = JS_NewCFunction(js, js_sdl_set_cursor, "setCursor", 1); + JS_SetPropertyStr(js, ret, "setCursor", _setCursor); JS_RETURN(ret); )