Commit f04d27d2 authored by Tim Lunn's avatar Tim Lunn

New upstream version 1.51.91

parents 3868e9fc 542f9b7b
Copyright (c) 2008 litl, LLC
This project is dual-licensed as MIT and LGPLv2+.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
......
......@@ -30,25 +30,6 @@ mock-js-resources.h: $(srcdir)/test/mock-js-resources.gresource.xml $(modules_re
mock-js-resources.c: $(srcdir)/test/mock-js-resources.gresource.xml $(modules_resource_files)
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --sourcedir=$(builddir) --generate --c-name mock_js_resources $<
mock_js_invalidation_resources_dir = $(top_srcdir)/test/gjs-test-coverage/cache_invalidation
mock_js_invalidation_before_resources_files = \
$(mock_js_invalidation_resources_dir)/before/resource.js \
$(mock_js_invalidation_resources_dir)/before/mock-js-resource-cache-before.gresource.xml \
$(NULL)
mock_js_invalidation_after_resources_files = \
$(mock_js_invalidation_resources_dir)/after/resource.js \
$(mock_js_invalidation_resources_dir)/after/mock-js-resource-cache-after.gresource.xml \
$(NULL)
mock_js_invalidation_resources_files = \
$(mock_js_invalidation_before_resources_files) \
$(mock_js_invalidation_after_resources_files) \
$(NULL)
mock-cache-invalidation-before.gresource: $(mock_js_invalidation_before_resources_files)
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(mock_js_invalidation_resources_dir)/before $(mock_js_invalidation_resources_dir)/before/mock-js-resource-cache-before.gresource.xml
mock-cache-invalidation-after.gresource: $(mock_js_invalidation_after_resources_files)
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(mock_js_invalidation_resources_dir)/after $(mock_js_invalidation_resources_dir)/after/mock-js-resource-cache-after.gresource.xml
jsunit_resources_files := $(shell glib-compile-resources --sourcedir=$(srcdir)/installed-tests/js --generate-dependencies $(srcdir)/installed-tests/js/jsunit.gresources.xml)
jsunit-resources.h: $(srcdir)/installed-tests/js/jsunit.gresources.xml $(jsunit_resources_files)
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir)/installed-tests/js --sourcedir=$(builddir) --generate --c-name jsunit_resources $<
......@@ -59,15 +40,11 @@ BUILT_SOURCES += mock-js-resources.c jsunit-resources.h jsunit-resources.c
EXTRA_DIST += \
$(mock_js_resources_files) \
$(mock_js_invalidation_resources_files) \
$(srcdir)/test/mock-js-resources.gresource.xml \
$(srcdir)/test/gjs-test-coverage/loadedJSFromResource.js \
$(jsunit_resources_files) \
$(NULL)
CLEANFILES += \
mock-cache-invalidation-before.gresource \
mock-cache-invalidation-after.gresource \
mock-js-resources.c \
jsunit-resources.c \
jsunit-resources.h \
......@@ -105,11 +82,6 @@ gjs_tests_gtester_SOURCES = \
mock-js-resources.c \
$(NULL)
gjs_tests_gtester_DEPENDENCIES = \
mock-cache-invalidation-before.gresource \
mock-cache-invalidation-after.gresource \
$(NULL)
minijasmine_SOURCES = \
installed-tests/minijasmine.cpp \
jsunit-resources.c \
......@@ -218,7 +190,6 @@ CLEANFILES += $(TEST_INTROSPECTION_GIRS) $(TEST_INTROSPECTION_TYPELIBS)
common_jstests_files = \
installed-tests/js/testself.js \
installed-tests/js/testByteArray.js \
installed-tests/js/testCoverage.js \
installed-tests/js/testExceptions.js \
installed-tests/js/testEverythingBasic.js \
installed-tests/js/testEverythingEncapsulated.js \
......
......@@ -43,6 +43,12 @@ pkgconfig_DATA = gjs-1.0.pc
EXTRA_DIST += gjs-1.0.pc.in
valgrinddir = $(datadir)/gjs-1.0/valgrind
dist_valgrind_DATA = installed-tests/extra/gjs.supp
lsandir = $(datadir)/gjs-1.0/lsan
dist_lsan_DATA = installed-tests/extra/lsan.supp
########################################################################
gjs_directory_defines = \
-DGJS_TOP_SRCDIR=\"$(top_srcdir)\" \
......@@ -77,6 +83,10 @@ endif
# reasons
libgjs_la_SOURCES = $(gjs_srcs)
if ENABLE_PROFILER
libgjs_la_SOURCES += $(gjs_sysprof_srcs)
endif
# Also, these files used to be a separate library
libgjs_private_source_files = $(gjs_private_srcs)
......@@ -212,6 +222,8 @@ CPPCHECK=cppcheck
### cppcheck static code analysis
#
cppcheck:
$(CPPCHECK) --enable=warning,performance,portability,information,missingInclude --force -q $(top_srcdir) -I $(top_builddir)
$(CPPCHECK) --inline-suppr \
--enable=warning,performance,portability,information,missingInclude \
--force -q $(top_srcdir) -I $(top_builddir)
-include $(top_srcdir)/git.mk
This diff is collapsed.
Version 1.51.91
---------------
- Promises now resolve with a higher priority, so asynchronous code should be
faster. [Jason Hicks]
- Closed bugs and merge requests:
* New build 'warnings' [#117, !62, !63, Claudio André, Philip Chimento]
* Various CI maintenance [!64, !65, !66, Claudio André, Philip Chimento]
* profiler: Don't include alloca.h when disabled [!69, Ting-Wei Lan]
* GNOME crash with fatal error "Finalizing proxy for an object that's
scheduled to be unrooted: Gio.Subprocess" in gjs [#26, !70, Philip Chimento]
Version 1.51.90
---------------
- Note that all the old Bugzilla bug reports have been migrated over to GitLab.
- GJS now, once again, includes a profiler, which outputs files that can be
read with sysprof. To use it, simply run your program with the environment
variable GJS_ENABLE_PROFILER=1 set. If your program is a JS script that is
executed with the interpreter, you can also pass --profile to the
interpreter. See "gjs --help" for more info.
- New API: For programs that want more control over when to start and stop
profiling, there is new API for GjsContext. When you create your GjsContext
there are two construct-only properties available, "profiler-enabled" and
"profiler-sigusr2". If you set profiler-sigusr2 to TRUE, then the profiler
can be started and stopped while the program is running by sending SIGUSR2 to
the process. You can also use gjs_context_get_profiler(),
gjs_profiler_set_filename(), gjs_profiler_start(), and gjs_profiler_stop()
for more explicit control.
- New API: GObject.signal_connect(), GObject.signal_disconnect(), and
GObject.signal_emit_by_name() are now available in case a GObject-derived
class has conflicting connect(), disconnect() or emit() methods.
- Closed bugs and merge requests:
* Handle 0-valued GType gracefully [#11, !10, Philip Chimento]
* Profiler [#31, !37, Christian Hergert, Philip Chimento]
* Various maintenance [!40, !59, Philip Chimento, Giovanni Campagna]
* Rename GObject.Object.connect/disconnect? [#65, !47, Giovanni Campagna]
* Better debugging output for uncatchable exceptions [!39, Simon McVittie]
* Update Docker images and various CI maintenance [!54, !56, !57, !58,
Claudio André]
* Install GJS suppression file for Valgrind [#2, !55, Philip Chimento]
Version 1.50.4
--------------
- Closed bugs and merge requests:
* Gnome Shell crash with places-status extension when you plug an USB device
[#33, !38, Philip Chimento]
Version 1.50.3
--------------
......@@ -14,6 +71,76 @@ Version 1.50.3
!35, Valentín Barros]
* Various fixes from the master branch for rare crashes [Philip Chimento]
Version 1.51.4
--------------
- We welcomed code and documentation from several new contributors in this
release!
- GJS will now log a warning when a GObject is accessed in Javascript code
after the underlying object has been freed in C. (This used to work most of
the time, but crash unpredictably.) We now prevent this situation which, is
usually caused by a memory management bug in the underlying C library.
- APIs exposed through GObject Introspection that use the GdkAtom type are now
usable from Javascript. Previously these did not work. On the Javascript side,
a GdkAtom translates to a string, so there is no Gdk.Atom type that you can
access. The special atom GDK_NONE translates to null in Javascript, and there
is also no Gdk.NONE constant.
- The GitLab CI tasks have continued to gradually become more and more
sophisticated.
- Closed bugs and merge requests:
* Add checks for GObjects that have been finalized [#21, #23, !22, !27, Marco
Trevisan]
* Fail static analyzer if new warnings are found [!24, Claudio André]
* Run code coverage on GitLab [!20, Claudio André]
* Amend gtk.js and add gtk-application.js with suggestion [!32, Andy Holmes]
* Improve GdkAtom support that is blocking clipboard APIs [#14, !29, makepost]
* Test "Cairo context has methods when created from a C function" fails [#27,
!35, Valentín Barros]
* Various CI improvements [#6, !26, !34, Claudio André]
* Various maintenance [!23, !36, Philip Chimento]
Version 1.51.3
--------------
- This release was made from an earlier state of master, before a breaking
change was merged, while we decide whether to revert that change or not.
- Closed bugs and merge requests:
* CI improvements on GitLab [!14, !15, !19, Claudio André]
* Fix CI build on Ubuntu [#16, !18, !21, Claudio André, Philip Chimento]
Version 1.51.2
--------------
- Version 1.51.1 was skipped.
- The home of GJS is now at GNOME's GitLab instance:
https://gitlab.gnome.org/GNOME/gjs
From now on we'll be taking GitLab merge requests instead of Bugzilla
patches. If you want to report a bug, please report it at GitLab.
- Closed bugs and merge requests:
* Allow throwing GErrors from JS virtual functions [#682701, Giovanni
Campagna]
* [RFC] bootstrap system [#777724, Jasper St. Pierre, Philip Chimento]
* Fix code coverage (and refactor it to take advantage of mozjs52 features)
[#788166, !1, !3, Philip Chimento]
* Various maintenance [!2, Philip Chimento]
* Get GitLab CI working and various improvements [#6, !7, !9, !11, !13,
Claudio André]
* Add build status badge to README [!8, Claudio André]
* Use Docker images for CI [!12, Claudio André]
- Some changes in progress to improve garbage collection when signals are
disconnected. See bug #679688 for more information [Giovanni Campagna]
Version 1.50.2
--------------
......
[![Build Status](https://gitlab.gnome.org/GNOME/gjs/badges/master/build.svg)](https://gitlab.gnome.org/GNOME/gjs/pipelines)
[![coverage report](https://gitlab.gnome.org/GNOME/gjs/badges/master/coverage.svg)](https://gitlab.gnome.org/GNOME/gjs/-/jobs)
[![License](https://img.shields.io/badge/License-LGPL%20v2%2B-blue.svg)](https://gitlab.gnome.org/GNOME/gjs/blob/master/COPYING)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://gitlab.gnome.org/GNOME/gjs/blob/master/COPYING)
JavaScript bindings for GNOME
=============================
It's mainly based on Spidermonkey javascript engine and the GObject introspection framework.
Available as part of your GNOME distribution. Powers GNOME Shell, Polari,
GNOME Documents, and many other apps.
......
......@@ -1237,6 +1237,7 @@ m4_include([m4/ax_is_release.m4])
m4_include([m4/ax_pkg_check_modules.m4])
m4_include([m4/ax_require_defined.m4])
m4_include([m4/ax_valgrind_check.m4])
m4_include([m4/extensions.m4])
m4_include([m4/introspection.m4])
m4_include([m4/libtool.m4])
m4_include([m4/ltoptions.m4])
......@@ -1244,3 +1245,4 @@ m4_include([m4/ltsugar.m4])
m4_include([m4/ltversion.m4])
m4_include([m4/lt~obsolete.m4])
m4_include([m4/pkg.m4])
m4_include([m4/timer_time.m4])
......@@ -6,6 +6,9 @@
/* Define if you want to build with GTK+ support */
#undef ENABLE_GTK
/* Define if the profiler should be built. */
#undef ENABLE_PROFILER
/* The name of the gettext domain */
#undef GETTEXT_PACKAGE
......@@ -54,6 +57,9 @@
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the `timer_settime' function. */
#undef HAVE_TIMER_SETTIME
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
......@@ -85,5 +91,86 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable general extensions on macOS. */
#ifndef _DARWIN_C_SOURCE
# undef _DARWIN_C_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable NetBSD extensions on NetBSD. */
#ifndef _NETBSD_SOURCE
# undef _NETBSD_SOURCE
#endif
/* Enable OpenBSD extensions on NetBSD. */
#ifndef _OPENBSD_SOURCE
# undef _OPENBSD_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions specified by ISO/IEC TS 18661-5:2014. */
#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
#endif
/* Enable extensions specified by ISO/IEC TS 18661-1:2014. */
#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
# undef __STDC_WANT_IEC_60559_BFP_EXT__
#endif
/* Enable extensions specified by ISO/IEC TS 18661-2:2015. */
#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
# undef __STDC_WANT_IEC_60559_DFP_EXT__
#endif
/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */
#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
#endif
/* Enable extensions specified by ISO/IEC TS 18661-3:2015. */
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
# undef __STDC_WANT_IEC_60559_TYPES_EXT__
#endif
/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */
#ifndef __STDC_WANT_LIB_EXT2__
# undef __STDC_WANT_LIB_EXT2__
#endif
/* Enable extensions specified by ISO/IEC 24747:2009. */
#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
# undef __STDC_WANT_MATH_SPEC_FUNCS__
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable X/Open extensions if necessary. HP-UX 11.11 defines
mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
whether compiling with -Ae or -D_HPUX_SOURCE=1. */
#ifndef _XOPEN_SOURCE
# undef _XOPEN_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Version number of package */
#undef VERSION
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 1 to make NetBSD features available. MINIX 3 needs this. */
#undef _NETBSD_SOURCE
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for 'stat' and other things to work. */
#undef _POSIX_SOURCE
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,8 +2,8 @@
# Process this file with autoconf to produce a configure script.
m4_define(pkg_major_version, 1)
m4_define(pkg_minor_version, 50)
m4_define(pkg_micro_version, 3)
m4_define(pkg_minor_version, 51)
m4_define(pkg_micro_version, 91)
m4_define(pkg_version, pkg_major_version.pkg_minor_version.pkg_micro_version)
m4_define(pkg_int_version, (pkg_major_version * 100 + pkg_minor_version) * 100 + pkg_micro_version)
......@@ -30,6 +30,7 @@ PKG_PROG_PKG_CONFIG
PKG_INSTALLDIR
AC_LANG([C++])
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CXX
AX_CXX_COMPILE_STDCXX_11
......@@ -105,6 +106,18 @@ AS_IF([test x$have_gtk = xyes], [
], [AS_IF([test "x$with_gtk" = "xyes"],
[AC_MSG_ERROR([GTK requested but not found])])])
# Some Linux APIs required for profiler
AC_ARG_ENABLE([profiler],
[AS_HELP_STRING([--disable-profiler], [Don't build profiler])])
AS_IF([test x$enable_profiler != xno], [
gl_TIMER_TIME
AS_IF([test x$ac_cv_func_timer_settime = xno],
[AC_MSG_ERROR([The profiler is currently only supported on Linux.
Configure with --disable-profiler to skip it on other platforms.])])
AC_DEFINE([ENABLE_PROFILER], [1], [Define if the profiler should be built.])
])
AM_CONDITIONAL([ENABLE_PROFILER], [test x$enable_profiler != xno])
PKG_CHECK_VAR([GI_DATADIR], [gobject-introspection-1.0], [gidatadir])
# readline
......@@ -243,6 +256,11 @@ AS_IF([test -n "${SAN_FLAGS}"], [
])
AC_SUBST([NO_UNDEFINED_FLAG])
# This is needed (at least) for clang on Ubuntu PIC (Position-Independent Code)
AX_APPEND_COMPILE_FLAGS([$lt_prog_compiler_pic], [CXXFLAGS])
AX_APPEND_COMPILE_FLAGS([$lt_prog_compiler_pic], [CFLAGS])
AX_APPEND_LINK_FLAGS([$lt_prog_compiler_pic])
AC_ARG_WITH([xvfb-tests],
[AS_HELP_STRING([--with-xvfb-tests],
[Run all tests under an XVFB server @<:@default=no@:>@])])
......@@ -304,6 +322,7 @@ AC_MSG_RESULT([
readline: ${ac_cv_header_readline_readline_h}
dtrace: ${enable_dtrace:-no}
systemtap: ${enable_systemtap:-no}
Profiler: ${enable_profiler:-yes}
Run tests under: ${TEST_MSG}
Code coverage: ${enable_code_coverage}
])
imports.gi.versions.Gtk = '3.0';
// Include this in case both GTK3 and GTK4 installed, otherwise an exception
// will be thrown
imports.gi.versions.Gtk = "3.0";
const Gtk = imports.gi.Gtk;
// This is a callback function. The data arguments are ignored
// in this example. More on callbacks below.
function hello(widget) {
log("Hello World");
}
// Initialize Gtk before you start calling anything from the import
Gtk.init(null);
// Construct a top-level window
let window = new Gtk.Window ({
type: Gtk.WindowType.TOPLEVEL,
title: "A default title",
default_width: 300,
default_height: 250,
// A decent example of how constants are mapped:
// 'Gtk' and 'WindowPosition' from the enum name GtkWindowPosition,
// 'CENTER' from the enum's constant GTK_WIN_POS_CENTER
window_position: Gtk.WindowPosition.CENTER
});
// Object properties can also be set or changed after construction, unless they
// are marked construct-only.
window.title = "Hello World!";
// This is a callback function
function onDeleteEvent(widget, event) {
// If you return false in the "delete_event" signal handler,
// GTK will emit the "destroy" signal. Returning true means
// you don't want the window to be destroyed.
// This is useful for popping up 'are you sure you want to quit?'
// type dialogs.
log("delete event occurred");
// Change false to true and the main window will not be destroyed
// with a "delete_event".
log("delete-event emitted");
// If you return false in the "delete_event" signal handler, Gtk will emit
// the "destroy" signal.
//
// Returning true gives you a chance to pop up 'are you sure you want to
// quit?' type dialogs.
return false;
}
function onDestroy(widget) {
log("destroy signal occurred");
};
// When the window is given the "delete_event" signal (this is given by the
// window manager, usually by the "close" option, or on the titlebar), we ask
// it to call the onDeleteEvent() function as defined above.
window.connect("delete-event", onDeleteEvent);
// GJS will warn when calling a C function with unexpected arguments...
//
// window.connect("destroy", Gtk.main_quit);
//
// ...so use arrow functions for inline callbacks with arguments to adjust
window.connect("destroy", () => {
Gtk.main_quit();
}
Gtk.init(null);
// create a new window
let win = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL });
// When the window is given the "delete_event" signal (this is given
// by the window manager, usually by the "close" option, or on the
// titlebar), we ask it to call the onDeleteEvent () function
// as defined above.
win.connect("delete-event", onDeleteEvent);
// Here we connect the "destroy" event to a signal handler.
// This event occurs when we call gtk_widget_destroy() on the window,
// or if we return false in the "onDeleteEvent" callback.
win.connect("destroy", onDestroy);
// Sets the border width of the window.
win.set_border_width(10);
// Creates a new button with the label "Hello World".
let button = new Gtk.Button({ label: "Hello World" });
// When the button receives the "clicked" signal, it will call the
// function hello(). The hello() function is defined above.
button.connect("clicked", hello);
// This will cause the window to be destroyed by calling
// gtk_widget_destroy(window) when "clicked". Again, the destroy
// signal could come from here, or the window manager.
button.connect("clicked", function() {
win.destroy();
});
// This packs the button into the window (a GTK container).
win.add(button);
// The final step is to display this newly created widget.
button.show();
// and the window
win.show();
// All gtk applications must have a Gtk.main(). Control ends here
// and waits for an event to occur (like a key press or mouse event).
});
// Create a button to close the window
let button = new Gtk.Button({
label: "Close the Window",
// Set visible to 'true' if you don't want to call button.show() later
visible: true,
// Another example of constant mapping:
// 'Gtk' and 'Align' are taken from the GtkAlign enum,
// 'CENTER' from the constant GTK_ALIGN_CENTER
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER
});
// Connect to the 'clicked' signal, using another way to call an arrow function
button.connect("clicked", () => window.destroy());
// Add the button to the window
window.add(button);
// Show the window
window.show();
// All gtk applications must have a Gtk.main(). Control will end here and wait
// for an event to occur (like a key press or mouse event). The main loop will
// run until Gtk.main_quit is called.
Gtk.main();
This diff is collapsed.
......@@ -110,11 +110,8 @@ gjs_define_static_methods(JSContext *context,
return true;
}
/*
* The *objp out parameter, on success, should be null to indicate that id
* was not resolved; and non-null, referring to obj or one of its prototypes,
* if id was resolved.
*/
/* The *resolved out parameter, on success, should be false to indicate that id
* was not resolved; and true if id was resolved. */
static bool
boxed_resolve(JSContext *context,
JS::HandleObject obj,
......@@ -122,7 +119,7 @@ boxed_resolve(JSContext *context,
bool *resolved)
{
Boxed *priv;
GjsAutoJSChar name(context);
GjsAutoJSChar name;
if (!gjs_get_string_id(context, id, &name)) {
*resolved = false;
......@@ -278,7 +275,7 @@ boxed_init_from_props(JSContext *context,
JS::RootedId prop_id(context);
for (ix = 0, length = ids.length(); ix < length; ix++) {
GIFieldInfo *field_info;
GjsAutoJSChar name(context);
GjsAutoJSChar name;
if (!gjs_get_string_id(context, ids[ix], &name))
return false;
......@@ -1284,7 +1281,7 @@ gjs_typecheck_boxed(JSContext *context,
if (priv->gboxed == NULL) {
if (throw_error) {
gjs_throw_custom(context, "TypeError", NULL,
gjs_throw_custom(context, JSProto_TypeError, nullptr,
"Object is %s.%s.prototype, not an object instance - cannot convert to a boxed instance",
g_base_info_get_namespace( (GIBaseInfo*) priv->info),
g_base_info_get_name( (GIBaseInfo*) priv->info));
......@@ -1302,14 +1299,14 @@ gjs_typecheck_boxed(JSContext *context,
if (!result && throw_error) {
if (expected_info != NULL) {
gjs_throw_custom(context, "TypeError", NULL,
gjs_throw_custom(context, JSProto_TypeError, nullptr,
"Object is of type %s.%s - cannot convert to %s.%s",
g_base_info_get_namespace((GIBaseInfo*) priv->info),
g_base_info_get_name((GIBaseInfo*) priv->info),
g_base_info_get_namespace((GIBaseInfo*) expected_info),
g_base_info_get_name((GIBaseInfo*) expected_info));
} else {
gjs_throw_custom(context, "TypeError", NULL,
gjs_throw_custom(context, JSProto_TypeError, nullptr,
"Object is of type %s.%s - cannot convert to %s",
g_base_info_get_namespace((GIBaseInfo*) priv->info),
g_base_info_get_name((GIBaseInfo*) priv->info),
......
......@@ -185,10 +185,12 @@ closure_finalize(gpointer data,
self->~Closure();
}
void
bool
gjs_closure_invoke(GClosure *closure,
JS::HandleObject this_obj,
const JS::HandleValueArray& args,
JS::MutableHandleValue retval)
JS::MutableHandleValue retval,
bool return_exception)
{
Closure *c;
JSContext *context;
......@@ -198,11 +200,11 @@ gjs_closure_invoke(GClosure *closure,
if (c->obj == nullptr) {
/* We were destroyed; become a no-op */
c->context = NULL;
return;
return false;
}
context = c->context;
JS_BeginRequest(context);
JSAutoRequest ar(context);
JSAutoCompartment ac(context, c->obj);
if (JS_IsExceptionPending(context)) {
......@@ -212,18 +214,26 @@ gjs_closure_invoke(GClosure *closure,
}
JS::RootedValue v_closure(context, JS::ObjectValue(*c->obj));
if (!gjs_call_function_value(context,
/* "this" object; null is some kind of default presumably */
nullptr,
v_closure, args, retval)) {
if (!gjs_call_function_value(context, this_obj, v_closure, args, retval)) {
/* Exception thrown... */
gjs_debug_closure("Closure invocation failed (exception should "
"have been thrown) closure %p callable %p",
closure, c->obj.get());
if (!gjs_log_exception(context))
/* If an exception has been thrown, log it, unless the caller
* explicitly wants to handle it manually (for example to turn it
* into a GError), in which case it replaces the return value
* (which is not valid anyway) */
if (JS_IsExceptionPending(context)) {
if (return_exception)
JS_GetPendingException(context, retval);
else
gjs_log_exception(context);
} else {
retval.setUndefined();
gjs_debug_closure("Closure invocation failed but no exception was set?"
"closure %p", closure);
goto out;
}
return false;
}
if (gjs_log_exception(context)) {
......@@ -232,9 +242,7 @@ gjs_closure_invoke(GClosure *closure,
}
JS_MaybeGC(context);
out:
JS_EndRequest(context);
return true;
}
bool
......
......@@ -36,9 +36,11 @@ GClosure* gjs_closure_new (JSContext *context,
const char *description,
bool root_function);
void gjs_closure_invoke(GClosure *closure,
bool gjs_closure_invoke(GClosure *closure,
JS::HandleObject this_obj,
const JS::HandleValueArray& args,
JS::MutableHandleValue retval);
JS::MutableHandleValue retval,
bool return_exception);
JSContext* gjs_closure_get_context (GClosure *closure);
bool gjs_closure_is_valid (GClosure *closure);
......
......@@ -61,8 +61,6 @@ gjs_foreign_load_foreign_module(JSContext *context,
int i;
for (i = 0; foreign_modules[i].gi_namespace; ++i) {
int code;
GError *error = NULL;
char *script;
if (strcmp(gi_namespace, foreign_modules[i].gi_namespace) != 0)
......@@ -74,12 +72,11 @@ gjs_foreign_load_foreign_module(JSContext *context,
// FIXME: Find a way to check if a module is imported
// and only execute this statement if isn't
script = g_strdup_printf("imports.%s;", gi_namespace);
if (!gjs_context_eval((GjsContext*) JS_GetContextPrivate(context), script, strlen(script),
"<internal>", &code,
&error)) {
g_printerr("ERROR: %s\n", error->message);
JS::RootedValue retval(context);
if (!gjs_eval_with_scope(context, nullptr, script, strlen(script),
"<internal>", &retval)) {