Send prints to the browser console. Obvious in retrospect.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3840 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -32,6 +32,7 @@ typedef struct _tf_taskstub_t {
|
||||
|
||||
JSValue _on_exit;
|
||||
JSValue _on_error;
|
||||
JSValue _on_print;
|
||||
|
||||
tf_task_t* _owner;
|
||||
tf_packetstream_t* _stream;
|
||||
@ -61,6 +62,8 @@ static JSValue _taskstub_get_on_exit(JSContext* context, JSValueConst this_val,
|
||||
static JSValue _taskstub_set_on_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _taskstub_get_on_error(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _taskstub_set_on_error(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _taskstub_get_on_print(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _taskstub_set_on_print(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static JSValue _taskstub_loadFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
|
||||
static void _taskstub_on_process_exit(uv_process_t* process, int64_t status, int terminationSignal);
|
||||
static void _taskstub_finalizer(JSRuntime *runtime, JSValue value);
|
||||
@ -77,6 +80,7 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
stub->_owner = parent;
|
||||
stub->_on_exit = JS_UNDEFINED;
|
||||
stub->_on_error = JS_UNDEFINED;
|
||||
stub->_on_print = JS_UNDEFINED;
|
||||
stub->_object = JS_DupValue(context, taskObject);
|
||||
|
||||
JSAtom atom = JS_NewAtom(context, "onExit");
|
||||
@ -99,6 +103,16 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a
|
||||
0);
|
||||
JS_FreeAtom(context, atom);
|
||||
|
||||
atom = JS_NewAtom(context, "onPrint");
|
||||
JS_DefinePropertyGetSet(
|
||||
context,
|
||||
taskObject,
|
||||
atom,
|
||||
JS_NewCFunction(context, _taskstub_get_on_print, "getOnPrint", 0),
|
||||
JS_NewCFunction(context, _taskstub_set_on_print, "setOnPrint", 0),
|
||||
0);
|
||||
JS_FreeAtom(context, atom);
|
||||
|
||||
JS_SetPropertyStr(context, taskObject, "activate", JS_NewCFunction(context, _taskstub_activate, "activate", 0));
|
||||
JS_SetPropertyStr(context, taskObject, "execute", JS_NewCFunction(context, _taskstub_execute, "execute", 1));
|
||||
JSAtom imports = JS_NewAtom(context, "imports");
|
||||
@ -166,6 +180,7 @@ void _taskstub_gc_mark(JSRuntime* rt, JSValueConst value, JS_MarkFunc mark_func)
|
||||
{
|
||||
JS_MarkValue(rt, stub->_on_exit, mark_func);
|
||||
JS_MarkValue(rt, stub->_on_error, mark_func);
|
||||
JS_MarkValue(rt, stub->_on_print, mark_func);
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,6 +226,7 @@ tf_taskstub_t* tf_taskstub_create_parent(tf_task_t* task, uv_file file)
|
||||
parentStub->_stream = tf_packetstream_create();
|
||||
parentStub->_on_exit = JS_UNDEFINED;
|
||||
parentStub->_on_error = JS_UNDEFINED;
|
||||
parentStub->_on_print = JS_UNDEFINED;
|
||||
|
||||
parentStub->_taskObject = parentObject;
|
||||
JS_SetOpaque(parentObject, parentStub);
|
||||
@ -247,6 +263,7 @@ static void _taskstub_finalizer(JSRuntime* runtime, JSValue value)
|
||||
tf_taskstub_t* stub = JS_GetOpaque(value, _classId);
|
||||
stub->_on_exit = JS_UNDEFINED;
|
||||
stub->_on_error = JS_UNDEFINED;
|
||||
stub->_on_print = JS_UNDEFINED;
|
||||
tf_packetstream_destroy(stub->_stream);
|
||||
stub->_stream = NULL;
|
||||
stub->_finalized = true;
|
||||
@ -353,6 +370,23 @@ static JSValue _taskstub_set_on_error(JSContext* context, JSValueConst this_val,
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue _taskstub_get_on_print(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId);
|
||||
return JS_DupValue(context, stub->_on_print);
|
||||
}
|
||||
|
||||
static JSValue _taskstub_set_on_print(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId);
|
||||
if (!JS_IsUndefined(stub->_on_print))
|
||||
{
|
||||
JS_FreeValue(context, stub->_on_print);
|
||||
}
|
||||
stub->_on_print = JS_DupValue(context, argv[0]);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue _taskstub_activate(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId);
|
||||
@ -399,3 +433,14 @@ void tf_taskstub_on_error(tf_taskstub_t* stub, JSValue error)
|
||||
JS_FreeValue(context, result);
|
||||
}
|
||||
}
|
||||
|
||||
void tf_taskstub_on_print(tf_taskstub_t* stub, JSValue arguments)
|
||||
{
|
||||
JSContext* context = tf_task_get_context(stub->_owner);
|
||||
if (!JS_IsUndefined(stub->_on_print))
|
||||
{
|
||||
JSValue result = JS_Call(context, stub->_on_print, JS_NULL, 1, &arguments);
|
||||
tf_util_report_error(context, result);
|
||||
JS_FreeValue(context, result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user