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:
2022-01-14 03:05:37 +00:00
parent 27c2f27708
commit 0bcc7d8c59
5 changed files with 43 additions and 44 deletions

View File

@ -406,9 +406,9 @@ static JSValue _import_call(JSContext* context, JSValueConst func_obj, JSValueCo
tf_taskstub_t* recipient = _tf_task_get_stub(sender, import->_task);
if (recipient)
{
promiseid_t promise = tf_task_allocate_promise(sender);
promiseid_t promise = -1;
result = tf_task_allocate_promise(sender, &promise);
_tf_task_sendPromiseExportMessage(sender, recipient, kInvokeExport, promise, import->_export, array);
result = tf_task_get_promise(sender, promise);
}
else
{
@ -1120,7 +1120,7 @@ static void _tf_task_free_promise(tf_task_t* task, promiseid_t id)
}
}
promiseid_t tf_task_allocate_promise(tf_task_t* task)
JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
{
promiseid_t promiseId;
do {
@ -1142,7 +1142,8 @@ promiseid_t tf_task_allocate_promise(tf_task_t* task)
task->_promises[index] = promise;
task->_promise_count++;
_tf_task_trace_promises(task);
return promiseId;
*out_promise = promiseId;
return promise.values[0];
}
void tf_task_resolve_promise(tf_task_t* task, promiseid_t promise, JSValue value)