Skip to content

Commit b5e467d

Browse files
committed
Convert many native modules to JS modules
Less C code and more JS + introspection means more maintenability and fewer bugs. https://bugzilla.gnome.org/show_bug.cgi?id=692025
1 parent 3c6c3e0 commit b5e467d

File tree

13 files changed

+161
-943
lines changed

13 files changed

+161
-943
lines changed

Makefile-modules.am

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ dist_gjsoverride_DATA = \
1111
dist_gjsjs_DATA += \
1212
modules/gettext.js \
1313
modules/lang.js \
14+
modules/mainloop.js \
1415
modules/jsUnit.js \
1516
modules/signals.js \
1617
modules/promise.js \
1718
modules/format.js
1819

19-
gjsnative_LTLIBRARIES += console.la debugger.la langNative.la mainloop.la gettextNative.la system.la formatNative.la
20+
gjsnative_LTLIBRARIES += console.la langNative.la system.la
2021

2122
if ENABLE_CAIRO
2223
dist_gjsjs_DATA += \
@@ -48,30 +49,6 @@ langNative_la_SOURCES = \
4849
modules/lang.h \
4950
modules/lang.c
5051

51-
mainloop_la_CFLAGS = \
52-
$(JS_NATIVE_MODULE_CFLAGS)
53-
mainloop_la_LIBADD = \
54-
libgjs.la \
55-
$(JS_NATIVE_MODULE_LIBADD)
56-
mainloop_la_LDFLAGS = \
57-
$(JS_NATIVE_MODULE_LDFLAGS)
58-
59-
mainloop_la_SOURCES = \
60-
modules/mainloop.h \
61-
modules/mainloop.c
62-
63-
gettextNative_la_CFLAGS = \
64-
$(JS_NATIVE_MODULE_CFLAGS)
65-
gettextNative_la_LIBADD = \
66-
libgjs.la \
67-
$(JS_NATIVE_MODULE_LIBADD)
68-
gettextNative_la_LDFLAGS = \
69-
$(JS_NATIVE_MODULE_LDFLAGS)
70-
71-
gettextNative_la_SOURCES = \
72-
modules/gettext-native.h \
73-
modules/gettext-native.c
74-
7552
cairoNative_la_CFLAGS = \
7653
$(JS_NATIVE_MODULE_CFLAGS) \
7754
$(GJS_CAIRO_CFLAGS) \
@@ -123,27 +100,3 @@ console_la_LDFLAGS = \
123100
console_la_SOURCES = \
124101
modules/console.h \
125102
modules/console.c
126-
127-
debugger_la_CFLAGS = \
128-
$(JS_NATIVE_MODULE_CFLAGS)
129-
debugger_la_LIBADD = \
130-
libgjs.la \
131-
$(JS_NATIVE_MODULE_LIBADD)
132-
debugger_la_LDFLAGS = \
133-
$(JS_NATIVE_MODULE_LDFLAGS)
134-
135-
debugger_la_SOURCES = \
136-
modules/debugger.h \
137-
modules/debugger.c
138-
139-
formatNative_la_CFLAGS = \
140-
$(JS_NATIVE_MODULE_CFLAGS)
141-
formatNative_la_LIBADD = \
142-
libgjs.la \
143-
$(JS_NATIVE_MODULE_LIBADD)
144-
formatNative_la_LDFLAGS = \
145-
$(JS_NATIVE_MODULE_LDFLAGS)
146-
147-
formatNative_la_SOURCES = \
148-
modules/format.h \
149-
modules/format.c

Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ libgjs_la_SOURCES += \
149149
# Also, these files used to be a separate library
150150
libgjs_private_source_files = \
151151
libgjs-private/gjs-gdbus-wrapper.c \
152-
libgjs-private/gjs-gdbus-wrapper.h
152+
libgjs-private/gjs-gdbus-wrapper.h \
153+
libgjs-private/gjs-util.c \
154+
libgjs-private/gjs-util.h
153155
libgjs_la_SOURCES += $(libgjs_private_source_files)
154156

155157
GjsPrivate-1.0.gir: libgjs.la

modules/debugger.h renamed to libgjs-private/gjs-util.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2-
/*
3-
* Copyright (c) 2008 litl, LLC
2+
/* Copyright 2012 Giovanni Campagna <[email protected]>
43
*
54
* Permission is hereby granted, free of charge, to any person obtaining a copy
65
* of this software and associated documentation files (the "Software"), to
@@ -21,18 +20,31 @@
2120
* IN THE SOFTWARE.
2221
*/
2322

24-
#ifndef __GJS_DEBUGGER_H__
25-
#define __GJS_DEBUGGER_H__
26-
2723
#include <config.h>
24+
#include <string.h>
25+
2826
#include <glib.h>
29-
#include "gjs/jsapi-util.h"
27+
#include <glib/gi18n.h>
3028

31-
G_BEGIN_DECLS
29+
#include "gjs-util.h"
3230

33-
JSBool gjs_define_debugger_stuff (JSContext *context,
34-
JSObject *in_object);
31+
char *
32+
gjs_format_int_alternative_output(int n)
33+
{
34+
return g_strdup_printf("%Id", n);
35+
}
3536

36-
G_END_DECLS
37+
void
38+
gjs_textdomain(const char *domain)
39+
{
40+
textdomain(domain);
41+
}
3742

38-
#endif /* __GJS_DEBUGGER_H__ */
43+
void
44+
gjs_bindtextdomain(const char *domain,
45+
const char *location)
46+
{
47+
bindtextdomain(domain, location);
48+
/* Always use UTF-8; we assume it internally here */
49+
bind_textdomain_codeset(domain, "UTF-8");
50+
}

modules/mainloop.h renamed to libgjs-private/gjs-util.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2-
/*
3-
* Copyright (c) 2008 litl, LLC
2+
/* Copyright 2012 Giovanni Campagna <[email protected]>
43
*
54
* Permission is hereby granted, free of charge, to any person obtaining a copy
65
* of this software and associated documentation files (the "Software"), to
@@ -21,18 +20,21 @@
2120
* IN THE SOFTWARE.
2221
*/
2322

24-
#ifndef __GJS_MAINLOOP_H__
25-
#define __GJS_MAINLOOP_H__
23+
#ifndef __GJS_PRIVATE_UTIL_H__
24+
#define __GJS_PRIVATE_UTIL_H__
2625

27-
#include <config.h>
2826
#include <glib.h>
29-
#include "gjs/jsapi-util.h"
3027

3128
G_BEGIN_DECLS
3229

33-
JSBool gjs_define_mainloop_stuff (JSContext *context,
34-
JSObject *in_object);
30+
/* For imports.format */
31+
char * gjs_format_int_alternative_output (int n);
32+
33+
/* For imports.gettext */
34+
void gjs_textdomain (const char *domain);
35+
void gjs_bindtextdomain (const char *domain,
36+
const char *location);
3537

3638
G_END_DECLS
3739

38-
#endif /* __GJS_MAINLOOP_H__ */
40+
#endif

modules/debugger.c

Lines changed: 0 additions & 52 deletions
This file was deleted.

modules/format.c

Lines changed: 0 additions & 67 deletions
This file was deleted.

modules/format.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

modules/format.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
22

3-
const FormatNative = imports.formatNative;
3+
const GjsPrivate = imports.gi.GjsPrivate;
44

55
function vprintf(str, args) {
66
let i = 0;
@@ -33,7 +33,7 @@ function vprintf(str, args) {
3333
case 'd':
3434
let intV = parseInt(args[i++]);
3535
if (hasAlternativeIntFlag)
36-
s = FormatNative.format_int_alternative_output(intV);
36+
s = GjsPrivate.format_int_alternative_output(intV);
3737
else
3838
s = intV.toString();
3939
break;

0 commit comments

Comments
 (0)