[gjs/wip/xulrunner-2-rebase2: 9/9] function ctor



commit 172dc180257805cfcfdcb323661f572b5ab57e04
Author: Colin Walters <walters verbum org>
Date:   Mon Oct 25 16:21:31 2010 -0400

    function ctor

 gi/function.c |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/gi/function.c b/gi/function.c
index b32b859..85c3e4c 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -755,37 +755,43 @@ release:
     }
 }
 
-#ifdef HAVE_JS_FAST_CONSTRUCTORS
+#ifdef JSFUN_CONSTRUCTOR
 static JSBool
 function_call(JSContext *context,
               uintN      js_argc,
               jsval     *vp)
 {
     jsval *js_argv = JS_ARGV(context, vp);
-    jsval *obj = JS_THIS_OBJECT(context, vp);
+    JSObject *object = JS_THIS_OBJECT(context, vp);
+    JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(context, vp));
+    jsval retval;
 #else
 static JSBool
 function_call(JSContext *context,
-              JSObject  *obj, /* "this" object, not the function object */
+              JSObject  *object, /* "this" object, not the function object */
               uintN      js_argc,
               jsval     *js_argv,
-              jsval     *rval)
+              jsval     *retval)
 {
+    JSObject *callee = JSVAL_TO_OBJECT(JS_ARGV_CALLEE(js_argv));
 #endif
+    JSBool success;
     Function *priv;
-    JSObject *callee;
-
-    callee = JSVAL_TO_OBJECT(JS_ARGV_CALLEE(js_argv)); /* Callee is the Function object being called */
 
     priv = priv_from_js(context, callee);
     gjs_debug_marshal(GJS_DEBUG_GFUNCTION, "Call callee %p priv %p this obj %p %s", callee, priv,
                       obj, JS_GetTypeName(context,
-                                          JS_TypeOfValue(context, OBJECT_TO_JSVAL(obj))));
+                                          JS_TypeOfValue(context, OBJECT_TO_JSVAL(object))));
 
     if (priv == NULL)
         return JS_TRUE; /* we are the prototype, or have the wrong class */
 
-    return gjs_invoke_c_function(context, priv, obj, js_argc, js_argv, rval);
+
+    success = gjs_invoke_c_function(context, priv, object, js_argc, js_argv, retval);
+#ifdef JSFUN_CONSTRUCTOR
+    JS_SET_RVAL(context, vp, retval);
+#endif
+    return success;
 }
 
 /* If we set JSCLASS_CONSTRUCT_PROTOTYPE flag, then this is called on
@@ -796,24 +802,39 @@ function_call(JSContext *context,
  * identify the prototype as an object of our class with NULL private
  * data.
  */
+#ifdef JSFUN_CONSTRUCTOR
 static JSBool
 function_constructor(JSContext *context,
-                     JSObject  *obj,
+                     uintN      argc,
+                     jsval     *vp)
+{
+    JSObject *object;
+    if (!JS_IsConstructing_PossiblyWithGivenThisObject(context, vp, &object)) {
+        gjs_throw_constructor_error(context);
+        return JS_FALSE;
+    }
+    if (object == NULL)
+        object = JS_NewObject(context, &gjs_function_class, NULL, NULL);
+#else
+static JSBool
+function_constructor(JSContext *context,
+                     JSObject  *object,
                      uintN      argc,
                      jsval     *argv,
                      jsval     *retval)
 {
+#endif
     Function *priv;
 
     priv = g_slice_new0(Function);
 
     GJS_INC_COUNTER(function);
 
-    g_assert(priv_from_js(context, obj) == NULL);
-    JS_SetPrivate(context, obj, priv);
+    g_assert(priv_from_js(context, object) == NULL);
+    JS_SetPrivate(context, object, priv);
 
     gjs_debug_lifecycle(GJS_DEBUG_GFUNCTION,
-                        "function constructor, obj %p priv %p", obj, priv);
+                        "function constructor, obj %p priv %p", object, priv);
 
     return JS_TRUE;
 }



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