Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit a1797cc6 authored by Deucе's avatar Deucе 👌🏾

Add js.setImmediate(callback[, thisObj)

I haven't added a clearImmediate() because there's currently no way
of manipulating the run queue, and I can't come up with a reason
someone would actually need it.
parent 78146ab2
Pipeline #1833 passed with stage
in 9 minutes and 33 seconds
...@@ -879,6 +879,52 @@ js_setInterval(JSContext *cx, uintN argc, jsval *arglist) ...@@ -879,6 +879,52 @@ js_setInterval(JSContext *cx, uintN argc, jsval *arglist)
return JS_TRUE; return JS_TRUE;
} }
static JSBool
js_setImmediate(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
JSFunction *cbf;
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
js_callback_t *cb;
struct js_runq_entry *rqe;
if((cb=(js_callback_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
if (argc < 1) {
JS_ReportError(cx, "js.setImmediate() requires a callback");
return JS_FALSE;
}
cbf = JS_ValueToFunction(cx, argv[0]);
if (cbf == NULL) {
return JS_FALSE;
}
if (argc > 1) {
if (!JS_ValueToObject(cx, argv[1], &obj))
return JS_FALSE;
}
rqe = malloc(sizeof(*rqe));
if (rqe == NULL) {
JS_ReportError(cx, "error allocating %ul bytes", sizeof(*rqe));
return JS_FALSE;
}
rqe->func = cbf;
rqe->cx = obj;
JS_AddObjectRoot(cx, &rqe->cx);
rqe->next = NULL;
if (cb->rq_tail != NULL)
cb->rq_tail->next = rqe;
cb->rq_tail = rqe;
if (cb->rq_head == NULL)
cb->rq_head = rqe;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
return JS_TRUE;
}
static JSBool static JSBool
js_addEventListener(JSContext *cx, uintN argc, jsval *arglist) js_addEventListener(JSContext *cx, uintN argc, jsval *arglist)
{ {
...@@ -1438,6 +1484,10 @@ static jsSyncMethodSpec js_functions[] = { ...@@ -1438,6 +1484,10 @@ static jsSyncMethodSpec js_functions[] = {
,JSDOCSTR("Add all listeners of eventName to the runqueue. If obj is passed, specifies this in the callback (the js object is used otherwise).") ,JSDOCSTR("Add all listeners of eventName to the runqueue. If obj is passed, specifies this in the callback (the js object is used otherwise).")
,31802 ,31802
}, },
{"setImmediate", js_setImmediate, 1, JSTYPE_VOID, JSDOCSTR("callback[, thisObj]")
,JSDOCSTR("adds the callback to the end of the run queue, where it will be called after all pending events are processed")
,31900
},
{0} {0}
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment