[gjs/wip/xulrunner-2-rebase2: 5/9] Port more custom functions to be "fast" natives



commit 3be6a316b282ea4a281846ecb6798cb0317c7dfe
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 +---
 3 files changed, 25 insertions(+), 32 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
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]