| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
| |
This is split out into a separate commit so that it's easier to see what
changed in "gtype: Remove JSClass macros".
|
|
|
|
|
|
|
|
|
|
| |
Port gtype.cpp to use the CWrapper template, instead of the
GJS_DEFINE_PRIV_FROM_JS family of macros. This is slightly different than
Ns because GTypeObj is a class with only static methods, whereas the
actual data stored in the object's private pointer slot is the GType,
stuffed into a void*.
Also requires adding a debug topic for GTypes.
|
|
|
|
|
|
| |
This function was only used in one place, and it was unnecessary because
gjs_gtype_get_actual_gtype() is used on the same object later, which also
checks the type. So, we can remove the function altogether.
|
|
|
|
|
|
|
|
| |
The SPDX format is machine-readable, which should make it much easier to
avoid mistakes with licensing and copyright using automated tools.
This commit does not add any implicit information. It converts exactly
what was already specified into SPDX format comments.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Now that we depend on C++17, we can use these attributes that are part
of the language, instead of relying on macros to make them portable.
(GJS_USE still needs to be defined for public header files, which may be
compiled in C.)
Attributes which are new in C++17 are [[maybe_unused]], [[nodiscard]],
and [[fallthrough]].
[skip cpplint] because cpplint doesn't deal with C++ attributes:
https://github.com/google/styleguide/issues/165
|
|
|
|
|
|
|
|
| |
SpiderMonkey 78 will stop using the JSClass.name string as the string
tag. For backwards compatibility, we should make sure the string tag
doesn't change.
See: GNOME/gjs#329
|
|
|
|
|
|
|
| |
This updates all the includes according to what IWYU suggests. In a few
cases we move a typedef down in order to avoid IWYU wanting a forward
declaration, or use a JS::Heap<T>{braced initializer} in order to avoid
an implicit std::move.
|
|
|
|
|
|
|
|
|
|
|
| |
This was a bug exposed by more efficient garbage collection and better
debug assertions in SpiderMonkey 68. We cannot use lookupForAdd() when
checking if a GType is already present in the GType table (which we did
to anticipate adding it if it wasn't present) because creating the GType
wrapper object might trigger a GC, which could cause another GType to be
garbage collected, which would remove it from the GType table. Mutating
the table invalidates the AddPtr returned by lookupForAdd(), which is a
bug.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
With SpiderMonkey 68, it's no longer necessary to mark SpiderMonkey
header files as system headers, and it's also no longer necessary to
include <js-config.h> before any other header files, as SpiderMonkey
has sorted that out internally.
We remove jsapi-wrapper.h and define DEBUG directly in config.h instead
of indirectly in jsapi-wrapper.h via HAVE_SPIDERMONKEY_DEBUG.
This should reduce compile time, on average, because in most .h files
we now only need to include <js/TypeDecls.h>.
|
|
|
|
|
|
| |
JSAutoRequest, JS_BeginRequest(), and JS_EndRequest() are no longer
necessary in SpiderMonkey 68. We can just remove them wherever they
appear.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously #include statements were a bit of a mess across the codebase.
This commit is the result of a pass by the IWYU (Include What You Use)
tool, which suggests headers to add or remove based on what is in the
file, and can also suggest forward-declaring classes instead of
including their headers, if they are only used as a pointer in a
particular file. Cleaning this up should in general speed up compile
times.
IWYU isn't perfect, it produces a number of false positives, so we don't
try to automate this process and we don't accept all of its
recommendations. We do add a script and configuration file to the tools/
directory so that IWYU can be every so often in the future.
We also clean up all the includes according to a consistent style, which
is now described clearly in the C++ style guide.
|
|
|
|
|
|
|
|
|
|
|
| |
GType objects don't allocate any memory for their private data. Instead,
they just store their GType value in the JSObject's private data pointer
slot. Since nothing is allocated, nothing needs to be freed in the
finalize function.
We are required to have a finalize function because of the
GJS_DEFINE_PROTO_ABSTRACT macro used to define this JSClass. However, we
can just make it empty. The statements currently in there seem useless.
|
|
|
|
|
|
|
|
|
|
|
|
| |
As in a previous change in fundamental.cpp, JS::WeakCache allows us to
get rid of the weak pointer callback, as that is all implemented
internally. The hash table is automatically swept when the GType wrapper
objects are garbage collected.
We move the table to GjsContextPrivate instead of using a static
variable. Although there is probably little difference in practice, that
is a more accurate place to store it, in case there is more than one
GjsContext in use.
|
|
|
|
| |
With the new GI wrapper framework, this function is now not used.
|
|
|
|
|
|
|
|
|
|
| |
There are a number of places where we used JS_{Get,Set,Define}Property()
or JS_DefineFunction() with a string literal. In these cases it would be
better to use an atom so that the string doesn't have to be converted from
UTF-8 internally each time.
In some cases there was already an atom defined, and in others we add a
new atom.
|
|
|
|
| |
We can avoid doing a copy of the string for a static one
|
| |
|
|
|
|
| |
So we don't have to manage the deletion manually.
|
| |
|
|
|
|
|
| |
This makes gjs_gtype_get_actual_gtype() conform to the JSAPI return
convention, so that it is clear when an exception is pending.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This introduces two annotations to functions. GJS_USE is a macro for GCC
and Clang's "warn_unused_result" annotation, meaning that the return
value of a function must not be ignored. This allows us to catch some
cases where we are neglecting to do error checking.
The second annotation is GJS_JSAPI_RETURN_CONVENTION which for now is
identical to GJS_USE, but could be made into a custom annotation in the
future which a static analyzer plugin could use to enforce further checks
at compile time. The "JSAPI return convention" is valid on functions that
return bool or a pointer type, and whose first parameter is JSContext*. If
false or nullptr is returned, then an exception must be pending at return
time on the passed-in JSContext. If true or a non-nullptr value is
returned, then no exception must be pending.
This commit only has the addition of the attributes, and a few fixes
mandated by the autoformatter, so it can be reviewed "lightly".
|
|
|
|
|
|
| |
The macro simply changed its name.
See: #161
|
|
|
|
|
|
|
|
| |
Zero is a valid return value from e.g. GObject.type_from_name() in case
the type in question is not registered. We marshal a value of 0
(G_TYPE_INVALID) into JS null.
Closes #11.
|
|
|
|
|
|
|
|
|
|
|
|
| |
There are two paths for decoding UTF8 strings directly to JSString:
JS_NewStringCopyUTF8N() and JS_NewStringCopyUTF8Z(). Mostly we have a
zero-terminated string in GJS, so we shorten gjs_string_from_utf8() to
remove its string length argument and use JS_NewStringCopyUTF8Z().
There are a few places where we have a non-zero-terminated string, so we
introduce gjs_string_from_utf8_n() to handle that path.
A few places we were doing a UTF8 conversion where it was not necessary.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Inside the weak pointer callback, we only need to compare the pointer to
nullptr. Since we don't actually use the pointer's location, no read
barrier is needed.
Previously this was not a problem, but SpiderMonkey 52 now asserts that
the heap is not active when exposing a pointer to active JS through a
read barrier, so the weak pointer callback will crash if we try to use a
read barrier.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
|
|
|
|
|
| |
Many APIs that adapted to the removal of JSRuntime can be trivially
replaced with JSContext without any other code changes.
JS_AbortIfWrongThread() also takes JSContext instead of JSRuntime, but
we only called it to check that we were creating a JSContext on the
correct thread. Before creating the JSContext, there is no point in
calling it, so remove it.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
|
| |
For all classes with a finalize hook, SpiderMonkey 52 requires that they
either have JSCLASS_FOREGROUND_FINALIZE or JSCLASS_BACKGROUND_FINALIZE set.
Previously, only the BACKGROUND flag existed and FOREGROUND was implicit.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
|
| |
Weak pointer callbacks now come in two flavours: per-zone and
per-compartment. We do everything in one compartment, and don't care
about zones, so we should use the per-compartment flavour.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
| |
JS::NullPtr() is gone, and instead now functions that took JS::NullPtr()
as a null handle value take nullptr_t, so we should use C++ nullptr.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
|
|
|
|
|
| |
This allows the GJS_DEFINE_PROTO_* family of macros to have a JSFunctionSpec
array for functions defined on the constructor, rather than on the
prototype: i.e. static functions.
We clean up an incongruity in cairo-image-surface.cpp where you had to pass
the constructor into gjs_cairo_image_surface_init() in order to get the
static functions defined.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This refactors the GJS_DEFINE_PROTO family of macros to store the created
prototype objects in slots on the global object. We split up the
gjs_WHATEVER_create_proto() function into two functions: one that must be
called at least once for each type to define the class, store the prototype
in a global slot, and define the constructor as a property on a passed-in
module or global object, gjs_WHATEVER_define_proto(); and one that
retrieves the prototype from its global slot, gjs_WHATEVER_get_proto().
We also add two macros, GJS_DEFINE_PROTO_WITH_PARENT and
GJS_DEFINE_PROTO_ABSTRACT_WITH_PARENT, which also move the definition of
the parent to compile time rather than runtime, and keep it in the same
place as the rest of each class's macro definition. Similarly, previously
we had to pass the parent prototype object to gjs_WHATEVER_create_proto().
This mostly affects the cairo module.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There's no need to have a "proto_name" that's different from the class's
name. Getting rid of this distinction will allow us to refactor things so
that JS_InitClass() defines the correct constructor directly on the global
object or the module object.
This is a small behavioural API break, since it changes the output of
toString() on the various Cairo objects, but I would say that people
should not be parsing the output of toString(). (I know we do in our tests,
but that's terrible.)
https://bugzilla.gnome.org/show_bug.cgi?id=614413
|
|
|
|
|
|
|
|
|
| |
I finally figured out why my highlighting was always messed up; the mode
lines in all these files said "C" whereas they were C++ or JS files. This
was in such a blind spot that I even copied it to new files that I had
created in the meantime...
Unreviewed.
|
|
|
|
|
|
|
|
|
| |
I've been wishing I had done this for three days now; jsapi-util.h is far
too long, and it's no fun to recompile the entire program every time one
of the macros is changed. The class macros plus the dynamic class functions
make a fairly independent unit, so this seems logical.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
|
|
|
|
|
|
|
| |
The return value is a prototype object, so there's no use in returning
JS::Value here only to convert it to an object in the calling code.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There are two places where we maintain weak pointers to GC things: one is
in object.cpp, where a GObject is associated with its JS wrapper object.
The other is in gtype.cpp, where each GType is associated with its
wrapper object.
In SpiderMonkey 38, we have to call JS_UpdateWeakPointerAfterGC() on weak
pointers, every garbage collection cycle, in case the garbage collector
moves them.
We considered adding a separate callback for each object with
JS_AddWeakPointerCallback() instead of one callback per file that
processes all the weak pointers it knows about, but that is prohibitive
since SpiderMonkey doesn't take the user data into account when calling
JS_RemoveWeakPointerCallback(), so you can't add and remove multiple
instances of the same callback.
https://bugzilla.gnome.org/show_bug.cgi?id=777962
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Since in mozjs31 all out parameters for GC things have been changed from
pointers to MutableHandles, there is no need to get the underlying GC
thing's address with JS::Handle::address(). Instead, we can simply use
the unary & operator to get a MutableHandle from a Rooted.
In some cases, such as JS_SetProperty(), the SpiderMonkey API changed a
JS::Value* parameter to a JS::HandleValue, so we can just delete the
.address() call and pass the RootedValue directly.
https://bugzilla.gnome.org/show_bug.cgi?id=751252
|
|
|
|
|
|
|
| |
In APIs that now take a JS::HandleObject, we must pass JS::NullPtr()
since JS::HandleObject cannot directly be constructed from NULL.
https://bugzilla.gnome.org/show_bug.cgi?id=751252
|
|
|
|
|
|
|
| |
Since mozjs31 does away with JSBool entirely, we can now replace the
remaining occurrences of it in the API with C++ bool.
https://bugzilla.gnome.org/show_bug.cgi?id=751252
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, JS_NewObject() was able to infer the prototype of the GType
object because the prototype was there in the global namespace.
JS_NewObject() has stopped doing this in mozjs31, so we need to
explicitly specify the prototype using JS_NewObjectWithGivenProto().
(I'm not sure if this needs to be fixed up anywhere else. The tests all
pass without it, and in the importer case, the tests were relying on the
importer object _not_ having the prototype of Object.)
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
| |
This is redundant, since you already can't set a property that doesn't
have a setter. It will be illegal and caught at compile time in mozjs31.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
|
|
| |
This ports the rest of the main codebase to use exact GC rooting for
everything that would otherwise have caused a compile error in mozjs31.
There were only a few modifications per file still to do so I stuck them
all in one commit.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
| |
This changes the gjs_whatever_create_proto() functions generated by the
GJS_DEFINE_PROTO macros in jsapi-util.h to be correctly rooted, letting
changes to those function prototypes cascade everywhere else.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
| |
Fixing various compiler warnings that are too small to have their own
commit.
https://bugzilla.gnome.org/show_bug.cgi?id=773297
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We got rid of all the "compat" stuff in compat.h already, before this
commit it only included jsapi.h, jsdbgapi.h, and jsapi-util.h, wrapping
the former two in some diagnostic pragmas. If we get rid of the
jsapi-util.h include, then we can use a system_header pragma to mark it
as a system header so that we don't have to painstakingly maintain all
those diagnostic pragmas.
(The system_header pragma ignores all warnings coming from that file:
https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html)
Since compat.h already wasn't a fitting name anymore, rename the header
to jsapi-wrapper.h.
https://bugzilla.gnome.org/show_bug.cgi?id=773297
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Starting with gjs_string_from_utf8(), we convert the JS::Value out-arg to
JS::MutableHandleValue. Working backwards from there in a huge cascade,
we change JS::Value * to JS::MutableHandleValue in many functions that
call gjs_string_from_utf8(), and root the values with JS::RootedValue
where they are created.
This is mostly straightforward, though requires replacing a few instances
of a stack-allocated JS::Value array created with g_newa(), with
JS::AutoValueVector instead.
In the course of moving to more RAII classes such as JS::Rooted<T>, we
can get rid of some more gotos in favour of returns.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
|
|
| |
Per https://bugzilla.mozilla.org/show_bug.cgi?id=992977,
JSPropertyOp-style property accessors are going to be removed in a future
version of SpiderMonkey. Instead, we use JSNative property accessors.
This allows us to use the JS_PSG and JS_PSGS macros in our JSPropertySpec
arrays, making things safer by eliminating the callback casts.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This adds two macros, GJS_GET_THIS() to get a function's 'this' value as
a rooted object (and if it was not an object, to box it into one), and
GJS_GET_PRIV() to get our private C data from the 'this' object.
This operation is done over and over again inside most JSNative
functions, and SpiderMonkey code often uses convenience macros like this.
These will come in handy even more when we switch to JSNative property
accessors in a following commit.
At the same time we make things more typesafe by doing a typecheck on
each 'this' object in the native methods as part of GJS_GET_PRIV() and
throwing an error if it is not the correct type. This gets rid of the
args.thisv().toObjectOrNull() idiom which I'm pretty sure is wrong.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
|
|
|
| |
This removes gjs-internals-1.0.pc and gjs-module.h, and makes all the
module header files private, that were previously installed.
Removes "do not include separately" guards from those files, and makes
sure they are included with quotes instead of angle brackets. Untangles
any header inclusion problems resulting from the removal of gjs-module.h.
https://bugzilla.gnome.org/show_bug.cgi?id=772386
|