[gjs] ns: Allow getting the name of a repository
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] ns: Allow getting the name of a repository
- Date: Wed, 28 Oct 2015 00:23:57 +0000 (UTC)
commit 4a74c955e4854833cd4466afe0544b1b93e993ac
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Sep 20 07:03:02 2012 -0300
ns: Allow getting the name of a repository
https://bugzilla.gnome.org/show_bug.cgi?id=685413
Makefile-insttest.am | 1 +
gi/ns.cpp | 25 +++++++++++++++++++++++++
installed-tests/js/testNamespace.js | 8 ++++++++
3 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-insttest.am b/Makefile-insttest.am
index d448871..08c86e5 100644
--- a/Makefile-insttest.am
+++ b/Makefile-insttest.am
@@ -142,6 +142,7 @@ dist_jstests_DATA += \
installed-tests/js/testLocale.js \
installed-tests/js/testMainloop.js \
installed-tests/js/testMetaClass.js \
+ installed-tests/js/testNamespace.js \
installed-tests/js/testParamSpec.js \
installed-tests/js/testReflectObject.js \
installed-tests/js/testSignals.js \
diff --git a/gi/ns.cpp b/gi/ns.cpp
index a7ae813..02bd6ca 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -124,6 +124,30 @@ ns_new_resolve(JSContext *context,
return ret;
}
+static JSBool
+get_name (JSContext *context,
+ JS::HandleObject obj,
+ JS::HandleId id,
+ jsval *vp)
+{
+ Ns *priv;
+ jsval retval;
+ JSBool ret = JS_FALSE;
+
+ priv = priv_from_js(context, obj);
+
+ if (priv == NULL)
+ goto out;
+
+ if (gjs_string_from_utf8(context, priv->gi_namespace, -1, &retval)) {
+ *vp = retval;
+ ret = JS_TRUE;
+ }
+
+ out:
+ return ret;
+}
+
GJS_NATIVE_CONSTRUCTOR_DEFINE_ABSTRACT(ns)
static void
@@ -165,6 +189,7 @@ struct JSClass gjs_ns_class = {
};
JSPropertySpec gjs_ns_proto_props[] = {
+ { "__name__", 0, GJS_MODULE_PROP_FLAGS | JSPROP_READONLY, (JSPropertyOp)get_name, NULL },
{ NULL }
};
diff --git a/installed-tests/js/testNamespace.js b/installed-tests/js/testNamespace.js
new file mode 100644
index 0000000..bcca986
--- /dev/null
+++ b/installed-tests/js/testNamespace.js
@@ -0,0 +1,8 @@
+const JSUnit = imports.jsUnit;
+const Everything = imports.gi.Regress;
+
+function testName() {
+ JSUnit.assertEquals(Everything.__name__, "Regress");
+}
+
+JSUnit.gjstestRun(this, JSUnit.setUp, JSUnit.tearDown);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]