Ugg, my print() was destructive to its arguments.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3933 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-07-24 21:05:23 +00:00
parent f764007fc6
commit 41afc3bdd6
2 changed files with 20 additions and 4 deletions

View File

@ -21,7 +21,7 @@ windebug winrelease: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VER
windebug winrelease: LDFLAGS += -static windebug winrelease: LDFLAGS += -static
ifeq ($(UNAME_M),x86_64) ifeq ($(UNAME_M),x86_64)
debug: CFLAGS += -fsanitize=address -fsanitize=undefined debug: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fno-common
debug: LDFLAGS += -fsanitize=address -fsanitize=undefined debug: LDFLAGS += -fsanitize=address -fsanitize=undefined
endif endif

View File

@ -154,6 +154,7 @@ static void _tf_task_sendPromiseExportMessage(tf_task_t* from, tf_taskstub_t* to
static JSValue _tf_task_executeSource(tf_task_t* task, const char* source, const char* name); static JSValue _tf_task_executeSource(tf_task_t* task, const char* source, const char* name);
static tf_taskstub_t* _tf_task_get_stub(tf_task_t* task, taskid_t id); static tf_taskstub_t* _tf_task_get_stub(tf_task_t* task, taskid_t id);
static void _tf_task_release_export(tf_taskstub_t* stub, exportid_t exportId); static void _tf_task_release_export(tf_taskstub_t* stub, exportid_t exportId);
static bool _tf_task_run_jobs(tf_task_t* task);
static void _tf_task_run_jobs_idle(uv_idle_t* idle); static void _tf_task_run_jobs_idle(uv_idle_t* idle);
static void _tf_task_run_jobs_prepare(uv_prepare_t* prepare); static void _tf_task_run_jobs_prepare(uv_prepare_t* prepare);
@ -370,7 +371,7 @@ static tf_taskstub_t* _tf_task_get_stub(tf_task_t* task, taskid_t id)
} }
static JSValue _import_call(JSContext* context, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst *argv, int flags) static JSValue _import_call(JSContext* context, JSValueConst func_obj, JSValueConst this_val, int argc, JSValueConst* argv, int flags)
{ {
import_record_t* import = JS_GetOpaque(func_obj, _import_class_id); import_record_t* import = JS_GetOpaque(func_obj, _import_class_id);
if (!import) if (!import)
@ -729,6 +730,15 @@ static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int a
return result; return result;
} }
static JSValue _tf_task_promiseTest(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
tf_task_t* task = JS_GetContextOpaque(context);
promiseid_t promise_id = -1;
JSValue promise = tf_task_allocate_promise(task, &promise_id);
tf_task_resolve_promise(task, promise_id, argv[0]);
return promise;
}
const char* _tf_task_get_message_type(tf_task_message_t type) const char* _tf_task_get_message_type(tf_task_message_t type)
{ {
switch (type) switch (type)
@ -1041,16 +1051,21 @@ void tf_task_reject_promise(tf_task_t* task, promiseid_t promise, JSValue value)
free_arg = true; free_arg = true;
} }
JSValue result = JS_Call(task->_context, it->values[1], JS_UNDEFINED, 1, &arg); JSValue result = JS_Call(task->_context, it->values[1], JS_UNDEFINED, 1, &arg);
tf_util_report_error(task->_context, result);
if (free_arg) if (free_arg)
{ {
JS_FreeValue(task->_context, arg); JS_FreeValue(task->_context, arg);
} }
tf_util_report_error(task->_context, result);
JS_FreeValue(task->_context, it->values[0]); JS_FreeValue(task->_context, it->values[0]);
JS_FreeValue(task->_context, it->values[1]); JS_FreeValue(task->_context, it->values[1]);
JS_FreeValue(task->_context, result); JS_FreeValue(task->_context, result);
_tf_task_free_promise(task, promise); _tf_task_free_promise(task, promise);
} }
else
{
printf("Didn't find promise %d to reject.\n", promise);
abort();
}
} }
taskid_t tf_task_allocate_task_id(tf_task_t* task, tf_taskstub_t* stub) taskid_t tf_task_allocate_task_id(tf_task_t* task, tf_taskstub_t* stub)
@ -1381,6 +1396,7 @@ void tf_task_activate(tf_task_t* task)
JS_SetPropertyStr(context, global, "exit", JS_NewCFunction(context, _tf_task_exit, "exit", 1)); JS_SetPropertyStr(context, global, "exit", JS_NewCFunction(context, _tf_task_exit, "exit", 1));
JS_SetPropertyStr(context, global, "version", JS_NewCFunction(context, _tf_task_version, "version", 0)); JS_SetPropertyStr(context, global, "version", JS_NewCFunction(context, _tf_task_version, "version", 0));
JS_SetPropertyStr(context, global, "getFile", JS_NewCFunction(context, _tf_task_getFile, "getFile", 1)); JS_SetPropertyStr(context, global, "getFile", JS_NewCFunction(context, _tf_task_getFile, "getFile", 1));
JS_SetPropertyStr(context, global, "promiseTest", JS_NewCFunction(context, _tf_task_promiseTest, "promiseTest", 1));
JS_FreeValue(context, global); JS_FreeValue(context, global);
} }
@ -1534,7 +1550,7 @@ void tf_task_print(tf_task_t* task, int argc, JSValueConst* argv)
JSValue array = JS_NewArray(task->_context); JSValue array = JS_NewArray(task->_context);
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)
{ {
JS_SetPropertyUint32(task->_context, array, i, argv[i]); JS_SetPropertyUint32(task->_context, array, i, JS_DupValue(task->_context, argv[i]));
} }
void* buffer; void* buffer;