[seed] Add the native gjs module dummy "system" for compatibility
- From: Alan Knowles <alank src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seed] Add the native gjs module dummy "system" for compatibility
- Date: Mon, 21 Dec 2015 02:47:23 +0000 (UTC)
commit 53b6d3841ce4975e3f353eda68e405799f40dcc1
Author: Peter Rustler <peter rustler basyskom com>
Date: Thu Dec 17 15:23:05 2015 +0000
Add the native gjs module dummy "system" for compatibility
This is just a dummy. The functions should be implemented.
It shows how to implement native gjs compatibility modules.
It has the flaw, that the js compatibility modules do not recognice
native gjs compatibility modules, this should be solved.
I get this running gjs code:
** (seed:27750): CRITICAL **: Line 49 in
/usr/local/share/seed-gtk4/gjs/package.js:
TypeError undefined is not an object
(evaluating 'System.programInvocationName')
It do not harm to integrate this
patch, even when it is just a dummy.
Makefile.am | 11 ++
configure.ac | 1 +
modules/gjs/Makefile.am | 2 +
modules/gjs/system/Makefile.am | 28 ++++
modules/gjs/system/seed-system.c | 267 ++++++++++++++++++++++++++++++++++++++
5 files changed, 309 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 30613d0..c7be24b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -56,10 +56,21 @@ if PROFILE_MODULES
cd modules/sqlite/.libs ; gcov *.c
endif
+#gjs compat
+if PROFILE_MODULES
+if SEED_ENABLE_GJSCOMPAT
+ cp modules/gjs/system/*.c modules/system/.libs/
+endif
+endif
+
profile-gui: profile
if PROFILE_MODULES
+if SEED_ENABLE_GJSCOMPAT
+ lcov --directory libseed/.libs --directory modules/cairo/.libs --directory modules/canvas/.libs
--directory modules/dbus/.libs --directory modules/example/.libs --directory modules/system/.libs --directory
modules/gettext/.libs --directory modules/gtkbuilder/.libs --directory modules/libxml/.libs --directory
modules/os/.libs --directory modules/readline/.libs --directory modules/sandbox/.libs --directory
modules/sqlite/.libs --capture --output-file seed.info
+else
lcov --directory libseed/.libs --directory modules/cairo/.libs --directory modules/canvas/.libs
--directory modules/dbus/.libs --directory modules/example/.libs --directory modules/gettext/.libs
--directory modules/gtkbuilder/.libs --directory modules/libxml/.libs --directory modules/os/.libs
--directory modules/readline/.libs --directory modules/sandbox/.libs --directory modules/sqlite/.libs
--capture --output-file seed.info
+endif
else
lcov --directory libseed/.libs --capture --output-file seed.info
endif
diff --git a/configure.ac b/configure.ac
index 7985583..a82027d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -520,6 +520,7 @@ modules/mpfr/Makefile
modules/ffi/Makefile
modules/DynamicObject/Makefile
+modules/gjs/system/Makefile
extensions/gjs/Makefile
modules/gjs/Makefile
diff --git a/modules/gjs/Makefile.am b/modules/gjs/Makefile.am
index b83f7ee..a2f2e0b 100644
--- a/modules/gjs/Makefile.am
+++ b/modules/gjs/Makefile.am
@@ -1,5 +1,7 @@
if SEED_ENABLE_GJSCOMPAT
+SUBDIRS = system
+
EXTRA_DIST= cairo.js coverage.js format.js gettext.js jsUnit.js lang.js mainloop.js package.js signals.js
gjs_extensiondir=$(datadir)/seed SEED_GTK_VERSION@/gjs
diff --git a/modules/gjs/system/Makefile.am b/modules/gjs/system/Makefile.am
new file mode 100644
index 0000000..22f63af
--- /dev/null
+++ b/modules/gjs/system/Makefile.am
@@ -0,0 +1,28 @@
+if SEED_ENABLE_GJSCOMPAT
+
+seedlibdir = ${libdir}/seed SEED_GTK_VERSION@/gjs
+
+seedlib_LTLIBRARIES = \
+ libseed_system.la
+
+libseed_system_la_SOURCES = \
+ seed-system.c
+
+AM_CPPFLAGS = \
+ -I top_srcdir@/libseed/ \
+ $(GOBJECT_INTROSPECTION_CFLAGS) \
+ $(SEED_DEBUG_CFLAGS) \
+ $(SEED_PROFILE_CFLAGS)
+
+libseed_system_la_LDFLAGS = \
+ -module -avoid-version \
+ $(GOBJECT_INTROSPECTION_LDFLAGS)
+
+libseed_system_la_LIBADD = \
+ $(top_builddir)/libseed/libseed SEED_GTK_VERSION@.la \
+ $(SEED_PROFILE_LIBS)
+
+endif
+
+
+
diff --git a/modules/gjs/system/seed-system.c b/modules/gjs/system/seed-system.c
new file mode 100644
index 0000000..d80e14f
--- /dev/null
+++ b/modules/gjs/system/seed-system.c
@@ -0,0 +1,267 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (c) 2008 litl, LLC
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <glib.h>
+#include <seed-module.h>
+#include <config.h>
+
+#define GJS_COMPAT_VERSION (1 * 100 + 40) * 100 + 0
+
+static SeedValue
+gjs_address_of (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[], SeedException * exception)
+{
+/*static SeedValue
+gjs_address_of(SeedContext context,
+ unsigned argc,
+ SeedValue *vp)
+{
+ JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
+ SeedObject *target_obj;
+ bool ret;
+ char *pointer_string;
+ SeedValue retval;
+
+ if (!gjs_parse_call_args(context, "addressOf", "o", argv, "object", &target_obj))
+ return FALSE;
+
+ pointer_string = g_strdup_printf("%p", target_obj);
+
+ ret = gjs_string_from_utf8(context, pointer_string, -1, &retval);
+ g_free(pointer_string);
+
+ if (ret)
+ argv.rval().set(retval);
+
+ return ret;*/
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static SeedValue
+gjs_refcount (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[], SeedException * exception)
+{
+/*static SeedValue
+gjs_refcount(SeedContext context,
+ unsigned argc,
+ SeedValue *vp)
+{
+ JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
+ SeedValue retval;
+ SeedObject *target_obj;
+ GObject *obj;
+
+ if (!gjs_parse_call_args(context, "refcount", "o", argv, "object", &target_obj))
+ return FALSE;
+
+ if (!gjs_typecheck_object(context, target_obj,
+ G_TYPE_OBJECT, TRUE))
+ return FALSE;
+
+ obj = gjs_g_object_from_object(context, target_obj);
+ if (obj == NULL)
+ return FALSE;
+
+ retval = INT_TO_JSVAL(obj->ref_count);
+ argv.rval().set(retval);
+ return TRUE;*/
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static SeedValue
+gjs_breakpoint (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[], SeedException * exception)
+{
+/*static SeedValue
+gjs_breakpoint(SeedContext context,
+ unsigned argc,
+ SeedValue *vp)
+{
+ JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
+ if (!gjs_parse_call_args(context, "breakpoint", "", argv))
+ return FALSE;
+ G_BREAKPOINT();
+ argv.rval().set(JSVAL_VOID);
+ return TRUE;*/
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static SeedValue
+gjs_gc (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[], SeedException * exception)
+{
+/*static SeedValue
+gjs_gc(SeedContext context,
+ unsigned argc,
+ SeedValue *vp)
+{
+ JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
+ if (!gjs_parse_call_args(context, "gc", "", argv))
+ return FALSE;
+ JS_GC(JS_GetRuntime(context));
+ argv.rval().set(JSVAL_VOID);
+ return TRUE;*/
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static SeedValue
+gjs_exit (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[], SeedException * exception)
+{
+/*static SeedValue
+gjs_exit(SeedContext context,
+ unsigned argc,
+ SeedValue *vp)
+{
+ JS::CallArgs argv = JS::CallArgsFromVp (argc, vp);
+ gint32 ecode;
+ if (!gjs_parse_call_args(context, "exit", "i", argv, "ecode", &ecode))
+ return FALSE;
+ exit(ecode);
+ return TRUE;*/
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static SeedValue
+gjs_clear_date_caches (SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[], SeedException * exception)
+{
+/*static SeedValue
+gjs_clear_date_caches(SeedContext context,
+ unsigned argc,
+ SeedValue *vp)
+{
+ JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
+ JS_BeginRequest(context);
+
+ // Workaround for a bug in SpiderMonkey where tzset is not called before
+ // localtime_r, see https://bugzilla.mozilla.org/show_bug.cgi?id=1004706
+ tzset();
+
+ JS_ClearDateCaches(context);
+ JS_EndRequest(context);
+
+ rec.rval().set(JSVAL_VOID);
+ return TRUE;*/
+ return seed_value_from_boolean (ctx, TRUE, exception);
+}
+
+static seed_static_function module_funcs[] = {
+ {"addressOf", gjs_address_of, 0},
+ {"refcount", gjs_refcount, 0},
+ {"breakpoint", gjs_breakpoint, 0},
+ {"gc", gjs_gc, 0},
+ {"exit", gjs_exit, 0},
+ {"clearDateCaches", gjs_clear_date_caches, 0},
+ {0, 0, 0}
+};
+
+static seed_class_definition system_def = {
+ 0, /* Version, always 0 */
+ SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE, /* JSClassAttributes */
+ "System", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ module_funcs, /* Static Functions */
+ NULL,
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
+};
+
+SeedObject
+gjs_compat_define_system_stuff(SeedEngine *eng)
+{
+ SeedContext context = eng->context;
+ char *program_name = "gnome-weather";
+ SeedObject module;
+ gboolean ret;
+
+ module = seed_make_object(context, seed_create_class(&system_def), NULL);
+ g_print("Module: %p\n", module);
+
+ SeedValue seed = seed_object_get_property(context, eng->global, "Seed");
+ SeedValue argv = seed_object_get_property(context, seed, "argv");
+
+ g_print("Seed: %p\n", seed);
+ g_print("Argv: %p\n", argv);
+
+ //gjs_context = (GjsContext*) JS_GetContextPrivate(context);
+ //g_object_get(gjs_context,
+ // "program-name", &program_name,
+ // NULL);
+
+ //if (!gjs_string_from_utf8(context, program_name,
+ // -1, &value))
+ // goto out;
+
+ /* The name is modeled after program_invocation_name,
+ part of the glibc */
+ ret = seed_object_set_property (context, module, "programInvocationName",
+ (SeedValue)seed_value_from_string (context, program_name, NULL));
+ g_print("Module: %d\n", ret);
+
+ ret = seed_object_set_property (context, module, "version",
+ (SeedValue)seed_value_from_int (context, GJS_COMPAT_VERSION, NULL));
+ g_print("Module: %d\n", ret);
+
+ return module;
+}
+
+SeedObject
+seed_module_init(SeedEngine * eng)
+{
+ return gjs_compat_define_system_stuff(eng);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]