summaryrefslogtreecommitdiff
path: root/libseed
diff options
context:
space:
mode:
Diffstat (limited to 'libseed')
-rw-r--r--libseed/Makefile.am11
-rw-r--r--libseed/Makefile.in276
-rw-r--r--libseed/seed-api.c499
-rw-r--r--libseed/seed-builtins.c911
-rw-r--r--libseed/seed-builtins.h7
-rw-r--r--libseed/seed-closure.c748
-rw-r--r--libseed/seed-closure.h83
-rw-r--r--libseed/seed-debug.h54
-rw-r--r--libseed/seed-engine.c3059
-rw-r--r--libseed/seed-engine.h60
-rw-r--r--libseed/seed-exceptions.c206
-rw-r--r--libseed/seed-exceptions.h27
-rw-r--r--libseed/seed-gtype.c1658
-rw-r--r--libseed/seed-gtype.h2
-rw-r--r--libseed/seed-importer.c1631
-rw-r--r--libseed/seed-importer.h12
-rw-r--r--libseed/seed-module.h27
-rw-r--r--libseed/seed-path.h2
-rw-r--r--libseed/seed-private.h9
-rw-r--r--libseed/seed-signals.c638
-rw-r--r--libseed/seed-signals.h45
-rw-r--r--libseed/seed-structs.c1179
-rw-r--r--libseed/seed-structs.h63
-rw-r--r--libseed/seed-types.c3789
-rw-r--r--libseed/seed-types.h334
-rw-r--r--libseed/seed.h822
26 files changed, 8266 insertions, 7886 deletions
diff --git a/libseed/Makefile.am b/libseed/Makefile.am
index 5ff186b..9e056d2 100644
--- a/libseed/Makefile.am
+++ b/libseed/Makefile.am
@@ -25,18 +25,24 @@ libseed@SEED_GTK_VERSION@_la_SOURCES = \
seed-importer.h \
seed-path.h
+nodist_libseed@SEED_GTK_VERSION@_la_SOURCES = \
+ ../jsextensions/libseed-resources.c
+
+
libseed@SEED_GTK_VERSION@_la_CFLAGS = \
-Wall \
$(GOBJECT_INTROSPECTION_CFLAGS) \
$(WEBKIT_CFLAGS) \
$(SEED_OSX_CFLAGS) \
$(SEED_DEBUG_CFLAGS) \
+ $(SEED_GJSCOMPAT_CFLAGS) \
$(SEED_PROFILE_CFLAGS) \
$(FFI_CFLAGS) \
-DGOBJECT_INTROSPECTION_VERSION=$(GOBJECT_INTROSPECTION_VERSION)
libseed@SEED_GTK_VERSION@_la_LDFLAGS = \
- $(FFI_LDFLAGS)
+ $(FFI_LDFLAGS) \
+ -export-symbols-regex "^seed_.*"
libseed@SEED_GTK_VERSION@_la_LIBADD = \
$(GOBJECT_INTROSPECTION_LIBS) \
@@ -44,7 +50,8 @@ libseed@SEED_GTK_VERSION@_la_LIBADD = \
$(SEED_PROFILE_LIBS) \
$(SEED_OSX_LIBS) \
$(GIO_LIBS) \
- $(FFI_LIBS) -ldl
+ $(GMODULE_LIBS) \
+ $(FFI_LIBS) $(LIBDL)
seedheaders_HEADERS = seed.h seed-debug.h seed-module.h
diff --git a/libseed/Makefile.in b/libseed/Makefile.in
index e12fbcf..d6d5cb3 100644
--- a/libseed/Makefile.in
+++ b/libseed/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# Makefile.in generated by automake 1.15 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -17,23 +16,61 @@
VPATH = @srcdir@
-am__make_dryrun = \
- { \
- am__dry=no; \
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
- echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
- | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
- *) \
- for am__flg in $$MAKEFLAGS; do \
- case $$am__flg in \
- *=*|--*) ;; \
- *n*) am__dry=yes; break;; \
- esac; \
- done;; \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
- test $$am__dry = yes; \
- }
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -53,13 +90,17 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = libseed
-DIST_COMMON = $(seedheaders_HEADERS) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in $(srcdir)/seed-path.h.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/m4/gtk-doc.m4 \
+ $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+DIST_COMMON = $(srcdir)/Makefile.am $(seedheaders_HEADERS) \
+ $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES = seed-path.h
CONFIG_CLEAN_VPATH_FILES =
@@ -95,6 +136,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libseed@SEED_GTK_VERSION@_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_libseed@SEED_GTK_VERSION@_la_OBJECTS = \
libseed@SEED_GTK_VERSION@_la-seed-closure.lo \
@@ -107,15 +149,31 @@ am_libseed@SEED_GTK_VERSION@_la_OBJECTS = \
libseed@SEED_GTK_VERSION@_la-seed-gtype.lo \
libseed@SEED_GTK_VERSION@_la-seed-types.lo \
libseed@SEED_GTK_VERSION@_la-seed-importer.lo
+nodist_libseed@SEED_GTK_VERSION@_la_OBJECTS = \
+ libseed@SEED_GTK_VERSION@_la-libseed-resources.lo
libseed@SEED_GTK_VERSION@_la_OBJECTS = \
- $(am_libseed@SEED_GTK_VERSION@_la_OBJECTS)
+ $(am_libseed@SEED_GTK_VERSION@_la_OBJECTS) \
+ $(nodist_libseed@SEED_GTK_VERSION@_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
+am__v_lt_1 =
libseed@SEED_GTK_VERSION@_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(libseed@SEED_GTK_VERSION@_la_CFLAGS) $(CFLAGS) \
$(libseed@SEED_GTK_VERSION@_la_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -128,21 +186,18 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
-am__v_CC_0 = @echo " CC " $@;
-AM_V_at = $(am__v_at_@AM_V@)
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
-am__v_at_0 = @
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
-am__v_CCLD_0 = @echo " CCLD " $@;
-AM_V_GEN = $(am__v_GEN_@AM_V@)
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
-SOURCES = $(libseed@SEED_GTK_VERSION@_la_SOURCES)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(libseed@SEED_GTK_VERSION@_la_SOURCES) \
+ $(nodist_libseed@SEED_GTK_VERSION@_la_SOURCES)
DIST_SOURCES = $(libseed@SEED_GTK_VERSION@_la_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
@@ -150,8 +205,27 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \
esac
HEADERS = $(seedheaders_HEADERS)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
+am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/seed-path.h.in \
+ $(top_srcdir)/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALL_LINGUAS = @ALL_LINGUAS@
@@ -215,6 +289,8 @@ GDK_LIBS = @GDK_LIBS@
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
GIO_CFLAGS = @GIO_CFLAGS@
GIO_LIBS = @GIO_LIBS@
+GMODULE_CFLAGS = @GMODULE_CFLAGS@
+GMODULE_LIBS = @GMODULE_LIBS@
GMOFILES = @GMOFILES@
GMSGFMT = @GMSGFMT@
GNOME_JS_CFLAGS = @GNOME_JS_CFLAGS@
@@ -228,6 +304,7 @@ GREP = @GREP@
GTHREAD_CFLAGS = @GTHREAD_CFLAGS@
GTHREAD_LIBS = @GTHREAD_LIBS@
GTKDOC_CHECK = @GTKDOC_CHECK@
+GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@
GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
GTKDOC_MKPDF = @GTKDOC_MKPDF@
@@ -251,8 +328,17 @@ INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@
INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@
INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@
INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@
+INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@
+INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@
+INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@
+INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@
+INTROSPECTION_LIBS = @INTROSPECTION_LIBS@
+INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@
+INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@
+INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@
LD = @LD@
LDFLAGS = @LDFLAGS@
+LIBDL = @LIBDL@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
@@ -264,6 +350,7 @@ LIBXSS_LIBS = @LIBXSS_LIBS@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
@@ -358,6 +445,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
+runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@@ -393,18 +481,23 @@ libseed@SEED_GTK_VERSION@_la_SOURCES = \
seed-importer.h \
seed-path.h
+nodist_libseed@SEED_GTK_VERSION@_la_SOURCES = \
+ ../jsextensions/libseed-resources.c
+
libseed@SEED_GTK_VERSION@_la_CFLAGS = \
-Wall \
$(GOBJECT_INTROSPECTION_CFLAGS) \
$(WEBKIT_CFLAGS) \
$(SEED_OSX_CFLAGS) \
$(SEED_DEBUG_CFLAGS) \
+ $(SEED_GJSCOMPAT_CFLAGS) \
$(SEED_PROFILE_CFLAGS) \
$(FFI_CFLAGS) \
-DGOBJECT_INTROSPECTION_VERSION=$(GOBJECT_INTROSPECTION_VERSION)
libseed@SEED_GTK_VERSION@_la_LDFLAGS = \
- $(FFI_LDFLAGS)
+ $(FFI_LDFLAGS) \
+ -export-symbols-regex "^seed_.*"
libseed@SEED_GTK_VERSION@_la_LIBADD = \
$(GOBJECT_INTROSPECTION_LIBS) \
@@ -412,7 +505,8 @@ libseed@SEED_GTK_VERSION@_la_LIBADD = \
$(SEED_PROFILE_LIBS) \
$(SEED_OSX_LIBS) \
$(GIO_LIBS) \
- $(FFI_LIBS) -ldl
+ $(GMODULE_LIBS) \
+ $(FFI_LIBS) $(LIBDL)
seedheaders_HEADERS = seed.h seed-debug.h seed-module.h
seedheadersdir = $(pkgincludedir)@SEED_GTK_VERSION@
@@ -432,7 +526,6 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libseed/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --gnu libseed/Makefile
-.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
@@ -452,6 +545,7 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
$(am__aclocal_m4_deps):
seed-path.h: $(top_builddir)/config.status $(srcdir)/seed-path.h.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
@@ -478,12 +572,15 @@ uninstall-libLTLIBRARIES:
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
- @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
- dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
- test "$$dir" != "$$p" || dir=.; \
- echo "rm -f \"$${dir}/so_locations\""; \
- rm -f "$${dir}/so_locations"; \
- done
+ @list='$(lib_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
libseed@SEED_GTK_VERSION@.la: $(libseed@SEED_GTK_VERSION@_la_OBJECTS) $(libseed@SEED_GTK_VERSION@_la_DEPENDENCIES) $(EXTRA_libseed@SEED_GTK_VERSION@_la_DEPENDENCIES)
$(AM_V_CCLD)$(libseed@SEED_GTK_VERSION@_la_LINK) -rpath $(libdir) $(libseed@SEED_GTK_VERSION@_la_OBJECTS) $(libseed@SEED_GTK_VERSION@_la_LIBADD) $(LIBS)
@@ -493,6 +590,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libseed@SEED_GTK_VERSION@_la-libseed-resources.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libseed@SEED_GTK_VERSION@_la-seed-api.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libseed@SEED_GTK_VERSION@_la-seed-builtins.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libseed@SEED_GTK_VERSION@_la-seed-closure.Plo@am__quote@
@@ -509,14 +607,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -595,6 +693,13 @@ libseed@SEED_GTK_VERSION@_la-seed-importer.lo: seed-importer.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libseed@SEED_GTK_VERSION@_la_CFLAGS) $(CFLAGS) -c -o libseed@SEED_GTK_VERSION@_la-seed-importer.lo `test -f 'seed-importer.c' || echo '$(srcdir)/'`seed-importer.c
+libseed@SEED_GTK_VERSION@_la-libseed-resources.lo: ../jsextensions/libseed-resources.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libseed@SEED_GTK_VERSION@_la_CFLAGS) $(CFLAGS) -MT libseed@SEED_GTK_VERSION@_la-libseed-resources.lo -MD -MP -MF $(DEPDIR)/libseed@SEED_GTK_VERSION@_la-libseed-resources.Tpo -c -o libseed@SEED_GTK_VERSION@_la-libseed-resources.lo `test -f '../jsextensions/libseed-resources.c' || echo '$(srcdir)/'`../jsextensions/libseed-resources.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libseed@SEED_GTK_VERSION@_la-libseed-resources.Tpo $(DEPDIR)/libseed@SEED_GTK_VERSION@_la-libseed-resources.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='../jsextensions/libseed-resources.c' object='libseed@SEED_GTK_VERSION@_la-libseed-resources.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libseed@SEED_GTK_VERSION@_la_CFLAGS) $(CFLAGS) -c -o libseed@SEED_GTK_VERSION@_la-libseed-resources.lo `test -f '../jsextensions/libseed-resources.c' || echo '$(srcdir)/'`../jsextensions/libseed-resources.c
+
mostlyclean-libtool:
-rm -f *.lo
@@ -622,26 +727,15 @@ uninstall-seedheadersHEADERS:
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(seedheadersdir)'; $(am__uninstall_files_from_dir)
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
- mkid -fID $$unique
-tags: TAGS
-
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ $(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
@@ -653,15 +747,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$unique; \
fi; \
fi
-ctags: CTAGS
-CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
- $(TAGS_FILES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | \
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in files) print i; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
@@ -670,6 +760,21 @@ GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -814,20 +919,23 @@ uninstall-am: uninstall-libLTLIBRARIES uninstall-seedheadersHEADERS
.MAKE: install-am install-strip
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
- clean-libLTLIBRARIES clean-libtool ctags distclean \
- distclean-compile distclean-generic distclean-libtool \
- distclean-tags distdir dvi dvi-am html html-am info info-am \
- install install-am install-data install-data-am install-dvi \
- install-dvi-am install-exec install-exec-am install-html \
- install-html-am install-info install-info-am \
- install-libLTLIBRARIES install-man install-pdf install-pdf-am \
- install-ps install-ps-am install-seedheadersHEADERS \
- install-strip installcheck installcheck-am installdirs \
- maintainer-clean maintainer-clean-generic mostlyclean \
- mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
- pdf pdf-am ps ps-am tags uninstall uninstall-am \
- uninstall-libLTLIBRARIES uninstall-seedheadersHEADERS
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
+ clean-libLTLIBRARIES clean-libtool cscopelist-am ctags \
+ ctags-am distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-libLTLIBRARIES install-man install-pdf \
+ install-pdf-am install-ps install-ps-am \
+ install-seedheadersHEADERS install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES \
+ uninstall-seedheadersHEADERS
+
+.PRECIOUS: Makefile
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/libseed/seed-api.c b/libseed/seed-api.c
index 7ec4b11..c35c050 100644
--- a/libseed/seed-api.c
+++ b/libseed/seed-api.c
@@ -34,9 +34,9 @@
*
*/
void
-seed_value_protect (JSContextRef ctx, JSValueRef value)
+seed_value_protect(JSContextRef ctx, JSValueRef value)
{
- JSValueProtect (ctx, value);
+ JSValueProtect(ctx, value);
}
/**
@@ -49,9 +49,9 @@ seed_value_protect (JSContextRef ctx, JSValueRef value)
*
*/
void
-seed_value_unprotect (JSContextRef ctx, JSValueRef value)
+seed_value_unprotect(JSContextRef ctx, JSValueRef value)
{
- JSValueUnprotect (ctx, value);
+ JSValueUnprotect(ctx, value);
}
/**
@@ -69,9 +69,9 @@ seed_value_unprotect (JSContextRef ctx, JSValueRef value)
*
*/
JSGlobalContextRef
-seed_context_create (JSContextGroupRef group, JSClassRef global_class)
+seed_context_create(JSContextGroupRef group, JSClassRef global_class)
{
- return JSGlobalContextCreateInGroup (group, global_class);
+ return JSGlobalContextCreateInGroup(group, global_class);
}
/**
@@ -84,9 +84,9 @@ seed_context_create (JSContextGroupRef group, JSClassRef global_class)
*
*/
JSGlobalContextRef
-seed_context_ref (JSGlobalContextRef ctx)
+seed_context_ref(JSGlobalContextRef ctx)
{
- return JSGlobalContextRetain (ctx);
+ return JSGlobalContextRetain(ctx);
}
/**
@@ -97,9 +97,9 @@ seed_context_ref (JSGlobalContextRef ctx)
*
*/
void
-seed_context_unref (JSGlobalContextRef ctx)
+seed_context_unref(JSGlobalContextRef ctx)
{
- JSGlobalContextRelease (ctx);
+ JSGlobalContextRelease(ctx);
}
/**
@@ -112,9 +112,9 @@ seed_context_unref (JSGlobalContextRef ctx)
*
*/
void
-seed_context_collect (JSGlobalContextRef ctx)
+seed_context_collect(JSGlobalContextRef ctx)
{
- JSGarbageCollect(ctx);
+ JSGarbageCollect(ctx);
}
/**
@@ -128,9 +128,9 @@ seed_context_collect (JSGlobalContextRef ctx)
*
*/
JSObjectRef
-seed_make_object (JSContextRef ctx, JSClassRef class, gpointer private)
+seed_make_object(JSContextRef ctx, JSClassRef class, gpointer private)
{
- return JSObjectMake (ctx, class, private);
+ return JSObjectMake(ctx, class, private);
}
/**
@@ -146,27 +146,30 @@ seed_make_object (JSContextRef ctx, JSClassRef class, gpointer private)
*
*/
void
-seed_object_set_property_at_index (JSContextRef ctx,
- JSObjectRef object,
- gint index,
- JSValueRef value, JSValueRef * exception)
+seed_object_set_property_at_index(JSContextRef ctx,
+ JSObjectRef object,
+ gint index,
+ JSValueRef value,
+ JSValueRef* exception)
{
- JSObjectSetPropertyAtIndex (ctx, object, index, value, exception);
+ JSObjectSetPropertyAtIndex(ctx, object, index, value, exception);
}
JSValueRef
-seed_object_get_property_at_index (JSContextRef ctx,
- JSObjectRef object,
- gint index, JSValueRef * exception)
+seed_object_get_property_at_index(JSContextRef ctx,
+ JSObjectRef object,
+ gint index,
+ JSValueRef* exception)
{
- return JSObjectGetPropertyAtIndex (ctx, object, index, exception);
+ return JSObjectGetPropertyAtIndex(ctx, object, index, exception);
}
/**
* seed_object_call
* @ctx: A #SeedContext.
* @object: A #SeedObject to call.
- * @this: The #SeedObject to use as the 'this' object inside the called function.
+ * @this: The #SeedObject to use as the 'this' object inside the called
+ * function.
* @argument_count: The number of arguments in the @arguments array.
* @arguments: An array (@argument_count long) of #SeedValues to pass in as the
* function's arguments.
@@ -180,14 +183,15 @@ seed_object_get_property_at_index (JSContextRef ctx,
*
*/
JSValueRef
-seed_object_call (JSContextRef ctx,
- JSObjectRef object,
- JSObjectRef this,
- size_t argument_count,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_object_call(JSContextRef ctx,
+ JSObjectRef object,
+ JSObjectRef this,
+ size_t argument_count,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- return JSObjectCallAsFunction (ctx, object, this,
- argument_count, arguments, exception);
+ return JSObjectCallAsFunction(ctx, object, this, argument_count, arguments,
+ exception);
}
/**
@@ -196,7 +200,7 @@ seed_object_call (JSContextRef ctx,
* @js: A string representing the contents of the script.
* @source_url: The filename of the script, for reference in errors, or %NULL.
* @line_number: The line number of the beginning of the script, for reference
- * in error messages, or %NULL.
+ * in error messages, or 0.
*
* Creates a new #SeedScript instance with @js as the contents, then
* checks for proper syntax.
@@ -207,28 +211,28 @@ seed_object_call (JSContextRef ctx,
* Return value: The newly created #SeedScript.
*
*/
-SeedScript *
-seed_make_script (JSContextRef ctx,
- const gchar * js,
- const gchar * source_url, gint line_number)
+SeedScript*
+seed_make_script(JSContextRef ctx,
+ const gchar* js,
+ const gchar* source_url,
+ gint line_number)
{
- SeedScript *ret = g_new0 (SeedScript, 1);
+ SeedScript* ret = g_new0(SeedScript, 1);
- if (js)
- ret->script = JSStringCreateWithUTF8CString (js);
- else
- ret->script = JSStringCreateWithUTF8CString ("");
+ if (js)
+ ret->script = JSStringCreateWithUTF8CString(js);
+ else
+ ret->script = JSStringCreateWithUTF8CString("");
- if (source_url)
- {
- ret->source_url = JSStringCreateWithUTF8CString (source_url);
+ if (source_url) {
+ ret->source_url = JSStringCreateWithUTF8CString(source_url);
}
- ret->line_number = line_number;
+ ret->line_number = line_number;
- JSCheckScriptSyntax (ctx, ret->script,
- ret->source_url, ret->line_number, &ret->exception);
+ JSCheckScriptSyntax(ctx, ret->script, ret->source_url, ret->line_number,
+ &ret->exception);
- return ret;
+ return ret;
}
/**
@@ -241,22 +245,21 @@ seed_make_script (JSContextRef ctx,
* Return value: The newly created #SeedScript.
*
*/
-SeedScript *
-seed_script_new_from_file (JSContextRef ctx, gchar * file)
+SeedScript*
+seed_script_new_from_file(JSContextRef ctx, gchar* file)
{
- SeedScript *script;
- GError *e = NULL;
- gchar *contents = NULL;
+ SeedScript* script;
+ GError* e = NULL;
+ gchar* contents = NULL;
- g_file_get_contents (file, &contents, NULL, &e);
- script = seed_make_script (ctx, contents, file, 0);
- if (e)
- {
- seed_make_exception_from_gerror (ctx, &script->exception, e);
- g_error_free (e);
+ seed_importer_get_file_contents(file, &contents, NULL, &e);
+ script = seed_make_script(ctx, contents, file, 0);
+ if (e) {
+ seed_make_exception_from_gerror(ctx, &script->exception, e);
+ g_error_free(e);
}
- return script;
+ return script;
}
/**
@@ -271,16 +274,15 @@ seed_script_new_from_file (JSContextRef ctx, gchar * file)
*
*/
JSValueRef
-seed_evaluate (JSContextRef ctx, SeedScript * s, JSObjectRef this)
+seed_evaluate(JSContextRef ctx, SeedScript* s, JSObjectRef this)
{
- JSValueRef ret;
+ JSValueRef ret;
- s->exception = 0;
- ret = JSEvaluateScript (ctx,
- s->script, this, s->source_url,
- s->line_number, &s->exception);
+ s->exception = 0;
+ ret = JSEvaluateScript(ctx, s->script, this, s->source_url, s->line_number,
+ &s->exception);
- return ret;
+ return ret;
}
/**
@@ -296,16 +298,17 @@ seed_evaluate (JSContextRef ctx, SeedScript * s, JSObjectRef this)
*
*/
JSValueRef
-seed_simple_evaluate (JSContextRef ctx,
- const gchar * source, JSValueRef * exception)
+seed_simple_evaluate(JSContextRef ctx,
+ const gchar* source,
+ JSValueRef* exception)
{
- JSValueRef ret;
- JSStringRef script = JSStringCreateWithUTF8CString (source);
+ JSValueRef ret;
+ JSStringRef script = JSStringCreateWithUTF8CString(source);
- ret = JSEvaluateScript (ctx, script, NULL, NULL, 0, exception);
+ ret = JSEvaluateScript(ctx, script, NULL, NULL, 0, exception);
- JSStringRelease (script);
- return ret;
+ JSStringRelease(script);
+ return ret;
}
/**
@@ -318,9 +321,9 @@ seed_simple_evaluate (JSContextRef ctx,
*
*/
JSValueRef
-seed_script_exception (SeedScript * s)
+seed_script_exception(SeedScript* s)
{
- return s->exception;
+ return s->exception;
}
/**
@@ -332,9 +335,9 @@ seed_script_exception (SeedScript * s)
*
*/
gsize
-seed_string_get_maximum_size (JSStringRef string)
+seed_string_get_maximum_size(JSStringRef string)
{
- return JSStringGetMaximumUTF8CStringSize (string);
+ return JSStringGetMaximumUTF8CStringSize(string);
}
/**
@@ -347,10 +350,11 @@ seed_string_get_maximum_size (JSStringRef string)
*
*/
gsize
-seed_string_to_utf8_buffer (JSStringRef string, gchar * buffer,
- size_t buffer_size)
+seed_string_to_utf8_buffer(JSStringRef string,
+ gchar* buffer,
+ size_t buffer_size)
{
- return JSStringGetUTF8CString (string, buffer, buffer_size);
+ return JSStringGetUTF8CString(string, buffer, buffer_size);
}
/**
@@ -362,9 +366,9 @@ seed_string_to_utf8_buffer (JSStringRef string, gchar * buffer,
*
*/
gboolean
-seed_string_is_equal (JSStringRef a, JSStringRef b)
+seed_string_is_equal(JSStringRef a, JSStringRef b)
{
- return JSStringIsEqual (a, b);
+ return JSStringIsEqual(a, b);
}
/**
@@ -378,9 +382,9 @@ seed_string_is_equal (JSStringRef a, JSStringRef b)
*
*/
gboolean
-seed_string_is_equal_utf8 (JSStringRef a, const gchar * b)
+seed_string_is_equal_utf8(JSStringRef a, const gchar* b)
{
- return JSStringIsEqualToUTF8CString (a, b);
+ return JSStringIsEqualToUTF8CString(a, b);
}
/**
@@ -393,9 +397,9 @@ seed_string_is_equal_utf8 (JSStringRef a, const gchar * b)
*
*/
JSStringRef
-seed_string_ref (JSStringRef string)
+seed_string_ref(JSStringRef string)
{
- return JSStringRetain (string);
+ return JSStringRetain(string);
}
/**
@@ -406,18 +410,19 @@ seed_string_ref (JSStringRef string)
*
*/
void
-seed_string_unref (JSStringRef string)
+seed_string_unref(JSStringRef string)
{
- JSStringRelease (string);
+ JSStringRelease(string);
}
void
-seed_script_destroy (SeedScript * s)
+seed_script_destroy(SeedScript* s)
{
- seed_string_unref (s->script);
- seed_string_unref (s->source_url);
+ seed_string_unref(s->script);
+ if (s->source_url)
+ seed_string_unref(s->source_url);
- g_free (s);
+ g_free(s);
}
// TODO:FIXME: Do we have an external typedef or anything for JSClassDefinition?
@@ -430,9 +435,9 @@ seed_script_destroy (SeedScript * s)
*
*/
JSClassRef
-seed_create_class (JSClassDefinition * def)
+seed_create_class(JSClassDefinition* def)
{
- return JSClassCreate (def);
+ return JSClassCreate(def);
}
/* TODO:FIXME: GtkDoc is choking on JSObjectCallAsConstructorCallback, and
@@ -449,11 +454,11 @@ seed_create_class (JSClassDefinition * def)
*
*/
JSObjectRef
-seed_make_constructor (JSContextRef ctx,
- JSClassRef class,
- JSObjectCallAsConstructorCallback constructor)
+seed_make_constructor(JSContextRef ctx,
+ JSClassRef class,
+ JSObjectCallAsConstructorCallback constructor)
{
- return JSObjectMakeConstructor (ctx, class, constructor);
+ return JSObjectMakeConstructor(ctx, class, constructor);
}
/**
@@ -466,9 +471,9 @@ seed_make_constructor (JSContextRef ctx,
*
*/
gpointer
-seed_object_get_private (JSObjectRef object)
+seed_object_get_private(JSObjectRef object)
{
- return (gpointer) JSObjectGetPrivate (object);
+ return (gpointer) JSObjectGetPrivate(object);
}
/**
@@ -480,9 +485,9 @@ seed_object_get_private (JSObjectRef object)
*
*/
void
-seed_object_set_private (JSObjectRef object, gpointer value)
+seed_object_set_private(JSObjectRef object, gpointer value)
{
- JSObjectSetPrivate (object, value);
+ JSObjectSetPrivate(object, value);
}
/**
@@ -496,9 +501,9 @@ seed_object_set_private (JSObjectRef object, gpointer value)
*
*/
gboolean
-seed_value_is_null (JSContextRef ctx, JSValueRef value)
+seed_value_is_null(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsNull (ctx, value);
+ return JSValueIsNull(ctx, value);
}
/**
@@ -512,9 +517,9 @@ seed_value_is_null (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_undefined (JSContextRef ctx, JSValueRef value)
+seed_value_is_undefined(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsUndefined (ctx, value);
+ return JSValueIsUndefined(ctx, value);
}
/**
@@ -528,9 +533,9 @@ seed_value_is_undefined (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_object (JSContextRef ctx, JSValueRef value)
+seed_value_is_object(JSContextRef ctx, JSValueRef value)
{
- return !seed_value_is_null (ctx, value) && JSValueIsObject (ctx, value);
+ return !seed_value_is_null(ctx, value) && JSValueIsObject(ctx, value);
}
/**
@@ -545,11 +550,12 @@ seed_value_is_object (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_object_of_class (JSContextRef ctx, JSValueRef value,
- JSClassRef klass)
+seed_value_is_object_of_class(JSContextRef ctx,
+ JSValueRef value,
+ JSClassRef klass)
{
- return !seed_value_is_null (ctx, value)
- && JSValueIsObjectOfClass (ctx, value, klass);
+ return !seed_value_is_null(ctx, value)
+ && JSValueIsObjectOfClass(ctx, value, klass);
}
/**
@@ -564,9 +570,9 @@ seed_value_is_object_of_class (JSContextRef ctx, JSValueRef value,
*
*/
gboolean
-seed_value_is_function (JSContextRef ctx, JSObjectRef value)
+seed_value_is_function(JSContextRef ctx, JSObjectRef value)
{
- return seed_value_is_object (ctx, value) && JSObjectIsFunction (ctx, value);
+ return seed_value_is_object(ctx, value) && JSObjectIsFunction(ctx, value);
}
/**
@@ -580,9 +586,9 @@ seed_value_is_function (JSContextRef ctx, JSObjectRef value)
*
*/
gboolean
-seed_value_is_string (JSContextRef ctx, JSValueRef value)
+seed_value_is_string(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsString (ctx, value);
+ return JSValueIsString(ctx, value);
}
/**
@@ -596,9 +602,9 @@ seed_value_is_string (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_number (JSContextRef ctx, JSValueRef value)
+seed_value_is_number(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsNumber (ctx, value);
+ return JSValueIsNumber(ctx, value);
}
/**
@@ -610,12 +616,12 @@ seed_value_is_number (JSContextRef ctx, JSValueRef value)
*
*/
void
-seed_engine_set_search_path (SeedEngine * eng, const gchar * path)
+seed_engine_set_search_path(SeedEngine* eng, const gchar* path)
{
- /* this should be null from seed_init unless there's already a path set. */
+ /* this should be null from seed_init unless there's already a path set. */
- g_strfreev (eng->search_path);
- eng->search_path = g_strsplit (path, ":", -1);
+ g_strfreev(eng->search_path);
+ eng->search_path = g_strsplit(path, ":", -1);
}
/**
@@ -628,10 +634,10 @@ seed_engine_set_search_path (SeedEngine * eng, const gchar * path)
* Return value: A null-terminated array of strings containing the paths.
*
*/
-gchar **
-seed_engine_get_search_path (SeedEngine * eng)
+gchar**
+seed_engine_get_search_path(SeedEngine* eng)
{
- return eng->search_path;
+ return eng->search_path;
}
/**
@@ -647,13 +653,13 @@ seed_engine_get_search_path (SeedEngine * eng)
*
*/
void
-seed_signal_connect_full (JSContextRef ctx,
- GObject * object,
- const gchar * signal,
- JSObjectRef function, JSObjectRef user_data)
+seed_signal_connect_full(JSContextRef ctx,
+ GObject* object,
+ const gchar* signal,
+ JSObjectRef function,
+ JSObjectRef user_data)
{
- seed_gobject_signal_connect (ctx, signal, object, function,
- NULL, user_data);
+ seed_gobject_signal_connect(ctx, signal, object, function, NULL, user_data);
}
/**
@@ -669,14 +675,15 @@ seed_signal_connect_full (JSContextRef ctx,
*
*/
void
-seed_signal_connect (JSContextRef ctx,
- GObject * object,
- const gchar * signal, const gchar * script)
+seed_signal_connect(JSContextRef ctx,
+ GObject* object,
+ const gchar* signal,
+ const gchar* script)
{
- JSValueRef func;
+ JSValueRef func;
- func = seed_simple_evaluate (ctx, script, NULL);
- seed_signal_connect_full (ctx, object, signal, (JSObjectRef) func, NULL);
+ func = seed_simple_evaluate(ctx, script, NULL);
+ seed_signal_connect_full(ctx, object, signal, (JSObjectRef) func, NULL);
}
/**
@@ -686,12 +693,11 @@ seed_signal_connect (JSContextRef ctx,
* Return value: The global object for @ctx.
*/
JSObjectRef
-seed_context_get_global_object (JSGlobalContextRef ctx)
+seed_context_get_global_object(JSGlobalContextRef ctx)
{
- return JSContextGetGlobalObject (ctx);
+ return JSContextGetGlobalObject(ctx);
}
-
/**
* seed_make_array:
* @ctx: A valid #SeedContext
@@ -707,11 +713,12 @@ seed_context_get_global_object (JSGlobalContextRef ctx)
*/
JSObjectRef
-seed_make_array (JSContextRef ctx,
- const JSValueRef elements[],
- gsize num_elements, JSValueRef * exception)
+seed_make_array(JSContextRef ctx,
+ const JSValueRef elements[],
+ gsize num_elements,
+ JSValueRef* exception)
{
- return JSObjectMakeArray (ctx, num_elements, elements, exception);
+ return JSObjectMakeArray(ctx, num_elements, elements, exception);
}
/**
@@ -726,9 +733,9 @@ seed_make_array (JSContextRef ctx,
*
*/
JSValueRef
-seed_make_null (JSContextRef ctx)
+seed_make_null(JSContextRef ctx)
{
- return JSValueMakeNull (ctx);
+ return JSValueMakeNull(ctx);
}
/**
@@ -742,9 +749,9 @@ seed_make_null (JSContextRef ctx)
* Return value: A #SeedValue of the 'undefined' type.
*/
JSValueRef
-seed_make_undefined (JSContextRef ctx)
+seed_make_undefined(JSContextRef ctx)
{
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
/**
@@ -755,9 +762,9 @@ seed_make_undefined (JSContextRef ctx)
* Return value: The type of @value
*/
JSType
-seed_value_get_type (JSContextRef ctx, JSValueRef value)
+seed_value_get_type(JSContextRef ctx, JSValueRef value)
{
- return JSValueGetType (ctx, value);
+ return JSValueGetType(ctx, value);
}
/**
@@ -765,34 +772,33 @@ seed_value_get_type (JSContextRef ctx, JSValueRef value)
* @ctx: A valid #SeedContext
* @object: An object from which to copy property names.
*
- * Return value: A %NULL terminated array containing the property names of @object
- */
-gchar **
-seed_object_copy_property_names (JSContextRef ctx, JSObjectRef object)
-{
- JSPropertyNameArrayRef names;
- JSStringRef name;
- guint i, length;
- gsize max_length;
- gchar *c_name;
- gchar **ret;
-
- names = JSObjectCopyPropertyNames (ctx, object);
- length = JSPropertyNameArrayGetCount (names);
- ret = (gchar **) g_malloc ((length + 1) * sizeof (gchar *));
- for (i = 0; i < length; i++)
- {
- name = JSPropertyNameArrayGetNameAtIndex (names, i);
- max_length = JSStringGetMaximumUTF8CStringSize (name);
- c_name = (gchar *) g_malloc (max_length * sizeof (gchar));
- JSStringGetUTF8CString (name, c_name, max_length);
- ret[i] = c_name;
-
+ * Return value: A %NULL terminated array containing the property names of
+ * @object
+ */
+gchar**
+seed_object_copy_property_names(JSContextRef ctx, JSObjectRef object)
+{
+ JSPropertyNameArrayRef names;
+ JSStringRef name;
+ guint i, length;
+ gsize max_length;
+ gchar* c_name;
+ gchar** ret;
+
+ names = JSObjectCopyPropertyNames(ctx, object);
+ length = JSPropertyNameArrayGetCount(names);
+ ret = (gchar**) g_malloc((length + 1) * sizeof(gchar*));
+ for (i = 0; i < length; i++) {
+ name = JSPropertyNameArrayGetNameAtIndex(names, i);
+ max_length = JSStringGetMaximumUTF8CStringSize(name);
+ c_name = (gchar*) g_malloc(max_length * sizeof(gchar));
+ JSStringGetUTF8CString(name, c_name, max_length);
+ ret[i] = c_name;
}
- ret[length] = NULL;
- JSPropertyNameArrayRelease (names);
+ ret[length] = NULL;
+ JSPropertyNameArrayRelease(names);
- return ret;
+ return ret;
}
/**
@@ -803,15 +809,15 @@ seed_object_copy_property_names (JSContextRef ctx, JSObjectRef object)
* Return value: The prototype of @obj.
*/
JSObjectRef
-seed_object_get_prototype (JSContextRef ctx, JSObjectRef obj)
+seed_object_get_prototype(JSContextRef ctx, JSObjectRef obj)
{
- return (JSObjectRef) JSObjectGetPrototype (ctx, obj);
+ return (JSObjectRef) JSObjectGetPrototype(ctx, obj);
}
gboolean
-seed_object_is_of_class (JSContextRef ctx, JSObjectRef obj, JSClassRef class)
+seed_object_is_of_class(JSContextRef ctx, JSObjectRef obj, JSClassRef class)
{
- return JSValueIsObjectOfClass (ctx, obj, class);
+ return JSValueIsObjectOfClass(ctx, obj, class);
}
/**
@@ -826,18 +832,18 @@ seed_object_is_of_class (JSContextRef ctx, JSObjectRef obj, JSClassRef class)
* Return value: A #SeedObject representing the function
*/
JSObjectRef
-seed_make_function (JSContextRef ctx, gpointer func, gchar * name)
+seed_make_function(JSContextRef ctx, gpointer func, gchar* name)
{
- JSObjectRef oref;
- JSStringRef jsname = NULL;
- if (name)
- jsname = JSStringCreateWithUTF8CString (name);
- oref = JSObjectMakeFunctionWithCallback (ctx, NULL, func);
+ JSObjectRef oref;
+ JSStringRef jsname = NULL;
+ if (name)
+ jsname = JSStringCreateWithUTF8CString(name);
+ oref = JSObjectMakeFunctionWithCallback(ctx, NULL, func);
- if (jsname)
- JSStringRelease (jsname);
+ if (jsname)
+ JSStringRelease(jsname);
- return oref;
+ return oref;
}
/**
@@ -846,7 +852,8 @@ seed_make_function (JSContextRef ctx, gpointer func, gchar * name)
* @format: Format string to use.
* @exception: Location to store an exception.
* @values: The values to convert.
- * @Varargs: A %NULL-terminated list of locations to store the results of conversion.
+ * @Varargs: A %NULL-terminated list of locations to store the results of
+ * conversion.
*
* A convenience API for converting multiple values at once, the format string
* is composed of single characters specifying types, for example:
@@ -864,66 +871,57 @@ seed_make_function (JSContextRef ctx, gpointer func, gchar * name)
* Return value: Whether conversion was successful.
*/
gboolean
-seed_value_to_format (JSContextRef ctx,
- const gchar * format,
- JSValueRef * values, JSValueRef * exception, ...)
-{
- va_list argp;
- const gchar *c;
- guint i = 0;
-
- c = format;
-
- va_start (argp, exception);
-
- for (c = format; *c; c++)
- {
- JSValueRef val = values[i];
- gpointer p = va_arg (argp, gpointer);
-
- if (!val || !p)
- {
- va_end (argp);
- return FALSE;
- }
- switch (*c)
- {
- case 'i':
- {
- *((gint *) p) = seed_value_to_int (ctx, val, exception);
- break;
- }
- case 'u':
- {
- *((guint *) p) = seed_value_to_uint (ctx, val, exception);
- break;
- }
- case 's':
- {
- *((gchar **) p) = seed_value_to_string (ctx, val, exception);
- break;
- }
- case 'f':
- {
- *((gdouble *) p) = seed_value_to_int (ctx, val, exception);
- break;
- }
- case 'o':
- {
- *((GObject **) p) = seed_value_to_object (ctx, val, exception);
- break;
- }
- case 'c':
- {
- *((gchar *) c) = seed_value_to_char (ctx, val, exception);
- break;
- }
- }
- i++;
+seed_value_to_format(JSContextRef ctx,
+ const gchar* format,
+ JSValueRef* values,
+ JSValueRef* exception,
+ ...)
+{
+ va_list argp;
+ const gchar* c;
+ guint i = 0;
+
+ va_start(argp, exception);
+
+ for (c = format; *c; c++) {
+ JSValueRef val = values[i];
+ gpointer p = va_arg(argp, gpointer);
+
+ if (!val || !p) {
+ va_end(argp);
+ return FALSE;
+ }
+ switch (*c) {
+ case 'i': {
+ *((gint*) p) = seed_value_to_int(ctx, val, exception);
+ break;
+ }
+ case 'u': {
+ *((guint*) p) = seed_value_to_uint(ctx, val, exception);
+ break;
+ }
+ case 's': {
+ *((gchar**) p) = seed_value_to_string(ctx, val, exception);
+ break;
+ }
+ case 'f': {
+ *((gdouble*) p) = seed_value_to_int(ctx, val, exception);
+ break;
+ }
+ case 'o': {
+ *((GObject**) p) = seed_value_to_object(ctx, val, exception);
+ break;
+ }
+ case 'c': {
+ *((gchar*) c) = seed_value_to_char(ctx, val, exception);
+ break;
+ }
+ }
+ i++;
}
- va_end (argp);
- return TRUE;
+ va_end(argp);
+ return TRUE;
}
/*************************** CALLBACK DOCUMENTATION **************************/
@@ -935,7 +933,8 @@ seed_value_to_format (JSContextRef ctx,
* @this_object: The #SeedObject representing the "this" object in the caller
* @argument_count: The number of arguments passed into the callback
* @arguments: An array of #SeedValues; the value of the arguments passed in
- * @exception: A reference to a #SeedException; use seed_make_exception() in order
+ * @exception: A reference to a #SeedException; use seed_make_exception() in
+ * order
* to throw a JavaScript exception from the callback.
*
* All native C function callbacks should use the prototype of
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index b5b14fc..709d070 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -22,536 +22,627 @@
#include <sys/mman.h>
#include <stdio.h>
#include <signal.h>
+#include <gio/gio.h>
JSValueRef seed_print_ref;
JSValueRef seed_printerr_ref;
+JSValueRef seed_log_error_ref;
static JSValueRef
-seed_include (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_include(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSStringRef file_contents, file_name;
+ JSStringRef file_contents, file_name;
+
+ GDir* dir;
+ gchar *import_file, *abs_path;
+ gchar *walk, *buffer = NULL;
+ guint i, len;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.include expected 1 argument, "
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
+ }
- GDir *dir;
- gchar *import_file, *abs_path;
- gchar *buffer, *walk;
- guint i, len;
+ import_file = seed_value_to_string(ctx, arguments[0], exception);
- if (argumentCount != 1)
+ /* just try current dir if no path set, or use the absolute path */
+ if (!eng->search_path || g_path_is_absolute(import_file))
+ seed_importer_get_file_contents(import_file, &buffer, 0, NULL);
+ else /* A search path is set and path given is not absolute. */
{
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.include expected 1 argument, "
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
- }
+ len = g_strv_length(eng->search_path);
+ for (i = 0; i < len; ++i) {
+ dir = g_dir_open(eng->search_path[i], 0, NULL);
- import_file = seed_value_to_string (ctx, arguments[0], exception);
+ if (!dir) /* skip bad path entries */
+ continue;
- /* just try current dir if no path set, or use the absolute path */
- if (!eng->search_path || g_path_is_absolute (import_file))
- g_file_get_contents (import_file, &buffer, 0, NULL);
- else /* A search path is set and path given is not absolute. */
- {
- len = g_strv_length (eng->search_path);
- for (i = 0; i < len; ++i)
- {
- dir = g_dir_open (eng->search_path[i], 0, NULL);
-
- if (!dir) /* skip bad path entries */
- continue;
-
- abs_path =
- g_build_filename (eng->search_path[i], import_file, NULL);
-
- if (g_file_get_contents (abs_path, &buffer, 0, NULL))
- {
- g_free (abs_path);
- g_dir_close (dir);
- break;
- }
-
- g_dir_close (dir);
- g_free (abs_path);
- }
+ abs_path = g_build_filename(eng->search_path[i], import_file, NULL);
+
+ if (seed_importer_get_file_contents(abs_path, &buffer, 0, NULL)) {
+ g_free(abs_path);
+ g_dir_close(dir);
+ break;
+ }
+
+ g_dir_close(dir);
+ g_free(abs_path);
+ }
}
- if (!buffer)
- {
- seed_make_exception (ctx, exception, "FileNotFound",
- "File not found: %s", import_file);
+ if (!buffer) {
+ seed_make_exception(ctx, exception, "FileNotFound",
+ "File not found: %s", import_file);
- g_free (import_file);
- g_free (buffer);
- return JSValueMakeNull (ctx);
+ g_free(import_file);
+ g_free(buffer);
+ return JSValueMakeNull(ctx);
}
- walk = buffer;
+ walk = buffer;
- if (*walk == '#')
- {
- while (*walk != '\n')
- walk++;
- walk++;
+ if (*walk == '#') {
+ while (*walk != '\n')
+ walk++;
+ walk++;
}
- walk = g_strdup (walk);
- g_free (buffer);
+ walk = g_strdup(walk);
+ g_free(buffer);
- file_contents = JSStringCreateWithUTF8CString (walk);
- file_name = JSStringCreateWithUTF8CString (import_file);
+ file_contents = JSStringCreateWithUTF8CString(walk);
+ file_name = JSStringCreateWithUTF8CString(import_file);
- JSEvaluateScript (ctx, file_contents, NULL, file_name, 0, exception);
+ JSEvaluateScript(ctx, file_contents, NULL, file_name, 0, exception);
- JSStringRelease (file_contents);
- JSStringRelease (file_name);
- g_free (import_file);
- g_free (walk);
+ JSStringRelease(file_contents);
+ JSStringRelease(file_name);
+ g_free(import_file);
+ g_free(walk);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_scoped_include (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_scoped_include(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSContextRef nctx;
- JSObjectRef global;
- JSStringRef file_contents, file_name;
- GDir *dir;
- gchar *import_file, *abs_path;
- gchar *buffer, *walk;
- guint i;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.include expected 1 argument, "
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
+ JSContextRef nctx;
+ JSObjectRef global;
+ JSStringRef file_contents, file_name;
+ GDir* dir;
+ gchar *import_file, *abs_path;
+ gchar *walk, *buffer = NULL;
+ guint i;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.include expected 1 argument, "
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- import_file = seed_value_to_string (ctx, arguments[0], exception);
+ import_file = seed_value_to_string(ctx, arguments[0], exception);
- /* just try current dir if no path set, or use the absolute path */
- if (!eng->search_path || g_path_is_absolute (import_file))
- g_file_get_contents (import_file, &buffer, 0, NULL);
- else /* A search path is set and path given is not absolute. */
+ /* just try current dir if no path set, or use the absolute path */
+ if (!eng->search_path || g_path_is_absolute(import_file))
+ seed_importer_get_file_contents(import_file, &buffer, 0, NULL);
+ else /* A search path is set and path given is not absolute. */
{
- for (i = 0; i < g_strv_length (eng->search_path); ++i)
- {
- dir = g_dir_open (eng->search_path[i], 0, NULL);
+ for (i = 0; i < g_strv_length(eng->search_path); ++i) {
+ dir = g_dir_open(eng->search_path[i], 0, NULL);
- if (!dir) /* skip bad path entries */
- continue;
+ if (!dir) /* skip bad path entries */
+ continue;
- abs_path =
- g_build_filename (eng->search_path[i], import_file, NULL);
+ abs_path = g_build_filename(eng->search_path[i], import_file, NULL);
- if (g_file_get_contents (abs_path, &buffer, 0, NULL))
- {
- g_free (abs_path);
- break;
- }
+ if (seed_importer_get_file_contents(abs_path, &buffer, 0, NULL)) {
+ g_free(abs_path);
+ break;
+ }
- g_dir_close (dir);
- g_free (abs_path);
- }
+ g_dir_close(dir);
+ g_free(abs_path);
+ }
}
- if (!buffer)
- {
- seed_make_exception (ctx, exception, "FileNotFound",
- "File not found: %s", import_file);
+ if (!buffer) {
+ seed_make_exception(ctx, exception, "FileNotFound",
+ "File not found: %s", import_file);
- g_free (import_file);
- g_free (buffer);
- return JSValueMakeNull (ctx);
+ g_free(import_file);
+ g_free(buffer);
+ return JSValueMakeNull(ctx);
}
- walk = buffer;
+ walk = buffer;
- if (*walk == '#')
- {
- while (*walk != '\n')
- walk++;
- walk++;
+ if (*walk == '#') {
+ while (*walk != '\n')
+ walk++;
+ walk++;
}
- walk = g_strdup (walk);
- g_free (buffer);
+ walk = g_strdup(walk);
+ g_free(buffer);
- file_contents = JSStringCreateWithUTF8CString (walk);
- file_name = JSStringCreateWithUTF8CString (import_file);
+ file_contents = JSStringCreateWithUTF8CString(walk);
+ file_name = JSStringCreateWithUTF8CString(import_file);
+ nctx = JSGlobalContextCreateInGroup(context_group, 0);
+ seed_prepare_global_context(nctx);
- nctx = JSGlobalContextCreateInGroup (context_group, 0);
- seed_prepare_global_context (nctx);
+ JSEvaluateScript(nctx, file_contents, NULL, file_name, 0, exception);
- JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
+ global = JSContextGetGlobalObject(nctx);
- global = JSContextGetGlobalObject (nctx);
+ JSGlobalContextRelease((JSGlobalContextRef) nctx);
- JSGlobalContextRelease ((JSGlobalContextRef) nctx);
+ JSStringRelease(file_contents);
+ JSStringRelease(file_name);
+ g_free(import_file);
+ g_free(walk);
- JSStringRelease (file_contents);
- JSStringRelease (file_name);
- g_free (import_file);
- g_free (walk);
-
- return global;
+ return global;
}
static JSValueRef
-seed_print (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_print(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *buf;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "print expected 1 argument, got %zd",
- argumentCount);
- return JSValueMakeNull (ctx);
+ gchar* buf;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "print expected 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- buf = seed_value_to_string (ctx, arguments[0], exception);
+ buf = seed_value_to_string(ctx, arguments[0], exception);
- g_print ("%s\n", buf);
- g_free (buf);
+ g_print("%s\n", buf);
+ g_free(buf);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_printerr (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef *exception)
+seed_log_error(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *buf;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "printerr expected 1 argument, got %zd",
- argumentCount);
- return JSValueMakeNull (ctx);
+ gchar* buf1;
+ gchar* buf2 = NULL;
+ if (argumentCount != 1 && argumentCount != 2) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "logError expected 1 or 2 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- buf = seed_value_to_string (ctx, arguments[0], exception);
-
- g_printerr ("%s\n", buf);
- g_free (buf);
-
- return JSValueMakeUndefined (ctx);
-}
-
-const gchar *
-seed_g_type_name_to_string (GITypeInfo * type)
-{
- GITypeTag type_tag = g_type_info_get_tag (type);
-
- const gchar *type_name;
- GIBaseInfo *interface;
-
- if (type_tag == GI_TYPE_TAG_INTERFACE)
- {
- interface = g_type_info_get_interface (type);
-
- type_name = g_base_info_get_name (interface);
- g_base_info_unref (interface);
- }
- else
- {
- type_name = g_type_tag_to_string (type_tag);
+ buf1 = seed_value_to_string(ctx, arguments[0], exception);
+ if (argumentCount == 2) {
+ buf2 = seed_value_to_string(ctx, arguments[1], exception);
+ g_print("%s - %s\n", buf1, buf2);
+ } else {
+ g_print("%s\n", buf1);
}
+ g_free(buf1);
+ g_free(buf2);
- return type_name;
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_introspect (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_printerr(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- // TODO: LEAKY!
-
- GICallableInfo *info;
- JSObjectRef data_obj, args_obj, argument;
- guint i, nargs;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.introspect expected 1 argument, "
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
+ gchar* buf;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "printerr expected 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- if (!JSValueIsObject (ctx, arguments[0]))
- return JSValueMakeNull (ctx);
- if (!JSValueIsObjectOfClass (ctx, arguments[0], gobject_method_class))
- return JSValueMakeNull (ctx);
+ buf = seed_value_to_string(ctx, arguments[0], exception);
- info = (GICallableInfo *) JSObjectGetPrivate ((JSObjectRef) arguments[0]);
- data_obj = JSObjectMake (ctx, NULL, NULL);
+ g_printerr("%s\n", buf);
+ g_free(buf);
- seed_object_set_property (ctx, data_obj, "name", (JSValueRef)
- seed_value_from_string (ctx, g_base_info_get_name
- ((GIBaseInfo *) info),
- exception));
+ return JSValueMakeUndefined(ctx);
+}
- seed_object_set_property (ctx, data_obj, "return_type",
- seed_value_from_string
- (ctx, seed_g_type_name_to_string
- (g_callable_info_get_return_type (info)),
- exception));
+const gchar*
+seed_g_type_name_to_string(GITypeInfo* type)
+{
+ GITypeTag type_tag = g_type_info_get_tag(type);
- args_obj = JSObjectMake (ctx, NULL, NULL);
+ const gchar* type_name;
+ GIBaseInfo* interface;
- seed_object_set_property (ctx, data_obj, "args", args_obj);
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
+ interface = g_type_info_get_interface(type);
- nargs = g_callable_info_get_n_args (info);
- for (i = 0; i < nargs; ++i)
- {
- argument = JSObjectMake (ctx, NULL, NULL);
- GIArgInfo* arg_info = g_callable_info_get_arg (info, i);
- const gchar *arg_type = seed_g_type_name_to_string (
- g_arg_info_get_type(arg_info));
- const gchar *arg_name = g_base_info_get_name((GIBaseInfo*) arg_info);
- GIDirection dir = g_arg_info_get_direction (arg_info);
-
-
- seed_object_set_property (ctx, argument, "type",
- seed_value_from_string (ctx,
- arg_type, exception));
- seed_object_set_property (ctx, argument, "name",
- seed_value_from_string (ctx,
- arg_name, exception));
-
- seed_object_set_property (ctx, argument, "allow_none",
- seed_value_from_boolean (ctx,
- g_arg_info_may_be_null (arg_info) ? 1 : 0, exception));
-
-
- seed_object_set_property (ctx, argument, "direction",
- seed_value_from_string (ctx,
- dir == GI_DIRECTION_OUT ? "out" :
- (dir == GI_DIRECTION_IN ? "in" : "inout")
- , exception));
-
- JSObjectSetPropertyAtIndex (ctx, args_obj, i, argument, NULL);
+ type_name = g_base_info_get_name(interface);
+ g_base_info_unref(interface);
+ } else {
+ type_name = g_type_tag_to_string(type_tag);
}
- return data_obj;
+ return type_name;
}
static JSValueRef
-seed_check_syntax (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_introspect(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSStringRef jsstr;
- if (argumentCount == 1)
- {
- jsstr = JSValueToStringCopy (ctx, arguments[0], exception);
-
- JSCheckScriptSyntax (ctx, jsstr, 0, 0, exception);
- if (jsstr)
- JSStringRelease (jsstr);
+ // TODO: LEAKY!
+
+ GICallableInfo* info;
+ JSObjectRef data_obj, args_obj, argument;
+ guint i, nargs;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.introspect expected 1 argument, "
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- else
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.check_syntax expected "
- "1 argument, got %zd", argumentCount);
+
+ if (!JSValueIsObject(ctx, arguments[0]))
+ return JSValueMakeNull(ctx);
+ if (!JSValueIsObjectOfClass(ctx, arguments[0], gobject_method_class))
+ return JSValueMakeNull(ctx);
+
+ info = (GICallableInfo*) JSObjectGetPrivate((JSObjectRef) arguments[0]);
+ data_obj = JSObjectMake(ctx, NULL, NULL);
+
+ seed_object_set_property(ctx, data_obj, "name",
+ (JSValueRef) seed_value_from_string(
+ ctx, g_base_info_get_name((GIBaseInfo*) info),
+ exception));
+
+ seed_object_set_property(
+ ctx, data_obj, "return_type",
+ seed_value_from_string(ctx, seed_g_type_name_to_string(
+ g_callable_info_get_return_type(info)),
+ exception));
+
+ args_obj = JSObjectMake(ctx, NULL, NULL);
+
+ seed_object_set_property(ctx, data_obj, "args", args_obj);
+
+ nargs = g_callable_info_get_n_args(info);
+ for (i = 0; i < nargs; ++i) {
+ argument = JSObjectMake(ctx, NULL, NULL);
+ GIArgInfo* arg_info = g_callable_info_get_arg(info, i);
+ const gchar* arg_type
+ = seed_g_type_name_to_string(g_arg_info_get_type(arg_info));
+ const gchar* arg_name = g_base_info_get_name((GIBaseInfo*) arg_info);
+ GIDirection dir = g_arg_info_get_direction(arg_info);
+
+ seed_object_set_property(ctx, argument, "type",
+ seed_value_from_string(ctx, arg_type,
+ exception));
+ seed_object_set_property(ctx, argument, "name",
+ seed_value_from_string(ctx, arg_name,
+ exception));
+
+ seed_object_set_property(
+ ctx, argument, "allow_none",
+ seed_value_from_boolean(ctx, g_arg_info_may_be_null(arg_info) ? 1 : 0,
+ exception));
+
+ seed_object_set_property(
+ ctx, argument, "direction",
+ seed_value_from_string(ctx,
+ dir == GI_DIRECTION_OUT
+ ? "out"
+ : (dir == GI_DIRECTION_IN ? "in" : "inout"),
+ exception));
+
+ JSObjectSetPropertyAtIndex(ctx, args_obj, i, argument, NULL);
}
- return JSValueMakeNull (ctx);
+
+ return data_obj;
}
static JSValueRef
-seed_spawn (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_check_syntax(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *line, *stdoutstr, *stderrstr;
- JSObjectRef ret;
- GError *error = NULL;
+ JSStringRef jsstr;
+ if (argumentCount == 1) {
+ jsstr = JSValueToStringCopy(ctx, arguments[0], exception);
+
+ JSCheckScriptSyntax(ctx, jsstr, 0, 0, exception);
+ if (jsstr)
+ JSStringRelease(jsstr);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.check_syntax expected "
+ "1 argument, got %zd",
+ argumentCount);
+ }
+ return JSValueMakeNull(ctx);
+}
- if (argumentCount != 1)
- {
- // I am so lazy
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.spawn expected 1 argument");
- return JSValueMakeNull (ctx);
+static JSValueRef
+seed_spawn(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ gchar *line, *stdoutstr, *stderrstr;
+ JSObjectRef ret;
+ GError* error = NULL;
+
+ if (argumentCount != 1) {
+ // I am so lazy
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.spawn expected 1 argument");
+ return JSValueMakeNull(ctx);
}
- line = seed_value_to_string (ctx, arguments[0], exception);
- g_spawn_command_line_sync (line, &stdoutstr, &stderrstr, NULL, &error);
- if (error)
- {
- seed_make_exception_from_gerror (ctx, exception, error);
+ line = seed_value_to_string(ctx, arguments[0], exception);
+ g_spawn_command_line_sync(line, &stdoutstr, &stderrstr, NULL, &error);
+ if (error) {
+ seed_make_exception_from_gerror(ctx, exception, error);
- g_free (line);
- g_error_free (error);
- return JSValueMakeNull (ctx);
+ g_free(line);
+ g_error_free(error);
+ return JSValueMakeNull(ctx);
}
- ret = JSObjectMake (ctx, NULL, NULL);
- seed_object_set_property (ctx, ret, "stdout",
- seed_value_from_string (ctx, stdoutstr,
- exception));
- seed_object_set_property (ctx, ret, "stderr",
- seed_value_from_string (ctx, stderrstr,
- exception));
+ ret = JSObjectMake(ctx, NULL, NULL);
+ seed_object_set_property(ctx, ret, "stdout",
+ seed_value_from_string(ctx, stdoutstr, exception));
+ seed_object_set_property(ctx, ret, "stderr",
+ seed_value_from_string(ctx, stderrstr, exception));
- g_free (line);
- g_free (stdoutstr);
- g_free (stderrstr);
+ g_free(line);
+ g_free(stdoutstr);
+ g_free(stderrstr);
- return ret;
+ return ret;
}
static JSValueRef
-seed_quit (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_quit(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- if (argumentCount == 1)
- {
- exit (seed_value_to_int (ctx, arguments[0], NULL));
- }
- else if (argumentCount > 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.quit expected " "1 argument, got %zd",
- argumentCount);
+ if (argumentCount == 1) {
+ exit(seed_value_to_int(ctx, arguments[0], NULL));
+ } else if (argumentCount > 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.quit expected "
+ "1 argument, got %zd",
+ argumentCount);
}
- exit (EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static JSValueRef
-seed_breakpoint (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_breakpoint(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- G_BREAKPOINT ();
- return JSValueMakeUndefined (ctx);
+ G_BREAKPOINT();
+ return JSValueMakeUndefined(ctx);
}
-
static JSValueRef
-seed_argv_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_argv_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- SeedArgvPrivates *priv;
- gchar *cproperty_name;
- gsize length;
- guint index;
-
- priv = JSObjectGetPrivate (object);
- if (!priv->argc)
- return JSValueMakeUndefined (ctx);
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- if (!g_strcmp0 (cproperty_name, "length"))
- {
- return seed_value_from_int (ctx, priv->argc, exception);
+ SeedArgvPrivates* priv;
+ gchar* cproperty_name;
+ gsize length;
+ gint index;
+
+ priv = JSObjectGetPrivate(object);
+ if (!priv->argc)
+ return JSValueMakeUndefined(ctx);
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ if (!g_strcmp0(cproperty_name, "length")) {
+ return seed_value_from_int(ctx, priv->argc, exception);
+ }
+ index = atoi(cproperty_name);
+ if (index >= 0 && index < priv->argc) {
+ return seed_value_from_string(ctx, priv->argv[index], exception);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError", "ArgumentCount "
+ "%d, got %d",
+ priv->argc, index);
+ return JSValueMakeNull(ctx);
}
- index = atoi (cproperty_name);
- return seed_value_from_string (ctx, priv->argv[index], exception);
}
JSClassDefinition seed_argv_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
- "argv_array", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL,
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_argv_get_property, /* Get Property */
- NULL,
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "argv_array", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_argv_get_property, /* Get Property */
+ NULL,
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassRef seed_argv_class;
-void
-seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
+static JSValueRef
+seed_ARGV_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- SeedArgvPrivates *priv;
- JSObjectRef arrayObj;
- JSObjectRef obj =
- (JSObjectRef) seed_object_get_property (local_eng->context,
- local_eng->global,
- "Seed");
-
- seed_create_function (local_eng->context, "include", &seed_include, obj);
- seed_create_function (local_eng->context, "scoped_include",
- &seed_scoped_include, obj);
-
- seed_print_ref =
- JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_print);
- seed_object_set_property (local_eng->context, obj, "print", seed_print_ref);
- seed_object_set_property (local_eng->context, local_eng->global, "print",
- seed_print_ref);
- JSValueProtect (local_eng->context, seed_print_ref);
-
- seed_printerr_ref =
- JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_printerr);
- seed_object_set_property (local_eng->context, obj, "printerr", seed_printerr_ref);
- seed_object_set_property (local_eng->context, local_eng->global, "printerr",
- seed_printerr_ref);
- JSValueProtect (local_eng->context, seed_printerr_ref);
-
- seed_create_function (local_eng->context,
- "check_syntax", &seed_check_syntax, obj);
- seed_create_function (local_eng->context,
- "introspect", &seed_introspect, obj);
- seed_create_function (local_eng->context, "spawn", &seed_spawn, obj);
- seed_create_function (local_eng->context, "quit", &seed_quit, obj);
- seed_create_function (local_eng->context, "breakpoint",
- &seed_breakpoint, obj);
-
- priv = g_new0 (SeedArgvPrivates, 1);
- priv->argv = argv ? *argv : 0;
- priv->argc = argc ? *argc : 0;
-
- seed_argv_class = JSClassCreate (&seed_argv_def);
- arrayObj = JSObjectMake (local_eng->context, seed_argv_class, priv);
-
- seed_object_set_property (local_eng->context, obj, "argv", arrayObj);
+ SeedArgvPrivates* priv;
+ gchar* cproperty_name;
+ gsize length;
+ gint index;
+
+ priv = JSObjectGetPrivate(object);
+ if (!priv->argc)
+ return JSValueMakeUndefined(ctx);
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ if (!g_strcmp0(cproperty_name, "length")) {
+ return seed_value_from_int(ctx, priv->argc - 2, exception);
+ }
+ index = atoi(cproperty_name);
+ if (index >= 0 && index < priv->argc - 2) {
+ return seed_value_from_string(ctx, priv->argv[index + 2], exception);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError", "ArgumentCount "
+ "%d, got %d",
+ priv->argc - 2, index);
+ return JSValueMakeNull(ctx);
+ }
+}
+
+JSClassDefinition seed_ARGV_def = {
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "argv_array", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_ARGV_get_property, /* Get Property */
+ NULL,
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
+};
+JSClassRef seed_ARGV_class;
+
+void
+seed_init_builtins(SeedEngine* local_eng, gint* argc, gchar*** argv)
+{
+ SeedArgvPrivates* priv;
+ JSObjectRef argvArrayObj;
+ JSObjectRef ARGVArrayObj;
+ JSObjectRef obj
+ = (JSObjectRef) seed_object_get_property(local_eng->context,
+ local_eng->global, "Seed");
+
+ seed_create_function(local_eng->context, "include", &seed_include, obj);
+ seed_create_function(local_eng->context, "scoped_include",
+ &seed_scoped_include, obj);
+
+ seed_print_ref
+ = JSObjectMakeFunctionWithCallback(local_eng->context, NULL, &seed_print);
+ seed_object_set_property(local_eng->context, obj, "print", seed_print_ref);
+ seed_object_set_property(local_eng->context, local_eng->global, "print",
+ seed_print_ref);
+ seed_object_set_property(local_eng->context, local_eng->global, "log",
+ seed_print_ref);
+ JSValueProtect(local_eng->context, seed_print_ref);
+
+ seed_printerr_ref = JSObjectMakeFunctionWithCallback(local_eng->context,
+ NULL, &seed_printerr);
+ seed_object_set_property(local_eng->context, obj, "printerr",
+ seed_printerr_ref);
+ seed_object_set_property(local_eng->context, local_eng->global, "printerr",
+ seed_printerr_ref);
+ JSValueProtect(local_eng->context, seed_printerr_ref);
+
+ seed_log_error_ref
+ = JSObjectMakeFunctionWithCallback(local_eng->context, NULL,
+ &seed_log_error);
+ seed_object_set_property(local_eng->context, local_eng->global, "logError",
+ seed_log_error_ref);
+ JSValueProtect(local_eng->context, seed_log_error_ref);
+
+ seed_create_function(local_eng->context, "check_syntax", &seed_check_syntax,
+ obj);
+ seed_create_function(local_eng->context, "introspect", &seed_introspect,
+ obj);
+ seed_create_function(local_eng->context, "spawn", &seed_spawn, obj);
+ seed_create_function(local_eng->context, "quit", &seed_quit, obj);
+ seed_create_function(local_eng->context, "breakpoint", &seed_breakpoint,
+ obj);
+
+ priv = g_new0(SeedArgvPrivates, 1);
+ priv->argv = argv ? *argv : 0;
+ priv->argc = argc ? *argc : 0;
+
+ seed_argv_class = JSClassCreate(&seed_argv_def);
+ argvArrayObj = JSObjectMake(local_eng->context, seed_argv_class, priv);
+
+ seed_object_set_property(local_eng->context, obj, "argv", argvArrayObj);
+
+ seed_ARGV_class = JSClassCreate(&seed_ARGV_def);
+ ARGVArrayObj = JSObjectMake(local_eng->context, seed_ARGV_class, priv);
+
+ seed_object_set_property(local_eng->context, local_eng->global, "ARGV",
+ ARGVArrayObj);
}
diff --git a/libseed/seed-builtins.h b/libseed/seed-builtins.h
index 762ecc9..4386de4 100644
--- a/libseed/seed-builtins.h
+++ b/libseed/seed-builtins.h
@@ -25,14 +25,13 @@
extern JSValueRef seed_print_ref;
extern JSValueRef seed_printerr_ref;
-void seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv);
+void seed_init_builtins(SeedEngine* local_eng, gint* argc, gchar*** argv);
extern JSClassRef seed_argv_class;
typedef struct _SeedArgvPrivates
{
- gchar **argv;
- gint argc;
+ gchar** argv;
+ gint argc;
} SeedArgvPrivates;
-
#endif
diff --git a/libseed/seed-closure.c b/libseed/seed-closure.c
index 62241c8..dc88258 100644
--- a/libseed/seed-closure.c
+++ b/libseed/seed-closure.c
@@ -24,457 +24,439 @@
JSClassRef seed_native_callback_class;
static void
-seed_closure_finalize (JSObjectRef object)
+seed_closure_finalize(JSObjectRef object)
{
- SeedNativeClosure *privates =
- (SeedNativeClosure *) JSObjectGetPrivate (object);
+ SeedNativeClosure* privates
+ = (SeedNativeClosure*) JSObjectGetPrivate(object);
- SEED_NOTE (FINALIZATION, "Finalizing closure object %p with "
- "GIBaseInfo: %s \n", object,
- g_base_info_get_name ((GIBaseInfo *) privates->info));
+ SEED_NOTE(FINALIZATION, "Finalizing closure object %p with "
+ "GIBaseInfo: %s \n",
+ object, g_base_info_get_name((GIBaseInfo*) privates->info));
- g_free (privates->cif->arg_types);
- g_free (privates->cif);
- g_callable_info_free_closure (privates->info, privates->closure);
- g_base_info_unref ((GIBaseInfo *) privates->info);
-
- JSValueUnprotect (eng->context, object);
+ g_free(privates->cif->arg_types);
+ g_free(privates->cif);
+ g_callable_info_free_closure(privates->info, privates->closure);
+ g_base_info_unref((GIBaseInfo*) privates->info);
}
static void
-seed_handle_closure (ffi_cif * cif, void *result, void **args, gpointer userdata)
+seed_handle_closure(ffi_cif* cif, void* result, void** args, gpointer userdata)
{
- SeedNativeClosure *privates = userdata;
- gint num_args, i;
- JSValueRef *jsargs;
- JSValueRef return_value, exception = 0;
- GITypeTag return_tag;
- GIArgInfo *arg_info;
- GITypeInfo *return_type;
- GITypeInfo *arg_type;
- GITypeTag tag;
- GArgument rarg, return_arg;
- JSContextRef ctx = JSGlobalContextCreateInGroup (
- context_group, 0);
- GArgument *arg = &rarg;
- gchar *mes;
-
- seed_prepare_global_context (ctx);
-
- SEED_NOTE (INVOCATION, "Invoking closure of type: %s \n",
- g_base_info_get_name ((GIBaseInfo *) privates->info));
-
- num_args = g_callable_info_get_n_args (privates->info);
- return_type = g_callable_info_get_return_type (privates->info);
- return_tag = g_type_info_get_tag (return_type);
- jsargs = (JSValueRef *) g_newa (JSValueRef, num_args);
-
- for (i = 0; i < num_args; i++)
- {
-
- arg_info = g_callable_info_get_arg (privates->info, i);
- arg_type = g_arg_info_get_type (arg_info);
- tag = g_type_info_get_tag (arg_type);
-
- switch (tag)
- {
+ SeedNativeClosure* privates = userdata;
+ gint num_args, i;
+ JSValueRef* jsargs;
+ JSValueRef return_value, exception = 0;
+ GITypeTag return_tag;
+ GIArgInfo* arg_info;
+ GITypeInfo* return_type;
+ GITypeInfo* arg_type;
+ GITypeTag tag;
+ GArgument rarg, return_arg;
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ GArgument* arg = &rarg;
+ gchar* mes;
+
+ seed_prepare_global_context(ctx);
+
+ SEED_NOTE(INVOCATION, "Invoking closure of type: %s \n",
+ g_base_info_get_name((GIBaseInfo*) privates->info));
+
+ num_args = g_callable_info_get_n_args(privates->info);
+ return_type = g_callable_info_get_return_type(privates->info);
+ return_tag = g_type_info_get_tag(return_type);
+ jsargs = (JSValueRef*) g_newa(JSValueRef, num_args);
+
+ for (i = 0; i < num_args; i++) {
+
+ arg_info = g_callable_info_get_arg(privates->info, i);
+ arg_type = g_arg_info_get_type(arg_info);
+ tag = g_type_info_get_tag(arg_type);
+
+ switch (tag) {
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- arg->v_long = *(glong *) args[i];
- break;
- case GI_TYPE_TAG_ULONG:
- arg->v_ulong = *(gulong *) args[i];
- break;
- case GI_TYPE_TAG_INT:
- arg->v_int = *(gint *) args[i];
- break;
- case GI_TYPE_TAG_SSIZE:
- arg->v_ssize = *(gssize *) args[i];
- break;
- case GI_TYPE_TAG_SIZE:
- arg->v_size = *(gsize *) args[i];
- break;
- case GI_TYPE_TAG_UINT:
- arg->v_uint = *(guint *) args[i];
- break;
+ case GI_TYPE_TAG_LONG:
+ arg->v_long = *(glong*) args[i];
+ break;
+ case GI_TYPE_TAG_ULONG:
+ arg->v_ulong = *(gulong*) args[i];
+ break;
+ case GI_TYPE_TAG_INT:
+ arg->v_int = *(gint*) args[i];
+ break;
+ case GI_TYPE_TAG_SSIZE:
+ arg->v_ssize = *(gssize*) args[i];
+ break;
+ case GI_TYPE_TAG_SIZE:
+ arg->v_size = *(gsize*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT:
+ arg->v_uint = *(guint*) args[i];
+ break;
#endif
- case GI_TYPE_TAG_BOOLEAN:
- arg->v_boolean = *(gboolean *) args[i];
- break;
- case GI_TYPE_TAG_INT8:
- arg->v_int8 = *(gint8 *) args[i];
- break;
- case GI_TYPE_TAG_UINT8:
- arg->v_uint8 = *(guint8 *) args[i];
- break;
- case GI_TYPE_TAG_INT16:
- arg->v_int16 = *(gint16 *) args[i];
- break;
- case GI_TYPE_TAG_UINT16:
- arg->v_uint16 = *(guint16 *) args[i];
- break;
- case GI_TYPE_TAG_INT32:
- arg->v_int32 = *(gint32 *) args[i];
- break;
- case GI_TYPE_TAG_UINT32:
- arg->v_uint32 = *(guint32 *) args[i];
- break;
- case GI_TYPE_TAG_INT64:
- arg->v_int64 = *(gint64 *) args[i];
- break;
- case GI_TYPE_TAG_UINT64:
- arg->v_uint64 = *(guint64 *) args[i];
- break;
- case GI_TYPE_TAG_FLOAT:
- arg->v_float = *(gfloat *) args[i];
- break;
- case GI_TYPE_TAG_DOUBLE:
- arg->v_double = *(gdouble *) args[i];
- break;
- case GI_TYPE_TAG_UTF8:
- arg->v_string = *(gchar **) args[i];
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (arg_type);
- interface_type = g_base_info_get_type (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- arg->v_pointer = *(gpointer *) args[i];
- g_base_info_unref (interface);
- break;
- }
-
- else if (interface_type == GI_INFO_TYPE_ENUM ||
- interface_type == GI_INFO_TYPE_FLAGS)
- {
- arg->v_double = *(double *) args[i];
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT)
- {
- arg->v_pointer = *(gpointer *) args[i];
- g_base_info_unref (interface);
- break;
- }
-
- g_base_info_unref (interface);
- }
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- arg->v_pointer = *(gpointer *) args[i];
- break;
- default:
- arg->v_pointer = 0;
- }
- jsargs[i] = seed_value_from_gi_argument (ctx, arg, arg_type, 0);
- seed_gi_release_arg (g_arg_info_get_ownership_transfer (arg_info),
- arg_type, arg);
- g_base_info_unref ((GIBaseInfo *) arg_info);
- g_base_info_unref ((GIBaseInfo *) arg_type);
+ case GI_TYPE_TAG_BOOLEAN:
+ arg->v_boolean = *(gboolean*) args[i];
+ break;
+ case GI_TYPE_TAG_INT8:
+ arg->v_int8 = *(gint8*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT8:
+ arg->v_uint8 = *(guint8*) args[i];
+ break;
+ case GI_TYPE_TAG_INT16:
+ arg->v_int16 = *(gint16*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT16:
+ arg->v_uint16 = *(guint16*) args[i];
+ break;
+ case GI_TYPE_TAG_INT32:
+ arg->v_int32 = *(gint32*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT32:
+ arg->v_uint32 = *(guint32*) args[i];
+ break;
+ case GI_TYPE_TAG_INT64:
+ arg->v_int64 = *(gint64*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT64:
+ arg->v_uint64 = *(guint64*) args[i];
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ arg->v_float = *(gfloat*) args[i];
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ arg->v_double = *(gdouble*) args[i];
+ break;
+ case GI_TYPE_TAG_UTF8:
+ arg->v_string = *(gchar**) args[i];
+ break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(arg_type);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ arg->v_pointer = *(gpointer*) args[i];
+ g_base_info_unref(interface);
+ break;
+ }
+
+ else if (interface_type == GI_INFO_TYPE_ENUM
+ || interface_type == GI_INFO_TYPE_FLAGS) {
+ arg->v_double = *(double*) args[i];
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+ arg->v_pointer = *(gpointer*) args[i];
+ g_base_info_unref(interface);
+ break;
+ }
+
+ g_base_info_unref(interface);
+ }
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ arg->v_pointer = *(gpointer*) args[i];
+ break;
+ default:
+ arg->v_pointer = 0;
+ }
+ jsargs[i] = seed_value_from_gi_argument(ctx, arg, arg_type, 0);
+ seed_gi_release_arg(g_arg_info_get_ownership_transfer(arg_info),
+ arg_type, arg);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ g_base_info_unref((GIBaseInfo*) arg_type);
}
- return_value = (JSValueRef)
- JSObjectCallAsFunction (ctx,
- (JSObjectRef) privates->function, 0,
- num_args, jsargs, &exception);
-
- if (exception)
- {
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in closure marshal. %s \n", mes);
- g_free (mes);
- exception = 0;
+ return_value
+ = (JSValueRef) JSObjectCallAsFunction(ctx,
+ (JSObjectRef) privates->function, 0,
+ num_args, jsargs, &exception);
+
+ if (exception) {
+ mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in closure marshal. %s \n", mes);
+ g_free(mes);
+ exception = 0;
}
- seed_value_to_gi_argument (ctx, (JSValueRef) return_value, return_type,
- &return_arg, 0);
- switch (return_tag)
- {
+ seed_value_to_gi_argument(ctx, (JSValueRef) return_value, return_type,
+ GI_TRANSFER_NOTHING, &return_arg, 0);
+
+ switch (return_tag) {
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- *(glong *) result = return_arg.v_long;
- break;
- case GI_TYPE_TAG_ULONG:
- *(gulong *) result = return_arg.v_ulong;
- break;
- case GI_TYPE_TAG_INT:
- *(gint *) result = return_arg.v_int;
- break;
- case GI_TYPE_TAG_SSIZE:
- *(gssize *) result = return_arg.v_ssize;
- break;
- case GI_TYPE_TAG_SIZE:
- *(gsize *) result = return_arg.v_size;
- break;
- case GI_TYPE_TAG_UINT:
- *(guint *) result = return_arg.v_uint;
- break;
+ case GI_TYPE_TAG_LONG:
+ *(glong*) result = return_arg.v_long;
+ break;
+ case GI_TYPE_TAG_ULONG:
+ *(gulong*) result = return_arg.v_ulong;
+ break;
+ case GI_TYPE_TAG_INT:
+ *(gint*) result = return_arg.v_int;
+ break;
+ case GI_TYPE_TAG_SSIZE:
+ *(gssize*) result = return_arg.v_ssize;
+ break;
+ case GI_TYPE_TAG_SIZE:
+ *(gsize*) result = return_arg.v_size;
+ break;
+ case GI_TYPE_TAG_UINT:
+ *(guint*) result = return_arg.v_uint;
+ break;
#endif
- case GI_TYPE_TAG_BOOLEAN:
- *(gboolean *) result = return_arg.v_boolean;
- break;
- case GI_TYPE_TAG_INT8:
- *(gint8 *) result = return_arg.v_int8;
- break;
- case GI_TYPE_TAG_UINT8:
- *(guint8 *) result = return_arg.v_uint8;
- break;
- case GI_TYPE_TAG_INT16:
- *(gint16 *) result = return_arg.v_int16;
- break;
- case GI_TYPE_TAG_UINT16:
- *(guint16 *) result = return_arg.v_uint16;
- break;
- case GI_TYPE_TAG_INT32:
- *(gint32 *) result = return_arg.v_int32;
- break;
- case GI_TYPE_TAG_UINT32:
- *(guint32 *) result = return_arg.v_uint32;
- break;
- case GI_TYPE_TAG_INT64:
- *(gint64 *) result = return_arg.v_int64;
- break;
- case GI_TYPE_TAG_UINT64:
- *(guint64 *) result = return_arg.v_uint64;
- break;
- case GI_TYPE_TAG_FLOAT:
- *(gfloat *) result = return_arg.v_float;
- break;
- case GI_TYPE_TAG_DOUBLE:
- *(gdouble *) result = return_arg.v_double;
- break;
- case GI_TYPE_TAG_UTF8:
- *(gchar **) result = return_arg.v_string;
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (return_type);
- interface_type = g_base_info_get_type (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- *(gpointer *) result = return_arg.v_pointer;
- break;
- }
-
- else if (interface_type == GI_INFO_TYPE_ENUM ||
- interface_type == GI_INFO_TYPE_FLAGS)
- {
- *(double *) result = return_arg.v_double;
- break;
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT)
- {
- *(gpointer *) result = return_arg.v_pointer;
- break;
- }
- }
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- *(gpointer *) result = return_arg.v_pointer;
- break;
- default:
- *(gpointer *) result = 0;
+ case GI_TYPE_TAG_BOOLEAN:
+ *(gboolean*) result = return_arg.v_boolean;
+ break;
+ case GI_TYPE_TAG_INT8:
+ *(gint8*) result = return_arg.v_int8;
+ break;
+ case GI_TYPE_TAG_UINT8:
+ *(guint8*) result = return_arg.v_uint8;
+ break;
+ case GI_TYPE_TAG_INT16:
+ *(gint16*) result = return_arg.v_int16;
+ break;
+ case GI_TYPE_TAG_UINT16:
+ *(guint16*) result = return_arg.v_uint16;
+ break;
+ case GI_TYPE_TAG_INT32:
+ *(gint32*) result = return_arg.v_int32;
+ break;
+ case GI_TYPE_TAG_UINT32:
+ *(guint32*) result = return_arg.v_uint32;
+ break;
+ case GI_TYPE_TAG_INT64:
+ *(gint64*) result = return_arg.v_int64;
+ break;
+ case GI_TYPE_TAG_UINT64:
+ *(guint64*) result = return_arg.v_uint64;
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ *(gfloat*) result = return_arg.v_float;
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ *(gdouble*) result = return_arg.v_double;
+ break;
+ case GI_TYPE_TAG_UTF8:
+ *(gchar**) result = return_arg.v_string;
+ break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(return_type);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ *(gpointer*) result = return_arg.v_pointer;
+ break;
+ }
+
+ else if (interface_type == GI_INFO_TYPE_ENUM
+ || interface_type == GI_INFO_TYPE_FLAGS) {
+ *(double*) result = return_arg.v_double;
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+ *(gpointer*) result = return_arg.v_pointer;
+ break;
+ }
+ }
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ *(gpointer*) result = return_arg.v_pointer;
+ break;
+ default:
+ *(gpointer*) result = 0;
}
- g_base_info_unref ((GIBaseInfo *) return_type);
-
- JSGarbageCollect(ctx);
+ g_base_info_unref((GIBaseInfo*) return_type);
+
+ JSGarbageCollect(ctx);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
-SeedNativeClosure *
-seed_make_native_closure (JSContextRef ctx,
- GICallableInfo * info,
- JSValueRef function)
+SeedNativeClosure*
+seed_make_native_closure(JSContextRef ctx,
+ GICallableInfo* info,
+ JSValueRef function)
{
- ffi_cif *cif;
- ffi_closure *closure;
- GITypeInfo *return_type;
- SeedNativeClosure *privates;
- JSObjectRef cached;
-
- cached =
- (JSObjectRef) seed_object_get_property (ctx, (JSObjectRef) function,
- "__seed_native_closure");
- if (cached
- && JSValueIsObjectOfClass (ctx, cached, seed_native_callback_class))
- {
- return (SeedNativeClosure *) JSObjectGetPrivate (cached);
+ ffi_cif* cif;
+ ffi_closure* closure;
+ GITypeInfo* return_type;
+ SeedNativeClosure* privates;
+ JSObjectRef cached;
+
+ cached = (JSObjectRef) seed_object_get_property(ctx, (JSObjectRef) function,
+ "__seed_native_closure");
+ if (cached
+ && JSValueIsObjectOfClass(ctx, cached, seed_native_callback_class)) {
+ return (SeedNativeClosure*) JSObjectGetPrivate(cached);
}
- return_type = g_callable_info_get_return_type (info);
- cif = g_new0 (ffi_cif, 1);
+ return_type = g_callable_info_get_return_type(info);
+ cif = g_new0(ffi_cif, 1);
- privates = g_new0 (SeedNativeClosure, 1);
- privates->ctx = ctx;
- privates->info = (GICallableInfo *) g_base_info_ref ((GIBaseInfo *) info);
- privates->function = function;
- privates->cif = cif;
+ privates = g_new0(SeedNativeClosure, 1);
+ privates->ctx = ctx;
+ privates->info = (GICallableInfo*) g_base_info_ref((GIBaseInfo*) info);
+ privates->function = function;
+ privates->cif = cif;
- closure =
- g_callable_info_prepare_closure (info, cif, seed_handle_closure,
- privates);
- privates->closure = closure;
+ closure = g_callable_info_prepare_closure(info, cif, seed_handle_closure,
+ privates);
+ privates->closure = closure;
- JSValueProtect (ctx, function);
+ JSValueProtect(ctx, function);
- seed_object_set_property (ctx, (JSObjectRef) function,
- "__seed_native_closure",
- (JSValueRef) JSObjectMake (ctx,
- seed_native_callback_class,
- privates));
+ seed_object_set_property(
+ ctx, (JSObjectRef) function, "__seed_native_closure",
+ (JSValueRef) JSObjectMake(ctx, seed_native_callback_class, privates));
- g_base_info_unref ((GIBaseInfo *) return_type);
+ g_base_info_unref((GIBaseInfo*) return_type);
- return privates;
+ return privates;
}
static void
-closure_invalidated (gpointer data, GClosure * c)
+closure_invalidated(gpointer data, GClosure* c)
{
- SeedClosure *closure = (SeedClosure *) c;
+ SeedClosure* closure = (SeedClosure*) c;
- SEED_NOTE (FINALIZATION, "Finalizing closure.");
- if (closure->user_data
- && !JSValueIsUndefined (eng->context, closure->user_data))
- JSValueUnprotect (eng->context, closure->user_data);
- if (!JSValueIsUndefined (eng->context, closure->function))
- JSValueUnprotect (eng->context, closure->function);
-
- g_free (closure->description);
+ SEED_NOTE(FINALIZATION, "Finalizing closure.");
+ if (closure->user_data
+ && !JSValueIsUndefined(eng->context, closure->user_data))
+ JSValueUnprotect(eng->context, closure->user_data);
+ if (!JSValueIsUndefined(eng->context, closure->function))
+ JSValueUnprotect(eng->context, closure->function);
+ g_free(closure->description);
}
JSObjectRef
-seed_closure_get_callable (GClosure * c)
+seed_closure_get_callable(GClosure* c)
{
- return ((SeedClosure *) c)->function;
+ return ((SeedClosure*) c)->function;
}
JSValueRef
-seed_closure_invoke (GClosure * closure, JSValueRef * args, guint argc,
- JSValueRef * exception)
+seed_closure_invoke(GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception)
{
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
- JSValueRef ret;
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ JSValueRef ret;
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- ret =
- seed_closure_invoke_with_context (ctx, closure, args, argc, exception);
+ ret = seed_closure_invoke_with_context(ctx, closure, args, argc, exception);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
- return ret;
+ return ret;
}
JSValueRef
-seed_closure_invoke_with_context (JSContextRef ctx, GClosure * closure,
- JSValueRef * args, guint argc,
- JSValueRef * exception)
+seed_closure_invoke_with_context(JSContextRef ctx,
+ GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception)
{
- JSValueRef *real_args = g_newa (JSValueRef, argc + 1);
- guint i;
-
- for (i = 0; i < argc; i++)
- real_args[i] = args[i];
- real_args[argc] =
- ((SeedClosure *) closure)->user_data ? ((SeedClosure *) closure)->
- user_data : JSValueMakeNull (ctx);
-
- return
- JSObjectCallAsFunction (ctx, ((SeedClosure *) closure)->function, NULL,
- argc + 1, real_args, exception);
+ JSValueRef* real_args = g_newa(JSValueRef, argc + 1);
+ guint i;
+
+ for (i = 0; i < argc; i++)
+ real_args[i] = args[i];
+ real_args[argc] = ((SeedClosure*) closure)->user_data
+ ? ((SeedClosure*) closure)->user_data
+ : JSValueMakeNull(ctx);
+
+ return JSObjectCallAsFunction(ctx, ((SeedClosure*) closure)->function, NULL,
+ argc + 1, real_args, exception);
}
-GClosure *
-seed_closure_new_for_signal (JSContextRef ctx, JSObjectRef function,
- JSObjectRef user_data, const gchar * description,
- guint signal_id)
+GClosure*
+seed_closure_new_for_signal(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description,
+ guint signal_id)
{
- GClosure *closure;
-
- closure = g_closure_new_simple (sizeof (SeedClosure), 0);
- g_closure_add_finalize_notifier (closure, 0, closure_invalidated);
- g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (signal_id),
- seed_signal_marshal_func);
-
- JSValueProtect (ctx, function);
- ((SeedClosure *) closure)->function = function;
- if (user_data && !JSValueIsNull (ctx, user_data))
- {
- ((SeedClosure *) closure)->user_data = user_data;
- JSValueProtect (ctx, user_data);
+ GClosure* closure;
+
+ closure = g_closure_new_simple(sizeof(SeedClosure), 0);
+ g_closure_add_finalize_notifier(closure, 0, closure_invalidated);
+ g_closure_set_meta_marshal(closure, GUINT_TO_POINTER(signal_id),
+ seed_signal_marshal_func);
+
+ JSValueProtect(ctx, function);
+ ((SeedClosure*) closure)->function = function;
+ if (user_data && !JSValueIsNull(ctx, user_data)) {
+ ((SeedClosure*) closure)->user_data = user_data;
+ JSValueProtect(ctx, user_data);
}
- if (description)
- ((SeedClosure *) closure)->description = g_strdup (description);
+ if (description)
+ ((SeedClosure*) closure)->description = g_strdup(description);
- return closure;
+ return closure;
}
-GClosure *
-seed_closure_new (JSContextRef ctx, JSObjectRef function,
- JSObjectRef user_data, const gchar * description)
+GClosure*
+seed_closure_new(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description)
{
- return seed_closure_new_for_signal (ctx, function, user_data, description,
- 0);
+ return seed_closure_new_for_signal(ctx, function, user_data, description,
+ 0);
}
void
-seed_closure_warn_exception (GClosure * c,
- JSContextRef ctx, JSValueRef exception)
+seed_closure_warn_exception(GClosure* c, JSContextRef ctx, JSValueRef exception)
{
- JSObjectRef callable = seed_closure_get_callable (c);
- gchar *name = seed_value_to_string (ctx,
- seed_object_get_property (ctx, callable,
- "name"),
- NULL);
- gchar *mes = seed_exception_to_string (ctx, exception);
-
- g_warning ("Exception in closure (%p) for %s (handler %s). %s", c,
- ((SeedClosure *) c)->description,
- *name == '\0' ? "[anonymous]" : name, mes);
-
- g_free (name);
- g_free (mes);
+ JSObjectRef callable = seed_closure_get_callable(c);
+ gchar* name
+ = seed_value_to_string(ctx,
+ seed_object_get_property(ctx, callable, "name"),
+ NULL);
+ gchar* mes = seed_exception_to_string(ctx, exception);
+
+ g_warning("Exception in closure (%p) for %s (handler %s). %s", c,
+ ((SeedClosure*) c)->description,
+ *name == '\0' ? "[anonymous]" : name, mes);
+
+ g_free(name);
+ g_free(mes);
}
JSClassDefinition seed_native_callback_def = {
- 0, /* Version, always 0 */
- 0,
- "seed_native_callback", /* Class Name */
- 0, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_closure_finalize, /* 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 */
+ 0, /* Version, always 0 */
+ 0, "seed_native_callback", /* Class Name */
+ 0, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, seed_closure_finalize, /* 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 */
};
void
-seed_closures_init (void)
+seed_closures_init(void)
{
- seed_native_callback_class = JSClassCreate (&seed_native_callback_def);
- JSClassRetain (seed_native_callback_class);
+ seed_native_callback_class = JSClassCreate(&seed_native_callback_def);
+ JSClassRetain(seed_native_callback_class);
}
diff --git a/libseed/seed-closure.h b/libseed/seed-closure.h
index 49246f1..03590a1 100644
--- a/libseed/seed-closure.h
+++ b/libseed/seed-closure.h
@@ -24,58 +24,57 @@
typedef struct _SeedClosure
{
- GClosure closure;
+ GClosure closure;
- JSObjectRef function;
- JSValueRef user_data;
+ JSObjectRef function;
+ JSValueRef user_data;
- GType return_type;
- gchar *description;
+ GType return_type;
+ gchar* description;
} SeedClosure;
typedef struct _SeedNativeClosure
{
- JSContextRef ctx;
- GICallableInfo *info;
- JSValueRef function;
+ JSContextRef ctx;
+ GICallableInfo* info;
+ JSValueRef function;
- ffi_closure *closure;
- ffi_cif *cif;
+ ffi_closure* closure;
+ ffi_cif* cif;
} SeedNativeClosure;
extern JSClassRef seed_native_callback_class;
-SeedNativeClosure *seed_make_native_closure (JSContextRef ctx,
- GICallableInfo * info,
- JSValueRef function);
-GClosure *seed_closure_new (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef user_data, const gchar * description);
-
-
-GClosure *seed_closure_new_for_signal (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef user_data,
- const gchar *description,
- guint signal_id);
-
-
-JSObjectRef seed_closure_get_callable (GClosure * c);
-
-JSValueRef
-seed_closure_invoke (GClosure * closure, JSValueRef * args, guint argc,
- JSValueRef * exception);
-JSValueRef seed_closure_invoke_with_context (JSContextRef ctx,
- GClosure * closure,
- JSValueRef * args, guint argc,
- JSValueRef * exception);
-
-void
-seed_closure_warn_exception (GClosure * c,
- JSContextRef ctx, JSValueRef exception);
-
-
-
-void seed_closures_init ();
+SeedNativeClosure* seed_make_native_closure(JSContextRef ctx,
+ GICallableInfo* info,
+ JSValueRef function);
+GClosure* seed_closure_new(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description);
+
+GClosure* seed_closure_new_for_signal(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description,
+ guint signal_id);
+
+JSObjectRef seed_closure_get_callable(GClosure* c);
+
+JSValueRef seed_closure_invoke(GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception);
+JSValueRef seed_closure_invoke_with_context(JSContextRef ctx,
+ GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception);
+
+void seed_closure_warn_exception(GClosure* c,
+ JSContextRef ctx,
+ JSValueRef exception);
+
+void seed_closures_init();
#endif
diff --git a/libseed/seed-debug.h b/libseed/seed-debug.h
index 32bd87d..11a099f 100644
--- a/libseed/seed-debug.h
+++ b/libseed/seed-debug.h
@@ -24,39 +24,43 @@
#include <glib.h>
-typedef enum
-{
- SEED_DEBUG_ALL = 1 << 0,
- SEED_DEBUG_MISC = 1 << 1,
- SEED_DEBUG_FINALIZATION = 1 << 2,
- SEED_DEBUG_INITIALIZATION = 1 << 3,
- SEED_DEBUG_CONSTRUCTION = 1 << 4,
- SEED_DEBUG_INVOCATION = 1 << 5,
- SEED_DEBUG_SIGNAL = 1 << 6,
- SEED_DEBUG_STRUCTS = 1 << 7,
- SEED_DEBUG_GTYPE = 1 << 8,
- SEED_DEBUG_IMPORTER = 1 << 9,
- SEED_DEBUG_MODULE = 1 << 10
+typedef enum {
+ SEED_DEBUG_ALL = 1 << 0,
+ SEED_DEBUG_MISC = 1 << 1,
+ SEED_DEBUG_FINALIZATION = 1 << 2,
+ SEED_DEBUG_INITIALIZATION = 1 << 3,
+ SEED_DEBUG_CONSTRUCTION = 1 << 4,
+ SEED_DEBUG_INVOCATION = 1 << 5,
+ SEED_DEBUG_SIGNAL = 1 << 6,
+ SEED_DEBUG_STRUCTS = 1 << 7,
+ SEED_DEBUG_GTYPE = 1 << 8,
+ SEED_DEBUG_IMPORTER = 1 << 9,
+ SEED_DEBUG_MODULE = 1 << 10
} SeedDebugFlag;
#ifdef SEED_ENABLE_DEBUG
-#define SEED_NOTE(type,...) G_STMT_START { \
- if ((seed_debug_flags & SEED_DEBUG_##type) || \
- seed_debug_flags & SEED_DEBUG_ALL) \
- { \
- gchar * _fmt = g_strdup_printf (__VA_ARGS__); \
- g_message ("[" #type "] " G_STRLOC ": %s",_fmt); \
- g_free (_fmt); \
- } \
-} G_STMT_END
+#define SEED_NOTE(type, ...) \
+ G_STMT_START \
+ { \
+ if ((seed_debug_flags & SEED_DEBUG_##type) \
+ || seed_debug_flags & SEED_DEBUG_ALL) { \
+ gchar* _fmt = g_strdup_printf(__VA_ARGS__); \
+ g_message("[" #type "] " G_STRLOC ": %s", _fmt); \
+ g_free(_fmt); \
+ } \
+ } \
+ G_STMT_END
-#define SEED_MARK() SEED_NOTE(MISC, "== mark ==")
-#define SEED_DBG(x) { a }
+#define SEED_MARK() SEED_NOTE(MISC, "== mark ==")
+#define SEED_DBG(x) \
+ { \
+ a \
+ }
#else /* !SEED_ENABLE_DEBUG */
-#define SEED_NOTE(type,...)
+#define SEED_NOTE(type, ...)
#define SEED_MARK()
#define SEED_DBG(x)
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 3870fb0..3c524f5 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -25,12 +25,15 @@
#include <stdarg.h>
#include <string.h>
#include <pthread.h>
+#include "seed-signals.h"
#include "config.h"
JSObjectRef function_proto;
JSObjectRef seed_obj_ref;
+JSObjectRef ARGV_obj_ref;
+JSObjectRef window_obj_ref;
GQuark qname;
GQuark qprototype;
@@ -43,50 +46,50 @@ JSContextGroupRef context_group;
JSStringRef defaults_script;
-gchar *glib_message = 0;
+gchar* glib_message = 0;
-GIBaseInfo *base_info_info = 0;
+GIBaseInfo* base_info_info = 0;
GQuark js_ref_quark;
-guint seed_debug_flags = 0; /* global seed debug flag */
+guint seed_debug_flags = 0; /* global seed debug flag */
gboolean seed_arg_print_version = FALSE; // Flag to print version and quit
pthread_key_t seed_next_gobject_wrapper_key;
#ifdef SEED_ENABLE_DEBUG
-static const GDebugKey seed_debug_keys[] = {
- {"misc", SEED_DEBUG_MISC},
- {"finalization", SEED_DEBUG_FINALIZATION},
- {"initialization", SEED_DEBUG_INITIALIZATION},
- {"signal", SEED_DEBUG_SIGNAL},
- {"invocation", SEED_DEBUG_INVOCATION},
- {"structs", SEED_DEBUG_STRUCTS},
- {"construction", SEED_DEBUG_CONSTRUCTION},
- {"gtype", SEED_DEBUG_GTYPE},
- {"importer", SEED_DEBUG_IMPORTER},
- {"module", SEED_DEBUG_MODULE}
-};
+static const GDebugKey seed_debug_keys[]
+ = { { "misc", SEED_DEBUG_MISC },
+ { "finalization", SEED_DEBUG_FINALIZATION },
+ { "initialization", SEED_DEBUG_INITIALIZATION },
+ { "signal", SEED_DEBUG_SIGNAL },
+ { "invocation", SEED_DEBUG_INVOCATION },
+ { "structs", SEED_DEBUG_STRUCTS },
+ { "construction", SEED_DEBUG_CONSTRUCTION },
+ { "gtype", SEED_DEBUG_GTYPE },
+ { "importer", SEED_DEBUG_IMPORTER },
+ { "module", SEED_DEBUG_MODULE } };
#endif /* SEED_ENABLE_DEBUG */
static bool
-seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
- JSValueRef possible_instance, JSValueRef* exception)
+seed_gobject_has_instance(JSContextRef ctx,
+ JSObjectRef constructor,
+ JSValueRef possible_instance,
+ JSValueRef* exception)
{
- GType constructor_type, value_type;
- if (JSValueIsNull (ctx, possible_instance) ||
- !JSValueIsObject (ctx, possible_instance) ||
- !JSValueIsObjectOfClass (ctx, possible_instance, gobject_class))
- return FALSE;
+ GType constructor_type, value_type;
+ if (JSValueIsNull(ctx, possible_instance)
+ || !JSValueIsObject(ctx, possible_instance)
+ || !JSValueIsObjectOfClass(ctx, possible_instance, gobject_class))
+ return FALSE;
- constructor_type = (GType) JSObjectGetPrivate (constructor);
- value_type = G_OBJECT_TYPE ((GObject *)
- JSObjectGetPrivate ((JSObjectRef) possible_instance));
+ constructor_type = (GType) JSObjectGetPrivate(constructor);
+ value_type = G_OBJECT_TYPE(
+ (GObject*) JSObjectGetPrivate((JSObjectRef) possible_instance));
- return g_type_is_a (value_type, constructor_type);
+ return g_type_is_a(value_type, constructor_type);
}
-
/**
* seed_prepare_global_context:
* @ctx: A #SeedContext on which to add the default set of global objects.
@@ -96,1418 +99,1503 @@ seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
*
*/
void
-seed_prepare_global_context (JSContextRef ctx)
+seed_prepare_global_context(JSContextRef ctx)
{
- JSObjectRef global = JSContextGetGlobalObject (ctx);
- JSStringRef check_sprintf = JSStringCreateWithUTF8CString ("sprintf");
-
- seed_object_set_property (ctx, global, "imports", importer);
- seed_object_set_property (ctx, global, "GType", seed_gtype_constructor);
- seed_object_set_property (ctx, global, "Seed", seed_obj_ref);
- seed_object_set_property (ctx, global, "print", seed_print_ref);
- seed_object_set_property (ctx, global, "printerr", seed_printerr_ref);
-
- /* No need to re-import Seed.js if not needed. */
- if (!JSObjectHasProperty( ctx, seed_obj_ref, check_sprintf)) {
- JSEvaluateScript (ctx, defaults_script, NULL, NULL, 0, NULL);
- }
- JSStringRelease (check_sprintf);
+ JSObjectRef global = JSContextGetGlobalObject(ctx);
+ JSStringRef check_sprintf = JSStringCreateWithUTF8CString("sprintf");
+
+ seed_object_set_property(ctx, global, "imports", importer);
+ seed_object_set_property(ctx, global, "GType", seed_gtype_constructor);
+ seed_object_set_property(ctx, global, "Seed", seed_obj_ref);
+ seed_object_set_property(ctx, global, "ARGV", ARGV_obj_ref);
+ seed_object_set_property(ctx, global, "window", window_obj_ref);
+ seed_object_set_property(ctx, global, "print", seed_print_ref);
+ seed_object_set_property(ctx, global, "printerr", seed_printerr_ref);
+
+ /* No need to re-import Seed.js if not needed. */
+ if (!JSObjectHasProperty(ctx, seed_obj_ref, check_sprintf)) {
+ JSEvaluateScript(ctx, defaults_script, NULL, NULL, 0, NULL);
+ }
+ JSStringRelease(check_sprintf);
}
static JSObjectRef
-seed_struct_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_struct_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GIBaseInfo *info = JSObjectGetPrivate (constructor);
- JSValueRef ret;
- JSObjectRef parameters = 0;
-
- if (argumentCount == 1)
- {
- if (!JSValueIsObject (ctx, arguments[0]))
- {
-
- // new GObject.GValue() can accept anything as a argument...
- GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
- if (!g_type_is_a (gtype, G_TYPE_VALUE)) {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Constructor expects object as argument");
- return (JSObjectRef) JSValueMakeNull (ctx);
- }
- }
- parameters = (JSObjectRef) arguments[0];
+ GIBaseInfo* info = JSObjectGetPrivate(constructor);
+ JSValueRef ret;
+ JSObjectRef parameters = 0;
+
+ if (argumentCount == 1) {
+ if (!JSValueIsObject(ctx, arguments[0])) {
+
+ // new GObject.GValue() can accept anything as a argument...
+ GType gtype
+ = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+ if (!g_type_is_a(gtype, G_TYPE_VALUE)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Constructor expects object as argument");
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+ }
+ parameters = (JSObjectRef) arguments[0];
}
- ret = seed_construct_struct_type_with_parameters (ctx, info,
- parameters, exception);
+ ret = seed_construct_struct_type_with_parameters(ctx, info, parameters,
+ exception);
- return (JSObjectRef) ret;
+ return (JSObjectRef) ret;
}
static JSObjectRef
-seed_gobject_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GType type;
- GParameter *params;
- GObjectClass *oclass;
- GObject *gobject;
- GParamSpec *param_spec;
- gchar *prop_name;
- gint i, nparams = 0, length, ri;
- JSObjectRef ret;
- JSPropertyNameArrayRef jsprops = 0;
- JSStringRef jsprop_name;
- JSValueRef jsprop_value;
-
- type = (GType) JSObjectGetPrivate (constructor);
- if (!type)
- return 0;
-
- oclass = g_type_class_ref (type);
-
- // Check for an exception in class init (which may have just been called
- // by g_type_class_ref, if this is the first construction of this class).
- // Bubble up the exception, and clear it from the class's qdata so that
- // this doesn't happen on subsequent construction.
- GQuark class_init_exception_q =
- g_quark_from_static_string("type-class-init-exception");
- JSValueRef class_init_exception =
- (JSValueRef)g_type_get_qdata(type, class_init_exception_q);
- if(class_init_exception)
- {
- *exception = class_init_exception;
- g_type_set_qdata(type, class_init_exception_q, NULL);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ GType type;
+ GParameter* params;
+ GObjectClass* oclass;
+ GObject* gobject;
+ GParamSpec* param_spec;
+ gchar* prop_name;
+ gint i, nparams = 0, length, ri;
+ JSObjectRef ret;
+ JSPropertyNameArrayRef jsprops = 0;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+
+ type = (GType) JSObjectGetPrivate(constructor);
+ if (!type)
+ return 0;
+
+ oclass = g_type_class_ref(type);
+
+ // Check for an exception in class init (which may have just been called
+ // by g_type_class_ref, if this is the first construction of this class).
+ // Bubble up the exception, and clear it from the class's qdata so that
+ // this doesn't happen on subsequent construction.
+ GQuark class_init_exception_q
+ = g_quark_from_static_string("type-class-init-exception");
+ JSValueRef class_init_exception
+ = (JSValueRef) g_type_get_qdata(type, class_init_exception_q);
+ if (class_init_exception) {
+ *exception = class_init_exception;
+ g_type_set_qdata(type, class_init_exception_q, NULL);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (argumentCount > 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Constructor expects"
- " 1 argument, got %zd", argumentCount);
+ if (argumentCount > 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Constructor expects"
+ " 1 argument, got %zd",
+ argumentCount);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (argumentCount == 1)
- {
- if (!JSValueIsObject (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Constructor expects object as argument");
- g_type_class_unref (oclass);
- return (JSObjectRef) JSValueMakeNull (ctx);
- }
-
- jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) arguments[0]);
- nparams = JSPropertyNameArrayGetCount (jsprops);
- }
- ri = i = 0;
-
- params = g_new0 (GParameter, nparams + 1);
- SEED_NOTE (INITIALIZATION, "Constructing object of type %s",
- g_type_name (type));
-
-
- pthread_setspecific (seed_next_gobject_wrapper_key,
- seed_make_wrapper_for_type (ctx, type));
-
- while (i < nparams)
- {
- GType type;
- jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
-
- length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
- prop_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (jsprop_name, prop_name, length);
-
- param_spec = g_object_class_find_property (oclass, prop_name);
-
- jsprop_value = JSObjectGetProperty (ctx,
- (JSObjectRef) arguments[0],
- jsprop_name, NULL);
-
- if (param_spec == NULL)
- {
- JSObjectSetProperty (ctx, pthread_getspecific(seed_next_gobject_wrapper_key), jsprop_name,
- jsprop_value, 0, NULL);
- ++i;
- continue;
- }
- // TODO: exception handling
-
- if (g_type_is_a (param_spec->value_type, G_TYPE_ENUM))
- type = G_TYPE_INT;
- else
- type = param_spec->value_type;
-
- seed_value_to_gvalue (ctx, jsprop_value,
- type, &params[ri].value, exception);
-
- if (*exception)
- {
- g_free (params);
- JSPropertyNameArrayRelease (jsprops);
- pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
- return 0;
- }
- params[ri].name = prop_name;
-
- ++i;
- ++ri;
+ if (argumentCount == 1) {
+ if (!JSValueIsObject(ctx, arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Constructor expects object as argument");
+ g_type_class_unref(oclass);
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+
+ jsprops = JSObjectCopyPropertyNames(ctx, (JSObjectRef) arguments[0]);
+ nparams = JSPropertyNameArrayGetCount(jsprops);
}
+ ri = i = 0;
+
+ params = g_new0(GParameter, nparams + 1);
+ SEED_NOTE(INITIALIZATION, "Constructing object of type %s",
+ g_type_name(type));
+
+ pthread_setspecific(seed_next_gobject_wrapper_key,
+ seed_make_wrapper_for_type(ctx, type));
- if (jsprops)
- JSPropertyNameArrayRelease (jsprops);
+ while (i < nparams) {
+ GType type;
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex(jsprops, i);
+
+ length = JSStringGetMaximumUTF8CStringSize(jsprop_name);
+ prop_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsprop_name, prop_name, length);
+
+ param_spec = g_object_class_find_property(oclass, prop_name);
+
+ jsprop_value = JSObjectGetProperty(ctx, (JSObjectRef) arguments[0],
+ jsprop_name, NULL);
+
+ if (param_spec == NULL) {
+ JSObjectSetProperty(ctx, pthread_getspecific(
+ seed_next_gobject_wrapper_key),
+ jsprop_name, jsprop_value, 0, NULL);
+ ++i;
+ continue;
+ }
+ // TODO: exception handling
+
+ if (g_type_is_a(param_spec->value_type, G_TYPE_ENUM))
+ type = G_TYPE_INT;
+ else
+ type = param_spec->value_type;
+
+ seed_value_to_gvalue(ctx, jsprop_value, type, &params[ri].value,
+ exception);
+
+ if (*exception) {
+ g_free(params);
+ JSPropertyNameArrayRelease(jsprops);
+ pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
+ return 0;
+ }
+ params[ri].name = prop_name;
+
+ ++i;
+ ++ri;
+ }
- SEED_NOTE (INITIALIZATION, "G_TYPE_IS_INSTANTIATABLE = %d G_TYPE_IS_ABSTRACT = %d",
- G_TYPE_IS_INSTANTIATABLE(type) , G_TYPE_IS_ABSTRACT(type));
+ if (jsprops)
+ JSPropertyNameArrayRelease(jsprops);
+ SEED_NOTE(INITIALIZATION,
+ "G_TYPE_IS_INSTANTIATABLE = %d G_TYPE_IS_ABSTRACT = %d",
+ G_TYPE_IS_INSTANTIATABLE(type), G_TYPE_IS_ABSTRACT(type));
-
- if (! G_TYPE_IS_INSTANTIATABLE(type) || G_TYPE_IS_ABSTRACT(type) ) {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Type can not be created - not INSTANTIATABLE");
+ if (!G_TYPE_IS_INSTANTIATABLE(type) || G_TYPE_IS_ABSTRACT(type)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Type can not be created - not INSTANTIATABLE");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
-
-
- gobject = g_object_newv (type, ri, params);
+ gobject = g_object_newv(type, ri, params);
- if (G_IS_INITIALLY_UNOWNED (gobject) && !g_object_is_floating (gobject))
- g_object_ref (gobject);
- else if (g_object_is_floating (gobject))
- g_object_ref_sink (gobject);
+ if (G_IS_INITIALLY_UNOWNED(gobject) && !g_object_is_floating(gobject))
+ g_object_ref(gobject);
+ else if (g_object_is_floating(gobject))
+ g_object_ref_sink(gobject);
- if (!gobject)
- ret = (JSObjectRef) JSValueMakeNull (ctx);
- else
- ret = (JSObjectRef) seed_value_from_object (ctx, gobject, exception);
+ if (!gobject)
+ ret = (JSObjectRef) JSValueMakeNull(ctx);
+ else
+ ret = (JSObjectRef) seed_value_from_object(ctx, gobject, exception);
- for (i = 0; i < ri; i++)
- {
- g_value_unset (&params[i].value);
+ for (i = 0; i < ri; i++) {
+ g_value_unset(&params[i].value);
}
- g_object_unref (gobject);
+ g_object_unref(gobject);
- g_type_class_unref (oclass);
+ g_type_class_unref(oclass);
- g_free (params);
+ g_free(params);
- return ret;
+ return ret;
}
static JSValueRef
-seed_gobject_property_type (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_property_type(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *spec;
- gchar *name;
- GObject *this;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "__property_type expects 1 argument"
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
+ GParamSpec* spec;
+ gchar* name;
+ GObject* this;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "__property_type expects 1 argument"
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- this = seed_value_to_object (ctx, this_object, exception);
- name = seed_value_to_string (ctx, arguments[0], exception);
+ this = seed_value_to_object(ctx, this_object, exception);
+ name = seed_value_to_string(ctx, arguments[0], exception);
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (this), name);
- g_free (name);
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(this), name);
+ g_free(name);
- return seed_value_from_long (ctx, spec->value_type, exception);
+ return seed_value_from_long(ctx, spec->value_type, exception);
}
static JSValueRef
-seed_gobject_ref_count (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_gobject_ref_count(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GObject *this;
+ GObject* this;
- this = seed_value_to_object (ctx, (JSValueRef) this_object, exception);
+ this = seed_value_to_object(ctx, (JSValueRef) this_object, exception);
- return seed_value_from_int (ctx, this->ref_count, exception);
+ return seed_value_from_int(ctx, this->ref_count, exception);
}
static void
-seed_gobject_method_finalize (JSObjectRef method)
+seed_gobject_method_finalize(JSObjectRef method)
{
- GIBaseInfo *info = (GIBaseInfo *) JSObjectGetPrivate (method);
- if (info)
- g_base_info_unref (info);
+ GIBaseInfo* info = (GIBaseInfo*) JSObjectGetPrivate(method);
+ if (info)
+ g_base_info_unref(info);
}
-typedef void (*InitMethodCallback) (gint * argc, gchar *** argv);
+typedef void (*InitMethodCallback)(gint* argc, gchar*** argv);
static gboolean
-seed_gobject_init_build_argv (JSContextRef ctx,
- JSObjectRef array,
- SeedArgvPrivates * priv, JSValueRef * exception)
+seed_gobject_init_build_argv(JSContextRef ctx,
+ JSObjectRef array,
+ SeedArgvPrivates* priv,
+ JSValueRef* exception)
{
- guint i, length;
- JSValueRef jsl;
+ guint i, length;
+ JSValueRef jsl;
- jsl = seed_object_get_property (ctx, array, "length");
- if (JSValueIsNull (ctx, jsl) || JSValueIsUndefined (ctx, jsl))
- return FALSE;
+ jsl = seed_object_get_property(ctx, array, "length");
+ if (JSValueIsNull(ctx, jsl) || JSValueIsUndefined(ctx, jsl))
+ return FALSE;
- length = seed_value_to_uint (ctx, jsl, exception);
- priv->argv = g_new (gchar *, length);
- priv->argc = length;
-
- for (i = 0; i < length; i++)
- {
- priv->argv[i] = seed_value_to_string (ctx,
- JSObjectGetPropertyAtIndex (ctx,
- array,
- i,
- exception),
- exception);
- }
- return TRUE;
+ length = seed_value_to_uint(ctx, jsl, exception);
+ priv->argv = g_new(gchar*, length);
+ priv->argc = length;
+ for (i = 0; i < length; i++) {
+ priv->argv[i] = seed_value_to_string(
+ ctx, JSObjectGetPropertyAtIndex(ctx, array, i, exception), exception);
+ }
+ return TRUE;
}
static JSValueRef
-seed_gobject_init_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_init_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GIBaseInfo *info;
- GTypelib *typelib;
- InitMethodCallback c;
- SeedArgvPrivates *priv = NULL;
- gboolean allocated = FALSE;
-
- if (argumentCount != 1 && argumentCount != 2)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "init method expects 1 argument, got %zd",
- argumentCount);
- return JSValueMakeUndefined (ctx);
+ GIBaseInfo* info;
+ GTypelib* typelib;
+ InitMethodCallback c;
+ SeedArgvPrivates* priv = NULL;
+ gboolean allocated = FALSE;
+
+ if (argumentCount != 1 && argumentCount != 2) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "init method expects 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeUndefined(ctx);
}
- if (argumentCount == 1)
- {
- if (JSValueIsNull (ctx, arguments[0])
- || !JSValueIsObject (ctx, arguments[0]))
-
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "init method expects an array object as argument");
- return JSValueMakeUndefined (ctx);
- }
- if (JSValueIsObjectOfClass (ctx, arguments[0], seed_argv_class))
- {
- priv = JSObjectGetPrivate ((JSObjectRef) arguments[0]);
- }
- else
- {
- priv = g_newa (SeedArgvPrivates, 1);
- if (!seed_gobject_init_build_argv (ctx,
- (JSObjectRef) arguments[0],
- priv, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Init method expects an array as argument");
- return JSValueMakeUndefined (ctx);
-
- }
- allocated = TRUE;
- }
+ if (argumentCount == 1) {
+ if (!JSValueIsNull(ctx, arguments[0])
+ && !JSValueIsObject(ctx, arguments[0]))
+
+ {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "init method expects an array object as argument");
+ return JSValueMakeUndefined(ctx);
+ }
+ if (JSValueIsNull(ctx, arguments[0])) {
+ priv = NULL;
+ } else if (JSValueIsObjectOfClass(ctx, arguments[0], seed_argv_class)) {
+ priv = JSObjectGetPrivate((JSObjectRef) arguments[0]);
+ } else {
+ priv = g_newa(SeedArgvPrivates, 1);
+ if (!seed_gobject_init_build_argv(ctx, (JSObjectRef) arguments[0],
+ priv, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Init method expects an array as argument");
+ return JSValueMakeUndefined(ctx);
+ }
+ allocated = TRUE;
+ }
}
- info = JSObjectGetPrivate (function);
- typelib = g_base_info_get_typelib (info);
- g_typelib_symbol (typelib,
- g_function_info_get_symbol ((GIFunctionInfo *) info),
- (gpointer *) & c);
- // Backwards compatibility
- if (!priv)
- {
- c (NULL, NULL);
- return JSValueMakeUndefined (ctx);
+ info = JSObjectGetPrivate(function);
+ typelib = g_base_info_get_typelib(info);
+ g_typelib_symbol(typelib,
+ g_function_info_get_symbol((GIFunctionInfo*) info),
+ (gpointer*) &c);
+ // Backwards compatibility
+ if (!priv) {
+ c(NULL, NULL);
+ return JSValueMakeUndefined(ctx);
}
- c (&priv->argc, &priv->argv);
+ c(&priv->argc, &priv->argv);
+
+ if (allocated)
+ g_free(priv->argv);
+
+ return JSValueMakeUndefined(ctx);
+}
+
+// Pre-process the arguments list to find which arguments needs to be skipped.
+gint*
+_process_skipped_arguments(const JSValueRef arguments[],
+ GIBaseInfo* info,
+ gint* out_skipped_args)
+{
+ int n_args = g_callable_info_get_n_args((GICallableInfo*) info);
+ int skipped_args = 0;
+ ;
+ int i;
+
+ gint* skip = g_new0(gint, n_args + 1);
+
+ GITypeInfo* type_info = NULL;
+ GIArgInfo* arg_info = NULL;
+
+ for (i = 0; (i < (n_args)); i++) {
+ arg_info = g_callable_info_get_arg((GICallableInfo*) info, i);
+ type_info = g_arg_info_get_type(arg_info);
+ GIDirection dir = g_arg_info_get_direction(arg_info);
+
+ GITypeTag type_tag = g_type_info_get_tag(type_info);
+ gint array_len_pos = g_type_info_get_array_length(type_info);
+
+ if (dir == GI_DIRECTION_IN)
+ if (type_tag == GI_TYPE_TAG_ARRAY
+ && g_type_info_get_array_type(type_info) == GI_ARRAY_TYPE_C
+ && array_len_pos >= 0) {
+ skip[array_len_pos] = 1;
+ skipped_args++;
+ }
- if (allocated)
- g_free (priv->argv);
+ g_base_info_unref((GIBaseInfo*) type_info);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ type_info = NULL;
+ arg_info = NULL;
+ }
- return JSValueMakeUndefined (ctx);
+ *out_skipped_args = skipped_args;
+ return skip;
+}
+
+void
+_add_jsvalue_in_array(JSContextRef ctx,
+ JSObjectRef dest,
+ gint pos,
+ JSValueRef obj)
+{
+ gchar* int_str = g_strdup_printf("%d", pos);
+ seed_object_set_property(ctx, (JSObjectRef) dest, int_str, obj);
+ g_free(int_str);
}
static JSValueRef
-seed_gobject_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GIBaseInfo *info;
- GObject *object = NULL;
- gboolean instance_method = TRUE;
- gboolean is_caller_allocates = FALSE;
- gboolean *caller_allocated;
- GIBaseInfo *iface_info = NULL;
- GArgument retval;
- GArgument *in_args;
- GArgument *out_args;
- GArgument *out_values;
- gint *out_pos;
- gint first_out = -1;
- guint use_return_as_out = 0;
- guint n_args, n_in_args, n_out_args, i;
- guint in_args_pos, out_args_pos;
- GIArgInfo *arg_info = NULL;
- GITypeInfo *type_info = NULL;
- GITypeTag tag;
- GIDirection dir;
- JSValueRef retval_ref;
- GError *error = 0;
- gint length_arg_pos = 0;
- guint64 array_len = 0;
-
- info = JSObjectGetPrivate (function);
-
- // We just want to check if there IS an object, not actually throw an
- // exception if we don't get it.
- if (!this_object || !
- ((object = seed_value_to_object (ctx, this_object, 0)) ||
- (object = seed_pointer_get_pointer (ctx, this_object))))
- instance_method = FALSE;
-
- n_args = g_callable_info_get_n_args ((GICallableInfo *) info);
-
- out_pos = g_new0 (gint, n_args + 1);
- in_args = g_new0 (GArgument, n_args + 1);
- out_args = g_new0 (GArgument, n_args + 1);
- out_values = g_new0 (GArgument, n_args + 1);
- n_in_args = n_out_args = 0;
- caller_allocated = g_new0 (gboolean, n_args + 1);
-
- // start buy pushing the object onto the call stack.
-
- if (instance_method)
- in_args[n_in_args++].v_pointer = object;
-
-
- // now loop through all the other args.
- for (i = 0; (i < (n_args)); i++)
- {
- out_pos[i] = -1;
- arg_info = g_callable_info_get_arg ((GICallableInfo *) info, i);
- dir = g_arg_info_get_direction (arg_info);
- type_info = g_arg_info_get_type (arg_info);
- is_caller_allocates = FALSE;
-
+ GIBaseInfo* info;
+ GObject* object = NULL;
+ gboolean instance_method = TRUE;
+ gboolean is_caller_allocates = FALSE;
+ gboolean* caller_allocated;
+ GIBaseInfo* iface_info = NULL;
+ GArgument retval;
+ GArgument* in_args;
+ GArgument* out_args;
+ GArgument* out_values;
+ gint* skipped_args = NULL;
+ gint* out_pos;
+ gint first_out = -1;
+ guint use_return_as_out = 0;
+ guint n_args, n_in_args, n_out_args, i, j;
+ guint in_args_pos, out_args_pos;
+ GIArgInfo* arg_info = NULL;
+ GITypeInfo* type_info = NULL;
+ GITypeTag tag;
+ GIDirection dir;
+ GITransfer transfer;
+ JSValueRef retval_ref;
+ GError* error = 0;
+ gint length_arg_pos = 0;
+ guint64 array_len = 0;
+ gint array_return_value_count = 0;
+ gboolean return_only_one_out = false;
+
+ info = JSObjectGetPrivate(function);
+
+ // We just want to check if there IS an object, not actually throw an
+ // exception if we don't get it.
+ if (!this_object
+ || !((object = seed_value_to_object(ctx, this_object, 0))
+ || (object = seed_pointer_get_pointer(ctx, this_object))))
+ instance_method = FALSE;
+
+ n_args = g_callable_info_get_n_args((GICallableInfo*) info);
+
+ out_pos = g_new0(gint, n_args + 1);
+ in_args = g_new0(GArgument, n_args + 1);
+ out_args = g_new0(GArgument, n_args + 1);
+ out_values = g_new0(GArgument, n_args + 1);
+ n_in_args = n_out_args = 0;
+ caller_allocated = g_new0(gboolean, n_args + 1);
+
+ // start by pushing the object onto the call stack.
+ if (instance_method)
+ in_args[n_in_args++].v_pointer = object;
+
+ int out_skipped_args = 0;
+ skipped_args
+ = _process_skipped_arguments(arguments, info, &out_skipped_args);
+
+ SEED_NOTE(INVOCATION, "Calling seed_object_method_invoked for function %s",
+ g_base_info_get_name(info));
+
+ // now loop through all the other args.
+ for (i = 0, j = 0; (i < (n_args)); i++) {
+ if (skipped_args[i]) {
+ SEED_NOTE(INVOCATION, "Skipping parameter %d", i);
+ n_in_args++;
+ j++;
+ continue;
+ }
+
+ out_pos[i] = -1;
+ arg_info = g_callable_info_get_arg((GICallableInfo*) info, i);
+ dir = g_arg_info_get_direction(arg_info);
+ type_info = g_arg_info_get_type(arg_info);
+ transfer = g_arg_info_get_ownership_transfer(arg_info);
+ is_caller_allocates = FALSE;
+
#if GOBJECT_INTROSPECTION_VERSION > 0x000613
- is_caller_allocates = (dir == GI_DIRECTION_OUT) && g_arg_info_is_caller_allocates (arg_info);
-
- /* caller allocates only applies to structures but GI has
- * no way to denote that yet, so we only use caller allocates
- * if we see a structure
- */
- if (is_caller_allocates)
- {
- GITypeTag type_tag = g_type_info_get_tag (type_info);
+ is_caller_allocates = (dir == GI_DIRECTION_OUT)
+ && g_arg_info_is_caller_allocates(arg_info);
- is_caller_allocates = FALSE;
+ /* caller allocates only applies to structures but GI has
+ * no way to denote that yet, so we only use caller allocates
+ * if we see a structure
+ */
+ if (is_caller_allocates) {
+ GITypeTag type_tag = g_type_info_get_tag(type_info);
+ is_caller_allocates = FALSE;
- if (type_tag == GI_TYPE_TAG_INTERFACE)
- {
- GIInfoType info_type;
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
+ GIInfoType info_type;
- iface_info = g_type_info_get_interface (type_info);
- g_assert (info != NULL);
- info_type = g_base_info_get_type (iface_info);
+ iface_info = g_type_info_get_interface(type_info);
+ g_assert(info != NULL);
+ info_type = g_base_info_get_type(iface_info);
- if (info_type == GI_INFO_TYPE_STRUCT)
- is_caller_allocates = TRUE;
+ if (info_type == GI_INFO_TYPE_STRUCT)
+ is_caller_allocates = TRUE;
}
- }
+ }
#endif
+ SEED_NOTE(INVOCATION,
+ "Converting arg: %s (%d) of function %s, exception is %p",
+ g_base_info_get_name((GIBaseInfo*) arg_info), i,
+ g_base_info_get_name(info), exception);
- SEED_NOTE (INVOCATION,
- "Converting arg: %s (%d) of function %s, exception is %p",
- g_base_info_get_name ((GIBaseInfo *)arg_info), i,
- g_base_info_get_name (info), exception);
+ if (i + 1 > argumentCount + out_skipped_args) {
+ if (dir == GI_DIRECTION_OUT) {
+ GArgument* out_value = &out_values[n_out_args];
+ out_values[n_out_args].v_pointer = NULL;
+ out_args[n_out_args].v_pointer = out_value;
+ out_pos[i] = n_out_args;
- if (i + 1 > argumentCount)
- {
-
- if (dir == GI_DIRECTION_OUT)
- {
- GArgument *out_value = &out_values[n_out_args];
- out_values[n_out_args].v_pointer = NULL;
- out_args[n_out_args].v_pointer = out_value;
-
- out_pos[ i ] = n_out_args;
-
- if (is_caller_allocates)
- {
- gsize size = g_struct_info_get_size ( (GIStructInfo *) iface_info) ;
- out_args[n_out_args].v_pointer = g_malloc0 (size);
- out_values[n_out_args].v_pointer = out_args[n_out_args].v_pointer;
- caller_allocated[i] = TRUE;
-
+ if (is_caller_allocates) {
+ gsize size
+ = g_struct_info_get_size((GIStructInfo*) iface_info);
+ out_args[n_out_args].v_pointer = g_malloc0(size);
+ out_values[n_out_args].v_pointer
+ = out_args[n_out_args].v_pointer;
+ caller_allocated[i] = TRUE;
}
- n_out_args++;
- }
- else
- in_args[n_in_args++].v_pointer = 0;
-
- }
- else if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT)
- {
-
- if ( !g_arg_info_may_be_null (arg_info) )
- {
- gboolean is_null = ( !arguments[i] || JSValueIsNull (ctx, arguments[i]) );
-
- if (!is_null && (g_type_info_get_tag (type_info) == GI_TYPE_TAG_INTERFACE))
- {
- /* see if the pointer is null for struct/unions. */
- GIBaseInfo *interface = g_type_info_get_interface (type_info);
- GIInfoType interface_type = g_base_info_get_type (interface);
-
- gboolean arg_is_object = JSValueIsObject (ctx, arguments[i]);
-
- gboolean is_gvalue = (interface_type == GI_INFO_TYPE_STRUCT) &&
- !g_strcmp0(g_base_info_get_name((GIBaseInfo *)interface), "Value") &&
- !g_strcmp0(g_base_info_get_namespace((GIBaseInfo *)interface), "GObject");
-
-
- gboolean is_struct_or_union = (
- interface_type == GI_INFO_TYPE_STRUCT ||
- interface_type == GI_INFO_TYPE_UNION
- );
-
- /* this test ignores non-objects being sent where interfaces are expected
- hopefully our type manipluation code will pick that up.
- The only exception to this is GObject.GValues which are arrays.
- */
- if (!is_gvalue && is_struct_or_union && arg_is_object &&
- (seed_pointer_get_pointer (ctx, arguments[i]) == 0)) {
- is_null = TRUE;
- }
- g_base_info_unref (interface);
+ n_out_args++;
+ } else
+ in_args[n_in_args++].v_pointer = 0;
+
+ } else if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT) {
+
+ if (!g_arg_info_may_be_null(arg_info)) {
+ gboolean is_null
+ = (!arguments[i - j] || JSValueIsNull(ctx, arguments[i - j]));
+
+ if (!is_null && (g_type_info_get_tag(type_info)
+ == GI_TYPE_TAG_INTERFACE)) {
+ /* see if the pointer is null for struct/unions. */
+ GIBaseInfo* interface = g_type_info_get_interface(
+ type_info);
+ GIInfoType interface_type = g_base_info_get_type(interface);
+
+ gboolean arg_is_object
+ = JSValueIsObject(ctx, arguments[i - j]);
+
+ gboolean is_gvalue
+ = (interface_type == GI_INFO_TYPE_STRUCT)
+ && !g_strcmp0(g_base_info_get_name(
+ (GIBaseInfo*) interface),
+ "Value")
+ && !g_strcmp0(g_base_info_get_namespace(
+ (GIBaseInfo*) interface),
+ "GObject");
+
+ gboolean is_struct_or_union
+ = (interface_type == GI_INFO_TYPE_STRUCT
+ || interface_type == GI_INFO_TYPE_UNION);
+
+ /* this test ignores non-objects being sent where interfaces
+ are expected
+ hopefully our type manipluation code will pick that up.
+ The only exception to this is GObject.GValues which are
+ arrays.
+ */
+ if (!is_gvalue && is_struct_or_union && arg_is_object
+ && (seed_pointer_get_pointer(ctx, arguments[i - j])
+ == 0)) {
+ is_null = TRUE;
+ }
+ g_base_info_unref(interface);
}
- if (is_null)
- {
- GIBaseInfo *ctr = g_base_info_get_container((GIBaseInfo *) info);
- // note - ctr does not need unref'ing (see ginfo.c source for why)
-
- // RE-INSTATE THIS CODE LATER.. - when gtk etc. has be release with fixes
- //seed_make_exception (ctx, exception,
- // "ArgumentError",
- g_warning( "ArgumentError - probably due to incorrect gir file (which may be fixed upstream)"
- " argument %d must not be null for"
- " function: %s%s%s \n",
- i + 1,
- ctr ? g_base_info_get_name ((GIBaseInfo *) ctr) : "",
- ctr ? "." : "",
- g_base_info_get_name ((GIBaseInfo *)
- info));
- //goto arg_error;
+ if (is_null) {
+ GIBaseInfo* ctr
+ = g_base_info_get_container((GIBaseInfo*) info);
+ // note - ctr does not need unref'ing (see ginfo.c source
+ // for why)
+
+ // RE-INSTATE THIS CODE LATER.. - when gtk etc. has be
+ // release with fixes
+ // seed_make_exception (ctx, exception,
+ // "ArgumentError",
+ g_warning("ArgumentError - probably due to incorrect gir "
+ "file (which may be fixed upstream)"
+ " argument %d must not be null for"
+ " function: %s%s%s \n",
+ i + 1,
+ ctr ? g_base_info_get_name((GIBaseInfo*) ctr)
+ : "",
+ ctr ? "." : "",
+ g_base_info_get_name((GIBaseInfo*) info));
+ // goto arg_error;
}
}
- if (!seed_value_to_gi_argument (ctx, arguments[i], type_info,
- &in_args[n_in_args++], exception))
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "Unable to make argument %d for"
- " function: %s. \n",
- i + 1,
- g_base_info_get_name ((GIBaseInfo *)
- info));
-
-
- retval_ref = JSValueMakeNull (ctx);
- goto invoke_return;
-
- }
- if (dir == GI_DIRECTION_INOUT)
- {
- GArgument *out_value = &out_values[n_out_args];
- out_args[n_out_args++].v_pointer = out_value;
- out_pos[ i ] = n_out_args;
- }
-
- }
- else if (dir == GI_DIRECTION_OUT)
- {
- GArgument *out_value = &out_values[n_out_args];
- out_values[n_out_args].v_pointer = NULL;
- out_args[n_out_args].v_pointer = out_value;
- out_pos[ i ] = n_out_args;
- if (is_caller_allocates)
- {
- gsize size = g_struct_info_get_size ( (GIStructInfo *) iface_info) ;
- out_args[n_out_args].v_pointer = g_malloc0 (size);
- out_values[n_out_args].v_pointer = out_args[n_out_args].v_pointer;
- caller_allocated[i] = TRUE;
-
- }
- n_out_args++;
- first_out = first_out > -1 ? first_out : i;
-
- }
-
- g_base_info_unref ((GIBaseInfo *) type_info);
- g_base_info_unref ((GIBaseInfo *) arg_info);
- if (iface_info) g_base_info_unref (iface_info);
- iface_info = NULL;
- type_info = NULL;
- arg_info = NULL;
+ guint out_length = 0;
+ if (!seed_value_to_gi_argument_with_out_length(
+ ctx, arguments[i - j], type_info, transfer,
+ &in_args[n_in_args++], &out_length, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unable to make argument %d for"
+ " function: %s. \n",
+ i + 1,
+ g_base_info_get_name((GIBaseInfo*) info));
+
+ retval_ref = JSValueMakeNull(ctx);
+ goto invoke_return;
+ }
+
+ // check if what we did we did on an array,
+ // if yes, fill the g_type_info_get_array_length() position with the
+ // size of the array and mark it as already skipped.
+ GITypeTag type_tag = g_type_info_get_tag(type_info);
+ gint array_len_pos = g_type_info_get_array_length(type_info);
+ if (type_tag == GI_TYPE_TAG_ARRAY
+ && g_type_info_get_array_type(type_info) == GI_ARRAY_TYPE_C
+ && array_len_pos >= 0) {
+ skipped_args[array_len_pos] = TRUE;
+ in_args[array_len_pos + 1].v_uint64 = out_length;
+ }
+
+ if (dir == GI_DIRECTION_INOUT) {
+ GArgument* out_value = &out_values[n_out_args];
+ out_args[n_out_args++].v_pointer = out_value;
+ out_pos[i] = n_out_args;
+ }
+
+ } else if (dir == GI_DIRECTION_OUT) {
+ GArgument* out_value = &out_values[n_out_args];
+ out_values[n_out_args].v_pointer = NULL;
+ out_args[n_out_args].v_pointer = out_value;
+ out_pos[i] = n_out_args;
+ if (is_caller_allocates) {
+ gsize size = g_struct_info_get_size((GIStructInfo*) iface_info);
+ out_args[n_out_args].v_pointer = g_malloc0(size);
+ out_values[n_out_args].v_pointer
+ = out_args[n_out_args].v_pointer;
+ caller_allocated[i] = TRUE;
+ }
+ n_out_args++;
+ first_out = first_out > -1 ? first_out : i;
+ }
+
+ g_base_info_unref((GIBaseInfo*) type_info);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ if (iface_info)
+ g_base_info_unref(iface_info);
+ iface_info = NULL;
+ type_info = NULL;
+ arg_info = NULL;
}
-
-
- // --- Finished building the args, now call the method / function.
-
-
- SEED_NOTE (INVOCATION, "Invoking method: %s with %d 'in' arguments"
- " and %d 'out' arguments",
- g_base_info_get_name (info), n_in_args, n_out_args);
- if (!g_function_info_invoke ((GIFunctionInfo *) info,
- in_args,
- n_in_args,
- out_args, n_out_args, &retval, &error))
- {
-
- // failed...
- seed_make_exception_from_gerror (ctx, exception, error);
- g_error_free (error);
- retval_ref = JSValueMakeNull (ctx);
- goto invoke_return;
-
+
+ // --- Finished building the args, now call the method / function.
+
+ SEED_NOTE(INVOCATION, "Invoking method: %s with %d 'in' arguments"
+ " and %d 'out' arguments",
+ g_base_info_get_name(info), n_in_args, n_out_args);
+ if (!g_function_info_invoke((GIFunctionInfo*) info, in_args, n_in_args,
+ out_args, n_out_args, &retval, &error)) {
+
+ // failed...
+ seed_make_exception_from_gerror(ctx, exception, error);
+ g_error_free(error);
+ retval_ref = JSValueMakeNull(ctx);
+ goto invoke_return;
}
-
- // -- returned OK..
-
- type_info = g_callable_info_get_return_type ((GICallableInfo *) info);
- tag = g_type_info_get_tag (type_info);
+
+ // -- returned OK..
+
+ type_info = g_callable_info_get_return_type((GICallableInfo*) info);
+ tag = g_type_info_get_tag(type_info);
// might need to add g_type_info_is_pointer (type_info) check here..
-
- if (tag == GI_TYPE_TAG_VOID)
- {
- // if we have no out args - returns undefined
- // otherwise we return an object, and put the return values into that
- // along with supporting the old object.value way
- if (n_out_args < 1)
- retval_ref = JSValueMakeUndefined (ctx);
- else
- {
- retval_ref = JSObjectMake (ctx, NULL, NULL);
- use_return_as_out = 1;
- }
- }
- else
- {
-
- // not a void return.
-
- GIBaseInfo *interface;
- gboolean sunk = FALSE;
-
- // for most returns we just pump it though our type convert calls.
- // however gobjects are different, if they are not owned by anybody,
- // then we add a ref so that it can not be destroyed during this process.
- // this ref is removed after we have converted it to a JSObject.
-
- if (tag == GI_TYPE_TAG_INTERFACE)
- {
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (type_info);
- interface_type = g_base_info_get_type (interface);
- g_base_info_unref (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- if (G_IS_OBJECT (retval.v_pointer))
- {
- sunk =
- G_IS_INITIALLY_UNOWNED (G_OBJECT (retval.v_pointer));
- if (sunk)
- g_object_ref_sink (G_OBJECT (retval.v_pointer));
- }
- }
-
- }
-
- length_arg_pos = g_type_info_get_array_length(type_info);
- SEED_NOTE (INVOCATION, "length_arg_pos=%d\n", length_arg_pos);
- if (length_arg_pos < 0)
- {
- array_len = 0;
- }
- else
- {
- array_len = (&out_values[ out_pos[length_arg_pos] ])->v_uint32;
- }
- SEED_NOTE (INVOCATION, "array_len=%d\n", array_len);
- retval_ref =
- seed_value_from_gi_argument_full (ctx, &retval, type_info, exception,
- array_len, tag);
-
- if (sunk)
- g_object_unref (G_OBJECT (retval.v_pointer));
- else
- seed_gi_release_arg (g_callable_info_get_caller_owns
- ((GICallableInfo *) info),
- type_info, &retval);
- }
- if (type_info) g_base_info_unref ((GIBaseInfo *) type_info);
- type_info = NULL;
-
-
- // finished with return.. now go thorugh the args and handle any out/inout etc..
-
- in_args_pos = out_args_pos = 0;
- for (i = 0; (i < n_args); i++)
- {
- JSValueRef jsout_val;
- arg_info = g_callable_info_get_arg ((GICallableInfo *) info, i);
- dir = g_arg_info_get_direction (arg_info);
- type_info = g_arg_info_get_type (arg_info);
- // since we succesfully called, we can presume that
-
- if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT)
- {
- seed_gi_release_in_arg (g_arg_info_get_ownership_transfer
- (arg_info), type_info,
- &in_args[in_args_pos +
- (instance_method ? 1 : 0)]);
- in_args_pos++;
-
- g_base_info_unref ((GIBaseInfo *) type_info);
- g_base_info_unref ((GIBaseInfo *) arg_info);
- type_info = NULL;
- arg_info = NULL;
-
- continue;
- }
-
- // we are now only dealing with OUT arguments.
-
- // if the type_info is an array with a length position, we
- // need to send that as well, so it can be used to build the seed value.
- {
- length_arg_pos = g_type_info_get_array_length(type_info);
- array_len = 0;
- if (length_arg_pos > -1) {
- GIArgInfo *array_arg_info;
- GITypeInfo *array_type_info;
- GArgument *array_len_arg;
-
- g_assert (out_pos[length_arg_pos] > -1);
-
-
- array_arg_info = g_callable_info_get_arg ((GICallableInfo *) info, length_arg_pos);
- array_type_info = g_arg_info_get_type (array_arg_info);
-
- array_len_arg = &out_values[ out_pos[length_arg_pos] ] ;
-
+
+ // We force a return array in the following situation:
+ // There's more than one n_out_args OR
+ // There's one out_arg AND tag != GI_TYPE_TAG_VOID
+ // AND, of course, if it's not an INTERFACE.
+ gboolean force_return_array = false;
+ force_return_array = (tag != GI_TYPE_TAG_INTERFACE);
+
+ if (force_return_array) {
+ if (n_out_args + !!(tag != GI_TYPE_TAG_VOID) > 1) {
+ retval_ref = JSObjectMakeArray(ctx, NULL, NULL, NULL);
+ use_return_as_out = 1;
+ }
+ }
+
+ if (tag == GI_TYPE_TAG_VOID) {
+ // * if we have no out args - returns undefined
+ // * if we have *one* out_arg but no return type,
+ // do nothing here and return the OUT as return later.
+ // * otherwise we return an object, and put the return values into that
+ // along with supporting the old object.value way
+ if (n_out_args < 1)
+ retval_ref = JSValueMakeUndefined(ctx);
+ else if (n_out_args == 1) {
+ return_only_one_out = true;
+ use_return_as_out = 1;
+ } else {
+ retval_ref = JSObjectMake(ctx, NULL, NULL);
+ use_return_as_out = 1;
+ }
+ } else {
+
+ // not a void return.
+
+ GIBaseInfo* interface;
+ gboolean sunk = FALSE;
+
+ // for most returns we just pump it though our type convert calls.
+ // however gobjects are different, if they are not owned by anybody,
+ // then we add a ref so that it can not be destroyed during this
+ // process.
+ // this ref is removed after we have converted it to a JSObject.
+
+ if (tag == GI_TYPE_TAG_INTERFACE) {
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(type_info);
+ interface_type = g_base_info_get_type(interface);
+ g_base_info_unref(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ if (G_IS_OBJECT(retval.v_pointer)) {
+ sunk = G_IS_INITIALLY_UNOWNED(G_OBJECT(retval.v_pointer));
+ if (sunk)
+ g_object_ref_sink(G_OBJECT(retval.v_pointer));
+ }
+ }
+ }
+
+ length_arg_pos = g_type_info_get_array_length(type_info);
+ SEED_NOTE(INVOCATION, "length_arg_pos=%d\n", length_arg_pos);
+ if (length_arg_pos < 0) {
array_len = 0;
- switch( g_type_info_get_tag (array_type_info) )
- {
- // not sure if the non-unsigned versions are need as length should not be -ve..
- case GI_TYPE_TAG_INT8: array_len = (guint64) array_len_arg->v_int8; break;
- case GI_TYPE_TAG_UINT8:array_len = (guint64) array_len_arg->v_uint8; break;
- case GI_TYPE_TAG_INT16: array_len =(guint64) array_len_arg->v_int16; break;
- case GI_TYPE_TAG_UINT16: array_len =(guint64) array_len_arg->v_uint16; break;
- case GI_TYPE_TAG_INT32: array_len =(guint64) array_len_arg->v_int32; break;
- case GI_TYPE_TAG_UINT32: array_len =(guint64) array_len_arg->v_uint32; break;
- case GI_TYPE_TAG_INT64: array_len = (guint64) array_len_arg->v_int64; break;
- case GI_TYPE_TAG_UINT64: array_len = (guint64) array_len_arg->v_uint64; break;
- default: g_assert(1==0); break;
-
- }
-
- // this may work, but the above should be more accurate..
- //array_len = (&out_values[ out_pos[length_arg_pos] ])->v_uint32;
-
- SEED_NOTE (INVOCATION, "Getting length from OUTPOS=%d, ORIGPOS=%d : result = %d",
- out_pos[length_arg_pos], length_arg_pos, array_len);
- // free stuff.
-
- g_base_info_unref ((GIBaseInfo *) array_type_info);
- g_base_info_unref ((GIBaseInfo *) array_arg_info);
-
- }
-
-
- jsout_val = seed_value_from_gi_argument_full (ctx, &out_values[out_args_pos],
- type_info, exception, array_len, g_type_info_get_tag (type_info) );
-
- }
- /* caller allocates only applies to structures but GI has
- * no way to denote that yet, so we only use caller allocates
- * if we see a structure
- */
-
- if (caller_allocated[i]) {
-
- // this is the old python code..
- // if we are going to do this, the caching the iface_info at the top would be a better idea.
-
- //if (g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) iface_info) == G_TYPE_VALUE)
- // g_value_unset ( (GValue *) state->args[i]);
-
-
- // clear the caller allocated flag so it's not free'd at the end..
- caller_allocated[i] = FALSE;
- }
-
-
- // old ? depreciated ? way to handle out args -> set 'value' on object that was send through.
- out_args_pos++;
-
- if ( (i < argumentCount) &&
- !JSValueIsNull (ctx, arguments[i]) &&
- JSValueIsObject (ctx, arguments[i]))
- {
- seed_object_set_property (ctx, (JSObjectRef) arguments[i],
- "value", jsout_val);
+ } else {
+ array_len = (&out_values[out_pos[length_arg_pos]])->v_uint32;
}
+ SEED_NOTE(INVOCATION, "array_len=%" G_GUINT64_FORMAT "\n", array_len);
+
+ JSValueRef jsout_val
+ = seed_value_from_gi_argument_full(ctx, &retval, type_info, exception,
+ array_len, tag);
+
+ if (use_return_as_out && force_return_array) {
+ _add_jsvalue_in_array(ctx, (JSObjectRef) retval_ref,
+ array_return_value_count++, jsout_val);
+ } else
+ retval_ref = jsout_val;
+
+ if (sunk)
+ g_object_unref(G_OBJECT(retval.v_pointer));
+ else
+ seed_gi_release_arg(g_callable_info_get_caller_owns(
+ (GICallableInfo*) info),
+ type_info, &retval);
+ }
+ if (type_info)
+ g_base_info_unref((GIBaseInfo*) type_info);
+ type_info = NULL;
+ // finished with return.. now go thorugh the args and handle any out/inout
+ // etc..
+
+ in_args_pos = out_args_pos = 0;
+ for (i = 0; (i < n_args); i++) {
+ JSValueRef jsout_val;
+ arg_info = g_callable_info_get_arg((GICallableInfo*) info, i);
+ dir = g_arg_info_get_direction(arg_info);
+ type_info = g_arg_info_get_type(arg_info);
+ // since we succesfully called, we can presume that
+
+ if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT) {
+ seed_gi_release_in_arg(
+ g_arg_info_get_ownership_transfer(arg_info), type_info,
+ &in_args[in_args_pos + (instance_method ? 1 : 0)]);
+ in_args_pos++;
+
+ g_base_info_unref((GIBaseInfo*) type_info);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ type_info = NULL;
+ arg_info = NULL;
+
+ continue;
+ }
- // if we add it to the return argument and/or the first out arguement
+ // we are now only dealing with OUT arguments.
- if (use_return_as_out)
+ // if the type_info is an array with a length position, we
+ // need to send that as well, so it can be used to build the seed value.
{
- seed_object_set_property (ctx, (JSObjectRef) retval_ref,
- g_base_info_get_name((GIBaseInfo*) arg_info) , jsout_val);
+ length_arg_pos = g_type_info_get_array_length(type_info);
+ array_len = 0;
+ if (length_arg_pos > -1) {
+ GIArgInfo* array_arg_info;
+ GITypeInfo* array_type_info;
+ GArgument* array_len_arg;
+
+ g_assert(out_pos[length_arg_pos] > -1);
+
+ array_arg_info = g_callable_info_get_arg((GICallableInfo*) info,
+ length_arg_pos);
+ array_type_info = g_arg_info_get_type(array_arg_info);
+
+ array_len_arg = &out_values[out_pos[length_arg_pos]];
+
+ array_len = 0;
+ switch (g_type_info_get_tag(array_type_info)) {
+ // not sure if the non-unsigned versions are need as length
+ // should not be -ve..
+ case GI_TYPE_TAG_INT8:
+ array_len = (guint64) array_len_arg->v_int8;
+ break;
+ case GI_TYPE_TAG_UINT8:
+ array_len = (guint64) array_len_arg->v_uint8;
+ break;
+ case GI_TYPE_TAG_INT16:
+ array_len = (guint64) array_len_arg->v_int16;
+ break;
+ case GI_TYPE_TAG_UINT16:
+ array_len = (guint64) array_len_arg->v_uint16;
+ break;
+ case GI_TYPE_TAG_INT32:
+ array_len = (guint64) array_len_arg->v_int32;
+ break;
+ case GI_TYPE_TAG_UINT32:
+ array_len = (guint64) array_len_arg->v_uint32;
+ break;
+ case GI_TYPE_TAG_INT64:
+ array_len = (guint64) array_len_arg->v_int64;
+ break;
+ case GI_TYPE_TAG_UINT64:
+ array_len = (guint64) array_len_arg->v_uint64;
+ break;
+ default:
+ g_assert(1 == 0);
+ break;
+ }
+
+ // this may work, but the above should be more accurate..
+ // array_len = (&out_values[ out_pos[length_arg_pos]
+ // ])->v_uint32;
+
+ SEED_NOTE(INVOCATION,
+ "Getting length from OUTPOS=%d, ORIGPOS=%d : "
+ "result = %" G_GUINT64_FORMAT,
+ out_pos[length_arg_pos], length_arg_pos, array_len);
+ // free stuff.
+
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+ g_base_info_unref((GIBaseInfo*) array_arg_info);
+ }
+
+ jsout_val = seed_value_from_gi_argument_full(
+ ctx, &out_values[out_args_pos], type_info, exception, array_len,
+ g_type_info_get_tag(type_info));
}
-
+ /* caller allocates only applies to structures but GI has
+ * no way to denote that yet, so we only use caller allocates
+ * if we see a structure
+ */
- if ( (first_out > -1) &&
- !JSValueIsNull (ctx, arguments[first_out]) &&
- JSValueIsObject (ctx, arguments[first_out]) )
-
- {
- seed_object_set_property (ctx, (JSObjectRef) arguments[first_out],
- g_base_info_get_name((GIBaseInfo*) arg_info) , jsout_val);
+ if (caller_allocated[i]) {
+
+ // this is the old python code..
+ // if we are going to do this, the caching the iface_info at the top
+ // would be a better idea.
+
+ // if (g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *)
+ // iface_info) == G_TYPE_VALUE)
+ // g_value_unset ( (GValue *) state->args[i]);
+
+ // clear the caller allocated flag so it's not free'd at the end..
+ caller_allocated[i] = FALSE;
+ }
+
+ // old ? depreciated ? way to handle out args -> set 'value' on object
+ // that was send through.
+ out_args_pos++;
+
+ if ((i < argumentCount) && !JSValueIsNull(ctx, arguments[i])
+ && JSValueIsObject(ctx, arguments[i])) {
+ seed_object_set_property(ctx, (JSObjectRef) arguments[i], "value",
+ jsout_val);
}
+ // if we add it to the return argument and/or the first out arguement
+
+ if (use_return_as_out) {
+ if (return_only_one_out) {
+ retval_ref = jsout_val;
+ } else if (force_return_array) {
+ _add_jsvalue_in_array(ctx, (JSObjectRef) retval_ref,
+ array_return_value_count++, jsout_val);
+ } else {
+ seed_object_set_property(ctx, (JSObjectRef) retval_ref,
+ g_base_info_get_name(
+ (GIBaseInfo*) arg_info),
+ jsout_val);
+ }
+ }
+
+ if ((first_out > -1) && !JSValueIsNull(ctx, arguments[first_out])
+ && JSValueIsObject(ctx, arguments[first_out]))
+
+ {
+ seed_object_set_property(ctx, (JSObjectRef) arguments[first_out],
+ g_base_info_get_name(
+ (GIBaseInfo*) arg_info),
+ jsout_val);
+ }
- g_base_info_unref ((GIBaseInfo *) arg_info);
- g_base_info_unref ((GIBaseInfo *) type_info);
- type_info = NULL;
- arg_info = NULL;
-
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ g_base_info_unref((GIBaseInfo*) type_info);
+ type_info = NULL;
+ arg_info = NULL;
}
invoke_return:
-
-// clean up everything..
- for (i = 0; (i < (n_args)); i++)
- if (caller_allocated[i])
- g_free(out_args[out_pos[i]].v_pointer);
-
- g_free(caller_allocated);
-
- if (type_info) g_base_info_unref ((GIBaseInfo *) type_info);
- if (arg_info) g_base_info_unref ((GIBaseInfo *) arg_info);
- if (iface_info) g_base_info_unref (iface_info);
-
- g_free (in_args);
- g_free (out_args);
- g_free (out_pos);
- g_free (out_values);
- return retval_ref;
-
-
-
-
+ SEED_NOTE(INVOCATION, "END seed_object_method_invoked for function %s",
+ g_base_info_get_name(info));
+
+ // clean up everything..
+ for (i = 0; (i < (n_args)); i++)
+ if (caller_allocated[i])
+ g_free(out_args[out_pos[i]].v_pointer);
+
+ g_free(caller_allocated);
+
+ if (type_info)
+ g_base_info_unref((GIBaseInfo*) type_info);
+ if (arg_info)
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ if (iface_info)
+ g_base_info_unref(iface_info);
+
+ g_free(in_args);
+ g_free(out_args);
+ g_free(out_pos);
+ g_free(out_values);
+ return retval_ref;
}
static JSObjectRef
-seed_gobject_named_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_named_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- return (JSObjectRef) seed_gobject_method_invoked (ctx, constructor,
- NULL, argumentCount,
- arguments, exception);
+ return (JSObjectRef) seed_gobject_method_invoked(ctx, constructor, NULL,
+ argumentCount, arguments,
+ exception);
}
void
-seed_gobject_define_property_from_function_info (JSContextRef ctx,
- GIFunctionInfo * info,
- JSObjectRef object,
- gboolean instance)
+seed_gobject_define_property_from_function_info(JSContextRef ctx,
+ GIFunctionInfo* info,
+ JSObjectRef object,
+ gboolean instance)
{
- GIFunctionInfoFlags flags;
- JSObjectRef method_ref;
- const gchar *name;
+ GIFunctionInfoFlags flags;
+ JSObjectRef method_ref;
+ const gchar* name;
- //if (g_base_info_is_deprecated ((GIBaseInfo *) info))
- //g_printf("Not defining deprecated symbol: %s \n",
- //g_base_info_get_name((GIBaseInfo *)info));
+ // if (g_base_info_is_deprecated ((GIBaseInfo *) info))
+ // g_printf("Not defining deprecated symbol: %s \n",
+ // g_base_info_get_name((GIBaseInfo *)info));
- flags = g_function_info_get_flags (info);
+ flags = g_function_info_get_flags(info);
- if (instance && (flags & GI_FUNCTION_IS_CONSTRUCTOR))
- {
- return;
+ if (instance && (flags & GI_FUNCTION_IS_CONSTRUCTOR)) {
+ return;
}
- method_ref = JSObjectMake (ctx, gobject_method_class,
- g_base_info_ref ((GIBaseInfo *) info));
-
- JSObjectSetPrototype (ctx, method_ref, function_proto);
+ method_ref = JSObjectMake(ctx, gobject_method_class,
+ g_base_info_ref((GIBaseInfo*) info));
- name = g_base_info_get_name ((GIBaseInfo *) info);
- if (!g_strcmp0 (name, "new"))
- name = "c_new";
- seed_object_set_property (ctx, object, name, method_ref);
-
- seed_object_set_property (ctx, method_ref, "info",
- seed_make_struct (ctx,
- g_base_info_ref ((GIBaseInfo *)
- info),
- base_info_info));
+ JSObjectSetPrototype(ctx, method_ref, function_proto);
+ name = g_base_info_get_name((GIBaseInfo*) info);
+ if (!g_strcmp0(name, "new")) {
+ // To be compatible with gjs, we need to have new as function, too.
+ seed_object_set_property(ctx, object, name, method_ref);
+ name = "c_new";
+ }
+ seed_object_set_property(ctx, object, name, method_ref);
+ /*
+ // Disabled as this crashes in a recursive loop now
+ seed_object_set_property (ctx, method_ref, "info",
+ seed_make_struct (ctx,
+ g_base_info_ref ((GIBaseInfo *)
+ info),
+ base_info_info));
+ */
}
static void
-seed_gobject_add_methods_for_interfaces (JSContextRef ctx,
- GIObjectInfo * oinfo,
- JSObjectRef object)
+seed_gobject_add_methods_for_interfaces(JSContextRef ctx,
+ GIObjectInfo* oinfo,
+ JSObjectRef object)
{
- GIInterfaceInfo *interface;
- GIFunctionInfo *function;
- gint n_interfaces, i, n_functions, k;
-
- n_interfaces = g_object_info_get_n_interfaces (oinfo);
-
- for (i = 0; i < n_interfaces; i++)
- {
- interface = g_object_info_get_interface (oinfo, i);
-
- n_functions = g_interface_info_get_n_methods (interface);
- for (k = 0; k < n_functions; k++)
- {
- function = g_interface_info_get_method (interface, k);
- seed_gobject_define_property_from_function_info
- (ctx, function, object, TRUE);
- }
- // g_base_info_unref((GIBaseInfo*)interface);
+ GIInterfaceInfo* interface;
+ GIFunctionInfo* function;
+ gint n_interfaces, i, n_functions, k;
+
+ n_interfaces = g_object_info_get_n_interfaces(oinfo);
+
+ for (i = 0; i < n_interfaces; i++) {
+ interface = g_object_info_get_interface(oinfo, i);
+
+ n_functions = g_interface_info_get_n_methods(interface);
+ for (k = 0; k < n_functions; k++) {
+ function = g_interface_info_get_method(interface, k);
+ seed_gobject_define_property_from_function_info(ctx, function,
+ object, TRUE);
+ }
+ g_base_info_unref((GIBaseInfo*) interface);
}
}
static void
-seed_gobject_add_methods_for_type (JSContextRef ctx,
- GIObjectInfo * oinfo, JSObjectRef object)
+seed_gobject_add_methods_for_type(JSContextRef ctx,
+ GIObjectInfo* oinfo,
+ JSObjectRef object)
{
- gint n_methods;
- gint i;
- GIFunctionInfo *info;
-
- n_methods = g_object_info_get_n_methods (oinfo);
-
- for (i = 0; i < n_methods; i++)
- {
- info = g_object_info_get_method (oinfo, i);
- seed_gobject_define_property_from_function_info (ctx,
- info, object, TRUE);
- g_base_info_unref ((GIBaseInfo *) info);
+ gint n_methods;
+ gint i;
+ GIFunctionInfo* info;
+
+ n_methods = g_object_info_get_n_methods(oinfo);
+
+ for (i = 0; i < n_methods; i++) {
+ info = g_object_info_get_method(oinfo, i);
+ seed_gobject_define_property_from_function_info(ctx, info, object,
+ TRUE);
+ g_base_info_unref((GIBaseInfo*) info);
}
}
JSClassRef
-seed_gobject_get_class_for_gtype (JSContextRef ctx, GType type)
+seed_gobject_get_class_for_gtype(JSContextRef ctx, GType type)
{
- JSClassDefinition def;
- GType parent;
- JSClassRef ref;
- JSClassRef parent_class = 0;
- GIBaseInfo *info;
- JSObjectRef prototype_obj;
- JSObjectRef parent_prototype;
-
- if ((ref = g_type_get_qdata (type, qname)) != NULL)
- {
- return ref;
+ JSClassDefinition def;
+ GType parent;
+ JSClassRef ref;
+ JSClassRef parent_class = 0;
+ GIBaseInfo* info;
+ JSObjectRef prototype_obj;
+ JSObjectRef parent_prototype;
+
+ if ((ref = g_type_get_qdata(type, qname)) != NULL) {
+ return ref;
}
- info = g_irepository_find_by_gtype (g_irepository_get_default (), type);
+ info = g_irepository_find_by_gtype(g_irepository_get_default(), type);
- memset (&def, 0, sizeof (JSClassDefinition));
+ memset(&def, 0, sizeof(JSClassDefinition));
- def.className = g_type_name (type);
- if ((parent = g_type_parent (type)))
- parent_class = seed_gobject_get_class_for_gtype (ctx, parent);
- def.parentClass = parent_class;
- def.attributes = kJSClassAttributeNoAutomaticPrototype;
+ def.className = g_type_name(type);
+ if ((parent = g_type_parent(type)))
+ parent_class = seed_gobject_get_class_for_gtype(ctx, parent);
+ def.parentClass = parent_class;
+ def.attributes = kJSClassAttributeNoAutomaticPrototype;
- prototype_obj = JSObjectMake (ctx, 0, 0);
- if (parent)
- {
- parent_prototype = seed_gobject_get_prototype_for_gtype (parent);
- if (parent_prototype)
- JSObjectSetPrototype (ctx, prototype_obj, parent_prototype);
+ prototype_obj = JSObjectMake(ctx, 0, 0);
+ if (parent) {
+ parent_prototype = seed_gobject_get_prototype_for_gtype(parent);
+ if (parent_prototype)
+ JSObjectSetPrototype(ctx, prototype_obj, parent_prototype);
}
- ref = JSClassCreate (&def);
- JSClassRetain (ref);
-
- JSValueProtect (ctx, prototype_obj);
-
- g_type_set_qdata (type, qname, ref);
- g_type_set_qdata (type, qprototype, prototype_obj);
-
- if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_OBJECT))
- {
- seed_gobject_add_methods_for_interfaces (ctx, (GIObjectInfo *) info,
- prototype_obj);
- seed_gobject_add_methods_for_type (ctx,
- (GIObjectInfo *) info,
- prototype_obj);
- g_base_info_unref (info);
- }
- else
- {
- GType *interfaces;
- GIFunctionInfo *function;
- GIBaseInfo *interface;
- gint n_functions, k;
- guint i, n;
-
- interfaces = g_type_interfaces (type, &n);
- for (i = 0; i < n; i++)
- {
- interface = g_irepository_find_by_gtype (0, interfaces[i]);
- if (!interface)
- break;
- n_functions =
- g_interface_info_get_n_methods ((GIInterfaceInfo *) interface);
- for (k = 0; k < n_functions; k++)
- {
- function =
- g_interface_info_get_method ((GIInterfaceInfo
- *) interface, k);
- seed_gobject_define_property_from_function_info
- (ctx, function, prototype_obj, TRUE);
- }
- }
+ ref = JSClassCreate(&def);
+ JSClassRetain(ref);
+
+ JSValueProtect(ctx, prototype_obj);
+
+ g_type_set_qdata(type, qname, ref);
+ g_type_set_qdata(type, qprototype, prototype_obj);
+
+ if (info && (g_base_info_get_type(info) == GI_INFO_TYPE_OBJECT)) {
+ seed_gobject_add_methods_for_interfaces(ctx, (GIObjectInfo*) info,
+ prototype_obj);
+ seed_gobject_add_methods_for_type(ctx, (GIObjectInfo*) info,
+ prototype_obj);
+ g_base_info_unref(info);
+ } else {
+ GType* interfaces;
+ GIFunctionInfo* function;
+ GIBaseInfo* interface;
+ gint n_functions, k;
+ guint i, n;
+
+ interfaces = g_type_interfaces(type, &n);
+ for (i = 0; i < n; i++) {
+ interface = g_irepository_find_by_gtype(0, interfaces[i]);
+ if (!interface)
+ break;
+ n_functions
+ = g_interface_info_get_n_methods((GIInterfaceInfo*) interface);
+ for (k = 0; k < n_functions; k++) {
+ function
+ = g_interface_info_get_method((GIInterfaceInfo*) interface,
+ k);
+ seed_gobject_define_property_from_function_info(ctx, function,
+ prototype_obj,
+ TRUE);
+ }
+ }
}
- return ref;
+ return ref;
}
JSObjectRef
-seed_gobject_get_prototype_for_gtype (GType type)
+seed_gobject_get_prototype_for_gtype(GType type)
{
- JSObjectRef prototype = 0;
- while (type && !prototype)
- {
- prototype = g_type_get_qdata (type, qprototype);
- type = g_type_parent (type);
+ JSObjectRef prototype = 0;
+ while (type && !prototype) {
+ prototype = g_type_get_qdata(type, qprototype);
+ type = g_type_parent(type);
}
- return prototype;
+ return prototype;
}
static void
-seed_gobject_finalize (JSObjectRef object)
+seed_gobject_finalize(JSObjectRef object)
{
- GObject *gobject;
-
- gobject = (GObject *) JSObjectGetPrivate ((JSObjectRef) object);
- if (!gobject)
- {
- SEED_NOTE (FINALIZATION,
- "Attempting to finalize already destroyed object.");
- return;
+ GObject* gobject;
+ JSObjectRef js_ref;
+
+ gobject = (GObject*) JSObjectGetPrivate((JSObjectRef) object);
+ if (!gobject) {
+ SEED_NOTE(FINALIZATION,
+ "Attempting to finalize already destroyed object.");
+ return;
}
- SEED_NOTE (FINALIZATION, "%s at %p (%d refs)",
- g_type_name (G_OBJECT_TYPE (gobject)), gobject,
- gobject->ref_count);
-
- if (g_object_get_data (gobject, "js-ref"))
- {
- g_object_set_data_full (gobject, "js-ref", NULL, NULL);
-
- g_object_remove_toggle_ref (gobject, seed_toggle_ref, 0);
+ SEED_NOTE(FINALIZATION, "%s at %p (%d refs)",
+ g_type_name(G_OBJECT_TYPE(gobject)), gobject, gobject->ref_count);
+
+ js_ref = g_object_get_qdata(gobject, js_ref_quark);
+ if (js_ref) {
+ /* Steal the qdata here as otherwise we will call
+ * JSValueUnprotect() from the destroy notify of
+ * the qdata, which is not allowed to be called
+ * from a finalizer!
+ */
+ g_object_steal_qdata(gobject, js_ref_quark);
+
+ g_object_remove_toggle_ref(gobject, seed_toggle_ref, js_ref);
+ } else {
+ g_object_run_dispose(gobject);
}
- g_object_run_dispose (gobject);
}
static JSValueRef
-seed_gobject_get_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_gobject_get_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- GParamSpec *spec;
- GObject *b;
- GValue gval = { 0 };
- char *cproperty_name;
- gint length;
- JSValueRef ret;
- guint i;
- gsize len;
-
- b = seed_value_to_object (context, (JSValueRef) object, exception);
- if (!b)
- return 0;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- spec =
- g_object_class_find_property (G_OBJECT_GET_CLASS (b), cproperty_name);
-
- if (!spec)
- {
- len = strlen (cproperty_name) - 1;
- for (i = 0; i < len; i++)
- {
- if (cproperty_name[i] == '_')
- cproperty_name[i] = '-';
- }
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (b),
- cproperty_name);
- if (spec)
- goto found;
- else
- {
- GIFieldInfo *field = NULL;
- GIBaseInfo *info = (GIBaseInfo *)
- g_irepository_find_by_gtype (0, G_OBJECT_TYPE (b));
- gint n;
- const gchar *name;
-
- for (i = 0; i < len; i++)
- {
- if (cproperty_name[i] == '-')
- cproperty_name[i] = '_';
- }
-
- if (!info)
- {
- return NULL;
- }
-
- n = g_object_info_get_n_fields ((GIObjectInfo *) info);
- for (i = 0; i < n; i++)
- {
- field = g_object_info_get_field ((GIObjectInfo *) info, i);
- name = g_base_info_get_name ((GIBaseInfo *) field);
-
- if (!g_strcmp0 (name, cproperty_name))
- goto found_field;
- else
- {
- g_base_info_unref ((GIBaseInfo *) field);
- field = 0;
- }
- }
- found_field:
- if (field)
- {
- ret = seed_field_get_value (context, b, field, exception);
- g_base_info_unref ((GIBaseInfo *) info);
- return ret;
- }
- g_base_info_unref ((GIBaseInfo *) info);
- }
- return NULL;
+ GParamSpec* spec;
+ GObject* b;
+ GValue gval = { 0 };
+ char* cproperty_name;
+ gint length;
+ JSValueRef ret;
+ guint i;
+ gsize len;
+
+ b = seed_value_to_object(context, (JSValueRef) object, exception);
+ if (!b)
+ return 0;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(b), cproperty_name);
+
+ if (!spec) {
+ len = strlen(cproperty_name) - 1;
+ for (i = 0; i < len; i++) {
+ if (cproperty_name[i] == '_')
+ cproperty_name[i] = '-';
+ }
+ spec
+ = g_object_class_find_property(G_OBJECT_GET_CLASS(b), cproperty_name);
+ if (spec)
+ goto found;
+ else {
+ GIFieldInfo* field = NULL;
+ GIBaseInfo* info
+ = (GIBaseInfo*) g_irepository_find_by_gtype(0, G_OBJECT_TYPE(b));
+ gint n;
+ const gchar* name;
+
+ for (i = 0; i < len; i++) {
+ if (cproperty_name[i] == '-')
+ cproperty_name[i] = '_';
+ }
+
+ if (!info) {
+ return NULL;
+ }
+
+ n = g_object_info_get_n_fields((GIObjectInfo*) info);
+ for (i = 0; i < n; i++) {
+ field = g_object_info_get_field((GIObjectInfo*) info, i);
+ name = g_base_info_get_name((GIBaseInfo*) field);
+
+ if (!g_strcmp0(name, cproperty_name))
+ goto found_field;
+ else {
+ g_base_info_unref((GIBaseInfo*) field);
+ field = 0;
+ }
+ }
+ found_field:
+ if (field) {
+ ret = seed_field_get_value(context, b, field, exception);
+ g_base_info_unref((GIBaseInfo*) info);
+ return ret;
+ }
+ g_base_info_unref((GIBaseInfo*) info);
+ }
+ return NULL;
}
found:
- g_value_init (&gval, spec->value_type);
- g_object_get_property (b, cproperty_name, &gval);
- ret = seed_value_from_gvalue (context, &gval, exception);
- g_value_unset (&gval);
+ g_value_init(&gval, spec->value_type);
+ g_object_get_property(b, cproperty_name, &gval);
+ ret = seed_value_from_gvalue(context, &gval, exception);
+ g_value_unset(&gval);
- return (JSValueRef) ret;
+ return (JSValueRef) ret;
}
static bool
-seed_gobject_set_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef value, JSValueRef * exception)
+seed_gobject_set_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef value,
+ JSValueRef* exception)
{
- GParamSpec *spec = 0;
- GObject *obj;
- GValue gval = { 0 };
- GType type;
- gchar *cproperty_name;
- gsize length;
- gsize i, len;
-
- if (pthread_getspecific(seed_next_gobject_wrapper_key) ||
- JSValueIsNull (context, value))
- return 0;
-
-
- obj = seed_value_to_object (context, object, 0);
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj),
- cproperty_name);
-
- if (!spec)
- {
- len = strlen (cproperty_name);
- for (i = 0; i < len; i++)
- {
- if (cproperty_name[i] == '_')
- cproperty_name[i] = '-';
- }
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj),
- cproperty_name);
- if (!spec)
- {
- return FALSE;
- }
+ GParamSpec* spec = 0;
+ GObject* obj;
+ GValue gval = { 0 };
+ GType type;
+ gchar* cproperty_name;
+ gsize length;
+ gsize i, len;
+
+ if (pthread_getspecific(seed_next_gobject_wrapper_key)
+ || JSValueIsNull(context, value))
+ return 0;
+
+ obj = seed_value_to_object(context, object, 0);
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ spec
+ = g_object_class_find_property(G_OBJECT_GET_CLASS(obj), cproperty_name);
+
+ if (!spec) {
+ len = strlen(cproperty_name);
+ for (i = 0; i < len; i++) {
+ if (cproperty_name[i] == '_')
+ cproperty_name[i] = '-';
+ }
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(obj),
+ cproperty_name);
+ if (!spec) {
+ return FALSE;
+ }
}
- if (g_type_is_a (spec->value_type, G_TYPE_ENUM))
- type = G_TYPE_LONG;
- else
- type = spec->value_type;
+ if (g_type_is_a(spec->value_type, G_TYPE_ENUM))
+ type = G_TYPE_LONG;
+ else
+ type = spec->value_type;
- seed_value_to_gvalue (context, value, type, &gval, exception);
- if (*exception)
- {
- return FALSE;
+ seed_value_to_gvalue(context, value, type, &gval, exception);
+ if (*exception) {
+ return FALSE;
}
- if (glib_message)
- {
- g_free (glib_message);
- glib_message = 0;
+ if (glib_message) {
+ g_free(glib_message);
+ glib_message = 0;
}
- g_object_set_property (obj, cproperty_name, &gval);
- if (glib_message != 0)
- {
- seed_make_exception (context, exception, "PropertyError",
- glib_message, NULL);
+ g_object_set_property(obj, cproperty_name, &gval);
+ if (glib_message != 0) {
+ seed_make_exception(context, exception, "PropertyError", glib_message,
+ NULL);
- return FALSE;
+ return FALSE;
}
- g_value_unset (&gval);
+ g_value_unset(&gval);
- return TRUE;
+ return TRUE;
}
static JSValueRef
-seed_gobject_constructor_convert_to_type (JSContextRef ctx,
- JSObjectRef object,
- JSType type, JSValueRef * exception)
+seed_gobject_convert_to_type(JSContextRef ctx,
+ JSObjectRef object,
+ JSType type,
+ JSValueRef* exception)
{
- GType gtype;
- gchar *as_string;
+ GObject* obj;
+ gchar* as_string;
- if (type == kJSTypeString)
- {
- JSValueRef ret;
- gtype = (GType) JSObjectGetPrivate (object);
+ if (type == kJSTypeString) {
+ JSValueRef ret;
+ obj = (GObject*) JSObjectGetPrivate(object);
- as_string =
- g_strdup_printf ("[gobject_constructor %s]", g_type_name (gtype));
- ret = seed_value_from_string (ctx, as_string, exception);
- g_free (as_string);
+ as_string
+ = g_strdup_printf("[gobject %s %p]", G_OBJECT_TYPE_NAME(obj), obj);
+ ret = seed_value_from_string(ctx, as_string, exception);
+ g_free(as_string);
- return ret;
+ return ret;
}
- return FALSE;
+ return FALSE;
}
-JSStaticFunction gobject_static_funcs[] = {
- {"__debug_ref_count", seed_gobject_ref_count, 0}
- ,
- {"__property_type", seed_gobject_property_type, 0}
- ,
- {0, 0, 0}
-};
+static JSValueRef
+seed_gobject_constructor_convert_to_type(JSContextRef ctx,
+ JSObjectRef object,
+ JSType type,
+ JSValueRef* exception)
+{
+ GType gtype;
+ gchar* as_string;
+
+ if (type == kJSTypeString) {
+ JSValueRef ret;
+ gtype = (GType) JSObjectGetPrivate(object);
+
+ as_string
+ = g_strdup_printf("[gobject_constructor %s]", g_type_name(gtype));
+ ret = seed_value_from_string(ctx, as_string, exception);
+ g_free(as_string);
+
+ return ret;
+ }
+ return FALSE;
+}
+
+JSStaticFunction gobject_static_funcs[]
+ = { { "__debug_ref_count", seed_gobject_ref_count, 0 },
+ { "__property_type", seed_gobject_property_type, 0 },
+ { "connect", seed_gobject_signal_connect_by_name, 0 },
+ { 0, 0, 0 } };
JSClassDefinition gobject_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
- "gobject", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- gobject_static_funcs, /* Static Functions */
- NULL,
- seed_gobject_finalize, /* Finalize */
- NULL, /* Has Property */
- seed_gobject_get_property, /* Get Property */
- seed_gobject_set_property, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "gobject", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ gobject_static_funcs, /* Static Functions */
+ NULL,
+ seed_gobject_finalize, /* Finalize */
+ NULL, /* Has Property */
+ seed_gobject_get_property, /* Get Property */
+ seed_gobject_set_property, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ seed_gobject_convert_to_type /* Convert To Type */
};
JSClassDefinition gobject_method_def = {
- 0, /* Version, always 0 */
- 0,
- "gobject_method", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_gobject_method_finalize, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- seed_gobject_method_invoked, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "gobject_method", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ seed_gobject_method_finalize, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ seed_gobject_method_invoked, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition gobject_init_method_def = {
- 0, /* Version, always 0 */
- 0,
- "init_method", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_gobject_method_finalize, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- seed_gobject_init_method_invoked, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "init_method", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ seed_gobject_method_finalize, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ seed_gobject_init_method_invoked, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_callback_def = {
- 0, /* Version, always 0 */
- 0,
- "seed_callback", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* 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 */
+ 0, /* Version, always 0 */
+ 0, "seed_callback", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* 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 */
};
-JSClassDefinition gobject_constructor_def = {
- 0, /* Version, always 0 */
- 0,
- "gobject_constructor", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* 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 */
- seed_gobject_constructor_invoked, /* Call As Constructor */
- seed_gobject_has_instance, /* Has Instance */
- seed_gobject_constructor_convert_to_type
-};
-
-JSClassDefinition gobject_named_constructor_def = {
- 0, /* Version, always 0 */
- 0,
- "gobject_named_constructor", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* 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 */
- seed_gobject_named_constructor_invoked, /* Call As Constructor */
- seed_gobject_has_instance, /* Has Instance */
- seed_gobject_constructor_convert_to_type
-};
+JSClassDefinition gobject_constructor_def
+ = { 0, /* Version, always 0 */
+ 0,
+ "gobject_constructor", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* 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 */
+ seed_gobject_constructor_invoked, /* Call As Constructor */
+ seed_gobject_has_instance, /* Has Instance */
+ seed_gobject_constructor_convert_to_type };
+
+JSClassDefinition gobject_named_constructor_def
+ = { 0, /* Version, always 0 */
+ 0, "gobject_named_constructor", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ // To be compatible with gjs you need to be able to call named
+ // constructors without the new in front
+ seed_gobject_method_invoked, /* Call As Function */
+ seed_gobject_named_constructor_invoked, /* Call As Constructor */
+ seed_gobject_has_instance, /* Has Instance */
+ seed_gobject_constructor_convert_to_type };
JSClassDefinition struct_constructor_def = {
- 0, /* Version, always 0 */
- 0,
- "struct_constructor", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* 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 */
- seed_struct_constructor_invoked, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "struct_constructor", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* 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 */
+ seed_struct_constructor_invoked, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
/**
@@ -1515,7 +1603,7 @@ JSClassDefinition struct_constructor_def = {
* @ctx: A valid #SeedContext
* @name: The name of the function (used in exceptions).
* @func: A #SeedFunctionCallback to implement the function.
- * @obj: The #SeedObject on which to put the function.
+ * @obj: The #SeedObject on which to put the function.
*
* Creates a JavaScript object representing a first-class function; when
* the function is called from JavaScript, @func will be called. Places
@@ -1523,152 +1611,160 @@ JSClassDefinition struct_constructor_def = {
*
*/
void
-seed_create_function (JSContextRef ctx,
- gchar * name, gpointer func, JSObjectRef obj)
+seed_create_function(JSContextRef ctx,
+ gchar* name,
+ gpointer func,
+ JSObjectRef obj)
{
- JSObjectRef oref;
+ JSObjectRef oref;
- oref = JSObjectMakeFunctionWithCallback (ctx, NULL, func);
- seed_object_set_property (ctx, obj, name, oref);
+ oref = JSObjectMakeFunctionWithCallback(ctx, NULL, func);
+ seed_object_set_property(ctx, obj, name, oref);
}
void
-seed_repl_expose (JSContextRef ctx, ...)
+seed_repl_expose(JSContextRef ctx, ...)
{
- va_list argp;
- void *expose;
- JSObjectRef arrayObj;
- guint i = 0;
- JSStringRef script;
- JSObjectRef seed = (JSObjectRef) seed_object_get_property (ctx,
- JSContextGetGlobalObject
- (ctx),
- "Seed");
- va_start (argp, ctx);
-
- arrayObj = JSObjectMake (ctx, NULL, NULL);
-
- g_print ("Seed Debug REPL\n\nExposing:\n");
-
- while ((expose = va_arg (argp, void *)))
- {
- g_print (" Seed.debug_argv[%u] = %p\n", i, expose);
- JSObjectSetPropertyAtIndex (ctx, arrayObj, i++, expose, NULL);
+ va_list argp;
+ void* expose;
+ JSObjectRef arrayObj;
+ guint i = 0;
+ JSStringRef script;
+ JSObjectRef seed
+ = (JSObjectRef) seed_object_get_property(ctx,
+ JSContextGetGlobalObject(ctx),
+ "Seed");
+ va_start(argp, ctx);
+
+ arrayObj = JSObjectMake(ctx, NULL, NULL);
+
+ g_print("Seed Debug REPL\n\nExposing:\n");
+
+ while ((expose = va_arg(argp, void*) )) {
+ g_print(" Seed.debug_argv[%u] = %p\n", i, expose);
+ JSObjectSetPropertyAtIndex(ctx, arrayObj, i++, expose, NULL);
}
- g_print ("\n");
+ g_print("\n");
- seed_object_set_property (ctx, seed, "debug_argv", arrayObj);
+ seed_object_set_property(ctx, seed, "debug_argv", arrayObj);
- script = JSStringCreateWithUTF8CString ("readline = imports.readline;"
- "while(1) { try { print(eval("
- "readline.readline(\"> \"))); } catch(e) {"
- "print(e.name + \" \" + e.message);}}");
+ script = JSStringCreateWithUTF8CString(
+ "readline = imports.readline;"
+ "while(1) { try { print(eval("
+ "readline.readline(\"> \"))); } catch(e) {"
+ "print(e.name + \" \" + e.message);}}");
- JSEvaluateScript (ctx, script, NULL, NULL, 0, NULL);
+ JSEvaluateScript(ctx, script, NULL, NULL, 0, NULL);
- JSStringRelease (script);
+ JSStringRelease(script);
- va_end (argp);
+ va_end(argp);
}
static void
-seed_log_handler (const gchar * domain,
- GLogLevelFlags log_level,
- const gchar * message, gpointer user_data)
+seed_log_handler(const gchar* domain,
+ GLogLevelFlags log_level,
+ const gchar* message,
+ gpointer user_data)
{
- if (glib_message)
- g_free (glib_message);
- glib_message = g_strdup (message);
+ if (glib_message)
+ g_free(glib_message);
+ glib_message = g_strdup(message);
}
#ifdef SEED_ENABLE_DEBUG
static gboolean
-seed_arg_debug_cb (const char *key, const char *value, gpointer user_data)
+seed_arg_debug_cb(const char* key, const char* value, gpointer user_data)
{
- seed_debug_flags |=
- g_parse_debug_string (value,
- seed_debug_keys, G_N_ELEMENTS (seed_debug_keys));
- return TRUE;
+ seed_debug_flags |= g_parse_debug_string(value, seed_debug_keys,
+ G_N_ELEMENTS(seed_debug_keys));
+ return TRUE;
}
static gboolean
-seed_arg_no_debug_cb (const char *key, const char *value, gpointer user_data)
+seed_arg_no_debug_cb(const char* key, const char* value, gpointer user_data)
{
- seed_debug_flags &=
- ~g_parse_debug_string (value,
- seed_debug_keys, G_N_ELEMENTS (seed_debug_keys));
- return TRUE;
+ seed_debug_flags &= ~g_parse_debug_string(value, seed_debug_keys,
+ G_N_ELEMENTS(seed_debug_keys));
+ return TRUE;
}
#endif /* SEED_ENABLE_DEBUG */
-static GOptionEntry seed_args[] = {
+GOptionGroup*
+seed_get_option_group(SeedEngine* eng)
+{
+ GOptionGroup* group;
+
+ GOptionEntry seed_args[] = {
#ifdef SEED_ENABLE_DEBUG
- {"seed-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_debug_cb,
- "Seed debugging messages to show. Comma separated list of: all, misc, finalization, initialization, construction, invocation, signal, structs, gtype.",
- "FLAGS"},
- {"seed-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_no_debug_cb,
- "Disable Seed debugging", "FLAGS"},
+ { "seed-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_debug_cb,
+ "Seed debugging messages to show. Comma separated list of: all, "
+ "misc, "
+ "finalization, initialization, construction, invocation, signal, "
+ "structs, gtype.",
+ "FLAGS" },
+ { "seed-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_no_debug_cb,
+ "Disable Seed debugging", "FLAGS" },
#endif /* SEED_ENABLE_DEBUG */
- {"seed-version", 0, 0, G_OPTION_ARG_NONE, &seed_arg_print_version,
- "Print libseed version", 0},
- {NULL,},
-};
-
-GOptionGroup *
-seed_get_option_group (void)
-{
- GOptionGroup *group;
+ { "seed-version", 0, 0, G_OPTION_ARG_NONE, &seed_arg_print_version,
+ "Print libseed version", 0 },
+ { "program-name", 0, 0, G_OPTION_ARG_STRING, &eng->program_name,
+ "Program Name", 0 },
+ {
+ NULL,
+ },
+ };
- group = g_option_group_new ("seed", "Seed Options",
- "Show Seed Options", NULL, NULL);
- g_option_group_add_entries (group, seed_args);
+ group = g_option_group_new("seed", "Seed Options", "Show Seed Options",
+ NULL, NULL);
+ g_option_group_add_entries(group, seed_args);
- return group;
+ return group;
}
static gboolean
-seed_parse_args (int *argc, char ***argv)
+seed_parse_args(SeedEngine* eng, int* argc, char*** argv)
{
- GOptionContext *option_context;
- GOptionGroup *seed_group;
-
- GError *error = NULL;
- gboolean ret = TRUE;
+ GOptionContext* option_context;
+ GOptionGroup* seed_group;
- option_context = g_option_context_new (NULL);
- g_option_context_set_ignore_unknown_options (option_context, TRUE);
- g_option_context_set_help_enabled (option_context, TRUE);
+ GError* error = NULL;
+ gboolean ret = TRUE;
- /* Initiate any command line options from the backend */
+ option_context = g_option_context_new(NULL);
+ g_option_context_set_ignore_unknown_options(option_context, TRUE);
+ g_option_context_set_help_enabled(option_context, TRUE);
- seed_group = seed_get_option_group ();
- g_option_context_add_group (option_context, seed_group);
+ /* Initiate any command line options from the backend */
+ seed_group = seed_get_option_group(eng);
+ g_option_context_add_group(option_context, seed_group);
- if (!g_option_context_parse (option_context, argc, argv, &error))
- {
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ if (!g_option_context_parse(option_context, argc, argv, &error)) {
+ if (error) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ }
- ret = FALSE;
+ ret = FALSE;
}
- g_option_context_free (option_context);
+ if (!eng->program_name)
+ eng->program_name = g_strdup(*argv[0]);
- return ret;
+ g_option_context_free(option_context);
+
+ return ret;
}
void
-seed_engine_destroy (SeedEngine *eng)
+seed_engine_destroy(SeedEngine* eng)
{
- JSValueUnprotect (eng->context, eng->global);
- JSGlobalContextRelease (eng->context);
- JSContextGroupRelease (eng->group);
+ JSValueUnprotect(eng->context, eng->global);
+ JSGlobalContextRelease(eng->context);
+ JSContextGroupRelease(eng->group);
- g_free (eng);
+ g_free(eng);
}
/**
@@ -1678,15 +1774,18 @@ seed_engine_destroy (SeedEngine *eng)
* @context A reference to an existing JavascriptCore context
* @group: A #SeedContextGroup within which to create the initial context.
*
- * Initializes an empty new #SeedEngine. The Javascript context of this engine is
+ * Initializes an empty new #SeedEngine. The Javascript context of this engine
+ * is
* *not* filled with any builtins functions and the import system.
*
* The javascript code executed with this engine can't import arbitrary
* GObject introspected librairies.
*
- * Use this when control over what is exposed in the Javascript context is required,
+ * Use this when control over what is exposed in the Javascript context is
+ * required,
* for security concerns for example.
- * GObject instances can be selectively exposed by calling @seed_engine_expose_gobject.
+ * GObject instances can be selectively exposed by calling
+ * @seed_engine_expose_gobject.
* Namespaces can be selectively exposed by calling
*
* This function should only be called once within a single Seed application.
@@ -1694,77 +1793,82 @@ seed_engine_destroy (SeedEngine *eng)
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_constrained_with_context_and_group (gint * argc,
- gchar *** argv,
- JSGlobalContextRef context,
- JSContextGroupRef group)
+SeedEngine*
+seed_init_constrained_with_context_and_group(gint* argc,
+ gchar*** argv,
+ JSGlobalContextRef context,
+ JSContextGroupRef group)
{
- g_type_init ();
- g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler, 0);
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+ g_type_init();
+#endif
+ g_log_set_handler("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler, 0);
- if ((argc != 0) && seed_parse_args (argc, argv) == FALSE)
- {
- SEED_NOTE (MISC, "failed to parse arguments.");
- return FALSE;
- }
+ eng = (SeedEngine*) g_malloc(sizeof(SeedEngine));
- if (seed_arg_print_version)
- {
- g_print("%s\n", "Seed " VERSION);
- exit(EXIT_SUCCESS);
+ if ((argc != 0) && seed_parse_args(eng, argc, argv) == FALSE) {
+ SEED_NOTE(MISC, "failed to parse arguments.");
+ return FALSE;
}
- qname = g_quark_from_static_string ("js-type");
- qprototype = g_quark_from_static_string ("js-prototype");
- js_ref_quark = g_quark_from_static_string ("js-ref");
-
- pthread_key_create(&seed_next_gobject_wrapper_key, NULL);
-
- eng = (SeedEngine *) g_malloc (sizeof (SeedEngine));
-
- context_group = group;
-
- eng->context = context;
- eng->global = JSContextGetGlobalObject (eng->context);
- eng->group = context_group;
- eng->search_path = NULL;
-
- function_proto = (JSObjectRef)
- seed_simple_evaluate (eng->context, "Function.prototype", NULL);
-
- gobject_class = JSClassCreate (&gobject_def);
- JSClassRetain (gobject_class);
- gobject_method_class = JSClassCreate (&gobject_method_def);
- JSClassRetain (gobject_method_class);
- gobject_constructor_class = JSClassCreate (&gobject_constructor_def);
- JSClassRetain (gobject_constructor_class);
- gobject_named_constructor_class =
- JSClassCreate (&gobject_named_constructor_def);
- JSClassRetain (gobject_named_constructor_class);
- gobject_signal_class = JSClassCreate (seed_get_signal_class ());
- JSClassRetain (gobject_signal_class);
- seed_callback_class = JSClassCreate (&seed_callback_def);
- JSClassRetain (seed_callback_class);
- seed_struct_constructor_class = JSClassCreate (&struct_constructor_def);
- JSClassRetain (seed_struct_constructor_class);
- gobject_init_method_class = JSClassCreate (&gobject_init_method_def);
- JSClassRetain (gobject_init_method_class);
-
- g_type_set_qdata (G_TYPE_OBJECT, qname, gobject_class);
-
- seed_obj_ref = JSObjectMake (eng->context, NULL, NULL);
- seed_object_set_property (eng->context, eng->global, "Seed", seed_obj_ref);
- JSValueProtect (eng->context, seed_obj_ref);
-
- g_irepository_require (g_irepository_get_default (), "GObject", NULL, 0, 0);
- g_irepository_require (g_irepository_get_default (), "GIRepository",
- NULL, 0, 0);
-
- seed_structs_init ();
- seed_closures_init ();
+ if (seed_arg_print_version) {
+ g_print("%s\n", "Seed " VERSION);
+ exit(EXIT_SUCCESS);
+ }
- return eng;
+ qname = g_quark_from_static_string("js-type");
+ qprototype = g_quark_from_static_string("js-prototype");
+ js_ref_quark = g_quark_from_static_string("js-ref");
+
+ pthread_key_create(&seed_next_gobject_wrapper_key, NULL);
+
+ context_group = group;
+
+ eng->context = context;
+ eng->global = JSContextGetGlobalObject(eng->context);
+ eng->group = context_group;
+ eng->search_path = NULL;
+
+ function_proto
+ = (JSObjectRef) seed_simple_evaluate(eng->context, "Function.prototype",
+ NULL);
+
+ gobject_class = JSClassCreate(&gobject_def);
+ JSClassRetain(gobject_class);
+ gobject_method_class = JSClassCreate(&gobject_method_def);
+ JSClassRetain(gobject_method_class);
+ gobject_constructor_class = JSClassCreate(&gobject_constructor_def);
+ JSClassRetain(gobject_constructor_class);
+ gobject_named_constructor_class
+ = JSClassCreate(&gobject_named_constructor_def);
+ JSClassRetain(gobject_named_constructor_class);
+ gobject_signal_class = JSClassCreate(seed_get_signal_class());
+ JSClassRetain(gobject_signal_class);
+ seed_callback_class = JSClassCreate(&seed_callback_def);
+ JSClassRetain(seed_callback_class);
+ seed_struct_constructor_class = JSClassCreate(&struct_constructor_def);
+ JSClassRetain(seed_struct_constructor_class);
+ gobject_init_method_class = JSClassCreate(&gobject_init_method_def);
+ JSClassRetain(gobject_init_method_class);
+
+ g_type_set_qdata(G_TYPE_OBJECT, qname, gobject_class);
+
+ seed_obj_ref = JSObjectMake(eng->context, NULL, NULL);
+ seed_object_set_property(eng->context, eng->global, "Seed", seed_obj_ref);
+ JSValueProtect(eng->context, seed_obj_ref);
+
+ window_obj_ref = JSObjectMake(eng->context, NULL, NULL);
+ seed_object_set_property(eng->context, eng->global, "window",
+ window_obj_ref);
+ JSValueProtect(eng->context, window_obj_ref);
+ g_irepository_require(g_irepository_get_default(), "GObject", NULL, 0, 0);
+ g_irepository_require(g_irepository_get_default(), "GIRepository", NULL, 0,
+ 0);
+
+ seed_structs_init();
+ seed_closures_init();
+
+ return eng;
}
/**
@@ -1784,30 +1888,29 @@ seed_init_constrained_with_context_and_group (gint * argc,
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_with_context_and_group (gint * argc,
- gchar *** argv, JSGlobalContextRef context, JSContextGroupRef group)
+SeedEngine*
+seed_init_with_context_and_group(gint* argc,
+ gchar*** argv,
+ JSGlobalContextRef context,
+ JSContextGroupRef group)
{
- eng = seed_init_constrained_with_context_and_group (argc, argv, context, group);
- seed_init_builtins (eng, argc, argv);
- seed_initialize_importer (eng->context, eng->global);
- seed_gtype_init (eng);
+ eng = seed_init_constrained_with_context_and_group(argc, argv, context,
+ group);
+ seed_init_builtins(eng, argc, argv);
+ seed_initialize_importer(eng->context, eng->global);
+ seed_gtype_init(eng);
- defaults_script =
- JSStringCreateWithUTF8CString ("Seed.include(\"" SEED_PREFIX_PATH
- "extensions/Seed.js\");");
+ defaults_script = JSStringCreateWithUTF8CString(
+ "Seed.include(\"/org/seed/extensions/Seed.js\");");
- JSEvaluateScript (eng->context, defaults_script, NULL, NULL, 0, NULL);
+ JSEvaluateScript(eng->context, defaults_script, NULL, NULL, 0, NULL);
- base_info_info =
- g_irepository_find_by_name (0, "GIRepository", "IBaseInfo");
+ base_info_info = g_irepository_find_by_name(0, "GIRepository", "BaseInfo");
- return eng;
+ return eng;
}
-
-
/**
* seed_init_with_context_group:
* @argc: A reference to the number of arguments remaining to parse.
@@ -1823,11 +1926,11 @@ seed_init_with_context_and_group (gint * argc,
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_with_context_group (gint * argc,
- gchar *** argv, JSContextGroupRef group)
+SeedEngine*
+seed_init_with_context_group(gint* argc, gchar*** argv, JSContextGroupRef group)
{
- return seed_init_with_context_and_group (argc, argv, JSGlobalContextCreateInGroup (group, NULL), group);
+ return seed_init_with_context_and_group(
+ argc, argv, JSGlobalContextCreateInGroup(group, NULL), group);
}
/**
@@ -1844,12 +1947,12 @@ seed_init_with_context_group (gint * argc,
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init (gint * argc, gchar *** argv)
+SeedEngine*
+seed_init(gint* argc, gchar*** argv)
{
- context_group = JSContextGroupCreate ();
+ context_group = JSContextGroupCreate();
- return seed_init_with_context_group (argc, argv, context_group);
+ return seed_init_with_context_group(argc, argv, context_group);
}
/**
@@ -1858,7 +1961,7 @@ seed_init (gint * argc, gchar *** argv)
* @argv: A reference to an array of string arguments remaining to parse.
* @context A reference to an existing JavascriptCore context
- * Initializes a new #SeedEngine using an existing JavascriptCore context.
+ * Initializes a new #SeedEngine using an existing JavascriptCore context.
* This involves initializing GLib, adding the default globals to the provided
* @context and initializing various internal parts of Seed.
*
@@ -1867,12 +1970,12 @@ seed_init (gint * argc, gchar *** argv)
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
+SeedEngine*
+seed_init_with_context(gint* argc, gchar*** argv, JSGlobalContextRef context)
{
- context_group = JSContextGetGroup (context);
+ context_group = JSContextGetGroup(context);
- return seed_init_with_context_and_group (argc, argv, context, context_group);
+ return seed_init_with_context_and_group(argc, argv, context, context_group);
}
/**
@@ -1880,15 +1983,18 @@ seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
* @argc: A reference to the number of arguments remaining to parse.
* @argv: A reference to an array of string arguments remaining to parse.
*
- * Initializes an empty new #SeedEngine. The Javascript context of this engine is
+ * Initializes an empty new #SeedEngine. The Javascript context of this engine
+ * is
* *not* filled with any builtins functions and the import system.
*
* The javascript code executed with this engine can't import arbitrary
* GObject introspected librairies.
*
- * Use this when control over what is exposed in the Javascript context is required,
+ * Use this when control over what is exposed in the Javascript context is
+ * required,
* for security concerns for example.
- * GObject instances can be selectively exposed by calling @seed_engine_expose_gobject.
+ * GObject instances can be selectively exposed by calling
+ * @seed_engine_expose_gobject.
* Namespaces can be selectively exposed by calling
*
* This function should only be called once within a single Seed application.
@@ -1896,88 +2002,93 @@ seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_constrained (gint * argc, gchar *** argv)
+SeedEngine*
+seed_init_constrained(gint* argc, gchar*** argv)
{
- context_group = JSContextGroupCreate ();
+ context_group = JSContextGroupCreate();
- return seed_init_constrained_with_context_and_group(argc, argv,
- JSGlobalContextCreateInGroup (context_group, NULL),
- context_group);
+ return seed_init_constrained_with_context_and_group(
+ argc, argv, JSGlobalContextCreateInGroup(context_group, NULL),
+ context_group);
}
/*
* seed_engine_expose_gobject:
* @engine:
* @name: The name of the global javascript variable pointing to @object
- * @object: The #GObject instance that will be exposed in the the javascript context
- * @gir_namespace: The Introspection namespace containing the type of the provided
+ * @object: The #GObject instance that will be exposed in the the javascript
+ * context
+ * @gir_namespace: The Introspection namespace containing the type of the
+ * provided
* object.
*
- * Expose a GObject instance to the global Javascript context and makes it accessible
+ * Expose a GObject instance to the global Javascript context and makes it
+ * accessible
* under the provided @js_name
*
* return: the SeedValue representing @object, NULL in case of error
*/
JSValueRef
-seed_engine_expose_gobject (SeedEngine *engine,
- gchar *js_name,
- GObject *object,
- gchar *gir_namespace,
- JSValueRef * exception)
+seed_engine_expose_gobject(SeedEngine* engine,
+ gchar* js_name,
+ GObject* object,
+ gchar* gir_namespace,
+ JSValueRef* exception)
{
- GError *error = NULL;
+ GError* error = NULL;
- g_assert (engine != NULL && gir_namespace != NULL && js_name != NULL);
+ g_assert(engine != NULL && gir_namespace != NULL && js_name != NULL);
- GITypelib *type_lib = g_irepository_require (g_irepository_get_default(),
- gir_namespace, NULL, 0, &error);
- if (type_lib == NULL)
- {
- seed_make_exception_from_gerror (engine->context, exception, error);
- g_error_free (error);
- return NULL;
- }
+ GITypelib* type_lib = g_irepository_require(g_irepository_get_default(),
+ gir_namespace, NULL, 0, &error);
+ if (type_lib == NULL) {
+ seed_make_exception_from_gerror(engine->context, exception, error);
+ g_error_free(error);
+ return NULL;
+ }
- JSValueRef obj_js_value = seed_value_from_object (engine->context,
- G_OBJECT(object),
- exception);
- g_return_val_if_fail (obj_js_value != NULL, NULL);
+ JSValueRef obj_js_value
+ = seed_value_from_object(engine->context, G_OBJECT(object), exception);
+ g_return_val_if_fail(obj_js_value != NULL, NULL);
- g_return_val_if_fail (engine->global != NULL, NULL);
+ g_return_val_if_fail(engine->global != NULL, NULL);
- gboolean ok = seed_object_set_property (engine->context,
- engine->global, js_name, obj_js_value);
- g_return_val_if_fail (ok == TRUE, NULL);
+ gboolean ok = seed_object_set_property(engine->context, engine->global,
+ js_name, obj_js_value);
+ g_return_val_if_fail(ok == TRUE, NULL);
- return obj_js_value;
+ return obj_js_value;
}
/*
* seed_engine_expose_namespace:
* @engine:
- * @namespace: Name of the GIR Namespace that should be exposed in the JS context.
+ * @namespace: Name of the GIR Namespace that should be exposed in the JS
+ * context.
*
- * Expose a GIR namespace in the global Javascript context and makes it accessible
- * under a variable named after the namespace (ex: the namespace 'Notify' is held
+ * Expose a GIR namespace in the global Javascript context and makes it
+ * accessible
+ * under a variable named after the namespace (ex: the namespace 'Notify' is
+ * held
* by the 'Notify' javascript variable.
*
* return: the SeedValue representing @namespace in the javascript context,
* NULL in case of error
*/
JSValueRef
-seed_engine_expose_namespace (SeedEngine *engine,
- gchar *namespace_name,
- JSValueRef *exception)
+seed_engine_expose_namespace(SeedEngine* engine,
+ gchar* namespace_name,
+ JSValueRef* exception)
{
- g_assert (engine != NULL && namespace_name != NULL);
+ g_assert(engine != NULL && namespace_name != NULL);
- JSValueRef namespace = seed_gi_importer_do_namespace (engine->context,
- namespace_name, exception);
- g_return_val_if_fail (namespace != NULL, NULL);
- gboolean ok = seed_object_set_property (engine->context,
- engine->global, namespace_name, namespace);
- g_return_val_if_fail (ok == TRUE, FALSE);
+ JSValueRef namespace
+ = seed_gi_importer_do_namespace(engine->context, namespace_name,
+ exception);
+ g_return_val_if_fail(namespace != NULL, NULL);
+ gboolean ok = seed_object_set_property(engine->context, engine->global,
+ namespace_name, namespace);
+ g_return_val_if_fail(ok == TRUE, FALSE);
- return namespace;
+ return namespace;
}
diff --git a/libseed/seed-engine.h b/libseed/seed-engine.h
index 4adcde5..0905420 100644
--- a/libseed/seed-engine.h
+++ b/libseed/seed-engine.h
@@ -32,7 +32,7 @@ extern JSClassRef gobject_init_method_class;
extern pthread_key_t seed_next_gobject_wrapper_key;
extern JSClassRef seed_callback_class;
-extern SeedEngine *eng;
+extern SeedEngine* eng;
extern JSObjectRef seed_obj_ref;
@@ -42,44 +42,48 @@ extern JSStringRef defaults_script;
typedef struct _SeedScript
{
- JSStringRef script;
- JSValueRef exception;
+ JSStringRef script;
+ JSValueRef exception;
- JSStringRef source_url;
- gint line_number;
+ JSStringRef source_url;
+ gint line_number;
} SeedScript;
-JSObjectRef seed_gobject_get_prototype_for_gtype (GType type);
-JSClassRef seed_gobject_get_class_for_gtype (JSContextRef ctx, GType type);
+JSObjectRef seed_gobject_get_prototype_for_gtype(GType type);
+JSClassRef seed_gobject_get_class_for_gtype(JSContextRef ctx, GType type);
-void
-seed_gobject_define_property_from_function_info (JSContextRef ctx,
- GIFunctionInfo * info,
- JSObjectRef object,
- gboolean instance);
-void seed_create_function (JSContextRef ctx, gchar * name,
- gpointer func, JSObjectRef obj);
+void seed_gobject_define_property_from_function_info(JSContextRef ctx,
+ GIFunctionInfo* info,
+ JSObjectRef object,
+ gboolean instance);
+void seed_create_function(JSContextRef ctx,
+ gchar* name,
+ gpointer func,
+ JSObjectRef obj);
-void seed_repl_expose (JSContextRef ctx, ...);
+void seed_repl_expose(JSContextRef ctx, ...);
-typedef JSObjectRef (*SeedModuleInitCallback) (SeedEngine * eng);
+typedef JSObjectRef (*SeedModuleInitCallback)(SeedEngine* eng);
-void seed_prepare_global_context (JSContextRef ctx);
+void seed_prepare_global_context(JSContextRef ctx);
-SeedScript *seed_make_script (JSContextRef ctx,
- const gchar * js,
- const gchar * source_url, gint line_number);
-SeedScript *seed_script_new_from_file (JSContextRef ctx, gchar * file);
-JSValueRef seed_script_exception (SeedScript * s);
+SeedScript* seed_make_script(JSContextRef ctx,
+ const gchar* js,
+ const gchar* source_url,
+ gint line_number);
+SeedScript* seed_script_new_from_file(JSContextRef ctx, gchar* file);
+JSValueRef seed_script_exception(SeedScript* s);
-JSValueRef seed_evaluate (JSContextRef ctx, SeedScript * script,
- JSObjectRef this);
+JSValueRef seed_evaluate(JSContextRef ctx,
+ SeedScript* script,
+ JSObjectRef this);
-void seed_script_destroy (SeedScript * s);
+void seed_script_destroy(SeedScript* s);
-JSValueRef seed_simple_evaluate (JSContextRef ctx, const gchar * script,
- JSValueRef * exception);
+JSValueRef seed_simple_evaluate(JSContextRef ctx,
+ const gchar* script,
+ JSValueRef* exception);
-GOptionGroup * seed_get_option_group (void);
+GOptionGroup* seed_get_option_group(SeedEngine* engine);
#endif
diff --git a/libseed/seed-exceptions.c b/libseed/seed-exceptions.c
index abaa210..6336b21 100644
--- a/libseed/seed-exceptions.c
+++ b/libseed/seed-exceptions.c
@@ -35,48 +35,48 @@
*
*/
void
-seed_make_exception (JSContextRef ctx,
- JSValueRef * exception,
- const gchar * name, const gchar * message, ...)
+seed_make_exception(JSContextRef ctx,
+ JSValueRef* exception,
+ const gchar* name,
+ const gchar* message,
+ ...)
{
- JSStringRef js_name = 0;
- JSStringRef js_message = 0;
- JSValueRef js_name_ref = 0, js_message_ref = 0;
- JSObjectRef exception_obj;
- gchar *mes;
- va_list args;
+ JSStringRef js_name = 0;
+ JSStringRef js_message = 0;
+ JSValueRef js_name_ref = 0, js_message_ref = 0;
+ JSObjectRef exception_obj;
+ gchar* mes;
+ va_list args;
- if (!exception)
- return;
+ if (!exception)
+ return;
- va_start (args, message);
+ va_start(args, message);
- if (name)
- {
- js_name = JSStringCreateWithUTF8CString (name);
- js_name_ref = JSValueMakeString (ctx, js_name);
+ if (name) {
+ js_name = JSStringCreateWithUTF8CString(name);
+ js_name_ref = JSValueMakeString(ctx, js_name);
}
- if (message)
- {
- mes = g_strdup_vprintf (message, args);
- js_message = JSStringCreateWithUTF8CString (mes);
- js_message_ref = JSValueMakeString (ctx, js_message);
- g_free (mes);
+ if (message) {
+ mes = g_strdup_vprintf(message, args);
+ js_message = JSStringCreateWithUTF8CString(mes);
+ js_message_ref = JSValueMakeString(ctx, js_message);
+ g_free(mes);
}
- // TODO: needs to create a global class named 'name', and this needs to
- // be an instance of it, for integration with normal JS!
+ // TODO: needs to create a global class named 'name', and this needs to
+ // be an instance of it, for integration with normal JS!
- exception_obj = JSObjectMake (ctx, 0, NULL);
- seed_object_set_property (ctx, exception_obj, "message", js_message_ref);
- seed_object_set_property (ctx, exception_obj, "name", js_name_ref);
+ exception_obj = JSObjectMake(ctx, 0, NULL);
+ seed_object_set_property(ctx, exception_obj, "message", js_message_ref);
+ seed_object_set_property(ctx, exception_obj, "name", js_name_ref);
- *exception = exception_obj;
+ *exception = exception_obj;
- JSStringRelease (js_name);
- JSStringRelease (js_message);
+ JSStringRelease(js_name);
+ JSStringRelease(js_message);
- va_end (args);
+ va_end(args);
}
/**
@@ -89,29 +89,26 @@ seed_make_exception (JSContextRef ctx,
*
*/
void
-seed_make_exception_from_gerror (JSContextRef ctx,
- JSValueRef * exception, GError * error)
+seed_make_exception_from_gerror(JSContextRef ctx,
+ JSValueRef* exception,
+ GError* error)
{
- const gchar *domain = g_quark_to_string (error->domain);
- GString *string = g_string_new (domain);
- guint i;
- gsize len = string->len;
-
- *(string->str) = g_unichar_toupper (*(string->str));
- for (i = 0; i < len; i++)
- {
- if (*(string->str + i) == '-')
- {
- *(string->str + i + 1) = g_unichar_toupper (*(string->str + i + 1));
- g_string_erase (string, i, 1);
- }
- else if (!g_strcmp0 (string->str + i - 1, "Quark"))
- g_string_truncate (string, i - 1);
+ const gchar* domain = g_quark_to_string(error->domain);
+ GString* string = g_string_new(domain);
+ guint i;
+ gsize len = string->len;
+ *(string->str) = g_unichar_toupper(*(string->str));
+ for (i = 0; i < len; i++) {
+ if (*(string->str + i) == '-') {
+ *(string->str + i + 1) = g_unichar_toupper(*(string->str + i + 1));
+ g_string_erase(string, i, 1);
+ } else if (!g_strcmp0(string->str + i - 1, "Quark"))
+ g_string_truncate(string, i - 1);
}
- seed_make_exception (ctx, exception, string->str, error->message, NULL);
+ seed_make_exception(ctx, exception, string->str, error->message, NULL);
- g_string_free (string, TRUE);
+ g_string_free(string, TRUE);
}
/**
@@ -126,16 +123,16 @@ seed_make_exception_from_gerror (JSContextRef ctx,
* Return value: A #gchar* representing the name of @exception.
*
*/
-gchar *
-seed_exception_get_name (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_name(JSContextRef ctx, JSValueRef e)
{
- JSValueRef name;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return NULL;
+ JSValueRef name;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return NULL;
- name = seed_object_get_property (ctx, (JSObjectRef) e, "name");
- return seed_value_to_string (ctx, name, NULL);
+ name = seed_object_get_property(ctx, (JSObjectRef) e, "name");
+ return seed_value_to_string(ctx, name, NULL);
}
/**
@@ -151,16 +148,16 @@ seed_exception_get_name (JSContextRef ctx, JSValueRef e)
* Return value: A #gchar* representing the detailed message of @exception.
*
*/
-gchar *
-seed_exception_get_message (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_message(JSContextRef ctx, JSValueRef e)
{
- JSValueRef name;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
+ JSValueRef name;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
- name = seed_object_get_property (ctx, (JSObjectRef) e, "message");
- return seed_value_to_string (ctx, name, NULL);
+ name = seed_object_get_property(ctx, (JSObjectRef) e, "message");
+ return seed_value_to_string(ctx, name, NULL);
}
/**
@@ -176,14 +173,14 @@ seed_exception_get_message (JSContextRef ctx, JSValueRef e)
*
*/
guint
-seed_exception_get_line (JSContextRef ctx, JSValueRef e)
+seed_exception_get_line(JSContextRef ctx, JSValueRef e)
{
- JSValueRef line;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
- line = seed_object_get_property (ctx, (JSObjectRef) e, "line");
- return seed_value_to_uint (ctx, line, NULL);
+ JSValueRef line;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
+ line = seed_object_get_property(ctx, (JSObjectRef) e, "line");
+ return seed_value_to_uint(ctx, line, NULL);
}
/**
@@ -198,15 +195,15 @@ seed_exception_get_line (JSContextRef ctx, JSValueRef e)
* @exception was thrown.
*
*/
-gchar *
-seed_exception_get_file (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_file(JSContextRef ctx, JSValueRef e)
{
- JSValueRef line;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
- line = seed_object_get_property (ctx, (JSObjectRef) e, "sourceURL");
- return seed_value_to_string (ctx, line, 0);
+ JSValueRef line;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
+ line = seed_object_get_property(ctx, (JSObjectRef) e, "sourceURL");
+ return seed_value_to_string(ctx, line, 0);
}
/**
* seed_exception_get_stack:
@@ -219,18 +216,17 @@ seed_exception_get_file (JSContextRef ctx, JSValueRef e)
* @exception was thrown.
*
*/
-gchar *
-seed_exception_get_stack (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_stack(JSContextRef ctx, JSValueRef e)
{
- JSValueRef stack ;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
- stack = seed_object_get_property (ctx, (JSObjectRef) e, "stack");
- return seed_value_to_string (ctx, stack , 0);
+ JSValueRef stack;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
+ stack = seed_object_get_property(ctx, (JSObjectRef) e, "stack");
+ return seed_value_to_string(ctx, stack, 0);
}
-
/**
* seed_exception_to_string:
* @ctx: A #SeedContext.
@@ -244,23 +240,25 @@ seed_exception_get_stack (JSContextRef ctx, JSValueRef e)
* Return value: A #gchar* representing the @exception.
*
*/
-gchar *
-seed_exception_to_string (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_to_string(JSContextRef ctx, JSValueRef e)
{
- guint line;
- gchar *mes, *name, *file, *ret, *stack;
+ guint line;
+ gchar *mes, *name, *file, *ret, *stack;
- line = seed_exception_get_line (ctx, e);
- mes = seed_exception_get_message (ctx, e);
- file = seed_exception_get_file (ctx, e);
- name = seed_exception_get_name (ctx, e);
- stack = seed_exception_get_stack (ctx, e);
+ line = seed_exception_get_line(ctx, e);
+ mes = seed_exception_get_message(ctx, e);
+ file = seed_exception_get_file(ctx, e);
+ name = seed_exception_get_name(ctx, e);
+ stack = seed_exception_get_stack(ctx, e);
- ret = g_strdup_printf ("Line %d in %s: %s %s\n\nStack:\n%s", line, file, name, mes, stack);
+ ret = g_strdup_printf("Line %d in %s: %s %s\n\nStack:\n%s", line, file,
+ name, mes, stack);
- g_free (mes);
- g_free (file);
- g_free (name);
+ g_free(mes);
+ g_free(file);
+ g_free(name);
+ g_free(stack);
- return ret;
+ return ret;
}
diff --git a/libseed/seed-exceptions.h b/libseed/seed-exceptions.h
index cc1a261..db4b35c 100644
--- a/libseed/seed-exceptions.h
+++ b/libseed/seed-exceptions.h
@@ -22,20 +22,21 @@
#include "seed-private.h"
-void
-seed_make_exception (JSContextRef ctx, JSValueRef * exception,
- const gchar * name, const gchar * message, ...)
-G_GNUC_PRINTF (4, 5);
+void seed_make_exception(JSContextRef ctx,
+ JSValueRef* exception,
+ const gchar* name,
+ const gchar* message,
+ ...) G_GNUC_PRINTF(4, 5);
- void seed_make_exception_from_gerror (JSContextRef ctx,
- JSValueRef * exception,
- GError * e);
+void seed_make_exception_from_gerror(JSContextRef ctx,
+ JSValueRef* exception,
+ GError* e);
- gchar *seed_exception_get_name (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_get_message (JSContextRef ctx, JSValueRef e);
- guint seed_exception_get_line (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_get_file (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_get_stack (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_to_string (JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_name(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_message(JSContextRef ctx, JSValueRef e);
+guint seed_exception_get_line(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_file(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_stack(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_to_string(JSContextRef ctx, JSValueRef e);
#endif
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index 1121326..55f9e62 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -20,12 +20,13 @@
#include "seed-private.h"
#include <sys/mman.h>
-typedef GObject *(*GObjectConstructCallback) (GType, guint,
- GObjectConstructParam *);
+typedef GObject* (*GObjectConstructCallback)(GType,
+ guint,
+ GObjectConstructParam*);
JSClassRef seed_gtype_class;
-GIBaseInfo *objectclass_info = NULL;
-GIBaseInfo *paramspec_info = NULL;
+GIBaseInfo* objectclass_info = NULL;
+GIBaseInfo* paramspec_info = NULL;
JSObjectRef seed_gtype_constructor;
@@ -35,1033 +36,926 @@ GQuark qsetter;
GQuark qiinit;
GQuark qcinit;
-typedef struct _SeedGClassPrivates {
- JSObjectRef constructor;
- JSObjectRef func;
+typedef struct _SeedGClassPrivates
+{
+ JSObjectRef constructor;
+ JSObjectRef func;
- JSObjectRef definition;
+ JSObjectRef definition;
} SeedGClassPrivates;
static JSValueRef
-seed_property_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_property_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *spec;
- GObjectClass *class;
- guint property_count;
- JSValueRef newcount, oldcount;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Property installation expected 1 argument"
- " got %zd \n", argumentCount);
-
- return JSValueMakeNull (ctx);
+ GParamSpec* spec;
+ GObjectClass* class;
+ guint property_count;
+ JSValueRef newcount, oldcount;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Property installation expected 1 argument"
+ " got %zd \n",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[0]) ||
- // Might need to check if JSValueIsObject? Who knows with WebKit.
- !JSValueIsObjectOfClass (ctx, arguments[0], seed_struct_class))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Property installation expected a "
- "GParamSpec as argument");
- return JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[0]) ||
+ // Might need to check if JSValueIsObject? Who knows with WebKit.
+ !JSValueIsObjectOfClass(ctx, arguments[0], seed_struct_class)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Property installation expected a "
+ "GParamSpec as argument");
+ return JSValueMakeNull(ctx);
}
- spec = (GParamSpec *) seed_pointer_get_pointer (ctx, arguments[0]);
+ spec = (GParamSpec*) seed_pointer_get_pointer(ctx, arguments[0]);
- oldcount = seed_object_get_property (ctx, thisObject, "property_count");
- property_count = seed_value_to_int (ctx, oldcount, exception);
+ oldcount = seed_object_get_property(ctx, thisObject, "property_count");
+ property_count = seed_value_to_int(ctx, oldcount, exception);
- class = seed_pointer_get_pointer (ctx, thisObject);
- g_object_class_install_property (class, property_count, spec);
+ class = seed_pointer_get_pointer(ctx, thisObject);
+ g_object_class_install_property(class, property_count, spec);
- newcount = seed_value_from_int (ctx, property_count + 1, exception);
- seed_object_set_property (ctx, thisObject, "property_count", newcount);
+ newcount = seed_value_from_int(ctx, property_count + 1, exception);
+ seed_object_set_property(ctx, thisObject, "property_count", newcount);
- return oldcount;
+ return oldcount;
}
static JSValueRef
-seed_gsignal_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gsignal_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- // TODO: class_closure, and accumlator. Not useful until we have structs.
- JSValueRef jsname, jstype, jsflags, jsreturn_type, jsparams;
- GType itype, return_type;
- guint n_params = 0;
- GType *param_types = 0;
- gchar *name;
- guint signal_id;
- GSignalFlags flags;
-
- /* Sanity check */
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal constructor expected 1 argument"
- " got %zd \n", argumentCount);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ // TODO: class_closure, and accumlator. Not useful until we have structs.
+ JSValueRef jsname, jstype, jsflags, jsreturn_type, jsparams;
+ GType itype, return_type;
+ guint n_params = 0;
+ GType* param_types = 0;
+ gchar* name;
+ guint signal_id;
+ GSignalFlags flags;
+
+ /* Sanity check */
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal constructor expected 1 argument"
+ " got %zd \n",
+ argumentCount);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[0])
- || !JSValueIsObject (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal constructor expected object"
- " as first argument");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[0])
+ || !JSValueIsObject(ctx, arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal constructor expected object"
+ " as first argument");
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- /* Signal name */
- jsname = seed_object_get_property (ctx, (JSObjectRef) arguments[0], "name");
- /* seed_value_to_string can handle non strings, however the kind
- * of strings we want as a signal name are rather small, so make sure
- * we have an actual string */
- if (JSValueIsNull (ctx, jsname) || !JSValueIsString (ctx, jsname))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal definition needs name property");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ /* Signal name */
+ jsname = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
+ /* seed_value_to_string can handle non strings, however the kind
+ * of strings we want as a signal name are rather small, so make sure
+ * we have an actual string */
+ if (JSValueIsNull(ctx, jsname) || !JSValueIsString(ctx, jsname)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal definition needs name property");
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- name = seed_value_to_string (ctx, jsname, exception);
-
- /* Type to install on. Comes from class. */
- jstype = seed_object_get_property (ctx, thisObject, "type");
- itype = seed_value_to_int (ctx, jstype, exception);
-
- SEED_NOTE (GTYPE, "Installing signal with name: %s on type: %s",
- name, g_type_name (itype));
-
- /* Signal flags */
- jsflags = seed_object_get_property (ctx,
- (JSObjectRef) arguments[0], "flags");
- if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
- flags = G_SIGNAL_RUN_LAST;
- else
- flags = seed_value_to_long (ctx, jsflags, exception);
-
- /* Return type */
- jsreturn_type = seed_object_get_property (ctx, (JSObjectRef) arguments[0],
- "return_type");
- if (JSValueIsNull (ctx, jsreturn_type) ||
- !JSValueIsNumber (ctx, jsreturn_type))
- return_type = G_TYPE_NONE;
- else
- return_type = seed_value_to_int (ctx, jsreturn_type, exception);
-
- /* Number of params and types */
- jsparams = seed_object_get_property (ctx, (JSObjectRef) arguments[0],
- "parameters");
- if (!JSValueIsNull (ctx, jsparams) && JSValueIsObject (ctx, jsparams))
- {
- n_params = seed_value_to_int
- (ctx,
- seed_object_get_property (ctx, (JSObjectRef) jsparams, "length"),
- exception);
- if (n_params > 0)
- {
- guint i;
- JSValueRef ptype;
-
- param_types = g_new0 (GType, n_params);
- for (i = 0; i < n_params; i++)
- {
- ptype = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- jsparams, i, exception);
-
- param_types[i] = seed_value_to_int (ctx, ptype, exception);
- }
- }
+ name = seed_value_to_string(ctx, jsname, exception);
+
+ /* Type to install on. Comes from class. */
+ jstype = seed_object_get_property(ctx, thisObject, "type");
+ itype = seed_value_to_int(ctx, jstype, exception);
+
+ SEED_NOTE(GTYPE, "Installing signal with name: %s on type: %s", name,
+ g_type_name(itype));
+
+ /* Signal flags */
+ jsflags
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "flags");
+ if (JSValueIsNull(ctx, jsflags) || !JSValueIsNumber(ctx, jsflags))
+ flags = G_SIGNAL_RUN_LAST;
+ else
+ flags = seed_value_to_long(ctx, jsflags, exception);
+
+ /* Return type */
+ jsreturn_type = seed_object_get_property(ctx, (JSObjectRef) arguments[0],
+ "return_type");
+ if (JSValueIsNull(ctx, jsreturn_type)
+ || !JSValueIsNumber(ctx, jsreturn_type))
+ return_type = G_TYPE_NONE;
+ else
+ return_type = seed_value_to_int(ctx, jsreturn_type, exception);
+
+ /* Number of params and types */
+ jsparams
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "parameters");
+ if (!JSValueIsNull(ctx, jsparams) && JSValueIsObject(ctx, jsparams)) {
+ n_params = seed_value_to_int(
+ ctx, seed_object_get_property(ctx, (JSObjectRef) jsparams, "length"),
+ exception);
+ if (n_params > 0) {
+ guint i;
+ JSValueRef ptype;
+
+ param_types = g_new0(GType, n_params);
+ for (i = 0; i < n_params; i++) {
+ ptype = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) jsparams,
+ i, exception);
+
+ param_types[i] = seed_value_to_int(ctx, ptype, exception);
+ }
+ }
}
- signal_id = g_signal_newv (name, itype,
- flags, 0, 0, 0,
- gi_cclosure_marshal_generic,
- return_type, n_params, param_types);
+ signal_id
+ = g_signal_newv(name, itype, flags, 0, 0, 0, gi_cclosure_marshal_generic,
+ return_type, n_params, param_types);
- g_free (name);
- g_free (param_types);
+ g_free(name);
+ g_free(param_types);
- return (JSValueRef) seed_value_from_uint (ctx, signal_id, exception);
+ return (JSValueRef) seed_value_from_uint(ctx, signal_id, exception);
}
static void
-seed_gtype_builtin_set_property (GObject * object,
- guint property_id,
- const GValue * value, GParamSpec * spec)
+seed_gtype_builtin_set_property(GObject* object,
+ guint property_id,
+ const GValue* value,
+ GParamSpec* spec)
{
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
- gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
- JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ gchar* name = g_strjoin(NULL, "_", spec->name, NULL);
+ JSObjectRef jsobj = (JSObjectRef) seed_value_from_object(ctx, object, 0);
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- seed_object_set_property (ctx,
- jsobj,
- name,
- seed_value_from_gvalue (ctx, (GValue *) value,
- 0));
+ seed_object_set_property(ctx, jsobj, name,
+ seed_value_from_gvalue(ctx, (GValue*) value, 0));
- g_free (name);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ g_free(name);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
static void
-seed_gtype_builtin_get_property (GObject * object,
- guint property_id,
- GValue * value, GParamSpec * spec)
+seed_gtype_builtin_get_property(GObject* object,
+ guint property_id,
+ GValue* value,
+ GParamSpec* spec)
{
- // TODO: Exceptions
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
- gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
- JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
- JSValueRef jsval = seed_object_get_property (ctx, jsobj,
- name);
+ // TODO: Exceptions
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ gchar* name = g_strjoin(NULL, "_", spec->name, NULL);
+ JSObjectRef jsobj = (JSObjectRef) seed_value_from_object(ctx, object, 0);
+ JSValueRef jsval = seed_object_get_property(ctx, jsobj, name);
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- seed_value_to_gvalue (ctx, jsval, spec->value_type, value, 0);
+ seed_value_to_gvalue(ctx, jsval, spec->value_type, value, 0);
- g_free (name);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ g_free(name);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
static void
-seed_gtype_set_property (GObject * object,
- guint property_id,
- const GValue * value, GParamSpec * spec)
+seed_gtype_set_property(GObject* object,
+ guint property_id,
+ const GValue* value,
+ GParamSpec* spec)
{
- gpointer data = g_param_spec_get_qdata (spec, qsetter);
+ gpointer data = g_param_spec_get_qdata(spec, qsetter);
- if (!data)
- {
- seed_gtype_builtin_set_property (object, property_id, value, spec);
- return;
+ if (!data) {
+ seed_gtype_builtin_set_property(object, property_id, value, spec);
+ return;
}
}
static void
-seed_gtype_get_property (GObject * object,
- guint property_id, GValue * value, GParamSpec * spec)
+seed_gtype_get_property(GObject* object,
+ guint property_id,
+ GValue* value,
+ GParamSpec* spec)
{
- gpointer data = g_param_spec_get_qdata (spec, qgetter);
+ gpointer data = g_param_spec_get_qdata(spec, qgetter);
- if (!data)
- {
- seed_gtype_builtin_get_property (object, property_id, value, spec);
- return;
+ if (!data) {
+ seed_gtype_builtin_get_property(object, property_id, value, spec);
+ return;
}
}
-static GIBaseInfo *
-seed_get_class_info_for_type (GType type)
+static GIBaseInfo*
+seed_get_class_info_for_type(GType type)
{
- GIBaseInfo *object_info;
-
- // Note to self: Investigate the entire premise of this function.
- while ((type = g_type_parent (type)))
- {
- GIBaseInfo *ret;
-
- object_info = g_irepository_find_by_gtype (NULL, type);
- if (object_info)
- {
- ret = g_object_info_get_class_struct ((GIObjectInfo *)object_info);
- g_base_info_unref (object_info);
-
- return ret;
- }
+ GIBaseInfo* object_info;
+
+ // Note to self: Investigate the entire premise of this function.
+ while ((type = g_type_parent(type))) {
+ GIBaseInfo* ret;
+
+ object_info = g_irepository_find_by_gtype(NULL, type);
+ if (object_info) {
+ ret = g_object_info_get_class_struct((GIObjectInfo*) object_info);
+ g_base_info_unref(object_info);
+
+ return ret;
+ }
}
-
- return NULL;
+
+ return NULL;
}
static void
-seed_attach_methods_to_class_object (JSContextRef ctx,
- JSObjectRef object,
- JSValueRef * exception)
+seed_attach_methods_to_class_object(JSContextRef ctx,
+ JSObjectRef object,
+ JSValueRef* exception)
{
- seed_create_function (ctx, "c_install_property",
- &seed_property_method_invoked, object);
- seed_create_function (ctx, "install_signal",
- &seed_gsignal_method_invoked, object);
+ seed_create_function(ctx, "c_install_property",
+ &seed_property_method_invoked, object);
+ seed_create_function(ctx, "install_signal", &seed_gsignal_method_invoked,
+ object);
}
static void
-seed_gtype_call_construct (GType type, GObject * object)
+seed_gtype_call_construct(GType type, GObject* object)
{
- JSContextRef ctx;
- JSObjectRef func, this_object;
- JSValueRef exception = NULL, args[1];
- gchar *mes;
-
- func = g_type_get_qdata (type, qiinit);
-
- if (func)
- {
- ctx = JSGlobalContextCreateInGroup (context_group, 0);
- seed_prepare_global_context (ctx);
-
- SEED_NOTE (GTYPE, "Handling constructor for: %p with type: %s",
- object, g_type_name (type));
- this_object = (JSObjectRef) seed_value_from_object (ctx, object, NULL);
- args[0] = this_object;
-
- JSObjectCallAsFunction (ctx, func, this_object, 1, args, &exception);
- if (exception)
- {
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in instance construction. %s \n", mes);
- g_free (mes);
- }
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSContextRef ctx;
+ JSObjectRef func, this_object;
+ JSValueRef exception = NULL, args[1];
+ gchar* mes;
+
+ func = g_type_get_qdata(type, qiinit);
+
+ if (func) {
+ ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ seed_prepare_global_context(ctx);
+
+ SEED_NOTE(GTYPE, "Handling constructor for: %p with type: %s", object,
+ g_type_name(type));
+ this_object = (JSObjectRef) seed_value_from_object(ctx, object, NULL);
+ args[0] = this_object;
+
+ JSObjectCallAsFunction(ctx, func, this_object, 1, args, &exception);
+ if (exception) {
+ mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in instance construction. %s \n", mes);
+ g_free(mes);
+ }
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
-
-
}
-static GObject *
-seed_gtype_construct (GType type,
- guint n_construct_params,
- GObjectConstructParam * construct_params)
+static GObject*
+seed_gtype_construct(GType type,
+ guint n_construct_params,
+ GObjectConstructParam* construct_params)
{
- GObject *object;
- GType parent;
- GObjectClass *parent_class;
+ GObject* object;
+ GType parent;
+ GObjectClass* parent_class;
- parent = g_type_parent (type);
- parent_class = g_type_class_ref (parent);
+ parent = g_type_parent(type);
+ parent_class = g_type_class_ref(parent);
- if (parent_class->constructor == seed_gtype_construct)
- {
- GType t = parent;
- parent = g_type_parent (parent);
+ if (parent_class->constructor == seed_gtype_construct) {
+ GType t = parent;
+ parent = g_type_parent(parent);
- g_type_class_unref (parent_class);
- parent_class = g_type_class_ref (parent);
+ g_type_class_unref(parent_class);
+ parent_class = g_type_class_ref(parent);
- object =
- parent_class->constructor (type, n_construct_params,
- construct_params);
-
- seed_gtype_call_construct (t, object);
+ object = parent_class->constructor(type, n_construct_params,
+ construct_params);
- g_type_class_unref (parent_class);
- }
- else
- object =
- parent_class->constructor (type, n_construct_params, construct_params);
+ seed_gtype_call_construct(t, object);
+
+ g_type_class_unref(parent_class);
+ } else
+ object = parent_class->constructor(type, n_construct_params,
+ construct_params);
- seed_gtype_call_construct (type, object);
+ seed_gtype_call_construct(type, object);
- g_type_class_unref (parent_class);
+ g_type_class_unref(parent_class);
- return object;
+ return object;
}
static void
-seed_gtype_install_signals (JSContextRef ctx,
- JSObjectRef definition, GType type,
- JSValueRef * exception)
+seed_gtype_install_signals(JSContextRef ctx,
+ JSObjectRef definition,
+ GType type,
+ JSValueRef* exception)
{
- JSObjectRef signals, signal_def;
- JSValueRef jslength;
- guint i, j, length;
- GType return_type;
- GType *param_types = NULL;
- guint n_params = 0;
- GSignalFlags flags;
- JSValueRef jsname, jsflags, jsreturn_type, jsparams;
- gchar *name;
-
- signals =
- (JSObjectRef) seed_object_get_property (ctx, definition, "signals");
- if (JSValueIsNull (ctx, signals) || !JSValueIsObject (ctx, signals))
- return;
-
- jslength = seed_object_get_property (ctx, signals, "length");
- if (JSValueIsNull (ctx, jslength))
- return;
-
- length = seed_value_to_uint (ctx, jslength, exception);
- for (i = 0; i < length; i++)
- {
- signal_def = (JSObjectRef) JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- signals, i,
- exception);
-
- if (JSValueIsNull (ctx, signal_def)
- || !JSValueIsObject (ctx, signal_def))
- continue;
-
- // TODO: Error checking
- jsname = seed_object_get_property (ctx, signal_def, "name");
- name = seed_value_to_string (ctx, jsname, exception);
-
- SEED_NOTE (GTYPE, "Installing signal with name: %s on type: %s",
- name, g_type_name (type));
-
- jsflags =
- seed_object_get_property (ctx, (JSObjectRef) signal_def, "flags");
- if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
- flags = G_SIGNAL_RUN_LAST;
- else
- flags = seed_value_to_long (ctx, jsflags, exception);
-
- jsreturn_type =
- seed_object_get_property (ctx, signal_def, "return_type");
- if (JSValueIsNull (ctx, jsreturn_type)
- || !JSValueIsNumber (ctx, jsreturn_type))
- return_type = G_TYPE_NONE;
- else
- return_type = seed_value_to_long (ctx, jsreturn_type, exception);
-
- jsparams = seed_object_get_property (ctx, signal_def, "parameters");
-
- // reset params..
- param_types = NULL;
- n_params = 0;
-
- if (!JSValueIsNull (ctx, jsparams) && JSValueIsObject (ctx, jsparams))
- {
- n_params =
- seed_value_to_int (ctx,
- seed_object_get_property (ctx,
- (JSObjectRef)
- jsparams, "length"),
- exception);
- if (n_params > 0)
- {
- param_types = g_alloca (sizeof (GType) * n_params);
- for (j = 0; j < n_params; j++)
- {
- JSValueRef ptype = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- jsparams,
- j,
- exception);
- param_types[j] =
- (GType) seed_value_to_long (ctx, ptype, exception);
- }
- }
- }
-
- g_signal_newv (name, type,
- flags, 0, 0, 0,
- gi_cclosure_marshal_generic,
- return_type, n_params, param_types);
- g_free (name);
-
+ JSObjectRef signals, signal_def;
+ JSValueRef jslength;
+ guint i, j, length;
+ GType return_type;
+ GType* param_types = NULL;
+ guint n_params = 0;
+ GSignalFlags flags;
+ JSValueRef jsname, jsflags, jsreturn_type, jsparams;
+ gchar* name;
+
+ signals
+ = (JSObjectRef) seed_object_get_property(ctx, definition, "signals");
+ if (JSValueIsNull(ctx, signals) || !JSValueIsObject(ctx, signals))
+ return;
+
+ jslength = seed_object_get_property(ctx, signals, "length");
+ if (JSValueIsNull(ctx, jslength))
+ return;
+
+ length = seed_value_to_uint(ctx, jslength, exception);
+ for (i = 0; i < length; i++) {
+ signal_def
+ = (JSObjectRef) JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) signals,
+ i, exception);
+
+ if (JSValueIsNull(ctx, signal_def) || !JSValueIsObject(ctx, signal_def))
+ continue;
+
+ // TODO: Error checking
+ jsname = seed_object_get_property(ctx, signal_def, "name");
+ name = seed_value_to_string(ctx, jsname, exception);
+
+ SEED_NOTE(GTYPE, "Installing signal with name: %s on type: %s", name,
+ g_type_name(type));
+
+ jsflags
+ = seed_object_get_property(ctx, (JSObjectRef) signal_def, "flags");
+ if (JSValueIsNull(ctx, jsflags) || !JSValueIsNumber(ctx, jsflags))
+ flags = G_SIGNAL_RUN_LAST;
+ else
+ flags = seed_value_to_long(ctx, jsflags, exception);
+
+ jsreturn_type
+ = seed_object_get_property(ctx, signal_def, "return_type");
+ if (JSValueIsNull(ctx, jsreturn_type)
+ || !JSValueIsNumber(ctx, jsreturn_type))
+ return_type = G_TYPE_NONE;
+ else
+ return_type = seed_value_to_long(ctx, jsreturn_type, exception);
+
+ jsparams = seed_object_get_property(ctx, signal_def, "parameters");
+
+ // reset params..
+ param_types = NULL;
+ n_params = 0;
+
+ if (!JSValueIsNull(ctx, jsparams) && JSValueIsObject(ctx, jsparams)) {
+ n_params = seed_value_to_int(
+ ctx,
+ seed_object_get_property(ctx, (JSObjectRef) jsparams, "length"),
+ exception);
+ if (n_params > 0) {
+ param_types = g_alloca(sizeof(GType) * n_params);
+ for (j = 0; j < n_params; j++) {
+ JSValueRef ptype
+ = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) jsparams,
+ j, exception);
+ param_types[j]
+ = (GType) seed_value_to_long(ctx, ptype, exception);
+ }
+ }
+ }
+
+ g_signal_newv(name, type, flags, 0, 0, 0, gi_cclosure_marshal_generic,
+ return_type, n_params, param_types);
+ g_free(name);
}
}
static unsigned int
-seed_gtype_install_properties (JSContextRef ctx,
- JSObjectRef definition,
- GType type, GObjectClass *g_class,
- JSValueRef * exception)
+seed_gtype_install_properties(JSContextRef ctx,
+ JSObjectRef definition,
+ GType type,
+ GObjectClass* g_class,
+ JSValueRef* exception)
{
- JSObjectRef properties, property_def;
- JSValueRef jslength;
- guint i, length;
- GType property_type, object_type;
- GParamFlags flags;
- JSValueRef jsname, jsflags, jsproperty_type, jsdefault_value, jsobject_type;
- JSValueRef jsnick, jsblurb, jsmin_value, jsmax_value;
- gchar *name , *nick, *blurb;
- GParamSpec *pspec;
- guint property_count = 0;
-
- properties = (JSObjectRef) seed_object_get_property (ctx, definition,
- "properties");
- if (JSValueIsNull (ctx, properties) || !JSValueIsObject (ctx, properties))
- return 0;
-
- jslength = seed_object_get_property (ctx, properties, "length");
- if (JSValueIsNull (ctx, jslength))
- return 0;
-
- length = seed_value_to_uint (ctx, jslength, exception);
- for (i = 0; i < length; i++)
- {
- property_def = (JSObjectRef) JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- properties, i,
- NULL);
-
- if (JSValueIsNull (ctx, property_def)
- || !JSValueIsObject (ctx, property_def))
- continue;
-
- jsname = seed_object_get_property (ctx, property_def, "name");
- if (!JSValueIsString(ctx, jsname))
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property requires name attribute");
- return property_count;
- }
- name = seed_value_to_string (ctx, jsname, exception);
-
- // Check for "nick" property; set to name if nonexistent
- jsnick = seed_object_get_property (ctx, property_def, "nick");
- if (!JSValueIsString(ctx, jsnick))
- nick = name;
- else
- nick = seed_value_to_string (ctx, jsnick, exception);
-
- // Check for "blurb" property; set to name if nonexistent
- jsblurb = seed_object_get_property (ctx, property_def, "blurb");
- if (!JSValueIsString(ctx, jsblurb))
- blurb = name;
- else
- blurb = seed_value_to_string (ctx, jsblurb, exception);
-
- SEED_NOTE (GTYPE, "Installing property with name: %s on type: %s",
- name, g_type_name (type));
-
- // Flags default to read/write, non-construct
- jsflags =
- seed_object_get_property (ctx, (JSObjectRef) property_def, "flags");
- if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
- flags = G_PARAM_READABLE | G_PARAM_WRITABLE;
- else
- flags = seed_value_to_long (ctx, jsflags, exception);
-
- jsproperty_type = seed_object_get_property (ctx, property_def, "type");
-
- if (JSValueIsNull (ctx, jsproperty_type) ||
- !JSValueIsNumber (ctx, jsproperty_type))
- property_type = G_TYPE_NONE;
- else
- property_type = seed_value_to_long (ctx, jsproperty_type, exception);
-
- jsdefault_value = seed_object_get_property (ctx, property_def,
- "default_value");
-
- if (JSValueIsNull (ctx, jsdefault_value) ||
- JSValueIsUndefined (ctx, jsdefault_value))
- {
- if(property_type == G_TYPE_OBJECT)
- continue;
-
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires default_value attribute",
- g_type_name(property_type));
- return property_count;
- }
-
- jsmin_value = seed_object_get_property (ctx, property_def,
- "minimum_value");
- jsmax_value = seed_object_get_property (ctx, property_def,
- "maximum_value");
-
- // Make sure min/max properties are defined, based on type
- if(property_type == G_TYPE_CHAR ||
- property_type == G_TYPE_UCHAR ||
- property_type == G_TYPE_INT ||
- property_type == G_TYPE_UINT ||
- property_type == G_TYPE_INT64 ||
- property_type == G_TYPE_UINT64 ||
- property_type == G_TYPE_FLOAT ||
- property_type == G_TYPE_DOUBLE)
- {
- if (JSValueIsNull (ctx, jsmin_value) ||
- !JSValueIsNumber (ctx, jsmin_value))
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires minimum_value attribute",
- g_type_name(property_type));
- return property_count;
- }
- if (JSValueIsNull (ctx, jsmax_value) ||
- !JSValueIsNumber (ctx, jsmax_value))
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires maximum_value attribute",
- g_type_name(property_type));
- return property_count;
- }
- }
-
-
- switch(property_type)
- {
- case G_TYPE_BOOLEAN:
- pspec = g_param_spec_boolean(name, nick, blurb,
- seed_value_to_boolean(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_CHAR:
- pspec = g_param_spec_char(name, nick, blurb,
- seed_value_to_char(ctx,
- jsmin_value,
- exception),
- seed_value_to_char(ctx,
- jsmax_value,
- exception),
- seed_value_to_char(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_UCHAR:
- pspec = g_param_spec_uchar(name, nick, blurb,
- seed_value_to_uchar(ctx,
- jsmin_value,
- exception),
- seed_value_to_uchar(ctx,
- jsmax_value,
- exception),
- seed_value_to_uchar(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_INT:
- pspec = g_param_spec_int(name, nick, blurb,
- seed_value_to_int(ctx,
- jsmin_value,
- exception),
- seed_value_to_int(ctx,
- jsmax_value,
- exception),
- seed_value_to_int(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_UINT:
- pspec = g_param_spec_uint(name, nick, blurb,
- seed_value_to_uint(ctx,
- jsmin_value,
- exception),
- seed_value_to_uint(ctx,
- jsmax_value,
- exception),
- seed_value_to_uint(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_LONG:
- pspec = g_param_spec_long(name, nick, blurb,
- seed_value_to_long(ctx,
- jsmin_value,
- exception),
- seed_value_to_long(ctx,
- jsmax_value,
- exception),
- seed_value_to_long(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_ULONG:
- pspec = g_param_spec_ulong(name, nick, blurb,
- seed_value_to_ulong(ctx,
- jsmin_value,
- exception),
- seed_value_to_ulong(ctx,
- jsmax_value,
- exception),
- seed_value_to_ulong(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_INT64:
- pspec = g_param_spec_int64(name, nick, blurb,
- seed_value_to_int64(ctx,
- jsmin_value,
- exception),
- seed_value_to_int64(ctx,
- jsmax_value,
- exception),
- seed_value_to_int64(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_UINT64:
- pspec = g_param_spec_uint64(name, nick, blurb,
- seed_value_to_uint64(ctx,
- jsmin_value,
- exception),
- seed_value_to_uint64(ctx,
- jsmax_value,
- exception),
- seed_value_to_uint64(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_FLOAT:
- pspec = g_param_spec_float(name, nick, blurb,
- seed_value_to_float(ctx,
- jsmin_value,
- exception),
- seed_value_to_float(ctx,
- jsmax_value,
- exception),
- seed_value_to_float(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_DOUBLE:
- pspec = g_param_spec_double(name, nick, blurb,
- seed_value_to_double(ctx,
- jsmin_value,
- exception),
- seed_value_to_double(ctx,
- jsmax_value,
- exception),
- seed_value_to_double(ctx,
- jsdefault_value,
- exception), flags);
- break;
- // TODO: support enums/flags/params
- case G_TYPE_STRING:
- // TODO: leaky?
- pspec = g_param_spec_string(name, nick, blurb,
- seed_value_to_string(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_OBJECT:
- jsobject_type = seed_object_get_property (ctx, property_def,
- "object_type");
-
- if (JSValueIsNull (ctx, jsobject_type) ||
- !JSValueIsNumber (ctx, jsobject_type))
- object_type = G_TYPE_NONE;
- else
- object_type = seed_value_to_long (ctx, jsobject_type, exception);
-
- if(object_type == G_TYPE_NONE)
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires object_type attribute",
- g_type_name(property_type));
- return property_count;
- }
-
- pspec = g_param_spec_object(name, nick, blurb,
- object_type, flags);
- break;
- case G_TYPE_BOXED: // Boxed types TODO: this is almost certainly wrong
- pspec = g_param_spec_boxed(name, nick, blurb, type, flags);
- break;
- default:
- case G_TYPE_NONE:
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property requires type attribute");
- return property_count;
- break;
- }
-
- g_object_class_install_property (g_class, ++property_count, pspec);
-
- if (nick != name)
- g_free (nick);
-
- if (blurb != name)
- g_free (blurb);
-
- g_free (name);
+ JSObjectRef properties, property_def;
+ JSValueRef jslength;
+ guint i, length;
+ GType property_type, object_type;
+ GParamFlags flags;
+ JSValueRef jsname, jsflags, jsproperty_type, jsdefault_value, jsobject_type;
+ JSValueRef jsnick, jsblurb, jsmin_value, jsmax_value;
+ gchar *name, *nick, *blurb;
+ GParamSpec* pspec;
+ guint property_count = 0;
+
+ properties
+ = (JSObjectRef) seed_object_get_property(ctx, definition, "properties");
+ if (JSValueIsNull(ctx, properties) || !JSValueIsObject(ctx, properties))
+ return 0;
+
+ jslength = seed_object_get_property(ctx, properties, "length");
+ if (JSValueIsNull(ctx, jslength))
+ return 0;
+
+ length = seed_value_to_uint(ctx, jslength, exception);
+ for (i = 0; i < length; i++) {
+ property_def
+ = (JSObjectRef) JSObjectGetPropertyAtIndex(ctx,
+ (JSObjectRef) properties,
+ i, NULL);
+
+ if (JSValueIsNull(ctx, property_def)
+ || !JSValueIsObject(ctx, property_def))
+ continue;
+
+ jsname = seed_object_get_property(ctx, property_def, "name");
+ if (!JSValueIsString(ctx, jsname)) {
+ seed_make_exception(ctx, exception, "PropertyInstallationError",
+ "Property requires name attribute");
+ return property_count;
+ }
+ name = seed_value_to_string(ctx, jsname, exception);
+
+ // Check for "nick" property; set to name if nonexistent
+ jsnick = seed_object_get_property(ctx, property_def, "nick");
+ if (!JSValueIsString(ctx, jsnick))
+ nick = name;
+ else
+ nick = seed_value_to_string(ctx, jsnick, exception);
+
+ // Check for "blurb" property; set to name if nonexistent
+ jsblurb = seed_object_get_property(ctx, property_def, "blurb");
+ if (!JSValueIsString(ctx, jsblurb))
+ blurb = name;
+ else
+ blurb = seed_value_to_string(ctx, jsblurb, exception);
+
+ SEED_NOTE(GTYPE, "Installing property with name: %s on type: %s", name,
+ g_type_name(type));
+
+ // Flags default to read/write, non-construct
+ jsflags
+ = seed_object_get_property(ctx, (JSObjectRef) property_def, "flags");
+ if (JSValueIsNull(ctx, jsflags) || !JSValueIsNumber(ctx, jsflags))
+ flags = G_PARAM_READABLE | G_PARAM_WRITABLE;
+ else
+ flags = seed_value_to_long(ctx, jsflags, exception);
+
+ jsproperty_type = seed_object_get_property(ctx, property_def, "type");
+
+ if (JSValueIsNull(ctx, jsproperty_type)
+ || !JSValueIsNumber(ctx, jsproperty_type))
+ property_type = G_TYPE_NONE;
+ else
+ property_type = seed_value_to_long(ctx, jsproperty_type, exception);
+
+ jsdefault_value
+ = seed_object_get_property(ctx, property_def, "default_value");
+
+ if (JSValueIsNull(ctx, jsdefault_value)
+ || JSValueIsUndefined(ctx, jsdefault_value)) {
+ if (property_type == G_TYPE_OBJECT)
+ continue;
+
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires default_value attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+
+ jsmin_value
+ = seed_object_get_property(ctx, property_def, "minimum_value");
+ jsmax_value
+ = seed_object_get_property(ctx, property_def, "maximum_value");
+
+ // Make sure min/max properties are defined, based on type
+ if (property_type == G_TYPE_CHAR || property_type == G_TYPE_UCHAR
+ || property_type == G_TYPE_INT || property_type == G_TYPE_UINT
+ || property_type == G_TYPE_INT64 || property_type == G_TYPE_UINT64
+ || property_type == G_TYPE_FLOAT
+ || property_type == G_TYPE_DOUBLE) {
+ if (JSValueIsNull(ctx, jsmin_value)
+ || !JSValueIsNumber(ctx, jsmin_value)) {
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires minimum_value attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+ if (JSValueIsNull(ctx, jsmax_value)
+ || !JSValueIsNumber(ctx, jsmax_value)) {
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires maximum_value attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+ }
+
+ switch (property_type) {
+ case G_TYPE_BOOLEAN:
+ pspec = g_param_spec_boolean(
+ name, nick, blurb,
+ seed_value_to_boolean(ctx, jsdefault_value, exception),
+ flags);
+ break;
+ case G_TYPE_CHAR:
+ pspec = g_param_spec_char(
+ name, nick, blurb,
+ seed_value_to_char(ctx, jsmin_value, exception),
+ seed_value_to_char(ctx, jsmax_value, exception),
+ seed_value_to_char(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_UCHAR:
+ pspec = g_param_spec_uchar(
+ name, nick, blurb,
+ seed_value_to_uchar(ctx, jsmin_value, exception),
+ seed_value_to_uchar(ctx, jsmax_value, exception),
+ seed_value_to_uchar(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_INT:
+ pspec = g_param_spec_int(
+ name, nick, blurb,
+ seed_value_to_int(ctx, jsmin_value, exception),
+ seed_value_to_int(ctx, jsmax_value, exception),
+ seed_value_to_int(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_UINT:
+ pspec = g_param_spec_uint(
+ name, nick, blurb,
+ seed_value_to_uint(ctx, jsmin_value, exception),
+ seed_value_to_uint(ctx, jsmax_value, exception),
+ seed_value_to_uint(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_LONG:
+ pspec = g_param_spec_long(
+ name, nick, blurb,
+ seed_value_to_long(ctx, jsmin_value, exception),
+ seed_value_to_long(ctx, jsmax_value, exception),
+ seed_value_to_long(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_ULONG:
+ pspec = g_param_spec_ulong(
+ name, nick, blurb,
+ seed_value_to_ulong(ctx, jsmin_value, exception),
+ seed_value_to_ulong(ctx, jsmax_value, exception),
+ seed_value_to_ulong(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_INT64:
+ pspec = g_param_spec_int64(
+ name, nick, blurb,
+ seed_value_to_int64(ctx, jsmin_value, exception),
+ seed_value_to_int64(ctx, jsmax_value, exception),
+ seed_value_to_int64(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_UINT64:
+ pspec = g_param_spec_uint64(
+ name, nick, blurb,
+ seed_value_to_uint64(ctx, jsmin_value, exception),
+ seed_value_to_uint64(ctx, jsmax_value, exception),
+ seed_value_to_uint64(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_FLOAT:
+ pspec = g_param_spec_float(
+ name, nick, blurb,
+ seed_value_to_float(ctx, jsmin_value, exception),
+ seed_value_to_float(ctx, jsmax_value, exception),
+ seed_value_to_float(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_DOUBLE:
+ pspec = g_param_spec_double(
+ name, nick, blurb,
+ seed_value_to_double(ctx, jsmin_value, exception),
+ seed_value_to_double(ctx, jsmax_value, exception),
+ seed_value_to_double(ctx, jsdefault_value, exception), flags);
+ break;
+ // TODO: support enums/flags/params
+ case G_TYPE_STRING:
+ // TODO: leaky?
+ pspec = g_param_spec_string(
+ name, nick, blurb,
+ seed_value_to_string(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_OBJECT:
+ jsobject_type
+ = seed_object_get_property(ctx, property_def, "object_type");
+
+ if (JSValueIsNull(ctx, jsobject_type)
+ || !JSValueIsNumber(ctx, jsobject_type))
+ object_type = G_TYPE_NONE;
+ else
+ object_type
+ = seed_value_to_long(ctx, jsobject_type, exception);
+
+ if (object_type == G_TYPE_NONE) {
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires object_type attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+
+ pspec
+ = g_param_spec_object(name, nick, blurb, object_type, flags);
+ break;
+ case G_TYPE_BOXED: // Boxed types TODO: this is almost certainly
+ // wrong
+ pspec = g_param_spec_boxed(name, nick, blurb, type, flags);
+ break;
+ default:
+ case G_TYPE_NONE:
+ seed_make_exception(ctx, exception, "PropertyInstallationError",
+ "Property requires type attribute");
+ return property_count;
+ break;
+ }
+
+ g_object_class_install_property(g_class, ++property_count, pspec);
+
+ if (nick != name)
+ g_free(nick);
+
+ if (blurb != name)
+ g_free(blurb);
+
+ g_free(name);
}
- return property_count;
+ return property_count;
}
static void
-seed_gtype_class_init (gpointer g_class, gpointer class_data)
+seed_gtype_class_init(gpointer g_class, gpointer class_data)
{
- SeedGClassPrivates *priv;
- GIBaseInfo *class_info;
- JSContextRef ctx;
- JSValueRef jsargs[2];
- GType type;
- JSValueRef exception = NULL;
- int initial_prop_count = 1;
- GQuark class_init_exception_q =
- g_quark_from_static_string("type-class-init-exception");
-
- priv = (SeedGClassPrivates *) class_data;
-
- ((GObjectClass *)g_class)->get_property = seed_gtype_get_property;
- ((GObjectClass *)g_class)->set_property = seed_gtype_set_property;
- ((GObjectClass *)g_class)->constructor = seed_gtype_construct;
-
- ctx = JSGlobalContextCreateInGroup (context_group, 0);
-
- type = (GType) JSObjectGetPrivate (priv->constructor);
- seed_gtype_install_signals (ctx, priv->definition, type, &exception);
- initial_prop_count = seed_gtype_install_properties (ctx,
- priv->definition,
- type,
- (GObjectClass *) g_class,
- &exception);
-
- if (!priv->func)
- {
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
- if (exception)
- {
- g_type_set_qdata(type, class_init_exception_q, (gpointer)exception);
- }
- return;
+ SeedGClassPrivates* priv;
+ GIBaseInfo* class_info;
+ JSContextRef ctx;
+ JSValueRef jsargs[2];
+ GType type;
+ JSValueRef exception = NULL;
+ int initial_prop_count = 1;
+ GQuark class_init_exception_q
+ = g_quark_from_static_string("type-class-init-exception");
+
+ priv = (SeedGClassPrivates*) class_data;
+
+ ((GObjectClass*) g_class)->get_property = seed_gtype_get_property;
+ ((GObjectClass*) g_class)->set_property = seed_gtype_set_property;
+ ((GObjectClass*) g_class)->constructor = seed_gtype_construct;
+
+ ctx = JSGlobalContextCreateInGroup(context_group, 0);
+
+ type = (GType) JSObjectGetPrivate(priv->constructor);
+ seed_gtype_install_signals(ctx, priv->definition, type, &exception);
+ initial_prop_count
+ = seed_gtype_install_properties(ctx, priv->definition, type,
+ (GObjectClass*) g_class, &exception);
+
+ if (!priv->func) {
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
+ if (exception) {
+ g_type_set_qdata(type, class_init_exception_q,
+ (gpointer) exception);
+ }
+ return;
}
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- class_info = seed_get_class_info_for_type (type);
+ class_info = seed_get_class_info_for_type(type);
- jsargs[0] = seed_make_struct (ctx, g_class, class_info);
- jsargs[1] = seed_gobject_get_prototype_for_gtype (type);
+ jsargs[0] = seed_make_struct(ctx, g_class, class_info);
+ jsargs[1] = seed_gobject_get_prototype_for_gtype(type);
- seed_attach_methods_to_class_object (ctx, (JSObjectRef) jsargs[0],
- &exception);
+ seed_attach_methods_to_class_object(ctx, (JSObjectRef) jsargs[0],
+ &exception);
- g_base_info_unref ((GIBaseInfo *) class_info);
+ g_base_info_unref((GIBaseInfo*) class_info);
- SEED_NOTE (GTYPE, "Marshalling class init for type: %s",
- g_type_name (type));
+ SEED_NOTE(GTYPE, "Marshalling class init for type: %s", g_type_name(type));
- seed_object_set_property (ctx, (JSObjectRef) jsargs[0],
- "type", seed_value_from_int (ctx, type, 0));
- seed_object_set_property (ctx, (JSObjectRef) jsargs[0],
- "property_count",
- seed_value_from_int (ctx, initial_prop_count + 1,
- 0));
+ seed_object_set_property(ctx, (JSObjectRef) jsargs[0], "type",
+ seed_value_from_int(ctx, type, 0));
+ seed_object_set_property(ctx, (JSObjectRef) jsargs[0], "property_count",
+ seed_value_from_int(ctx, initial_prop_count + 1,
+ 0));
- JSObjectCallAsFunction (ctx, priv->func, 0, 2, jsargs, &exception);
- if (exception)
- {
- g_type_set_qdata(type, class_init_exception_q, (gpointer)exception);
+ JSObjectCallAsFunction(ctx, priv->func, 0, 2, jsargs, &exception);
+ if (exception) {
+ g_type_set_qdata(type, class_init_exception_q, (gpointer) exception);
}
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
static JSObjectRef
-seed_gtype_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gtype_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSValueRef class_init, instance_init, name, parent_ref;
- GType parent_type, new_type;
- gchar *new_name;
- GTypeInfo type_info = {
- 0,
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) NULL,
- (GClassFinalizeFunc) NULL,
- NULL,
- 0,
- 0,
- NULL
- };
- GTypeQuery query;
- JSObjectRef constructor_ref;
- SeedGClassPrivates *priv;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "GType constructor expected 1 "
- "argument, got %zd \n", argumentCount);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ JSValueRef class_init, instance_init, name, parent_ref;
+ GType parent_type, new_type;
+ gchar* new_name;
+ GTypeInfo type_info = { 0,
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) NULL,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ 0,
+ 0,
+ NULL };
+ GTypeQuery query;
+ JSObjectRef constructor_ref;
+ SeedGClassPrivates* priv;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "GType constructor expected 1 "
+ "argument, got %zd \n",
+ argumentCount);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (!JSValueIsObject (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "GType constructor expected a"
- "class definition object. Got a nonobject");
+ if (!JSValueIsObject(ctx, arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "GType constructor expected a"
+ "class definition object. Got a nonobject");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- parent_ref = seed_object_get_property (ctx,
- (JSObjectRef) arguments[0],
- "parent");
- class_init =
- seed_object_get_property (ctx, (JSObjectRef) arguments[0], "class_init");
- instance_init =
- seed_object_get_property (ctx, (JSObjectRef) arguments[0], "init");
- name = seed_object_get_property (ctx, (JSObjectRef) arguments[0], "name");
-
- new_name = seed_value_to_string (ctx, name, exception);
- if (!JSValueIsNumber (ctx, parent_ref))
- {
- seed_make_exception (ctx, exception, "TypeError",
- "GType constructor expected GType for parent");
-
- return (JSObjectRef) JSValueMakeNull (ctx);
+ parent_ref
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "parent");
+ class_init
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "class_init");
+ instance_init
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "init");
+ name = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
+
+ new_name = seed_value_to_string(ctx, name, exception);
+ if (!JSValueIsNumber(ctx, parent_ref)) {
+ seed_make_exception(ctx, exception, "TypeError",
+ "GType constructor expected GType for parent");
+
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
+ // TODO: GType is of variable length, so this is an incorrect fix
+ parent_type = (GType) seed_value_to_long(ctx, parent_ref, exception);
- // TODO: GType is of variable length, so this is an incorrect fix
- parent_type = (GType) seed_value_to_long (ctx, parent_ref, exception);
-
- SEED_NOTE (GTYPE, "Registering new GType with name: %s as child of %s.",
- new_name, g_type_name (parent_type));
+ SEED_NOTE(GTYPE, "Registering new GType with name: %s as child of %s.",
+ new_name, g_type_name(parent_type));
- g_type_query (parent_type, &query);
- type_info.class_size = query.class_size;
- type_info.instance_size = query.instance_size;
- type_info.class_init = seed_gtype_class_init;
+ g_type_query(parent_type, &query);
+ type_info.class_size = query.class_size;
+ type_info.instance_size = query.instance_size;
+ type_info.class_init = seed_gtype_class_init;
- priv = g_slice_alloc (sizeof (SeedGClassPrivates));
+ priv = g_slice_alloc(sizeof(SeedGClassPrivates));
- if (!JSValueIsNull (ctx, class_init) &&
- JSValueIsObject (ctx, class_init) &&
- JSObjectIsFunction (ctx, (JSObjectRef) class_init))
- {
- priv->func = (gpointer) class_init;
- JSValueProtect (ctx, class_init);
+ if (!JSValueIsNull(ctx, class_init) && JSValueIsObject(ctx, class_init)
+ && JSObjectIsFunction(ctx, (JSObjectRef) class_init)) {
+ priv->func = (gpointer) class_init;
+ JSValueProtect(ctx, class_init);
}
+ constructor_ref
+ = JSObjectMake(ctx, gobject_constructor_class, (gpointer) 0);
+ JSValueProtect(ctx, constructor_ref);
- constructor_ref = JSObjectMake (ctx, gobject_constructor_class,
- (gpointer) 0);
- JSValueProtect (ctx, constructor_ref);
+ priv->constructor = constructor_ref;
- priv->constructor = constructor_ref;
+ JSValueProtect(ctx, arguments[0]);
+ priv->definition = (JSObjectRef) arguments[0];
- JSValueProtect (ctx, arguments[0]);
- priv->definition = (JSObjectRef) arguments[0];
+ type_info.class_data = priv;
- type_info.class_data = priv;
+ new_type = g_type_register_static(parent_type, new_name, &type_info, 0);
+ seed_gobject_get_class_for_gtype(ctx, new_type);
+ JSObjectSetPrivate(constructor_ref, (gpointer) new_type);
- new_type = g_type_register_static (parent_type, new_name, &type_info, 0);
- seed_gobject_get_class_for_gtype (ctx, new_type);
- JSObjectSetPrivate (constructor_ref, (gpointer) new_type);
+ seed_object_set_property(ctx, constructor_ref, "type",
+ seed_value_from_int(ctx, new_type, exception));
- seed_object_set_property (ctx, constructor_ref,
- "type", seed_value_from_int (ctx, new_type,
- exception));
-
- if (!JSValueIsNull (ctx, instance_init) &&
- JSValueIsObject (ctx, instance_init) &&
- JSObjectIsFunction (ctx, (JSObjectRef) instance_init))
- {
- g_type_set_qdata (new_type, qiinit, (gpointer) instance_init);
- JSValueProtect (ctx, instance_init);
+ if (!JSValueIsNull(ctx, instance_init)
+ && JSValueIsObject(ctx, instance_init)
+ && JSObjectIsFunction(ctx, (JSObjectRef) instance_init)) {
+ g_type_set_qdata(new_type, qiinit, (gpointer) instance_init);
+ JSValueProtect(ctx, instance_init);
}
- g_free (new_name);
- return constructor_ref;
+ g_free(new_name);
+ return constructor_ref;
}
static JSValueRef
-seed_param_getter_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_param_getter_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *pspec = seed_pointer_get_pointer (ctx, thisObject);
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.get expected "
- "1 argument, got %zd", argumentCount);
-
- return JSValueMakeNull (ctx);
- }
- else if (JSValueIsNull (ctx, arguments[0]) ||
- !JSValueIsObject (ctx, arguments[0]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
- {
- // Maybe should accept C functions
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.get expected a function");
- return JSValueMakeNull (ctx);
+ GParamSpec* pspec = seed_pointer_get_pointer(ctx, thisObject);
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.get expected "
+ "1 argument, got %zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
+ } else if (JSValueIsNull(ctx, arguments[0])
+ || !JSValueIsObject(ctx, arguments[0])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[0])) {
+ // Maybe should accept C functions
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.get expected a function");
+ return JSValueMakeNull(ctx);
}
- g_param_spec_set_qdata (pspec, qgetter, (gpointer) arguments[0]);
+ g_param_spec_set_qdata(pspec, qgetter, (gpointer) arguments[0]);
- return seed_value_from_boolean (ctx, TRUE, exception);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
static JSValueRef
-seed_param_setter_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_param_setter_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *pspec = seed_pointer_get_pointer (ctx, thisObject);
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.set expected "
- "1 argument, got %zd", argumentCount);
-
- return JSValueMakeNull (ctx);
- }
- else if (JSValueIsNull (ctx, arguments[0]) ||
- !JSValueIsObject (ctx, arguments[0]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
- {
- // Maybe should accept C functions
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.set expected a function");
- return JSValueMakeNull (ctx);
+ GParamSpec* pspec = seed_pointer_get_pointer(ctx, thisObject);
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.set expected "
+ "1 argument, got %zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
+ } else if (JSValueIsNull(ctx, arguments[0])
+ || !JSValueIsObject(ctx, arguments[0])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[0])) {
+ // Maybe should accept C functions
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.set expected a function");
+ return JSValueMakeNull(ctx);
}
- g_param_spec_set_qdata (pspec, qsetter, (gpointer) arguments[0]);
+ g_param_spec_set_qdata(pspec, qsetter, (gpointer) arguments[0]);
- return seed_value_from_boolean (ctx, TRUE, exception);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
void
-seed_define_gtype_functions (JSContextRef ctx)
+seed_define_gtype_functions(JSContextRef ctx)
{
- JSObjectRef proto;
-
- objectclass_info = g_irepository_find_by_name (NULL,
- "GObject", "ObjectClass");
-
- proto = seed_struct_prototype (ctx, objectclass_info);
-/*
- // paramspec is remove in newer versions of introspeciton - removing
- // until we can work out how to replace this.
- paramspec_info = g_irepository_find_by_name (NULL, "GObject", "ParamSpec");
- proto = seed_struct_prototype (ctx, paramspec_info);
-*/
- seed_create_function (ctx, "get", &seed_param_getter_invoked, proto);
- seed_create_function (ctx, "set", &seed_param_setter_invoked, proto);
+ JSObjectRef proto;
+
+ objectclass_info
+ = g_irepository_find_by_name(NULL, "GObject", "ObjectClass");
+
+ proto = seed_struct_prototype(ctx, objectclass_info);
+ /*
+ // paramspec is remove in newer versions of introspeciton - removing
+ // until we can work out how to replace this.
+ paramspec_info = g_irepository_find_by_name (NULL, "GObject",
+ "ParamSpec");
+ proto = seed_struct_prototype (ctx, paramspec_info);
+ */
+ seed_create_function(ctx, "get", &seed_param_getter_invoked, proto);
+ seed_create_function(ctx, "set", &seed_param_setter_invoked, proto);
}
void
-seed_gtype_init (SeedEngine * local_eng)
+seed_gtype_init(SeedEngine* local_eng)
{
- JSClassDefinition gtype_def = kJSClassDefinitionEmpty;
+ JSClassDefinition gtype_def = kJSClassDefinitionEmpty;
- gtype_def.callAsConstructor = seed_gtype_constructor_invoked;
- seed_gtype_class = JSClassCreate (&gtype_def);
- JSClassRetain (seed_gtype_class);
+ gtype_def.callAsConstructor = seed_gtype_constructor_invoked;
+ seed_gtype_class = JSClassCreate(&gtype_def);
+ JSClassRetain(seed_gtype_class);
- seed_gtype_constructor =
- JSObjectMake (local_eng->context, seed_gtype_class, 0);
+ seed_gtype_constructor
+ = JSObjectMake(local_eng->context, seed_gtype_class, 0);
- seed_object_set_property (local_eng->context,
- local_eng->global, "GType",
- seed_gtype_constructor);
+ seed_object_set_property(local_eng->context, local_eng->global, "GType",
+ seed_gtype_constructor);
- qiinit = g_quark_from_static_string("js-instance-init");
+ qiinit = g_quark_from_static_string("js-instance-init");
- seed_define_gtype_functions (local_eng->context);
+ seed_define_gtype_functions(local_eng->context);
}
diff --git a/libseed/seed-gtype.h b/libseed/seed-gtype.h
index b16fc58..466eaa0 100644
--- a/libseed/seed-gtype.h
+++ b/libseed/seed-gtype.h
@@ -22,7 +22,7 @@
#include "seed-private.h"
-void seed_gtype_init (SeedEngine * eng);
+void seed_gtype_init(SeedEngine* eng);
extern JSObjectRef seed_gtype_constructor;
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index de331ff..b40d614 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#include <gio/gio.h>
#include "seed-private.h"
@@ -35,8 +36,8 @@ JSObjectRef importer_search_path;
JSClassRef importer_dir_class;
-GHashTable *gi_imports;
-GHashTable *file_imports;
+GHashTable* gi_imports;
+GHashTable* file_imports;
/*
* Some high level documentation of the importer object.
@@ -72,41 +73,77 @@ GHashTable *file_imports;
* for that context.
*/
+gboolean
+seed_file_test(const gchar* path, GFileTest test)
+{
+ // XXX: This is a nasty hack. what we should do is probably
+ // to check for GResource children in a given path and
+ // then return TRUE if any children exists for that path
+ gboolean exists = FALSE;
+ gboolean isdir = FALSE;
+
+ if (g_str_has_prefix(path, "/org/seed")) {
+ if (g_strcmp0(path, "/org/seed") == 0
+ || g_strcmp0(path, "/org/seed/extensions") == 0
+ || g_strcmp0(path, "/org/seed/extensions/gjs") == 0) {
+ isdir = TRUE;
+ exists = TRUE;
+ } else if (g_resources_get_info(path, G_RESOURCE_LOOKUP_FLAGS_NONE,
+ NULL, NULL, NULL)) {
+ isdir = FALSE;
+ exists = TRUE;
+ }
+
+ // Return only if file is in GResource.
+ // Otherwise fallback to g_file_test
+ if (exists) {
+ if (test & G_FILE_TEST_EXISTS)
+ return TRUE;
+ if (test & G_FILE_TEST_IS_REGULAR)
+ if (!isdir)
+ return !isdir;
+ if (test & G_FILE_TEST_IS_DIR)
+ if (isdir)
+ return isdir;
+ }
+ }
+
+ return g_file_test(path, test);
+}
+
/*
* Handle definition of toplevel functions in a namespace.
-* i.e. Gtk.main
+* i.e. Gtk.main.
*/
static gboolean
-seed_gi_importer_is_init (GIFunctionInfo * info)
+seed_gi_importer_is_init(GIFunctionInfo* info)
{
- if (g_strcmp0 (g_base_info_get_name ((GIBaseInfo *) info), "init"))
- {
- return FALSE;
+ if (g_strcmp0(g_base_info_get_name((GIBaseInfo*) info), "init")) {
+ return FALSE;
}
- if (g_callable_info_get_n_args ((GICallableInfo *) info) != 2)
- return FALSE;
+ if (g_callable_info_get_n_args((GICallableInfo*) info) != 2)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
-seed_gi_importer_handle_function (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIFunctionInfo * info,
- JSValueRef * exception)
+seed_gi_importer_handle_function(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIFunctionInfo* info,
+ JSValueRef* exception)
{
- if (!seed_gi_importer_is_init (info))
- seed_gobject_define_property_from_function_info (ctx,
- (GIFunctionInfo *) info,
- namespace_ref, FALSE);
- else
- {
- JSObjectRef init_method;
-
- init_method = JSObjectMake (ctx, gobject_init_method_class,
- g_base_info_ref ((GIBaseInfo *) info));
- seed_object_set_property (ctx, namespace_ref, "init", init_method);
+ if (!seed_gi_importer_is_init(info))
+ seed_gobject_define_property_from_function_info(ctx,
+ (GIFunctionInfo*) info,
+ namespace_ref, FALSE);
+ else {
+ JSObjectRef init_method;
+
+ init_method = JSObjectMake(ctx, gobject_init_method_class,
+ g_base_info_ref((GIBaseInfo*) info));
+ seed_object_set_property(ctx, namespace_ref, "init", init_method);
}
}
@@ -117,46 +154,44 @@ seed_gi_importer_handle_function (JSContextRef ctx,
* i.e. Gtk.WindowType.NORMAL
*/
static void
-seed_gi_importer_handle_enum (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIEnumInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_enum(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIEnumInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef enum_class;
- guint num_vals, i, j;
- gsize name_len;
- gint value; // TODO: investigate what's up with the glong/gint mystery here
- gchar *name;
- GIValueInfo *val;
-
- enum_class = JSObjectMake (ctx, 0, 0);
- num_vals = g_enum_info_get_n_values (info);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- enum_class);
-
- for (i = 0; i < num_vals; i++)
- {
- val = g_enum_info_get_value ((GIEnumInfo *) info, i);
- value = g_value_info_get_value (val);
- name = g_strdup (g_base_info_get_name ((GIBaseInfo *) val));
- name_len = strlen (name);
- JSValueRef value_ref;
-
- value_ref = JSValueMakeNumber (ctx, value);
- JSValueProtect (ctx, (JSValueRef) value_ref);
-
- for (j = 0; j < name_len; j++)
- {
- if (name[j] == '-')
- name[j] = '_';
- name[j] = g_ascii_toupper (name[j]);
- }
-
- seed_object_set_property (ctx, enum_class, name, value_ref);
-
- g_free (name);
- g_base_info_unref ((GIBaseInfo *) val);
+ JSObjectRef enum_class;
+ guint num_vals, i, j;
+ gsize name_len;
+ gint value; // TODO: investigate what's up with the glong/gint mystery here
+ gchar* name;
+ GIValueInfo* val;
+
+ enum_class = JSObjectMake(ctx, 0, 0);
+ num_vals = g_enum_info_get_n_values(info);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ enum_class);
+
+ for (i = 0; i < num_vals; i++) {
+ val = g_enum_info_get_value((GIEnumInfo*) info, i);
+ value = g_value_info_get_value(val);
+ name = g_strdup(g_base_info_get_name((GIBaseInfo*) val));
+ name_len = strlen(name);
+ JSValueRef value_ref;
+
+ value_ref = JSValueMakeNumber(ctx, value);
+ JSValueProtect(ctx, (JSValueRef) value_ref);
+
+ for (j = 0; j < name_len; j++) {
+ if (name[j] == '-')
+ name[j] = '_';
+ name[j] = g_ascii_toupper(name[j]);
+ }
+ seed_object_set_property(ctx, enum_class, name, value_ref);
+
+ g_free(name);
+ g_base_info_unref((GIBaseInfo*) val);
}
}
@@ -166,925 +201,1027 @@ seed_gi_importer_handle_enum (JSContextRef ctx,
* the prototype object. Namespace.Type.type will be the GType.
*/
static void
-seed_gi_importer_handle_object (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIObjectInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_object(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIObjectInfo* info,
+ JSValueRef* exception)
+{
+ GType type;
+ JSClassRef class_ref;
+
+ type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+
+ if (type != 0) {
+ GIFunctionInfo* finfo;
+ GIFunctionInfoFlags flags;
+ JSObjectRef constructor_ref;
+ guint i, n_methods;
+
+ class_ref = seed_gobject_get_class_for_gtype(ctx, type);
+
+ constructor_ref
+ = JSObjectMake(ctx, gobject_constructor_class, (gpointer) type);
+
+ seed_object_set_property(ctx, constructor_ref, "type",
+ seed_value_from_long(ctx, type, exception));
+ n_methods = g_object_info_get_n_methods(info);
+ for (i = 0; i < n_methods; i++) {
+ finfo = g_object_info_get_method(info, i);
+ flags = g_function_info_get_flags(finfo);
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
+ JSObjectRef constructor
+ = JSObjectMake(ctx, gobject_named_constructor_class, finfo);
+ const gchar* fname = g_base_info_get_name((GIBaseInfo*) finfo);
+ if (g_strrstr(fname, "new_") == fname) {
+ // To be compatible with gjs, we need to have a method with
+ // new_, too.
+ seed_object_set_property(ctx, constructor_ref, fname,
+ constructor);
+ fname += 4;
+ }
+
+ else if (!g_strcmp0(fname, "new")) {
+ // To be compatible with gjs, we need to have new as
+ // function, too.
+ seed_object_set_property(ctx, constructor_ref, fname,
+ constructor);
+ fname = "c_new";
+ }
+
+ seed_object_set_property(ctx, constructor_ref, fname,
+ constructor);
+ } else if (!(flags & GI_FUNCTION_IS_METHOD)) {
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ constructor_ref,
+ FALSE);
+ } else {
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
+ }
+
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ constructor_ref);
+ seed_object_set_property(ctx, constructor_ref, "prototype",
+ seed_gobject_get_prototype_for_gtype(type));
+ }
+}
+
+static void
+seed_gi_importer_handle_iface(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIObjectInfo* info,
+ JSValueRef* exception)
{
- GType type;
- JSClassRef class_ref;
-
- type = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
-
- if (type != 0)
- {
- GIFunctionInfo *finfo;
- GIFunctionInfoFlags flags;
- JSObjectRef constructor_ref;
- guint i, n_methods;
-
- class_ref = seed_gobject_get_class_for_gtype (ctx, type);
-
- constructor_ref =
- JSObjectMake (ctx, gobject_constructor_class, (gpointer) type);
-
- seed_object_set_property (ctx, constructor_ref,
- "type",
- seed_value_from_long (ctx, type, exception));
- n_methods = g_object_info_get_n_methods (info);
- for (i = 0; i < n_methods; i++)
- {
- finfo = g_object_info_get_method (info, i);
- flags = g_function_info_get_flags (finfo);
- if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
- {
- JSObjectRef constructor = JSObjectMake (ctx,
- gobject_named_constructor_class,
- finfo);
- const gchar *fname =
- g_base_info_get_name ((GIBaseInfo *) finfo);
- if (g_strrstr (fname, "new_") == fname)
- fname += 4;
- else if (!g_strcmp0 (fname, "new"))
- fname = "c_new";
-
- seed_object_set_property (ctx,
- constructor_ref, fname, constructor);
- }
- else if (!(flags & GI_FUNCTION_IS_METHOD))
- {
- seed_gobject_define_property_from_function_info
- (ctx, finfo, constructor_ref, FALSE);
- }
- else
- {
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
- }
-
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- constructor_ref);
- seed_object_set_property (ctx, constructor_ref,
- "prototype",
- seed_gobject_get_prototype_for_gtype (type));
+ GType type;
+
+ type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+
+ if (type != 0) {
+ GIFunctionInfo* finfo;
+ GIFunctionInfoFlags flags;
+ JSObjectRef constructor_ref;
+ guint i, n_methods;
+
+ constructor_ref
+ = JSObjectMake(ctx, gobject_constructor_class, (gpointer) type);
+
+ seed_object_set_property(ctx, constructor_ref, "type",
+ seed_value_from_long(ctx, type, exception));
+ n_methods = g_interface_info_get_n_methods(info);
+ for (i = 0; i < n_methods; i++) {
+ finfo = g_interface_info_get_method(info, i);
+ flags = g_function_info_get_flags(finfo);
+ if (!(flags & GI_FUNCTION_IS_METHOD)) {
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ constructor_ref,
+ FALSE);
+ } else {
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
+ }
+
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ constructor_ref);
+ seed_object_set_property(ctx, constructor_ref, "prototype",
+ seed_gobject_get_prototype_for_gtype(type));
}
}
/*
- * Set up prototype and constructor for structs. Same semantics as objects except
+ * Set up prototype and constructor for structs. Same semantics as objects
+ * except
* for the type.
*/
static void
-seed_gi_importer_handle_struct (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIStructInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_struct(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIStructInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef struct_ref;
- JSObjectRef proto;
- gint i, n_methods;
- GIFunctionInfo *finfo;
-
- struct_ref = JSObjectMake (ctx, seed_struct_constructor_class, info);
- g_base_info_ref (info);
-
- n_methods = g_struct_info_get_n_methods (info);
-
- for (i = 0; i < n_methods; i++)
- {
- GIFunctionInfoFlags flags;
- finfo = g_struct_info_get_method (info, i);
-
- flags = g_function_info_get_flags (finfo);
-
- if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
- {
- JSObjectRef constructor = JSObjectMake (ctx,
- gobject_named_constructor_class,
- finfo);
- const gchar *fname = g_base_info_get_name ((GIBaseInfo *) finfo);
- if (g_str_has_prefix (fname, "new_"))
- fname += 4;
- else if (!g_strcmp0 (fname, "new"))
- fname = "c_new";
-
- seed_object_set_property (ctx, struct_ref, fname, constructor);
- }
- else if (flags & GI_FUNCTION_IS_METHOD)
- g_base_info_unref ((GIBaseInfo *) finfo);
- else
- seed_gobject_define_property_from_function_info
- (ctx, finfo, struct_ref, FALSE);
+ JSObjectRef struct_ref;
+ JSObjectRef proto;
+ gint i, n_methods;
+ GIFunctionInfo* finfo;
+
+ struct_ref = JSObjectMake(ctx, seed_struct_constructor_class, info);
+ g_base_info_ref(info);
+
+ n_methods = g_struct_info_get_n_methods(info);
+
+ for (i = 0; i < n_methods; i++) {
+ GIFunctionInfoFlags flags;
+ finfo = g_struct_info_get_method(info, i);
+
+ flags = g_function_info_get_flags(finfo);
+
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
+ JSObjectRef constructor
+ = JSObjectMake(ctx, gobject_named_constructor_class, finfo);
+ const gchar* fname = g_base_info_get_name((GIBaseInfo*) finfo);
+ if (g_strrstr(fname, "new_") == fname) {
+ // To be compatible with gjs, we need to have a method with
+ // new_, too.
+ seed_object_set_property(ctx, struct_ref, fname, constructor);
+ fname += 4;
+ }
+
+ else if (!g_strcmp0(fname, "new")) {
+ // To be compatible with gjs, we need to have new as function,
+ // too.
+ seed_object_set_property(ctx, struct_ref, fname, constructor);
+ fname = "c_new";
+ }
+
+ seed_object_set_property(ctx, struct_ref, fname, constructor);
+ } else if (flags & GI_FUNCTION_IS_METHOD)
+ g_base_info_unref((GIBaseInfo*) finfo);
+ else
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ struct_ref, FALSE);
}
- proto = seed_struct_prototype (ctx, (GIBaseInfo *) info);
- seed_object_set_property (ctx, struct_ref, "prototype", proto);
+ proto = seed_struct_prototype(ctx, (GIBaseInfo*) info);
+ seed_object_set_property(ctx, struct_ref, "prototype", proto);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- struct_ref);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ struct_ref);
}
static void
-seed_gi_importer_handle_union (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIUnionInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_union(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIUnionInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef union_ref;
- JSObjectRef proto;
- guint i, n_methods;
- GIFunctionInfo *finfo;
+ JSObjectRef union_ref;
+ JSObjectRef proto;
+ guint i, n_methods;
+ GIFunctionInfo* finfo;
- union_ref = JSObjectMake (ctx, seed_struct_constructor_class, info);
- g_base_info_ref (info);
+ union_ref = JSObjectMake(ctx, seed_struct_constructor_class, info);
+ g_base_info_ref(info);
- n_methods = g_union_info_get_n_methods (info);
+ n_methods = g_union_info_get_n_methods(info);
- for (i = 0; i < n_methods; i++)
- {
- GIFunctionInfoFlags flags;
- finfo = g_union_info_get_method (info, i);
+ for (i = 0; i < n_methods; i++) {
+ GIFunctionInfoFlags flags;
+ finfo = g_union_info_get_method(info, i);
- flags = g_function_info_get_flags (finfo);
+ flags = g_function_info_get_flags(finfo);
- if (flags & GI_FUNCTION_IS_METHOD)
- g_base_info_unref ((GIBaseInfo *) finfo);
- else
- seed_gobject_define_property_from_function_info
- (ctx, finfo, union_ref, FALSE);
+ if (flags & GI_FUNCTION_IS_METHOD)
+ g_base_info_unref((GIBaseInfo*) finfo);
+ else
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ union_ref, FALSE);
}
- proto = seed_union_prototype (ctx, (GIBaseInfo *) info);
- seed_object_set_property (ctx, union_ref, "prototype", proto);
+ proto = seed_union_prototype(ctx, (GIBaseInfo*) info);
+ seed_object_set_property(ctx, union_ref, "prototype", proto);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- union_ref);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ union_ref);
}
static void
-seed_gi_importer_handle_callback (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GICallbackInfo * info,
- JSValueRef * exception)
+seed_gi_importer_handle_callback(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GICallbackInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef callback_ref = JSObjectMake (ctx,
- seed_callback_class,
- info);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- (JSValueRef) callback_ref);
+ JSObjectRef callback_ref = JSObjectMake(ctx, seed_callback_class, info);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ (JSValueRef) callback_ref);
}
/*
* Define constants toplevel. Uses the casing as in the typelib
*/
static void
-seed_gi_importer_handle_constant (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIConstantInfo * info,
- JSValueRef * exception)
+seed_gi_importer_handle_constant(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIConstantInfo* info,
+ JSValueRef* exception)
{
- GArgument argument;
- GITypeInfo *constant_type = g_constant_info_get_type (info);
- JSValueRef constant_value;
-
- g_constant_info_get_value (info, &argument);
- constant_value =
- seed_value_from_gi_argument (ctx, &argument, constant_type, exception);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- constant_value);
-
- g_base_info_unref ((GIBaseInfo *) constant_type);
+ GArgument argument;
+ GITypeInfo* constant_type = g_constant_info_get_type(info);
+ JSValueRef constant_value;
+
+ g_constant_info_get_value(info, &argument);
+ constant_value
+ = seed_value_from_gi_argument(ctx, &argument, constant_type, exception);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ constant_value);
+
+ g_base_info_unref((GIBaseInfo*) constant_type);
+ g_constant_info_free_value(info, &argument);
}
-static gchar *
-seed_gi_importer_get_version (JSContextRef ctx,
- gchar * namespace, JSValueRef * exception)
+static gchar*
+seed_gi_importer_get_version(JSContextRef ctx,
+ gchar* namespace,
+ JSValueRef* exception)
{
- JSValueRef version_ref;
- gchar *version = NULL;
+ JSValueRef version_ref;
+ gchar* version = NULL;
- version_ref =
- seed_object_get_property (ctx, gi_importer_versions, namespace);
- if (!JSValueIsUndefined (ctx, version_ref))
- version = seed_value_to_string (ctx, version_ref, exception);
+ version_ref
+ = seed_object_get_property(ctx, gi_importer_versions, namespace);
+ if (!JSValueIsUndefined(ctx, version_ref))
+ version = seed_value_to_string(ctx, version_ref, exception);
- return version;
+ return version;
}
JSObjectRef
-seed_gi_importer_do_namespace (JSContextRef ctx,
- gchar * namespace, JSValueRef * exception)
+seed_gi_importer_do_namespace(JSContextRef ctx,
+ gchar* namespace,
+ JSValueRef* exception)
{
- GIBaseInfo *info;
- JSObjectRef namespace_ref;
- GError *e = NULL;
- guint n, i;
- gchar *version = NULL;
- gchar *jsextension;
- JSStringRef extension_script;
-
- if (gi_imports == NULL)
- gi_imports = g_hash_table_new (g_str_hash, g_str_equal);
-
- if ((namespace_ref = g_hash_table_lookup (gi_imports, namespace)))
- {
- SEED_NOTE (IMPORTER, "Using existing namespace ref (%p) for %s",
- namespace_ref, namespace);
- return namespace_ref;
+ GIBaseInfo* info;
+ JSObjectRef namespace_ref;
+ GError* e = NULL;
+ guint n, i;
+ gchar* version = NULL;
+ gchar* jsextension;
+ JSStringRef extension_script;
+
+ if (gi_imports == NULL)
+ gi_imports = g_hash_table_new(g_str_hash, g_str_equal);
+
+ if ((namespace_ref = g_hash_table_lookup(gi_imports, namespace))) {
+ SEED_NOTE(IMPORTER, "Using existing namespace ref (%p) for %s",
+ namespace_ref, namespace);
+ return namespace_ref;
}
- if (gi_importer_versions != NULL)
- version = seed_gi_importer_get_version (ctx, namespace, exception);
- if (!g_irepository_require (NULL, namespace, version, 0, &e))
- {
- seed_make_exception_from_gerror (ctx, exception, e);
- g_error_free (e);
- g_free (version);
- return NULL;
+ if (gi_importer_versions != NULL)
+ version = seed_gi_importer_get_version(ctx, namespace, exception);
+ if (!g_irepository_require(NULL, namespace, version, 0, &e)) {
+ seed_make_exception_from_gerror(ctx, exception, e);
+ g_error_free(e);
+ g_free(version);
+ return NULL;
}
- if (version != NULL)
- g_free (version);
-
- n = g_irepository_get_n_infos (NULL, namespace);
-
- namespace_ref = JSObjectMake (ctx, NULL, NULL);
- SEED_NOTE (IMPORTER, "Constructing namespace ref (%p) for %s",
- namespace_ref, namespace);
-
- JSValueProtect (ctx, namespace_ref);
-
- for (i = 0; i < n; i++)
- {
- GIInfoType info_type;
-
- info = g_irepository_get_info (NULL, namespace, i);
- info_type = g_base_info_get_type (info);
-
- switch (info_type)
- {
- case GI_INFO_TYPE_FUNCTION:
- seed_gi_importer_handle_function (ctx, namespace_ref,
- (GIFunctionInfo *) info,
- exception);
- break;
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
- seed_gi_importer_handle_enum (ctx, namespace_ref,
- (GIEnumInfo *) info, exception);
- break;
- case GI_INFO_TYPE_OBJECT:
- seed_gi_importer_handle_object (ctx, namespace_ref,
- (GIObjectInfo *) info, exception);
- break;
- case GI_INFO_TYPE_STRUCT:
- seed_gi_importer_handle_struct (ctx, namespace_ref,
- (GIStructInfo *) info, exception);
- break;
- case GI_INFO_TYPE_UNION:
- seed_gi_importer_handle_union (ctx, namespace_ref,
- (GIUnionInfo *) info, exception);
- break;
- case GI_INFO_TYPE_CALLBACK:
- seed_gi_importer_handle_callback (ctx, namespace_ref,
- (GICallbackInfo *) info,
- exception);
- break;
- case GI_INFO_TYPE_CONSTANT:
- seed_gi_importer_handle_constant (ctx, namespace_ref,
- (GIConstantInfo *) info,
- exception);
- break;
- default:
- break;
- }
- g_base_info_unref (info);
+ if (version != NULL)
+ g_free(version);
+
+ n = g_irepository_get_n_infos(NULL, namespace);
+
+ namespace_ref = JSObjectMake(ctx, NULL, NULL);
+ SEED_NOTE(IMPORTER, "Constructing namespace ref (%p) for %s", namespace_ref,
+ namespace);
+
+ JSValueProtect(ctx, namespace_ref);
+
+ for (i = 0; i < n; i++) {
+ GIInfoType info_type;
+
+ info = g_irepository_get_info(NULL, namespace, i);
+ info_type = g_base_info_get_type(info);
+
+ switch (info_type) {
+ case GI_INFO_TYPE_FUNCTION:
+ seed_gi_importer_handle_function(ctx, namespace_ref,
+ (GIFunctionInfo*) info,
+ exception);
+ break;
+ case GI_INFO_TYPE_ENUM:
+ case GI_INFO_TYPE_FLAGS:
+ seed_gi_importer_handle_enum(ctx, namespace_ref,
+ (GIEnumInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_OBJECT:
+ seed_gi_importer_handle_object(ctx, namespace_ref,
+ (GIObjectInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_INTERFACE:
+ seed_gi_importer_handle_iface(ctx, namespace_ref,
+ (GIObjectInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_STRUCT:
+ seed_gi_importer_handle_struct(ctx, namespace_ref,
+ (GIStructInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_UNION:
+ seed_gi_importer_handle_union(ctx, namespace_ref,
+ (GIUnionInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_CALLBACK:
+ seed_gi_importer_handle_callback(ctx, namespace_ref,
+ (GICallbackInfo*) info,
+ exception);
+ break;
+ case GI_INFO_TYPE_CONSTANT:
+ seed_gi_importer_handle_constant(ctx, namespace_ref,
+ (GIConstantInfo*) info,
+ exception);
+ break;
+ default:
+ SEED_NOTE(IMPORTER, "Unhandled type %s for %s",
+ g_info_type_to_string(info_type),
+ g_base_info_get_name(info));
+ break;
+ }
+ g_base_info_unref(info);
}
- g_hash_table_insert (gi_imports, g_strdup (namespace), namespace_ref);
-
- jsextension = g_strdup_printf ("imports.extensions.%s", namespace);
- extension_script = JSStringCreateWithUTF8CString (jsextension);
- JSEvaluateScript (ctx, extension_script, NULL, NULL, 0, exception);
- JSStringRelease (extension_script);
- g_free (jsextension);
+ g_hash_table_insert(gi_imports, g_strdup(namespace), namespace_ref);
+ jsextension = g_strdup_printf("imports.extensions.%s", namespace);
+ extension_script = JSStringCreateWithUTF8CString(jsextension);
+ JSEvaluateScript(ctx, extension_script, NULL, NULL, 0, exception);
+ JSStringRelease(extension_script);
+ g_free(jsextension);
- return namespace_ref;
-
+ return namespace_ref;
}
static JSValueRef
-seed_gi_importer_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef * exception)
+seed_gi_importer_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- JSObjectRef ret;
- guint len;
- gchar *prop;
+ JSObjectRef ret;
+ guint len;
+ gchar* prop;
- len = JSStringGetMaximumUTF8CStringSize (property_name);
- prop = g_alloca (len * sizeof (gchar));
- JSStringGetUTF8CString (property_name, prop, len);
+ len = JSStringGetMaximumUTF8CStringSize(property_name);
+ prop = g_alloca(len * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, prop, len);
- SEED_NOTE (IMPORTER, "seed_gi_importer_get_property with %s", prop);
+ SEED_NOTE(IMPORTER, "seed_gi_importer_get_property with %s", prop);
- if (!g_strcmp0 (prop, "versions"))
- return gi_importer_versions;
- // Nasty hack
- else if (!g_strcmp0 (prop, "toString"))
- return 0;
- if (!g_strcmp0 (prop, "valueOf")) // HACK
- return NULL;
+ if (!g_strcmp0(prop, "versions"))
+ return gi_importer_versions;
+ // Nasty hack
+ else if (!g_strcmp0(prop, "toString"))
+ return 0;
+ if (!g_strcmp0(prop, "valueOf")) // HACK
+ return NULL;
+ ret = seed_gi_importer_do_namespace(ctx, prop, exception);
+ SEED_NOTE(IMPORTER, "Result (%p) from attempting to import %s: %s", ret,
+ prop, seed_value_to_string(ctx, ret, exception));
- ret = seed_gi_importer_do_namespace (ctx, prop, exception);
- SEED_NOTE (IMPORTER, "Result (%p) from attempting to import %s: %s",
- ret, prop, seed_value_to_string (ctx, ret, exception));
+ return ret;
+}
- return ret;
+gboolean
+seed_importer_get_file_contents(const gchar* filename,
+ gchar** contents,
+ gsize* length,
+ GError** error)
+{
+ GBytes* bytes
+ = g_resources_lookup_data(filename, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ if (bytes) {
+ *contents = g_strdup(g_bytes_get_data(bytes, length));
+ g_bytes_unref(bytes);
+ return true;
+ }
+
+ return g_file_get_contents(filename, contents, length, error);
}
static JSObjectRef
-seed_make_importer_dir (JSContextRef ctx, gchar * path)
+seed_make_importer_dir(JSContextRef ctx, gchar* path)
{
- gchar *init;
- JSObjectRef dir;
+ gchar* init;
+ JSObjectRef dir;
- dir = JSObjectMake (ctx, importer_dir_class, path);
+ dir = JSObjectMake(ctx, importer_dir_class, path);
- init = g_build_filename (path, "__init__.js", NULL);
- if (g_file_test (init, G_FILE_TEST_IS_REGULAR))
- {
- SeedScript *s;
- SEED_NOTE (IMPORTER, "Found __init__.js (%s)", path);
+ init = g_build_filename(path, "__init__.js", NULL);
+ if (seed_file_test(init, G_FILE_TEST_IS_REGULAR)) {
+ SeedScript* s;
+ SEED_NOTE(IMPORTER, "Found __init__.js (%s)", path);
- s = seed_script_new_from_file (ctx, init);
- seed_evaluate (ctx, s, dir);
- seed_script_destroy (s);
+ s = seed_script_new_from_file(ctx, init);
+ seed_evaluate(ctx, s, dir);
+ seed_script_destroy(s);
}
- g_free (init);
- return dir;
+ g_free(init);
+ return dir;
}
static void
-seed_importer_free_search_path (GSList * path)
+seed_importer_free_search_path(GSList* path)
{
- GSList *walk = path;
+ GSList* walk = path;
- while (walk)
- {
- g_free (walk->data);
- walk = walk->next;
+ while (walk) {
+ g_free(walk->data);
+ walk = walk->next;
}
- g_slist_free (path);
+ g_slist_free(path);
}
-
-GSList *
-seed_importer_get_search_path (JSContextRef ctx, JSValueRef * exception)
+GSList*
+seed_importer_get_search_path(JSContextRef ctx, JSValueRef* exception)
{
- GSList *path = NULL;
- gchar *entry;
- JSValueRef search_path_ref, length_ref;
- guint length, i;
-
- search_path_ref = seed_object_get_property (ctx, importer, "searchPath");
- if (!JSValueIsObject (ctx, search_path_ref))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Importer searchPath object is not an array");
- return NULL;
+ GSList* path = NULL;
+ gchar* entry;
+ JSValueRef search_path_ref, length_ref;
+ guint length, i;
+
+ search_path_ref = seed_object_get_property(ctx, importer, "searchPath");
+ if (!JSValueIsObject(ctx, search_path_ref)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Importer searchPath object is not an array");
+ return NULL;
}
- length_ref =
- seed_object_get_property (ctx, (JSObjectRef) search_path_ref, "length");
- length = seed_value_to_uint (ctx, length_ref, exception);
+ length_ref
+ = seed_object_get_property(ctx, (JSObjectRef) search_path_ref, "length");
+ length = seed_value_to_uint(ctx, length_ref, exception);
- for (i = 0; i < length; i++)
- {
- JSValueRef entry_ref;
+ for (i = 0; i < length; i++) {
+ JSValueRef entry_ref;
- entry_ref =
- JSObjectGetPropertyAtIndex (ctx, (JSObjectRef) search_path_ref, i,
- exception);
- entry = seed_value_to_string (ctx, entry_ref, exception);
+ entry_ref
+ = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) search_path_ref, i,
+ exception);
+ entry = seed_value_to_string(ctx, entry_ref, exception);
- if (g_file_test (entry, G_FILE_TEST_EXISTS) == TRUE)
- path = g_slist_append (path, entry);
+ if (seed_file_test(entry, G_FILE_TEST_EXISTS) == TRUE)
+ path = g_slist_append(path, entry);
+ else {
+ g_free(entry);
+ }
}
- return path;
+ return path;
}
/* forward reference */
-static JSObjectRef
-seed_importer_handle_file (JSContextRef ctx,
- const gchar * dir,
- const gchar * file,
- JSValueRef * exception);
-
-
+static JSObjectRef seed_importer_handle_file(JSContextRef ctx,
+ const gchar* dir,
+ const gchar* file,
+ const gchar* module_name,
+ JSValueRef* exception);
static JSObjectRef
-seed_importer_handle_native_module (JSContextRef ctx,
- const gchar * dir,
- const gchar * prop,
- JSValueRef * exception)
+seed_importer_handle_native_module(JSContextRef ctx,
+ const gchar* dir,
+ const gchar* prop,
+ JSValueRef* exception)
{
- GModule *module;
- JSObjectRef module_obj;
- SeedModuleInitCallback init;
- gchar *file_path = g_strconcat (dir, "/libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
-
- SEED_NOTE (IMPORTER, "Trying native module: %s", file_path);
-
- if ((module_obj = g_hash_table_lookup (file_imports, file_path)))
- {
- SEED_NOTE (IMPORTER, "Using existing global");
- g_free (file_path);
- return module_obj;
+ GModule* module;
+ JSObjectRef module_obj;
+ SeedModuleInitCallback init;
+ gchar* file_path
+ = g_strconcat(dir, "/libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
+
+ SEED_NOTE(IMPORTER, "Trying native module: %s", file_path);
+
+ if ((module_obj = g_hash_table_lookup(file_imports, file_path))) {
+ SEED_NOTE(IMPORTER, "Using existing global");
+ g_free(file_path);
+ return module_obj;
}
- module = g_module_open (file_path, 0);
+ module = g_module_open(file_path, 0);
- if (!module)
- {
- // Could be a better exception
- seed_make_exception (ctx, exception, "ModuleError",
- "Error loading native module at %s: %s",
- file_path, g_module_error ());
- g_free (file_path);
+ if (!module) {
+ // Could be a better exception
+ seed_make_exception(ctx, exception, "ModuleError",
+ "Error loading native module at %s: %s", file_path,
+ g_module_error());
+ g_free(file_path);
- return NULL;
+ return NULL;
}
- g_module_symbol (module, "seed_module_init", (gpointer *) & init);
- module_obj = (*init) (eng);
- g_hash_table_insert (file_imports, file_path, module_obj);
- SEED_NOTE (IMPORTER, "Loaded native module");
-
- //protect module_obj since the GC won't find the module in our file_imports cache
- JSValueProtect (ctx, module_obj);
-
- file_path = g_strconcat ("libseed_", prop, ".js", NULL);
- seed_importer_handle_file (ctx, dir, file_path, exception);
- g_free (file_path);
-
- return module_obj;
+ g_module_symbol(module, "seed_module_init", (gpointer*) &init);
+ module_obj = (*init)(eng);
+ g_hash_table_insert(file_imports, file_path, module_obj);
+ SEED_NOTE(IMPORTER, "Loaded native module");
+
+ // protect module_obj since the GC won't find the module in our file_imports
+ // cache
+ JSValueProtect(ctx, module_obj);
+
+ file_path = g_strconcat("libseed_", prop, ".js", NULL);
+ seed_importer_handle_file(ctx, dir, file_path, prop, exception);
+ g_free(file_path);
+
+ return module_obj;
}
-static gchar *
-seed_importer_canonicalize_path (gchar * path)
+static gchar*
+seed_importer_canonicalize_path(gchar* path)
{
- GFile *file;
- gchar *absolute_path;
+ GFile* file;
+ gchar* absolute_path;
- file = g_file_new_for_path (path);
- absolute_path = g_file_get_path (file);
- g_object_unref (file);
+ file = g_file_new_for_path(path);
+ absolute_path = g_file_get_path(file);
+ g_object_unref(file);
- return absolute_path;
+ return absolute_path;
}
static JSObjectRef
-seed_importer_handle_file (JSContextRef ctx,
- const gchar * dir,
- const gchar * file, JSValueRef * exception)
+seed_importer_handle_file(JSContextRef ctx,
+ const gchar* dir,
+ const gchar* file,
+ const gchar* module_name,
+ JSValueRef* exception)
{
- JSContextRef nctx;
- JSValueRef js_file_dirname;
- JSObjectRef global, c_global;
- JSStringRef file_contents, file_name;
- gchar *contents, *walk, *file_path, *canonical, *absolute_path, *normalp;
- gchar *normalized_path;
- gsize path_max;
-
- file_path = g_build_filename (dir, file, NULL);
- canonical = seed_importer_canonicalize_path (file_path);
- SEED_NOTE (IMPORTER, "Trying to import file: %s", file_path);
-
- if ((global = g_hash_table_lookup (file_imports, canonical)))
- {
- SEED_NOTE (IMPORTER, "Using existing global");
-
- g_free (file_path);
- g_free (canonical);
- return global;
+ JSContextRef nctx;
+ JSValueRef js_file_dirname;
+ JSObjectRef global, c_global;
+ JSStringRef file_contents, file_name, initscript;
+ gchar *contents, *walk, *file_path, *canonical, *absolute_path;
+ char* normalized_path;
+
+ file_path = g_build_filename(dir, file, NULL);
+ canonical = seed_importer_canonicalize_path(file_path);
+ SEED_NOTE(IMPORTER, "Trying to import file: %s", file_path);
+
+ if ((global = g_hash_table_lookup(file_imports, canonical))) {
+ SEED_NOTE(IMPORTER, "Using existing global");
+
+ g_free(file_path);
+ g_free(canonical);
+ return global;
}
- if (!g_file_test (file_path, G_FILE_TEST_IS_REGULAR))
- {
- if (g_file_test (file_path, G_FILE_TEST_IS_DIR))
- {
- SEED_NOTE (IMPORTER, "File is directory");
- return seed_make_importer_dir (ctx, file_path);
- }
- return NULL;
+ if (!seed_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ if (seed_file_test(file_path, G_FILE_TEST_IS_DIR)) {
+ SEED_NOTE(IMPORTER, "File is directory");
+ return seed_make_importer_dir(ctx, file_path);
+ }
+ return NULL;
}
- g_file_get_contents (file_path, &contents, 0, NULL);
- walk = contents;
- if (*walk == '#')
- {
- while (*walk != '\n')
- walk++;
- walk++;
+ seed_importer_get_file_contents(file_path, &contents, 0, NULL);
+ walk = contents;
+ if (*walk == '#') {
+ while (*walk != '\n')
+ walk++;
+ walk++;
}
- walk = g_strdup (walk);
- g_free (contents);
+ walk = g_strdup(walk);
+ g_free(contents);
- file_contents = JSStringCreateWithUTF8CString (walk);
- file_name = JSStringCreateWithUTF8CString (canonical);
+ file_contents = JSStringCreateWithUTF8CString(walk);
+ file_name = JSStringCreateWithUTF8CString(canonical);
- nctx = JSGlobalContextCreateInGroup (context_group, 0);
- seed_prepare_global_context (nctx);
+ nctx = JSGlobalContextCreateInGroup(context_group, 0);
+ seed_prepare_global_context(nctx);
- global = JSContextGetGlobalObject (nctx);
- c_global = JSContextGetGlobalObject (ctx);
- JSValueProtect (eng->context, global);
+ global = JSContextGetGlobalObject(nctx);
+ c_global = JSContextGetGlobalObject(ctx);
+ JSValueProtect(eng->context, global);
- absolute_path = g_path_get_dirname (file_path);
- if (!g_path_is_absolute (absolute_path))
- {
- g_free (absolute_path);
- absolute_path = g_build_filename (g_get_current_dir (),
- g_path_get_dirname (file_path), NULL);
+ absolute_path = g_path_get_dirname(file_path);
+ if (!g_path_is_absolute(absolute_path)) {
+ g_free(absolute_path);
+ absolute_path = g_build_filename(g_get_current_dir(),
+ g_path_get_dirname(file_path), NULL);
}
-#ifdef PATH_MAX
- path_max = PATH_MAX;
-#else
- path_max = pathconf (absolute_path, _PC_PATH_MAX);
- if (path_max <= 0)
- path_max = 4096;
-#endif
- normalized_path = (gchar *) g_malloc (path_max);
- normalp = realpath (absolute_path, normalized_path);
+ normalized_path = realpath(absolute_path, NULL);
+
+ js_file_dirname = seed_value_from_string(ctx, normalized_path, NULL);
- js_file_dirname = seed_value_from_string (ctx, normalp, NULL);
+ seed_object_set_property(nctx, global, "__script_path__", js_file_dirname);
- seed_object_set_property (nctx, global, "__script_path__", js_file_dirname);
+ g_hash_table_insert(file_imports, canonical, global);
+ g_free(file_path);
+ g_free(absolute_path);
+ g_free(normalized_path);
- g_hash_table_insert (file_imports, canonical, global);
- g_free (file_path);
- g_free (absolute_path);
- g_free (normalized_path);
+ JSEvaluateScript(nctx, file_contents, NULL, file_name, 0, exception);
- JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
+ if (gi_imports && g_hash_table_lookup(gi_imports, module_name)) {
+ SEED_NOTE(IMPORTER, "Calling %s_init():", module_name);
+ gchar* initstr = g_strdup_printf(
+ "if (typeof(_init) === \"function\") { _init.apply(imports.gi.%s)}",
+ module_name);
+ initscript = JSStringCreateWithUTF8CString(initstr);
+ JSEvaluateScript(nctx, initscript, NULL, file_name, 0, exception);
+ JSStringRelease(initscript);
+ g_free(initstr);
+ }
- // Does leak...but it's a debug statement.
- SEED_NOTE (IMPORTER, "Evaluated file, exception: %s",
- *exception ? seed_exception_to_string (ctx,
- *exception) : "(null)");
+ // Does leak...but it's a debug statement.
+ SEED_NOTE(IMPORTER, "Evaluated file, exception: %s",
+ *exception ? seed_exception_to_string(ctx, *exception)
+ : "(null)");
- JSGlobalContextRelease ((JSGlobalContextRef) nctx);
+ JSGlobalContextRelease((JSGlobalContextRef) nctx);
- JSStringRelease (file_contents);
- JSStringRelease (file_name);
- g_free (walk);
+ JSStringRelease(file_contents);
+ JSStringRelease(file_name);
+ g_free(walk);
- return global;
+ return global;
}
static JSObjectRef
-seed_importer_search_dirs (JSContextRef ctx, GSList *path, gchar *prop, JSValueRef *exception)
+seed_importer_try_load(JSContextRef ctx,
+ const gchar* test_path,
+ const gchar* script_path,
+ const gchar* prop,
+ const gchar* prop_as_js,
+ const gchar* prop_as_lib,
+ JSValueRef* exception)
{
- GSList *walk;
+ gchar* file_path = NULL;
+ JSObjectRef ret = NULL;
+ // replace '.' with current script_path if not null
+ if (script_path && !g_strcmp0(".", test_path))
+ test_path = script_path;
+
+ // check if prop is a file or dir (imports['foo.js'] or imports.mydir)
+ file_path = g_build_filename(test_path, prop, NULL);
+ if (seed_file_test(file_path,
+ G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) {
+ ret = seed_importer_handle_file(ctx, test_path, prop, prop, exception);
+ g_free(file_path);
+ return ret;
+ }
+ g_free(file_path);
+
+ // check if prop is file ending with '.js'
+ file_path = g_build_filename(test_path, prop_as_js, NULL);
+ if (seed_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ ret = seed_importer_handle_file(ctx, test_path, prop_as_js, prop,
+ exception);
+ g_free(file_path);
+ return ret;
+ }
+ g_free(file_path);
+
+ // check if file is native module
+ file_path = g_build_filename(test_path, prop_as_lib, NULL);
+ if (seed_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ ret
+ = seed_importer_handle_native_module(ctx, test_path, prop, exception);
+ g_free(file_path);
+ return ret;
+ }
+ g_free(file_path);
+
+ return ret;
+}
+
+static JSObjectRef
+seed_importer_search_dirs(JSContextRef ctx,
+ GSList* path,
+ gchar* prop,
+ JSValueRef* exception)
+{
+ GSList* walk;
JSObjectRef ret, global;
JSValueRef script_path_prop;
gchar *prop_as_lib, *prop_as_js, *script_path;
- prop_as_lib = g_strconcat ("libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
- prop_as_js = g_strconcat (prop, ".js", NULL);
+ prop_as_lib = g_strconcat("libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
+ prop_as_js = g_strconcat(prop, ".js", NULL);
- // get the current script_path
- global = JSContextGetGlobalObject (ctx);
- script_path_prop = seed_object_get_property (ctx, global, "__script_path__");
- if (script_path_prop==NULL || JSValueIsUndefined (ctx, script_path_prop))
+ // get the current script_path
+ global = JSContextGetGlobalObject(ctx);
+ script_path_prop = seed_object_get_property(ctx, global, "__script_path__");
+ if (script_path_prop == NULL || JSValueIsUndefined(ctx, script_path_prop))
script_path = NULL;
else
- script_path = seed_value_to_string (ctx, script_path_prop, exception);
+ script_path = seed_value_to_string(ctx, script_path_prop, exception);
ret = NULL;
walk = path;
while (walk) {
- gchar *test_path = walk->data;
- gchar *file_path;
-
- // replace '.' with current script_path if not null
- if(script_path && !g_strcmp0(".",test_path))
- test_path = script_path;
-
- // check if prop is a file or dir (imports['foo.js'] or imports.mydir)
- file_path = g_build_filename (test_path, prop, NULL);
- if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) {
- ret = seed_importer_handle_file (ctx, test_path, prop, exception);
- g_free (file_path);
- break;
- }
- g_free (file_path);
+ gchar* test_path = g_strconcat(walk->data, "/gjs", NULL);
- // check if prop is file ending with '.js'
- file_path = g_build_filename (test_path, prop_as_js, NULL);
- if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)) {
- ret = seed_importer_handle_file (ctx, test_path, prop_as_js, exception);
- g_free (file_path);
- break;
- }
- g_free (file_path);
-
- // check if file is native module
- file_path = g_build_filename (test_path, prop_as_lib, NULL);
- if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)) {
- ret = seed_importer_handle_native_module (ctx, test_path, prop, exception);
- g_free (file_path);
+ ret = seed_importer_try_load(ctx, test_path, script_path, prop,
+ prop_as_js, prop_as_lib, exception);
+ g_free(test_path);
+ walk = walk->next;
+
+ if (ret)
break;
- }
- g_free (file_path);
+ }
+ if (!ret) {
+ walk = path;
+ while (walk) {
+ gchar* test_path = walk->data;
- walk = walk->next;
+ ret = seed_importer_try_load(ctx, test_path, script_path, prop,
+ prop_as_js, prop_as_lib, exception);
+ walk = walk->next;
+
+ if (ret)
+ break;
+ }
}
- g_free (prop_as_lib);
- g_free (prop_as_js);
- g_free (script_path);
-
+ g_free(prop_as_lib);
+ g_free(prop_as_js);
+ g_free(script_path);
+
return ret;
}
static JSObjectRef
-seed_importer_search (JSContextRef ctx, gchar *prop, JSValueRef *exception)
+seed_importer_search(JSContextRef ctx, gchar* prop, JSValueRef* exception)
{
+
JSObjectRef ret = NULL;
- GSList *path = seed_importer_get_search_path (ctx, exception);
- ret = seed_importer_search_dirs (ctx, path, prop, exception);
- seed_importer_free_search_path (path);
+ GSList* path = seed_importer_get_search_path(ctx, exception);
+ ret = seed_importer_search_dirs(ctx, path, prop, exception);
+ seed_importer_free_search_path(path);
return ret;
}
static JSValueRef
-seed_importer_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_importer_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- JSValueRef ret;
- guint len;
- gchar *prop;
+ JSValueRef ret;
+ guint len;
+ gchar* prop;
- len = JSStringGetMaximumUTF8CStringSize (property_name);
- prop = g_alloca (len * sizeof (gchar));
- JSStringGetUTF8CString (property_name, prop, len);
+ len = JSStringGetMaximumUTF8CStringSize(property_name);
+ prop = g_alloca(len * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, prop, len);
- if (!g_strcmp0 (prop, "gi"))
- return gi_importer;
- if (!g_strcmp0 (prop, "searchPath"))
- return NULL;
- if (!g_strcmp0 (prop, "toString")) // HACK
- return NULL;
+ if (!g_strcmp0(prop, "gi"))
+ return gi_importer;
+ if (!g_strcmp0(prop, "searchPath"))
+ return NULL;
+ if (!g_strcmp0(prop, "toString")) // HACK
+ return NULL;
- ret = seed_importer_search (ctx, prop, exception);
+ ret = seed_importer_search(ctx, prop, exception);
- return ret;
+ return ret;
}
static JSValueRef
-seed_importer_dir_get_property (JSContextRef ctx,
+seed_importer_dir_get_property(JSContextRef ctx,
JSObjectRef object,
JSStringRef property_name,
- JSValueRef * exception)
+ JSValueRef* exception)
{
guint len;
- gchar *prop;
+ gchar* prop;
GSList path;
- path.data = JSObjectGetPrivate (object);
+ path.data = JSObjectGetPrivate(object);
path.next = NULL;
- len = JSStringGetMaximumUTF8CStringSize (property_name);
- prop = g_alloca (len * sizeof (gchar));
- JSStringGetUTF8CString (property_name, prop, len);
+ len = JSStringGetMaximumUTF8CStringSize(property_name);
+ prop = g_alloca(len * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, prop, len);
- /* These prevent print(imports.somefile) running "somefile/toString.js"
+ /* These prevent print(imports.somefile) running "somefile/toString.js"
Which is more than a little unexpected.. */
- if (!g_strcmp0 (prop, "toString"))
+ if (!g_strcmp0(prop, "toString"))
return NULL;
- if (!g_strcmp0 (prop, "valueOf"))
+ if (!g_strcmp0(prop, "valueOf"))
return NULL;
-
+
return seed_importer_search_dirs(ctx, &path, prop, exception);
}
static void
-seed_importer_dir_finalize (JSObjectRef dir)
+seed_importer_dir_finalize(JSObjectRef dir)
{
- gchar *dir_path = (gchar *) JSObjectGetPrivate (dir);
- g_free (dir_path);
+ gchar* dir_path = (gchar*) JSObjectGetPrivate(dir);
+ g_free(dir_path);
}
void
-seed_importer_add_global (JSObjectRef global, gchar * name)
+seed_importer_add_global(JSObjectRef global, gchar* name)
{
- JSValueProtect (eng->context, global);
- g_hash_table_insert (file_imports, seed_importer_canonicalize_path (name),
- global);
+ JSValueProtect(eng->context, global);
+ g_hash_table_insert(file_imports, seed_importer_canonicalize_path(name),
+ global);
}
static void
-seed_importer_dir_enumerate_properties (JSContextRef ctx,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef
- propertyNames)
+seed_importer_dir_enumerate_properties(
+ JSContextRef ctx,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef propertyNames)
{
- const gchar *entry;
- GDir *dir;
- GError *e = NULL;
- gchar *path = JSObjectGetPrivate (object);
-
-
- dir = g_dir_open (path, 0, &e);
- if (e)
- {
- SEED_NOTE (IMPORTER,
- "Error in g_dir_open in seed_importer_enumerate_dir_properties: %s",
- e->message);
- g_error_free (e);
- // Not much we can do here.
- return;
+ const gchar* entry;
+ GDir* dir;
+ GError* e = NULL;
+ gchar* path = JSObjectGetPrivate(object);
+
+ dir = g_dir_open(path, 0, &e);
+ if (e) {
+ SEED_NOTE(
+ IMPORTER,
+ "Error in g_dir_open in seed_importer_enumerate_dir_properties: %s",
+ e->message);
+ g_error_free(e);
+ // Not much we can do here.
+ return;
}
- while ((entry = g_dir_read_name (dir)))
- {
- JSStringRef jname;
+ while ((entry = g_dir_read_name(dir))) {
+ JSStringRef jname;
- jname = JSStringCreateWithUTF8CString (entry);
- JSPropertyNameAccumulatorAddName (propertyNames, jname);
- JSStringRelease (jname);
+ jname = JSStringCreateWithUTF8CString(entry);
+ JSPropertyNameAccumulatorAddName(propertyNames, jname);
+ JSStringRelease(jname);
}
- g_dir_close (dir);
+ g_dir_close(dir);
}
JSObjectRef
-seed_importer_construct_dir (JSContextRef ctx,
- JSObjectRef constructor,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_importer_construct_dir(JSContextRef ctx,
+ JSObjectRef constructor,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *path;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Directory constructor expects 1 argument");
- return (JSObjectRef) JSValueMakeUndefined (ctx);
+ gchar* path;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Directory constructor expects 1 argument");
+ return (JSObjectRef) JSValueMakeUndefined(ctx);
}
- path = seed_value_to_string (ctx, arguments[0], exception);
-
- if (!g_file_test (path, G_FILE_TEST_IS_DIR))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Path (%s) is not a directory", path);
- g_free (path);
- return (JSObjectRef) JSValueMakeUndefined (ctx);
+ path = seed_value_to_string(ctx, arguments[0], exception);
+
+ if (!seed_file_test(path, G_FILE_TEST_IS_DIR)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Path (%s) is not a directory", path);
+ g_free(path);
+ return (JSObjectRef) JSValueMakeUndefined(ctx);
}
- return seed_make_importer_dir (ctx, path);
+ return seed_make_importer_dir(ctx, path);
}
void
-seed_importer_set_search_path (JSContextRef ctx, gchar ** search_path)
+seed_importer_set_search_path(JSContextRef ctx, gchar** search_path)
{
- JSObjectRef imports, array;
- JSValueRef *array_elem;
- guint length = g_strv_length (search_path), i;
-
- array_elem = g_alloca (length * sizeof (array_elem));
- imports =
- (JSObjectRef) seed_object_get_property (ctx,
- JSContextGetGlobalObject (ctx),
- "imports");
-
- for (i = 0; i < length; i++)
- {
- array_elem[i] = seed_value_from_string (ctx, search_path[i], NULL);
+ JSObjectRef imports, array;
+ JSValueRef* array_elem;
+ guint length = g_strv_length(search_path), i;
+
+ array_elem = g_alloca(length * sizeof(array_elem));
+ imports
+ = (JSObjectRef) seed_object_get_property(ctx,
+ JSContextGetGlobalObject(ctx),
+ "imports");
+
+ for (i = 0; i < length; i++) {
+ array_elem[i] = seed_value_from_string(ctx, search_path[i], NULL);
}
- array = JSObjectMakeArray (ctx, length, array_elem, NULL);
- seed_object_set_property (ctx, imports, "searchPath", array);
+ array = JSObjectMakeArray(ctx, length, array_elem, NULL);
+ seed_object_set_property(ctx, imports, "searchPath", array);
}
void
-seed_importer_add_search_path (JSContextRef ctx, gchar *search_path)
+seed_importer_add_search_path(JSContextRef ctx, gchar* search_path)
{
- GSList *paths, *l;
- GPtrArray *tmp;
+ GSList *paths, *l;
+ GPtrArray* tmp;
- tmp = g_ptr_array_new ();
+ tmp = g_ptr_array_new();
- paths = seed_importer_get_search_path (ctx, NULL);
- for (l = paths; l != NULL; l = g_slist_next (l))
- {
- g_ptr_array_add (tmp, l->data);
+ paths = seed_importer_get_search_path(ctx, NULL);
+ for (l = paths; l != NULL; l = g_slist_next(l)) {
+ g_ptr_array_add(tmp, l->data);
}
- g_ptr_array_add (tmp, search_path);
- g_ptr_array_add (tmp, NULL);
+ g_ptr_array_add(tmp, search_path);
+ g_ptr_array_add(tmp, NULL);
- seed_importer_set_search_path (ctx, (gchar **) tmp->pdata);
+ seed_importer_set_search_path(ctx, (gchar**) tmp->pdata);
- g_ptr_array_unref (tmp);
- seed_importer_free_search_path (paths);
+ g_ptr_array_unref(tmp);
+ seed_importer_free_search_path(paths);
}
JSClassDefinition importer_class_def = {
- 0, /* Version, always 0 */
- 0,
- "importer", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL, /* Initialize */
- NULL, /* Finalize */
- NULL, /* Has Property */
- seed_importer_get_property, /* 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 */
+ 0, /* Version, always 0 */
+ 0,
+ "importer", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, /* Initialize */
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ seed_importer_get_property, /* 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 */
};
JSClassDefinition gi_importer_class_def = {
- 0, /* Version, always 0 */
- 0,
- "gi_importer", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL, /* Initialize */
- NULL, /* Finalize */
- NULL, /* Has Property */
- seed_gi_importer_get_property, /* 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 */
+ 0, /* Version, always 0 */
+ 0,
+ "gi_importer", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, /* Initialize */
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ seed_gi_importer_get_property, /* 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 */
};
JSClassDefinition importer_dir_class_def = {
- 0, /* Version, always 0 */
- 0,
- "importer_dir", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL, /* Initialize */
- seed_importer_dir_finalize, /* Finalize */
- NULL, /* Has Property */
- seed_importer_dir_get_property, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- seed_importer_dir_enumerate_properties, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "importer_dir", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, /* Initialize */
+ seed_importer_dir_finalize, /* Finalize */
+ NULL, /* Has Property */
+ seed_importer_dir_get_property, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ seed_importer_dir_enumerate_properties, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
+extern GResource* libseed_get_resource(void);
+
void
-seed_initialize_importer (JSContextRef ctx, JSObjectRef global)
+seed_initialize_importer(JSContextRef ctx, JSObjectRef global)
{
- JSObjectRef dir_constructor;
+ JSObjectRef dir_constructor;
- importer_class = JSClassCreate (&importer_class_def);
- importer = JSObjectMake (ctx, importer_class, NULL);
+ importer_class = JSClassCreate(&importer_class_def);
+ importer = JSObjectMake(ctx, importer_class, NULL);
- gi_importer_class = JSClassCreate (&gi_importer_class_def);
- gi_importer = JSObjectMake (ctx, gi_importer_class, NULL);
- gi_importer_versions = JSObjectMake (ctx, NULL, NULL);
+ gi_importer_class = JSClassCreate(&gi_importer_class_def);
+ gi_importer = JSObjectMake(ctx, gi_importer_class, NULL);
+ gi_importer_versions = JSObjectMake(ctx, NULL, NULL);
- JSValueProtect (ctx, gi_importer);
- JSValueProtect (ctx, gi_importer_versions);
+ JSValueProtect(ctx, gi_importer);
+ JSValueProtect(ctx, gi_importer_versions);
- importer_dir_class = JSClassCreate (&importer_dir_class_def);
+ importer_dir_class = JSClassCreate(&importer_dir_class_def);
- gi_imports = g_hash_table_new (g_str_hash, g_str_equal);
- file_imports = g_hash_table_new (g_str_hash, g_str_equal);
+ gi_imports = g_hash_table_new(g_str_hash, g_str_equal);
+ file_imports = g_hash_table_new(g_str_hash, g_str_equal);
- /* Passing nonnull for class requires a webkit fix that most people wont have yet. It also has minimal benefit */
- // dir_constructor = JSObjectMakeConstructor (ctx, importer_dir_class, seed_importer_construct_dir);
- dir_constructor =
- JSObjectMakeConstructor (ctx, NULL, seed_importer_construct_dir);
- seed_object_set_property (ctx, importer, "Directory", dir_constructor);
+ /* Passing nonnull for class requires a webkit fix that most people wont
+ * have yet. It also has minimal benefit */
+ // dir_constructor = JSObjectMakeConstructor (ctx, importer_dir_class,
+ // seed_importer_construct_dir);
+ dir_constructor
+ = JSObjectMakeConstructor(ctx, NULL, seed_importer_construct_dir);
+ seed_object_set_property(ctx, importer, "Directory", dir_constructor);
- seed_object_set_property (ctx, global, "imports", importer);
+ seed_object_set_property(ctx, global, "imports", importer);
}
diff --git a/libseed/seed-importer.h b/libseed/seed-importer.h
index 8fb2e7a..9aa2309 100644
--- a/libseed/seed-importer.h
+++ b/libseed/seed-importer.h
@@ -24,8 +24,14 @@
extern JSObjectRef importer;
-void seed_initialize_importer (JSContextRef ctx, JSObjectRef global);
-JSObjectRef seed_gi_importer_do_namespace (JSContextRef ctx,
- gchar * namespace, JSValueRef * exception);
+void seed_initialize_importer(JSContextRef ctx, JSObjectRef global);
+JSObjectRef seed_gi_importer_do_namespace(JSContextRef ctx,
+ gchar* namespace,
+ JSValueRef* exception);
+
+gboolean seed_importer_get_file_contents(const gchar* filename,
+ gchar** contents,
+ gsize* length,
+ GError** error);
#endif
diff --git a/libseed/seed-module.h b/libseed/seed-module.h
index e8b7fd6..e704fb6 100644
--- a/libseed/seed-module.h
+++ b/libseed/seed-module.h
@@ -43,14 +43,13 @@
*
*/
-#define CHECK_ARG_COUNT(name, argnum) \
- if ( argument_count != argnum ) \
- { \
- seed_make_exception (ctx, exception, "ArgumentError", \
- "wrong number of arguments; expected %s, got %Zd", \
- #argnum, argument_count); \
- return seed_make_undefined (ctx); \
- }
+#define CHECK_ARG_COUNT(name, argnum) \
+ if (argument_count != argnum) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "wrong number of arguments; expected %s, got %zd", \
+ #argnum, argument_count); \
+ return seed_make_undefined(ctx); \
+ }
/**
* DEFINE_ENUM_MEMBER:
@@ -64,9 +63,9 @@
* &num;defines as well.
*
*/
-#define DEFINE_ENUM_MEMBER(holder, member) \
- seed_object_set_property(ctx, holder, #member, \
- seed_value_from_long(ctx, member, NULL))
+#define DEFINE_ENUM_MEMBER(holder, member) \
+ seed_object_set_property(ctx, holder, #member, \
+ seed_value_from_long(ctx, member, NULL))
/**
* DEFINE_ENUM_MEMBER_EXT:
@@ -85,8 +84,8 @@
* </programlisting>
*
*/
-#define DEFINE_ENUM_MEMBER_EXT(holder, name, val) \
- seed_object_set_property(ctx, holder, name, \
- seed_value_from_long(ctx, val, NULL))
+#define DEFINE_ENUM_MEMBER_EXT(holder, name, val) \
+ seed_object_set_property(ctx, holder, name, \
+ seed_value_from_long(ctx, val, NULL))
#endif
diff --git a/libseed/seed-path.h b/libseed/seed-path.h
index 73bb65c..876a5c7 100644
--- a/libseed/seed-path.h
+++ b/libseed/seed-path.h
@@ -1 +1 @@
-#define SEED_PREFIX_PATH "/usr/local""/share/seed-gtk3/"
+#define SEED_PREFIX_PATH "/home/danilo/webkitinstall""/share/seed-gtk4/"
diff --git a/libseed/seed-private.h b/libseed/seed-private.h
index c60ac38..880a6c6 100644
--- a/libseed/seed-private.h
+++ b/libseed/seed-private.h
@@ -36,11 +36,12 @@ typedef struct _SeedEngine SeedEngine;
struct _SeedEngine
{
- JSGlobalContextRef context;
- JSObjectRef global;
- gchar **search_path;
+ JSGlobalContextRef context;
+ JSObjectRef global;
+ gchar** search_path;
- JSContextGroupRef group;
+ JSContextGroupRef group;
+ gchar* program_name;
};
#include "seed-debug.h"
diff --git a/libseed/seed-signals.c b/libseed/seed-signals.c
index f1bbddc..4e31275 100644
--- a/libseed/seed-signals.c
+++ b/libseed/seed-signals.c
@@ -22,444 +22,420 @@
typedef struct _signal_privates
{
- GObject *object;
- gchar *signal_name;
+ GObject* object;
+ gchar* signal_name;
} signal_privates;
JSClassRef signal_holder_class;
static void
-seed_signal_finalize (JSObjectRef object)
+seed_signal_finalize(JSObjectRef object)
{
- signal_privates *sig_priv = JSObjectGetPrivate (object);
+ signal_privates* sig_priv = JSObjectGetPrivate(object);
- g_free (sig_priv->signal_name);
- g_slice_free1 (sizeof (signal_privates), sig_priv);
+ g_free(sig_priv->signal_name);
+ g_slice_free1(sizeof(signal_privates), sig_priv);
}
-
gulong
-seed_gobject_signal_connect (JSContextRef ctx,
- const gchar * signal_name,
- GObject * on_obj,
- JSObjectRef func,
- JSObjectRef this_obj, JSObjectRef user_data)
+seed_gobject_signal_connect(JSContextRef ctx,
+ const gchar* signal_name,
+ GObject* on_obj,
+ JSObjectRef func,
+ JSObjectRef this_obj,
+ JSObjectRef user_data)
{
- GSignalQuery query;
- GClosure *closure;
+ GSignalQuery query;
+ GClosure* closure;
- if (g_str_has_prefix (signal_name, "notify::"))
- g_signal_query (g_signal_lookup ("notify", G_OBJECT_TYPE (on_obj)),
- &query);
- else
- g_signal_query (g_signal_lookup (signal_name, G_OBJECT_TYPE (on_obj)),
- &query);
+ if (g_str_has_prefix(signal_name, "notify::"))
+ g_signal_query(g_signal_lookup("notify", G_OBJECT_TYPE(on_obj)),
+ &query);
+ else
+ g_signal_query(g_signal_lookup(signal_name, G_OBJECT_TYPE(on_obj)),
+ &query);
#ifdef SEED_ENABLE_DEBUG
- {
- guint function_arity = seed_value_to_uint (ctx,
- seed_object_get_property (ctx,
- func,
- "length"),
- NULL);
- if (function_arity != query.n_params)
- {
- SEED_MARK ();
- SEED_NOTE (SIGNAL,
- "Connecting signal: %s. Function has arity %d, signal expects %d",
- query.signal_name, function_arity, query.n_params);
- SEED_MARK ();
- }
- }
+ {
+ guint function_arity
+ = seed_value_to_uint(ctx,
+ seed_object_get_property(ctx, func, "length"),
+ NULL);
+ if (function_arity != query.n_params) {
+ SEED_MARK();
+ SEED_NOTE(
+ SIGNAL,
+ "Connecting signal: %s. Function has arity %d, signal expects %d",
+ query.signal_name, function_arity, query.n_params);
+ SEED_MARK();
+ }
+ }
#endif
- closure = seed_closure_new_for_signal (ctx, func, user_data, "signal handler", query.signal_id);
+ closure = seed_closure_new_for_signal(ctx, func, user_data,
+ "signal handler", query.signal_id);
- // This seems wrong...
- ((SeedClosure *) closure)->return_type = query.return_type;
- return g_signal_connect_closure (on_obj, signal_name, closure, FALSE);
+ // This seems wrong...
+ ((SeedClosure*) closure)->return_type = query.return_type;
+ return g_signal_connect_closure(on_obj, signal_name, closure, FALSE);
}
-static JSValueRef
-seed_gobject_signal_connect_by_name (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+JSValueRef
+seed_gobject_signal_connect_by_name(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GType obj_type;
- JSObjectRef user_data = NULL;
- gchar *signal_name;
- GObject *obj;
- gulong id;
-
- if (argumentCount < 2 || argumentCount > 3)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection expected"
- " 2 or 3 arguments. Got " "%zd", argumentCount);
-
- return JSValueMakeNull (ctx);
+ JSObjectRef user_data = NULL;
+ gchar* signal_name;
+ GObject* obj;
+ gulong id;
+
+ if (argumentCount < 2 || argumentCount > 3) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection expected"
+ " 2 or 3 arguments. Got "
+ "%zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[1]) ||
- !JSValueIsObject (ctx, arguments[1]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[1]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection by name "
- "requires a function" " as second argument");
- return JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[1]) || !JSValueIsObject(ctx, arguments[1])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[1])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection by name "
+ "requires a function"
+ " as second argument");
+ return JSValueMakeNull(ctx);
}
- if (argumentCount == 3)
- {
- user_data = (JSObjectRef) arguments[2];
+ if (argumentCount == 3) {
+ user_data = (JSObjectRef) arguments[2];
}
- signal_name = seed_value_to_string (ctx, arguments[0], exception);
- obj = (GObject *) JSObjectGetPrivate (thisObject);
- obj_type = G_OBJECT_TYPE (obj);
+ signal_name = seed_value_to_string(ctx, arguments[0], exception);
+ obj = (GObject*) JSObjectGetPrivate(thisObject);
- id = seed_gobject_signal_connect (ctx, signal_name, obj,
- (JSObjectRef) arguments[1], NULL,
- user_data);
+ id = seed_gobject_signal_connect(ctx, signal_name, obj,
+ (JSObjectRef) arguments[1], NULL,
+ user_data);
- g_free (signal_name);
+ g_free(signal_name);
- return seed_value_from_ulong (ctx, id, exception);
+ return seed_value_from_ulong(ctx, id, exception);
}
void
-seed_add_signals_to_object (JSContextRef ctx,
- JSObjectRef object_ref, GObject * obj)
+seed_add_signals_to_object(JSContextRef ctx,
+ JSObjectRef object_ref,
+ GObject* obj)
{
- GType type;
- JSObjectRef signals_ref;
+ g_assert(obj);
- g_assert (obj);
+ JSObjectRef signals_ref;
- type = G_OBJECT_TYPE (obj);
+ signals_ref = JSObjectMake(ctx, signal_holder_class, obj);
- signals_ref = JSObjectMake (ctx, signal_holder_class, obj);
-
- seed_object_set_property (ctx, object_ref, "signal", signals_ref);
+ seed_object_set_property(ctx, object_ref, "signal", signals_ref);
}
void
-seed_signal_marshal_func (GClosure * closure,
- GValue * return_value,
- guint n_param_values,
- const GValue * param_values,
- gpointer invocation_hint, gpointer marshal_data)
+seed_signal_marshal_func(GClosure* closure,
+ GValue* return_value,
+ guint n_param_values,
+ const GValue* param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data)
{
- SeedClosure *seed_closure = (SeedClosure *) closure;
- JSValueRef *args, exception = 0;
- JSValueRef ret = 0;
- guint i;
- gchar *mes;
- GSignalQuery signal_query = { 0, };
-
- if (marshal_data)
- {
- /* Inspired from gjs/gi/value.c:closure_marshal() */
- /* we are used for a signal handler */
- guint signal_id;
-
- signal_id = GPOINTER_TO_UINT(marshal_data);
-
- g_signal_query(signal_id, &signal_query);
-
- if (!signal_query.signal_id)
- g_error("Signal handler being called on invalid signal");
-
- if (signal_query.n_params + 1 != n_param_values)
- g_error("Signal handler being called with wrong number of parameters");
- }
-
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group,
- 0);
+ SeedClosure* seed_closure = (SeedClosure*) closure;
+ JSValueRef *args, exception = 0;
+ JSValueRef ret = 0;
+ guint i;
+ gchar* mes;
+ GSignalQuery signal_query = {
+ 0,
+ };
+
+ if (marshal_data) {
+ /* Inspired from gjs/gi/value.c:closure_marshal() */
+ /* we are used for a signal handler */
+ guint signal_id;
+
+ signal_id = GPOINTER_TO_UINT(marshal_data);
+
+ g_signal_query(signal_id, &signal_query);
+
+ if (!signal_query.signal_id)
+ g_error("Signal handler being called on invalid signal");
+
+ if (signal_query.n_params + 1 != n_param_values)
+ g_error(
+ "Signal handler being called with wrong number of parameters");
+ }
- seed_prepare_global_context (ctx);
- SEED_NOTE (INVOCATION, "Signal Marshal: ");
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
- args = g_newa (JSValueRef, n_param_values + 1);
+ seed_prepare_global_context(ctx);
+ SEED_NOTE(INVOCATION, "Signal Marshal: ");
- for (i = 0; i < n_param_values; i++)
- {
- args[i] = seed_value_from_gvalue_for_signal (ctx,
- (GValue *) & param_values[i], 0, &signal_query, i);
+ args = g_newa(JSValueRef, n_param_values + 1);
- if (!args[i])
- g_error ("Error in signal marshal. "
- "Unable to convert argument of type: %s \n",
- g_type_name (param_values[i].g_type));
+ for (i = 0; i < n_param_values; i++) {
+ args[i]
+ = seed_value_from_gvalue_for_signal(ctx, (GValue*) &param_values[i],
+ 0, &signal_query, i);
+ if (!args[i])
+ g_error("Error in signal marshal. "
+ "Unable to convert argument of type: %s \n",
+ g_type_name(param_values[i].g_type));
}
- if (seed_closure->user_data)
- args[i] = seed_closure->user_data;
- else
- args[i] = JSValueMakeNull (ctx);
+ if (seed_closure->user_data)
+ args[i] = seed_closure->user_data;
+ else
+ args[i] = JSValueMakeNull(ctx);
- ret = JSObjectCallAsFunction (ctx, seed_closure->function,
- NULL, n_param_values + 1, args, &exception);
+ ret = JSObjectCallAsFunction(ctx, seed_closure->function, NULL,
+ n_param_values + 1, args, &exception);
- if (exception)
- {
- seed_closure_warn_exception (closure, ctx, exception);
- exception = NULL;
+ if (exception) {
+ seed_closure_warn_exception(closure, ctx, exception);
+ exception = NULL;
}
- if (ret && !JSValueIsNull (ctx, ret)
- && (seed_closure->return_type != G_TYPE_NONE))
- {
- seed_value_to_gvalue (ctx, ret, seed_closure->return_type,
- return_value, &exception);
+ if (ret && !JSValueIsNull(ctx, ret)
+ && (seed_closure->return_type != G_TYPE_NONE)) {
+ seed_value_to_gvalue(ctx, ret, seed_closure->return_type, return_value,
+ &exception);
}
- if (exception)
- {
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in signal handler return value. %s \n", mes);
- g_free (mes);
+ if (exception) {
+ mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in signal handler return value. %s \n", mes);
+ g_free(mes);
}
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
- JSGarbageCollect(ctx);
-
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
+ JSGarbageCollect(ctx);
}
static JSValueRef
-seed_gobject_signal_emit (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_emit(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSValueRef ret;
- GValue *params;
- GValue ret_value = { 0 };
- GSignalQuery query;
+ JSValueRef ret;
+ GValue* params;
+ GValue ret_value = { 0 };
+ GSignalQuery query;
- signal_privates *privates;
- guint i, signal_id;
+ signal_privates* privates;
+ guint i, signal_id;
- privates = JSObjectGetPrivate (thisObject);
+ privates = JSObjectGetPrivate(thisObject);
- signal_id = g_signal_lookup (privates->signal_name,
- G_OBJECT_TYPE (privates->object));
+ signal_id
+ = g_signal_lookup(privates->signal_name, G_OBJECT_TYPE(privates->object));
- g_signal_query (signal_id, &query);
+ g_signal_query(signal_id, &query);
- if (argumentCount != query.n_params)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal: %s for type %s expected %u "
- "arguments, got %zd",
- query.signal_name,
- g_type_name (query.itype),
- query.n_params, argumentCount);
-
- return JSValueMakeNull (ctx);
- }
+ if (argumentCount != query.n_params) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal: %s for type %s expected %u "
+ "arguments, got %zd",
+ query.signal_name, g_type_name(query.itype),
+ query.n_params, argumentCount);
- params = g_new0 (GValue, argumentCount + 1);
+ return JSValueMakeNull(ctx);
+ }
- g_value_init (&params[0], G_TYPE_OBJECT);
- g_value_set_object (&params[0], privates->object);
- for (i = 0; i < argumentCount; i++)
- seed_value_to_gvalue (ctx, arguments[i],
- query.param_types[i],
- &params[i + 1], exception);
+ params = g_new0(GValue, argumentCount + 1);
+ g_value_init(&params[0], G_TYPE_OBJECT);
+ g_value_set_object(&params[0], privates->object);
+ for (i = 0; i < argumentCount; i++)
+ seed_value_to_gvalue(ctx, arguments[i], query.param_types[i],
+ &params[i + 1], exception);
- if (query.return_type != G_TYPE_NONE)
- g_value_init (&ret_value, query.return_type);
- g_signal_emitv (params, signal_id, 0, &ret_value);
+ if (query.return_type != G_TYPE_NONE)
+ g_value_init(&ret_value, query.return_type);
+ g_signal_emitv(params, signal_id, 0, &ret_value);
- for (i = 0; i < argumentCount; i++)
- g_value_unset (&params[i]);
- g_free (params);
+ for (i = 0; i < argumentCount; i++)
+ g_value_unset(&params[i]);
+ g_free(params);
- ret = seed_value_from_gvalue (ctx, &ret_value, exception);
+ ret = seed_value_from_gvalue(ctx, &ret_value, exception);
- if (query.return_type != G_TYPE_NONE)
- g_value_unset (&ret_value);
+ if (query.return_type != G_TYPE_NONE)
+ g_value_unset(&ret_value);
- return ret;
+ return ret;
}
static JSValueRef
-seed_gobject_signal_disconnect (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_disconnect(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gulong id;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal disconnection expects 1 argument"
- " got %zd", argumentCount);
- return JSValueMakeUndefined (ctx);
+ gulong id;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal disconnection expects 1 argument"
+ " got %zd",
+ argumentCount);
+ return JSValueMakeUndefined(ctx);
}
- id = seed_value_to_ulong (ctx, arguments[0], exception);
- g_signal_handler_disconnect (JSObjectGetPrivate (thisObject), id);
+ id = seed_value_to_ulong(ctx, arguments[0], exception);
+ g_signal_handler_disconnect(JSObjectGetPrivate(thisObject), id);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_gobject_signal_connect_on_property (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_connect_on_property(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gulong id = 0;
- JSObjectRef this_obj;
- signal_privates *privates;
-
- privates = (signal_privates *) JSObjectGetPrivate (thisObject);
- if (!privates)
- g_error ("Signal constructed with invalid parameters"
- "in namespace import \n");
-
- this_obj =
- (JSObjectRef) seed_value_from_object (ctx, privates->object, exception);
-
- if ((argumentCount > 2) || (argumentCount == 0))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection expected"
- " 1, or 2 arguments. Got " "%zd", argumentCount);
-
- return JSValueMakeNull (ctx);
+ gulong id = 0;
+ JSObjectRef this_obj;
+ signal_privates* privates;
+
+ privates = (signal_privates*) JSObjectGetPrivate(thisObject);
+ if (!privates)
+ g_error("Signal constructed with invalid parameters"
+ "in namespace import \n");
+
+ this_obj
+ = (JSObjectRef) seed_value_from_object(ctx, privates->object, exception);
+
+ if ((argumentCount > 2) || (argumentCount == 0)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection expected"
+ " 1, or 2 arguments. Got "
+ "%zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[0]) ||
- !JSValueIsObject (ctx, arguments[0]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection requires a function"
- " as first argument");
- return JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[0]) || !JSValueIsObject(ctx, arguments[0])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection requires a function"
+ " as first argument");
+ return JSValueMakeNull(ctx);
}
- if (argumentCount == 1)
- {
- id = seed_gobject_signal_connect (ctx, privates->signal_name,
- privates->object,
- (JSObjectRef) arguments[0], this_obj,
- NULL);
-
- }
- else if (argumentCount == 2)
- {
- id = seed_gobject_signal_connect (ctx, privates->signal_name,
- privates->object,
- (JSObjectRef) arguments[0],
- this_obj, (JSObjectRef) arguments[1]);
+ if (argumentCount == 1) {
+ id = seed_gobject_signal_connect(ctx, privates->signal_name,
+ privates->object,
+ (JSObjectRef) arguments[0], this_obj,
+ NULL);
+
+ } else if (argumentCount == 2) {
+ id = seed_gobject_signal_connect(ctx, privates->signal_name,
+ privates->object,
+ (JSObjectRef) arguments[0], this_obj,
+ (JSObjectRef) arguments[1]);
}
- return seed_value_from_ulong (ctx, id, exception);
+ return seed_value_from_ulong(ctx, id, exception);
}
-JSStaticFunction signal_static_functions[] = {
- {"connect", seed_gobject_signal_connect_on_property, 0}
- ,
- {"emit", seed_gobject_signal_emit, 0}
- ,
- {0, 0, 0}
-};
+JSStaticFunction signal_static_functions[]
+ = { { "connect", seed_gobject_signal_connect_on_property, 0 },
+ { "emit", seed_gobject_signal_emit, 0 },
+ { 0, 0, 0 } };
-JSStaticFunction signal_holder_static_functions[] = {
- {"connect", seed_gobject_signal_connect_by_name, 0}
- ,
- {"disconnect", seed_gobject_signal_disconnect, 0}
- ,
- {0, 0, 0}
-};
+JSStaticFunction signal_holder_static_functions[]
+ = { { "connect", seed_gobject_signal_connect_by_name, 0 },
+ { "disconnect", seed_gobject_signal_disconnect, 0 },
+ { 0, 0, 0 } };
JSClassDefinition gobject_signal_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "gobject_signal", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- signal_static_functions, /* Static Functions */
- NULL,
- seed_signal_finalize, /* 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 */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "gobject_signal", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ signal_static_functions, /* Static Functions */
+ NULL,
+ seed_signal_finalize, /* 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 */
};
static JSValueRef
-seed_signal_holder_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef * exception)
+seed_signal_holder_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- GObject *gobj = JSObjectGetPrivate (object);
- signal_privates *priv;
- guint length = JSStringGetMaximumUTF8CStringSize (property_name);
- gchar *signal_name = g_malloc (length * sizeof (gchar));
- JSObjectRef signal_ref;
-
- JSStringGetUTF8CString (property_name, signal_name, length);
-
- if (!
- (g_strcmp0 (signal_name, "connect")
- && g_strcmp0 (signal_name, "disconnect")))
- {
- g_free (signal_name);
- return NULL;
+ GObject* gobj = JSObjectGetPrivate(object);
+ signal_privates* priv;
+ guint length = JSStringGetMaximumUTF8CStringSize(property_name);
+ gchar* signal_name = g_malloc(length * sizeof(gchar));
+ JSObjectRef signal_ref;
+
+ JSStringGetUTF8CString(property_name, signal_name, length);
+
+ if (!(g_strcmp0(signal_name, "connect")
+ && g_strcmp0(signal_name, "disconnect"))) {
+ g_free(signal_name);
+ return NULL;
}
- if (!g_str_has_prefix (signal_name, "notify::") &&
- !g_signal_lookup (signal_name, G_OBJECT_TYPE (gobj)))
- {
- seed_make_exception (ctx, exception, "InvalidSignalName",
- "Failed to connect to %s. "
- "Invalid signal name.", signal_name);
- g_free (signal_name);
- return NULL;
+ if (!g_str_has_prefix(signal_name, "notify::")
+ && !g_signal_lookup(signal_name, G_OBJECT_TYPE(gobj))) {
+ seed_make_exception(ctx, exception, "InvalidSignalName",
+ "Failed to connect to %s. "
+ "Invalid signal name.",
+ signal_name);
+ g_free(signal_name);
+ return NULL;
}
- priv = g_slice_alloc (sizeof (signal_privates));
+ priv = g_slice_alloc(sizeof(signal_privates));
- priv->object = gobj;
- priv->signal_name = signal_name;
+ priv->object = gobj;
+ priv->signal_name = signal_name;
- signal_ref = JSObjectMake (ctx, gobject_signal_class, priv);
+ signal_ref = JSObjectMake(ctx, gobject_signal_class, priv);
- return signal_ref;
+ return signal_ref;
}
-JSClassDefinition *
-seed_get_signal_class (void)
+JSClassDefinition*
+seed_get_signal_class(void)
{
- JSClassDefinition signal_holder = kJSClassDefinitionEmpty;
+ JSClassDefinition signal_holder = kJSClassDefinitionEmpty;
- signal_holder.className = "gobject_signals";
- signal_holder.getProperty = seed_signal_holder_get_property;
- signal_holder.staticFunctions = signal_holder_static_functions;
- signal_holder_class = JSClassCreate (&signal_holder);
- JSClassRetain (signal_holder_class);
+ signal_holder.className = "gobject_signals";
+ signal_holder.getProperty = seed_signal_holder_get_property;
+ signal_holder.staticFunctions = signal_holder_static_functions;
+ signal_holder_class = JSClassCreate(&signal_holder);
+ JSClassRetain(signal_holder_class);
- return &gobject_signal_def;
+ return &gobject_signal_def;
}
diff --git a/libseed/seed-signals.h b/libseed/seed-signals.h
index ab7eaea..1ce4e04 100644
--- a/libseed/seed-signals.h
+++ b/libseed/seed-signals.h
@@ -22,25 +22,32 @@
#include "seed-private.h"
-void seed_signal_marshal_func (GClosure * closure,
- GValue * return_value,
- guint n_param_values,
- const GValue * param_values,
- gpointer invocation_hint,
- gpointer marshall_data);
-
-void seed_add_signals_to_object (JSContextRef ctx,
- JSObjectRef object_ref, GObject * obj);
-
-gulong seed_gobject_signal_connect (JSContextRef ctx,
- const gchar * signal_name,
- GObject * on_obj,
- JSObjectRef func,
- JSObjectRef this_obj,
- JSObjectRef user_data);
-
-
-JSClassDefinition *seed_get_signal_class (void);
+void seed_signal_marshal_func(GClosure* closure,
+ GValue* return_value,
+ guint n_param_values,
+ const GValue* param_values,
+ gpointer invocation_hint,
+ gpointer marshall_data);
+
+void seed_add_signals_to_object(JSContextRef ctx,
+ JSObjectRef object_ref,
+ GObject* obj);
+
+gulong seed_gobject_signal_connect(JSContextRef ctx,
+ const gchar* signal_name,
+ GObject* on_obj,
+ JSObjectRef func,
+ JSObjectRef this_obj,
+ JSObjectRef user_data);
+
+JSValueRef seed_gobject_signal_connect_by_name(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
+JSClassDefinition* seed_get_signal_class(void);
extern JSClassRef gobject_signal_class;
#endif
diff --git a/libseed/seed-structs.c b/libseed/seed-structs.c
index 793e754..0982e36 100644
--- a/libseed/seed-structs.c
+++ b/libseed/seed-structs.c
@@ -25,781 +25,752 @@ JSClassRef seed_boxed_class = 0;
typedef struct _seed_struct_privates
{
- gpointer pointer;
- GIBaseInfo *info;
+ gpointer pointer;
+ GIBaseInfo* info;
- gboolean free_pointer;
- gboolean slice_alloc;
- gsize size;
+ gboolean free_pointer;
+ gboolean slice_alloc;
+ gsize size;
} seed_struct_privates;
-GHashTable *struct_prototype_hash = NULL;
-GHashTable *union_prototype_hash = NULL;
+GHashTable* struct_prototype_hash = NULL;
+GHashTable* union_prototype_hash = NULL;
static void
-seed_pointer_finalize (JSObjectRef object)
+seed_pointer_finalize(JSObjectRef object)
{
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
-
- SEED_NOTE (STRUCTS, "Finalizing seed_pointer object %p. with "
- "priv->free_pointer = %d with type: %s, size: %zu",
- priv->pointer,
- priv->free_pointer,
- priv->info ? g_base_info_get_name (priv->info) : "[generic]",
- priv->size);
-
- if (priv->free_pointer)
- {
- if (priv->slice_alloc)
- g_slice_free1 (priv->size, priv->pointer);
- else
- g_free (priv->pointer);
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+
+ SEED_NOTE(STRUCTS, "Finalizing seed_pointer object %p. with "
+ "priv->free_pointer = %d with type: %s, size: %zu",
+ priv->pointer, priv->free_pointer,
+ priv->info ? g_base_info_get_name(priv->info) : "[generic]",
+ priv->size);
+
+ if (priv->free_pointer) {
+ if (priv->slice_alloc)
+ g_slice_free1(priv->size, priv->pointer);
+ else
+ g_free(priv->pointer);
}
- if (priv->info)
- g_base_info_unref (priv->info);
+ if (priv->info)
+ g_base_info_unref(priv->info);
- g_slice_free1 (sizeof (seed_struct_privates), priv);
+ g_slice_free1(sizeof(seed_struct_privates), priv);
}
static void
-seed_boxed_finalize (JSObjectRef object)
+seed_boxed_finalize(JSObjectRef object)
{
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- GType type;
- GIRegisteredTypeInfo *info =
- (GIRegisteredTypeInfo *) g_base_info_get_type (priv->info);
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ GType type;
+ GIRegisteredTypeInfo* info
+ = (GIRegisteredTypeInfo*) g_base_info_get_type(priv->info);
- SEED_NOTE (STRUCTS, "Finalizing boxed object of type %s \n",
- g_base_info_get_name (priv->info));
+ SEED_NOTE(STRUCTS, "Finalizing boxed object of type %s \n",
+ g_base_info_get_name(priv->info));
- type = g_registered_type_info_get_g_type (info);
- g_base_info_unref ((GIBaseInfo *) info);
-
- g_boxed_free (type, priv->pointer);
+ type = g_registered_type_info_get_g_type(info);
+ g_base_info_unref((GIBaseInfo*) info);
+ g_boxed_free(type, priv->pointer);
}
-GIFieldInfo *
-seed_union_find_field (GIUnionInfo * info, gchar * field_name)
+GIFieldInfo*
+seed_union_find_field(GIUnionInfo* info, gchar* field_name)
{
- gint n, i;
- GIFieldInfo *field;
-
- n = g_union_info_get_n_fields (info);
- for (i = 0; i < n; i++)
- {
- const gchar *name;
-
- field = g_union_info_get_field (info, i);
- name = g_base_info_get_name ((GIBaseInfo *) field);
- if (!g_strcmp0 (name, field_name))
- return field;
- else
- g_base_info_unref ((GIBaseInfo *) field);
+ gint n, i;
+ GIFieldInfo* field;
+
+ n = g_union_info_get_n_fields(info);
+ for (i = 0; i < n; i++) {
+ const gchar* name;
+
+ field = g_union_info_get_field(info, i);
+ name = g_base_info_get_name((GIBaseInfo*) field);
+ if (!g_strcmp0(name, field_name))
+ return field;
+ else
+ g_base_info_unref((GIBaseInfo*) field);
}
- return NULL;
+ return NULL;
}
-GIFieldInfo *
-seed_struct_find_field (GIStructInfo * info, gchar * field_name)
+GIFieldInfo*
+seed_struct_find_field(GIStructInfo* info, gchar* field_name)
{
- gint n, i;
- const gchar *name;
- GIFieldInfo *field;
-
- n = g_struct_info_get_n_fields (info);
- for (i = 0; i < n; i++)
- {
-
- field = g_struct_info_get_field (info, i);
- name = g_base_info_get_name ((GIBaseInfo *) field);
- if (!g_strcmp0 (name, field_name))
- return field;
- else
- g_base_info_unref ((GIBaseInfo *) field);
+ gint n, i;
+ const gchar* name;
+ GIFieldInfo* field;
+
+ n = g_struct_info_get_n_fields(info);
+ for (i = 0; i < n; i++) {
+
+ field = g_struct_info_get_field(info, i);
+ name = g_base_info_get_name((GIBaseInfo*) field);
+ if (!g_strcmp0(name, field_name))
+ return field;
+ else
+ g_base_info_unref((GIBaseInfo*) field);
}
- return NULL;
+ return NULL;
}
JSValueRef
-seed_field_get_value (JSContextRef ctx,
- gpointer object,
- GIFieldInfo * field, JSValueRef * exception)
+seed_field_get_value(JSContextRef ctx,
+ gpointer object,
+ GIFieldInfo* field,
+ JSValueRef* exception)
{
- GITypeInfo *field_type;
- GIBaseInfo *interface;
- GArgument field_value;
- JSValueRef ret = JSValueMakeNull (ctx);
- gint offset;
-
- field_type = g_field_info_get_type (field);
- if (!g_field_info_get_field (field, object, &field_value))
- {
- GITypeTag tag;
-
- tag = g_type_info_get_tag (field_type);
- if (tag == GI_TYPE_TAG_INTERFACE)
- {
- interface = g_type_info_get_interface (field_type);
- offset = g_field_info_get_offset (field);
-
- g_base_info_unref ((GIBaseInfo *) field_type);
- switch (g_base_info_get_type (interface))
- {
- case GI_INFO_TYPE_STRUCT:
- ret = seed_make_struct (ctx, (object + offset), interface);
- break;
- case GI_INFO_TYPE_UNION:
- ret = seed_make_union (ctx, (object + offset), interface);
- break;
- case GI_INFO_TYPE_BOXED:
- ret = seed_make_boxed (ctx, (object + offset), interface);
- break;
- default:
- break;
- }
- g_base_info_unref (interface);
-
- return ret;
- }
-
- return JSValueMakeNull (ctx);
+ GITypeInfo* field_type;
+ GIBaseInfo* interface;
+ GArgument field_value;
+ JSValueRef ret = JSValueMakeNull(ctx);
+ gint offset;
+
+ field_type = g_field_info_get_type(field);
+ if (!g_field_info_get_field(field, object, &field_value)) {
+ GITypeTag tag;
+
+ tag = g_type_info_get_tag(field_type);
+ if (tag == GI_TYPE_TAG_INTERFACE) {
+ interface = g_type_info_get_interface(field_type);
+ offset = g_field_info_get_offset(field);
+
+ g_base_info_unref((GIBaseInfo*) field_type);
+ switch (g_base_info_get_type(interface)) {
+ case GI_INFO_TYPE_STRUCT:
+ ret = seed_make_struct(ctx, (object + offset), interface);
+ break;
+ case GI_INFO_TYPE_UNION:
+ ret = seed_make_union(ctx, (object + offset), interface);
+ break;
+ case GI_INFO_TYPE_BOXED:
+ ret = seed_make_boxed(ctx, (object + offset), interface);
+ break;
+ default:
+ break;
+ }
+ g_base_info_unref(interface);
+
+ return ret;
+ }
+
+ return JSValueMakeNull(ctx);
}
- // Maybe need to release argument.
- ret = seed_value_from_gi_argument (ctx, &field_value, field_type, exception);
- if (field_type)
- g_base_info_unref ((GIBaseInfo *) field_type);
- return ret;
+ // Maybe need to release argument.
+ ret = seed_value_from_gi_argument(ctx, &field_value, field_type, exception);
+ if (field_type)
+ g_base_info_unref((GIBaseInfo*) field_type);
+ return ret;
}
static JSValueRef
-seed_union_get_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_union_get_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- gchar *cproperty_name;
- gsize length;
- seed_struct_privates *priv = JSObjectGetPrivate (object);
- GIFieldInfo *field = 0;
- JSValueRef ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Getting property on union of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- field = seed_union_find_field ((GIUnionInfo *) priv->info, cproperty_name);
- if (!field)
- {
- return 0;
+ gchar* cproperty_name;
+ gsize length;
+ seed_struct_privates* priv = JSObjectGetPrivate(object);
+ GIFieldInfo* field = 0;
+ JSValueRef ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Getting property on union of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ field = seed_union_find_field((GIUnionInfo*) priv->info, cproperty_name);
+ if (!field) {
+ return 0;
}
- ret = seed_field_get_value (context, priv->pointer, field, exception);
+ ret = seed_field_get_value(context, priv->pointer, field, exception);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field);
- return ret;
+ return ret;
}
static bool
-seed_union_set_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef value, JSValueRef * exception)
+seed_union_set_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef value,
+ JSValueRef* exception)
{
- gsize length;
- GArgument field_value;
- GIFieldInfo *field;
- gchar *cproperty_name;
- GITypeInfo *field_type;
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- gboolean ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Setting property on union of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- field = seed_union_find_field ((GIUnionInfo *) priv->info, cproperty_name);
-
- if (!field)
- {
- return FALSE;
+ gsize length;
+ GArgument field_value;
+ GIFieldInfo* field;
+ gchar* cproperty_name;
+ GITypeInfo* field_type;
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ gboolean ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Setting property on union of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ field = seed_union_find_field((GIUnionInfo*) priv->info, cproperty_name);
+
+ if (!field) {
+ return FALSE;
}
- field_type = g_field_info_get_type (field);
+ field_type = g_field_info_get_type(field);
+
+ seed_value_to_gi_argument(context, value, field_type, GI_TRANSFER_NOTHING,
+ &field_value, exception);
- seed_value_to_gi_argument (context, value, field_type, &field_value, exception);
- ret = g_field_info_set_field (field, priv->pointer, &field_value);
+ ret = g_field_info_set_field(field, priv->pointer, &field_value);
+ if (!ret)
+ g_warning("Setting property failed on union of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
- g_base_info_unref ((GIBaseInfo *) field_type);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field_type);
+ g_base_info_unref((GIBaseInfo*) field);
- return TRUE;
+ return TRUE;
}
static bool
-seed_struct_set_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef value, JSValueRef * exception)
+seed_struct_set_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef value,
+ JSValueRef* exception)
{
- gsize length;
- GArgument field_value;
- GIFieldInfo *field;
- gchar *cproperty_name;
- GITypeInfo *field_type;
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- gboolean ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Setting property on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- field =
- seed_struct_find_field ((GIStructInfo *) priv->info, cproperty_name);
-
- if (!field)
- {
- return FALSE;
+ gsize length;
+ GArgument field_value;
+ GIFieldInfo* field;
+ gchar* cproperty_name;
+ GITypeInfo* field_type;
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ gboolean ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Setting property on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ field = seed_struct_find_field((GIStructInfo*) priv->info, cproperty_name);
+
+ if (!field) {
+ return FALSE;
}
- field_type = g_field_info_get_type (field);
+ field_type = g_field_info_get_type(field);
+
+ seed_value_to_gi_argument(context, value, field_type, GI_TRANSFER_NOTHING,
+ &field_value, exception);
+ ret = g_field_info_set_field(field, priv->pointer, &field_value);
- seed_value_to_gi_argument (context, value, field_type, &field_value, exception);
- ret = g_field_info_set_field (field, priv->pointer, &field_value);
+ if (!ret)
+ g_warning("Setting property failed on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
- if (!ret)
- g_warning("Setting property failed on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- g_base_info_unref ((GIBaseInfo *) field_type);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field_type);
+ g_base_info_unref((GIBaseInfo*) field);
- return TRUE;
+ return TRUE;
}
static JSValueRef
-seed_struct_get_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_struct_get_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- gchar *cproperty_name;
- gsize length;
- seed_struct_privates *priv = JSObjectGetPrivate (object);
- GIFieldInfo *field = NULL;
- JSValueRef ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Getting property on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- // for a gvalue, it has a special property 'value' (read-only)
- GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) priv->info);
-
- if (g_type_is_a (gtype, G_TYPE_VALUE) && !g_strcmp0 (cproperty_name, "value"))
- {
- return seed_value_from_gvalue ( context, ( GValue *) priv->pointer, exception);
-
+ gchar* cproperty_name;
+ gsize length;
+ seed_struct_privates* priv = JSObjectGetPrivate(object);
+ GIFieldInfo* field = NULL;
+ JSValueRef ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Getting property on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ // for a gvalue, it has a special property 'value' (read-only)
+ GType gtype
+ = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) priv->info);
+
+ if (g_type_is_a(gtype, G_TYPE_VALUE)
+ && !g_strcmp0(cproperty_name, "value")) {
+ return seed_value_from_gvalue(context, (GValue*) priv->pointer,
+ exception);
}
- field =
- seed_struct_find_field ((GIStructInfo *) priv->info, cproperty_name);
+ field = seed_struct_find_field((GIStructInfo*) priv->info, cproperty_name);
- if (!field)
- {
- return NULL;
+ if (!field) {
+ return NULL;
}
- ret = seed_field_get_value (context, priv->pointer, field, exception);
+ ret = seed_field_get_value(context, priv->pointer, field, exception);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field);
- return ret;
+ return ret;
}
static void
-seed_enumerate_structlike_properties (JSContextRef ctx,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef
- propertyNames)
+seed_enumerate_structlike_properties(JSContextRef ctx,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef propertyNames)
{
- GIFieldInfo *field;
- gint i, n;
- guchar type = 0;
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- GIBaseInfo *info = priv->info;
-
- if (!info)
- return;
-
- if (JSValueIsObjectOfClass (ctx, object, seed_struct_class))
- type = 1;
- else if (JSValueIsObjectOfClass (ctx, object, seed_union_class))
- type = 2;
- else
- g_assert_not_reached ();
-
- (type == 1) ?
- (n = g_struct_info_get_n_fields ((GIStructInfo *) info)) :
- (n = g_union_info_get_n_fields ((GIUnionInfo *) info));
-
- for (i = 0; i < n; i++)
- {
- JSStringRef jname;
-
- (type == 1) ?
- (field = g_struct_info_get_field ((GIStructInfo *) info, i)) :
- (field = g_union_info_get_field ((GIUnionInfo *) info, i));
-
- jname =
- JSStringCreateWithUTF8CString (g_base_info_get_name
- ((GIBaseInfo *) field));
-
- g_base_info_unref ((GIBaseInfo *) field);
- JSPropertyNameAccumulatorAddName (propertyNames, jname);
-
- JSStringRelease (jname);
+ GIFieldInfo* field;
+ gint i, n;
+ guchar type = 0;
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ GIBaseInfo* info = priv->info;
+
+ if (!info)
+ return;
+
+ if (JSValueIsObjectOfClass(ctx, object, seed_struct_class))
+ type = 1;
+ else if (JSValueIsObjectOfClass(ctx, object, seed_union_class))
+ type = 2;
+ else
+ g_assert_not_reached();
+
+ (type == 1) ? (n = g_struct_info_get_n_fields((GIStructInfo*) info))
+ : (n = g_union_info_get_n_fields((GIUnionInfo*) info));
+
+ for (i = 0; i < n; i++) {
+ JSStringRef jname;
+
+ (type == 1) ? (field = g_struct_info_get_field((GIStructInfo*) info, i))
+ : (field = g_union_info_get_field((GIUnionInfo*) info, i));
+
+ jname = JSStringCreateWithUTF8CString(
+ g_base_info_get_name((GIBaseInfo*) field));
+
+ g_base_info_unref((GIBaseInfo*) field);
+ JSPropertyNameAccumulatorAddName(propertyNames, jname);
+
+ JSStringRelease(jname);
}
}
JSClassDefinition seed_pointer_def = {
- 0, /* Version, always 0 */
- 0,
- "seed_pointer", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_pointer_finalize,
- NULL, /* Has Property */
- 0,
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL,
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0, "seed_pointer", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, seed_pointer_finalize,
+ NULL, /* Has Property */
+ 0, NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_struct_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "seed_struct", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_struct_get_property,
- seed_struct_set_property, /* Set Property */
- NULL, /* Delete Property */
- seed_enumerate_structlike_properties, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "seed_struct", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_struct_get_property,
+ seed_struct_set_property, /* Set Property */
+ NULL, /* Delete Property */
+ seed_enumerate_structlike_properties, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_union_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "seed_union", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_union_get_property,
- seed_union_set_property, /* Set Property */
- NULL, /* Delete Property */
- seed_enumerate_structlike_properties, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "seed_union", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_union_get_property,
+ seed_union_set_property, /* Set Property */
+ NULL, /* Delete Property */
+ seed_enumerate_structlike_properties, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_boxed_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "seed_boxed", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_boxed_finalize,
- NULL, /* Has Property */
- NULL,
- 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 */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "seed_boxed", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ seed_boxed_finalize,
+ NULL, /* Has Property */
+ NULL,
+ 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 */
};
gpointer
-seed_pointer_get_pointer (JSContextRef ctx, JSValueRef pointer)
+seed_pointer_get_pointer(JSContextRef ctx, JSValueRef pointer)
{
- if (JSValueIsObjectOfClass (ctx, pointer, seed_pointer_class))
- {
- seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
- return priv->pointer;
+ if (JSValueIsObjectOfClass(ctx, pointer, seed_pointer_class)) {
+ seed_struct_privates* priv = JSObjectGetPrivate((JSObjectRef) pointer);
+ return priv->pointer;
}
- return NULL;
+ return NULL;
}
void
-seed_pointer_set_free (JSContextRef ctx,
- JSValueRef pointer, gboolean free_pointer)
+seed_pointer_set_free(JSContextRef ctx,
+ JSValueRef pointer,
+ gboolean free_pointer)
{
- if (JSValueIsObjectOfClass (ctx, pointer, seed_pointer_class))
- {
- seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
- priv->free_pointer = free_pointer;
+ if (JSValueIsObjectOfClass(ctx, pointer, seed_pointer_class)) {
+ seed_struct_privates* priv = JSObjectGetPrivate((JSObjectRef) pointer);
+ priv->free_pointer = free_pointer;
}
}
static void
-seed_pointer_set_slice (JSContextRef ctx,
- JSValueRef pointer, gboolean free_pointer, gsize size)
+seed_pointer_set_slice(JSContextRef ctx,
+ JSValueRef pointer,
+ gboolean free_pointer,
+ gsize size)
{
- seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
- priv->slice_alloc = free_pointer;
- priv->size = size;
+ seed_struct_privates* priv = JSObjectGetPrivate((JSObjectRef) pointer);
+ priv->slice_alloc = free_pointer;
+ priv->size = size;
}
JSObjectRef
-seed_make_pointer (JSContextRef ctx, gpointer pointer)
+seed_make_pointer(JSContextRef ctx, gpointer pointer)
{
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
- priv->pointer = pointer;
- priv->info = 0;
- priv->free_pointer = FALSE;
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
+ priv->pointer = pointer;
+ priv->info = 0;
+ priv->free_pointer = FALSE;
- return JSObjectMake (ctx, seed_pointer_class, priv);
+ return JSObjectMake(ctx, seed_pointer_class, priv);
}
JSObjectRef
-seed_union_prototype (JSContextRef ctx, GIBaseInfo * info)
+seed_union_prototype(JSContextRef ctx, GIBaseInfo* info)
{
- JSObjectRef proto;
- const gchar *namespace, *name;
- gchar *key;
- gint n_methods, i;
- GIFunctionInfo *finfo;
-
- name = g_base_info_get_name (info);
- namespace = g_base_info_get_namespace (info);
- key = g_strjoin (NULL, namespace, name, NULL);
-
- proto = (JSObjectRef) g_hash_table_lookup (union_prototype_hash, key);
-
- if (!proto)
- {
- proto = JSObjectMake (ctx, 0, 0);
- JSValueProtect (eng->context, proto);
-
- n_methods = g_union_info_get_n_methods ((GIUnionInfo *) info);
- for (i = 0; i < n_methods; i++)
- {
- finfo = g_union_info_get_method ((GIUnionInfo *) info, i);
-
- seed_gobject_define_property_from_function_info (ctx,
- (GIFunctionInfo *)
- finfo, proto,
- TRUE);
-
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
-
- g_hash_table_insert (union_prototype_hash, key, proto);
- }
- else
- {
- g_free (key);
+ JSObjectRef proto;
+ const gchar* namespace, *name;
+ gchar* key;
+ gint n_methods, i;
+ GIFunctionInfo* finfo;
+
+ name = g_base_info_get_name(info);
+ namespace = g_base_info_get_namespace(info);
+ key = g_strjoin(NULL, namespace, name, NULL);
+
+ proto = (JSObjectRef) g_hash_table_lookup(union_prototype_hash, key);
+
+ if (!proto) {
+ proto = JSObjectMake(ctx, 0, 0);
+ JSValueProtect(eng->context, proto);
+
+ n_methods = g_union_info_get_n_methods((GIUnionInfo*) info);
+ for (i = 0; i < n_methods; i++) {
+ finfo = g_union_info_get_method((GIUnionInfo*) info, i);
+
+ seed_gobject_define_property_from_function_info(
+ ctx, (GIFunctionInfo*) finfo, proto, TRUE);
+
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
+
+ g_hash_table_insert(union_prototype_hash, key, proto);
+ } else {
+ g_free(key);
}
- return proto;
+ return proto;
}
JSObjectRef
-seed_make_union (JSContextRef ctx, gpointer younion, GIBaseInfo * info)
+seed_make_union(JSContextRef ctx, gpointer younion, GIBaseInfo* info)
{
- JSObjectRef object;
+ JSObjectRef object;
- if (younion == NULL)
- {
- return (JSObjectRef) JSValueMakeNull (ctx);
+ if (younion == NULL) {
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
- priv->pointer = younion;
- priv->info = info ? g_base_info_ref (info) : 0;
- priv->free_pointer = FALSE;
+ priv->pointer = younion;
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->free_pointer = FALSE;
- object = JSObjectMake (ctx, seed_union_class, priv);
+ object = JSObjectMake(ctx, seed_union_class, priv);
- if (info)
- {
- JSObjectRef proto = seed_union_prototype (ctx, info);
- if (proto)
- JSObjectSetPrototype (ctx, object, proto);
- else
- g_assert_not_reached ();
+ if (info) {
+ JSObjectRef proto = seed_union_prototype(ctx, info);
+ if (proto)
+ JSObjectSetPrototype(ctx, object, proto);
+ else
+ g_assert_not_reached();
}
- return object;
+ return object;
}
JSObjectRef
-seed_make_boxed (JSContextRef ctx, gpointer boxed, GIBaseInfo * info)
+seed_make_boxed(JSContextRef ctx, gpointer boxed, GIBaseInfo* info)
{
- JSObjectRef object;
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
+ JSObjectRef object;
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
- priv->info = info ? g_base_info_ref (info) : 0;
- priv->pointer = boxed;
- // Boxed finalize handler handles freeing.
- priv->free_pointer = FALSE;
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->pointer = boxed;
+ // Boxed finalize handler handles freeing.
+ priv->free_pointer = FALSE;
- object = JSObjectMake (ctx, seed_boxed_class, priv);
+ object = JSObjectMake(ctx, seed_boxed_class, priv);
- // FIXME: Instance methods?
+ // FIXME: Instance methods?
- return object;
+ return object;
}
JSObjectRef
-seed_struct_prototype (JSContextRef ctx, GIBaseInfo * info)
+seed_struct_prototype(JSContextRef ctx, GIBaseInfo* info)
{
- JSObjectRef proto;
- const gchar *namespace, *name;
- gchar *key;
- gint n_methods, i;
+ JSObjectRef proto;
+ const gchar* namespace, *name;
+ gchar* key;
+ gint n_methods, i;
- name = g_base_info_get_name (info);
- namespace = g_base_info_get_namespace (info);
- key = g_strjoin (NULL, namespace, name, NULL);
+ name = g_base_info_get_name(info);
+ namespace = g_base_info_get_namespace(info);
+ key = g_strjoin(NULL, namespace, name, NULL);
- proto = (JSObjectRef) g_hash_table_lookup (struct_prototype_hash, key);
+ proto = (JSObjectRef) g_hash_table_lookup(struct_prototype_hash, key);
- if (!proto)
- {
- proto = JSObjectMake (ctx, 0, 0);
- JSValueProtect (eng->context, proto);
+ if (!proto) {
+ proto = JSObjectMake(ctx, 0, 0);
+ JSValueProtect(eng->context, proto);
- n_methods = g_struct_info_get_n_methods ((GIStructInfo *) info);
- for (i = 0; i < n_methods; i++)
- {
- GIFunctionInfo *finfo;
+ n_methods = g_struct_info_get_n_methods((GIStructInfo*) info);
+ for (i = 0; i < n_methods; i++) {
+ GIFunctionInfo* finfo;
- finfo = g_struct_info_get_method ((GIStructInfo *) info, i);
+ finfo = g_struct_info_get_method((GIStructInfo*) info, i);
- seed_gobject_define_property_from_function_info (ctx,
- (GIFunctionInfo *)
- finfo, proto,
- TRUE);
+ seed_gobject_define_property_from_function_info(
+ ctx, (GIFunctionInfo*) finfo, proto, TRUE);
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
- g_hash_table_insert (struct_prototype_hash, key, proto);
- }
- else
- {
- g_free (key);
+ g_hash_table_insert(struct_prototype_hash, key, proto);
+ } else {
+ g_free(key);
}
- return proto;
+ return proto;
}
JSObjectRef
-seed_make_struct (JSContextRef ctx, gpointer strukt, GIBaseInfo * info)
+seed_make_struct(JSContextRef ctx, gpointer strukt, GIBaseInfo* info)
{
- JSObjectRef object, proto;
+ JSObjectRef object, proto;
- if (strukt == NULL)
- {
- return (JSObjectRef) JSValueMakeNull (ctx);
+ if (strukt == NULL) {
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
-
- priv->info = info ? g_base_info_ref (info) : 0;
- priv->pointer = strukt;
- priv->free_pointer = FALSE;
-
- object = JSObjectMake (ctx, seed_struct_class, priv);
- // Examine cases where struct is being used without info.
- if (info)
- {
- proto = seed_struct_prototype (ctx, info);
- if (proto)
- JSObjectSetPrototype (ctx, object, proto);
- else
- g_assert_not_reached ();
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
+
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->pointer = strukt;
+ priv->free_pointer = FALSE;
+
+ object = JSObjectMake(ctx, seed_struct_class, priv);
+ // Examine cases where struct is being used without info.
+ if (info) {
+ proto = seed_struct_prototype(ctx, info);
+ if (proto)
+ JSObjectSetPrototype(ctx, object, proto);
+ else
+ g_assert_not_reached();
}
- return object;
+ return object;
}
void
-seed_structs_init (void)
+seed_structs_init(void)
{
- seed_pointer_class = JSClassCreate (&seed_pointer_def);
- seed_struct_def.parentClass = seed_pointer_class;
- seed_struct_class = JSClassCreate (&seed_struct_def);
- seed_union_def.parentClass = seed_pointer_class;
- seed_union_class = JSClassCreate (&seed_union_def);
- seed_boxed_def.parentClass = seed_struct_class;
- seed_boxed_class = JSClassCreate (&seed_boxed_def);
-
- struct_prototype_hash = g_hash_table_new (g_str_hash, g_str_equal);
- union_prototype_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ seed_pointer_class = JSClassCreate(&seed_pointer_def);
+ seed_struct_def.parentClass = seed_pointer_class;
+ seed_struct_class = JSClassCreate(&seed_struct_def);
+ seed_union_def.parentClass = seed_pointer_class;
+ seed_union_class = JSClassCreate(&seed_union_def);
+ seed_boxed_def.parentClass = seed_struct_class;
+ seed_boxed_class = JSClassCreate(&seed_boxed_def);
+
+ struct_prototype_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ union_prototype_hash = g_hash_table_new(g_str_hash, g_str_equal);
}
JSObjectRef
-seed_construct_struct_type_with_parameters (JSContextRef ctx,
- GIBaseInfo * info,
- JSObjectRef parameters,
- JSValueRef * exception)
+seed_construct_struct_type_with_parameters(JSContextRef ctx,
+ GIBaseInfo* info,
+ JSObjectRef parameters,
+ JSValueRef* exception)
{
- gsize size = 0;
- gpointer object;
- GIInfoType type = g_base_info_get_type (info);
- JSObjectRef ret;
- gboolean set_ret;
- gint nparams, i = 0;
- gsize length;
- GIFieldInfo *field = 0;
- JSPropertyNameArrayRef jsprops;
- JSStringRef jsprop_name;
- JSValueRef jsprop_value;
- GArgument field_value;
- gchar *prop_name;
- GITypeInfo *field_type;
-
- if (type == GI_INFO_TYPE_STRUCT)
- {
- GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
- if (g_type_is_a (gtype, G_TYPE_VALUE))
- {
- GValue *gval = g_slice_alloc0 (sizeof (GValue));
- if (!parameters)
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Missing Type in GValue constructor");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ gsize size = 0;
+ gpointer object;
+ GIInfoType type = g_base_info_get_type(info);
+ JSObjectRef ret;
+ gboolean set_ret;
+ gint nparams, i = 0;
+ gsize length;
+ GIFieldInfo* field = 0;
+ JSPropertyNameArrayRef jsprops;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+ GArgument field_value;
+ gchar* prop_name;
+ GITypeInfo* field_type;
+
+ if (type == GI_INFO_TYPE_STRUCT) {
+ GType gtype
+ = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+ if (g_type_is_a(gtype, G_TYPE_VALUE)) {
+ GValue* gval = g_slice_alloc0(sizeof(GValue));
+ if (!parameters) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Missing Type in GValue constructor");
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- SEED_NOTE (CONSTRUCTION, "Created a GValue struct");
- seed_value_to_gvalue (ctx, parameters , 0, gval, exception);
- ret = seed_make_struct (ctx, (gpointer)gval, info);
- return ret;
+ SEED_NOTE(CONSTRUCTION, "Created a GValue struct");
+ seed_value_to_gvalue(ctx, parameters, 0, gval, exception);
+ ret = seed_make_struct(ctx, (gpointer) gval, info);
+ return ret;
}
- size = g_struct_info_get_size ((GIStructInfo *) info);
- }
- else
- {
- size = g_union_info_get_size ((GIUnionInfo *) info);
+ size = g_struct_info_get_size((GIStructInfo*) info);
+ } else {
+ size = g_union_info_get_size((GIUnionInfo*) info);
}
- if (!size)
- {
- g_critical ("Struct/union of type: %s has size 0 in introspection data. Please check GIR",
- g_base_info_get_name (info));
- g_assert(size);
+ if (!size) {
+ g_critical("Struct/union of type: %s has size 0 in introspection data. "
+ "Please check GIR",
+ g_base_info_get_name(info));
+ g_assert(size);
}
- object = g_slice_alloc0 (size);
+ object = g_slice_alloc0(size);
- SEED_NOTE (CONSTRUCTION,
- "Constructing struct/union of type: %s. Size: %zu \n",
- g_base_info_get_name (info), size);
+ SEED_NOTE(CONSTRUCTION,
+ "Constructing struct/union of type: %s. Size: %zu \n",
+ g_base_info_get_name(info), size);
- if (type == GI_INFO_TYPE_STRUCT)
- ret = seed_make_struct (ctx, object, info);
- else
- ret = seed_make_union (ctx, object, info);
+ if (type == GI_INFO_TYPE_STRUCT)
+ ret = seed_make_struct(ctx, object, info);
+ else
+ ret = seed_make_union(ctx, object, info);
- seed_pointer_set_free (ctx, ret, TRUE);
- seed_pointer_set_slice (ctx, ret, TRUE, size);
+ seed_pointer_set_free(ctx, ret, TRUE);
+ seed_pointer_set_slice(ctx, ret, TRUE, size);
- if (!parameters)
- return ret;
+ if (!parameters)
+ return ret;
+
+ jsprops = JSObjectCopyPropertyNames(ctx, (JSObjectRef) parameters);
+ nparams = JSPropertyNameArrayGetCount(jsprops);
- jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) parameters);
- nparams = JSPropertyNameArrayGetCount (jsprops);
-
- while (i < nparams)
- {
- jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
-
- length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
- prop_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (jsprop_name, prop_name, length);
-
- if (type == GI_INFO_TYPE_STRUCT)
- field = seed_struct_find_field ((GIStructInfo *) info, prop_name);
- else
- field = seed_union_find_field ((GIUnionInfo *) info, prop_name);
- if (!field)
- {
- seed_make_exception (ctx, exception, "PropertyError",
- "Invalid property for construction: %s",
- prop_name);
-
- JSPropertyNameArrayRelease (jsprops);
- return (JSObjectRef) JSValueMakeNull (ctx);
- }
- field_type = g_field_info_get_type (field);
-
- jsprop_value = JSObjectGetProperty (ctx,
- (JSObjectRef) parameters,
- jsprop_name, NULL);
-
- seed_value_to_gi_argument (ctx, jsprop_value, field_type, &field_value,
- exception);
- set_ret = g_field_info_set_field (field, object, &field_value);
-
- if (!set_ret)
- g_warning("Constructor setting property failed on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (info), prop_name);
-
- g_base_info_unref ((GIBaseInfo *) field_type);
- g_base_info_unref ((GIBaseInfo *) field);
-
- i++;
+ while (i < nparams) {
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex(jsprops, i);
+
+ length = JSStringGetMaximumUTF8CStringSize(jsprop_name);
+ prop_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsprop_name, prop_name, length);
+
+ if (type == GI_INFO_TYPE_STRUCT)
+ field = seed_struct_find_field((GIStructInfo*) info, prop_name);
+ else
+ field = seed_union_find_field((GIUnionInfo*) info, prop_name);
+ if (!field) {
+ seed_make_exception(ctx, exception, "PropertyError",
+ "Invalid property for construction: %s",
+ prop_name);
+
+ JSPropertyNameArrayRelease(jsprops);
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+ field_type = g_field_info_get_type(field);
+
+ jsprop_value = JSObjectGetProperty(ctx, (JSObjectRef) parameters,
+ jsprop_name, NULL);
+
+ seed_value_to_gi_argument(ctx, jsprop_value, field_type,
+ GI_TRANSFER_NOTHING, &field_value, exception);
+
+ set_ret = g_field_info_set_field(field, object, &field_value);
+
+ if (!set_ret)
+ g_warning(
+ "Constructor setting property failed on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(info), prop_name);
+
+ g_base_info_unref((GIBaseInfo*) field_type);
+ g_base_info_unref((GIBaseInfo*) field);
+
+ i++;
}
- JSPropertyNameArrayRelease (jsprops);
+ JSPropertyNameArrayRelease(jsprops);
- return ret;
+ return ret;
}
diff --git a/libseed/seed-structs.h b/libseed/seed-structs.h
index 92f85e9..33ad639 100644
--- a/libseed/seed-structs.h
+++ b/libseed/seed-structs.h
@@ -21,36 +21,37 @@
extern JSClassRef seed_struct_class;
extern JSClassRef seed_union_class;
-JSObjectRef seed_make_union (JSContextRef ctx, gpointer younion,
- GIBaseInfo * info);
-JSObjectRef seed_make_struct (JSContextRef ctx, gpointer strukt,
- GIBaseInfo * info);
-JSObjectRef seed_make_boxed (JSContextRef ctx,
- gpointer boxed, GIBaseInfo * info);
-
-JSObjectRef seed_make_pointer (JSContextRef ctx, gpointer pointer);
-
-JSValueRef
-seed_field_get_value (JSContextRef ctx,
- gpointer object,
- GIFieldInfo * field, JSValueRef * exception);
-
-gpointer seed_pointer_get_pointer (JSContextRef ctx, JSValueRef strukt);
-void seed_pointer_set_free (JSContextRef ctx,
- JSValueRef pointer, gboolean free_pointer);
-
-GIFieldInfo *seed_struct_find_field (GIStructInfo * info, gchar * field_name);
-GIFieldInfo *seed_union_find_field (GIUnionInfo * info, gchar * field_name);
-
-JSObjectRef
-seed_construct_struct_type_with_parameters (JSContextRef ctx,
- GIBaseInfo * info,
- JSObjectRef parameters,
- JSValueRef * exception);
-
-JSObjectRef seed_union_prototype (JSContextRef ctx, GIBaseInfo * info);
-JSObjectRef seed_struct_prototype (JSContextRef ctx, GIBaseInfo * info);
-
-void seed_structs_init ();
+JSObjectRef seed_make_union(JSContextRef ctx,
+ gpointer younion,
+ GIBaseInfo* info);
+JSObjectRef seed_make_struct(JSContextRef ctx,
+ gpointer strukt,
+ GIBaseInfo* info);
+JSObjectRef seed_make_boxed(JSContextRef ctx, gpointer boxed, GIBaseInfo* info);
+
+JSObjectRef seed_make_pointer(JSContextRef ctx, gpointer pointer);
+
+JSValueRef seed_field_get_value(JSContextRef ctx,
+ gpointer object,
+ GIFieldInfo* field,
+ JSValueRef* exception);
+
+gpointer seed_pointer_get_pointer(JSContextRef ctx, JSValueRef strukt);
+void seed_pointer_set_free(JSContextRef ctx,
+ JSValueRef pointer,
+ gboolean free_pointer);
+
+GIFieldInfo* seed_struct_find_field(GIStructInfo* info, gchar* field_name);
+GIFieldInfo* seed_union_find_field(GIUnionInfo* info, gchar* field_name);
+
+JSObjectRef seed_construct_struct_type_with_parameters(JSContextRef ctx,
+ GIBaseInfo* info,
+ JSObjectRef parameters,
+ JSValueRef* exception);
+
+JSObjectRef seed_union_prototype(JSContextRef ctx, GIBaseInfo* info);
+JSObjectRef seed_struct_prototype(JSContextRef ctx, GIBaseInfo* info);
+
+void seed_structs_init();
#endif
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 5f17d9b..722f265 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -26,1634 +26,1661 @@ JSClassRef gobject_method_class;
JSClassRef gobject_constructor_class;
JSClassRef seed_callback_class;
JSClassRef gobject_init_method_class;
-SeedEngine *eng;
+SeedEngine* eng;
static gboolean
-seed_value_is_gobject (JSContextRef ctx, JSValueRef value)
+seed_value_is_gobject(JSContextRef ctx, JSValueRef value)
{
- if (!JSValueIsObject (ctx, value) || JSValueIsNull (ctx, value))
- return FALSE;
+ if (!JSValueIsObject(ctx, value) || JSValueIsNull(ctx, value))
+ return FALSE;
- return JSValueIsObjectOfClass (ctx, value, gobject_class);
+ return JSValueIsObjectOfClass(ctx, value, gobject_class);
}
void
-seed_toggle_ref (gpointer data, GObject * object, gboolean is_last_ref)
+seed_toggle_ref(gpointer data, GObject* object, gboolean is_last_ref)
{
- JSValueRef wrapper;
+ JSValueRef wrapper;
- if (!g_object_get_data (object, "js-ref"))
- return;
+ if (!g_object_get_qdata(object, js_ref_quark))
+ return;
- wrapper = (JSValueRef) data;
+ wrapper = (JSValueRef) data;
- if (is_last_ref)
- {
- JSValueUnprotect (eng->context, wrapper);
- }
- else
- {
- JSValueProtect (eng->context, wrapper);
+ if (is_last_ref) {
+ JSValueUnprotect(eng->context, wrapper);
+ } else {
+ JSValueProtect(eng->context, wrapper);
}
}
static void
-seed_gobject_destroyed (gpointer object)
+seed_gobject_destroyed(gpointer object)
{
- JSValueUnprotect (eng->context, (JSValueRef) object);
- JSObjectSetPrivate ((JSObjectRef) object, 0);
+ JSValueUnprotect(eng->context, (JSValueRef) object);
+ JSObjectSetPrivate((JSObjectRef) object, 0);
}
JSObjectRef
-seed_make_wrapper_for_type (JSContextRef ctx, GType type)
+seed_make_wrapper_for_type(JSContextRef ctx, GType type)
{
- JSClassRef class;
- JSObjectRef ret;
- JSValueRef prototype;
+ JSClassRef class;
+ JSObjectRef ret;
+ JSValueRef prototype;
- class = seed_gobject_get_class_for_gtype (ctx, type);
+ class = seed_gobject_get_class_for_gtype(ctx, type);
- while (!class && (type = g_type_parent (type)))
- class = seed_gobject_get_class_for_gtype (ctx, type);
+ while (!class && (type = g_type_parent(type)))
+ class = seed_gobject_get_class_for_gtype(ctx, type);
- prototype = seed_gobject_get_prototype_for_gtype (type);
- ret = JSObjectMake (ctx, class, NULL);
- if (prototype)
- JSObjectSetPrototype (ctx, ret, prototype);
- else
- g_assert_not_reached ();
+ prototype = seed_gobject_get_prototype_for_gtype(type);
+ ret = JSObjectMake(ctx, class, NULL);
+ if (prototype)
+ JSObjectSetPrototype(ctx, ret, prototype);
+ else
+ g_assert_not_reached();
- return ret;
+ return ret;
}
static JSValueRef
-seed_wrap_object (JSContextRef ctx, GObject * object)
+seed_wrap_object(JSContextRef ctx, GObject* object)
{
- JSValueRef user_data;
- JSObjectRef js_ref;
- GType type;
+ JSValueRef user_data;
+ JSObjectRef js_ref;
+ GType type;
- type = G_OBJECT_TYPE (object);
+ type = G_OBJECT_TYPE(object);
- user_data = (JSValueRef) g_object_get_qdata (object, js_ref_quark);
+ user_data = (JSValueRef) g_object_get_qdata(object, js_ref_quark);
- if (user_data)
- return user_data;
+ if (user_data)
+ return user_data;
- if (pthread_getspecific(seed_next_gobject_wrapper_key))
- js_ref = pthread_getspecific(seed_next_gobject_wrapper_key);
- else
- js_ref = seed_make_wrapper_for_type (ctx, type);
+ if (pthread_getspecific(seed_next_gobject_wrapper_key))
+ js_ref = pthread_getspecific(seed_next_gobject_wrapper_key);
+ else
+ js_ref = seed_make_wrapper_for_type(ctx, type);
- JSObjectSetPrivate (js_ref, object);
+ JSObjectSetPrivate(js_ref, object);
- g_object_set_qdata_full (object, js_ref_quark, (gpointer) js_ref,
- seed_gobject_destroyed);
+ g_object_set_qdata_full(object, js_ref_quark, (gpointer) js_ref,
+ seed_gobject_destroyed);
- JSValueProtect (eng->context, js_ref);
- g_object_add_toggle_ref (object, seed_toggle_ref, (gpointer) js_ref);
+ JSValueProtect(eng->context, js_ref);
+ g_object_add_toggle_ref(object, seed_toggle_ref, (gpointer) js_ref);
- seed_add_signals_to_object (ctx, js_ref, object);
+ seed_add_signals_to_object(ctx, js_ref, object);
- pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
+ pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
- return js_ref;
+ return js_ref;
}
static gboolean
-seed_release_arg (GITransfer transfer,
- GITypeInfo * type_info, GITypeTag type_tag, GArgument * arg)
+seed_release_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GITypeTag type_tag,
+ GArgument* arg)
{
- GType gtype;
- GITypeInfo *param_type;
- GIBaseInfo *interface_info;
- GValue *gval;
-
- switch (type_tag)
- {
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- g_free (arg->v_string);
- break;
- case GI_TYPE_TAG_ARRAY:
- if (arg->v_pointer)
- {
- param_type = g_type_info_get_param_type (type_info, 0);
-
- switch (g_type_info_get_tag (param_type))
- {
- case GI_TYPE_TAG_UTF8:
- if (transfer == GI_TRANSFER_EVERYTHING)
- g_strfreev (arg->v_pointer);
- else if (transfer == GI_TRANSFER_CONTAINER)
- g_free (arg->v_pointer);
- break;
- case GI_TYPE_TAG_GTYPE:
- case GI_TYPE_TAG_FLOAT:
- case GI_TYPE_TAG_UINT8:
- case GI_TYPE_TAG_UINT32:
- g_free (arg->v_pointer);
- break;
- case GI_TYPE_TAG_INTERFACE:
- break;
- default:
- g_assert_not_reached ();
- }
-
- g_base_info_unref ((GIBaseInfo *) param_type);
- }
- break;
- case GI_TYPE_TAG_GHASH:
- {
- GITypeInfo *val_param_info;
- GHashTableIter iter;
- GArgument value;
-
- val_param_info = g_type_info_get_param_type (type_info, 1);
- g_assert(val_param_info != NULL);
-
- /* release the hashtable's values */
- g_hash_table_iter_init (&iter, arg->v_pointer);
- while (g_hash_table_iter_next (&iter, NULL, &value.v_pointer))
- {
- seed_release_arg (GI_TRANSFER_EVERYTHING, val_param_info,
- g_type_info_get_tag (val_param_info), &value);
- }
-
- /* release the hashtable's keys and the hashtable itself */
- g_hash_table_destroy (arg->v_pointer);
- break;
- }
- case GI_TYPE_TAG_INTERFACE:
- {
- if (arg->v_pointer)
- {
- interface_info = g_type_info_get_interface (type_info);
-
- GIInfoType interface_type = g_base_info_get_type (interface_info);
- if (interface_type == GI_INFO_TYPE_CALLBACK)
- {
- /* FIXME: - callback returns are not handled yet */
- g_base_info_unref (interface_info);
- break;
- }
-
- gtype =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)
- interface_info);
-
- if (g_type_is_a (gtype, G_TYPE_OBJECT)
- || g_type_is_a (gtype, G_TYPE_INTERFACE))
- {
- SEED_NOTE (MISC,
- "Unreffing object of type: %s in"
- "argument release. Reference count: %d\n",
- g_type_name (G_OBJECT_TYPE
- (G_OBJECT (arg->v_pointer))),
- G_OBJECT (arg->v_pointer)->ref_count);
- g_object_unref (G_OBJECT (arg->v_pointer));
- }
- else if (g_type_is_a (gtype, G_TYPE_VALUE))
- {
- gval = (GValue *) arg->v_pointer;
- // Free/unref the GValue's contents.
- g_value_unset (gval);
- // Free the GValue.
- g_slice_free1 (sizeof (GValue), gval);
- }
- else if (g_type_is_a (gtype, G_TYPE_CLOSURE))
- {
- g_closure_unref (arg->v_pointer);
- }
-
- g_base_info_unref (interface_info);
- }
- break;
- }
- default:
- break;
-
+ GType gtype;
+ GITypeInfo* param_type;
+ GIBaseInfo* interface_info;
+ GValue* gval;
+
+ switch (type_tag) {
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ g_free(arg->v_string);
+ break;
+ case GI_TYPE_TAG_ARRAY:
+ if (arg->v_pointer) {
+ param_type = g_type_info_get_param_type(type_info, 0);
+
+ switch (g_type_info_get_tag(param_type)) {
+ case GI_TYPE_TAG_UTF8:
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ g_strfreev(arg->v_pointer);
+ else if (transfer == GI_TRANSFER_CONTAINER)
+ g_free(arg->v_pointer);
+ break;
+ case GI_TYPE_TAG_GTYPE:
+ case GI_TYPE_TAG_FLOAT:
+ case GI_TYPE_TAG_UINT8:
+ case GI_TYPE_TAG_INT32:
+ case GI_TYPE_TAG_UINT32:
+ g_free(arg->v_pointer);
+ break;
+ case GI_TYPE_TAG_INTERFACE:
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ g_base_info_unref((GIBaseInfo*) param_type);
+ }
+ break;
+ case GI_TYPE_TAG_GHASH: {
+ GITypeInfo* val_param_info;
+ GHashTableIter iter;
+ GArgument value;
+
+ val_param_info = g_type_info_get_param_type(type_info, 1);
+ g_assert(val_param_info != NULL);
+
+ /* release the hashtable's values */
+ g_hash_table_iter_init(&iter, arg->v_pointer);
+ while (g_hash_table_iter_next(&iter, NULL, &value.v_pointer)) {
+ seed_release_arg(GI_TRANSFER_EVERYTHING, val_param_info,
+ g_type_info_get_tag(val_param_info), &value);
+ }
+
+ /* release the hashtable's keys and the hashtable itself */
+ g_hash_table_destroy(arg->v_pointer);
+ break;
+ }
+ case GI_TYPE_TAG_INTERFACE: {
+ if (arg->v_pointer) {
+ interface_info = g_type_info_get_interface(type_info);
+
+ GIInfoType interface_type
+ = g_base_info_get_type(interface_info);
+ if (interface_type == GI_INFO_TYPE_CALLBACK) {
+ /* FIXME: - callback returns are not handled yet */
+ g_base_info_unref(interface_info);
+ break;
+ }
+
+ gtype = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface_info);
+
+ if (g_type_is_a(gtype, G_TYPE_OBJECT)
+ || g_type_is_a(gtype, G_TYPE_INTERFACE)) {
+ SEED_NOTE(MISC, "Unreffing object of type: %s in"
+ "argument release. Reference count: %d\n",
+ g_type_name(
+ G_OBJECT_TYPE(G_OBJECT(arg->v_pointer))),
+ G_OBJECT(arg->v_pointer)->ref_count);
+ g_object_unref(G_OBJECT(arg->v_pointer));
+ } else if (g_type_is_a(gtype, G_TYPE_VALUE)) {
+ gval = (GValue*) arg->v_pointer;
+ // Free/unref the GValue's contents.
+ g_value_unset(gval);
+ // Free the GValue.
+ g_slice_free1(sizeof(GValue), gval);
+ } else if (g_type_is_a(gtype, G_TYPE_CLOSURE)) {
+ g_closure_unref(arg->v_pointer);
+ }
+
+ g_base_info_unref(interface_info);
+ }
+ break;
+ }
+ default:
+ break;
}
- return TRUE;
+ return TRUE;
}
gboolean
-seed_gi_release_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg)
+seed_gi_release_arg(GITransfer transfer, GITypeInfo* type_info, GArgument* arg)
{
- GITypeTag type_tag;
+ GITypeTag type_tag;
- if (transfer == GI_TRANSFER_NOTHING)
- return TRUE;
+ if (transfer == GI_TRANSFER_NOTHING)
+ return TRUE;
- type_tag = g_type_info_get_tag ((GITypeInfo *) type_info);
+ type_tag = g_type_info_get_tag((GITypeInfo*) type_info);
- return seed_release_arg (transfer, type_info, type_tag, arg);
+ return seed_release_arg(transfer, type_info, type_tag, arg);
}
gboolean
-seed_gi_release_in_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg)
+seed_gi_release_in_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GArgument* arg)
{
- GITypeTag type_tag;
+ GITypeTag type_tag;
- if (transfer == GI_TRANSFER_EVERYTHING)
- return TRUE;
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ return TRUE;
+
+ type_tag = g_type_info_get_tag((GITypeInfo*) type_info);
- type_tag = g_type_info_get_tag ((GITypeInfo *) type_info);
-
- switch (type_tag)
- {
- // TODO: FIXME: Leaaaks?
- case GI_TYPE_TAG_INTERFACE:
- {
- // TODO: FIXME: Need some safe way to look for GClosure.
- break;
- }
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- case GI_TYPE_TAG_ARRAY:
- case GI_TYPE_TAG_GHASH:
- return seed_release_arg (GI_TRANSFER_EVERYTHING,
- type_info, type_tag, arg);
- default:
- break;
+ switch (type_tag) {
+ // TODO: FIXME: Leaaaks?
+ case GI_TYPE_TAG_INTERFACE: {
+ // TODO: FIXME: Need some safe way to look for GClosure.
+ break;
+ }
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_GHASH:
+ return seed_release_arg(GI_TRANSFER_EVERYTHING, type_info, type_tag,
+ arg);
+ default:
+ break;
}
- return TRUE;
+ return TRUE;
}
static JSValueRef
-seed_gi_make_jsarray (JSContextRef ctx,
- void *array,
- GITypeInfo * param_type, JSValueRef * exception)
+seed_gi_make_jsarray(JSContextRef ctx,
+ void* array,
+ GITypeInfo* param_type,
+ JSValueRef* exception)
{
- GITypeTag element_type;
- JSValueRef *elements;
- guint length, i;
- gchar **str_array = (gchar **) array;
- JSValueRef ret = JSValueMakeNull (ctx);
+ GITypeTag element_type;
+ JSValueRef* elements;
+ guint length, i;
+ gchar** str_array = (gchar**) array;
+ JSValueRef ret = JSValueMakeNull(ctx);
+
+ element_type = g_type_info_get_tag(param_type);
- element_type = g_type_info_get_tag (param_type);
+ if (element_type == GI_TYPE_TAG_UTF8) {
- if (element_type == GI_TYPE_TAG_UTF8)
- {
+ length = g_strv_length(str_array);
+ if (!length)
+ return ret;
+
+ elements = g_alloca(sizeof(JSValueRef) * length);
+ for (i = 0; i < length; ++i) {
+ elements[i] = seed_value_from_string(ctx, str_array[i], exception);
+ }
- length = g_strv_length (str_array);
- if (!length)
- return ret;
+ ret = (JSValueRef) JSObjectMakeArray(ctx, length, elements, exception);
+ }
+
+ if (element_type == GI_TYPE_TAG_GTYPE) {
+ GType* ptr = (GType*) array;
+ length = 0;
+ while (ptr[length])
+ length++;
+
+ elements = g_alloca(sizeof(JSValueRef) * length);
+
+ for (i = 0; i < length; ++i)
+ elements[i] = seed_value_from_long(ctx, ptr[i], exception);
+
+ return (JSValueRef) JSObjectMakeArray(ctx, length, elements, exception);
+ }
+
+ return ret;
+}
- elements = g_alloca (sizeof (JSValueRef) * length);
- for (i = 0; i < length; ++i)
- {
- elements[i] = seed_value_from_string (ctx, str_array[i], exception);
- }
+JSValueRef
+seed_array_from_zero_terminated_c_array(JSContextRef ctx,
+ gpointer pointer,
+ GITypeInfo* param_info,
+ JSValueRef* exception)
+{
+ JSObjectRef ret;
+ GITypeTag element_type;
+ GArgument arg;
+ guint i;
+
+ element_type = g_type_info_get_tag(param_info);
+
+ // Special case handling array(guint8), which happens to be a string
+ // in most cases
+ if (element_type == GI_TYPE_TAG_UINT8) {
+ // TODO: this is pretty simple and probably incomplete.
+ // GJS makes possible the return of an array, supporting
+ // all types. We're only supporting strings ATM.
+ ret = seed_value_from_string(ctx, pointer, exception);
+ return ret;
+ }
- ret = (JSValueRef) JSObjectMakeArray (ctx, length, elements, exception);
+ ret = JSObjectMakeArray(ctx, NULL, NULL, NULL);
+
+#define ITERATE(type) \
+ do { \
+ g##type* array = (g##type*) pointer; \
+ for (i = 0; array[i]; i++) { \
+ arg.v_##type = array[i]; \
+ JSValueRef val \
+ = seed_value_from_gi_argument(ctx, &arg, param_info, exception); \
+ seed_object_set_property_at_index(ctx, ret, i, val, exception); \
+ } \
+ } while (0);
+
+ switch (element_type) {
+ /* We handle GI_TYPE_TAG_UINT8 above. */
+ case GI_TYPE_TAG_INT8:
+ ITERATE(int8);
+ break;
+ case GI_TYPE_TAG_UINT16:
+ ITERATE(uint16);
+ break;
+ case GI_TYPE_TAG_INT16:
+ ITERATE(int16);
+ break;
+ case GI_TYPE_TAG_UINT32:
+ ITERATE(uint32);
+ break;
+ case GI_TYPE_TAG_INT32:
+ ITERATE(int32);
+ break;
+ case GI_TYPE_TAG_UINT64:
+ ITERATE(uint64);
+ break;
+ case GI_TYPE_TAG_INT64:
+ ITERATE(int64);
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ ITERATE(float);
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ ITERATE(double);
+ break;
+ case GI_TYPE_TAG_GTYPE:
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_INTERFACE:
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ case GI_TYPE_TAG_ERROR:
+ ITERATE(pointer);
+ break;
+ default:
+ seed_make_exception(ctx, exception, "Argumenterror",
+ "Unknown element-type %d", element_type);
}
- if (element_type == GI_TYPE_TAG_GTYPE)
- {
- GType* ptr = (GType*)array;
- length = 0;
- while (ptr[length]) length++;
-
- elements = g_alloca (sizeof (JSValueRef) * length);
+#undef ITERATE
- for (i = 0; i < length; ++i)
- elements[i] = seed_value_from_long (ctx, ptr[i], exception);
-
- return (JSValueRef) JSObjectMakeArray (ctx, length, elements, exception);
+ return ret;
+}
+static gboolean
+seed_gi_make_array_from_string(JSContextRef ctx,
+ JSStringRef js_string,
+ GITypeInfo* param_type,
+ guint length,
+ void** array_p,
+ guint* out_array_length,
+ JSValueRef* exception)
+{
+ GITypeTag element_type;
+ element_type = g_type_info_get_tag(param_type);
+
+ // This could be handled by the case where the value is an object,
+ // however, getting length from a string crashs inside JSC. So,
+ // we're now proper handling strings here
+ gchar* buffer = g_malloc(length * sizeof(gchar));
+ guint real_size = JSStringGetUTF8CString(js_string, buffer, length);
+
+ switch (element_type) {
+ case GI_TYPE_TAG_INT8:
+ case GI_TYPE_TAG_UINT8: {
+ *array_p = buffer;
+
+ // So, GJS doesn't computer the \0 at the end of line.
+ // it does make sense, as converting a string to an array
+ // we don't want the EOS. However, I couldn't find a way to do it
+ // with
+ // JSC, so I'm basically reducing one byte.
+ if (out_array_length)
+ *out_array_length = real_size - 1;
+ break;
+ }
+ case GI_TYPE_TAG_INT16:
+ case GI_TYPE_TAG_UINT16:
+ // TODO: implement utf16 support
+ default: {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Cannot convert string to array of '%s'",
+ g_type_tag_to_string(element_type));
+ return FALSE;
+ }
}
- return ret;
+ return TRUE;
}
static gboolean
-seed_gi_make_array (JSContextRef ctx,
- JSValueRef array,
- guint length,
- GITypeInfo * param_type,
- void **array_p, JSValueRef * exception)
+seed_gi_make_array(JSContextRef ctx,
+ JSValueRef array,
+ guint length,
+ GITypeInfo* param_type,
+ void** array_p,
+ JSValueRef* exception)
{
- GITypeTag element_type;
- JSValueRef elem;
- guint i;
-
- element_type = g_type_info_get_tag (param_type);
-
- switch (element_type)
- {
- case GI_TYPE_TAG_UTF8:
- {
- gchar **strresult = g_new0 (gchar *, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- strresult[i] = seed_value_to_string (ctx, elem, exception);
- }
-
- *array_p = strresult;
- }
- break;
- case GI_TYPE_TAG_GTYPE:
- {
- GType *typeresult;
-
- typeresult = g_new0 (GType, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- typeresult[i] = seed_value_to_int (ctx, elem, exception);
- }
-
- *array_p = typeresult;
- }
- break;
- case GI_TYPE_TAG_FLOAT:
- {
- gfloat *floatresult;
-
- floatresult = g_new0 (gfloat, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- floatresult[i] = seed_value_to_float (ctx, elem, exception);
- }
-
- *array_p = floatresult;
- }
- break;
- case GI_TYPE_TAG_DOUBLE:
- {
- gdouble *dblresult;
-
- dblresult = g_new0 (gdouble, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- dblresult[i] = seed_value_to_double (ctx, elem, exception);
- }
-
- *array_p = dblresult;
- }
- break;
+ GITypeTag element_type;
+ JSValueRef elem;
+ guint i;
+
+ element_type = g_type_info_get_tag(param_type);
+
+ switch (element_type) {
+ case GI_TYPE_TAG_UTF8: {
+ gchar** strresult = g_new0(gchar*, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ strresult[i] = seed_value_to_string(ctx, elem, exception);
+ }
+
+ *array_p = strresult;
+ } break;
+ case GI_TYPE_TAG_GTYPE: {
+ GType* typeresult;
+
+ typeresult = g_new0(GType, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ typeresult[i] = seed_value_to_int(ctx, elem, exception);
+ }
+
+ *array_p = typeresult;
+ } break;
+ case GI_TYPE_TAG_FLOAT: {
+ gfloat* floatresult;
+
+ floatresult = g_new0(gfloat, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ floatresult[i] = seed_value_to_float(ctx, elem, exception);
+ }
+
+ *array_p = floatresult;
+ } break;
+ case GI_TYPE_TAG_DOUBLE: {
+ gdouble* dblresult;
+
+ dblresult = g_new0(gdouble, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ dblresult[i] = seed_value_to_double(ctx, elem, exception);
+ }
+
+ *array_p = dblresult;
+ } break;
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_INT:
+ case GI_TYPE_TAG_INT:
#endif
- case GI_TYPE_TAG_INT32:
- {
- gint *intresult;
-
- intresult = g_new0 (gint, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- intresult[i] = seed_value_to_int (ctx, elem, exception);
- }
-
- *array_p = intresult;
- }
- break;
- case GI_TYPE_TAG_UINT8:
- {
- guint8 *guint8result;
-
- guint8result = g_new0 (guint8, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- guint8result[i] = seed_value_to_uchar (ctx, elem, exception);
- }
-
- *array_p = guint8result;
- }
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface = g_type_info_get_interface (param_type);
- GIInfoType interface_type = g_base_info_get_type (interface);
- if (interface_type == GI_INFO_TYPE_OBJECT
- || interface_type == GI_INFO_TYPE_INTERFACE
- || interface_type == GI_INFO_TYPE_STRUCT)
- {
- GType type =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)
- interface);
- if (g_type_is_a (type, G_TYPE_VALUE))
- {
- GValue *gvalresult;
-
- // TODO:FIXME: Robb. Valgrind thinks there's a leak here,
- // at least while running Same Seed.
- gvalresult = g_new0 (GValue, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- seed_value_to_gvalue (ctx, elem,
- (GType) 0,
- &gvalresult[i], exception);
- }
- *array_p = gvalresult;
-
- g_base_info_unref (interface);
- break;
- }
- }
-
- g_base_info_unref (interface);
- }
- case GI_TYPE_TAG_UINT32:
- {
- guint32 *uintresult;
-
- uintresult = g_new0 (guint32, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- uintresult[i] = seed_value_to_uint (ctx, elem, exception);
- }
- *array_p = uintresult;
- }
- break;
- default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "Unhandled array element type");
- return FALSE;
+ case GI_TYPE_TAG_INT32: {
+ gint* intresult;
+
+ intresult = g_new0(gint, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ intresult[i] = seed_value_to_int(ctx, elem, exception);
+ }
+
+ *array_p = intresult;
+ } break;
+ case GI_TYPE_TAG_UINT8: {
+ guint8* guint8result;
+
+ guint8result = g_new0(guint8, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ guint8result[i] = seed_value_to_uchar(ctx, elem, exception);
+ }
+
+ *array_p = guint8result;
+ } break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface = g_type_info_get_interface(param_type);
+ GIInfoType interface_type = g_base_info_get_type(interface);
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE
+ || interface_type == GI_INFO_TYPE_STRUCT) {
+ GType type = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+ if (g_type_is_a(type, G_TYPE_VALUE)) {
+ GValue* gvalresult;
+
+ // TODO:FIXME: Robb. Valgrind thinks there's a leak here,
+ // at least while running Same Seed.
+ gvalresult = g_new0(GValue, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem
+ = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array,
+ i, exception);
+ seed_value_to_gvalue(ctx, elem, (GType) 0,
+ &gvalresult[i], exception);
+ }
+ *array_p = gvalresult;
+
+ g_base_info_unref(interface);
+ break;
+ }
+ }
+
+ g_base_info_unref(interface);
+ }
+ case GI_TYPE_TAG_UINT32: {
+ guint32* uintresult;
+
+ uintresult = g_new0(guint32, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ uintresult[i] = seed_value_to_uint(ctx, elem, exception);
+ }
+ *array_p = uintresult;
+ } break;
+ default:
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unhandled array element type");
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
gboolean
-seed_value_to_gi_argument (JSContextRef ctx,
- JSValueRef value,
- GITypeInfo * type_info,
- GArgument * arg,
- JSValueRef * exception)
+seed_value_to_gi_argument_with_out_length(JSContextRef ctx,
+ JSValueRef value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ guint* out_array_length,
+ JSValueRef* exception)
{
- GITypeTag gi_tag = g_type_info_get_tag (type_info);
-
- // FIXME: Some types are not "nullable", also need to check if argument
- // can be null before doing this.
- if (!value || JSValueIsNull (ctx, value))
- {
- arg->v_pointer = 0;
- return 1;
- }
+ GITypeTag gi_tag = g_type_info_get_tag(type_info);
- switch (gi_tag)
- {
- case GI_TYPE_TAG_VOID:
-
- if (g_type_info_is_pointer (type_info))
- {
- GObject *gobject;
- if (JSValueIsString (ctx, value))
- {
- /*
- things like gio.outputstream.write use void pointers
- might need a few other types here..
- not very well memory managed. - should be solved by bytearrays when
- introspection implements it.
- */
- arg->v_string = seed_value_to_string (ctx, value, exception);
- break;
- }
- /* gtk_statusicon_position_menu / gtk_menu_popup use the userdata for the Gobject */
- gobject = seed_value_to_object (ctx, value, exception);
- if (!gobject)
- return FALSE;
+ // FIXME: Some types are not "nullable", also need to check if argument
+ // can be null before doing this.
+ if (!value || JSValueIsNull(ctx, value)) {
+ arg->v_pointer = 0;
+ return 1;
+ }
- arg->v_pointer = gobject;
- }
- break;
+ switch (gi_tag) {
+ case GI_TYPE_TAG_VOID:
+
+ if (g_type_info_is_pointer(type_info)) {
+ GObject* gobject;
+ if (JSValueIsString(ctx, value)) {
+ /*
+ things like gio.outputstream.write use void pointers
+ might need a few other types here..
+ not very well memory managed. - should be solved by
+ bytearrays when
+ introspection implements it.
+ */
+ arg->v_string = seed_value_to_string(ctx, value, exception);
+ break;
+ }
+ /* gtk_statusicon_position_menu / gtk_menu_popup use the
+ * userdata for the Gobject */
+ gobject = seed_value_to_object(ctx, value, exception);
+ if (!gobject)
+ return FALSE;
+
+ arg->v_pointer = gobject;
+ }
+ break;
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- arg->v_long = seed_value_to_long (ctx, value, exception);
- break;
- case GI_TYPE_TAG_ULONG:
- arg->v_ulong = seed_value_to_ulong (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT:
- arg->v_int = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT:
- arg->v_uint = seed_value_to_uint (ctx, value, exception);
- break;
- case GI_TYPE_TAG_SIZE:
- arg->v_size = seed_value_to_size (ctx, value, exception);
- break;
- case GI_TYPE_TAG_SSIZE:
- arg->v_ssize = seed_value_to_ssize (ctx, value, exception);
- break;
- case GI_TYPE_TAG_TIME_T:
- arg->v_long = seed_value_to_time_t (ctx, value, exception);
- break;
+ case GI_TYPE_TAG_LONG:
+ arg->v_long = seed_value_to_long(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_ULONG:
+ arg->v_ulong = seed_value_to_ulong(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT:
+ arg->v_int = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT:
+ arg->v_uint = seed_value_to_uint(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_SIZE:
+ arg->v_size = seed_value_to_size(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_SSIZE:
+ arg->v_ssize = seed_value_to_ssize(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_TIME_T:
+ arg->v_long = seed_value_to_time_t(ctx, value, exception);
+ break;
#endif
- case GI_TYPE_TAG_BOOLEAN:
- arg->v_boolean = seed_value_to_boolean (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT8:
- arg->v_int8 = seed_value_to_char (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT8:
- arg->v_uint8 = seed_value_to_uchar (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT16:
- arg->v_int16 = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT16:
- arg->v_uint16 = seed_value_to_uint (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT32:
- arg->v_int32 = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT32:
- arg->v_uint32 = seed_value_to_uint (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT64:
- arg->v_int64 = seed_value_to_int64 (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT64:
- arg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
- break;
- case GI_TYPE_TAG_FLOAT:
- arg->v_float = seed_value_to_float (ctx, value, exception);
- break;
- case GI_TYPE_TAG_DOUBLE:
- arg->v_double = seed_value_to_double (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UTF8:
- arg->v_string = seed_value_to_string (ctx, value, exception);
- break;
- case GI_TYPE_TAG_FILENAME:
- arg->v_string = seed_value_to_filename (ctx, value, exception);
- break;
- case GI_TYPE_TAG_GTYPE:
- arg->v_int = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
- GType required_gtype;
- GObject *gobject;
-
- interface = g_type_info_get_interface (type_info);
- interface_type = g_base_info_get_type (interface);
-
- arg->v_pointer = NULL;
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- gobject = seed_value_to_object (ctx, value, exception);
- required_gtype =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)
- interface);
-
- // FIXME: Not clear if the g_type_is_a check is desired here.
- // Possibly 'breaks things' when we don't have introspection
- // data for some things in an interface hierarchy. Hasn't
- // provided any problems so far.
- if (!gobject
- || !g_type_is_a (G_OBJECT_TYPE (gobject), required_gtype))
- {
- g_base_info_unref (interface);
- return FALSE;
- }
-
- arg->v_pointer = gobject;
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_ENUM ||
- interface_type == GI_INFO_TYPE_FLAGS)
- {
- // this might need fixing...
- arg->v_long = seed_value_to_long (ctx, value, exception);
- if (!(interface_type == GI_INFO_TYPE_FLAGS)
- && !seed_validate_enum ((GIEnumInfo *) interface,
- arg->v_long))
- {
- seed_make_exception (ctx, exception, "EnumRange",
- "Enum value: %ld is out of range",
- arg->v_long);
- g_base_info_unref (interface);
-
- return FALSE;
- }
-
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT ||
- interface_type == GI_INFO_TYPE_UNION)
- {
- if (JSValueIsObjectOfClass (ctx, value, seed_struct_class))
- arg->v_pointer = seed_pointer_get_pointer (ctx, value);
- else if (JSValueIsObjectOfClass (ctx, value, seed_union_class))
- arg->v_pointer = seed_pointer_get_pointer (ctx, value);
- else
- {
- GType type =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo
- *) interface);
- if (!type)
- {
- g_base_info_unref (interface);
- return FALSE;
- }
- else if (type == G_TYPE_VALUE)
- {
- GValue *gval = g_slice_alloc0 (sizeof (GValue));
- seed_value_to_gvalue (ctx,
- value,
- (GType) NULL,
- gval, exception);
- arg->v_pointer = gval;
-
- g_base_info_unref (interface);
- break;
- }
- // Automatically convert between functions and
- // GClosures where expected.
- else if (g_type_is_a (type, G_TYPE_CLOSURE))
- {
- if (JSObjectIsFunction (ctx, (JSObjectRef) value))
- {
- arg->v_pointer =
- seed_closure_new (ctx, (JSObjectRef) value, NULL,
- NULL);
- }
- }
- else
- {
- JSObjectRef strukt =
- seed_construct_struct_type_with_parameters (ctx,
- interface,
- (JSObjectRef) value,
- exception);
- arg->v_pointer = seed_pointer_get_pointer (ctx, strukt);
- }
- }
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_CALLBACK)
- {
- if (JSValueIsNull (ctx, value))
- {
- arg->v_pointer = NULL;
- g_base_info_unref (interface);
- break;
- }
- // Someone passes in a wrapper around a method where a
- // callback is expected, i.e Clutter.sine_inc_func, as an alpha
- // Have to dlsym the symbol to be able to do this.
- // NOTE: Some cases where dlsym(NULL, symbol) doesn't work depending
- // On how libseed is loaded.
- else if (JSValueIsObjectOfClass (ctx,
- value, gobject_method_class))
- {
- GIFunctionInfo *info =
- JSObjectGetPrivate ((JSObjectRef) value);
- const gchar *symbol = g_function_info_get_symbol (info);
- gchar *error;
- void *fp;
-
- dlerror ();
- fp = (void *) dlsym (0, symbol);
- if ((error = dlerror ()) != NULL)
- {
- g_critical ("dlerror: %s \n", error);
- }
- else
- {
- arg->v_pointer = fp;
- g_base_info_unref (interface);
- break;
- }
- }
- // Somewhat deprecated from when it was necessary to manually
- // create closure objects...
- else if (JSValueIsObjectOfClass (ctx,
- value,
- seed_native_callback_class))
- {
- SeedNativeClosure *privates =
- (SeedNativeClosure *)
- JSObjectGetPrivate ((JSObjectRef) value);
- arg->v_pointer = privates->closure;
- g_base_info_unref (interface);
- break;
- }
- // Automagically create closure around function passed in as
- // callback.
- else if (JSObjectIsFunction (ctx, (JSObjectRef) value))
- {
- SeedNativeClosure *privates = seed_make_native_closure (ctx,
- (GICallableInfo *) interface,
- value);
- arg->v_pointer = privates->closure;
- g_base_info_unref (interface);
- break;
- }
-
- }
- }
- case GI_TYPE_TAG_ARRAY:
- {
- if (JSValueIsNull (ctx, value))
- {
- arg->v_pointer = NULL;
- break;
- }
- else if (!JSValueIsObject (ctx, value))
- {
- // TODO: FIXME: Is this right?
- return FALSE;
- }
- else
- {
- GITypeInfo *param_type;
- //TODO: FIXME: Better array test like the cool one on reddit.
- guint length =
- seed_value_to_int (ctx, seed_object_get_property (ctx,
- (JSObjectRef)
- value,
- "length"),
- exception);
- if (!length)
- {
- arg->v_pointer = NULL;
- break;
- }
-
- param_type = g_type_info_get_param_type (type_info, 0);
- if (!seed_gi_make_array (ctx, value, length, param_type,
- &arg->v_pointer, exception))
- {
- g_base_info_unref ((GIBaseInfo *) param_type);
- return FALSE;
- }
- g_base_info_unref ((GIBaseInfo *) param_type);
- break;
- }
- }
- case GI_TYPE_TAG_GHASH:
- {
- GITypeInfo *key_param_info, *val_param_info;
- GHashTable *hash_table;
-
- JSPropertyNameArrayRef jsprops = 0;
- JSStringRef jsprop_name;
- JSValueRef jsprop_value;
- int i, nparams = 0;
-
- if (!JSValueIsObject (ctx, value))
- {
- return FALSE;
- }
+ case GI_TYPE_TAG_BOOLEAN:
+ arg->v_boolean = seed_value_to_boolean(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT8:
+ arg->v_int8 = seed_value_to_char(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT8:
+ arg->v_uint8 = seed_value_to_uchar(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT16:
+ arg->v_int16 = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT16:
+ arg->v_uint16 = seed_value_to_uint(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT32:
+ arg->v_int32 = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT32:
+ arg->v_uint32 = seed_value_to_uint(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT64:
+ arg->v_int64 = seed_value_to_int64(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT64:
+ arg->v_uint64 = seed_value_to_uint64(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ arg->v_float = seed_value_to_float(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ arg->v_double = seed_value_to_double(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UTF8:
+ arg->v_string = seed_value_to_string(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_FILENAME:
+ arg->v_string = seed_value_to_filename(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_GTYPE:
+ arg->v_int = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+ GType required_gtype;
+ GObject* gobject;
+
+ interface = g_type_info_get_interface(type_info);
+ interface_type = g_base_info_get_type(interface);
- if (JSValueIsNull (ctx, value))
- {
arg->v_pointer = NULL;
- break;
- }
-
- key_param_info = g_type_info_get_param_type (type_info, 0);
- g_assert(key_param_info != NULL);
- if (g_type_info_get_tag (key_param_info) != GI_TYPE_TAG_UTF8)
- {
- /* Functions requesting a hash table with non-string keys are
- * not supported */
- return FALSE;
- }
-
- val_param_info = g_type_info_get_param_type (type_info, 1);
- g_assert(val_param_info != NULL);
-
- jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) value);
- nparams = JSPropertyNameArrayGetCount (jsprops);
-
- /* keys are strings and the destructor is g_free
- * values will be freed in seed_release_arg
- */
- hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
- for (i = 0; i < nparams; i++)
- {
- char *prop_name;
- int length;
- GArgument hash_arg;
-
- jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
-
- length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
- prop_name = g_malloc (length * sizeof (gchar));
- JSStringGetUTF8CString (jsprop_name, prop_name, length);
-
- jsprop_value = JSObjectGetProperty (ctx,
- (JSObjectRef) value,
- jsprop_name, NULL);
-
- if (!seed_value_to_gi_argument (ctx, jsprop_value,
- val_param_info,
- &hash_arg,
- exception))
- {
- g_hash_table_destroy (hash_table);
- g_base_info_unref ((GIBaseInfo *) val_param_info);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ gobject = seed_value_to_object(ctx, value, exception);
+ required_gtype = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+
+ // FIXME: Not clear if the g_type_is_a check is desired here.
+ // Possibly 'breaks things' when we don't have introspection
+ // data for some things in an interface hierarchy. Hasn't
+ // provided any problems so far.
+ if (!gobject
+ || !g_type_is_a(G_OBJECT_TYPE(gobject), required_gtype)) {
+ g_base_info_unref(interface);
+ return FALSE;
+ }
+
+ arg->v_pointer = gobject;
+ // FIXME: This has to be done for other types too
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ g_object_ref(gobject);
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_ENUM
+ || interface_type == GI_INFO_TYPE_FLAGS) {
+ // this might need fixing...
+ arg->v_long = seed_value_to_long(ctx, value, exception);
+ if (!(interface_type == GI_INFO_TYPE_FLAGS)
+ && !seed_validate_enum((GIEnumInfo*) interface,
+ arg->v_long)) {
+ seed_make_exception(ctx, exception, "EnumRange",
+ "Enum value: %ld is out of range",
+ arg->v_long);
+ g_base_info_unref(interface);
+
+ return FALSE;
+ }
+
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT
+ || interface_type == GI_INFO_TYPE_UNION) {
+ if (JSValueIsObjectOfClass(ctx, value, seed_struct_class))
+ arg->v_pointer = seed_pointer_get_pointer(ctx, value);
+ else if (JSValueIsObjectOfClass(ctx, value, seed_union_class))
+ arg->v_pointer = seed_pointer_get_pointer(ctx, value);
+ else {
+ GType type = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+ if (!type) {
+ g_base_info_unref(interface);
+ return FALSE;
+ } else if (type == G_TYPE_VALUE) {
+ GValue* gval = g_slice_alloc0(sizeof(GValue));
+ seed_value_to_gvalue(ctx, value, (GType) NULL, gval,
+ exception);
+ arg->v_pointer = gval;
+
+ g_base_info_unref(interface);
+ break;
+ }
+ // Automatically convert between functions and
+ // GClosures where expected.
+ else if (g_type_is_a(type, G_TYPE_CLOSURE)) {
+ if (JSObjectIsFunction(ctx, (JSObjectRef) value)) {
+ arg->v_pointer
+ = seed_closure_new(ctx, (JSObjectRef) value, NULL,
+ NULL);
+ }
+ } else {
+ JSObjectRef strukt
+ = seed_construct_struct_type_with_parameters(
+ ctx, interface, (JSObjectRef) value, exception);
+ arg->v_pointer = seed_pointer_get_pointer(ctx, strukt);
+ }
+ }
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_CALLBACK) {
+ if (JSValueIsNull(ctx, value)) {
+ arg->v_pointer = NULL;
+ g_base_info_unref(interface);
+ break;
+ }
+ // Someone passes in a wrapper around a method where a
+ // callback is expected, i.e Clutter.sine_inc_func, as an alpha
+ // Have to dlsym the symbol to be able to do this.
+ // NOTE: Some cases where dlsym(NULL, symbol) doesn't work
+ // depending
+ // On how libseed is loaded.
+ else if (JSValueIsObjectOfClass(ctx, value,
+ gobject_method_class)) {
+ GIFunctionInfo* info
+ = JSObjectGetPrivate((JSObjectRef) value);
+ const gchar* symbol = g_function_info_get_symbol(info);
+ gchar* error;
+ void* fp;
+
+ dlerror();
+ fp = (void*) dlsym(0, symbol);
+ if ((error = dlerror()) != NULL) {
+ g_critical("dlerror: %s \n", error);
+ } else {
+ arg->v_pointer = fp;
+ g_base_info_unref(interface);
+ break;
+ }
+ }
+ // Somewhat deprecated from when it was necessary to manually
+ // create closure objects...
+ else if (JSValueIsObjectOfClass(ctx, value,
+ seed_native_callback_class)) {
+ SeedNativeClosure* privates
+ = (SeedNativeClosure*) JSObjectGetPrivate(
+ (JSObjectRef) value);
+ arg->v_pointer = privates->closure;
+ g_base_info_unref(interface);
+ break;
+ }
+ // Automagically create closure around function passed in as
+ // callback.
+ else if (JSObjectIsFunction(ctx, (JSObjectRef) value)) {
+ SeedNativeClosure* privates
+ = seed_make_native_closure(ctx,
+ (GICallableInfo*) interface,
+ value);
+ arg->v_pointer = privates->closure;
+ g_base_info_unref(interface);
+ break;
+ }
+ }
+ }
+ case GI_TYPE_TAG_ARRAY: {
+ if (JSValueIsNull(ctx, value)) {
+ arg->v_pointer = NULL;
+ break;
+ } else if (JSValueIsString(ctx, value)) {
+ GITypeInfo* param_type;
+ param_type = g_type_info_get_param_type(type_info, 0);
+
+ JSStringRef js_string
+ = JSValueToStringCopy(ctx, value, exception);
+ size_t length = JSStringGetMaximumUTF8CStringSize(js_string);
+ if (!seed_gi_make_array_from_string(ctx, js_string, param_type,
+ length, &arg->v_pointer,
+ out_array_length,
+ exception)) {
+ g_base_info_unref((GIBaseInfo*) param_type);
+ JSStringRelease(js_string);
+ return FALSE;
+ }
+ JSStringRelease(js_string);
+ g_base_info_unref((GIBaseInfo*) param_type);
+ break;
+ } else if (!JSValueIsObject(ctx, value)) {
+ // TODO: FIXME: Is this right?
return FALSE;
- }
+ } else {
+ GITypeInfo* param_type;
+ // TODO: FIXME: Better array test like the cool one on reddit.
+ guint length = seed_value_to_int(
+ ctx,
+ seed_object_get_property(ctx, (JSObjectRef) value, "length"),
+ exception);
+ if (!length) {
+ arg->v_pointer = NULL;
+ break;
+ }
+
+ param_type = g_type_info_get_param_type(type_info, 0);
+ if (!seed_gi_make_array(ctx, value, length, param_type,
+ &arg->v_pointer, exception)) {
+ g_base_info_unref((GIBaseInfo*) param_type);
+ return FALSE;
+ }
+ if (out_array_length != NULL)
+ *out_array_length = length;
+
+ g_base_info_unref((GIBaseInfo*) param_type);
+ break;
+ }
+ }
+ case GI_TYPE_TAG_GHASH: {
+ GITypeInfo *key_param_info, *val_param_info;
+ GHashTable* hash_table;
+
+ JSPropertyNameArrayRef jsprops = 0;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+ int i, nparams = 0;
+
+ if (!JSValueIsObject(ctx, value)) {
+ return FALSE;
+ }
+
+ if (JSValueIsNull(ctx, value)) {
+ arg->v_pointer = NULL;
+ break;
+ }
+
+ key_param_info = g_type_info_get_param_type(type_info, 0);
+ g_assert(key_param_info != NULL);
+ if (g_type_info_get_tag(key_param_info) != GI_TYPE_TAG_UTF8) {
+ /* Functions requesting a hash table with non-string keys are
+ * not supported */
+ return FALSE;
+ }
+
+ val_param_info = g_type_info_get_param_type(type_info, 1);
+ g_assert(val_param_info != NULL);
- g_hash_table_insert (hash_table,
- prop_name,
- hash_arg.v_pointer);
- }
+ jsprops = JSObjectCopyPropertyNames(ctx, (JSObjectRef) value);
+ nparams = JSPropertyNameArrayGetCount(jsprops);
- arg->v_pointer = hash_table;
+ /* keys are strings and the destructor is g_free
+ * values will be freed in seed_release_arg
+ */
+ hash_table
+ = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- break;
- }
- default:
- return FALSE;
+ for (i = 0; i < nparams; i++) {
+ char* prop_name;
+ int length;
+ GArgument hash_arg;
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex(jsprops, i);
+
+ length = JSStringGetMaximumUTF8CStringSize(jsprop_name);
+ prop_name = g_malloc(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsprop_name, prop_name, length);
+
+ jsprop_value = JSObjectGetProperty(ctx, (JSObjectRef) value,
+ jsprop_name, NULL);
+
+ if (!seed_value_to_gi_argument(ctx, jsprop_value,
+ val_param_info,
+ GI_TRANSFER_NOTHING, &hash_arg,
+ exception)) {
+ g_hash_table_destroy(hash_table);
+ g_base_info_unref((GIBaseInfo*) val_param_info);
+ return FALSE;
+ }
+
+ g_hash_table_insert(hash_table, prop_name, hash_arg.v_pointer);
+ }
+
+ arg->v_pointer = hash_table;
+
+ break;
+ }
+ default:
+ return FALSE;
}
- return TRUE;
+ return TRUE;
+}
+gboolean
+seed_value_to_gi_argument(JSContextRef ctx,
+ JSValueRef value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ JSValueRef* exception)
+{
+ return seed_value_to_gi_argument_with_out_length(ctx, value, type_info,
+ transfer, arg, NULL,
+ exception);
}
JSValueRef
-seed_value_from_gi_argument (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception)
+seed_value_from_gi_argument(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception)
{
-
- return seed_value_from_gi_argument_full (
- ctx,
- arg,
- type_info,
- exception,
- 0,
- g_type_info_get_tag (type_info) );
+
+ return seed_value_from_gi_argument_full(ctx, arg, type_info, exception, 0,
+ g_type_info_get_tag(type_info));
}
-
+
JSValueRef
-seed_value_from_gi_argument_full (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception,
- guint64 array_len,
- GITypeTag gi_tag
- )
+seed_value_from_gi_argument_full(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception,
+ guint64 array_len,
+ GITypeTag gi_tag)
{
-
- //seed_value_from_gi_argument_with_length : g_type_tag_to_string(gi_tag)
- SEED_NOTE (INVOCATION,
- "seed_value_from_gi_argument_full: arg_type = %s ",
- g_type_tag_to_string(gi_tag)
- );
- switch (gi_tag)
- {
+ // seed_value_from_gi_argument_with_length : g_type_tag_to_string(gi_tag)
+ SEED_NOTE(INVOCATION, "seed_value_from_gi_argument_full: arg_type = %s ",
+ g_type_tag_to_string(gi_tag));
+
+ switch (gi_tag) {
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- return seed_value_from_long (ctx, arg->v_long, exception);
- case GI_TYPE_TAG_ULONG:
- return seed_value_from_ulong (ctx, arg->v_ulong, exception);
- case GI_TYPE_TAG_INT:
- return seed_value_from_int (ctx, arg->v_int32, exception);
- case GI_TYPE_TAG_UINT:
- return seed_value_from_uint (ctx, arg->v_uint32, exception);
- case GI_TYPE_TAG_SSIZE:
- return seed_value_from_ssize (ctx, arg->v_ssize, exception);
- case GI_TYPE_TAG_SIZE:
- return seed_value_from_size (ctx, arg->v_size, exception);
- case GI_TYPE_TAG_TIME_T:
- return seed_value_from_time_t (ctx, arg->v_long, exception);
+ case GI_TYPE_TAG_LONG:
+ return seed_value_from_long(ctx, arg->v_long, exception);
+ case GI_TYPE_TAG_ULONG:
+ return seed_value_from_ulong(ctx, arg->v_ulong, exception);
+ case GI_TYPE_TAG_INT:
+ return seed_value_from_int(ctx, arg->v_int32, exception);
+ case GI_TYPE_TAG_UINT:
+ return seed_value_from_uint(ctx, arg->v_uint32, exception);
+ case GI_TYPE_TAG_SSIZE:
+ return seed_value_from_ssize(ctx, arg->v_ssize, exception);
+ case GI_TYPE_TAG_SIZE:
+ return seed_value_from_size(ctx, arg->v_size, exception);
+ case GI_TYPE_TAG_TIME_T:
+ return seed_value_from_time_t(ctx, arg->v_long, exception);
#endif
- case GI_TYPE_TAG_VOID:
- return JSValueMakeUndefined (ctx);
- case GI_TYPE_TAG_BOOLEAN:
- return seed_value_from_boolean (ctx, arg->v_boolean, exception);
- case GI_TYPE_TAG_INT8:
- return seed_value_from_char (ctx, arg->v_int8, exception);
- case GI_TYPE_TAG_UINT8:
- return seed_value_from_uchar (ctx, arg->v_uint8, exception);
- case GI_TYPE_TAG_INT16:
- return seed_value_from_int (ctx, arg->v_int16, exception);
- case GI_TYPE_TAG_UINT16:
- return seed_value_from_uint (ctx, arg->v_uint16, exception);
- case GI_TYPE_TAG_INT32:
- return seed_value_from_int (ctx, arg->v_int32, exception);
- case GI_TYPE_TAG_UINT32:
- return seed_value_from_uint (ctx, arg->v_uint32, exception);
- case GI_TYPE_TAG_INT64:
- return seed_value_from_int64 (ctx, arg->v_int64, exception);
- case GI_TYPE_TAG_UINT64:
- return seed_value_from_uint64 (ctx, arg->v_uint64, exception);
- case GI_TYPE_TAG_FLOAT:
- return seed_value_from_float (ctx, arg->v_float, exception);
- case GI_TYPE_TAG_DOUBLE:
- return seed_value_from_double (ctx, arg->v_double, exception);
- case GI_TYPE_TAG_UTF8:
- return seed_value_from_string (ctx, arg->v_string, exception);
- case GI_TYPE_TAG_FILENAME:
- return seed_value_from_filename (ctx, arg->v_string, exception);
- case GI_TYPE_TAG_GTYPE:
- return seed_value_from_int (ctx, arg->v_int, exception);
- case GI_TYPE_TAG_ARRAY:
- {
-
- GIArrayType array_type;
- GITypeInfo *array_type_info;
- JSValueRef ret;
-
- if (arg->v_pointer == NULL)
- return JSValueMakeNull (ctx);
-
- array_type = g_type_info_get_array_type (type_info);
-
- array_type_info = g_type_info_get_param_type (type_info, 0);
-
-
-
- if (array_type == GI_ARRAY_TYPE_PTR_ARRAY)
- {
- JSObjectRef ret_ptr_array;
- GPtrArray *ptr = arg->v_pointer;
- GArgument larg;
- int length = 0;
- int i;
+ case GI_TYPE_TAG_VOID:
+ return JSValueMakeUndefined(ctx);
+ case GI_TYPE_TAG_BOOLEAN:
+ return seed_value_from_boolean(ctx, arg->v_boolean, exception);
+ case GI_TYPE_TAG_INT8:
+ return seed_value_from_char(ctx, arg->v_int8, exception);
+ case GI_TYPE_TAG_UINT8:
+ return seed_value_from_uchar(ctx, arg->v_uint8, exception);
+ case GI_TYPE_TAG_INT16:
+ return seed_value_from_int(ctx, arg->v_int16, exception);
+ case GI_TYPE_TAG_UINT16:
+ return seed_value_from_uint(ctx, arg->v_uint16, exception);
+ case GI_TYPE_TAG_INT32:
+ return seed_value_from_int(ctx, arg->v_int32, exception);
+ case GI_TYPE_TAG_UINT32:
+ return seed_value_from_uint(ctx, arg->v_uint32, exception);
+ case GI_TYPE_TAG_INT64:
+ return seed_value_from_int64(ctx, arg->v_int64, exception);
+ case GI_TYPE_TAG_UINT64:
+ return seed_value_from_uint64(ctx, arg->v_uint64, exception);
+ case GI_TYPE_TAG_FLOAT:
+ return seed_value_from_float(ctx, arg->v_float, exception);
+ case GI_TYPE_TAG_DOUBLE:
+ return seed_value_from_double(ctx, arg->v_double, exception);
+ case GI_TYPE_TAG_UTF8:
+ return seed_value_from_string(ctx, arg->v_string, exception);
+ case GI_TYPE_TAG_FILENAME:
+ return seed_value_from_filename(ctx, arg->v_string, exception);
+ case GI_TYPE_TAG_GTYPE:
+ return seed_value_from_int(ctx, arg->v_int, exception);
+ case GI_TYPE_TAG_ARRAY: {
+
+ GIArrayType array_type;
+ GITypeInfo* array_type_info;
+ JSValueRef ret;
- length = ptr->len;
- ret_ptr_array = JSObjectMakeArray (ctx, 0, NULL, exception);
+ if (arg->v_pointer == NULL)
+ return JSValueMakeNull(ctx);
- for (i = 0; i < length; ++i)
- {
- JSValueRef ival;
+ array_type = g_type_info_get_array_type(type_info);
- larg.v_pointer = g_ptr_array_index(ptr, i);
- ival = (JSValueRef) seed_value_from_gi_argument (ctx, &larg,
- array_type_info, exception);
- if (!ival)
- ival = JSValueMakeNull (ctx);
-
- JSObjectSetPropertyAtIndex (ctx, ret_ptr_array, i, ival, NULL);
- }
-
- g_base_info_unref ((GIBaseInfo *) array_type_info);
-
- return ret_ptr_array;
- }
-
- // technically gir has arrays of bytes, eg.
- // <array length="2" zero-terminated="0" c:type="gchar**"><type name="guint8"/>
- // example : g_file_get_contents..
- // we can treat this as a string.. - it's a bit flakey, we should really use
- // Uint8Array - need to check the webkit API for this..
-
- if (
- !g_type_info_is_zero_terminated (type_info)
- && array_type == GI_ARRAY_TYPE_C
- && GI_TYPE_TAG_UINT8 == g_type_info_get_tag (array_type_info)
- && array_len > 0
- )
- {
- // got a stringy array..
- // we should check g_type_info_get_array_fixed_size
- // we are assuming that this is the array_len from the call..
- g_base_info_unref ((GIBaseInfo *) array_type_info);
-
- ret = seed_value_from_binary_string (ctx, arg->v_pointer, array_len, exception);
- // always free arg... what about when we do not own it...?
- //g_free(arg->v_pointer);
-
- return ret;
-
- }
-
-
- if (!g_type_info_is_zero_terminated (type_info))
- {
- g_base_info_unref ((GIBaseInfo *) array_type_info);
- break;
- }
-
- ret = seed_gi_make_jsarray (ctx, arg->v_pointer, array_type_info,
- exception);
-
- g_base_info_unref ((GIBaseInfo *) array_type_info);
-
- return ret;
- }
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (type_info);
- interface_type = g_base_info_get_type (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- if (arg->v_pointer == 0)
- {
- g_base_info_unref (interface);
- return JSValueMakeNull (ctx);
- }
- g_base_info_unref (interface);
- return seed_value_from_object (ctx, arg->v_pointer, exception);
- }
- else if (interface_type == GI_INFO_TYPE_ENUM)
- {
- JSValueRef ret;
- GITypeTag etype = g_enum_info_get_storage_type (interface);
-
- // needs GITypeInfo - we are sending it GIBaseInfo
-
- ret = seed_value_from_gi_argument_full (
- ctx,
- arg,
- type_info,
- exception,
- 0,
- etype);
- g_base_info_unref (interface);
- return ret;
- }
- else if ( interface_type == GI_INFO_TYPE_FLAGS)
- {
-
- g_base_info_unref (interface);
- return seed_value_from_long (ctx, arg->v_long, exception);
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT)
- {
- JSValueRef strukt;
-
- strukt = seed_make_struct (ctx, arg->v_pointer, interface);
- g_base_info_unref (interface);
-
- return strukt;
- }
- else if (interface_type == GI_INFO_TYPE_CALLBACK)
- {
- /* FIXME: return values of type callback are not handled yet. */
- g_base_info_unref (interface);
- return FALSE;
- }
- /* fall through - other types?? */
- g_base_info_unref (interface);
- return FALSE;
- }
-
- case GI_TYPE_TAG_GLIST:
- {
- GITypeInfo *list_type;
- JSObjectRef ret;
- GArgument larg;
- gint i = 0;
- GList *list = arg->v_pointer;
-
- ret = JSObjectMakeArray (ctx, 0, NULL, exception);
- list_type = g_type_info_get_param_type (type_info, 0);
-
- for (; list != NULL; list = list->next)
- {
- JSValueRef ival;
-
- larg.v_pointer = list->data;
- ival =
- (JSValueRef) seed_value_from_gi_argument (ctx, &larg,
- list_type, exception);
- if (!ival)
- ival = JSValueMakeNull (ctx);
- JSObjectSetPropertyAtIndex (ctx, ret, i, ival, NULL);
- i++;
- }
- return ret;
-
- }
- case GI_TYPE_TAG_GSLIST:
- {
- GITypeInfo *list_type;
- JSObjectRef ret;
- JSValueRef ival;
- GArgument larg;
- guint i = 0;
- GSList *list = arg->v_pointer;
-
- ret = JSObjectMakeArray (ctx, 0, NULL, exception);
- list_type = g_type_info_get_param_type (type_info, 0);
-
- for (; list != NULL; list = list->next)
- {
- larg.v_pointer = list->data;
- ival =
- (JSValueRef) seed_value_from_gi_argument (ctx, &larg,
- list_type, exception);
- if (!ival)
- ival = JSValueMakeNull (ctx);
- JSObjectSetPropertyAtIndex (ctx, ret, i, ival, NULL);
- i++;
- }
- return ret;
- }
- case GI_TYPE_TAG_GHASH:
- {
- GITypeInfo *key_type;
- GITypeTag key_type_tag;
- GITypeInfo *value_type;
- JSObjectRef ret;
- GHashTable *hash_table;
- GHashTableIter iter;
- gpointer key, value;
-
- key_type = g_type_info_get_param_type (type_info, 0);
- key_type_tag = g_type_info_get_tag (key_type);
-
- if ((key_type_tag != GI_TYPE_TAG_UTF8) &&
- (key_type_tag != GI_TYPE_TAG_FILENAME))
- {
- char *error_message = g_strdup_printf ("Unable to make object from hash table indexed with values of type %s", g_type_tag_to_string (key_type_tag));
- seed_make_exception (ctx, exception, "ArgumentError",
- error_message);
- g_free (error_message);
- return JSValueMakeNull (ctx);
- }
-
- value_type = g_type_info_get_param_type (type_info, 1);
-
- ret = JSObjectMake (ctx, NULL, NULL);
-
- hash_table = arg->v_pointer;
- g_hash_table_iter_init (&iter, hash_table);
-
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- JSStringRef js_key;
- GArgument value_arg;
- JSValueRef value_jsval;
-
- js_key = JSStringCreateWithUTF8CString ((const char*) key);
-
- value_arg.v_string = value;
- value_jsval = seed_value_from_gi_argument_full (ctx, &value_arg,
- value_type, exception, 0, key_type_tag);
-
- JSObjectSetProperty (ctx, ret, js_key, value_jsval, 0, NULL);
- }
+ array_type_info = g_type_info_get_param_type(type_info, 0);
- return ret;
- }
- case GI_TYPE_TAG_ERROR:
- {
- JSValueRef ret;
- seed_make_exception_from_gerror (ctx, &ret, (GError*) arg->v_pointer);
- return ret;
- }
+ if (array_type == GI_ARRAY_TYPE_PTR_ARRAY) {
+ JSObjectRef ret_ptr_array;
+ GPtrArray* ptr = arg->v_pointer;
+ GArgument larg;
+ int length = 0;
+ int i;
- default:
- return FALSE;
+ length = ptr->len;
+ ret_ptr_array = JSObjectMakeArray(ctx, 0, NULL, exception);
- }
- return 0;
-}
+ for (i = 0; i < length; ++i) {
+ JSValueRef ival;
-JSValueRef
-seed_value_from_gvalue_for_signal (JSContextRef ctx, GValue * gval,
- JSValueRef * exception,
- GSignalQuery *signal_query, gint arg_n)
-{
- if (!G_IS_VALUE (gval))
- {
- return false;
- }
- switch (G_VALUE_TYPE (gval))
- {
- case G_TYPE_BOOLEAN:
- return seed_value_from_boolean (ctx,
- g_value_get_boolean (gval), exception);
- case G_TYPE_CHAR:
- return seed_value_from_char (ctx, g_value_get_char (gval), exception);
- case G_TYPE_UCHAR:
- return seed_value_from_uchar (ctx, g_value_get_uchar (gval), exception);
- case G_TYPE_INT:
- return seed_value_from_int (ctx, g_value_get_int (gval), exception);
- case G_TYPE_UINT:
- return seed_value_from_uint (ctx, g_value_get_uint (gval), exception);
- case G_TYPE_LONG:
- return seed_value_from_long (ctx, g_value_get_long (gval), exception);
- case G_TYPE_ULONG:
- return seed_value_from_ulong (ctx, g_value_get_ulong (gval), exception);
- case G_TYPE_INT64:
- return seed_value_from_int64 (ctx, g_value_get_int64 (gval), exception);
- case G_TYPE_UINT64:
- return seed_value_from_uint64 (ctx, g_value_get_uint64 (gval),
- exception);
- case G_TYPE_FLOAT:
- return seed_value_from_float (ctx, g_value_get_float (gval), exception);
- case G_TYPE_DOUBLE:
- return seed_value_from_double (ctx, g_value_get_double (gval),
- exception);
- case G_TYPE_STRING:
- return seed_value_from_string (ctx, (gchar *)
- g_value_get_string (gval), exception);
- case G_TYPE_POINTER:
- if (signal_query)
- {
- JSValueRef res;
- GArgument arg;
- GIBaseInfo *obj;
- GISignalInfo *signal_info;
- GIArgInfo *arg_info;
- GITypeInfo type_info;
+ larg.v_pointer = g_ptr_array_index(ptr, i);
+ ival = (JSValueRef) seed_value_from_gi_argument(
+ ctx, &larg, array_type_info, exception);
+ if (!ival)
+ ival = JSValueMakeNull(ctx);
- obj = g_irepository_find_by_gtype(NULL, signal_query->itype);
- if (!obj)
- return NULL;
+ JSObjectSetPropertyAtIndex(ctx, ret_ptr_array, i, ival,
+ NULL);
+ }
- signal_info = g_object_info_find_signal((GIObjectInfo *) obj,
- signal_query->signal_name);
+ g_base_info_unref((GIBaseInfo*) array_type_info);
- if (!signal_info) {
- g_base_info_unref((GIBaseInfo *) obj);
- return NULL;
- }
+ return ret_ptr_array;
+ } else if (array_type == GI_ARRAY_TYPE_C) {
- arg_info = g_callable_info_get_arg(signal_info, arg_n - 1);
- g_arg_info_load_type(arg_info, &type_info);
+ if (g_type_info_is_zero_terminated(type_info)) {
+ GITypeInfo* param_info;
+ param_info = g_type_info_get_param_type(type_info, 0);
+ g_assert(param_info != NULL);
- arg.v_pointer = g_value_get_pointer(gval);
+ ret = seed_array_from_zero_terminated_c_array(
+ ctx, arg->v_pointer, param_info, exception);
- res = seed_value_from_gi_argument (ctx, &arg, &type_info, exception);
+ g_base_info_unref((GIBaseInfo*) param_info);
+ g_base_info_unref((GIBaseInfo*) array_type_info);
- g_base_info_unref((GIBaseInfo*)arg_info);
- g_base_info_unref((GIBaseInfo*)signal_info);
- g_base_info_unref((GIBaseInfo*)obj);
+ return ret;
+ }
+ }
- return res;
+ // technically gir has arrays of bytes, eg.
+ // <array length="2" zero-terminated="0" c:type="gchar**"><type
+ // name="guint8"/>
+ // example : g_file_get_contents..
+ // we can treat this as a string.. - it's a bit flakey, we should
+ // really use
+ // Uint8Array - need to check the webkit API for this..
+
+ if (!g_type_info_is_zero_terminated(type_info)
+ && array_type == GI_ARRAY_TYPE_C
+ && GI_TYPE_TAG_UINT8 == g_type_info_get_tag(array_type_info)
+ && array_len > 0) {
+ // got a stringy array..
+ // we should check g_type_info_get_array_fixed_size
+ // we are assuming that this is the array_len from the call..
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+
+ ret = seed_value_from_binary_string(ctx, arg->v_pointer,
+ array_len, exception);
+ // always free arg... what about when we do not own it...?
+ // g_free(arg->v_pointer);
+
+ return ret;
+ }
+
+ if (!g_type_info_is_zero_terminated(type_info)) {
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+ break;
+ }
+
+ ret = seed_gi_make_jsarray(ctx, arg->v_pointer, array_type_info,
+ exception);
+
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+
+ return ret;
}
- else
- {
- return seed_make_pointer (ctx, g_value_get_pointer (gval));
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(type_info);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ if (arg->v_pointer == 0) {
+ g_base_info_unref(interface);
+ return JSValueMakeNull(ctx);
+ }
+ g_base_info_unref(interface);
+ return seed_value_from_object(ctx, arg->v_pointer, exception);
+ } else if (interface_type == GI_INFO_TYPE_ENUM) {
+ JSValueRef ret;
+ GITypeTag etype = g_enum_info_get_storage_type(interface);
+
+ // needs GITypeInfo - we are sending it GIBaseInfo
+
+ ret = seed_value_from_gi_argument_full(ctx, arg, type_info,
+ exception, 0, etype);
+ g_base_info_unref(interface);
+ return ret;
+ } else if (interface_type == GI_INFO_TYPE_FLAGS) {
+
+ g_base_info_unref(interface);
+ return seed_value_from_long(ctx, arg->v_long, exception);
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+
+ // Trying to find out if this struct can be converted into
+ // GValue
+ // If it can be converted, just send the converted value back to
+ // JS context instead
+ // of the GValue itself.
+ GType gtype = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+ if (G_TYPE_IS_INSTANTIATABLE(gtype)
+ || G_TYPE_IS_INTERFACE(gtype))
+ gtype = G_TYPE_FROM_INSTANCE(arg->v_pointer);
+
+ SEED_NOTE(INVOCATION, "gtype of INTERFACE is %s",
+ g_type_name(gtype));
+ if (g_type_is_a(gtype, G_TYPE_VALUE)) {
+ JSValueRef ret;
+ // We're using seed_value_from_gvalue_for_signal with NULL
+ // signal handler
+ // the current code will only handle basic types.
+ if ((ret = seed_value_from_gvalue_for_signal(
+ ctx, arg->v_pointer, exception, NULL, 0))) {
+ g_base_info_unref(interface);
+ return ret;
+ }
+ }
+
+ JSValueRef strukt;
+
+ strukt = seed_make_struct(ctx, arg->v_pointer, interface);
+ g_base_info_unref(interface);
+
+ return strukt;
+ } else if (interface_type == GI_INFO_TYPE_CALLBACK) {
+ /* FIXME: return values of type callback are not handled yet. */
+ g_base_info_unref(interface);
+ return FALSE;
+ }
+ /* fall through - other types?? */
+ g_base_info_unref(interface);
+ return FALSE;
}
- case G_TYPE_PARAM:
- // Might need to dup and make a boxed.
- return seed_make_pointer (ctx, g_value_get_param (gval));
- }
- if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_STRV))
- {
- return seed_value_from_strv(ctx, g_value_get_boxed (gval), exception);
+ case GI_TYPE_TAG_GLIST: {
+ GITypeInfo* list_type;
+ JSObjectRef ret;
+ GArgument larg;
+ gint i = 0;
+ GList* list = arg->v_pointer;
+
+ ret = JSObjectMakeArray(ctx, 0, NULL, exception);
+ list_type = g_type_info_get_param_type(type_info, 0);
+
+ for (; list != NULL; list = list->next) {
+ JSValueRef ival;
+
+ larg.v_pointer = list->data;
+ ival = (JSValueRef) seed_value_from_gi_argument(ctx, &larg,
+ list_type,
+ exception);
+ if (!ival)
+ ival = JSValueMakeNull(ctx);
+ JSObjectSetPropertyAtIndex(ctx, ret, i, ival, NULL);
+ i++;
+ }
+ return ret;
+ }
+ case GI_TYPE_TAG_GSLIST: {
+ GITypeInfo* list_type;
+ JSObjectRef ret;
+ JSValueRef ival;
+ GArgument larg;
+ guint i = 0;
+ GSList* list = arg->v_pointer;
+
+ ret = JSObjectMakeArray(ctx, 0, NULL, exception);
+ list_type = g_type_info_get_param_type(type_info, 0);
+
+ for (; list != NULL; list = list->next) {
+ larg.v_pointer = list->data;
+ ival = (JSValueRef) seed_value_from_gi_argument(ctx, &larg,
+ list_type,
+ exception);
+ if (!ival)
+ ival = JSValueMakeNull(ctx);
+ JSObjectSetPropertyAtIndex(ctx, ret, i, ival, NULL);
+ i++;
+ }
+ return ret;
+ }
+ case GI_TYPE_TAG_GHASH: {
+ GITypeInfo* key_type;
+ GITypeTag key_type_tag;
+ GITypeInfo* value_type;
+ JSObjectRef ret;
+ GHashTable* hash_table;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ key_type = g_type_info_get_param_type(type_info, 0);
+ key_type_tag = g_type_info_get_tag(key_type);
+
+ if ((key_type_tag != GI_TYPE_TAG_UTF8)
+ && (key_type_tag != GI_TYPE_TAG_FILENAME)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unable to make object from hash table "
+ "indexed with values of type %s",
+ g_type_tag_to_string(key_type_tag));
+ return JSValueMakeNull(ctx);
+ }
+
+ hash_table = arg->v_pointer;
+ if (!hash_table) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Unable to make hash table indexed with values of type %s",
+ g_type_tag_to_string(key_type_tag));
+ return JSValueMakeNull(ctx);
+ }
+
+ value_type = g_type_info_get_param_type(type_info, 1);
+
+ ret = JSObjectMake(ctx, NULL, NULL);
+
+ g_hash_table_iter_init(&iter, hash_table);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ JSStringRef js_key;
+ GArgument value_arg;
+ JSValueRef value_jsval;
+
+ js_key = JSStringCreateWithUTF8CString((const char*) key);
+
+ value_arg.v_string = value;
+ value_jsval
+ = seed_value_from_gi_argument_full(ctx, &value_arg,
+ value_type, exception, 0,
+ key_type_tag);
+
+ JSObjectSetProperty(ctx, ret, js_key, value_jsval, 0, NULL);
+ }
+
+ return ret;
+ }
+ case GI_TYPE_TAG_ERROR: {
+ JSValueRef ret;
+ seed_make_exception_from_gerror(ctx, &ret,
+ (GError*) arg->v_pointer);
+ return ret;
+ }
+
+ default:
+ return FALSE;
}
+ return 0;
+}
+JSValueRef
+seed_value_from_gvalue_for_signal(JSContextRef ctx,
+ GValue* gval,
+ JSValueRef* exception,
+ GSignalQuery* signal_query,
+ gint arg_n)
+{
+ if (!G_IS_VALUE(gval)) {
+ return false;
+ }
+ switch (G_VALUE_TYPE(gval)) {
+ case G_TYPE_BOOLEAN:
+ return seed_value_from_boolean(ctx, g_value_get_boolean(gval),
+ exception);
+ case G_TYPE_CHAR:
+ return seed_value_from_char(ctx, g_value_get_schar(gval),
+ exception);
+ case G_TYPE_UCHAR:
+ return seed_value_from_uchar(ctx, g_value_get_uchar(gval),
+ exception);
+ case G_TYPE_INT:
+ return seed_value_from_int(ctx, g_value_get_int(gval), exception);
+ case G_TYPE_UINT:
+ return seed_value_from_uint(ctx, g_value_get_uint(gval), exception);
+ case G_TYPE_LONG:
+ return seed_value_from_long(ctx, g_value_get_long(gval), exception);
+ case G_TYPE_ULONG:
+ return seed_value_from_ulong(ctx, g_value_get_ulong(gval),
+ exception);
+ case G_TYPE_INT64:
+ return seed_value_from_int64(ctx, g_value_get_int64(gval),
+ exception);
+ case G_TYPE_UINT64:
+ return seed_value_from_uint64(ctx, g_value_get_uint64(gval),
+ exception);
+ case G_TYPE_FLOAT:
+ return seed_value_from_float(ctx, g_value_get_float(gval),
+ exception);
+ case G_TYPE_DOUBLE:
+ return seed_value_from_double(ctx, g_value_get_double(gval),
+ exception);
+ case G_TYPE_STRING:
+ return seed_value_from_string(ctx,
+ (gchar*) g_value_get_string(gval),
+ exception);
+ case G_TYPE_POINTER:
+ if (signal_query) {
+ JSValueRef res;
+ GArgument arg;
+ GIBaseInfo* obj;
+ GISignalInfo* signal_info;
+ GIArgInfo* arg_info;
+ GITypeInfo type_info;
+
+ obj = g_irepository_find_by_gtype(NULL, signal_query->itype);
+ if (!obj)
+ return NULL;
+
+ signal_info
+ = g_object_info_find_signal((GIObjectInfo*) obj,
+ signal_query->signal_name);
+
+ if (!signal_info) {
+ g_base_info_unref((GIBaseInfo*) obj);
+ return NULL;
+ }
+
+ arg_info = g_callable_info_get_arg(signal_info, arg_n - 1);
+ g_arg_info_load_type(arg_info, &type_info);
+
+ arg.v_pointer = g_value_get_pointer(gval);
+
+ res = seed_value_from_gi_argument(ctx, &arg, &type_info,
+ exception);
+
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ g_base_info_unref((GIBaseInfo*) signal_info);
+ g_base_info_unref((GIBaseInfo*) obj);
+
+ return res;
+ } else {
+ return seed_make_pointer(ctx, g_value_get_pointer(gval));
+ }
+ case G_TYPE_PARAM:
+ // Might need to dup and make a boxed.
+ return seed_make_pointer(ctx, g_value_get_param(gval));
+ }
- if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_ENUM) ||
- g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_FLAGS))
- return seed_value_from_long (ctx, gval->data[0].v_long, exception);
- else if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_ENUM))
- return seed_value_from_long (ctx, gval->data[0].v_long, exception);
- else if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_OBJECT))
- {
- GObject *obj = g_value_get_object (gval);
- return seed_value_from_object (ctx, obj, exception);
+ if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_STRV)) {
+ return seed_value_from_strv(ctx, (GStrv*) g_value_get_boxed(gval),
+ exception);
}
- else
- {
- GIBaseInfo *info;
- GIInfoType type;
-
- info = g_irepository_find_by_gtype (0, G_VALUE_TYPE (gval));
- if (!info)
- return FALSE;
- type = g_base_info_get_type (info);
-
- if (type == GI_INFO_TYPE_UNION)
- {
- return seed_make_union (ctx, g_value_peek_pointer (gval), info);
- }
- else if (type == GI_INFO_TYPE_STRUCT)
- {
- return seed_make_struct (ctx, g_value_peek_pointer (gval), info);
- }
- else if (type == GI_INFO_TYPE_BOXED)
- {
- return seed_make_boxed (ctx, g_value_dup_boxed (gval), info);
- }
+ if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM)
+ || g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_FLAGS))
+ return seed_value_from_long(ctx, gval->data[0].v_long, exception);
+ else if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM))
+ return seed_value_from_long(ctx, gval->data[0].v_long, exception);
+ else if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_OBJECT)) {
+ GObject* obj = g_value_get_object(gval);
+ return seed_value_from_object(ctx, obj, exception);
+ } else {
+ GIBaseInfo* info;
+ GIInfoType type;
+
+ info = g_irepository_find_by_gtype(0, G_VALUE_TYPE(gval));
+ if (!info)
+ return FALSE;
+ type = g_base_info_get_type(info);
+
+ if (type == GI_INFO_TYPE_UNION) {
+ return seed_make_union(ctx, g_value_peek_pointer(gval), info);
+ } else if (type == GI_INFO_TYPE_STRUCT) {
+ return seed_make_struct(ctx, g_value_peek_pointer(gval), info);
+ } else if (type == GI_INFO_TYPE_BOXED) {
+ return seed_make_boxed(ctx, g_value_dup_boxed(gval), info);
+ }
}
- return NULL;
+ return NULL;
}
JSValueRef
-seed_value_from_gvalue (JSContextRef ctx,
- GValue * gval, JSValueRef * exception)
+seed_value_from_gvalue(JSContextRef ctx, GValue* gval, JSValueRef* exception)
{
- return seed_value_from_gvalue_for_signal(ctx, gval, exception, NULL, 0);
+ return seed_value_from_gvalue_for_signal(ctx, gval, exception, NULL, 0);
}
gboolean
-seed_value_to_gvalue (JSContextRef ctx,
- JSValueRef val,
- GType type, GValue * ret, JSValueRef * exception)
+seed_value_to_gvalue(JSContextRef ctx,
+ JSValueRef val,
+ GType type,
+ GValue* ret,
+ JSValueRef* exception)
{
- if (G_IS_VALUE (ret))
- g_value_unset (ret);
-
- if (type == G_TYPE_STRV)
- {
- gchar **result;
- JSValueRef jslen;
- guint length, i;
-
- if (JSValueIsNull (ctx, val) || !JSValueIsObject (ctx, val))
- return FALSE;
-
- jslen = seed_object_get_property (ctx, (JSObjectRef) val, "length");
- length = seed_value_to_uint (ctx, jslen, exception);
-
- result = g_new0 (gchar *, length+1);
-
- for (i = 0; i < length; i++)
- {
- result[i] = seed_value_to_string (ctx,
- JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- val,
- i,
- exception),
- exception);
-
- }
- result[i] = 0;
-
- g_value_init (ret, G_TYPE_STRV);
- g_value_take_boxed (ret, result);
-
- return TRUE;
- }
- else if (g_type_is_a (type, G_TYPE_ENUM) && JSValueIsNumber (ctx, val))
- {
- g_value_init (ret, type);
- g_value_set_enum (ret, seed_value_to_long (ctx, val, exception));
- return TRUE;
- }
- else if (g_type_is_a (type, G_TYPE_FLAGS) && JSValueIsNumber (ctx, val))
- {
- g_value_init (ret, type);
- g_value_set_flags (ret, seed_value_to_long (ctx, val, exception));
- return TRUE;
- }
- else if (g_type_is_a (type, G_TYPE_OBJECT)
- && (JSValueIsNull (ctx, val) || seed_value_is_gobject (ctx, val)))
- {
- GObject *o = seed_value_to_object (ctx,
- val, exception);
-
- if (o == NULL || g_type_is_a (G_OBJECT_TYPE (o), type))
- {
- g_value_init (ret, type);
- g_value_set_object (ret, o);
-
- return TRUE;
- }
+ if (G_IS_VALUE(ret))
+ g_value_unset(ret);
+
+ if (type == G_TYPE_STRV) {
+ gchar** result;
+ JSValueRef jslen;
+ guint length, i;
+
+ if (JSValueIsNull(ctx, val) || !JSValueIsObject(ctx, val))
+ return FALSE;
+
+ jslen = seed_object_get_property(ctx, (JSObjectRef) val, "length");
+ length = seed_value_to_uint(ctx, jslen, exception);
+
+ result = g_new0(gchar*, length + 1);
+
+ for (i = 0; i < length; i++) {
+ result[i] = seed_value_to_string(
+ ctx,
+ JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) val, i, exception),
+ exception);
+ }
+ result[i] = 0;
+
+ g_value_init(ret, G_TYPE_STRV);
+ g_value_take_boxed(ret, result);
+
+ return TRUE;
+ } else if (g_type_is_a(type, G_TYPE_ENUM) && JSValueIsNumber(ctx, val)) {
+ g_value_init(ret, type);
+ g_value_set_enum(ret, seed_value_to_long(ctx, val, exception));
+ return TRUE;
+ } else if (g_type_is_a(type, G_TYPE_FLAGS) && JSValueIsNumber(ctx, val)) {
+ g_value_init(ret, type);
+ g_value_set_flags(ret, seed_value_to_long(ctx, val, exception));
+ return TRUE;
+ } else if (g_type_is_a(type, G_TYPE_OBJECT)
+ && (JSValueIsNull(ctx, val)
+ || seed_value_is_gobject(ctx, val))) {
+ GObject* o = seed_value_to_object(ctx, val, exception);
+
+ if (o == NULL || g_type_is_a(G_OBJECT_TYPE(o), type)) {
+ g_value_init(ret, type);
+ g_value_set_object(ret, o);
+
+ return TRUE;
+ }
}
- /* Boxed handling is broken. Will be fixed in struct overhall. */
- else if (g_type_is_a (type, G_TYPE_BOXED))
- {
- gpointer p = seed_pointer_get_pointer (ctx, val);
- if (p)
- {
- g_value_init (ret, type);
- g_value_set_boxed (ret, p);
- return TRUE;
- }
- else
- {
- if (JSValueIsObject (ctx, val))
- {
- GIBaseInfo *info = g_irepository_find_by_gtype (0, type);
- JSObjectRef new_struct;
- if (!info)
- return FALSE;
-
- new_struct =
- seed_construct_struct_type_with_parameters (ctx,
- info,
- (JSObjectRef)
- val, exception);
- p = seed_pointer_get_pointer (ctx, new_struct);
- if (p)
- {
- g_value_init (ret, type);
- g_value_set_boxed (ret, p);
- g_base_info_unref (info);
- return TRUE;
- }
- g_base_info_unref (info);
- }
- }
+ /* Boxed handling is broken. Will be fixed in struct overhall. */
+ else if (g_type_is_a(type, G_TYPE_BOXED)) {
+ gpointer p = seed_pointer_get_pointer(ctx, val);
+ if (p) {
+ g_value_init(ret, type);
+ g_value_set_boxed(ret, p);
+ return TRUE;
+ } else {
+ if (JSValueIsObject(ctx, val)) {
+ GIBaseInfo* info = g_irepository_find_by_gtype(0, type);
+ JSObjectRef new_struct;
+ if (!info)
+ return FALSE;
+
+ new_struct = seed_construct_struct_type_with_parameters(
+ ctx, info, (JSObjectRef) val, exception);
+ p = seed_pointer_get_pointer(ctx, new_struct);
+ if (p) {
+ g_value_init(ret, type);
+ g_value_set_boxed(ret, p);
+ g_base_info_unref(info);
+ return TRUE;
+ }
+ g_base_info_unref(info);
+ }
+ }
}
- switch (type)
- {
- case G_TYPE_BOOLEAN:
- {
- g_value_init (ret, G_TYPE_BOOLEAN);
- g_value_set_boolean (ret, seed_value_to_boolean (ctx,
- val, exception));
- return TRUE;
- }
- case G_TYPE_INT:
- case G_TYPE_UINT:
- {
- g_value_init (ret, type);
- if (type == G_TYPE_INT)
- g_value_set_int (ret, seed_value_to_int (ctx, val, exception));
- else
- g_value_set_uint (ret, seed_value_to_uint (ctx, val, exception));
- return TRUE;
- }
- case G_TYPE_CHAR:
- {
- g_value_init (ret, G_TYPE_CHAR);
- g_value_set_char (ret, seed_value_to_char (ctx, val, exception));
- return TRUE;
- }
- case G_TYPE_UCHAR:
- {
- g_value_init (ret, G_TYPE_UCHAR);
- g_value_set_uchar (ret, seed_value_to_uchar (ctx, val, exception));
- return TRUE;
- }
- case G_TYPE_LONG:
- case G_TYPE_ULONG:
- case G_TYPE_INT64:
- case G_TYPE_UINT64:
- case G_TYPE_FLOAT:
- case G_TYPE_DOUBLE:
- {
- switch (type)
- {
- case G_TYPE_LONG:
- g_value_init (ret, G_TYPE_LONG);
- g_value_set_long (ret, seed_value_to_long (ctx, val, exception));
- break;
- case G_TYPE_ULONG:
- g_value_init (ret, G_TYPE_ULONG);
- g_value_set_ulong (ret, seed_value_to_ulong (ctx,
- val, exception));
- break;
- case G_TYPE_INT64:
- g_value_init (ret, G_TYPE_INT64);
- g_value_set_int64 (ret, seed_value_to_int64 (ctx,
- val, exception));
- break;
- case G_TYPE_UINT64:
- g_value_init (ret, G_TYPE_UINT64);
- g_value_set_uint64 (ret, seed_value_to_uint64 (ctx,
- val, exception));
- break;
- case G_TYPE_FLOAT:
- g_value_init (ret, G_TYPE_FLOAT);
- g_value_set_float (ret, seed_value_to_float (ctx,
- val, exception));
- break;
- case G_TYPE_DOUBLE:
- g_value_init (ret, G_TYPE_DOUBLE);
- g_value_set_double (ret, seed_value_to_double (ctx,
- val, exception));
- break;
- }
- return TRUE;
- }
- case G_TYPE_STRING:
- {
- gchar *cval = seed_value_to_string (ctx, val, exception);
-
- g_value_init (ret, G_TYPE_STRING);
- g_value_take_string (ret, cval);
-
- return TRUE;
- }
- default:
- {
- // TODO: FIXME: This whole undefined type area
- // needs some heaaavy improvement.
-
- if (type == 0 && seed_value_is_gobject(ctx, val))
- {
- GObject *o = seed_value_to_object (ctx, val, exception);
-
- g_value_init (ret, G_OBJECT_TYPE(o));
- g_value_set_object (ret, o);
- return TRUE;
- }
- // Support [GObject.TYPE_INT, 3]
- // TODO: FIXME: Might crash.
- else if (type == 0 && JSValueIsObject (ctx, val))
- {
- // TODO: FIXME: Better array test like the cool one on reddit.
- guint length = seed_value_to_int (ctx,
- seed_object_get_property (ctx,
- (JSObjectRef) val,
- "length"),
- exception);
-
- if (length)
- {
- type =
- seed_value_to_int (ctx,
- JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- val, 0,
- exception),
- exception);
- val =
- JSObjectGetPropertyAtIndex (ctx, (JSObjectRef) val, 1,
- exception);
- if (type) // Prevents recursion.
- {
- return seed_value_to_gvalue (ctx, val,
- type, ret, exception);
- }
- // TODO: FIXME: Handle better?
- else
- g_assert_not_reached ();
- }
- }
- switch (JSValueGetType (ctx, val))
- {
- case kJSTypeBoolean:
- {
- g_value_init (ret, G_TYPE_BOOLEAN);
- g_value_set_boolean (ret,
- seed_value_to_boolean (ctx,
- val, exception));
- return TRUE;
- }
- case kJSTypeNumber:
- {
- g_value_init (ret, G_TYPE_DOUBLE);
- g_value_set_double (ret,
- seed_value_to_double (ctx, val, exception));
- return TRUE;
- }
- case kJSTypeString:
- {
- gchar *cv = seed_value_to_string (ctx, val,
- exception);
-
- g_value_init (ret, G_TYPE_STRING);
- g_value_take_string (ret, cv);
- return TRUE;
- }
- default:
- break;
- }
- break;
- }
+ switch (type) {
+ case G_TYPE_BOOLEAN: {
+ g_value_init(ret, G_TYPE_BOOLEAN);
+ g_value_set_boolean(ret,
+ seed_value_to_boolean(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_INT:
+ case G_TYPE_UINT: {
+ g_value_init(ret, type);
+ if (type == G_TYPE_INT)
+ g_value_set_int(ret, seed_value_to_int(ctx, val, exception));
+ else
+ g_value_set_uint(ret, seed_value_to_uint(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_CHAR: {
+ g_value_init(ret, G_TYPE_CHAR);
+ g_value_set_schar(ret, seed_value_to_char(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_UCHAR: {
+ g_value_init(ret, G_TYPE_UCHAR);
+ g_value_set_uchar(ret, seed_value_to_uchar(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_LONG:
+ case G_TYPE_ULONG:
+ case G_TYPE_INT64:
+ case G_TYPE_UINT64:
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE: {
+ switch (type) {
+ case G_TYPE_LONG:
+ g_value_init(ret, G_TYPE_LONG);
+ g_value_set_long(ret,
+ seed_value_to_long(ctx, val, exception));
+ break;
+ case G_TYPE_ULONG:
+ g_value_init(ret, G_TYPE_ULONG);
+ g_value_set_ulong(ret,
+ seed_value_to_ulong(ctx, val, exception));
+ break;
+ case G_TYPE_INT64:
+ g_value_init(ret, G_TYPE_INT64);
+ g_value_set_int64(ret,
+ seed_value_to_int64(ctx, val, exception));
+ break;
+ case G_TYPE_UINT64:
+ g_value_init(ret, G_TYPE_UINT64);
+ g_value_set_uint64(ret, seed_value_to_uint64(ctx, val,
+ exception));
+ break;
+ case G_TYPE_FLOAT:
+ g_value_init(ret, G_TYPE_FLOAT);
+ g_value_set_float(ret,
+ seed_value_to_float(ctx, val, exception));
+ break;
+ case G_TYPE_DOUBLE:
+ g_value_init(ret, G_TYPE_DOUBLE);
+ g_value_set_double(ret, seed_value_to_double(ctx, val,
+ exception));
+ break;
+ }
+ return TRUE;
+ }
+ case G_TYPE_STRING: {
+ gchar* cval = seed_value_to_string(ctx, val, exception);
+
+ g_value_init(ret, G_TYPE_STRING);
+ g_value_take_string(ret, cval);
+
+ return TRUE;
+ }
+ default: {
+ // TODO: FIXME: This whole undefined type area
+ // needs some heaaavy improvement.
+
+ if (type == 0 && seed_value_is_gobject(ctx, val)) {
+ GObject* o = seed_value_to_object(ctx, val, exception);
+
+ g_value_init(ret, G_OBJECT_TYPE(o));
+ g_value_set_object(ret, o);
+ return TRUE;
+ }
+ // Support [GObject.TYPE_INT, 3]
+ // TODO: FIXME: Might crash.
+ else if (type == 0 && JSValueIsObject(ctx, val)) {
+ // TODO: FIXME: Better array test like the cool one on reddit.
+ guint length = seed_value_to_int(
+ ctx,
+ seed_object_get_property(ctx, (JSObjectRef) val, "length"),
+ exception);
+
+ if (length) {
+ type = seed_value_to_int(
+ ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) val, 0,
+ exception),
+ exception);
+ val = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) val, 1,
+ exception);
+ if (type) // Prevents recursion.
+ {
+ return seed_value_to_gvalue(ctx, val, type, ret,
+ exception);
+ }
+ // TODO: FIXME: Handle better?
+ else
+ g_assert_not_reached();
+ }
+ }
+ switch (JSValueGetType(ctx, val)) {
+ case kJSTypeBoolean: {
+ g_value_init(ret, G_TYPE_BOOLEAN);
+ g_value_set_boolean(ret, seed_value_to_boolean(ctx, val,
+ exception));
+ return TRUE;
+ }
+ case kJSTypeNumber: {
+ g_value_init(ret, G_TYPE_DOUBLE);
+ g_value_set_double(ret, seed_value_to_double(ctx, val,
+ exception));
+ return TRUE;
+ }
+ case kJSTypeString: {
+ gchar* cv = seed_value_to_string(ctx, val, exception);
+
+ g_value_init(ret, G_TYPE_STRING);
+ g_value_take_string(ret, cv);
+ return TRUE;
+ }
+ default:
+ break;
+ }
+ break;
+ }
}
- return FALSE;
+ return FALSE;
}
/**
@@ -1665,18 +1692,15 @@ seed_value_to_gvalue (JSContextRef ctx,
* Returns: The value of the property or the undefined value
*/
JSValueRef
-seed_object_get_property (JSContextRef ctx,
- JSObjectRef val, const gchar * name)
+seed_object_get_property(JSContextRef ctx, JSObjectRef val, const gchar* name)
{
- JSStringRef jname = JSStringCreateWithUTF8CString (name);
- JSValueRef ret = JSObjectGetProperty (ctx,
- (JSObjectRef) val,
- jname, NULL);
+ JSStringRef jname = JSStringCreateWithUTF8CString(name);
+ JSValueRef ret = JSObjectGetProperty(ctx, (JSObjectRef) val, jname, NULL);
- JSStringRelease (jname);
+ JSStringRelease(jname);
- return ret;
+ return ret;
}
/**
@@ -1689,21 +1713,22 @@ seed_object_get_property (JSContextRef ctx,
* Returns: %TRUE on success, %FALSE otherwise.
*/
gboolean
-seed_object_set_property (JSContextRef ctx, JSObjectRef object,
- const gchar * name, JSValueRef value)
+seed_object_set_property(JSContextRef ctx,
+ JSObjectRef object,
+ const gchar* name,
+ JSValueRef value)
{
- JSStringRef jname = JSStringCreateWithUTF8CString (name);
- JSValueRef exception = NULL;
+ JSStringRef jname = JSStringCreateWithUTF8CString(name);
+ JSValueRef exception = NULL;
- if (value)
- {
- JSObjectSetProperty (ctx, (JSObjectRef) object, jname, value, 0,
- &exception);
+ if (value) {
+ JSObjectSetProperty(ctx, (JSObjectRef) object, jname, value, 0,
+ &exception);
}
- JSStringRelease (jname);
+ JSStringRelease(jname);
- return TRUE;
+ return TRUE;
}
/* TODO: Make some macros or something for making exceptions, code is littered
@@ -1723,22 +1748,19 @@ seed_object_set_property (JSContextRef ctx, JSObjectRef object,
*
*/
gboolean
-seed_value_to_boolean (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+seed_value_to_boolean(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsBoolean (ctx, val) && !JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- {
- seed_make_exception (eng->context, exception, "ConversionError",
- "Can not convert Javascript value to boolean");
- return FALSE;
- }
-
- return FALSE;
+ if (!JSValueIsBoolean(ctx, val) && !JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val)) {
+ seed_make_exception(eng->context, exception, "ConversionError",
+ "Can not convert Javascript value to boolean");
+ return FALSE;
+ }
+
+ return FALSE;
}
- return JSValueToBoolean (ctx, val);
+ return JSValueToBoolean(ctx, val);
}
/**
@@ -1754,10 +1776,9 @@ seed_value_to_boolean (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_boolean (JSContextRef ctx,
- gboolean val, JSValueRef * exception)
+seed_value_from_boolean(JSContextRef ctx, gboolean val, JSValueRef* exception)
{
- return JSValueMakeBoolean (ctx, val);
+ return JSValueMakeBoolean(ctx, val);
}
/**
@@ -1773,20 +1794,18 @@ seed_value_from_boolean (JSContextRef ctx,
*
*/
guint
-seed_value_to_uint (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_uint(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to"
- " boolean");
- }
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val)) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " boolean");
+ }
+ return 0;
}
- return (guint) JSValueToNumber (ctx, val, NULL);
+ return (guint) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -1802,9 +1821,9 @@ seed_value_to_uint (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_uint (JSContextRef ctx, guint val, JSValueRef * exception)
+seed_value_from_uint(JSContextRef ctx, guint val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1820,17 +1839,17 @@ seed_value_from_uint (JSContextRef ctx, guint val, JSValueRef * exception)
*
*/
gint
-seed_value_to_int (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_int(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " int");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " int");
+ return 0;
}
- return (gint) JSValueToNumber (ctx, val, NULL);
+ return (gint) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -1846,9 +1865,9 @@ seed_value_to_int (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_int (JSContextRef ctx, gint val, JSValueRef * exception)
+seed_value_from_int(JSContextRef ctx, gint val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1864,28 +1883,27 @@ seed_value_from_int (JSContextRef ctx, gint val, JSValueRef * exception)
*
*/
gchar
-seed_value_to_char (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_char(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- gint cv;
-
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gchar");
- return 0;
+ gint cv;
+
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gchar");
+ return 0;
}
- cv = JSValueToNumber (ctx, val, NULL);
+ cv = JSValueToNumber(ctx, val, NULL);
- if (cv < G_MININT8 || cv > G_MAXINT8)
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Javascript number out of range of gchar");
- return 0;
+ if (cv < G_MININT8 || cv > G_MAXINT8) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Javascript number out of range of gchar");
+ return 0;
}
- return (gchar) cv;
+ return (gchar) cv;
}
/**
@@ -1901,9 +1919,9 @@ seed_value_to_char (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_char (JSContextRef ctx, gchar val, JSValueRef * exception)
+seed_value_from_char(JSContextRef ctx, gchar val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1919,28 +1937,27 @@ seed_value_from_char (JSContextRef ctx, gchar val, JSValueRef * exception)
*
*/
guchar
-seed_value_to_uchar (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_uchar(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- guint cv;
-
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " guchar");
- return 0;
+ guint cv;
+
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " guchar");
+ return 0;
}
- cv = JSValueToNumber (ctx, val, NULL);
+ cv = JSValueToNumber(ctx, val, NULL);
- if (cv > G_MAXUINT8)
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Javascript number out of range of guchar");
- return 0;
+ if (cv > G_MAXUINT8) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Javascript number out of range of guchar");
+ return 0;
}
- return (guchar) cv;
+ return (guchar) cv;
}
/**
@@ -1956,9 +1973,9 @@ seed_value_to_uchar (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_uchar (JSContextRef ctx, guchar val, JSValueRef * exception)
+seed_value_from_uchar(JSContextRef ctx, guchar val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1974,17 +1991,17 @@ seed_value_from_uchar (JSContextRef ctx, guchar val, JSValueRef * exception)
*
*/
gshort
-seed_value_to_short (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_short(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " short");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " short");
+ return 0;
}
- return (gshort) JSValueToNumber (ctx, val, NULL);
+ return (gshort) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2000,9 +2017,9 @@ seed_value_to_short (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_short (JSContextRef ctx, gshort val, JSValueRef * exception)
+seed_value_from_short(JSContextRef ctx, gshort val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2018,18 +2035,17 @@ seed_value_from_short (JSContextRef ctx, gshort val, JSValueRef * exception)
*
*/
gushort
-seed_value_to_ushort (JSContextRef ctx, JSValueRef val,
- JSValueRef * exception)
+seed_value_to_ushort(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " ushort");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " ushort");
+ return 0;
}
- return (gushort) JSValueToNumber (ctx, val, NULL);
+ return (gushort) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2045,9 +2061,9 @@ seed_value_to_ushort (JSContextRef ctx, JSValueRef val,
*
*/
JSValueRef
-seed_value_from_ushort (JSContextRef ctx, gushort val, JSValueRef * exception)
+seed_value_from_ushort(JSContextRef ctx, gushort val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2063,35 +2079,35 @@ seed_value_from_ushort (JSContextRef ctx, gushort val, JSValueRef * exception)
*
*/
glong
-seed_value_to_long (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_long(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " long");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " long");
+ return 0;
}
- return (glong) JSValueToNumber (ctx, val, NULL);
+ return (glong) JSValueToNumber(ctx, val, NULL);
}
- /**
- * seed_value_from_long:
- * @ctx: A #SeedContext.
- * @val: The #glong to represent.
- * @exception: A reference to a #SeedValue in which to store any exceptions.
- * Pass %NULL to ignore exceptions.
- *
- * Converts the given #glong into a #SeedValue.
- *
- * Return value: A #SeedValue which represents @val.
- *
- */
+/**
+* seed_value_from_long:
+* @ctx: A #SeedContext.
+* @val: The #glong to represent.
+* @exception: A reference to a #SeedValue in which to store any exceptions.
+* Pass %NULL to ignore exceptions.
+*
+* Converts the given #glong into a #SeedValue.
+*
+* Return value: A #SeedValue which represents @val.
+*
+*/
JSValueRef
-seed_value_from_long (JSContextRef ctx, glong val, JSValueRef * exception)
+seed_value_from_long(JSContextRef ctx, glong val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2107,18 +2123,18 @@ seed_value_from_long (JSContextRef ctx, glong val, JSValueRef * exception)
*
*/
gulong
-seed_value_to_ulong (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_ulong(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " ulong");
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " ulong");
- return 0;
+ return 0;
}
- return (gulong) JSValueToNumber (ctx, val, NULL);
+ return (gulong) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2134,9 +2150,9 @@ seed_value_to_ulong (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_ulong (JSContextRef ctx, gulong val, JSValueRef * exception)
+seed_value_from_ulong(JSContextRef ctx, gulong val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2152,18 +2168,18 @@ seed_value_from_ulong (JSContextRef ctx, gulong val, JSValueRef * exception)
*
*/
gint64
-seed_value_to_int64 (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_int64(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gint64");
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gint64");
- return 0;
+ return 0;
}
- return (gint64) JSValueToNumber (ctx, val, NULL);
+ return (gint64) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2179,9 +2195,9 @@ seed_value_to_int64 (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_int64 (JSContextRef ctx, gint64 val, JSValueRef * exception)
+seed_value_from_int64(JSContextRef ctx, gint64 val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2197,20 +2213,18 @@ seed_value_from_int64 (JSContextRef ctx, gint64 val, JSValueRef * exception)
*
*/
guint64
-seed_value_to_uint64 (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+seed_value_to_uint64(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to"
- " guint64");
-
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " guint64");
+
+ return 0;
}
- return (guint64) JSValueToNumber (ctx, val, NULL);
+ return (guint64) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2226,9 +2240,9 @@ seed_value_to_uint64 (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_uint64 (JSContextRef ctx, guint64 val, JSValueRef * exception)
+seed_value_from_uint64(JSContextRef ctx, guint64 val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2244,17 +2258,17 @@ seed_value_from_uint64 (JSContextRef ctx, guint64 val, JSValueRef * exception)
*
*/
gfloat
-seed_value_to_float (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_float(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gfloat");
- return 0;
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gfloat");
+ return 0;
}
- return (gfloat) JSValueToNumber (ctx, val, NULL);
+ return (gfloat) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2270,9 +2284,9 @@ seed_value_to_float (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_float (JSContextRef ctx, gfloat val, JSValueRef * exception)
+seed_value_from_float(JSContextRef ctx, gfloat val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2288,18 +2302,17 @@ seed_value_from_float (JSContextRef ctx, gfloat val, JSValueRef * exception)
*
*/
gdouble
-seed_value_to_double (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+seed_value_to_double(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " double");
- return 0;
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " double");
+ return 0;
}
- return (gdouble) JSValueToNumber (ctx, val, NULL);
+ return (gdouble) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2315,9 +2328,9 @@ seed_value_to_double (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_double (JSContextRef ctx, gdouble val, JSValueRef * exception)
+seed_value_from_double(JSContextRef ctx, gdouble val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2333,17 +2346,17 @@ seed_value_from_double (JSContextRef ctx, gdouble val, JSValueRef * exception)
*
*/
gsize
-seed_value_to_size (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_size(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gsize");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gsize");
+ return 0;
}
- return (gsize) JSValueToNumber (ctx, val, NULL);
+ return (gsize) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2359,9 +2372,9 @@ seed_value_to_size (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_size (JSContextRef ctx, gsize val, JSValueRef * exception)
+seed_value_from_size(JSContextRef ctx, gsize val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2377,17 +2390,17 @@ seed_value_from_size (JSContextRef ctx, gsize val, JSValueRef * exception)
*
*/
gssize
-seed_value_to_ssize (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_ssize(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gssize");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gssize");
+ return 0;
}
- return (gssize) JSValueToNumber (ctx, val, NULL);
+ return (gssize) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2403,9 +2416,9 @@ seed_value_to_ssize (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
+seed_value_from_ssize(JSContextRef ctx, gssize val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2422,7 +2435,7 @@ seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
* "[undefined]"; if it represents JavaScript's null value, this returns
* "[null]".
*
- * If the #SeedValue is a number or a boolean, it is printed as a double, with
+ * If the #SeedValue is a number or a boolean, it is printed as a double, with
* the printf format string "%.15g".
*
* If the #SeedValue is an object, the string returned is that obtained by
@@ -2431,57 +2444,46 @@ seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
* Return value: The #gchar* represented by @val.
*
*/
-gchar *
-seed_value_to_string (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+gchar*
+seed_value_to_string(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- JSStringRef jsstr = NULL;
- JSValueRef func;
- gchar *buf = NULL;
- gint length;
+ JSStringRef jsstr = NULL;
+ JSValueRef func;
+ gchar* buf = NULL;
+ gint length;
+
+ if (val == NULL)
+ return NULL;
+ else if (JSValueIsUndefined(ctx, val)) {
+ buf = g_strdup("[undefined]");
+ } else if (JSValueIsNull(ctx, val)) {
+ buf = g_strdup("[null]");
+ } else if (JSValueIsBoolean(ctx, val) || JSValueIsNumber(ctx, val)) {
+ buf = g_strdup_printf("%.15g", JSValueToNumber(ctx, val, NULL));
+ } else {
+ if (!JSValueIsString(ctx, val)) // In this case,
+ // it's an object
+ {
+ func = seed_object_get_property(ctx, (JSObjectRef) val, "toString");
- if (val == NULL)
- return NULL;
- else if (JSValueIsUndefined (ctx, val))
- {
- buf = g_strdup ("[undefined]");
- }
- else if (JSValueIsNull (ctx, val))
- {
- buf = g_strdup ("[null]");
- }
- else if (JSValueIsBoolean (ctx, val) || JSValueIsNumber (ctx, val))
- {
- buf = g_strdup_printf ("%.15g", JSValueToNumber (ctx, val, NULL));
- }
- else
- {
- if (!JSValueIsString (ctx, val)) // In this case,
- // it's an object
- {
- func =
- seed_object_get_property (ctx, (JSObjectRef) val, "toString");
-
- if (!JSValueIsNull (ctx, func) &&
- JSValueIsObject (ctx, func) &&
- JSObjectIsFunction (ctx, (JSObjectRef) func))
- //str = ... we dump the return value!?!
- JSObjectCallAsFunction (ctx, (JSObjectRef) func,
- (JSObjectRef) val, 0, NULL, NULL);
- }
-
- jsstr = JSValueToStringCopy (ctx, val, NULL);
- length = JSStringGetMaximumUTF8CStringSize (jsstr);
- if (length > 0)
- {
- buf = g_malloc (length * sizeof (gchar));
- JSStringGetUTF8CString (jsstr, buf, length);
- }
- if (jsstr)
- JSStringRelease (jsstr);
+ if (!JSValueIsNull(ctx, func) && JSValueIsObject(ctx, func)
+ && JSObjectIsFunction(ctx, (JSObjectRef) func))
+ // str = ... we dump the return value!?!
+ JSObjectCallAsFunction(ctx, (JSObjectRef) func,
+ (JSObjectRef) val, 0, NULL, NULL);
+ }
+
+ jsstr = JSValueToStringCopy(ctx, val, NULL);
+ length = JSStringGetMaximumUTF8CStringSize(jsstr);
+ if (length > 0) {
+ buf = g_malloc(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsstr, buf, length);
+ }
+ if (jsstr)
+ JSStringRelease(jsstr);
}
- return buf;
+ return buf;
}
/**
@@ -2497,18 +2499,18 @@ seed_value_to_string (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_string (JSContextRef ctx,
- const gchar * val, JSValueRef * exception)
+seed_value_from_string(JSContextRef ctx,
+ const gchar* val,
+ JSValueRef* exception)
{
- if (val == NULL)
- return JSValueMakeNull (ctx);
- else
- {
- JSStringRef jsstr = JSStringCreateWithUTF8CString (val);
- JSValueRef valstr = JSValueMakeString (ctx, jsstr);
- JSStringRelease (jsstr);
-
- return valstr;
+ if (val == NULL)
+ return JSValueMakeNull(ctx);
+ else {
+ JSStringRef jsstr = JSStringCreateWithUTF8CString(val);
+ JSValueRef valstr = JSValueMakeString(ctx, jsstr);
+ JSStringRelease(jsstr);
+
+ return valstr;
}
}
@@ -2529,37 +2531,34 @@ seed_value_from_string (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_binary_string (JSContextRef ctx,
- const gchar * bytes,
- gint n_bytes, JSValueRef * exception)
+seed_value_from_binary_string(JSContextRef ctx,
+ const gchar* bytes,
+ gint n_bytes,
+ JSValueRef* exception)
{
- JSStringRef jsstr;
- JSValueRef valstr;
- JSChar* jchar;
- gint i;
-
- SEED_NOTE (INVOCATION, "Creating binary string of length %d ",
- n_bytes);
-
- if (bytes == NULL)
- {
- return JSValueMakeNull (ctx);
+ JSStringRef jsstr;
+ JSValueRef valstr;
+ JSChar* jchar;
+ gint i;
+
+ SEED_NOTE(INVOCATION, "Creating binary string of length %d ", n_bytes);
+
+ if (bytes == NULL) {
+ return JSValueMakeNull(ctx);
}
-
- jchar = g_new0(JSChar, n_bytes);
- for(i =0;i < n_bytes; i++)
- {
- jchar[i] = bytes[i];
+
+ jchar = g_new0(JSChar, n_bytes);
+ for (i = 0; i < n_bytes; i++) {
+ jchar[i] = bytes[i];
}
- // this may leak...
-
- jsstr = JSStringCreateWithCharacters((const JSChar*)jchar, n_bytes);
- valstr = JSValueMakeString (ctx, jsstr);
- g_free(jchar);
- JSStringRelease (jsstr);
-
- return valstr;
-
+ // this may leak...
+
+ jsstr = JSStringCreateWithCharacters((const JSChar*) jchar, n_bytes);
+ valstr = JSValueMakeString(ctx, jsstr);
+ g_free(jchar);
+ JSStringRelease(jsstr);
+
+ return valstr;
}
/**
@@ -2569,31 +2568,29 @@ seed_value_from_binary_string (JSContextRef ctx,
* @exception: A reference to a #SeedValue in which to store any exceptions.
* Pass %NULL to ignore exceptions.
*
- * Converts the given #SeedValue into a #gchar*, properly converting to the
+ * Converts the given #SeedValue into a #gchar*, properly converting to the
* character set used for filenames on the local machine.
*
* Return value: The #gchar* represented by @val, or %NULL if an exception
* is raised during the conversion.
*
*/
-gchar *
-seed_value_to_filename (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+gchar*
+seed_value_to_filename(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- GError *e = NULL;
- gchar *utf8 = seed_value_to_string (ctx, val, exception);
- gchar *filename;
-
- filename = g_filename_from_utf8 (utf8, -1, NULL, NULL, &e);
- g_free (utf8);
- if (e)
- {
- seed_make_exception_from_gerror (ctx, exception, e);
- g_error_free (e);
- return NULL;
+ GError* e = NULL;
+ gchar* utf8 = seed_value_to_string(ctx, val, exception);
+ gchar* filename;
+
+ filename = g_filename_from_utf8(utf8, -1, NULL, NULL, &e);
+ g_free(utf8);
+ if (e) {
+ seed_make_exception_from_gerror(ctx, exception, e);
+ g_error_free(e);
+ return NULL;
}
- return filename;
+ return filename;
}
/**
@@ -2603,37 +2600,36 @@ seed_value_to_filename (JSContextRef ctx,
* @exception: A reference to a #SeedValue in which to store any exceptions.
* Pass %NULL to ignore exceptions.
*
- * Converts the given #gchar* filename into a #SeedValue, respecting the
+ * Converts the given #gchar* filename into a #SeedValue, respecting the
* character set used for filenames on the local machine.
*
* Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
-seed_value_from_filename (JSContextRef ctx,
- const gchar * val, JSValueRef * exception)
+seed_value_from_filename(JSContextRef ctx,
+ const gchar* val,
+ JSValueRef* exception)
{
- GError *e = NULL;
- gchar *utf8;
-
- if (val == NULL)
- return JSValueMakeNull (ctx);
- else
- {
- utf8 = g_filename_to_utf8 (val, -1, NULL, NULL, &e);
-
- if (e)
- {
- seed_make_exception_from_gerror (ctx, exception, e);
- g_error_free (e);
- return JSValueMakeNull (ctx);
+ GError* e = NULL;
+ gchar* utf8;
+
+ if (val == NULL)
+ return JSValueMakeNull(ctx);
+ else {
+ utf8 = g_filename_to_utf8(val, -1, NULL, NULL, &e);
+
+ if (e) {
+ seed_make_exception_from_gerror(ctx, exception, e);
+ g_error_free(e);
+ return JSValueMakeNull(ctx);
}
- JSValueRef valstr = seed_value_from_string (ctx, utf8, exception);
+ JSValueRef valstr = seed_value_from_string(ctx, utf8, exception);
- g_free (utf8);
+ g_free(utf8);
- return valstr;
+ return valstr;
}
}
@@ -2651,33 +2647,31 @@ seed_value_from_filename (JSContextRef ctx,
* is raised during the conversion.
*
*/
-GObject *
-seed_value_to_object (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+GObject*
+seed_value_to_object(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- GObject *gobject;
-
- /*
- * Worth investigating if this is the best way to handle null. Some of
- * the existing code depends on null Objects not throwing an exception
- * however, needs testing at higher level if value can be null
- * (through GI)
- */
-
- if (JSValueIsNull (ctx, val))
- return NULL;
- if (!seed_value_is_gobject (ctx, val))
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Attempt to convert from"
- " non GObject to GObject");
- return NULL;
+ GObject* gobject;
+
+ /*
+ * Worth investigating if this is the best way to handle null. Some of
+ * the existing code depends on null Objects not throwing an exception
+ * however, needs testing at higher level if value can be null
+ * (through GI)
+ */
+
+ if (JSValueIsNull(ctx, val))
+ return NULL;
+ if (!seed_value_is_gobject(ctx, val)) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Attempt to convert from"
+ " non GObject to GObject");
+ return NULL;
}
- gobject = (GObject *) JSObjectGetPrivate ((JSObjectRef) val);
- g_assert (G_IS_OBJECT (gobject));
+ gobject = (GObject*) JSObjectGetPrivate((JSObjectRef) val);
+ g_assert(G_IS_OBJECT(gobject));
- return gobject;
+ return gobject;
}
/**
@@ -2693,80 +2687,71 @@ seed_value_to_object (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_object (JSContextRef ctx,
- GObject * val, JSValueRef * exception)
+seed_value_from_object(JSContextRef ctx, GObject* val, JSValueRef* exception)
{
- if (val == NULL)
- return JSValueMakeNull (ctx);
- else
- return seed_wrap_object (ctx, val);
+ if (val == NULL)
+ return JSValueMakeNull(ctx);
+ else
+ return seed_wrap_object(ctx, val);
}
gboolean
-seed_validate_enum (GIEnumInfo * info, long val)
+seed_validate_enum(GIEnumInfo* info, long val)
{
- gint n, i;
- GIValueInfo *value_info;
- gint value; // TODO: investigate glong/gint mismatch w/ g_value_info_get_value
-
- n = g_enum_info_get_n_values (info);
- for (i = 0; i < n; i++)
- {
- value_info = g_enum_info_get_value (info, i);
- value = g_value_info_get_value (value_info);
-
- g_base_info_unref ((GIBaseInfo *) value_info);
- if (value == val)
- return TRUE;
+ gint n, i;
+ GIValueInfo* value_info;
+ gint
+ value; // TODO: investigate glong/gint mismatch w/ g_value_info_get_value
+
+ n = g_enum_info_get_n_values(info);
+ for (i = 0; i < n; i++) {
+ value_info = g_enum_info_get_value(info, i);
+ value = g_value_info_get_value(value_info);
+
+ g_base_info_unref((GIBaseInfo*) value_info);
+ if (value == val)
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
JSValueRef
-seed_value_from_time_t (JSContextRef ctx, time_t time, JSValueRef * exception)
+seed_value_from_time_t(JSContextRef ctx, time_t time, JSValueRef* exception)
{
- JSValueRef args[1];
+ JSValueRef args[1];
- args[0] = seed_value_from_double (ctx, ((gdouble) time) * 1000, exception);
- return JSObjectMakeDate (ctx, 1, args, exception);
+ args[0] = seed_value_from_double(ctx, ((gdouble) time) * 1000, exception);
+ return JSObjectMakeDate(ctx, 1, args, exception);
}
time_t
-seed_value_to_time_t (JSContextRef ctx,
- JSValueRef value, JSValueRef * exception)
+seed_value_to_time_t(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
- JSValueRef get_time_method;
- JSValueRef jstime;
- gdouble time;
-
-
- if (JSValueIsNumber (ctx, value))
- {
- return (unsigned long) seed_value_to_long (ctx, value, exception);
- }
- else if (JSValueIsObject (ctx, value))
- {
- get_time_method = seed_object_get_property (ctx, (JSObjectRef) value,
- "getTime");
- if (JSValueIsNull (ctx, get_time_method) ||
- !JSValueIsObject (ctx, get_time_method))
- {
- goto out;
- }
- jstime = JSObjectCallAsFunction (ctx,
- (JSObjectRef) get_time_method,
- (JSObjectRef) value,
- 0, NULL, exception);
- time = seed_value_to_double (ctx, jstime, exception);
- return (unsigned long) (time / 1000);
+ JSValueRef get_time_method;
+ JSValueRef jstime;
+ gdouble time;
+
+ if (JSValueIsNumber(ctx, value)) {
+ return (unsigned long) seed_value_to_long(ctx, value, exception);
+ } else if (JSValueIsObject(ctx, value)) {
+ get_time_method
+ = seed_object_get_property(ctx, (JSObjectRef) value, "getTime");
+ if (JSValueIsNull(ctx, get_time_method)
+ || !JSValueIsObject(ctx, get_time_method)) {
+ goto out;
+ }
+ jstime
+ = JSObjectCallAsFunction(ctx, (JSObjectRef) get_time_method,
+ (JSObjectRef) value, 0, NULL, exception);
+ time = seed_value_to_double(ctx, jstime, exception);
+ return (unsigned long) (time / 1000);
}
out:
- seed_make_exception (ctx, exception,
- "TypeError",
- "Unable to convert JavaScript value to time_t");
- return 0;
+ seed_make_exception(ctx, exception, "TypeError",
+ "Unable to convert JavaScript value to time_t");
+ return 0;
}
/**
@@ -2782,20 +2767,18 @@ out:
*
*/
JSValueRef
-seed_value_from_strv (JSContextRef ctx,
- GStrv * val, JSValueRef * exception)
+seed_value_from_strv(JSContextRef ctx, GStrv* val, JSValueRef* exception)
{
- GArray *js_string_array = g_array_new (FALSE, FALSE, sizeof(gpointer));
- for (; *val != NULL; val++)
- {
- JSStringRef js_string = seed_value_from_string (ctx, *val, exception);
- js_string_array = g_array_append_val(js_string_array, js_string);
- }
- JSValueRef res = JSObjectMakeArray (ctx,
- js_string_array->len,
- (JSValueRef*)js_string_array->data,
- exception);
- g_array_free (js_string_array, FALSE);
-
- return res;
+ GArray* js_string_array = g_array_new(FALSE, FALSE, sizeof(gpointer));
+ for (; *val != NULL; val++) {
+ JSValueRef js_string
+ = seed_value_from_string(ctx, (char*) *val, exception);
+ js_string_array = g_array_append_val(js_string_array, js_string);
+ }
+ JSValueRef res
+ = JSObjectMakeArray(ctx, js_string_array->len,
+ (JSValueRef*) js_string_array->data, exception);
+ g_array_free(js_string_array, FALSE);
+
+ return res;
}
diff --git a/libseed/seed-types.h b/libseed/seed-types.h
index 1ffdac3..fe90ae0 100644
--- a/libseed/seed-types.h
+++ b/libseed/seed-types.h
@@ -24,146 +24,198 @@
extern GQuark js_ref_quark;
-JSValueRef seed_value_from_gvalue (JSContextRef ctx,
- GValue * gval, JSValueRef * exception);
-
-JSValueRef seed_value_from_gvalue_for_signal (JSContextRef ctx,
- GValue * gval, JSValueRef * exception,
- GSignalQuery *signal_query, gint arg_n);
-
-gboolean seed_value_to_gvalue (JSContextRef ctx,
- JSValueRef val, GType type,
- GValue * gval, JSValueRef * exception);
-
-JSValueRef seed_object_get_property (JSContextRef ctx,
- JSObjectRef val, const gchar * name);
-
-gboolean seed_object_set_property (JSContextRef ctx, JSObjectRef object,
- const gchar * name, JSValueRef value);
-
-gboolean seed_value_to_gi_argument (JSContextRef ctx,
- JSValueRef value,
- GITypeInfo * type_info,
- GArgument * arg, JSValueRef * exception);
-
-JSValueRef seed_value_from_gi_argument (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception);
-
-JSValueRef seed_value_from_gi_argument_full (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception,
- guint64 array_len,
- GITypeTag gi_tag);
-gboolean seed_gi_release_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg);
-
-gboolean seed_gi_release_in_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg);
-
-gboolean seed_value_to_boolean (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_boolean (JSContextRef ctx,
- gboolean val, JSValueRef * exception);
-
-guint seed_value_to_uint (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_uint (JSContextRef ctx,
- guint val, JSValueRef * exception);
-
-gint seed_value_to_int (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_int (JSContextRef ctx,
- gint val, JSValueRef * exception);
-
-gchar seed_value_to_char (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_char (JSContextRef ctx,
- gchar val, JSValueRef * exception);
-
-guchar seed_value_to_uchar (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_uchar (JSContextRef ctx,
- guchar val, JSValueRef * exception);
-
-glong seed_value_to_long (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_long (JSContextRef ctx,
- glong val, JSValueRef * exception);
-
-gulong seed_value_to_ulong (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_ulong (JSContextRef ctx,
- gulong val, JSValueRef * exception);
-
-gint64 seed_value_to_int64 (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_int64 (JSContextRef ctx,
- gint64 val, JSValueRef * exception);
-
-guint64 seed_value_to_uint64 (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_uint64 (JSContextRef ctx,
- guint64 val, JSValueRef * exception);
-
-gfloat seed_value_to_float (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_float (JSContextRef ctx,
- gfloat val, JSValueRef * exception);
-
-gdouble seed_value_to_double (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_double (JSContextRef ctx,
- gdouble val, JSValueRef * exception);
-
-gsize seed_value_to_size (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_size (JSContextRef ctx,
- gsize val, JSValueRef * exception);
-
-gssize seed_value_to_ssize (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_ssize (JSContextRef ctx,
- gssize val, JSValueRef * exception);
-
-gchar *seed_value_to_filename (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_filename (JSContextRef ctx,
- const gchar * filename,
- JSValueRef * exception);
-
-gchar *seed_value_to_string (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_string (JSContextRef ctx,
- const gchar * val, JSValueRef * exception);
-
-time_t seed_value_to_time_t (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_time_t (JSContextRef ctx,
- time_t time, JSValueRef * exception);
-
-GObject *seed_value_to_object (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_object (JSContextRef ctx,
- GObject * val, JSValueRef * exception);
-JSValueRef seed_value_from_strv (JSContextRef ctx,
- GStrv * val, JSValueRef * exception);
-void seed_toggle_ref (gpointer data, GObject * object, gboolean is_last_ref);
-
-gboolean seed_validate_enum (GIEnumInfo * info, long val);
-
-JSValueRef
-seed_value_from_binary_string (JSContextRef ctx,
- const gchar * bytes,
- gint n_bytes, JSValueRef * exception);
-
-JSObjectRef seed_make_wrapper_for_type (JSContextRef ctx, GType type);
+JSValueRef seed_value_from_gvalue(JSContextRef ctx,
+ GValue* gval,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_gvalue_for_signal(JSContextRef ctx,
+ GValue* gval,
+ JSValueRef* exception,
+ GSignalQuery* signal_query,
+ gint arg_n);
+
+gboolean seed_value_to_gvalue(JSContextRef ctx,
+ JSValueRef val,
+ GType type,
+ GValue* gval,
+ JSValueRef* exception);
+
+JSValueRef seed_object_get_property(JSContextRef ctx,
+ JSObjectRef val,
+ const gchar* name);
+
+gboolean seed_object_set_property(JSContextRef ctx,
+ JSObjectRef object,
+ const gchar* name,
+ JSValueRef value);
+
+gboolean seed_value_to_gi_argument(JSContextRef ctx,
+ JSValueRef value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ JSValueRef* exception);
+
+gboolean seed_value_to_gi_argument_with_out_length(JSContextRef ctx,
+ JSValueRef value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ guint* out_array_length,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_gi_argument(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_gi_argument_full(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception,
+ guint64 array_len,
+ GITypeTag gi_tag);
+gboolean seed_gi_release_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GArgument* arg);
+
+gboolean seed_gi_release_in_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GArgument* arg);
+
+gboolean seed_value_to_boolean(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_boolean(JSContextRef ctx,
+ gboolean val,
+ JSValueRef* exception);
+
+guint seed_value_to_uint(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_uint(JSContextRef ctx,
+ guint val,
+ JSValueRef* exception);
+
+gint seed_value_to_int(JSContextRef ctx, JSValueRef val, JSValueRef* exception);
+
+JSValueRef seed_value_from_int(JSContextRef ctx,
+ gint val,
+ JSValueRef* exception);
+
+gchar seed_value_to_char(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_char(JSContextRef ctx,
+ gchar val,
+ JSValueRef* exception);
+
+guchar seed_value_to_uchar(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_uchar(JSContextRef ctx,
+ guchar val,
+ JSValueRef* exception);
+
+glong seed_value_to_long(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_long(JSContextRef ctx,
+ glong val,
+ JSValueRef* exception);
+
+gulong seed_value_to_ulong(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_ulong(JSContextRef ctx,
+ gulong val,
+ JSValueRef* exception);
+
+gint64 seed_value_to_int64(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_int64(JSContextRef ctx,
+ gint64 val,
+ JSValueRef* exception);
+
+guint64 seed_value_to_uint64(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_uint64(JSContextRef ctx,
+ guint64 val,
+ JSValueRef* exception);
+
+gfloat seed_value_to_float(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_float(JSContextRef ctx,
+ gfloat val,
+ JSValueRef* exception);
+
+gdouble seed_value_to_double(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_double(JSContextRef ctx,
+ gdouble val,
+ JSValueRef* exception);
+
+gsize seed_value_to_size(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_size(JSContextRef ctx,
+ gsize val,
+ JSValueRef* exception);
+
+gssize seed_value_to_ssize(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_ssize(JSContextRef ctx,
+ gssize val,
+ JSValueRef* exception);
+
+gchar* seed_value_to_filename(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_filename(JSContextRef ctx,
+ const gchar* filename,
+ JSValueRef* exception);
+
+gchar* seed_value_to_string(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_string(JSContextRef ctx,
+ const gchar* val,
+ JSValueRef* exception);
+
+time_t seed_value_to_time_t(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_time_t(JSContextRef ctx,
+ time_t time,
+ JSValueRef* exception);
+
+GObject* seed_value_to_object(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_object(JSContextRef ctx,
+ GObject* val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_strv(JSContextRef ctx,
+ GStrv* val,
+ JSValueRef* exception);
+void seed_toggle_ref(gpointer data, GObject* object, gboolean is_last_ref);
+
+gboolean seed_validate_enum(GIEnumInfo* info, long val);
+
+JSValueRef seed_value_from_binary_string(JSContextRef ctx,
+ const gchar* bytes,
+ gint n_bytes,
+ JSValueRef* exception);
+
+JSObjectRef seed_make_wrapper_for_type(JSContextRef ctx, GType type);
#endif
diff --git a/libseed/seed.h b/libseed/seed.h
index 0485f84..f00c129 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -36,432 +36,482 @@ typedef gpointer SeedContext;
typedef gpointer SeedGlobalContext;
typedef gpointer SeedContextGroup;
-typedef enum
-{
- SEED_TYPE_UNDEFINED,
- SEED_TYPE_NULL,
- SEED_TYPE_BOOLEAN,
- SEED_TYPE_NUMBER,
- SEED_TYPE_STRING,
- SEED_TYPE_OBJECT
+typedef enum {
+ SEED_TYPE_UNDEFINED,
+ SEED_TYPE_NULL,
+ SEED_TYPE_BOOLEAN,
+ SEED_TYPE_NUMBER,
+ SEED_TYPE_STRING,
+ SEED_TYPE_OBJECT
} SeedType;
-typedef enum
-{
- SEED_PROPERTY_ATTRIBUTE_NONE = 0,
- SEED_PROPERTY_ATTRIBUTE_READ_ONLY = 1 << 1,
- SEED_PROPERTY_ATTRIBUTE_DONT_ENUM = 1 << 2,
- SEED_PROPERTY_ATTRIBUTE_DONT_DELETE = 1 << 3
+typedef enum {
+ SEED_PROPERTY_ATTRIBUTE_NONE = 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY = 1 << 1,
+ SEED_PROPERTY_ATTRIBUTE_DONT_ENUM = 1 << 2,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE = 1 << 3
} SeedPropertyAttributes;
-typedef enum
-{
- SEED_CLASS_ATTRIBUTE_NONE = 0,
- SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE = 1 << 1
+typedef enum {
+ SEED_CLASS_ATTRIBUTE_NONE = 0,
+ SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE = 1 << 1
} SeedClassAttributes;
typedef struct _SeedScript SeedScript;
typedef struct _SeedEngine
{
- SeedGlobalContext context;
- SeedValue global;
- gchar **search_path;
+ SeedGlobalContext context;
+ SeedValue global;
+ gchar** search_path;
- SeedContextGroup group;
+ SeedContextGroup group;
+ gchar* program_name;
} SeedEngine;
/*
* seed-engine.c
*/
-SeedEngine *seed_init (gint *argc, gchar ***argv);
-SeedEngine *
-seed_init_with_context (gint * argc, gchar *** argv, SeedGlobalContext context);
-
-SeedEngine *seed_init_with_context_group (gint *argc, gchar ***argv,
- SeedContextGroup group);
-SeedEngine *seed_init_with_context_and_group (gint * argc,gchar *** argv,
- SeedGlobalContext context, SeedContextGroup group);
-SeedEngine *seed_init_constrained (gint * argc, gchar *** argv);
-SeedEngine *seed_init_constrained_with_context_and_group (gint * argc,
- gchar *** argv,
- SeedGlobalContext context,
- SeedContextGroup group);
-void seed_engine_destroy (SeedEngine *eng);
-
-SeedValue seed_simple_evaluate (SeedContext ctx,
- gchar * source,
- SeedException *exception);
-
-SeedScript *seed_make_script (SeedContext ctx,
- const gchar * js,
- const gchar * source_url,
- gint line_number);
-SeedScript *seed_script_new_from_file (SeedContext ctx, gchar * file);
-SeedException seed_script_exception (SeedScript * s);
-void seed_script_destroy (SeedScript *s);
-void seed_make_exception (SeedContext ctx, SeedException exception,
- const gchar * name, const gchar * message, ...) G_GNUC_PRINTF (4,5);
-gchar *seed_exception_get_name (SeedContext ctx, SeedException exception);
-gchar *seed_exception_get_message (SeedContext ctx, SeedException exception);
-guint seed_exception_get_line (SeedContext ctx, SeedException exception);
-gchar *seed_exception_get_file (SeedContext ctx, SeedException exception);
-gchar *seed_exception_to_string (SeedContext ctx, SeedException exception);
-
-SeedValue seed_evaluate (SeedContext ctx, SeedScript * s, SeedObject this_object);
-
-SeedValue
-seed_engine_expose_gobject (SeedEngine *engine, gchar *js_name, GObject *object, gchar *gir_namespace, SeedException exception);
-SeedValue
-seed_engine_expose_namespace (SeedEngine *engine, gchar *namespace_name, SeedException exception);
-GOptionGroup * seed_get_option_group (void);
+SeedEngine* seed_init(gint* argc, gchar*** argv);
+SeedEngine* seed_init_with_context(gint* argc,
+ gchar*** argv,
+ SeedGlobalContext context);
+
+SeedEngine* seed_init_with_context_group(gint* argc,
+ gchar*** argv,
+ SeedContextGroup group);
+SeedEngine* seed_init_with_context_and_group(gint* argc,
+ gchar*** argv,
+ SeedGlobalContext context,
+ SeedContextGroup group);
+SeedEngine* seed_init_constrained(gint* argc, gchar*** argv);
+SeedEngine* seed_init_constrained_with_context_and_group(
+ gint* argc,
+ gchar*** argv,
+ SeedGlobalContext context,
+ SeedContextGroup group);
+void seed_engine_destroy(SeedEngine* eng);
+
+SeedValue seed_simple_evaluate(SeedContext ctx,
+ gchar* source,
+ SeedException* exception);
+
+SeedScript* seed_make_script(SeedContext ctx,
+ const gchar* js,
+ const gchar* source_url,
+ gint line_number);
+SeedScript* seed_script_new_from_file(SeedContext ctx, gchar* file);
+SeedException seed_script_exception(SeedScript* s);
+void seed_script_destroy(SeedScript* s);
+void seed_make_exception(SeedContext ctx,
+ SeedException exception,
+ const gchar* name,
+ const gchar* message,
+ ...) G_GNUC_PRINTF(4, 5);
+gchar* seed_exception_get_name(SeedContext ctx, SeedException exception);
+gchar* seed_exception_get_message(SeedContext ctx, SeedException exception);
+guint seed_exception_get_line(SeedContext ctx, SeedException exception);
+gchar* seed_exception_get_file(SeedContext ctx, SeedException exception);
+gchar* seed_exception_get_stack(SeedContext ctx, SeedException exception);
+gchar* seed_exception_to_string(SeedContext ctx, SeedException exception);
+
+SeedValue seed_evaluate(SeedContext ctx, SeedScript* s, SeedObject this_object);
+
+SeedValue seed_engine_expose_gobject(SeedEngine* engine,
+ gchar* js_name,
+ GObject* object,
+ gchar* gir_namespace,
+ SeedException exception);
+SeedValue seed_engine_expose_namespace(SeedEngine* engine,
+ gchar* namespace_name,
+ SeedException exception);
+GOptionGroup* seed_get_option_group(void);
/*
* seed-api.c
*/
-SeedGlobalContext seed_context_create (SeedContextGroup group,
- SeedClass global_class);
-SeedGlobalContext seed_context_ref (SeedGlobalContext ctx);
-void seed_context_unref (SeedGlobalContext ctx);
-void seed_context_collect (SeedGlobalContext ctx);
-
-SeedObject seed_context_get_global_object (SeedContext ctx);
-
-void seed_importer_add_global(SeedContext ctx, gchar *name);
-void seed_importer_set_search_path (SeedContext ctx,
- gchar **search_path);
-void seed_prepare_global_context (SeedContext ctx);
-void seed_importer_add_search_path (SeedContext ctx, gchar *search_path);
-
-
-SeedValue seed_make_null (SeedContext ctx);
-SeedValue seed_make_undefined (SeedContext ctx);
-
-SeedString seed_string_ref (SeedString string);
-void seed_string_unref (SeedString string);
-
-gsize seed_string_get_maximum_size (SeedString string);
-gsize seed_string_to_utf8_buffer (SeedString string, gchar * buffer,
- size_t buffer_size);
-
-gboolean seed_string_is_equal (SeedString a, SeedString b);
-gboolean seed_string_is_equal_utf8 (SeedString a, const gchar * b);
-
-gboolean seed_value_is_null (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_undefined (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_object (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_object_of_class (SeedContext ctx, SeedValue value, SeedClass klass);
-gboolean seed_value_is_function (SeedContext ctx, SeedObject value);
-gboolean seed_value_is_string (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_number (SeedContext ctx, SeedValue value);
-
-void seed_value_unprotect (SeedContext ctx, SeedValue value);
-void seed_value_protect (SeedContext ctx, SeedValue value);
-
-gboolean seed_value_to_gvalue (SeedContext ctx,
- SeedValue val, GType type,
- GValue * gval, SeedException * exception);
-
-SeedValue seed_value_from_gvalue (SeedContext ctx,
- GValue * gval, SeedException * exception);
-
-gboolean seed_value_to_gi_argument (SeedContext ctx,
- SeedValue value,
- GITypeInfo * type_info,
- GArgument * arg, SeedValue * exception);
-
-SeedValue seed_value_from_gi_argument (SeedContext ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- SeedException * exception);
-
-gboolean seed_value_to_boolean (SeedContext ctx,
- SeedValue val, SeedException * exception);
-
-SeedValue seed_value_from_boolean (SeedContext ctx,
- gboolean val, SeedException * exception);
-
-guint seed_value_to_uint (SeedContext ctx,
- SeedValue val, SeedException * exception);
-
-SeedValue seed_value_from_uint (SeedContext ctx,
- guint val, SeedException * exception);
-
-gint seed_value_to_int (SeedContext ctx,
- SeedValue val, SeedException * exception);
-
-SeedValue seed_value_from_int (SeedContext ctx,
- gint val, SeedException * exception);
-
-gchar seed_value_to_char (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_char (SeedContext ctx,
- gchar val, SeedException * exception);
-
-guchar seed_value_to_uchar (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_uchar (SeedContext ctx,
- guchar val, SeedException * exception);
-
-glong seed_value_to_long (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_long (SeedContext ctx,
- glong val, SeedException * exception);
-
-gulong seed_value_to_ulong (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_ulong (SeedContext ctx,
- gulong val, SeedException * exception);
-
-gint64 seed_value_to_int64 (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_int64 (SeedContext ctx,
- gint64 val, SeedException * exception);
-
-guint64 seed_value_to_uint64 (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_uint64 (SeedContext ctx,
- guint64 val, SeedException * exception);
-
-gfloat seed_value_to_float (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_float (SeedContext ctx,
- gfloat val, SeedException * exception);
-
-gdouble seed_value_to_double (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_double (SeedContext ctx,
- gdouble val, SeedException * exception);
-
-gchar *seed_value_to_string (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_string (SeedContext ctx,
- const gchar * val, SeedException * exception);
-
-gchar *seed_value_to_filename (SeedContext ctx,
- SeedValue val, SeedValue *exception);
-SeedValue seed_value_from_filename (SeedContext ctx,
- SeedValue val, SeedValue *exception);
-
-SeedValue seed_value_from_binary_string (SeedContext ctx,
- const gchar *bytes,
- gint n_bytes,
- SeedException *exception);
-
-SeedType seed_value_get_type (SeedContext ctx, SeedValue value);
-
-gboolean
-seed_value_to_format (SeedContext ctx,
- const gchar *format,
- SeedValue *values,
- SeedValue *exception,
- ...);
-
-typedef SeedObject (*SeedModuleInitCallback) (SeedEngine * eng);
-
-gboolean seed_object_set_property (SeedContext ctx,
- SeedObject object,
- const gchar * name, SeedValue value);
-SeedValue seed_object_get_property (SeedContext ctx,
- SeedObject object, const gchar * name);
-
-void seed_object_set_property_at_index (SeedContext ctx,
- SeedObject object,
- gint index,
- SeedValue value,
- SeedException * exception);
-
-SeedValue seed_object_get_property_at_index (SeedContext ctx,
- SeedObject object,
- gint index,
- SeedException *exception);
-
-SeedValue seed_object_call (SeedContext ctx,
- SeedObject object,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception);
-
-GObject *seed_value_to_object (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_object (SeedContext ctx,
- GObject * val, SeedException * exception);
-
-SeedObject seed_make_object (SeedContext ctx, SeedClass klass,
- gpointer private_object);
-
-gpointer seed_object_get_private (SeedObject object);
-void seed_object_set_private (SeedObject object, gpointer value);
-
-gchar **seed_object_copy_property_names(SeedContext ctx, SeedObject object);
-
-gpointer seed_pointer_get_pointer (SeedContext ctx, SeedValue pointer);
-
-SeedObject
-seed_object_get_prototype (SeedContext ctx, SeedObject obj);
-
-gboolean
-seed_object_is_of_class (SeedContext ctx, SeedObject obj, SeedClass klass);
-
-SeedValue seed_make_pointer (SeedContext ctx, gpointer pointer);
-
-typedef SeedValue (*SeedFunctionCallback) (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception);
-
-void seed_create_function (SeedContext ctx,
- gchar * name, SeedFunctionCallback func,
- SeedObject obj);
-SeedObject seed_make_function (SeedContext ctx, SeedFunctionCallback func, const gchar *name);
-
-
-SeedObject seed_make_array (SeedContext ctx, const SeedValue elements,
- gsize num_elements, SeedException *exception);
-
-
-
-typedef void (*SeedObjectInitializeCallback) (SeedContext ctx,
- SeedObject object);
+SeedGlobalContext seed_context_create(SeedContextGroup group,
+ SeedClass global_class);
+SeedGlobalContext seed_context_ref(SeedGlobalContext ctx);
+void seed_context_unref(SeedGlobalContext ctx);
+void seed_context_collect(SeedGlobalContext ctx);
+
+SeedObject seed_context_get_global_object(SeedContext ctx);
+
+void seed_importer_add_global(SeedContext ctx, gchar* name);
+void seed_importer_set_search_path(SeedContext ctx, gchar** search_path);
+void seed_prepare_global_context(SeedContext ctx);
+void seed_importer_add_search_path(SeedContext ctx, gchar* search_path);
+
+SeedValue seed_make_null(SeedContext ctx);
+SeedValue seed_make_undefined(SeedContext ctx);
+
+SeedString seed_string_ref(SeedString string);
+void seed_string_unref(SeedString string);
+
+gsize seed_string_get_maximum_size(SeedString string);
+gsize seed_string_to_utf8_buffer(SeedString string,
+ gchar* buffer,
+ size_t buffer_size);
+
+gboolean seed_string_is_equal(SeedString a, SeedString b);
+gboolean seed_string_is_equal_utf8(SeedString a, const gchar* b);
+
+gboolean seed_value_is_null(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_undefined(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_object(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_object_of_class(SeedContext ctx,
+ SeedValue value,
+ SeedClass klass);
+gboolean seed_value_is_function(SeedContext ctx, SeedObject value);
+gboolean seed_value_is_string(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_number(SeedContext ctx, SeedValue value);
+
+void seed_value_unprotect(SeedContext ctx, SeedValue value);
+void seed_value_protect(SeedContext ctx, SeedValue value);
+
+gboolean seed_value_to_gvalue(SeedContext ctx,
+ SeedValue val,
+ GType type,
+ GValue* gval,
+ SeedException* exception);
+
+SeedValue seed_value_from_gvalue(SeedContext ctx,
+ GValue* gval,
+ SeedException* exception);
+
+gboolean seed_value_to_gi_argument(SeedContext ctx,
+ SeedValue value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ SeedValue* exception);
+
+SeedValue seed_value_from_gi_argument(SeedContext ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ SeedException* exception);
+
+gboolean seed_value_to_boolean(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+
+SeedValue seed_value_from_boolean(SeedContext ctx,
+ gboolean val,
+ SeedException* exception);
+
+guint seed_value_to_uint(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+
+SeedValue seed_value_from_uint(SeedContext ctx,
+ guint val,
+ SeedException* exception);
+
+gint seed_value_to_int(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+
+SeedValue seed_value_from_int(SeedContext ctx,
+ gint val,
+ SeedException* exception);
+
+gchar seed_value_to_char(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_char(SeedContext ctx,
+ gchar val,
+ SeedException* exception);
+
+guchar seed_value_to_uchar(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_uchar(SeedContext ctx,
+ guchar val,
+ SeedException* exception);
+
+glong seed_value_to_long(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_long(SeedContext ctx,
+ glong val,
+ SeedException* exception);
+
+gulong seed_value_to_ulong(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_ulong(SeedContext ctx,
+ gulong val,
+ SeedException* exception);
+
+gint64 seed_value_to_int64(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_int64(SeedContext ctx,
+ gint64 val,
+ SeedException* exception);
+
+guint64 seed_value_to_uint64(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_uint64(SeedContext ctx,
+ guint64 val,
+ SeedException* exception);
+
+gfloat seed_value_to_float(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_float(SeedContext ctx,
+ gfloat val,
+ SeedException* exception);
+
+gdouble seed_value_to_double(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_double(SeedContext ctx,
+ gdouble val,
+ SeedException* exception);
+
+gchar* seed_value_to_string(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_string(SeedContext ctx,
+ const gchar* val,
+ SeedException* exception);
+
+gchar* seed_value_to_filename(SeedContext ctx,
+ SeedValue val,
+ SeedValue* exception);
+SeedValue seed_value_from_filename(SeedContext ctx,
+ SeedValue val,
+ SeedValue* exception);
+
+SeedValue seed_value_from_binary_string(SeedContext ctx,
+ const gchar* bytes,
+ gint n_bytes,
+ SeedException* exception);
+
+SeedType seed_value_get_type(SeedContext ctx, SeedValue value);
+
+gboolean seed_value_to_format(SeedContext ctx,
+ const gchar* format,
+ SeedValue* values,
+ SeedValue* exception,
+ ...);
+
+typedef SeedObject (*SeedModuleInitCallback)(SeedEngine* eng);
+
+gboolean seed_object_set_property(SeedContext ctx,
+ SeedObject object,
+ const gchar* name,
+ SeedValue value);
+SeedValue seed_object_get_property(SeedContext ctx,
+ SeedObject object,
+ const gchar* name);
+
+void seed_object_set_property_at_index(SeedContext ctx,
+ SeedObject object,
+ gint index,
+ SeedValue value,
+ SeedException* exception);
+
+SeedValue seed_object_get_property_at_index(SeedContext ctx,
+ SeedObject object,
+ gint index,
+ SeedException* exception);
+
+SeedValue seed_object_call(SeedContext ctx,
+ SeedObject object,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+
+GObject* seed_value_to_object(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_object(SeedContext ctx,
+ GObject* val,
+ SeedException* exception);
+
+SeedObject seed_make_object(SeedContext ctx,
+ SeedClass klass,
+ gpointer private_object);
+
+gpointer seed_object_get_private(SeedObject object);
+void seed_object_set_private(SeedObject object, gpointer value);
+
+gchar** seed_object_copy_property_names(SeedContext ctx, SeedObject object);
+
+gpointer seed_pointer_get_pointer(SeedContext ctx, SeedValue pointer);
+
+SeedObject seed_object_get_prototype(SeedContext ctx, SeedObject obj);
+
+gboolean seed_object_is_of_class(SeedContext ctx,
+ SeedObject obj,
+ SeedClass klass);
+
+SeedValue seed_make_pointer(SeedContext ctx, gpointer pointer);
+
+typedef SeedValue (*SeedFunctionCallback)(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+
+void seed_create_function(SeedContext ctx,
+ gchar* name,
+ SeedFunctionCallback func,
+ SeedObject obj);
+SeedObject seed_make_function(SeedContext ctx,
+ SeedFunctionCallback func,
+ const gchar* name);
+
+SeedObject seed_make_array(SeedContext ctx,
+ const SeedValue elements,
+ gsize num_elements,
+ SeedException* exception);
+
+typedef void (*SeedObjectInitializeCallback)(SeedContext ctx,
+ SeedObject object);
/* Using any functions that require a context from
*this callback has undefined results */
-typedef void (*SeedObjectFinalizeCallback) (SeedObject object);
-
-typedef gboolean (*SeedObjectHasPropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString string);
-typedef SeedValue (*SeedObjectGetPropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException * e);
-typedef gboolean (*SeedObjectSetPropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedValue value,
- SeedException * e);
-typedef gboolean (*SeedObjectDeletePropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException * e);
+typedef void (*SeedObjectFinalizeCallback)(SeedObject object);
+
+typedef gboolean (*SeedObjectHasPropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString string);
+typedef SeedValue (*SeedObjectGetPropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* e);
+typedef gboolean (*SeedObjectSetPropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e);
+typedef gboolean (*SeedObjectDeletePropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* e);
/* TODO: Have to decide on accumulator API
//typedef void (*SeedObjectGetPropertyNamesCallback) (SeedContext ctx, */
-typedef void (*SeedObjectGetPropertyNamesCallback) (void);
-
-typedef SeedValue (*SeedObjectCallAsFunctionCallback) (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue
- arguments[],
- SeedException *
- exception);
-typedef SeedValue (*SeedObjectCallAsConstructorCallback) (SeedContext ctx,
- SeedObject
- constructor,
- gsize
- argument_count,
- const SeedValue
- arguments[],
- SeedException *
- exception);
-
-typedef gboolean (*SeedObjectHasInstanceCallback) (SeedContext ctx,
- SeedObject constructor,
- SeedObject instance_p,
- SeedException * exception);
-
-typedef SeedValue (*SeedObjectConvertToTypeCallback) (SeedContext ctx,
- SeedObject object,
- SeedType type,
- SeedException *
- exception);
+typedef void (*SeedObjectGetPropertyNamesCallback)(void);
+
+typedef SeedValue (*SeedObjectCallAsFunctionCallback)(
+ SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+typedef SeedValue (*SeedObjectCallAsConstructorCallback)(
+ SeedContext ctx,
+ SeedObject constructor,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+
+typedef gboolean (*SeedObjectHasInstanceCallback)(SeedContext ctx,
+ SeedObject constructor,
+ SeedObject instance_p,
+ SeedException* exception);
+
+typedef SeedValue (*SeedObjectConvertToTypeCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedType type,
+ SeedException* exception);
typedef struct _seed_static_value
{
- const gchar *const name;
- SeedObjectGetPropertyCallback get_property;
- SeedObjectSetPropertyCallback set_property;
- SeedPropertyAttributes attributes;
+ const gchar* const name;
+ SeedObjectGetPropertyCallback get_property;
+ SeedObjectSetPropertyCallback set_property;
+ SeedPropertyAttributes attributes;
} seed_static_value;
typedef struct _seed_static_function
{
- const gchar *const name;
- SeedObjectCallAsFunctionCallback callback;
- SeedPropertyAttributes attributes;
+ const gchar* const name;
+ SeedObjectCallAsFunctionCallback callback;
+ SeedPropertyAttributes attributes;
} seed_static_function;
typedef struct _seed_class_definition
{
- int version; /* Always 0 */
- SeedClassAttributes attributes;
-
- const gchar *class_name;
- SeedClass parent_class;
-
- const seed_static_value *static_values;
- const seed_static_function *static_functions;
-
- SeedObjectInitializeCallback initialize;
- SeedObjectFinalizeCallback finalize;
- SeedObjectHasPropertyCallback has_property;
- SeedObjectGetPropertyCallback get_property;
- SeedObjectSetPropertyCallback set_property;
- SeedObjectDeletePropertyCallback delete_property;
- SeedObjectGetPropertyNamesCallback get_property_names;
- SeedObjectCallAsFunctionCallback call_as_function;
- SeedObjectCallAsConstructorCallback call_as_constructor;
- SeedObjectHasInstanceCallback has_instance;
- SeedObjectConvertToTypeCallback convert_to_type;
+ int version; /* Always 0 */
+ SeedClassAttributes attributes;
+
+ const gchar* class_name;
+ SeedClass parent_class;
+
+ const seed_static_value* static_values;
+ const seed_static_function* static_functions;
+
+ SeedObjectInitializeCallback initialize;
+ SeedObjectFinalizeCallback finalize;
+ SeedObjectHasPropertyCallback has_property;
+ SeedObjectGetPropertyCallback get_property;
+ SeedObjectSetPropertyCallback set_property;
+ SeedObjectDeletePropertyCallback delete_property;
+ SeedObjectGetPropertyNamesCallback get_property_names;
+ SeedObjectCallAsFunctionCallback call_as_function;
+ SeedObjectCallAsConstructorCallback call_as_constructor;
+ SeedObjectHasInstanceCallback has_instance;
+ SeedObjectConvertToTypeCallback convert_to_type;
} seed_class_definition;
-#define seed_empty_class { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
-
-SeedClass seed_create_class (seed_class_definition * def);
-
-SeedObject seed_make_constructor (SeedContext ctx,
- SeedClass klass,
- SeedObjectCallAsConstructorCallback constructor);
-
-void seed_engine_set_search_path (SeedEngine * eng, const gchar * path);
-gchar **seed_engine_get_search_path (SeedEngine * eng);
-
-void
-seed_signal_connect (SeedContext ctx,
- GObject *object,
- const gchar *signal,
- const gchar *script);
-
-void
-seed_signal_connect_value (SeedContext ctx,
- GObject *object,
- const gchar *signal,
- SeedValue function,
- SeedValue user_data);
-
-GClosure *seed_closure_new (SeedContext ctx,
- SeedObject function,
- SeedObject user_data,
- const gchar *description);
-
-
-SeedObject
-seed_closure_get_callable (GClosure *c);
-
-SeedValue
-seed_closure_invoke (GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
-
-SeedValue
-seed_closure_invoke_with_context (SeedContext ctx, GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
-
-void
-seed_closure_warn_exception (GClosure *c, SeedContext ctx, SeedException exception);
+#define seed_empty_class \
+ { \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ };
+
+SeedClass seed_create_class(seed_class_definition* def);
+
+SeedObject seed_make_constructor(
+ SeedContext ctx,
+ SeedClass klass,
+ SeedObjectCallAsConstructorCallback constructor);
+
+void seed_engine_set_search_path(SeedEngine* eng, const gchar* path);
+gchar** seed_engine_get_search_path(SeedEngine* eng);
+
+void seed_signal_connect(SeedContext ctx,
+ GObject* object,
+ const gchar* signal,
+ const gchar* script);
+
+void seed_signal_connect_value(SeedContext ctx,
+ GObject* object,
+ const gchar* signal,
+ SeedValue function,
+ SeedValue user_data);
+
+GClosure* seed_closure_new(SeedContext ctx,
+ SeedObject function,
+ SeedObject user_data,
+ const gchar* description);
+
+SeedObject seed_closure_get_callable(GClosure* c);
+
+SeedValue seed_closure_invoke(GClosure* closure,
+ SeedValue* args,
+ guint argc,
+ SeedException* exception);
+
+SeedValue seed_closure_invoke_with_context(SeedContext ctx,
+ GClosure* closure,
+ SeedValue* args,
+ guint argc,
+ SeedException* exception);
+
+void seed_closure_warn_exception(GClosure* c,
+ SeedContext ctx,
+ SeedException exception);
G_END_DECLS