| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
| |
- js/CallAndConstruct.h: Now contains JS::Call, JS::Construct, and
related
- js/Debug.h: Already existed, but now contains JS_DefineDebuggerObject
- js/GlobalObject.h: Now contains JS::CurrentGlobalOrNull
- js/PropertyAndElement.h: Now contains APIs for getting, setting, and
defining properties, as well as array elements
- js/ScriptPrivate.h: Now contains JS::GetScriptPrivate/SetScriptPrivate
- js/Stack.h: Now contains APIs that have to do with the call stack
|
|
|
|
|
|
|
|
| |
These flags are now automatically determined based on whether the
passed getter or setter is null.
Changeset: https://phabricator.services.mozilla.com/D116091
See: https://bugzilla.mozilla.org/show_bug.cgi?id=1713083
|
|
|
|
| |
See https://bugzilla.mozilla.org/show_bug.cgi?id=1663365
|
|
|
|
|
|
| |
JS_New was removed in favor of JS::Construct.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1491055
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
Adapt the IWYU processing script to the contents of the new version of
js/TypeDecls.h, and adjust the includes where necessary.
See: GNOME/gjs#329.
|
|
|
|
|
|
|
|
|
|
| |
- <js/Array.h> and <js/ValueArray.h> are new headers.
- Rename JS_NewArrayObject to JS::NewArrayObject.
- Rename JS_GetArrayLength to JS::GetArrayLength.
- Rename JS_IsArrayObject to JS::IsArrayObject.
- Rename JS::AutoValueArray to JS::RootedValueArray.
See: GNOME/gjs#329
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
| |
This will be unsupported in SpiderMonkey 78. It seems that in these
particular cases, we can pre-define these properties on classes with
resolve hooks, without using the RESOLVING flag because the resolve hook
doesn't try to access any of these.
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>.
|
|
|
|
|
| |
These are straightforward renames that happened between SpiderMonkey 60
and 68.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In SpiderMonkey 68, a "realm" is the term for the environment belonging
to a particular global object, so when you enter the "realm" of a global
object you are executing code with that object as the global object.
"Compartments" are still a thing but they are now more focused on
security, and are used for isolating code in different browser tabs in
Firefox, for example. All code in GJS except the debugger and the
coverage collector is run within the same compartment.
Some APIs that previously operated on a global object that was passed
in, now operate on the current realm.
|
|
|
|
|
|
| |
JSAutoRequest, JS_BeginRequest(), and JS_EndRequest() are no longer
necessary in SpiderMonkey 68. We can just remove them wherever they
appear.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, passing the wrong kind of object where a Cairo.Path,
Cairo.Pattern (subclass), or Cairo.Surface (subclass) was expected,
would crash. This adds type checking to avoid these crashes.
The normal way to do this would be with JS_HasInstance(), but since
Cairo.Pattern and Cairo.Surface are abstract classes, that won't work.
JS_HasInstance() takes a constructor, and abstract classes don't have a
constructor. Instead, we have to check the passed-in object's prototype
chain. It turns out there isn't a JSAPI function to do that, so we add
gjs_object_in_prototype_chain() for this purpose.
In addition we add missing error checking in a few places.
Closes: #49.
|
|
|
|
|
|
|
|
| |
We are going to refactor this anyway when we remove JSRequest in
SpiderMonkey 68. So, use RAII classes here and get rid of the gotos. The
comment at the top of the function about using 'volatile' to force the
variables to be collected by the GC has been inaccurate since
SpiderMonkey switched to an exact garbage collector several years ago.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
This file only had one function in it. It's not clear why this util file
is "glib" and the other file with one function in it is "misc". Merge
them both into "misc".
|
|
|
|
|
| |
gjs_init_class_dynamic() should take a const JSClass* pointer, since it
is not modified, and JS_InitClass() takes a const pointer as well.
|
|
|
|
|
| |
Our two weapons are fear and surprise ... and ruthless efficiency ... our
*three* weapons are...
|
|
|
|
|
|
| |
This moves the atoms (interned strings) from GjsContextPrivate to a
separate class, so that we can decouple them from GjsContext, since in
some cases we will want to use them only with the SpiderMonkey API.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- An argument that we didn't use was removed from the JSFinalizeCallback
signature
- JS_SetLocaleCallbacks API changed (is JSRuntime coming back again?)
- Giving a JSVERSION to a compartment or CompileOptions is not supported
anymore
- Use JS::CurrentThreadIsHeapCollecting() instead of our hacky workaround
in GC
- JS::PromiseRejectionHandlingState now is in the JS namespace
- JS::Value is now incompatible with C-linkage, so any function returning
one must be moved outside G_BEGIN_DECLS/G_END_DECLS
- JSPROP_SHARED is gone
- Defining a property with getter and setter now doesn't take a JS::Value
See: #161
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These hooks are going away in SpiderMonkey 60, so we have to do something
different. Instead of intercepting the getProperty/setProperty
operations, we lazily define a JS property for each GObject property or
field accessed in the resolve hook.
This uses the same native-accessor-with-private-data API used in
gi/boxed.cpp. Two separate sets of accessors are used for properties and
fields, which makes them a bit simpler than the previous code.
One behaviour change is that we now can't distinguish whether we're
setting a readonly property in strict mode or not. Now we always throw
when setting a readonly property; in effect, we treat the property set as
if it were always in strict mode. ES6 modules are always treated as
strict mode, so this is a change that client code will have to go through
anyway when using ES6 modules.
Closes: #160
|
|
|
|
|
| |
This saves a lookup of the strings "constructor" and "prototype" in the
interned strings table.
|
|
|
|
|
|
| |
In SpiderMonkey 60, properties that have a value will not be able to have
C++ getters and setters. The getters and setters are already unnecessary
in all the cases where we use them, so just remove them.
|
|
|
|
|
|
|
| |
Ever since removing the gjs-module API, there has not really been a
distinction between "public" and "private" jsapi-util functions. Just
remove the private files and incorporate everything declared or defined
there into the other jsapi-util files.
|
|
|
|
|
|
| |
Instead of looking up the Error prototype by name on the global object
when we want to throw an error, use JS_GetClassObject and JSProtoKey to
avoid the conversion of string to ID and the property lookup.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Instead of the various operation hooks being members of JSClass directly,
now JSClass contains a pointer to a JSClassOps struct. The JSClassOps
instead contains the function pointers to the operation hooks.
For importer.cpp, we still use the internal js::Class instead of JSClass.
This also contains a pointer to another struct, JSObjectOps, which we still
need for our internal lazy enumerate hook.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
| |
These comments were previously correct, but have become incorrect in
SpiderMonkey 45.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
|
| |
JS_DefineProperty() can now call into a class's resolve hook, so when
pre-defining properties on classes with resolve hooks we have to include
JSPROP_RESOLVING in the flags so that the resolve hook is not called.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
| |
In many function calls where you had to pass in a global object, it is
now implicit and will use the global for the current scope.
https://bugzilla.gnome.org/show_bug.cgi?id=784196
|
|
|
|
|
|
|
|
| |
This is optional, and will become disallowed in SpiderMonkey 45. No
change in functionality, because leaving it out already causes JS to get
the global object internally.
https://bugzilla.gnome.org/show_bug.cgi?id=781429
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
| |
Small cleanup; there is a function in the JSAPI that does exactly this,
automatically with the right flags.
https://bugzilla.gnome.org/show_bug.cgi?id=614413
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Lazy enumeration is still available through the jsfriend API in
js::Class, which is really JSClass but with some extra fields that are
masked in the public version.
In addition, JSNewEnumerateOp has changed somewhat, compared with
SpiderMonkey 31. Instead of the enumerate callback being called
incrementally for each property, now it is just called once the first
time an object's properties are enumerated, and you have to fill in the
passed-in JS::AutoIdVector with any names of lazy properties.
This changes the behaviour slightly, since the AutoIdVector already
contains any enumerable property names that the JS engine already knows
about, before the enumerate callback is called! So we now get byteArray,
etc. when we enumerate the importer.
https://bugzilla.gnome.org/show_bug.cgi?id=777962
|
|
|
|
|
|
|
|
|
| |
In JS_DefineProperty(), the getter and setter parameters must now be of
type JSNative. We have already switched to JSNative accessors everywhere,
but there are a few macros that must change in order to ensure everything
is cast to the right type.
https://bugzilla.gnome.org/show_bug.cgi?id=777962
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
JS_NewObject() does not take a prototype parameter anymore, that has been
split into a different function, JS_NewObjectWithGivenProto(). Passing
JS::NullPtr() as prototype means "Look in the global object for a
prototype that matches the given class" and that is now the only possible
behaviour for JS_NewObject().
Both JS_NewObject() and JS_NewObjectWithGivenProto() have had their
global object parameter made optional, so in the cases where we were
passing JS::NullPtr() there, then we simply leave it out.
https://bugzilla.gnome.org/show_bug.cgi?id=777962
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This code was due for some refactoring, and changing GjsConstString to be
rooted in the following commit was the opportunity for it. We now have
gjs_object_get_property(), gjs_object_has_property(),
gjs_object_set_property(), and gjs_object_define_property() as wrappers
for JS_GetPropertyById(), etc., that take a GjsConstString constant
instead of a jsid.
In addition, we rename gjs_object_require_property_value() to be an
overload of gjs_object_require_property(); the old name was confusing
because the name _without_ "value" was the one that dealt with a
JS::Value!
Same rename for gjs_object_require_converted_property_value().
This whole thing allows us to get rid of some code, moving a bunch of
roots into these new functions. These roots are strictly speaking still
necessary, but in the next commit we're going to root all the interned
strings permanently, which should have been done all along.
https://bugzilla.gnome.org/show_bug.cgi?id=776966
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This fixes a regression introduced in commit
a2fdf358207d075e9cbc6d78895f87b4e5a72bea.
If the prototype passed to the dynamic class's constructor is NULL, then
we have to call JS_NewObject() to get a default prototype, instead of
JS_NewObjectWithGivenProto(). Otherwise the object has _no_ prototype at
all.
Includes a regression test that would have caught this bug.
https://bugzilla.gnome.org/show_bug.cgi?id=776966
|
|
|
|
|
|
|
|
|
|
| |
In mozjs38, JS_NewObject() doesn't take a prototype JSObject anymore;
instead, JS_NewObjectWithGivenProto() is used for that purpose. The
behaviour of JS_NewObject() is changed so that it looks for a default
prototype, which is the same as passing JS::NullPtr() as the proto
parameter in mozjs31.
https://bugzilla.gnome.org/show_bug.cgi?id=776966
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
According to MDN [1], an idiomatic way to indicate a custom error is by
setting the 'name' property:
var e = new Error('Malformed input'); // e.name is 'Error'
e.name = 'ParseError';
throw e;
// e.toString() would return 'ParseError: Malformed input'
Add an extra 'name' argument to gjs_throw_custom() to allow this. If
'name' is NULL, then the previous behaviour is maintained.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name
https://bugzilla.gnome.org/show_bug.cgi?id=730101
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The setter and getter parameters now come after the flags, and passing
NULL for them is no longer required, since they have default values in
mozjs31. I believe that NULL (use the object's class's default setters
and getters) is different from JSPropertyStub and JSStrictPropertyStub,
so I left those in where they occurred.
In mozjs31 a bunch of overloads were defined, where you can pass
JS::HandleObject, JS::HandleString, int32_t, uint32_t, and double
directly to JS_DefineProperty() instead of only JS::HandleValue. This
allows us to get rid of some roots in our code where we created a
JS::RootedValue for the sole purpose of passing some value to
JS_DefineProperty().
https://bugzilla.gnome.org/show_bug.cgi?id=751252
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
JS::HandleValueArray is a useful way to pass arrays of arguments around,
has handy constructors such that you can pass in JS::CallArgs directly.
Therefore we refactor some functions to take it instead of argc, argv.
This will make the following commit easier where we adapt to the new APIs
of JS_New(), JS_CallFunction(), etc. which require JS::HandleValueArray.
This requires some changes in the closure callback marshal as previously
we were passing in an array that was longer with some empty elements at
the end, and relying on argc not to fall off the end. Now that there is
no argc parameter, we have to rearrange things a bit in that function.
https://bugzilla.gnome.org/show_bug.cgi?id=751252
|
|
|
|
|
|
|
| |
Starting in jsapi-dynamic-class.cpp and working backwards, we cause
another cascade of GC rooting changes.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This adds several functions in an overloaded
gjs_object_require_property_value() family, as well as a
gjs_object_require_converted_property_value() that can be overloaded when
the opportunity arises.
One operation that is done many times across the codebase is to call
gjs_object_require_property() and then typecheck the JS::Value that it
returns, throwing a custom exception if the property was the wrong type.
We introduce gjs_object_require_property_value() which takes a pointer to
whatever type we expect in the JS::Value, and takes care of all the
rooting and exception throwing. Basically it calls the equivalent of
isWhateverType() and toWhateverType() while skipping JSString * in favour
of returning a UTF-8 encoded string.
For not only type-checking but also converting a JS::Value of the wrong
type to the requested type, there is
gjs_object_require_converted_property_value(). Currently in the codebase
this operation is only done on one type, uint32, but it can be overloaded
with more types later.
This reduces a lot of code duplication that would otherwise all have to
be converted to rooting by hand in the next commit.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|
|
|
|
|
|
|
|
|
|
|
|
| |
Starting out with gjs_object_require_property(), we do another cascade of
GC rooting changes.
This requires making some changes to the private structs of Boxed and
Fundamental. Since they contain members of type jsid, which are subject
to garbage collection, those members must be traced. JSClass provides a
trace callback for this purpose.
https://bugzilla.gnome.org/show_bug.cgi?id=742249
|