fix gc error
This commit is contained in:
18
hidapi.c
18
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);
|
||||
|
||||
Reference in New Issue
Block a user