Commit 173741d0 authored by Philip Chimento's avatar Philip Chimento

Merge branch 'master.windows' into 'master'

Fix Windows builds on GIT master

Closes #228

See merge request GNOME/gjs!270
parents 64a88b75 169e21fc
...@@ -36,6 +36,7 @@ AC_LANG([C++]) ...@@ -36,6 +36,7 @@ AC_LANG([C++])
AC_USE_SYSTEM_EXTENSIONS AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CXX AC_PROG_CXX
AX_CXX_COMPILE_STDCXX_14 AX_CXX_COMPILE_STDCXX_14
AC_CHECK_HEADERS([sys/syscall.h unistd.h])
LT_PREREQ([2.2.0]) LT_PREREQ([2.2.0])
# no stupid static libraries # no stupid static libraries
......
...@@ -1592,7 +1592,7 @@ gjs_value_to_g_argument(JSContext *context, ...@@ -1592,7 +1592,7 @@ gjs_value_to_g_argument(JSContext *context,
GjsAutoBaseInfo interface_info = GjsAutoBaseInfo interface_info =
g_type_info_get_interface(type_info); g_type_info_get_interface(type_info);
g_assert(interface_info != NULL); g_assert(interface_info);
GIInfoType interface_type = g_base_info_get_type(interface_info); GIInfoType interface_type = g_base_info_get_type(interface_info);
if (interface_type == GI_INFO_TYPE_ENUM || if (interface_type == GI_INFO_TYPE_ENUM ||
......
...@@ -882,6 +882,7 @@ BoxedPrototype::BoxedPrototype(GIStructInfo* info, GType gtype) ...@@ -882,6 +882,7 @@ BoxedPrototype::BoxedPrototype(GIStructInfo* info, GType gtype)
m_zero_args_constructor(-1), m_zero_args_constructor(-1),
m_default_constructor(-1), m_default_constructor(-1),
m_default_constructor_name(JSID_VOID), m_default_constructor_name(JSID_VOID),
m_field_map(nullptr),
m_can_allocate_directly(struct_is_simple(info)) { m_can_allocate_directly(struct_is_simple(info)) {
GJS_INC_COUNTER(boxed_prototype); GJS_INC_COUNTER(boxed_prototype);
} }
......
...@@ -55,7 +55,7 @@ class BoxedInstance; ...@@ -55,7 +55,7 @@ class BoxedInstance;
class BoxedBase class BoxedBase
: public GIWrapperBase<BoxedBase, BoxedPrototype, BoxedInstance> { : public GIWrapperBase<BoxedBase, BoxedPrototype, BoxedInstance> {
friend class GIWrapperBase; friend class GIWrapperBase<BoxedBase, BoxedPrototype, BoxedInstance>;
protected: protected:
explicit BoxedBase(BoxedPrototype* proto = nullptr) explicit BoxedBase(BoxedPrototype* proto = nullptr)
...@@ -89,8 +89,9 @@ class BoxedBase ...@@ -89,8 +89,9 @@ class BoxedBase
class BoxedPrototype : public GIWrapperPrototype<BoxedBase, BoxedPrototype, class BoxedPrototype : public GIWrapperPrototype<BoxedBase, BoxedPrototype,
BoxedInstance, GIStructInfo> { BoxedInstance, GIStructInfo> {
friend class GIWrapperPrototype; friend class GIWrapperPrototype<BoxedBase, BoxedPrototype, BoxedInstance,
friend class GIWrapperBase; GIStructInfo>;
friend class GIWrapperBase<BoxedBase, BoxedPrototype, BoxedInstance>;
using FieldMap = using FieldMap =
JS::GCHashMap<JS::Heap<JSString*>, GjsAutoFieldInfo, JS::GCHashMap<JS::Heap<JSString*>, GjsAutoFieldInfo,
...@@ -155,8 +156,8 @@ class BoxedPrototype : public GIWrapperPrototype<BoxedBase, BoxedPrototype, ...@@ -155,8 +156,8 @@ class BoxedPrototype : public GIWrapperPrototype<BoxedBase, BoxedPrototype,
class BoxedInstance class BoxedInstance
: public GIWrapperInstance<BoxedBase, BoxedPrototype, BoxedInstance> { : public GIWrapperInstance<BoxedBase, BoxedPrototype, BoxedInstance> {
friend class GIWrapperInstance; friend class GIWrapperInstance<BoxedBase, BoxedPrototype, BoxedInstance>;
friend class GIWrapperBase; friend class GIWrapperBase<BoxedBase, BoxedPrototype, BoxedInstance>;
friend class BoxedBase; // for field_getter, etc. friend class BoxedBase; // for field_getter, etc.
bool m_allocated_directly : 1; bool m_allocated_directly : 1;
......
...@@ -248,7 +248,8 @@ FundamentalPrototype::FundamentalPrototype(GIObjectInfo* info, GType gtype) ...@@ -248,7 +248,8 @@ FundamentalPrototype::FundamentalPrototype(GIObjectInfo* info, GType gtype)
m_ref_function(g_object_info_get_ref_function_pointer(info)), m_ref_function(g_object_info_get_ref_function_pointer(info)),
m_unref_function(g_object_info_get_unref_function_pointer(info)), m_unref_function(g_object_info_get_unref_function_pointer(info)),
m_get_value_function(g_object_info_get_get_value_function_pointer(info)), m_get_value_function(g_object_info_get_get_value_function_pointer(info)),
m_set_value_function(g_object_info_get_set_value_function_pointer(info)) { m_set_value_function(g_object_info_get_set_value_function_pointer(info)),
m_constructor_info(nullptr) {
g_assert(m_ref_function); g_assert(m_ref_function);
g_assert(m_unref_function); g_assert(m_unref_function);
g_assert(m_set_value_function); g_assert(m_set_value_function);
......
...@@ -45,7 +45,8 @@ class FundamentalInstance; ...@@ -45,7 +45,8 @@ class FundamentalInstance;
class FundamentalBase class FundamentalBase
: public GIWrapperBase<FundamentalBase, FundamentalPrototype, : public GIWrapperBase<FundamentalBase, FundamentalPrototype,
FundamentalInstance> { FundamentalInstance> {
friend class GIWrapperBase; friend class GIWrapperBase<FundamentalBase, FundamentalPrototype,
FundamentalInstance>;
protected: protected:
explicit FundamentalBase(FundamentalPrototype* proto = nullptr) explicit FundamentalBase(FundamentalPrototype* proto = nullptr)
...@@ -66,8 +67,10 @@ class FundamentalBase ...@@ -66,8 +67,10 @@ class FundamentalBase
class FundamentalPrototype class FundamentalPrototype
: public GIWrapperPrototype<FundamentalBase, FundamentalPrototype, : public GIWrapperPrototype<FundamentalBase, FundamentalPrototype,
FundamentalInstance> { FundamentalInstance> {
friend class GIWrapperPrototype; friend class GIWrapperPrototype<FundamentalBase, FundamentalPrototype,
friend class GIWrapperBase; FundamentalInstance>;
friend class GIWrapperBase<FundamentalBase, FundamentalPrototype,
FundamentalInstance>;
GIObjectInfoRefFunction m_ref_function; GIObjectInfoRefFunction m_ref_function;
GIObjectInfoUnrefFunction m_unref_function; GIObjectInfoUnrefFunction m_unref_function;
...@@ -122,8 +125,10 @@ class FundamentalPrototype ...@@ -122,8 +125,10 @@ class FundamentalPrototype
class FundamentalInstance class FundamentalInstance
: public GIWrapperInstance<FundamentalBase, FundamentalPrototype, : public GIWrapperInstance<FundamentalBase, FundamentalPrototype,
FundamentalInstance> { FundamentalInstance> {
friend class GIWrapperInstance; friend class GIWrapperInstance<FundamentalBase, FundamentalPrototype,
friend class GIWrapperBase; FundamentalInstance>;
friend class GIWrapperBase<FundamentalBase, FundamentalPrototype,
FundamentalInstance>;
explicit FundamentalInstance(JSContext* cx, JS::HandleObject obj); explicit FundamentalInstance(JSContext* cx, JS::HandleObject obj);
~FundamentalInstance(void); ~FundamentalInstance(void);
......
...@@ -51,7 +51,7 @@ class ErrorInstance; ...@@ -51,7 +51,7 @@ class ErrorInstance;
class ErrorBase class ErrorBase
: public GIWrapperBase<ErrorBase, ErrorPrototype, ErrorInstance> { : public GIWrapperBase<ErrorBase, ErrorPrototype, ErrorInstance> {
friend class GIWrapperBase; friend class GIWrapperBase<ErrorBase, ErrorPrototype, ErrorInstance>;
protected: protected:
explicit ErrorBase(ErrorPrototype* proto = nullptr) explicit ErrorBase(ErrorPrototype* proto = nullptr)
...@@ -93,8 +93,9 @@ class ErrorBase ...@@ -93,8 +93,9 @@ class ErrorBase
class ErrorPrototype : public GIWrapperPrototype<ErrorBase, ErrorPrototype, class ErrorPrototype : public GIWrapperPrototype<ErrorBase, ErrorPrototype,
ErrorInstance, GIEnumInfo> { ErrorInstance, GIEnumInfo> {
friend class GIWrapperPrototype; friend class GIWrapperPrototype<ErrorBase, ErrorPrototype, ErrorInstance,
friend class GIWrapperBase; GIEnumInfo>;
friend class GIWrapperBase<ErrorBase, ErrorPrototype, ErrorInstance>;
GQuark m_domain; GQuark m_domain;
...@@ -110,8 +111,9 @@ class ErrorPrototype : public GIWrapperPrototype<ErrorBase, ErrorPrototype, ...@@ -110,8 +111,9 @@ class ErrorPrototype : public GIWrapperPrototype<ErrorBase, ErrorPrototype,
class ErrorInstance : public GIWrapperInstance<ErrorBase, ErrorPrototype, class ErrorInstance : public GIWrapperInstance<ErrorBase, ErrorPrototype,
ErrorInstance, GError> { ErrorInstance, GError> {
friend class GIWrapperInstance; friend class GIWrapperInstance<ErrorBase, ErrorPrototype, ErrorInstance,
friend class GIWrapperBase; GError>;
friend class GIWrapperBase<ErrorBase, ErrorPrototype, ErrorInstance>;
explicit ErrorInstance(JSContext* cx, JS::HandleObject obj); explicit ErrorInstance(JSContext* cx, JS::HandleObject obj);
~ErrorInstance(void); ~ErrorInstance(void);
......
...@@ -50,7 +50,8 @@ class InterfaceInstance; ...@@ -50,7 +50,8 @@ class InterfaceInstance;
class InterfaceBase : public GIWrapperBase<InterfaceBase, InterfacePrototype, class InterfaceBase : public GIWrapperBase<InterfaceBase, InterfacePrototype,
InterfaceInstance> { InterfaceInstance> {
friend class GIWrapperBase; friend class GIWrapperBase<InterfaceBase, InterfacePrototype,
InterfaceInstance>;
protected: protected:
explicit InterfaceBase(InterfacePrototype* proto = nullptr) explicit InterfaceBase(InterfacePrototype* proto = nullptr)
...@@ -83,8 +84,10 @@ class InterfaceBase : public GIWrapperBase<InterfaceBase, InterfacePrototype, ...@@ -83,8 +84,10 @@ class InterfaceBase : public GIWrapperBase<InterfaceBase, InterfacePrototype,
class InterfacePrototype class InterfacePrototype
: public GIWrapperPrototype<InterfaceBase, InterfacePrototype, : public GIWrapperPrototype<InterfaceBase, InterfacePrototype,
InterfaceInstance, GIInterfaceInfo> { InterfaceInstance, GIInterfaceInfo> {
friend class GIWrapperPrototype; friend class GIWrapperPrototype<InterfaceBase, InterfacePrototype,
friend class GIWrapperBase; InterfaceInstance, GIInterfaceInfo>;
friend class GIWrapperBase<InterfaceBase, InterfacePrototype,
InterfaceInstance>;
friend class InterfaceBase; // for has_instance_impl friend class InterfaceBase; // for has_instance_impl
// the GTypeInterface vtable wrapped by this JS object // the GTypeInterface vtable wrapped by this JS object
...@@ -108,8 +111,10 @@ class InterfacePrototype ...@@ -108,8 +111,10 @@ class InterfacePrototype
class InterfaceInstance class InterfaceInstance
: public GIWrapperInstance<InterfaceBase, InterfacePrototype, : public GIWrapperInstance<InterfaceBase, InterfacePrototype,
InterfaceInstance> { InterfaceInstance> {
friend class GIWrapperInstance; friend class GIWrapperInstance<InterfaceBase, InterfacePrototype,
friend class GIWrapperBase; InterfaceInstance>;
friend class GIWrapperBase<InterfaceBase, InterfacePrototype,
InterfaceInstance>;
G_GNUC_NORETURN InterfaceInstance(JSContext* cx, JS::HandleObject obj) G_GNUC_NORETURN InterfaceInstance(JSContext* cx, JS::HandleObject obj)
: GIWrapperInstance(cx, obj) { : GIWrapperInstance(cx, obj) {
......
...@@ -658,7 +658,7 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj, ...@@ -658,7 +658,7 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj,
GjsAutoFunctionInfo method_info = GjsAutoFunctionInfo method_info =
g_interface_info_find_method(iface_info, name); g_interface_info_find_method(iface_info, name);
if (method_info != NULL) { if (method_info) {
if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) { if (g_function_info_get_flags (method_info) & GI_FUNCTION_IS_METHOD) {
if (!gjs_define_function(cx, obj, m_gtype, method_info)) { if (!gjs_define_function(cx, obj, m_gtype, method_info)) {
g_free(interfaces); g_free(interfaces);
...@@ -760,8 +760,7 @@ bool ObjectPrototype::resolve_impl(JSContext* context, JS::HandleObject obj, ...@@ -760,8 +760,7 @@ bool ObjectPrototype::resolve_impl(JSContext* context, JS::HandleObject obj,
bool defined_by_parent; bool defined_by_parent;
GjsAutoVFuncInfo vfunc = find_vfunc_on_parents( GjsAutoVFuncInfo vfunc = find_vfunc_on_parents(
m_info, name_without_vfunc_, &defined_by_parent); m_info, name_without_vfunc_, &defined_by_parent);
if (vfunc != NULL) { if (vfunc) {
/* In the event that the vfunc is unchanged, let regular /* In the event that the vfunc is unchanged, let regular
* prototypal inheritance take over. */ * prototypal inheritance take over. */
if (defined_by_parent && is_vfunc_unchanged(vfunc)) { if (defined_by_parent && is_vfunc_unchanged(vfunc)) {
...@@ -2195,7 +2194,7 @@ bool ObjectPrototype::hook_up_vfunc_impl(JSContext* cx, ...@@ -2195,7 +2194,7 @@ bool ObjectPrototype::hook_up_vfunc_impl(JSContext* cx,
&field_info)) &field_info))
return false; return false;
if (field_info != NULL) { if (field_info) {
gint offset; gint offset;
gpointer method_ptr; gpointer method_ptr;
GjsCallbackTrampoline *trampoline; GjsCallbackTrampoline *trampoline;
......
...@@ -79,7 +79,7 @@ class ObjectPrototype; ...@@ -79,7 +79,7 @@ class ObjectPrototype;
*/ */
class ObjectBase class ObjectBase
: public GIWrapperBase<ObjectBase, ObjectPrototype, ObjectInstance> { : public GIWrapperBase<ObjectBase, ObjectPrototype, ObjectInstance> {
friend class GIWrapperBase; friend class GIWrapperBase<ObjectBase, ObjectPrototype, ObjectInstance>;
protected: protected:
/* a list of all GClosures installed on this object (from /* a list of all GClosures installed on this object (from
...@@ -167,8 +167,9 @@ class ObjectBase ...@@ -167,8 +167,9 @@ class ObjectBase
class ObjectPrototype class ObjectPrototype
: public GIWrapperPrototype<ObjectBase, ObjectPrototype, ObjectInstance> { : public GIWrapperPrototype<ObjectBase, ObjectPrototype, ObjectInstance> {
friend class GIWrapperPrototype; friend class GIWrapperPrototype<ObjectBase, ObjectPrototype,
friend class GIWrapperBase; ObjectInstance>;
friend class GIWrapperBase<ObjectBase, ObjectPrototype, ObjectInstance>;
using PropertyCache = using PropertyCache =
JS::GCHashMap<JS::Heap<JSString*>, GjsAutoParam, JS::GCHashMap<JS::Heap<JSString*>, GjsAutoParam,
...@@ -250,8 +251,9 @@ class ObjectPrototype ...@@ -250,8 +251,9 @@ class ObjectPrototype
class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype, class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
ObjectInstance, GObject> { ObjectInstance, GObject> {
friend class GIWrapperInstance; friend class GIWrapperInstance<ObjectBase, ObjectPrototype, ObjectInstance,
friend class GIWrapperBase; GObject>;
friend class GIWrapperBase<ObjectBase, ObjectPrototype, ObjectInstance>;
friend class ObjectBase; // for add_property, prop_getter, etc. friend class ObjectBase; // for add_property, prop_getter, etc.
// GIWrapperInstance::m_ptr may be null in ObjectInstance. // GIWrapperInstance::m_ptr may be null in ObjectInstance.
......
...@@ -37,7 +37,7 @@ class UnionInstance; ...@@ -37,7 +37,7 @@ class UnionInstance;
class UnionBase class UnionBase
: public GIWrapperBase<UnionBase, UnionPrototype, UnionInstance> { : public GIWrapperBase<UnionBase, UnionPrototype, UnionInstance> {
friend class GIWrapperBase; friend class GIWrapperBase<UnionBase, UnionPrototype, UnionInstance>;
protected: protected:
explicit UnionBase(UnionPrototype* proto = nullptr) explicit UnionBase(UnionPrototype* proto = nullptr)
...@@ -55,8 +55,9 @@ class UnionBase ...@@ -55,8 +55,9 @@ class UnionBase
class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype, class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype,
UnionInstance, GIUnionInfo> { UnionInstance, GIUnionInfo> {
friend class GIWrapperPrototype; friend class GIWrapperPrototype<UnionBase, UnionPrototype, UnionInstance,
friend class GIWrapperBase; GIUnionInfo>;
friend class GIWrapperBase<UnionBase, UnionPrototype, UnionInstance>;
explicit UnionPrototype(GIUnionInfo* info, GType gtype); explicit UnionPrototype(GIUnionInfo* info, GType gtype);
~UnionPrototype(void); ~UnionPrototype(void);
...@@ -71,8 +72,8 @@ class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype, ...@@ -71,8 +72,8 @@ class UnionPrototype : public GIWrapperPrototype<UnionBase, UnionPrototype,
class UnionInstance class UnionInstance
: public GIWrapperInstance<UnionBase, UnionPrototype, UnionInstance> { : public GIWrapperInstance<UnionBase, UnionPrototype, UnionInstance> {
friend class GIWrapperInstance; friend class GIWrapperInstance<UnionBase, UnionPrototype, UnionInstance>;
friend class GIWrapperBase; friend class GIWrapperBase<UnionBase, UnionPrototype, UnionInstance>;
explicit UnionInstance(JSContext* cx, JS::HandleObject obj); explicit UnionInstance(JSContext* cx, JS::HandleObject obj);
~UnionInstance(void); ~UnionInstance(void);
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <array> #include <array>
#include <codecvt> #include <codecvt>
...@@ -59,6 +58,10 @@ ...@@ -59,6 +58,10 @@
#include <windows.h> #include <windows.h>
#endif #endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <string.h> #include <string.h>
static void gjs_context_dispose (GObject *object); static void gjs_context_dispose (GObject *object);
...@@ -126,6 +129,8 @@ static GList *all_contexts = NULL; ...@@ -126,6 +129,8 @@ static GList *all_contexts = NULL;
static GjsAutoChar dump_heap_output; static GjsAutoChar dump_heap_output;
static unsigned dump_heap_idle_id = 0; static unsigned dump_heap_idle_id = 0;
#ifdef G_OS_UNIX
/* Currently heap dumping is only supported on UNIX platforms! */
static void static void
gjs_context_dump_heaps(void) gjs_context_dump_heaps(void)
{ {
...@@ -167,6 +172,7 @@ dump_heap_signal_handler(int signum) ...@@ -167,6 +172,7 @@ dump_heap_signal_handler(int signum)
dump_heap_idle_id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, dump_heap_idle_id = g_idle_add_full(G_PRIORITY_HIGH_IDLE,
dump_heap_idle, nullptr, nullptr); dump_heap_idle, nullptr, nullptr);
} }
#endif
static void static void
setup_dump_heap(void) setup_dump_heap(void)
...@@ -178,6 +184,7 @@ setup_dump_heap(void) ...@@ -178,6 +184,7 @@ setup_dump_heap(void)
/* install signal handler only if environment variable is set */ /* install signal handler only if environment variable is set */
const char *heap_output = g_getenv("GJS_DEBUG_HEAP_OUTPUT"); const char *heap_output = g_getenv("GJS_DEBUG_HEAP_OUTPUT");
if (heap_output) { if (heap_output) {
#ifdef G_OS_UNIX
struct sigaction sa; struct sigaction sa;
dump_heap_output = g_strdup(heap_output); dump_heap_output = g_strdup(heap_output);
...@@ -185,6 +192,10 @@ setup_dump_heap(void) ...@@ -185,6 +192,10 @@ setup_dump_heap(void)
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler = dump_heap_signal_handler; sa.sa_handler = dump_heap_signal_handler;
sigaction(SIGUSR1, &sa, nullptr); sigaction(SIGUSR1, &sa, nullptr);
#else
g_message(
"heap dump is currently only supported on UNIX platforms");
#endif
} }
} }
} }
...@@ -956,8 +967,14 @@ bool GjsContextPrivate::eval_with_scope(JS::HandleObject scope_object, ...@@ -956,8 +967,14 @@ bool GjsContextPrivate::eval_with_scope(JS::HandleObject scope_object,
JS::CompileOptions options(m_cx); JS::CompileOptions options(m_cx);
options.setFileAndLine(filename, start_line_number).setSourceIsLazy(true); options.setFileAndLine(filename, start_line_number).setSourceIsLazy(true);
#if defined(G_OS_WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1900))
std::wstring wscript = gjs_win32_vc140_utf8_to_utf16(script);
std::u16string utf16_string(reinterpret_cast<const char16_t*>(wscript.c_str()));
#else
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
std::u16string utf16_string = convert.from_bytes(script); std::u16string utf16_string = convert.from_bytes(script);
#endif
JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(), JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(),
JS::SourceBufferHolder::NoOwnership); JS::SourceBufferHolder::NoOwnership);
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
* Authored By: Philip Chimento <philip.chimento@gmail.com> * Authored By: Philip Chimento <philip.chimento@gmail.com>
*/ */
#include <unistd.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "gjs/context-private.h" #include "gjs/context-private.h"
...@@ -36,6 +34,15 @@ ...@@ -36,6 +34,15 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#elif defined(XP_WIN)
# include <io.h>
# ifndef STDIN_FILENO
# define STDIN_FILENO 0
# endif
#endif
GJS_JSAPI_RETURN_CONVENTION GJS_JSAPI_RETURN_CONVENTION
static bool quit(JSContext* cx, unsigned argc, JS::Value* vp) { static bool quit(JSContext* cx, unsigned argc, JS::Value* vp) {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
...@@ -90,7 +97,7 @@ static bool do_readline(JSContext* cx, unsigned argc, JS::Value* vp) { ...@@ -90,7 +97,7 @@ static bool do_readline(JSContext* cx, unsigned argc, JS::Value* vp) {
args.rval().setUndefined(); args.rval().setUndefined();
return true; return true;
} }
} while (line && line[0] == '\0'); } while (line && line.get()[0] == '\0');
/* Add line to history and convert it to a JSString so that we can pass it /* Add line to history and convert it to a JSString so that we can pass it
* back as the return value */ * back as the return value */
......
...@@ -707,7 +707,7 @@ static bool importer_new_enumerate(JSContext* context, JS::HandleObject object, ...@@ -707,7 +707,7 @@ static bool importer_new_enumerate(JSContext* context, JS::HandleObject object,
GjsAutoChar filename = g_file_get_basename(file); GjsAutoChar filename = g_file_get_basename(file);
/* skip hidden files and directories (.svn, .git, ...) */ /* skip hidden files and directories (.svn, .git, ...) */
if (filename[0] == '.') if (filename.get()[0] == '.')
continue; continue;
/* skip module init file */ /* skip module init file */
......
...@@ -399,8 +399,8 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_parse_call_args( ...@@ -399,8 +399,8 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_parse_call_args(
} }
GjsAutoStrv parts = g_strsplit(format, "|", 2); GjsAutoStrv parts = g_strsplit(format, "|", 2);
fmt_required = parts[0]; fmt_required = parts.get()[0];
fmt_optional = parts[1]; /* may be NULL */ fmt_optional = parts.get()[1]; // may be NULL
retval = parse_call_args_helper(cx, function_name, args, retval = parse_call_args_helper(cx, function_name, args,
ignore_trailing_args, fmt_required, ignore_trailing_args, fmt_required,
......
...@@ -34,6 +34,11 @@ ...@@ -34,6 +34,11 @@
#include <js/GCAPI.h> #include <js/GCAPI.h>
#include <js/Printf.h> #include <js/Printf.h>
#ifdef XP_WIN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#include "gjs/context-private.h" #include "gjs/context-private.h"
#include "gjs/jsapi-class.h" #include "gjs/jsapi-class.h"
#include "gjs/jsapi-util.h" #include "gjs/jsapi-util.h"
...@@ -660,3 +665,26 @@ gjs_strip_unix_shebang(const char *script, ...@@ -660,3 +665,26 @@ gjs_strip_unix_shebang(const char *script,
return script; return script;
} }
#if defined(G_OS_WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1900))
/* Unfortunately Visual Studio's C++ .lib somehow did not contain the right
* codecvt stuff that we need to convert from utf8 to utf16 (char16_t), so we
* need to work around this Visual Studio bug. Use Windows API
* MultiByteToWideChar() and obtain the std::u16string on the std::wstring we
* obtain from MultiByteToWideChar(). See:
* https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error?forum=vcgeneral
*/
std::wstring gjs_win32_vc140_utf8_to_utf16(const char* str) {
int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0);
if (len == 0)
return nullptr;
std::wstring wstr(len, 0);
int result = MultiByteToWideChar(CP_UTF8, 0, str, -1, &wstr[0], len);
if (result == 0)
return nullptr;
wstr.resize(strlen(str));
return wstr;
}
#endif
...@@ -363,4 +363,8 @@ GJS_USE std::string gjs_debug_id(jsid id); ...@@ -363,4 +363,8 @@ GJS_USE std::string gjs_debug_id(jsid id);
GJS_USE GJS_USE
char* gjs_hyphen_to_underscore(const char* str); char* gjs_hyphen_to_underscore(const char* str);
#if defined(G_OS_WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1900))
GJS_USE std::wstring gjs_win32_vc140_utf8_to_utf16(const char* str);
#endif
#endif /* __GJS_JSAPI_UTIL_H__ */ #endif /* __GJS_JSAPI_UTIL_H__ */
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
# else # else
# define GJS_EXPORT __declspec(dllimport) # define GJS_EXPORT __declspec(dllimport)
# endif # endif
# define siginfo_t void
#else #else
# define GJS_EXPORT # define GJS_EXPORT
#endif #endif
......
...@@ -99,8 +99,15 @@ class GjsModule { ...@@ -99,8 +99,15 @@ class GjsModule {
JS::CompileOptions options(cx); JS::CompileOptions options(cx);
options.setFileAndLine(filename, line_number); options.setFileAndLine(filename, line_number);
#if defined(G_OS_WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1900))
std::wstring wscript = gjs_win32_vc140_utf8_to_utf16(script);
std::u16string utf16_string(
reinterpret_cast<const char16_t*>(wscript.c_str()));
#else
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
std::u16string utf16_string = convert.from_bytes(script); std::u16string utf16_string = convert.from_bytes(script);
#endif
JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(), JS::SourceBufferHolder buf(utf16_string.c_str(), utf16_string.size(),
JS::SourceBufferHolder::NoOwnership); JS::SourceBufferHolder::NoOwnership);
......
...@@ -27,11 +27,7 @@ ...@@ -27,11 +27,7 @@
#include <errno.h> #include <errno.h>
#include <memory> #include <memory>
#include <signal.h> #include <signal.h>
#include <sys/syscall.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <glib-unix.h>
#include "jsapi-wrapper.h" #include "jsapi-wrapper.h"
#include <js/ProfilingStack.h> #include <js/ProfilingStack.h>
...@@ -39,9 +35,19 @@ ...@@ -39,9 +35,19 @@
#include "context.h" #include "context.h"
#include "jsapi-util.h" #include "jsapi-util.h"
#include "profiler-private.h" #include "profiler-private.h"
#ifdef ENABLE_PROFILER #ifdef ENABLE_PROFILER
# include <alloca.h> # include <alloca.h>
# include "util/sp-capture-writer.h" # ifdef HAVE_SYS_SYSCALL_H
# include <sys/syscall.h>
# endif
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
# ifdef G_OS_UNIX
# include <glib-unix.h>
# endif
# include "util/sp-capture-writer.h"
#endif #endif
/* /*
......
...@@ -27,12 +27,15 @@ ...@@ -27,12 +27,15 @@
#include <string.h> #include <string.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <glib-unix.h>
#include <glib.h> #include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include "gjs-util.h" #include "gjs-util.h"
#ifdef G_OS_UNIX
# include <glib-unix.h>
#endif
char * char *
gjs_format_int_alternative_output(int n) gjs_format_int_alternative_output(int n)
{ {
...@@ -164,6 +167,7 @@ int gjs_open_bytes(GBytes* bytes, GError** error) { ...@@ -164,6 +167,7 @@ int gjs_open_bytes(GBytes* bytes, GError** error) {
g_return_val_if_fail(bytes, -1); g_return_val_if_fail(bytes, -1);
g_return_val_if_fail(error == NULL || *error == NULL, -1); g_return_val_if_fail(error == NULL || *error == NULL, -1);
#ifdef G_OS_UNIX
if (!g_unix_open_pipe(pipefd, FD_CLOEXEC, error)) if (!g_unix_open_pipe(pipefd, FD_CLOEXEC, error))
return -1; return -1;
...@@ -186,4 +190,7 @@ int gjs_open_bytes(GBytes* bytes, GError** error) { ...@@ -186,4 +190,7 @@ int gjs_open_bytes(GBytes* bytes, GError** error) {
} }
return pipefd[0]; return pipefd[0];
#else