[gjs/wip/xulrunner-2-rebase4: 8/8] Port more custom functions to be "fast" natives
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/xulrunner-2-rebase4: 8/8] Port more custom functions to be "fast" natives
- Date: Fri, 29 Oct 2010 17:03:19 +0000 (UTC)
commit 4ad6463194bbf2990df3d00ef9ff05c3752c68cc
Author: Colin Walters <walters verbum org>
Date: Wed Oct 20 18:40:20 2010 -0400
Port more custom functions to be "fast" natives
These were missed in the big conversion to fast natives in
c78646ed3f24bd915c7cfe4aca
gjs/context.c | 38 ++++++-------
modules/console.c | 15 +++---
modules/console.h | 4 +-
modules/dbus.c | 131 ++++++++++++++++++++++++----------------------
modules/gettext-native.c | 86 +++++++++++++++++-------------
modules/lang.c | 10 ++--
modules/mainloop.c | 68 ++++++++++++------------
7 files changed, 181 insertions(+), 171 deletions(-)
---
diff --git a/gjs/context.c b/gjs/context.c
index 7c0363e..34fdac8 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;
@@ -137,11 +136,10 @@ gjs_log(JSContext *context,
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;
@@ -243,11 +241,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)) {
@@ -262,11 +259,10 @@ gjs_print(JSContext *context,
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)) {
@@ -584,26 +580,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 7638125..bb930a7 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 07d457e..da78760 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 9702593..4295b8e 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,11 @@ 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)
{
+ jsval *argv = JS_ARGV(context, vp);
+ JSObject *obj = JS_THIS_OBJECT(context, vp);
DBusConnection *bus_connection;
DBusBusType bus_type;
@@ -957,17 +957,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 +992,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 +1113,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 +1125,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 +1190,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 +1202,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;
@@ -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;
@@ -1461,11 +1468,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 +1501,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 +1566,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 +1581,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 +1614,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);
@@ -1648,68 +1653,68 @@ define_bus_proto(JSContext *context,
if (!JS_DefineFunction(context, bus_proto_obj,
"call",
gjs_js_dbus_call,
- 8, GJS_MODULE_PROP_FLAGS))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE))
goto out;
/* Add the bus proto object inside the passed in module object */
@@ -1808,41 +1813,41 @@ gjs_js_define_dbus_stuff(JSContext *context,
if (!JS_DefineFunction(context, module_obj,
"signatureLength",
gjs_js_dbus_signature_length,
- 1, GJS_MODULE_PROP_FLAGS))
+ 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))
+ 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 e53ecdc..38f2bc0 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,
@@ -51,11 +50,10 @@ gjs_textdomain(JSContext *context,
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;
@@ -74,36 +72,38 @@ gjs_bindtextdomain(JSContext *context,
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 +112,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 +138,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 (retval)
+ JS_SET_RVAL(context, vp, retval);
g_free (msgid1);
g_free (msgid2);
return result;
@@ -144,17 +148,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 +168,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 +178,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 +195,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 +224,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;
}
@@ -228,49 +238,49 @@ gjs_define_gettext_stuff(JSContext *context,
if (!JS_DefineFunction(context, module_obj,
"textdomain",
gjs_textdomain,
- 1, GJS_MODULE_PROP_FLAGS))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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 1965fab..39cac7c 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;
}
@@ -60,7 +62,7 @@ gjs_define_lang_stuff(JSContext *context,
if (!JS_DefineFunction(context, module_obj,
"seal",
gjs_lang_seal,
- 1, GJS_MODULE_PROP_FLAGS))
+ 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 c58b58e..0c72bb8 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;
@@ -77,11 +76,10 @@ gjs_main_loop_quit(JSContext *context,
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 +178,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 +216,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 +259,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 +305,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 +327,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;
}
@@ -343,37 +343,37 @@ gjs_define_mainloop_stuff(JSContext *context,
if (!JS_DefineFunction(context, module_obj,
"run",
gjs_main_loop_run,
- 1, GJS_MODULE_PROP_FLAGS))
+ 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))
+ 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))
+ 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))
+ 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))
+ 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))
+ 1, GJS_MODULE_PROP_FLAGS | JSFUN_FAST_NATIVE))
return JS_FALSE;
return JS_TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]