diff options
-rw-r--r-- | gjs/context.c | 42 | ||||
-rw-r--r-- | modules/console.c | 15 | ||||
-rw-r--r-- | modules/console.h | 4 | ||||
-rw-r--r-- | modules/dbus.c | 158 | ||||
-rw-r--r-- | modules/gettext-native.c | 104 | ||||
-rw-r--r-- | modules/lang.c | 12 | ||||
-rw-r--r-- | modules/mainloop.c | 81 |
7 files changed, 217 insertions, 199 deletions
diff --git a/gjs/context.c b/gjs/context.c index 7c0363e6..b550c5f7 100644 --- a/gjs/context.c +++ b/gjs/context.c @@ -93,11 +93,10 @@ static GList *all_contexts = NULL; static JSBool gjs_log(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *s; JSExceptionState *exc_state; JSString *jstr; @@ -132,16 +131,16 @@ gjs_log(JSContext *context, g_free(s); JS_EndRequest(context); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } static JSBool gjs_log_error(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *s; JSExceptionState *exc_state; JSString *jstr; @@ -181,6 +180,7 @@ gjs_log_error(JSContext *context, g_free(s); JS_EndRequest(context); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } @@ -243,11 +243,10 @@ gjs_print_parse_args(JSContext *context, static JSBool gjs_print(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *buffer; if (!gjs_print_parse_args(context, argc, argv, &buffer)) { @@ -257,16 +256,16 @@ gjs_print(JSContext *context, g_print("%s\n", buffer); g_free(buffer); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } static JSBool gjs_printerr(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *buffer; if (!gjs_print_parse_args(context, argc, argv, &buffer)) { @@ -276,6 +275,7 @@ gjs_printerr(JSContext *context, g_printerr("%s\n", buffer); g_free(buffer); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } @@ -584,26 +584,26 @@ gjs_context_constructor (GType type, /* Define a global function called log() */ if (!JS_DefineFunction(js_context->context, js_context->global, "log", - gjs_log, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_log, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) gjs_fatal("Failed to define log function"); if (!JS_DefineFunction(js_context->context, js_context->global, "logError", - gjs_log_error, - 2, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_log_error, + 2, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) gjs_fatal("Failed to define logError function"); /* Define global functions called print() and printerr() */ if (!JS_DefineFunction(js_context->context, js_context->global, "print", - gjs_print, - 3, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_print, + 3, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) gjs_fatal("Failed to define print function"); if (!JS_DefineFunction(js_context->context, js_context->global, "printerr", - gjs_printerr, - 4, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_printerr, + 4, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) gjs_fatal("Failed to define printerr function"); /* We need to know what the default context is, since it's the context whose diff --git a/modules/console.c b/modules/console.c index 76381257..bb930a74 100644 --- a/modules/console.c +++ b/modules/console.c @@ -158,11 +158,10 @@ gjs_console_readline(JSContext *cx, char *bufp, FILE *file, const char *prompt) JSBool gjs_console_interact(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + JSObject *object = JS_THIS_OBJECT(context, vp); gboolean eof = FALSE; JSScript *script; jsval result; @@ -196,13 +195,13 @@ gjs_console_interact(JSContext *context, } bufp += strlen(bufp); lineno++; - } while (!JS_BufferIsCompilableUnit(context, obj, buffer, strlen(buffer))); + } while (!JS_BufferIsCompilableUnit(context, object, buffer, strlen(buffer))); - script = JS_CompileScript(context, obj, buffer, strlen(buffer), "typein", + script = JS_CompileScript(context, object, buffer, strlen(buffer), "typein", startline); if (script) - JS_ExecuteScript(context, obj, script, &result); + JS_ExecuteScript(context, object, script, &result); if (JS_GetPendingException(context, &result)) { str = JS_ValueToString(context, result); @@ -234,8 +233,8 @@ gjs_define_console_stuff(JSContext *context, { if (!JS_DefineFunction(context, module_obj, "interact", - gjs_console_interact, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative) gjs_console_interact, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; return JS_TRUE; diff --git a/modules/console.h b/modules/console.h index 07d457e3..da787600 100644 --- a/modules/console.h +++ b/modules/console.h @@ -34,10 +34,8 @@ G_BEGIN_DECLS JSBool gjs_define_console_stuff (JSContext *context, JSObject *in_object); JSBool gjs_console_interact (JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *rval); + jsval *vp); G_END_DECLS diff --git a/modules/dbus.c b/modules/dbus.c index 97025938..0ab3c795 100644 --- a/modules/dbus.c +++ b/modules/dbus.c @@ -365,11 +365,11 @@ pending_free_closure(void *data) /* Args are bus_name, object_path, iface, method, out signature, in signature, args, and callback to get returned value */ static JSBool gjs_js_dbus_call_async(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); GClosure *closure; DBusMessage *message; DBusPendingCall *pending; @@ -691,11 +691,11 @@ signal_handler_callback(DBusConnection *connection, /* Args are bus_name, object_path, iface, signal, and callback */ static JSBool gjs_js_dbus_watch_signal(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); const char *bus_name; const char *object_path; const char *iface; @@ -748,7 +748,7 @@ gjs_js_dbus_watch_signal(JSContext *context, * ref to the SignalHandler */ - *retval = INT_TO_JSVAL(id); + JS_SET_RVAL(context, vp, INT_TO_JSVAL(id)); return JS_TRUE; } @@ -756,11 +756,11 @@ gjs_js_dbus_watch_signal(JSContext *context, /* Args are handler id */ static JSBool gjs_js_dbus_unwatch_signal_by_id(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); int id; DBusBusType bus_type; @@ -782,11 +782,11 @@ gjs_js_dbus_unwatch_signal_by_id(JSContext *context, /* Args are bus_name, object_path, iface, signal, and callback */ static JSBool gjs_js_dbus_unwatch_signal(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); const char *bus_name; const char *object_path; const char *iface; @@ -850,11 +850,11 @@ gjs_js_dbus_unwatch_signal(JSContext *context, /* Args are object_path, iface, signal, arguments signature, arguments */ static JSBool gjs_js_dbus_emit_signal(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); DBusConnection *bus_connection; DBusMessage *message; DBusMessageIter arg_iter; @@ -926,11 +926,10 @@ gjs_js_dbus_emit_signal(JSContext *context, * to ensure that a signal has been sent before proceeding. */ static JSBool gjs_js_dbus_flush(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + JSObject *obj = JS_THIS_OBJECT(context, vp); DBusConnection *bus_connection; DBusBusType bus_type; @@ -957,17 +956,18 @@ gjs_js_dbus_flush(JSContext *context, /* Args are bus_name, object_path, iface, method, out signature, in signature, args */ static JSBool gjs_js_dbus_call(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); DBusMessage *message; DBusError derror; DBusMessage *reply; JSBool result; DBusConnection *bus_connection; DBusBusType bus_type; + jsval retval; if (argc < 8) { gjs_throw(context, "Not enough args, need bus name, object path, interface, method, out signature, in signature, autostart flag, and args"); @@ -991,7 +991,11 @@ gjs_js_dbus_call(JSContext *context, /* The retval is (we hope) rooted by jsapi when it invokes the * native function */ - result = complete_call(context, retval, reply, &derror); + retval = JSVAL_NULL; + JS_AddValueRoot(context, &retval); + result = complete_call(context, &retval, reply, &derror); + if (result) + JS_SET_RVAL(context, vp, retval); if (reply) dbus_message_unref(reply); @@ -1108,11 +1112,11 @@ owner_closure_invalidated(gpointer data, /* Args are bus_name, name type, acquired_func, lost_func */ static JSBool gjs_js_dbus_acquire_name(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); const char *bus_name; JSObject *acquire_func; JSObject *lost_func; @@ -1120,6 +1124,7 @@ gjs_js_dbus_acquire_name(JSContext *context, DBusBusType bus_type; GjsDBusNameType name_type; unsigned int id; + jsval retval = JSVAL_VOID; if (argc < 4) { gjs_throw(context, "Not enough args, need bus name, name type, acquired_func, lost_func"); @@ -1184,10 +1189,11 @@ gjs_js_dbus_acquire_name(JSContext *context, &owner->funcs, owner); - if (!JS_NewNumberValue(context, (jsdouble)id, retval)) { + if (!JS_NewNumberValue(context, (jsdouble)id, &retval)) { gjs_throw(context, "Could not convert name owner id to jsval"); return JS_FALSE; } + JS_SET_RVAL(context, vp, retval); return JS_TRUE; } @@ -1195,11 +1201,11 @@ gjs_js_dbus_acquire_name(JSContext *context, /* Args are name owner monitor id */ static JSBool gjs_js_dbus_release_name_by_id (JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); DBusBusType bus_type; unsigned int id; @@ -1215,6 +1221,7 @@ gjs_js_dbus_release_name_by_id (JSContext *context, gjs_dbus_release_name_by_id(bus_type, id); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } @@ -1342,11 +1349,11 @@ watch_closure_invalidated(gpointer data, /* Args are bus_name, start_if_not_found, appeared_func, vanished_func */ static JSBool gjs_js_dbus_watch_name(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); const char *bus_name; JSBool start_if_not_found; JSObject *appeared_func; @@ -1416,6 +1423,7 @@ gjs_js_dbus_watch_name(JSContext *context, &watch_name_funcs, watcher); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } @@ -1461,11 +1469,10 @@ unique_name_getter(JSContext *context, static JSBool gjs_js_dbus_signature_length(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); const char *signature; DBusSignatureIter iter; int length = 0; @@ -1495,18 +1502,18 @@ gjs_js_dbus_signature_length(JSContext *context, } while (dbus_signature_iter_next(&iter)); out: - *retval = INT_TO_JSVAL(length); + JS_SET_RVAL(context, vp, INT_TO_JSVAL(length)); return JS_TRUE; } static JSBool gjs_js_dbus_start_service(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); + JSObject *obj = JS_THIS_OBJECT(context, vp); const char *name; DBusBusType bus_type; DBusConnection *bus_connection; @@ -1560,11 +1567,10 @@ gjs_js_dbus_get_machine_id(JSContext *context, static JSBool gjs_js_dbus_get_current_message_context(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); const char *sender; JSString *sender_str; JSObject *context_obj; @@ -1576,7 +1582,7 @@ gjs_js_dbus_get_current_message_context(JSContext *context, return JS_FALSE; if (!_gjs_current_dbus_messages) { - *retval = JSVAL_NULL; + JS_SET_RVAL(context, vp, JSVAL_NULL); return JS_TRUE; } @@ -1609,7 +1615,7 @@ gjs_js_dbus_get_current_message_context(JSContext *context, goto out; result = JS_TRUE; - *retval = context_val; + JS_SET_RVAL(context, vp, context_val); out: JS_RemoveValueRoot(context, &context_val); @@ -1647,69 +1653,69 @@ define_bus_proto(JSContext *context, if (!JS_DefineFunction(context, bus_proto_obj, "call", - gjs_js_dbus_call, - 8, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_call, + 8, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "call_async", - gjs_js_dbus_call_async, - 9, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_call_async, + 9, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "acquire_name", - gjs_js_dbus_acquire_name, - 3, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_acquire_name, + 3, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "release_name_by_id", - gjs_js_dbus_release_name_by_id, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_release_name_by_id, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "watch_name", - gjs_js_dbus_watch_name, - 4, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_watch_name, + 4, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "watch_signal", - gjs_js_dbus_watch_signal, - 5, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_watch_signal, + 5, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "unwatch_signal_by_id", - gjs_js_dbus_unwatch_signal_by_id, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_unwatch_signal_by_id, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "unwatch_signal", - gjs_js_dbus_unwatch_signal, - 5, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_unwatch_signal, + 5, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "emit_signal", - gjs_js_dbus_emit_signal, - 3, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_emit_signal, + 3, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "flush", - gjs_js_dbus_flush, - 0, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_flush, + 0, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; if (!JS_DefineFunction(context, bus_proto_obj, "start_service", - gjs_js_dbus_start_service, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_start_service, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) goto out; /* Add the bus proto object inside the passed in module object */ @@ -1807,42 +1813,42 @@ gjs_js_define_dbus_stuff(JSContext *context, if (!JS_DefineFunction(context, module_obj, "signatureLength", - gjs_js_dbus_signature_length, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_signature_length, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineProperty(context, module_obj, "BUS_SESSION", INT_TO_JSVAL(DBUS_BUS_SESSION), NULL, NULL, - GJS_MODULE_PROP_FLAGS)) + GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineProperty(context, module_obj, "BUS_SYSTEM", INT_TO_JSVAL(DBUS_BUS_SYSTEM), NULL, NULL, - GJS_MODULE_PROP_FLAGS)) + GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineProperty(context, module_obj, "BUS_STARTER", INT_TO_JSVAL(DBUS_BUS_STARTER), NULL, NULL, - GJS_MODULE_PROP_FLAGS)) + GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineProperty(context, module_obj, "localMachineID", JSVAL_VOID, gjs_js_dbus_get_machine_id, NULL, - GJS_MODULE_PROP_FLAGS)) + GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "getCurrentMessageContext", - gjs_js_dbus_get_current_message_context, - 0, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_js_dbus_get_current_message_context, + 0, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; /* Define both the session and system objects */ diff --git a/modules/gettext-native.c b/modules/gettext-native.c index e53ecdcf..dc38f6d2 100644 --- a/modules/gettext-native.c +++ b/modules/gettext-native.c @@ -32,11 +32,10 @@ static JSBool gjs_textdomain(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *domain; if (!gjs_parse_args(context, "textdomain", "s", argc, argv, @@ -46,16 +45,16 @@ gjs_textdomain(JSContext *context, textdomain(domain); g_free(domain); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } static JSBool gjs_bindtextdomain(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *domain; char *location; @@ -69,41 +68,44 @@ gjs_bindtextdomain(JSContext *context, bind_textdomain_codeset(domain, "UTF-8"); g_free (domain); g_free (location); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } static JSBool gjs_gettext(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *msgid; const char *translated; JSBool result; + jsval retval; if (!gjs_parse_args (context, "gettext", "s", argc, argv, "msgid", &msgid)) return JS_FALSE; translated = gettext(msgid); - result = gjs_string_from_utf8(context, translated, -1, retval); + result = gjs_string_from_utf8(context, translated, -1, &retval); + if (result) + JS_SET_RVAL(context, vp, retval); g_free (msgid); return result; } static JSBool gjs_dgettext(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *domain; char *msgid; const char *translated; JSBool result; + jsval retval; if (!gjs_parse_args (context, "dgettext", "zs", argc, argv, "domain", &domain, "msgid", &msgid)) @@ -112,23 +114,25 @@ gjs_dgettext(JSContext *context, translated = dgettext(domain, msgid); g_free (domain); - result = gjs_string_from_utf8(context, translated, -1, retval); + result = gjs_string_from_utf8(context, translated, -1, &retval); + if (result) + JS_SET_RVAL(context, vp, retval); g_free (msgid); return result; } static JSBool gjs_ngettext(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *msgid1; char *msgid2; guint32 n; const char *translated; JSBool result; + jsval retval; if (!gjs_parse_args (context, "ngettext", "ssu", argc, argv, "msgid1", &msgid1, "msgid2", &msgid2, "n", &n)) @@ -136,7 +140,9 @@ gjs_ngettext(JSContext *context, translated = ngettext(msgid1, msgid2, n); - result = gjs_string_from_utf8(context, translated, -1, retval); + result = gjs_string_from_utf8(context, translated, -1, &retval); + if (result) + JS_SET_RVAL(context, vp, retval); g_free (msgid1); g_free (msgid2); return result; @@ -144,17 +150,17 @@ gjs_ngettext(JSContext *context, static JSBool gjs_dngettext(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *domain; char *msgid1; char *msgid2; guint n; const char *translated; JSBool result; + jsval retval; if (!gjs_parse_args (context, "dngettext", "zssu", argc, argv, "domain", &domain, "msgid1", &msgid1, @@ -164,7 +170,9 @@ gjs_dngettext(JSContext *context, translated = dngettext(domain, msgid1, msgid2, n); g_free (domain); - result = gjs_string_from_utf8(context, translated, -1, retval); + result = gjs_string_from_utf8(context, translated, -1, &retval); + if (result) + JS_SET_RVAL(context, vp, retval); g_free (msgid1); g_free (msgid2); return result; @@ -172,15 +180,15 @@ gjs_dngettext(JSContext *context, static JSBool gjs_pgettext(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *src_context; char *msgid; const char *translated; JSBool result; + jsval retval; if (!gjs_parse_args (context, "pgettext", "ss", argc, argv, "context", &src_context, "msgid", &msgid)) @@ -189,23 +197,25 @@ gjs_pgettext(JSContext *context, translated = g_dpgettext2(NULL, src_context, msgid); g_free (src_context); - result = gjs_string_from_utf8(context, translated, -1, retval); + result = gjs_string_from_utf8(context, translated, -1, &retval); + if (result) + JS_SET_RVAL(context, vp, retval); g_free (msgid); return result; } static JSBool gjs_dpgettext(JSContext *context, - JSObject *obj, uintN argc, - jsval *argv, - jsval *retval) + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *domain; char *src_context; char *msgid; const char *translated; JSBool result; + jsval retval; if (!gjs_parse_args (context, "dpgettext", "sss", argc, argv, "domain", &domain, "context", &src_context, @@ -216,7 +226,9 @@ gjs_dpgettext(JSContext *context, g_free (domain); g_free (src_context); - result = gjs_string_from_utf8(context, translated, -1, retval); + result = gjs_string_from_utf8(context, translated, -1, &retval); + if (result) + JS_SET_RVAL(context, vp, retval); g_free (msgid); return result; } @@ -227,50 +239,50 @@ gjs_define_gettext_stuff(JSContext *context, { if (!JS_DefineFunction(context, module_obj, "textdomain", - gjs_textdomain, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_textdomain, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "bindtextdomain", - gjs_bindtextdomain, - 2, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_bindtextdomain, + 2, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "gettext", - gjs_gettext, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_gettext, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "dgettext", - gjs_dgettext, - 2, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_dgettext, + 2, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "ngettext", - gjs_ngettext, - 3, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_ngettext, + 3, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "dngettext", - gjs_dngettext, - 4, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_dngettext, + 4, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "pgettext", - gjs_pgettext, - 2, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_pgettext, + 2, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "dpgettext", - gjs_dpgettext, - 3, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_dpgettext, + 3, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; return JS_TRUE; diff --git a/modules/lang.c b/modules/lang.c index 1965fab4..b7a0dcad 100644 --- a/modules/lang.c +++ b/modules/lang.c @@ -29,9 +29,11 @@ #include <jsapi.h> static JSBool -gjs_lang_seal(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *retval) +gjs_lang_seal(JSContext *cx, + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(cx, vp); JSObject *target; JSBool deep = JS_FALSE; @@ -49,7 +51,7 @@ gjs_lang_seal(JSContext *cx, JSObject *obj, uintN argc, return JS_FALSE; #endif - *retval = OBJECT_TO_JSVAL(target); + JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(target)); return JS_TRUE; } @@ -59,8 +61,8 @@ gjs_define_lang_stuff(JSContext *context, { if (!JS_DefineFunction(context, module_obj, "seal", - gjs_lang_seal, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_lang_seal, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; return JS_TRUE; diff --git a/modules/mainloop.c b/modules/mainloop.c index c58b58ef..af0ff652 100644 --- a/modules/mainloop.c +++ b/modules/mainloop.c @@ -37,11 +37,10 @@ static GHashTable *pending_main_loops; static JSBool gjs_main_loop_quit(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *cancel_id; GMainLoop *main_loop; @@ -72,16 +71,16 @@ gjs_main_loop_quit(JSContext *context, g_free(cancel_id); g_main_loop_quit(main_loop); + JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; } static JSBool gjs_main_loop_run(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); char *cancel_id; GMainLoop *main_loop; @@ -180,15 +179,15 @@ closure_invalidated(gpointer data, static JSBool gjs_timeout_add(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); GClosure *closure; JSObject *callback; guint32 interval; guint id; + jsval retval; /* Best I can tell, there is no way to know if argv[1] is really * callable other than to just try it. Checking whether it's a @@ -218,23 +217,24 @@ gjs_timeout_add(JSContext *context, g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id), closure_invalidated); - if (!JS_NewNumberValue(context, id, retval)) + if (!JS_NewNumberValue(context, id, &retval)) return JS_FALSE; + JS_SET_RVAL(context, vp, retval); return JS_TRUE; } static JSBool gjs_timeout_add_seconds(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); GClosure *closure; JSObject *callback; guint32 interval; guint id; + jsval retval; /* See comment for timeout_add above */ if (!gjs_parse_args(context, "timeout_add_seconds", "uo", argc, argv, @@ -260,23 +260,24 @@ gjs_timeout_add_seconds(JSContext *context, g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id), closure_invalidated); - if (!JS_NewNumberValue(context, id, retval)) + if (!JS_NewNumberValue(context, id, &retval)) return JS_FALSE; + JS_SET_RVAL(context, vp, retval); return JS_TRUE; } static JSBool gjs_idle_add(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); JSObject *callback; GClosure *closure; guint id; int priority = G_PRIORITY_DEFAULT_IDLE; + jsval retval; /* Best I can tell, there is no way to know if argv[0] is really * callable other than to just try it. Checking whether it's a @@ -305,19 +306,19 @@ gjs_idle_add(JSContext *context, g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id), closure_invalidated); - if (!JS_NewNumberValue(context, id, retval)) + if (!JS_NewNumberValue(context, id, &retval)) return JS_FALSE; + JS_SET_RVAL(context, vp, retval); return JS_TRUE; } static JSBool gjs_source_remove(JSContext *context, - JSObject *obj, - uintN argc, - jsval *argv, - jsval *retval) + uintN argc, + jsval *vp) { + jsval *argv = JS_ARGV(context, vp); guint32 source_id; gboolean success; @@ -327,7 +328,7 @@ gjs_source_remove(JSContext *context, success = g_source_remove(source_id); - *retval = BOOLEAN_TO_JSVAL(success); + JS_SET_RVAL(context, vp, BOOLEAN_TO_JSVAL(success)); return JS_TRUE; } @@ -342,38 +343,38 @@ gjs_define_mainloop_stuff(JSContext *context, if (!JS_DefineFunction(context, module_obj, "run", - gjs_main_loop_run, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_main_loop_run, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "quit", - gjs_main_loop_quit, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_main_loop_quit, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "idle_add", - gjs_idle_add, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_idle_add, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "timeout_add", - gjs_timeout_add, - 2, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_timeout_add, + 2, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "timeout_add_seconds", - gjs_timeout_add_seconds, - 2, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_timeout_add_seconds, + 2, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; if (!JS_DefineFunction(context, module_obj, "source_remove", - gjs_source_remove, - 1, GJS_MODULE_PROP_FLAGS)) + (JSNative)gjs_source_remove, + 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE)) return JS_FALSE; return JS_TRUE; |