forked from cory/tildefriends
Always fetch the promise JSValue and ID when we allocate one. Make it impossible that we've freed it before we return it. Hopefully fixes leaks. Definitely not worse for performance.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3758 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -114,7 +114,8 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar
|
||||
void* task = JS_GetContextOpaque(context);
|
||||
const char* file_name = JS_ToCString(context, argv[0]);
|
||||
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t) + k_file_read_max);
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
@ -126,7 +127,7 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar
|
||||
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result)));
|
||||
}
|
||||
JS_FreeCString(context, file_name);
|
||||
return tf_task_get_promise(task, promise);
|
||||
return promise_value;
|
||||
}
|
||||
|
||||
static void _file_write_write_callback(uv_fs_t* req)
|
||||
@ -189,8 +190,8 @@ static JSValue _file_write_file(JSContext* context, JSValueConst this_val, int a
|
||||
buffer = (uint8_t*)JS_ToCStringLen(context, &size, argv[1]);
|
||||
}
|
||||
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
JSValue promise_value = tf_task_get_promise(task, promise);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t) + sizeof(size_t) + size);
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
@ -234,8 +235,8 @@ static JSValue _file_rename_file(JSContext* context, JSValueConst this_val, int
|
||||
void* task = JS_GetContextOpaque(context);
|
||||
const char* old_name = JS_ToCString(context, argv[0]);
|
||||
const char* new_name = JS_ToCString(context, argv[1]);
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
JSValue promise_value = tf_task_get_promise(task, promise);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
@ -255,8 +256,8 @@ static JSValue _file_unlink_file(JSContext* context, JSValueConst this_val, int
|
||||
{
|
||||
void* task = JS_GetContextOpaque(context);
|
||||
const char* file_name = JS_ToCString(context, argv[0]);
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
JSValue promise_value = tf_task_get_promise(task, promise);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
@ -276,8 +277,8 @@ JSValue _file_make_directory(JSContext* context, JSValueConst this_val, int argc
|
||||
void* task = JS_GetContextOpaque(context);
|
||||
const char* directory = JS_ToCString(context, argv[0]);
|
||||
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
JSValue promise_value = tf_task_get_promise(task, promise);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
@ -297,8 +298,8 @@ JSValue _file_remove_directory(JSContext* context, JSValueConst this_val, int ar
|
||||
void* task = JS_GetContextOpaque(context);
|
||||
const char* directory = JS_ToCString(context, argv[0]);
|
||||
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
JSValue promise_value = tf_task_get_promise(task, promise);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
@ -317,7 +318,8 @@ JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueC
|
||||
{
|
||||
void* task = JS_GetContextOpaque(context);
|
||||
const char* path = JS_ToCString(context, argv[0]);
|
||||
promiseid_t promise = tf_task_allocate_promise(task);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
|
||||
file_stat_t* data = malloc(sizeof(file_stat_t));
|
||||
data->_task = task;
|
||||
@ -332,7 +334,7 @@ JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueC
|
||||
free(data);
|
||||
}
|
||||
JS_FreeCString(context, path);
|
||||
return tf_task_get_promise(task, promise);
|
||||
return promise_value;
|
||||
}
|
||||
|
||||
static double _time_spec_to_double(const uv_timespec_t* time_spec)
|
||||
|
Reference in New Issue
Block a user