Changeset 6 for trunk/sagot/src/sagot_glib_eventloop.c
- Timestamp:
- 04/03/06 00:50:06 (3 years ago)
- Files:
-
- 1 modified
-
trunk/sagot/src/sagot_glib_eventloop.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sagot/src/sagot_glib_eventloop.c
r5 r6 25 25 26 26 static JSFunctionSpec eventloop_methods[] = { 27 {"run", sagot_eventloop_run, 0,0,0 }, 28 {"quit", sagot_eventloop_quit, 0,0,0 }, 27 {"run", sagot_eventloop_run, 0,0,0 }, 28 {"quit", sagot_eventloop_quit, 0,0,0 }, 29 {"yield", sagot_eventloop_yield, 1,0,0 }, 29 30 }; 30 31 … … 82 83 JSContext *cx = qitem->cx; 83 84 jsval *argv = qitem->argv; 85 jsval argc = qitem->argc; 84 86 85 87 JSObject *fobj = JSVAL_TO_OBJECT(argv[0]); … … 89 91 90 92 jsval *rval; 91 JS_CallFunction(cx, parent, function, qitem->argc, argv, rval);93 jsval *args = g_malloc(sizeof(jsval *) * (argc - 1)); 92 94 93 JS_RemoveRoot(cx, rval); 94 JS_RemoveRoot(cx, argv); 95 for (int i = 1; i < argc; i++) { 96 args[i - 1] = argv[i]; 97 } 98 99 JS_CallFunction(cx, parent, function, qitem->argc, args, rval); 100 101 return TRUE; 102 } 103 104 void sagot_eventloop_dispatch_cleanup (void *data) { 105 struct queue_item *qitem = (struct queue_item *) data; 106 107 JS_RemoveRoot(qitem->cx, qitem->argv); 95 108 96 109 g_free(qitem); 97 110 } 98 111 99 void sagot_eventloop_dispatch_cleanup (void *data) { 100 JSObject *object = (JSObject *) data; 101 } 102 103 static JSBool sagot_eventloop_enqueue (JSContext *cx, JSObject *obj, uintN 112 static JSBool sagot_eventloop_yield (JSContext *cx, JSObject *obj, uintN 104 113 argc, jsval *argv, jsval *rval) { 105 114 GMainLoop *mainloop = (GMainLoop *) JS_GetPrivate(cx, obj); … … 115 124 if (argc < 1) { 116 125 JS_ReportError(cx, "EventLoop.enqueue() requires arguments"); 117 return JS_FALSE;126 return false; 118 127 } 119 128 … … 126 135 JS_AddRoot(cx, argv); 127 136 128 return JS_TRUE;137 return true; 129 138 } 130 139 131 140 JS_ReportError(cx, "argument 1 to enqueue() must be a function"); 132 141 133 return JS_FALSE;142 return false; 134 143 } 135 144