Commit 7c07aa33 authored by Philip Chimento's avatar Philip Chimento 🚮

Merge branch 'mozjs78prep' into 'master'

Preparation for SpiderMonkey 78

See merge request !462
parents f1dc698f 644f1177
Pipeline #199503 passed with stages
in 6 minutes and 34 seconds
......@@ -46,12 +46,12 @@ portable C++ code as the implementation language of choice.
### C++ Standard Versions ###
GJS is currently written using C++14 conforming code, although we
GJS is currently written using C++17 conforming code, although we
restrict ourselves to features which are available in the major
toolchains.
Regardless of the supported features, code is expected to (when
reasonable) be standard, portable, and modern C++14 code.
reasonable) be standard, portable, and modern C++17 code.
We avoid unnecessary vendor-specific extensions, etc., including
`g_autoptr()` and friends.
......@@ -65,9 +65,9 @@ and friends, for their type safety and memory management.
There are some exceptions such as the standard I/O streams library which
is avoided, and use in space-constrained situations.
### Supported C++14 Language and Library Features ###
### Supported C++17 Language and Library Features ###
While GJS and SpiderMonkey use C++14, not all features are available in
While GJS and SpiderMonkey use C++17, not all features are available in
all of the toolchains which we support.
A good rule of thumb is to check whether SpiderMonkey uses the feature.
If so, it's okay to use in GJS.
......
......@@ -1596,8 +1596,8 @@ struct JSClass gjs_function_class = {
static JSPropertySpec gjs_function_proto_props[] = {
JS_PSG("length", get_num_arguments, JSPROP_PERMANENT),
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "GIRepositoryFunction", JSPROP_READONLY),
JS_PS_END};
/* The original Function.prototype.toString complains when
given a GIRepository function as an argument */
......
......@@ -106,6 +106,7 @@ get_name_func (JSContext *context,
/* Properties */
JSPropertySpec gjs_gtype_proto_props[] = {
JS_PSG("name", get_name_func, JSPROP_PERMANENT),
JS_STRING_SYM_PS(toStringTag, "GIRepositoryGType", JSPROP_READONLY),
JS_PS_END,
};
......
......@@ -200,6 +200,7 @@ struct JSClass gjs_ns_class = {
};
static JSPropertySpec gjs_ns_proto_props[] = {
JS_STRING_SYM_PS(toStringTag, "GIRepositoryNamespace", JSPROP_READONLY),
JS_PSG("__name__", get_name, GJS_MODULE_PROP_FLAGS),
JS_PS_END
};
......
......@@ -2242,6 +2242,10 @@ JSFunctionSpec ObjectBase::proto_methods[] = {
JS_FN("emit", &ObjectBase::emit, 0, 0),
JS_FS_END
};
JSPropertySpec ObjectBase::proto_properties[] = {
JS_STRING_SYM_PS(toStringTag, "GObject_Object", JSPROP_READONLY),
JS_PS_END};
// clang-format on
// Override of GIWrapperPrototype::get_parent_proto()
......
......@@ -111,6 +111,7 @@ class ObjectBase
static const struct JSClassOps class_ops;
static const struct JSClass klass;
static JSFunctionSpec proto_methods[];
static JSPropertySpec proto_properties[];
static GObject* to_c_ptr(JSContext* cx, JS::HandleObject obj) = delete;
GJS_JSAPI_RETURN_CONVENTION
......@@ -224,7 +225,7 @@ class ObjectPrototype
JS::GCHashMap<JS::Heap<JSString*>, GjsAutoInfo<GI_INFO_TYPE_FIELD>,
js::DefaultHasher<JSString*>, js::SystemAllocPolicy>;
using NegativeLookupCache =
JS::GCHashSet<jsid, IdHasher, js::SystemAllocPolicy>;
JS::GCHashSet<JS::Heap<jsid>, IdHasher, js::SystemAllocPolicy>;
PropertyCache m_property_cache;
FieldCache m_field_cache;
......
......@@ -33,6 +33,7 @@
#include <js/Class.h>
#include <js/Id.h> // for JSID_IS_STRING, JSID_VOID
#include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT, JSPROP_RESOLVING
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <js/Utility.h> // for UniqueChars
......@@ -60,9 +61,6 @@
#include "gjs/mem-private.h"
#include "util/log.h"
struct JSFunctionSpec;
struct JSPropertySpec;
typedef struct {
void *dummy;
......@@ -250,7 +248,12 @@ struct JSClass gjs_repo_class = {
&gjs_repo_class_ops,
};
static JSPropertySpec *gjs_repo_proto_props = nullptr;
// clang-format off
static const JSPropertySpec gjs_repo_proto_props[] = {
JS_STRING_SYM_PS(toStringTag, "GIRepository", JSPROP_READONLY),
JS_PS_END};
// clang-format on
static JSFunctionSpec *gjs_repo_proto_funcs = nullptr;
static JSFunctionSpec *gjs_repo_static_funcs = nullptr;
......
......@@ -160,6 +160,7 @@ class GIWrapperBase {
// These three can be overridden in subclasses. See define_jsclass().
static constexpr JSPropertySpec* proto_properties = nullptr;
static constexpr JSPropertySpec* static_properties = nullptr;
static constexpr JSFunctionSpec* proto_methods = nullptr;
static constexpr JSFunctionSpec* static_methods = nullptr;
......@@ -868,8 +869,8 @@ class GIWrapperPrototype : public Base {
cx, in_object, parent_proto, gi_namespace, Base::name(),
&Base::klass, &Base::constructor, nargs, Base::proto_properties,
parent_proto ? nullptr : Base::proto_methods,
nullptr, // static properties, MyClass.myprop; not yet needed
Base::static_methods, prototype, constructor))
Base::static_properties, Base::static_methods, prototype,
constructor))
return false;
gjs_debug(Base::debug_topic,
......
......@@ -245,10 +245,10 @@ JSContext* gjs_create_js_context(GjsContextPrivate* uninitialized_gjs) {
auto hook = mozilla::MakeUnique<GjsSourceHook>();
js::SetSourceHook(cx, std::move(hook));
/* setExtraWarnings: Be extra strict about code that might hide a bug */
if (!g_getenv("GJS_DISABLE_EXTRA_WARNINGS")) {
gjs_debug(GJS_DEBUG_CONTEXT, "Enabling extra warnings");
JS::ContextOptionsRef(cx).setExtraWarnings(true);
if (g_getenv("GJS_DISABLE_EXTRA_WARNINGS")) {
g_warning(
"GJS_DISABLE_EXTRA_WARNINGS has been removed, GJS no longer logs "
"extra warnings.");
}
bool enable_jit = !(g_getenv("GJS_DISABLE_JIT"));
......@@ -256,9 +256,14 @@ JSContext* gjs_create_js_context(GjsContextPrivate* uninitialized_gjs) {
gjs_debug(GJS_DEBUG_CONTEXT, "Enabling JIT");
}
JS::ContextOptionsRef(cx)
.setIon(enable_jit)
.setBaseline(enable_jit)
.setAsmJS(enable_jit);
uint32_t value = enable_jit ? 1 : 0;
JS_SetGlobalJitCompilerOption(
cx, JSJitCompilerOption::JSJITCOMPILER_ION_ENABLE, value);
JS_SetGlobalJitCompilerOption(
cx, JSJitCompilerOption::JSJITCOMPILER_BASELINE_ENABLE, value);
return cx;
}
......@@ -170,6 +170,12 @@ class GjsGlobal : GjsBaseGlobal {
&defaultclassops,
};
// clang-format off
static constexpr JSPropertySpec static_props[] = {
JS_STRING_SYM_PS(toStringTag, "GjsGlobal", JSPROP_READONLY),
JS_PS_END};
// clang-format on
static constexpr JSFunctionSpec static_funcs[] = {
JS_FS_END};
......@@ -192,7 +198,8 @@ class GjsGlobal : GjsBaseGlobal {
const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
if (!JS_DefinePropertyById(cx, global, atoms.window(), global,
JSPROP_READONLY | JSPROP_PERMANENT) ||
!JS_DefineFunctions(cx, global, GjsGlobal::static_funcs))
!JS_DefineFunctions(cx, global, GjsGlobal::static_funcs) ||
!JS_DefineProperties(cx, global, GjsGlobal::static_props))
return false;
JS::Realm* realm = JS::GetObjectRealmOrNull(global);
......@@ -379,6 +386,7 @@ JS::Value detail::get_global_slot(JSObject* global, uint32_t slot) {
decltype(GjsGlobal::klass) constexpr GjsGlobal::klass;
decltype(GjsGlobal::static_funcs) constexpr GjsGlobal::static_funcs;
decltype(GjsGlobal::static_props) constexpr GjsGlobal::static_props;
decltype(GjsDebuggerGlobal::klass) constexpr GjsDebuggerGlobal::klass;
decltype(
......
......@@ -810,7 +810,10 @@ const JSClass gjs_importer_class = {
&gjs_importer_class_ops,
};
static JSPropertySpec *gjs_importer_proto_props = nullptr;
static const JSPropertySpec gjs_importer_proto_props[] = {
JS_STRING_SYM_PS(toStringTag, "GjsFileImporter", JSPROP_READONLY),
JS_PS_END};
static JSFunctionSpec *gjs_importer_static_funcs = nullptr;
JSFunctionSpec gjs_importer_proto_funcs[] = {
......
......@@ -30,8 +30,7 @@
#include <js/CallArgs.h> // for JSNative
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_RESOLVING, JSPROP_GETTER
#include <js/PropertySpec.h>
#include <js/PropertyDescriptor.h> // for JSPROP_GETTER
#include <js/Realm.h> // for GetRealmObjectPrototype
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -45,6 +44,9 @@
#include "gjs/jsapi-util.h"
#include "gjs/macros.h"
struct JSFunctionSpec;
struct JSPropertySpec;
/* Reserved slots of JSNative accessor wrappers */
enum {
DYNAMIC_PROPERTY_PRIVATE_SLOT,
......@@ -86,16 +88,6 @@ bool gjs_init_class_dynamic(JSContext* context, JS::HandleObject in_object,
if (!prototype)
return false;
/* Bypass resolve hooks when defining the initial properties */
if (clasp->cOps->resolve) {
JSPropertySpec *ps_iter;
JSFunctionSpec *fs_iter;
for (ps_iter = proto_ps; ps_iter && ps_iter->name; ps_iter++)
ps_iter->flags |= JSPROP_RESOLVING;
for (fs_iter = proto_fs; fs_iter && fs_iter->name; fs_iter++)
fs_iter->flags |= JSPROP_RESOLVING;
}
if (proto_ps && !JS_DefineProperties(context, prototype, proto_ps))
return false;
if (proto_fs && !JS_DefineFunctions(context, prototype, proto_fs))
......@@ -116,21 +108,8 @@ bool gjs_init_class_dynamic(JSContext* context, JS::HandleObject in_object,
if (static_fs && !JS_DefineFunctions(context, constructor, static_fs))
return false;
if (!clasp->cOps->resolve) {
if (!JS_LinkConstructorAndPrototype(context, constructor, prototype))
return false;
} else {
/* Have to fake it with JSPROP_RESOLVING, otherwise it will trigger
* the resolve hook */
const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
if (!JS_DefinePropertyById(
context, constructor, atoms.prototype(), prototype,
JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_RESOLVING))
return false;
if (!JS_DefinePropertyById(context, prototype, atoms.constructor(),
constructor, JSPROP_RESOLVING))
return false;
}
if (!JS_LinkConstructorAndPrototype(context, constructor, prototype))
return false;
/* The constructor defined by JS_InitClass has no property attributes, but this
is a more useful default for gjs */
......
......@@ -45,8 +45,6 @@ main(int argc, char **argv)
/* The fact that this isn't the default is kind of lame... */
g_setenv("GJS_DEBUG_OUTPUT", "stderr", false);
/* Jasmine library has some code style nits that trip this */
g_setenv("GJS_DISABLE_EXTRA_WARNINGS", "1", false);
setlocale(LC_ALL, "");
......
project('gjs', 'cpp', 'c', version: '1.65.90', license: ['MIT', 'LGPL2+'],
meson_version: '>= 0.52.0',
default_options: ['cpp_std=c++14', 'c_std=c99', 'warning_level=2'])
default_options: ['cpp_std=c++17', 'c_std=c99', 'warning_level=2'])
api_version = '1.0'
api_name = '@0@-@1@'.format(meson.project_name(), api_version)
......
......@@ -32,6 +32,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/Conversions.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -294,9 +295,11 @@ static void gjs_cairo_context_finalize(JSFreeOp*, JSObject* obj) {
}
/* Properties */
// clang-format off
JSPropertySpec gjs_cairo_context_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "Context", JSPROP_READONLY),
JS_PS_END};
// clang-format on
/* Methods */
......
......@@ -26,6 +26,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -48,9 +49,11 @@ gjs_cairo_gradient_finalize(JSFreeOp *fop,
}
/* Properties */
// clang-format off
JSPropertySpec gjs_cairo_gradient_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "Gradient", JSPROP_READONLY),
JS_PS_END};
// clang-format on
/* Methods */
......
......@@ -27,6 +27,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -79,9 +80,11 @@ gjs_cairo_image_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
// clang-format off
JSPropertySpec gjs_cairo_image_surface_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "ImageSurface", JSPROP_READONLY),
JS_PS_END};
// clang-format on
GJS_JSAPI_RETURN_CONVENTION
static bool
......
......@@ -26,6 +26,7 @@
#include <glib.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -79,8 +80,8 @@ gjs_cairo_linear_gradient_finalize(JSFreeOp *fop,
}
JSPropertySpec gjs_cairo_linear_gradient_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "LinearGradient", JSPROP_READONLY),
JS_PS_END};
JSFunctionSpec gjs_cairo_linear_gradient_proto_funcs[] = {
// getLinearPoints
......
......@@ -26,6 +26,7 @@
#include <glib.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -48,9 +49,11 @@ static void gjs_cairo_path_finalize(JSFreeOp*, JSObject* obj) {
}
/* Properties */
// clang-format off
JSPropertySpec gjs_cairo_path_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "Path", JSPROP_READONLY),
JS_PS_END};
// clang-format on
JSFunctionSpec gjs_cairo_path_proto_funcs[] = {
JS_FS_END
......
......@@ -28,6 +28,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -51,8 +52,7 @@ static void gjs_cairo_pattern_finalize(JSFreeOp*, JSObject* obj) {
/* Properties */
JSPropertySpec gjs_cairo_pattern_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "Pattern", JSPROP_READONLY), JS_PS_END};
/* Methods */
......
......@@ -34,6 +34,7 @@
# include <glib.h>
# include <js/Class.h>
# include <js/PropertyDescriptor.h> // for JSPROP_READONLY
# include <js/PropertySpec.h>
# include <js/RootingAPI.h>
# include <jsapi.h> // for JS_NewObjectWithGivenProto
......@@ -85,9 +86,11 @@ gjs_cairo_pdf_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
// clang-format off
JSPropertySpec gjs_cairo_pdf_surface_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "PDFSurface", JSPROP_READONLY),
JS_PS_END};
// clang-format on
JSFunctionSpec gjs_cairo_pdf_surface_proto_funcs[] = {
JS_FS_END
......
......@@ -34,6 +34,7 @@
# include <glib.h>
# include <js/Class.h>
# include <js/PropertyDescriptor.h> // for JSPROP_READONLY
# include <js/PropertySpec.h>
# include <js/RootingAPI.h>
# include <jsapi.h> // for JS_NewObjectWithGivenProto
......@@ -85,9 +86,11 @@ gjs_cairo_ps_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
// clang-format off
JSPropertySpec gjs_cairo_ps_surface_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "PSSurface", JSPROP_READONLY),
JS_PS_END};
// clang-format on
JSFunctionSpec gjs_cairo_ps_surface_proto_funcs[] = {
// restrictToLevel
......
......@@ -26,6 +26,7 @@
#include <glib.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -81,8 +82,8 @@ gjs_cairo_radial_gradient_finalize(JSFreeOp *fop,
}
JSPropertySpec gjs_cairo_radial_gradient_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "RadialGradient", JSPROP_READONLY),
JS_PS_END};
JSFunctionSpec gjs_cairo_radial_gradient_proto_funcs[] = {
// getRadialCircles
......
......@@ -30,6 +30,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/Conversions.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -222,9 +223,11 @@ get_rectangle_func(JSContext *context,
RETURN_STATUS;
}
// clang-format off
JSPropertySpec gjs_cairo_region_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "Region", JSPROP_READONLY),
JS_PS_END};
// clang-format on
JSFunctionSpec gjs_cairo_region_proto_funcs[] = {
JS_FN("union", union_func, 0, 0),
......
......@@ -27,6 +27,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -52,9 +53,11 @@ gjs_cairo_solid_pattern_finalize(JSFreeOp *fop,
gjs_cairo_pattern_finalize_pattern(fop, obj);
}
// clang-format off
JSPropertySpec gjs_cairo_solid_pattern_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "SolidPattern", JSPROP_READONLY),
JS_PS_END};
// clang-format on
GJS_JSAPI_RETURN_CONVENTION
static bool
......
......@@ -27,6 +27,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -83,8 +84,8 @@ gjs_cairo_surface_pattern_finalize(JSFreeOp *fop,
}
JSPropertySpec gjs_cairo_surface_pattern_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "SurfacePattern", JSPROP_READONLY),
JS_PS_END};
GJS_JSAPI_RETURN_CONVENTION
static bool
......
......@@ -29,6 +29,7 @@
#include <js/CallArgs.h>
#include <js/Class.h>
#include <js/PropertyDescriptor.h> // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
......@@ -55,9 +56,11 @@ static void gjs_cairo_surface_finalize(JSFreeOp*, JSObject* obj) {
}
/* Properties */
// clang-format off
JSPropertySpec gjs_cairo_surface_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "Surface", JSPROP_READONLY),
JS_PS_END};
// clang-format on
/* Methods */
GJS_JSAPI_RETURN_CONVENTION
......
......@@ -34,6 +34,7 @@
# include <glib.h>
# include <js/Class.h>
# include <js/PropertyDescriptor.h> // for JSPROP_READONLY
# include <js/PropertySpec.h>
# include <js/RootingAPI.h>
# include <jsapi.h> // for JS_NewObjectWithGivenProto
......@@ -85,9 +86,11 @@ gjs_cairo_svg_surface_finalize(JSFreeOp *fop,
gjs_cairo_surface_finalize_surface(fop, obj);
}
// clang-format off
JSPropertySpec gjs_cairo_svg_surface_proto_props[] = {
JS_PS_END
};
JS_STRING_SYM_PS(toStringTag, "SVGSurface", JSPROP_READONLY),
JS_PS_END};
// clang-format on
JSFunctionSpec gjs_cairo_svg_surface_proto_funcs[] = {
JS_FS_END
......
......@@ -716,9 +716,9 @@ static void test_function_names_written_to_coverage_data(void* fixture_data,
fixture->lcov_output);
const char* expected_function_names[] = {
"b",
"f",
"top-level",
"f",
"b",
};
const gsize expected_function_names_len = G_N_ELEMENTS(expected_function_names);
......@@ -764,9 +764,9 @@ static void test_function_lines_written_to_coverage_data(void* fixture_data,
fixture->tmp_js_script,
fixture->lcov_output);
const char* const expected_function_lines[] = {
"3",
"1",
"1",
"3",
};
const gsize expected_function_lines_len = G_N_ELEMENTS(expected_function_lines);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment