[gjs/wip/ptomato/mozjs31prep: 3/4] js: Root misc fundamental, param, repo, union
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31prep: 3/4] js: Root misc fundamental, param, repo, union
- Date: Thu, 3 Nov 2016 22:21:53 +0000 (UTC)
commit c9b686db5c0c315efe6eb11b72916e01e8c56aa8
Author: Philip Chimento <philip endlessm com>
Date: Wed Nov 2 19:22:49 2016 -0700
js: Root misc fundamental, param, repo, union
This converts everything in fundamental.cpp, param.cpp, repo.cpp, and
union.cpp to use exact rooting, that would otherwise have caused a
compile error in mozjs31.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
gi/fundamental.cpp | 30 +++++++++++++++---------------
gi/param.cpp | 17 +++++++----------
gi/repo.cpp | 43 +++++++++++++++++++++----------------------
gi/union.cpp | 13 ++++++-------
4 files changed, 49 insertions(+), 54 deletions(-)
---
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index f2e6a99..d2a4cce 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -130,8 +130,8 @@ _fundamental_lookup_object(void *native_object)
/**/
static inline Fundamental *
-proto_priv_from_js(JSContext *context,
- JSObject *obj)
+proto_priv_from_js(JSContext *context,
+ JS::HandleObject obj)
{
JS::RootedObject proto(context);
JS_GetPrototype(context, obj, proto.address());
@@ -403,9 +403,9 @@ fundamental_invoke_constructor(FundamentalInstance *priv,
}
JS::RootedObject constructor(context);
+ JS::RootedId constructor_name(context, priv->prototype->constructor_name);
if (!gjs_object_require_property_value(context, js_constructor, NULL,
- priv->prototype->constructor_name,
- &constructor)) {
+ constructor_name, &constructor)) {
gjs_throw (context,
"Couldn't find a constructor for type %s.%s",
g_base_info_get_namespace((GIBaseInfo*) priv->prototype->info),
@@ -602,7 +602,9 @@ gjs_lookup_fundamental_prototype(JSContext *context,
/* In case we're looking for a private type, and we don't find it,
we need to define it first.
*/
- gjs_define_fundamental_class(context, in_object, info, &constructor, NULL);
+ JS::RootedObject ignored(context);
+ gjs_define_fundamental_class(context, in_object, info, &constructor,
+ &ignored);
} else {
if (G_UNLIKELY (!value.isObject()))
return NULL;
@@ -646,7 +648,6 @@ gjs_define_fundamental_class(JSContext *context,
JS::MutableHandleObject prototype)
{
const char *constructor_name;
- JS::Value value;
jsid js_constructor_name = JSID_VOID;
JS::RootedObject parent_proto(context);
Fundamental *priv;
@@ -730,7 +731,8 @@ gjs_define_fundamental_class(JSContext *context,
gjs_object_define_static_methods(context, constructor, gtype, info);
- value = JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype));
+ JS::RootedValue value(context,
+ JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype)));
JS_DefineProperty(context, constructor, "$gtype", value,
NULL, NULL, JSPROP_PERMANENT);
@@ -742,8 +744,6 @@ gjs_object_from_g_fundamental(JSContext *context,
GIObjectInfo *info,
void *gfundamental)
{
- JSObject *proto;
-
if (gfundamental == NULL)
return NULL;
@@ -757,12 +757,12 @@ gjs_object_from_g_fundamental(JSContext *context,
g_base_info_get_name((GIBaseInfo *) info),
gfundamental);
- proto = gjs_lookup_fundamental_prototype_from_gtype(context,
- G_TYPE_FROM_INSTANCE(gfundamental));
-
- object = JS_NewObjectWithGivenProto(context,
- JS_GetClass(proto), proto,
- gjs_get_import_global(context));
+ JS::RootedObject proto(context,
+ gjs_lookup_fundamental_prototype_from_gtype(context,
+ G_TYPE_FROM_INSTANCE(gfundamental)));
+ JS::RootedObject global(context, gjs_get_import_global(context));
+ object = JS_NewObjectWithGivenProto(context, JS_GetClass(proto), proto,
+ global);
if (object == NULL)
goto out;
diff --git a/gi/param.cpp b/gi/param.cpp
index c0b75eb..1e1d0fa 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -182,10 +182,9 @@ static JSFunctionSpec gjs_param_constructor_funcs[] = {
static JSObject*
gjs_lookup_param_prototype(JSContext *context)
{
- JSObject *in_object;
-
JS::RootedId gobject_name(context, gjs_intern_string_to_id(context, "GObject"));
- in_object = gjs_lookup_namespace_object_by_name(context, gobject_name);
+ JS::RootedObject in_object(context,
+ gjs_lookup_namespace_object_by_name(context, gobject_name));
if (G_UNLIKELY (!in_object))
return NULL;
@@ -215,7 +214,6 @@ gjs_define_param_class(JSContext *context,
JS::HandleObject in_object)
{
const char *constructor_name;
- JS::Value value;
JS::RootedObject prototype(context), constructor(context);
GIObjectInfo *info;
@@ -240,7 +238,8 @@ gjs_define_param_class(JSContext *context,
g_error("Can't init class %s", constructor_name);
}
- value = JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, G_TYPE_PARAM));
+ JS::RootedValue value(context,
+ JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, G_TYPE_PARAM)));
JS_DefineProperty(context, constructor, "$gtype", value,
NULL, NULL, JSPROP_PERMANENT);
@@ -258,7 +257,6 @@ gjs_param_from_g_param(JSContext *context,
GParamSpec *gparam)
{
JSObject *obj;
- JSObject *proto;
Param *priv;
if (gparam == NULL)
@@ -270,11 +268,10 @@ gjs_param_from_g_param(JSContext *context,
gparam->name,
g_type_name(gparam->owner_type));
- proto = gjs_lookup_param_prototype(context);
+ JS::RootedObject proto(context, gjs_lookup_param_prototype(context));
+ JS::RootedObject global(context, gjs_get_import_global(context));
- obj = JS_NewObjectWithGivenProto(context,
- JS_GetClass(proto), proto,
- gjs_get_import_global (context));
+ obj = JS_NewObjectWithGivenProto(context, JS_GetClass(proto), proto, global);
GJS_INC_COUNTER(param);
priv = g_slice_new0(Param);
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 1706f35..09ef1f0 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -90,8 +90,6 @@ resolve_namespace_object(JSContext *context,
GIRepository *repo;
GError *error;
char *version;
- JSObject *override;
- JS::Value result;
JSAutoRequest ar(context);
@@ -122,19 +120,21 @@ resolve_namespace_object(JSContext *context,
/* Define the property early, to avoid reentrancy issues if
the override module looks for namespaces that import this */
- if (!JS_DefineProperty(context, repo_obj,
- ns_name, JS::ObjectValue(*gi_namespace),
+ JS::RootedValue v_namespace(context, JS::ObjectValue(*gi_namespace));
+ if (!JS_DefineProperty(context, repo_obj, ns_name, v_namespace,
NULL, NULL,
GJS_MODULE_PROP_FLAGS))
g_error("no memory to define ns property");
- override = lookup_override_function(context, ns_id);
- if (override && !JS_CallFunctionValue (context,
- gi_namespace, /* thisp */
- JS::ObjectValue(*override), /* callee */
- 0, /* argc */
- NULL, /* argv */
- &result))
+ JS::RootedValue override(context,
+ JS::ObjectOrNullValue(lookup_override_function(context, ns_id)));
+ JS::RootedValue result(context);
+ if (!override.isNull() &&
+ !JS_CallFunctionValue (context, gi_namespace, /* thisp */
+ override, /* callee */
+ 0, /* argc */
+ NULL, /* argv */
+ result.address()))
return false;
gjs_debug(GJS_DEBUG_GNAMESPACE,
@@ -244,13 +244,12 @@ static JSObject*
repo_new(JSContext *context)
{
Repo *priv;
- JSObject *global;
JSObject *versions;
JSObject *private_ns;
JSBool found;
jsid versions_name, private_ns_name;
- global = gjs_get_import_global(context);
+ JS::RootedObject global(context, gjs_get_import_global(context));
if (!JS_HasProperty(context, global, gjs_repo_class.name, &found))
return NULL;
@@ -320,8 +319,8 @@ repo_new(JSContext *context)
* gobject-introspection does not yet search a path properly.
*/
{
- JS::Value value;
- JS_GetProperty(context, repo, "GLib", &value);
+ JS::RootedValue value(context);
+ JS_GetProperty(context, repo, "GLib", value.address());
}
return repo;
@@ -337,9 +336,9 @@ gjs_define_repo(JSContext *cx,
}
static bool
-gjs_define_constant(JSContext *context,
- JSObject *in_object,
- GIConstantInfo *info)
+gjs_define_constant(JSContext *context,
+ JS::HandleObject in_object,
+ GIConstantInfo *info)
{
JS::RootedValue value(context);
GArgument garg = { 0, };
@@ -745,17 +744,17 @@ JSObject *
gjs_lookup_generic_constructor(JSContext *context,
GIBaseInfo *info)
{
- JSObject *in_object;
const char *constructor_name;
- JS::Value value;
- in_object = gjs_lookup_namespace_object(context, (GIBaseInfo*) info);
+ JS::RootedObject in_object(context,
+ gjs_lookup_namespace_object(context, (GIBaseInfo*) info));
constructor_name = g_base_info_get_name((GIBaseInfo*) info);
if (G_UNLIKELY (!in_object))
return NULL;
- if (!JS_GetProperty(context, in_object, constructor_name, &value))
+ JS::RootedValue value(context);
+ if (!JS_GetProperty(context, in_object, constructor_name, value.address()))
return NULL;
if (G_UNLIKELY (!value.isObject()))
diff --git a/gi/union.cpp b/gi/union.cpp
index a0016b4..2229d6d 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -325,7 +325,6 @@ gjs_define_union_class(JSContext *context,
GIUnionInfo *info)
{
const char *constructor_name;
- JS::Value value;
Union *priv;
GType gtype;
JS::RootedObject prototype(context), constructor(context);
@@ -376,7 +375,8 @@ gjs_define_union_class(JSContext *context,
constructor_name, prototype.get(), JS_GetClass(prototype),
in_object.get());
- value = JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype));
+ JS::RootedValue value(context,
+ JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype)));
JS_DefineProperty(context, constructor, "$gtype", value,
NULL, NULL, JSPROP_PERMANENT);
@@ -389,7 +389,6 @@ gjs_union_from_c_union(JSContext *context,
void *gboxed)
{
JSObject *obj;
- JSObject *proto;
Union *priv;
GType gtype;
@@ -409,11 +408,11 @@ gjs_union_from_c_union(JSContext *context,
"Wrapping union %s %p with JSObject",
g_base_info_get_name((GIBaseInfo *)info), gboxed);
- proto = gjs_lookup_generic_prototype(context, (GIUnionInfo*) info);
+ JS::RootedObject proto(context,
+ gjs_lookup_generic_prototype(context, (GIUnionInfo*) info));
+ JS::RootedObject global(context, gjs_get_import_global(context));
- obj = JS_NewObjectWithGivenProto(context,
- JS_GetClass(proto), proto,
- gjs_get_import_global (context));
+ obj = JS_NewObjectWithGivenProto(context, JS_GetClass(proto), proto, global);
GJS_INC_COUNTER(boxed);
priv = g_slice_new0(Union);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]