[gjs/wip/ptomato/mozjs45prep: 15/39] function: Use JS_GetFunctionProto()



commit 99bc633b2d3fb342560cdcd959e43bf2c69f4ec8
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Mar 27 19:29:07 2017 +0100

    function: Use JS_GetFunctionProto()
    
    Previously we got the global Function prototype in a roundabout way, but
    there is a function in the API for that now.

 gi/function.cpp |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 14e4c10..b86a4a9 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1671,22 +1671,13 @@ function_new(JSContext      *context,
 
     if (!JS_HasProperty(context, global, gjs_function_class.name, &found))
         return NULL;
+
     if (!found) {
         JSObject *prototype;
-        JS::RootedObject parent_proto(context);
-        JS::RootedValue v_native_function(context);
-
-        JS_GetProperty(context, global, "Function", &v_native_function);
-        JS::RootedObject native_function(context, &v_native_function.toObject());
-        /* We take advantage from that fact that Function.__proto__ is Function.prototype */
-        JS_GetPrototype(context, native_function, &parent_proto);
-
-        prototype = JS_InitClass(context, global,
-                                 /* parent prototype JSObject* for
-                                  * prototype; NULL for
-                                  * Object.prototype
-                                  */
-                                 parent_proto,
+        JS::RootedObject function_proto(context,
+                                        JS_GetFunctionPrototype(context, global));
+
+        prototype = JS_InitClass(context, global, function_proto,
                                  &gjs_function_class,
                                  /* constructor for instances (NULL for
                                   * none - just name the prototype like


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