diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2022-08-08 04:22:51 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2022-08-08 04:22:51 +0000 |
commit | 2192739168ee28cec7fa1663ff6f6fb95e1ce86c (patch) | |
tree | 3cad11f76712dd370f647733ca8aeb7f658871cb | |
parent | c01c41334c40dac2d8635e42423d0326385e501b (diff) | |
parent | a84c27da767351d13ade11cc094443b2ca179a1f (diff) | |
download | gjs-2192739168ee28cec7fa1663ff6f6fb95e1ce86c.tar.gz |
Merge branch 'mozjs102' into 'master'
Initial port to mozjs102
See merge request GNOME/gjs!765
59 files changed, 248 insertions, 189 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1323d822..8869ed6b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,7 +31,7 @@ build-alpine-image: mkdir -p /cwd .coverage: &coverage - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: coverage: '/^ lines.*(\d+\.\d+\%)/' script: @@ -75,7 +75,7 @@ build-alpine-image: build_recommended: <<: *build stage: source_check - image: registry.gitlab.gnome.org/gnome/gjs:job-2153951_fedora.mozjs91-debug # pinned on purpose + image: registry.gitlab.gnome.org/gnome/gjs:job-2190518_fedora.mozjs102-debug # pinned on purpose variables: TEST_OPTS: --verbose --no-stdsplit --print-errorlogs --setup=verbose except: @@ -86,7 +86,7 @@ sanitizer_gcc: stage: test tags: - asan # LSAN needs CAP_SYS_PTRACE - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: CONFIG_OPTS: -Db_sanitize=address,undefined TEST_OPTS: --timeout-multiplier=3 --setup=verbose @@ -100,7 +100,7 @@ sanitizer_thread_gcc: allow_failure: true tags: - asan # TSAN needs CAP_SYS_PTRACE - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: CONFIG_OPTS: -Db_sanitize=thread TEST_OPTS: --timeout-multiplier=3 --setup=verbose @@ -113,7 +113,7 @@ sanitizer_thread_gcc: build_maximal: <<: *build stage: test - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: CC: clang CXX: clang++ @@ -129,7 +129,7 @@ build_maximal: build_minimal: <<: *build stage: test - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91 + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102 variables: CONFIG_OPTS: >- -Dbuildtype=release @@ -141,7 +141,7 @@ build_minimal: build_unity: <<: *build stage: test - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91 + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102 variables: # unity-size here is forced to use an high number to check whether we can # join all the sources together, but should not be used in real world to @@ -253,7 +253,7 @@ pch_check: iwyu: when: on_success stage: source_check - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug script: - test/test-ci.sh UPSTREAM_BASE - meson setup _build -Db_pch=false @@ -304,7 +304,7 @@ coverage: iwyu-full: when: manual stage: manual - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug script: - meson setup _build - ./tools/run_iwyu.sh @@ -316,7 +316,7 @@ sanitizer_clang: stage: manual tags: - asan # LSAN needs CAP_SYS_PTRACE - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: CC: clang CXX: clang++ @@ -329,7 +329,7 @@ sanitizer_clang: installed_tests: <<: *build stage: manual - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: CONFIG_OPTS: -Dinstalled_tests=true -Dprefix=/usr TEST: skip @@ -345,7 +345,7 @@ installed_tests: valgrind: <<: *build stage: manual - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: TEST_OPTS: --setup=valgrind allow_failure: true @@ -357,7 +357,7 @@ valgrind: zeal_2: <<: *build stage: manual - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: TEST_OPTS: --setup=extra_gc when: manual @@ -367,7 +367,7 @@ zeal_2: zeal_4: <<: *build stage: manual - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: TEST_OPTS: --setup=pre_verify when: manual @@ -377,7 +377,7 @@ zeal_4: zeal_11: <<: *build stage: manual - image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs91-debug + image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs102-debug variables: TEST_OPTS: --setup=post_verify when: manual @@ -1,3 +1,18 @@ +Version 1.73.2 +-------------- + +- New JavaScript features! This version of GJS is based on SpiderMonkey 102, an + upgrade from the previous ESR (Extended Support Release) of SpiderMonkey 91. + Here are the highlights of the new JavaScript features. + For more information, look them up on MDN or devdocs.io. + + * New APIs + + The `Object.hasOwn()` static method can be used as an easier replacement + for `Object.prototype.hasOwnProperty.call(...)`. + + `Intl.supportedValuesOf()` lets you enumerate which calendars, currencies, + collation strategies, numbering systems, time zones, and units are + available for internationalization. + Version 1.73.1 -------------- diff --git a/README.MSVC.md b/README.MSVC.md index 9cf51a87..b5f54349 100644 --- a/README.MSVC.md +++ b/README.MSVC.md @@ -7,13 +7,13 @@ recent-enough Windows SDK from Microsoft is still required if using clang-cl, as we will still use items from the Windows SDK.
Recent official binary installers of CLang (which contains clang-cl)
-from the LLVM website are known to work to build SpiderMonkey 91 and
+from the LLVM website are known to work to build SpiderMonkey 102 and
GJS.
You will need the following items to build GJS using Visual Studio
or clang-cl (they can be built with Visual Studio 2015 or later,
unless otherwise noted):
--SpiderMonkey 91.x (mozjs-91). This must be built with clang-cl as
+-SpiderMonkey 102.x (mozjs-102). This must be built with clang-cl as
the Visual Studio compiler is no longer supported for building this.
Please see the below section carefully on this...
-GObject-Introspection (G-I) 1.61.2 or later
@@ -44,8 +44,8 @@ for the suitable release series of SpiderMonkey that corresponds to the GJS version that is being built, as GJS depends on ESR (Extended
Service Release, a.k.a Long-term support) releases of SpiderMonkey.
-You may also be able to obtain the SpiderMonkey 91.x sources via the
-FireFox (ESR) or Thunderbird 91.x sources, in $(srcroot)/js.
+You may also be able to obtain the SpiderMonkey 102.x sources via the
+FireFox (ESR) or Thunderbird 102.x sources, in $(srcroot)/js.
Please do note that the build must be done carefully, in addition to the
official instructions that are posted on the Mozilla website:
@@ -53,7 +53,7 @@ official instructions that are posted on the Mozilla website: https://firefox-source-docs.mozilla.org/js/build.html
You will need to create a .mozconfig file that will describe your build
-options for the build in the root directory of the Firefox/ThunderBird 91.x
+options for the build in the root directory of the Firefox/ThunderBird 102.x
sources. A sample content of the .mozconfig file can be added as follows:
```
@@ -66,7 +66,7 @@ ac_add_options --disable-tests ac_add_options --enable-optimize
ac_add_options --disable-debug
ac_add_options --disable-jemalloc
-ac_add_options --prefix=c:/software.b/mozjs91.bin
+ac_add_options --prefix=c:/software.b/mozjs102.bin
```
An explanation of the lines above:
@@ -79,10 +79,10 @@ An explanation of the lines above: * `ac_add_options --enable-optimize`: Use for release builds of SpiderMonkey. Use `--disable-optimize` instead if building with `--enable-debug`
* `ac_add_options --enable-debug`: Include debugging functions, for debug builds. Use `--disable-debug` instead if building with `--enable-optimize`
* `ac_add_options --disable-jemalloc`: This is absolutely needed, otherwise GJS will not build and run correctly
-* `ac_add_options --prefix=c:/software.b/mozjs91.bin`: Some installation path, change as needed
+* `ac_add_options --prefix=c:/software.b/mozjs102.bin`: Some installation path, change as needed
If your GJS build crashes upon launch, use Dependency Walker to ensure that
-mozjs-91.dll does not depend on mozglue.dll! If it does, or if GJS fails to
+mozjs-102.dll does not depend on mozglue.dll! If it does, or if GJS fails to
link with missing arena_malloc() and friends symbols, you have built SpiderMoney
incorrectly and will need to rebuild SpiderMonkey (with the build options as
noted above) and retry the build.
@@ -119,17 +119,17 @@ $(buildroot)/dist/include. Note that for PDB files and .lib files, you will need to search for them in $(buildroot),
where the PDB file names match the filenames for the DLLs/EXEs in
$(buildroot)/dist/bin, and you will need to look for the following .lib files:
--mozjs-91.lib
+-mozjs-102.lib
-js_static.lib (optional)
You may want to put the .lib's and DLLs/EXEs into $(PREFIX)\lib and
$(PREFIX)\bin respectively, and put the headers into
-$(PREFIX)\include\mozjs-91 for convenience.
+$(PREFIX)\include\mozjs-102 for convenience.
-You will need to place the generated mozjs-91.pc pkg-config file into
+You will need to place the generated mozjs-102.pc pkg-config file into
$(PREFIX)\lib\pkgconfig and ensure that pkg-config can find it by
setting PKG_CONFIG_PATH. Ensure that the 'includedir' and 'libdir'
-in there is correct so that the mozjs-91.pc can be used correctly in
+in there is correct so that the mozjs-102.pc can be used correctly in
Visual Studio/clang-cl builds, and replace the `-isystem` with `-I` if
building GJS with Visual Studio. You will also need to ensure that the
existing GObject-Introspection installation (if used) is on the same
diff --git a/doc/Hacking.md b/doc/Hacking.md index 1c732f43..d58f9362 100644 --- a/doc/Hacking.md +++ b/doc/Hacking.md @@ -37,7 +37,7 @@ You can also skip this step if you are not writing any C++ code.) ## Dependencies GJS requires five other libraries to be installed: GLib, libffi, -gobject-introspection, SpiderMonkey (also called "mozjs91" on some +gobject-introspection, SpiderMonkey (also called "mozjs102" on some systems.) and the build tool Meson. The readline library is not required, but strongly recommended. We recommend installing your system's development packages for GLib, @@ -70,15 +70,15 @@ example, Fedora 36 or Ubuntu 22.04 and later versions), then you don't need to build it yourself. Install SpiderMonkey using your system's package manager instead: -<!--Ubuntu does not currently ship a build of libmozjs-91--> +<!--Ubuntu does not currently ship a build of libmozjs-102--> <!-- <details> <summary>Ubuntu</summary> - <code>sudo apt-get install libmozjs-91-dev</code> + <code>sudo apt-get install libmozjs-102-dev</code> </details> --> <details> <summary>Fedora</summary> - <code>sudo dnf install mozjs91-devel</code> + <code>sudo dnf install mozjs102-devel</code> </details> If you _are_ writing C++ code, then please build SpiderMonkey yourself @@ -86,7 +86,7 @@ with the debugging features enabled. This can save you time later when you submit your merge request, because the code will be checked using the debugging features. -To build SpiderMonkey, follow the instructions on [this page](https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/esr91/docs/Building%20SpiderMonkey.md) to download the source code and build the library. +To build SpiderMonkey, follow the instructions on [this page](https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/esr102/docs/Building%20SpiderMonkey.md) to download the source code and build the library. If you are using `-Dprefix` to build GJS into a different path, then make sure to use the same build prefix for SpiderMonkey with `--prefix`. @@ -152,7 +152,7 @@ more likely to show up. To see which GC zeal options are available: ```sh -JS_GC_ZEAL=-1 js91 +JS_GC_ZEAL=-1 js102 ``` We include three test setups, `extra_gc`, `pre_verify`, and @@ -216,7 +216,7 @@ This will build GJS into a separate build directory with code coverage instrumentation enabled, run the test suite to collect the coverage data, and open the generated HTML report. -[embedder](https://github.com/spidermonkey-embedders/spidermonkey-embedding-examples/blob/esr91/docs/Building%20SpiderMonkey.md) +[embedder](https://github.com/spidermonkey-embedders/spidermonkey-embedding-examples/blob/esr102/docs/Building%20SpiderMonkey.md) ## Troubleshooting diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp index 7c269468..ce814d6b 100644 --- a/gi/arg-cache.cpp +++ b/gi/arg-cache.cpp @@ -26,7 +26,7 @@ #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/experimental/TypedData.h> -#include <jsapi.h> // for JS_TypeOfValue +#include <jsapi.h> // for InformalValueTypeName, JS_TypeOfValue #include <jsfriendapi.h> // for JS_GetObjectFunction #include <jspubtd.h> // for JSTYPE_FUNCTION @@ -20,6 +20,7 @@ #include <js/ErrorReport.h> // for JS_ReportOutOfMemory #include <js/Exception.h> #include <js/GCVector.h> // for RootedVector, MutableWrappedPtrOp... +#include <js/PropertyAndElement.h> // for JS_GetElement, JS_HasPropertyById #include <js/PropertyDescriptor.h> // for JSPROP_ENUMERATE #include <js/RootingAPI.h> #include <js/String.h> @@ -28,7 +29,7 @@ #include <js/Value.h> #include <js/ValueArray.h> #include <js/experimental/TypedData.h> -#include <jsapi.h> // for JS_ReportOutOfMemory, JS_GetElement +#include <jsapi.h> // for InformalValueTypeName, IdVector #include <jsfriendapi.h> // for JS_GetObjectFunction #include "gi/arg-inl.h" diff --git a/gi/boxed.cpp b/gi/boxed.cpp index c84cd4d4..378abb19 100644 --- a/gi/boxed.cpp +++ b/gi/boxed.cpp @@ -20,6 +20,7 @@ #include <js/GCHashTable.h> // for GCHashMap #include <js/GCVector.h> // for MutableWrappedPtrOperations #include <js/Object.h> // for SetReservedSlot +#include <js/PropertyAndElement.h> // for JS_DefineFunction, JS_Enumerate #include <js/String.h> #include <js/TracingAPI.h> #include <js/TypeDecls.h> @@ -763,7 +764,6 @@ const struct JSClassOps BoxedBase::class_ops = { nullptr, // mayResolve &BoxedBase::finalize, nullptr, // call - nullptr, // hasInstance nullptr, // construct &BoxedBase::trace }; @@ -929,7 +929,7 @@ BoxedPrototype::BoxedPrototype(GIStructInfo* info, GType gtype) : GIWrapperPrototype(info, gtype), m_zero_args_constructor(-1), m_default_constructor(-1), - m_default_constructor_name(JSID_VOID), + m_default_constructor_name(JS::PropertyKey::Void()), m_can_allocate_directly(struct_is_simple(info)) { if (!m_can_allocate_directly) { m_can_allocate_directly_without_pointers = false; @@ -944,8 +944,8 @@ BoxedPrototype::BoxedPrototype(GIStructInfo* info, GType gtype) bool BoxedPrototype::init(JSContext* context) { int i, n_methods; int first_constructor = -1; - jsid first_constructor_name = JSID_VOID; - jsid zero_args_constructor_name = JSID_VOID; + jsid first_constructor_name = JS::PropertyKey::Void(); + jsid zero_args_constructor_name = JS::PropertyKey::Void(); if (m_gtype != G_TYPE_NONE) { /* If the structure is registered as a boxed, we can create a new instance by diff --git a/gi/closure.cpp b/gi/closure.cpp index 288550a0..4d85a60a 100644 --- a/gi/closure.cpp +++ b/gi/closure.cpp @@ -8,11 +8,12 @@ #include <glib.h> // for g_assert +#include <js/CallAndConstruct.h> #include <js/Realm.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_IsExceptionPending, Call, JS_Get... +#include <jsapi.h> // for JS_GetFunctionObject #include "gi/closure.h" #include "gjs/context-private.h" diff --git a/gi/cwrapper.cpp b/gi/cwrapper.cpp index f5fbff8a..c6cca867 100644 --- a/gi/cwrapper.cpp +++ b/gi/cwrapper.cpp @@ -9,7 +9,6 @@ #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT #include <js/RootingAPI.h> #include <js/TypeDecls.h> -#include <jsapi.h> // for JS_DefinePropertyById #include "gi/cwrapper.h" #include "gi/gtype.h" diff --git a/gi/cwrapper.h b/gi/cwrapper.h index 159479e1..71198df0 100644 --- a/gi/cwrapper.h +++ b/gi/cwrapper.h @@ -16,13 +16,15 @@ #include <js/CallArgs.h> #include <js/Class.h> +#include <js/GlobalObject.h> // for CurrentGlobalOrNull #include <js/Id.h> #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Value.h> -#include <jsapi.h> -#include <jspubtd.h> +#include <jsapi.h> // for JSFUN_CONSTRUCTOR, JS_NewPlainObject, JS_GetFuncti... +#include <jspubtd.h> // for JSProto_Object, JSProtoKey, JSProto_TypeError #include "gjs/jsapi-util.h" #include "gjs/macros.h" @@ -84,7 +86,7 @@ class CWrapperPointerOps { if (!JS_InstanceOf(cx, wrapper, &Base::klass, nullptr)) return nullptr; - return Gjs::maybe_get_private<Wrapped>(wrapper, POINTER); + return JS::GetMaybePtrFromReservedSlot<Wrapped>(wrapper, POINTER); } /* @@ -137,7 +139,7 @@ class CWrapperPointerOps { * (It can return null if no private data has been set yet on the wrapper.) */ [[nodiscard]] static Wrapped* for_js_nocheck(JSObject* wrapper) { - return Gjs::maybe_get_private<Wrapped>(wrapper, POINTER); + return JS::GetMaybePtrFromReservedSlot<Wrapped>(wrapper, POINTER); } protected: @@ -151,7 +153,7 @@ class CWrapperPointerOps { * wrapper object. */ [[nodiscard]] static bool has_private(JSObject* wrapper) { - return !!Gjs::maybe_get_private<Wrapped>(wrapper, POINTER); + return !!JS::GetMaybePtrFromReservedSlot<Wrapped>(wrapper, POINTER); } /* @@ -202,7 +204,7 @@ class CWrapperPointerOps { * class_spec's flags member. * - static constexpr unsigned constructor_nargs: number of arguments that the * constructor takes. If you implement constructor_impl() then also add this. - * - void finalize_impl(JSFreeOp*, Wrapped*): called when the JS object is + * - void finalize_impl(JS::GCContext*, Wrapped*): called when the JS object is * garbage collected, use this to free the C pointer and do any other cleanup * * Add optional functionality by setting members of class_spec: @@ -289,14 +291,14 @@ class CWrapper : public CWrapperPointerOps<Base, Wrapped> { debug_jsprop(message, gjs_debug_id(id).c_str(), obj); } - static void finalize(JSFreeOp* fop, JSObject* obj) { + static void finalize(JS::GCContext* gcx, JSObject* obj) { Wrapped* priv = Base::for_js_nocheck(obj); // Call only CWrapper's original method here, not any overrides; e.g., // we don't want to deal with a read barrier. CWrapper::debug_lifecycle(priv, obj, "Finalize"); - Base::finalize_impl(fop, priv); + Base::finalize_impl(gcx, priv); CWrapperPointerOps<Base, Wrapped>::unset_private(obj); } diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp index 62090ce4..bc0e8274 100644 --- a/gi/enumeration.cpp +++ b/gi/enumeration.cpp @@ -8,9 +8,10 @@ #include <glib-object.h> #include <glib.h> +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> -#include <jsapi.h> // for JS_DefineProperty, JS_NewPlainObject +#include <jsapi.h> // for JS_NewPlainObject #include "gi/cwrapper.h" #include "gi/enumeration.h" diff --git a/gi/function.cpp b/gi/function.cpp index af739ecd..08a0ea25 100644 --- a/gi/function.cpp +++ b/gi/function.cpp @@ -22,6 +22,7 @@ #include <js/Class.h> #include <js/ErrorReport.h> // for JS_ReportOutOfMemory #include <js/Exception.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT #include <js/PropertySpec.h> #include <js/Realm.h> // for GetRealmFunctionPrototype @@ -31,7 +32,7 @@ #include <js/Value.h> #include <js/ValueArray.h> #include <js/Warnings.h> -#include <jsapi.h> // for HandleValueArray, JS_GetElement +#include <jsapi.h> // for HandleValueArray #include <jspubtd.h> // for JSProtoKey #include "gi/arg-cache.h" @@ -108,7 +109,7 @@ class Function : public CWrapper<Function> { GJS_JSAPI_RETURN_CONVENTION static bool call(JSContext* cx, unsigned argc, JS::Value* vp); - static void finalize_impl(JSFreeOp*, Function* priv); + static void finalize_impl(JS::GCContext*, Function* priv); GJS_JSAPI_RETURN_CONVENTION static bool get_length(JSContext* cx, unsigned argc, JS::Value* vp); @@ -1153,7 +1154,7 @@ Function::~Function() { GJS_DEC_COUNTER(function); } -void Function::finalize_impl(JSFreeOp*, Function* priv) { +void Function::finalize_impl(JS::GCContext*, Function* priv) { if (priv == NULL) return; /* we are the prototype, not a real instance, so constructor never called */ delete priv; diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp index 56cf2dc0..d2f591e3 100644 --- a/gi/fundamental.cpp +++ b/gi/fundamental.cpp @@ -13,10 +13,11 @@ #include <js/ErrorReport.h> // for JS_ReportOutOfMemory #include <js/GCHashTable.h> // for WeakCache #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars -#include <jsapi.h> // for InformalValueTypeName +#include <jsapi.h> // for InformalValueTypeName, JS_NewObjectWithGivenP... #include <mozilla/HashTable.h> #include "gi/arg-inl.h" @@ -243,7 +244,6 @@ const struct JSClassOps FundamentalBase::class_ops = { nullptr, // mayResolve &FundamentalBase::finalize, nullptr, // call - nullptr, // hasInstance nullptr, // construct &FundamentalBase::trace }; diff --git a/gi/gerror.cpp b/gi/gerror.cpp index ba70005b..91682453 100644 --- a/gi/gerror.cpp +++ b/gi/gerror.cpp @@ -11,17 +11,20 @@ #include <girepository.h> #include <glib-object.h> +#include <js/CallAndConstruct.h> #include <js/CallArgs.h> #include <js/Class.h> #include <js/Exception.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_ENUMERATE #include <js/RootingAPI.h> #include <js/SavedFrameAPI.h> +#include <js/Stack.h> // for BuildStackString, CaptureCurrentStack #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_DefinePropertyById, JS_GetProp... +#include <jsapi.h> // for InformalValueTypeName, JS_GetClassObject #include <jspubtd.h> // for JSProtoKey, JSProto_Error, JSProt... #include "gi/arg-inl.h" diff --git a/gi/gobject.cpp b/gi/gobject.cpp index 2ab1f28b..914f6176 100644 --- a/gi/gobject.cpp +++ b/gi/gobject.cpp @@ -10,13 +10,15 @@ #include <glib-object.h> #include <glib.h> +#include <js/CallAndConstruct.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_READONLY #include <js/Realm.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Value.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_SetProperty, JS_DefineProperty +#include <jsapi.h> // for JS_NewPlainObject #include <mozilla/Maybe.h> #include "gi/gobject.h" diff --git a/gi/gtype.cpp b/gi/gtype.cpp index 3b0b8b80..8f5bf38a 100644 --- a/gi/gtype.cpp +++ b/gi/gtype.cpp @@ -12,11 +12,12 @@ #include <js/CallArgs.h> #include <js/Class.h> #include <js/GCHashTable.h> // for WeakCache +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> -#include <jsapi.h> // for JS_GetPropertyById, JS_AtomizeString +#include <jsapi.h> // for JS_NewObjectWithGivenProto #include <mozilla/HashTable.h> #include "gi/cwrapper.h" @@ -47,7 +48,7 @@ class GTypeObj : public CWrapper<GTypeObj, void> { // No private data is allocated, it's stuffed directly in the private field // of JSObject, so nothing to free - static void finalize_impl(JSFreeOp*, void*) {} + static void finalize_impl(JS::GCContext*, void*) {} // Properties @@ -152,7 +152,7 @@ class Ns : private GjsAutoChar, public CWrapper<Ns> { return true; } - static void finalize_impl(JSFreeOp* fop [[maybe_unused]], Ns* priv) { + static void finalize_impl(JS::GCContext*, Ns* priv) { g_assert(priv && "Finalize called on wrong object"); delete priv; } diff --git a/gi/object.cpp b/gi/object.cpp index 6cf97c72..3ced434f 100644 --- a/gi/object.cpp +++ b/gi/object.cpp @@ -22,6 +22,7 @@ #include <glib-object.h> #include <glib.h> +#include <js/CallAndConstruct.h> // for IsCallable, JS_CallFunctionValue #include <js/CallArgs.h> #include <js/CharacterEncoding.h> #include <js/Class.h> @@ -31,6 +32,7 @@ #include <js/GCVector.h> // for MutableWrappedPtrOperations #include <js/HeapAPI.h> #include <js/MemoryFunctions.h> // for AddAssociatedMemory, RemoveAssoci... +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT, JSPROP_READONLY #include <js/String.h> #include <js/Symbol.h> @@ -39,8 +41,8 @@ #include <js/Value.h> #include <js/ValueArray.h> #include <js/Warnings.h> -#include <jsapi.h> // for IsCallable -#include <jsfriendapi.h> // for JS_GetObjectFunction, IsFunctionO... +#include <jsapi.h> // for JS_GetFunctionObject, IdVector +#include <jsfriendapi.h> // for JS_GetObjectFunction, GetFunctionNativeReserved #include <mozilla/HashTable.h> #include "gi/arg-inl.h" @@ -677,7 +679,7 @@ static bool interface_getter(JSContext* cx, unsigned argc, JS::Value* vp) { g_assert(v_override_symbol.isSymbol() && "override symbol must be a symbol"); JS::RootedSymbol override_symbol(cx, v_override_symbol.toSymbol()); - JS::RootedId override_id(cx, SYMBOL_TO_JSID(override_symbol)); + JS::RootedId override_id(cx, JS::PropertyKey::Symbol(override_symbol)); JS::RootedObject this_obj(cx); if (!args.computeThis(cx, &this_obj)) @@ -697,7 +699,7 @@ static bool interface_getter(JSContext* cx, unsigned argc, JS::Value* vp) { g_assert(v_prototype.isObject() && "prototype must be an object"); JS::RootedObject prototype(cx, &v_prototype.toObject()); - JS::RootedId id(cx, JS::PropertyKey::fromNonIntAtom(JS_GetFunctionId( + JS::RootedId id(cx, JS::PropertyKey::NonIntAtom(JS_GetFunctionId( JS_GetObjectFunction(&args.callee())))); return JS_GetPropertyById(cx, prototype, id, args.rval()); } @@ -721,7 +723,7 @@ static bool interface_setter(JSContext* cx, unsigned argc, JS::Value* vp) { JS::RootedObject this_obj(cx); if (!args.computeThis(cx, &this_obj)) return false; - JS::RootedId override_id(cx, SYMBOL_TO_JSID(symbol)); + JS::RootedId override_id(cx, JS::PropertyKey::Symbol(symbol)); return JS_SetPropertyById(cx, this_obj, override_id, args[0]); } @@ -1582,7 +1584,7 @@ ObjectPrototype::ObjectPrototype(GIObjectInfo* info, GType gtype) * Private callback, called after the JS engine finishes garbage collection, and * notifies when weak pointers need to be either moved or swept. */ -void ObjectInstance::update_heap_wrapper_weak_pointers(JSContext*, +void ObjectInstance::update_heap_wrapper_weak_pointers(JSTracer* trc, JS::Compartment*, void*) { gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "Weak pointer update callback, " @@ -1594,15 +1596,15 @@ void ObjectInstance::update_heap_wrapper_weak_pointers(JSContext*, auto locked_queue = ToggleQueue::get_default(); ObjectInstance::remove_wrapped_gobjects_if( - std::mem_fn(&ObjectInstance::weak_pointer_was_finalized), + [&trc](ObjectInstance* instance) -> bool { + return instance->weak_pointer_was_finalized(trc); + }, std::mem_fn(&ObjectInstance::disassociate_js_gobject)); s_wrapped_gobject_list.shrink_to_fit(); } -bool -ObjectInstance::weak_pointer_was_finalized(void) -{ +bool ObjectInstance::weak_pointer_was_finalized(JSTracer* trc) { if (has_wrapper() && !wrapper_is_rooted()) { bool toggle_down_queued, toggle_up_queued; @@ -1613,7 +1615,7 @@ ObjectInstance::weak_pointer_was_finalized(void) if (!toggle_down_queued && toggle_up_queued) return false; - if (!update_after_gc()) + if (!update_after_gc(trc)) return false; if (toggle_down_queued) @@ -1900,14 +1902,14 @@ void ObjectPrototype::trace_impl(JSTracer* tracer) { Gjs::Closure::for_gclosure(closure)->trace(tracer); } -void ObjectInstance::finalize_impl(JSFreeOp* fop, JSObject* obj) { +void ObjectInstance::finalize_impl(JS::GCContext* gcx, JSObject* obj) { GTypeQuery query; type_query_dynamic_safe(&query); if (G_LIKELY(query.type)) JS::RemoveAssociatedMemory(obj, query.instance_size, MemoryUse::GObjectInstanceStruct); - GIWrapperInstance::finalize_impl(fop, obj); + GIWrapperInstance::finalize_impl(gcx, obj); } ObjectInstance::~ObjectInstance() { @@ -2532,7 +2534,6 @@ const struct JSClassOps ObjectBase::class_ops = { &ObjectBase::finalize, NULL, NULL, - NULL, &ObjectBase::trace, }; diff --git a/gi/object.h b/gi/object.h index 0985845e..e6016cb7 100644 --- a/gi/object.h +++ b/gi/object.h @@ -170,7 +170,7 @@ struct IdHasher { return js::DefaultHasher<JSString*>::hash(id.toString()); if (id.isSymbol()) return js::DefaultHasher<JS::Symbol*>::hash(id.toSymbol()); - return mozilla::HashGeneric(JSID_BITS(id)); + return mozilla::HashGeneric(id.asRawBits()); } static bool match(jsid id1, jsid id2) { return id1 == id2; } }; @@ -333,18 +333,19 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype, void discard_wrapper(void) { m_wrapper.reset(); } void switch_to_rooted(JSContext* cx) { m_wrapper.switch_to_rooted(cx); } void switch_to_unrooted(JSContext* cx) { m_wrapper.switch_to_unrooted(cx); } - [[nodiscard]] bool update_after_gc() { return m_wrapper.update_after_gc(); } + [[nodiscard]] bool update_after_gc(JSTracer* trc) { + return m_wrapper.update_after_gc(trc); + } [[nodiscard]] bool wrapper_is_rooted() const { return m_wrapper.rooted(); } void release_native_object(void); void associate_js_gobject(JSContext* cx, JS::HandleObject obj, GObject* gobj); void disassociate_js_gobject(void); void handle_context_dispose(void); - [[nodiscard]] bool weak_pointer_was_finalized(); + [[nodiscard]] bool weak_pointer_was_finalized(JSTracer* trc); static void ensure_weak_pointer_callback(JSContext* cx); - static void update_heap_wrapper_weak_pointers(JSContext* cx, - JS::Compartment* compartment, - void* data); + static void update_heap_wrapper_weak_pointers(JSTracer* trc, + JS::Compartment*, void* data); public: void toggle_down(void); @@ -418,7 +419,7 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype, GJS_JSAPI_RETURN_CONVENTION bool add_property_impl(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value); - void finalize_impl(JSFreeOp* fop, JSObject* obj); + void finalize_impl(JS::GCContext*, JSObject* obj); void trace_impl(JSTracer* trc); /* JS property getters/setters */ diff --git a/gi/param.cpp b/gi/param.cpp index 5f419db9..93fff17e 100644 --- a/gi/param.cpp +++ b/gi/param.cpp @@ -12,11 +12,12 @@ #include <js/CallArgs.h> #include <js/Class.h> #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> -#include <jsapi.h> // for JS_GetPropertyById +#include <jsapi.h> // for JS_NewObjectForConstructor, JS_NewObjectWithG... #include <jspubtd.h> // for JSProto_TypeError #include "gi/cwrapper.h" @@ -47,7 +48,7 @@ struct Param : GjsAutoParam { if (!JS_InstanceOf(cx, obj, &gjs_param_class, nullptr)) return nullptr; - auto* priv = Gjs::maybe_get_private<Param>(obj, POINTER); + auto* priv = JS::GetMaybePtrFromReservedSlot<Param>(obj, POINTER); return priv ? priv->get() : nullptr; } @@ -122,8 +123,8 @@ static bool gjs_param_constructor(JSContext* cx, unsigned argc, JS::Value* vp) { return true; } -static void param_finalize(JSFreeOp*, JSObject* obj) { - Param* priv = Gjs::maybe_get_private<Param>(obj, POINTER); +static void param_finalize(JS::GCContext*, JSObject* obj) { + Param* priv = JS::GetMaybePtrFromReservedSlot<Param>(obj, POINTER); gjs_debug_lifecycle(GJS_DEBUG_GPARAM, "finalize, obj %p priv %p", obj, priv); if (!priv) diff --git a/gi/private.cpp b/gi/private.cpp index 85001cb6..02332b18 100644 --- a/gi/private.cpp +++ b/gi/private.cpp @@ -12,12 +12,13 @@ #include <js/Array.h> // for JS::GetArrayLength, #include <js/CallArgs.h> +#include <js/PropertyAndElement.h> #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/ValueArray.h> -#include <jsapi.h> // for JS_GetElement +#include <jsapi.h> // for JS_NewPlainObject #include "gi/gobject.h" #include "gi/gtype.h" diff --git a/gi/repo.cpp b/gi/repo.cpp index 221cf8c7..ab23677f 100644 --- a/gi/repo.cpp +++ b/gi/repo.cpp @@ -15,11 +15,14 @@ #include <glib-object.h> #include <glib.h> +#include <js/CallAndConstruct.h> // for JS_CallFunctionValue #include <js/Class.h> #include <js/ComparisonOperators.h> #include <js/Exception.h> +#include <js/GlobalObject.h> // for CurrentGlobalOrNull #include <js/Id.h> // for PropertyKey #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT, JSPROP_RESOLVING #include <js/RootingAPI.h> #include <js/String.h> @@ -28,7 +31,7 @@ #include <js/Value.h> #include <js/ValueArray.h> #include <js/Warnings.h> -#include <jsapi.h> // for JS_DefinePropertyById, JS_GetProp... +#include <jsapi.h> // for JS_NewPlainObject, JS_NewObject #include "gi/arg.h" #include "gi/boxed.h" diff --git a/gi/value.cpp b/gi/value.cpp index bd2def88..d7b12bc5 100644 --- a/gi/value.cpp +++ b/gi/value.cpp @@ -18,6 +18,7 @@ #include <js/Conversions.h> #include <js/Exception.h> #include <js/GCVector.h> // for RootedVector +#include <js/PropertyAndElement.h> #include <js/Realm.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h index 0b87f7cd..16c55f11 100644 --- a/gi/wrapperutils.h +++ b/gi/wrapperutils.h @@ -22,9 +22,10 @@ #include <js/Id.h> #include <js/MemoryFunctions.h> #include <js/Object.h> +#include <js/PropertyAndElement.h> // for JS_DefineFunctionById #include <js/RootingAPI.h> #include <js/TypeDecls.h> -#include <jsapi.h> // for JS_GetPrototype, JS_DefineFunctionById +#include <jsapi.h> // for JS_GetPrototype #include <jspubtd.h> // for JSProto_TypeError #include "gi/arg-inl.h" @@ -394,7 +395,7 @@ class GIWrapperBase : public CWrapperPointerOps<Base> { * necessary to include a finalize_impl() function in Prototype or Instance. * Any needed finalization should be done in ~Prototype() and ~Instance(). */ - static void finalize(JSFreeOp* fop, JSObject* obj) { + static void finalize(JS::GCContext* gcx, JSObject* obj) { Base* priv = Base::for_js_nocheck(obj); if (!priv) return; // construction didn't finish @@ -404,9 +405,9 @@ class GIWrapperBase : public CWrapperPointerOps<Base> { static_cast<GIWrapperBase*>(priv)->debug_lifecycle(obj, "Finalize"); if (priv->is_prototype()) - priv->to_prototype()->finalize_impl(fop, obj); + priv->to_prototype()->finalize_impl(gcx, obj); else - priv->to_instance()->finalize_impl(fop, obj); + priv->to_instance()->finalize_impl(gcx, obj); Base::unset_private(obj); } @@ -1012,7 +1013,7 @@ class GIWrapperPrototype : public Base { // JSClass operations protected: - void finalize_impl(JSFreeOp*, JSObject*) { release(); } + void finalize_impl(JS::GCContext*, JSObject*) { release(); } // Override if necessary void trace_impl(JSTracer*) {} @@ -1107,7 +1108,7 @@ class GIWrapperInstance : public Base { // JSClass operations protected: - void finalize_impl(JSFreeOp*, JSObject*) { + void finalize_impl(JS::GCContext*, JSObject*) { delete static_cast<Instance*>(this); } diff --git a/gjs/atoms.cpp b/gjs/atoms.cpp index 6cb04f89..46dae144 100644 --- a/gjs/atoms.cpp +++ b/gjs/atoms.cpp @@ -31,7 +31,7 @@ bool GjsSymbolAtom::init(JSContext* cx, const char* str) { JS::Symbol* symbol = JS::NewSymbol(cx, descr); if (!symbol) return false; - m_jsid = JS::Heap<jsid>{SYMBOL_TO_JSID(symbol)}; + m_jsid = JS::Heap<jsid>{JS::PropertyKey::Symbol(symbol)}; return true; } diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp index 455075fa..e0b7a03b 100644 --- a/gjs/byteArray.cpp +++ b/gjs/byteArray.cpp @@ -11,12 +11,13 @@ #include <js/ArrayBuffer.h> #include <js/CallArgs.h> +#include <js/PropertyAndElement.h> #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/experimental/TypedData.h> -#include <jsapi.h> // for JS_DefineFunctionById, JS_DefineFun... +#include <jsapi.h> // for JS_NewPlainObject #include "gi/boxed.h" #include "gjs/atoms.h" diff --git a/gjs/context.cpp b/gjs/context.cpp index a9dde93d..8bbebf84 100644 --- a/gjs/context.cpp +++ b/gjs/context.cpp @@ -36,6 +36,7 @@ #endif #include <js/AllocPolicy.h> // for SystemAllocPolicy +#include <js/CallAndConstruct.h> // for Call, JS_CallFunctionValue #include <js/CallArgs.h> // for UndefinedHandleValue #include <js/CharacterEncoding.h> #include <js/CompilationAndEvaluation.h> @@ -46,12 +47,15 @@ #include <js/GCAPI.h> // for JS_GC, JS_AddExtraGCRootsTr... #include <js/GCHashTable.h> // for WeakCache #include <js/GCVector.h> // for RootedVector +#include <js/GlobalObject.h> // for CurrentGlobalOrNull #include <js/Id.h> #include <js/Modules.h> #include <js/Promise.h> // for JobQueue::SavedJobQueue +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT, JSPROP_RE... #include <js/Realm.h> #include <js/RootingAPI.h> +#include <js/ScriptPrivate.h> #include <js/SourceText.h> #include <js/TracingAPI.h> #include <js/TypeDecls.h> @@ -59,7 +63,7 @@ #include <js/Value.h> #include <js/ValueArray.h> #include <js/friend/DumpFunctions.h> -#include <jsapi.h> // for Call, CurrentGlobalOrNull +#include <jsapi.h> // for JS_GetFunctionObject, JS_Ge... #include <jsfriendapi.h> // for ScriptEnvironmentPreparer #include <mozilla/UniquePtr.h> diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp index 7dcc20db..487268d4 100644 --- a/gjs/coverage.cpp +++ b/gjs/coverage.cpp @@ -14,6 +14,7 @@ #include <glib-object.h> #include <js/GCAPI.h> // for JS_AddExtraGCRootsTracer, JS_Remove... +#include <js/PropertyAndElement.h> #include <js/Realm.h> #include <js/RootingAPI.h> #include <js/TracingAPI.h> @@ -21,7 +22,7 @@ #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/experimental/CodeCoverage.h> // for EnableCodeCoverage -#include <jsapi.h> // for JS_SetPropertyById +#include <jsapi.h> // for JS_WrapObject #include "gjs/atoms.h" #include "gjs/context-private.h" diff --git a/gjs/debugger.cpp b/gjs/debugger.cpp index 310fa384..43982e10 100644 --- a/gjs/debugger.cpp +++ b/gjs/debugger.cpp @@ -15,6 +15,7 @@ #include <glib.h> #include <js/CallArgs.h> +#include <js/PropertyAndElement.h> #include <js/PropertySpec.h> #include <js/Realm.h> #include <js/RootingAPI.h> @@ -22,7 +23,7 @@ #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> -#include <jsapi.h> // for JS_DefineFunctions, JS_SetPropertyById +#include <jsapi.h> // for JS_WrapObject #include "gjs/atoms.h" #include "gjs/context-private.h" diff --git a/gjs/deprecation.cpp b/gjs/deprecation.cpp index f51e9880..c0382d59 100644 --- a/gjs/deprecation.cpp +++ b/gjs/deprecation.cpp @@ -16,11 +16,11 @@ #include <js/CharacterEncoding.h> #include <js/Conversions.h> #include <js/RootingAPI.h> +#include <js/Stack.h> // for CaptureCurrentStack, MaxFrames #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/friend/DumpFunctions.h> -#include <jsapi.h> // for MaxFrames, CaptureCurrentStack #include "gjs/deprecation.h" #include "gjs/macros.h" diff --git a/gjs/engine.cpp b/gjs/engine.cpp index 16d84cc1..d0f05e7d 100644 --- a/gjs/engine.cpp +++ b/gjs/engine.cpp @@ -21,10 +21,11 @@ #include <js/Initialization.h> // for JS_Init, JS_ShutDown #include <js/Promise.h> #include <js/RootingAPI.h> +#include <js/Stack.h> // for JS_SetNativeStackQuota #include <js/TypeDecls.h> #include <js/Warnings.h> #include <js/experimental/SourceHook.h> -#include <jsapi.h> // for InitSelfHostedCode, JS_Destr... +#include <jsapi.h> // for JS_SetGlobalJitCompilerOption #include <mozilla/UniquePtr.h> #include "gjs/context-private.h" @@ -32,7 +33,7 @@ #include "gjs/jsapi-util.h" #include "util/log.h" -static void gjs_finalize_callback(JSFreeOp*, JSFinalizeStatus status, +static void gjs_finalize_callback(JS::GCContext*, JSFinalizeStatus status, void* data) { auto* gjs = static_cast<GjsContextPrivate*>(data); gjs->set_finalize_status(status); @@ -167,12 +168,7 @@ JSContext* gjs_create_js_context(GjsContextPrivate* uninitialized_gjs) { if (enable_jit) { gjs_debug(GJS_DEBUG_CONTEXT, "Enabling JIT"); } - JS::ContextOptionsRef(cx) - .setAsmJS(enable_jit) - .setTopLevelAwait(true) - .setClassStaticBlocks(true) - .setPrivateClassFields(true) - .setPrivateClassMethods(true); + JS::ContextOptionsRef(cx).setAsmJS(enable_jit); uint32_t value = enable_jit ? 1 : 0; diff --git a/gjs/gjs_pch.hh b/gjs/gjs_pch.hh index d4a820ff..f8d5c915 100644 --- a/gjs/gjs_pch.hh +++ b/gjs/gjs_pch.hh @@ -53,6 +53,7 @@ #include <js/Array.h> #include <js/ArrayBuffer.h> #include <js/BigInt.h> +#include <js/CallAndConstruct.h> #include <js/CallArgs.h> #include <js/CharacterEncoding.h> #include <js/Class.h> @@ -62,12 +63,14 @@ #include <js/Context.h> #include <js/ContextOptions.h> #include <js/Conversions.h> +#include <js/Debug.h> #include <js/ErrorReport.h> #include <js/Exception.h> #include <js/GCAPI.h> #include <js/GCHashTable.h> #include <js/GCPolicyAPI.h> #include <js/GCVector.h> +#include <js/GlobalObject.h> #include <js/HashTable.h> #include <js/HeapAPI.h> #include <js/Id.h> @@ -79,13 +82,16 @@ #include <js/ProfilingCategory.h> #include <js/ProfilingStack.h> #include <js/Promise.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> #include <js/PropertySpec.h> #include <js/Realm.h> #include <js/RealmOptions.h> #include <js/RootingAPI.h> #include <js/SavedFrameAPI.h> +#include <js/ScriptPrivate.h> #include <js/SourceText.h> +#include <js/Stack.h> #include <js/String.h> #include <js/Symbol.h> #include <js/TracingAPI.h> diff --git a/gjs/global.cpp b/gjs/global.cpp index 9c2c91eb..84addc1b 100644 --- a/gjs/global.cpp +++ b/gjs/global.cpp @@ -16,9 +16,12 @@ #include <js/Class.h> #include <js/CompilationAndEvaluation.h> #include <js/CompileOptions.h> +#include <js/Debug.h> // for JS_DefineDebuggerObject +#include <js/GlobalObject.h> // for CurrentGlobalOrNull, JS_NewGlobalObject #include <js/Id.h> #include <js/MapAndSet.h> #include <js/Object.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_PERMANENT, JSPROP_RE... #include <js/PropertySpec.h> #include <js/Realm.h> // for GetObjectRealmOrNull, SetRealmPrivate @@ -27,7 +30,7 @@ #include <js/SourceText.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars -#include <jsapi.h> // for AutoSaveExceptionState, ... +#include <jsapi.h> // for JS_IdToValue, JS_InitReflectParse #include "gjs/atoms.h" #include "gjs/context-private.h" diff --git a/gjs/importer.cpp b/gjs/importer.cpp index 78e21e2e..0e64b5d4 100644 --- a/gjs/importer.cpp +++ b/gjs/importer.cpp @@ -24,8 +24,10 @@ #include <js/ComparisonOperators.h> #include <js/ErrorReport.h> // for JS_ReportOutOfMemory #include <js/Exception.h> +#include <js/GlobalObject.h> // for CurrentGlobalOrNull #include <js/Id.h> // for PropertyKey #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> #include <js/PropertySpec.h> #include <js/RootingAPI.h> @@ -34,7 +36,7 @@ #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> -#include <jsapi.h> // for JS_DefinePropertyById, JS_DefineP... +#include <jsapi.h> // for JS_NewPlainObject, IdVector, JS_... #include <jspubtd.h> // for JSProto_Error #include <mozilla/Maybe.h> #include <mozilla/UniquePtr.h> @@ -172,9 +174,9 @@ define_meta_properties(JSContext *context, module_path, attrs)) return false; - JS::RootedId to_string_tag_name(context, - SYMBOL_TO_JSID(JS::GetWellKnownSymbol(context, - JS::SymbolCode::toStringTag))); + JS::RootedId to_string_tag_name( + context, JS::PropertyKey::Symbol(JS::GetWellKnownSymbol( + context, JS::SymbolCode::toStringTag))); return JS_DefinePropertyById(context, module_obj, to_string_tag_name, to_string_tag, attrs); } diff --git a/gjs/internal.cpp b/gjs/internal.cpp index 9ffe4813..414d9375 100644 --- a/gjs/internal.cpp +++ b/gjs/internal.cpp @@ -14,6 +14,7 @@ #include <glib-object.h> #include <glib.h> +#include <js/CallAndConstruct.h> // for JS_CallFunction #include <js/CallArgs.h> #include <js/CharacterEncoding.h> #include <js/CompilationAndEvaluation.h> @@ -22,6 +23,7 @@ #include <js/GCAPI.h> // for JS_AddExtraGCRootsTracer #include <js/Modules.h> #include <js/Promise.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> #include <js/Realm.h> #include <js/RootingAPI.h> @@ -32,8 +34,8 @@ #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_DefinePropertyById, ... -#include <jsfriendapi.h> +#include <jsapi.h> // for JS_NewPlainObject, JS_ObjectIsFunction +#include <jsfriendapi.h> // for JS_GetObjectFunction, SetFunctionNativeReserved #include <jspubtd.h> // for JSProto_Error #include "gjs/context-private.h" diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp index b36c0bf8..2bc4823c 100644 --- a/gjs/jsapi-dynamic-class.cpp +++ b/gjs/jsapi-dynamic-class.cpp @@ -9,16 +9,18 @@ #include <glib.h> +#include <js/CallAndConstruct.h> #include <js/CallArgs.h> // for JSNative #include <js/Class.h> #include <js/ComparisonOperators.h> #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> // for JS_DefineFunctions, JS_DefinePro... #include <js/Realm.h> // for GetRealmObjectPrototype #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Value.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_DefineFunctions, JS_DefineProp... +#include <jsapi.h> // for JS_GetFunctionObject, JS_GetPrototype #include <jsfriendapi.h> // for GetFunctionNativeReserved, NewFun... #include <jspubtd.h> // for JSProto_TypeError diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp index c003904b..80074333 100644 --- a/gjs/jsapi-util-error.cpp +++ b/gjs/jsapi-util-error.cpp @@ -9,17 +9,20 @@ #include <glib.h> #include <js/AllocPolicy.h> +#include <js/CallAndConstruct.h> #include <js/CharacterEncoding.h> #include <js/ErrorReport.h> #include <js/Exception.h> #include <js/GCHashTable.h> // for GCHashSet #include <js/HashTable.h> // for DefaultHasher +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> +#include <js/Stack.h> // for BuildStackString #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/ValueArray.h> -#include <jsapi.h> // for BuildStackString, Construct, JS_GetClassObject -#include <jspubtd.h> // for JSProtoKey, JSProto_Error, JSProto... +#include <jsapi.h> // for JS_GetClassObject +#include <jspubtd.h> // for JSProtoKey, JSProto_Error, JSProto... #include <mozilla/HashTable.h> // for HashSet<>::AddPtr #include "gjs/atoms.h" diff --git a/gjs/jsapi-util-root.h b/gjs/jsapi-util-root.h index 7f4e2749..80f4d875 100644 --- a/gjs/jsapi-util-root.h +++ b/gjs/jsapi-util-root.h @@ -62,8 +62,9 @@ struct GjsHeapOperation { template<> struct GjsHeapOperation<JSObject *> { - [[nodiscard]] static bool update_after_gc(JS::Heap<JSObject*>* location) { - JS_UpdateWeakPointerAfterGC(location); + [[nodiscard]] static bool update_after_gc(JSTracer* trc, + JS::Heap<JSObject*>* location) { + JS_UpdateWeakPointerAfterGC(trc, location); return (location->unbarrieredGet() == nullptr); } @@ -178,7 +179,7 @@ class GjsMaybeOwned { void root(JSContext* cx, const T& thing) { debug("root()"); g_assert(!m_root); - g_assert(m_heap.get() == JS::SafelyInitialized<T>()); + g_assert(m_heap.get() == JS::SafelyInitialized<T>::create()); m_heap.~Heap(); m_root = std::make_unique<JS::PersistentRooted<T>>(cx, thing); } @@ -204,7 +205,7 @@ class GjsMaybeOwned { void reset() { debug("reset()"); if (!m_root) { - m_heap = JS::SafelyInitialized<T>(); + m_heap = JS::SafelyInitialized<T>::create(); return; } @@ -251,10 +252,10 @@ class GjsMaybeOwned { /* If not tracing, then you must call this method during GC in order to * update the object's location if it was moved, or null it out if it was * finalized. If the object was finalized, returns true. */ - bool update_after_gc() { + bool update_after_gc(JSTracer* trc) { debug("update_after_gc()"); g_assert(!m_root); - return GjsHeapOperation<T>::update_after_gc(&m_heap); + return GjsHeapOperation<T>::update_after_gc(trc, &m_heap); } [[nodiscard]] constexpr bool rooted() const { return m_root != nullptr; } diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp index 29e56c9e..fcef285f 100644 --- a/gjs/jsapi-util-string.cpp +++ b/gjs/jsapi-util-string.cpp @@ -438,7 +438,7 @@ bool gjs_get_string_id(JSContext* cx, jsid id, JS::UniqueChars* name_p) { return true; } - JSLinearString* lstr = JSID_TO_LINEAR_STRING(id); + JSLinearString* lstr = id.toLinearString(); JS::RootedString s(cx, JS_FORGET_STRING_LINEARNESS(lstr)); *name_p = JS_EncodeStringToUTF8(cx, s); return !!*name_p; @@ -475,7 +475,7 @@ gjs_intern_string_to_id(JSContext *cx, { JS::RootedString str(cx, JS_AtomizeAndPinString(cx, string)); if (!str) - return JSID_VOID; + return JS::PropertyKey::Void(); return JS::PropertyKey::fromPinnedString(str); } @@ -662,6 +662,6 @@ std::string gjs_debug_id(jsid id) { if (id.isString()) - return gjs_debug_linear_string(JSID_TO_LINEAR_STRING(id), NoQuotes); + return gjs_debug_linear_string(id.toLinearString(), NoQuotes); return gjs_debug_value(js::IdToValue(id)); } diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp index 3acb6642..7dc86fe8 100644 --- a/gjs/jsapi-util.cpp +++ b/gjs/jsapi-util.cpp @@ -30,12 +30,14 @@ #include <js/GCVector.h> // for RootedVector #include <js/HashTable.h> // for DefaultHasher #include <js/Object.h> // for GetClass +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> +#include <js/Stack.h> // for BuildStackString #include <js/String.h> #include <js/TypeDecls.h> #include <js/Value.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_GetPropertyById, JS_InstanceOf +#include <jsapi.h> // for JS_InstanceOf #include <jsfriendapi.h> // for ProtoKeyToClass #include <mozilla/HashTable.h> // for HashSet::AddPtr diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h index a891fa42..0724181e 100644 --- a/gjs/jsapi-util.h +++ b/gjs/jsapi-util.h @@ -26,10 +26,8 @@ #include <js/GCAPI.h> #include <js/GCPolicyAPI.h> // for IgnoreGCPolicy #include <js/Id.h> -#include <js/Object.h> // for GetReservedSlot #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars -#include <js/Value.h> #include <jspubtd.h> // for JSProtoKey #include "gjs/macros.h" @@ -636,18 +634,6 @@ template <typename T> return true; } -/** - * Helper function, backported from future SpiderMonkey's - * JS::GetMaybePtrFromReservedSlot(), to get the pointer value (or nullptr if - * not set) from an object's reserved slot. The slot must contain either a - * JS::PrivateValue(T*) or JS::UndefinedValue. - */ -template <typename T> -inline T* maybe_get_private(JSObject* obj, size_t slot) { - JS::Value v = JS::GetReservedSlot(obj, slot); - return v.isUndefined() ? nullptr : static_cast<T*>(v.toPrivate()); -} - } // namespace Gjs [[nodiscard]] const char* gjs_explain_gc_reason(JS::GCReason reason); diff --git a/gjs/module.cpp b/gjs/module.cpp index c8d4b21c..c0422caf 100644 --- a/gjs/module.cpp +++ b/gjs/module.cpp @@ -12,6 +12,7 @@ #include <gio/gio.h> #include <glib.h> +#include <js/CallAndConstruct.h> #include <js/CallArgs.h> #include <js/CharacterEncoding.h> // for ConstUTF8CharsZ #include <js/Class.h> @@ -21,21 +22,24 @@ #include <js/ErrorReport.h> // for JS_ReportOutOfMemory #include <js/Exception.h> #include <js/GCVector.h> // for RootedVector +#include <js/GlobalObject.h> // for CurrentGlobalOrNull #include <js/Id.h> #include <js/Modules.h> #include <js/Object.h> #include <js/Promise.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> #include <js/Realm.h> #include <js/RootingAPI.h> +#include <js/ScriptPrivate.h> #include <js/SourceText.h> #include <js/String.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/ValueArray.h> -#include <jsapi.h> // for JS_DefinePropertyById, ... -#include <jsfriendapi.h> // for SetFunctionNativeReserved +#include <jsapi.h> // for JS_GetFunctionObject, JS_Ne... +#include <jsfriendapi.h> // for NewFunctionWithReserved #include <mozilla/Maybe.h> #include "gjs/atoms.h" @@ -76,7 +80,7 @@ class GjsScriptModule { /* Private data accessors */ [[nodiscard]] static inline GjsScriptModule* priv(JSObject* module) { - return Gjs::maybe_get_private<GjsScriptModule>( + return JS::GetMaybePtrFromReservedSlot<GjsScriptModule>( module, GjsScriptModule::POINTER); } @@ -216,7 +220,9 @@ class GjsScriptModule { return priv(module)->resolve_impl(cx, module, id, resolved); } - static void finalize(JSFreeOp*, JSObject* module) { delete priv(module); } + static void finalize(JS::GCContext*, JSObject* module) { + delete priv(module); + } static constexpr JSClassOps class_ops = { nullptr, // addProperty diff --git a/gjs/promise.cpp b/gjs/promise.cpp index 0ce4bd7c..74127960 100644 --- a/gjs/promise.cpp +++ b/gjs/promise.cpp @@ -10,10 +10,11 @@ #include <glib-object.h> #include <js/CallArgs.h> +#include <js/PropertyAndElement.h> // for JS_DefineFunctions #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> -#include <jsapi.h> // for JS_DefineFunctions, JS_NewPlainObject +#include <jsapi.h> // for JS_NewPlainObject #include "gjs/context-private.h" #include "gjs/jsapi-util.h" diff --git a/gjs/text-encoding.cpp b/gjs/text-encoding.cpp index e9010023..95a6f86c 100644 --- a/gjs/text-encoding.cpp +++ b/gjs/text-encoding.cpp @@ -26,6 +26,7 @@ #include <js/ErrorReport.h> // for JS_ReportOutOfMemory #include <js/Exception.h> // for JS_ClearPendingException, JS_... #include <js/GCAPI.h> // for AutoCheckCannotGC +#include <js/PropertyAndElement.h> #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/String.h> @@ -33,7 +34,7 @@ #include <js/Utility.h> // for UniqueChars #include <js/Value.h> #include <js/experimental/TypedData.h> -#include <jsapi.h> // for JS_DefineFunctionById, JS_DefineFun... +#include <jsapi.h> // for JS_NewPlainObject, JS_InstanceOf #include <jsfriendapi.h> // for ProtoKeyToClass #include <jspubtd.h> // for JSProto_TypeError, JSProto_InternalError #include <mozilla/Maybe.h> diff --git a/meson.build b/meson.build index add390ec..55356a9c 100644 --- a/meson.build +++ b/meson.build @@ -127,7 +127,7 @@ gio = dependency('gio-2.0', version: glib_required_version, ffi = dependency('libffi', fallback: ['libffi', 'ffi_dep']) gi = dependency('gobject-introspection-1.0', version: '>= 1.66.0', fallback: ['gobject-introspection', 'girepo_dep']) -spidermonkey = dependency('mozjs-91', version: '>= 91.3.0') +spidermonkey = dependency('mozjs-102') # We might need to look for the headers and lib's for Cairo # manually on MSVC/clang-cl builds... diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp index 356ba456..b777fb29 100644 --- a/modules/cairo-context.cpp +++ b/modules/cairo-context.cpp @@ -13,13 +13,14 @@ #include <js/Array.h> // for JS::NewArrayObject #include <js/CallArgs.h> #include <js/Conversions.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_READONLY #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> -#include <jsapi.h> // for JS_SetElement +#include <jsapi.h> // for JS_NewPlainObject #include "gi/arg-inl.h" #include "gi/arg.h" @@ -260,7 +261,7 @@ cairo_t* CairoContext::constructor_impl(JSContext* context, return cr; } -void CairoContext::finalize_impl(JSFreeOp*, cairo_t* cr) { +void CairoContext::finalize_impl(JS::GCContext*, cairo_t* cr) { if (!cr) return; cairo_destroy(cr); diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp index 415fcf2e..b6b0726c 100644 --- a/modules/cairo-path.cpp +++ b/modules/cairo-path.cpp @@ -11,7 +11,7 @@ #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> -#include <jsapi.h> +#include <jsapi.h> // for JS_NewObjectWithGivenProto #include "modules/cairo-private.h" @@ -43,7 +43,7 @@ JSObject* CairoPath::take_c_ptr(JSContext* cx, cairo_path_t* ptr) { return wrapper; } -void CairoPath::finalize_impl(JSFreeOp*, cairo_path_t* path) { +void CairoPath::finalize_impl(JS::GCContext*, cairo_path_t* path) { if (!path) return; cairo_path_destroy(path); diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp index a9254184..9e7e3692 100644 --- a/modules/cairo-pattern.cpp +++ b/modules/cairo-pattern.cpp @@ -65,14 +65,13 @@ const JSFunctionSpec CairoPattern::proto_funcs[] = { /** * CairoPattern::finalize_impl: - * @fop: the free op * @pattern: pointer to free * * Destroys the resources associated with a pattern wrapper. * * This is mainly used for subclasses. */ -void CairoPattern::finalize_impl(JSFreeOp*, cairo_pattern_t* pattern) { +void CairoPattern::finalize_impl(JS::GCContext*, cairo_pattern_t* pattern) { if (!pattern) return; cairo_pattern_destroy(pattern); @@ -137,6 +136,6 @@ cairo_pattern_t* CairoPattern::for_js(JSContext* cx, return nullptr; } - return Gjs::maybe_get_private<cairo_pattern_t>(pattern_wrapper, - CairoPattern::POINTER); + return JS::GetMaybePtrFromReservedSlot<cairo_pattern_t>( + pattern_wrapper, CairoPattern::POINTER); } diff --git a/modules/cairo-private.h b/modules/cairo-private.h index 8e17c83e..75d111c5 100644 --- a/modules/cairo-private.h +++ b/modules/cairo-private.h @@ -55,7 +55,7 @@ class CairoRegion : public CWrapper<CairoRegion, cairo_region_t> { static cairo_region_t* constructor_impl(JSContext* cx, const JS::CallArgs& args); - static void finalize_impl(JSFreeOp* fop, cairo_region_t* cr); + static void finalize_impl(JS::GCContext*, cairo_region_t* cr); static const JSFunctionSpec proto_funcs[]; static const JSPropertySpec proto_props[]; @@ -95,7 +95,7 @@ class CairoContext : public CWrapper<CairoContext, cairo_t> { GJS_JSAPI_RETURN_CONVENTION static cairo_t* constructor_impl(JSContext* cx, const JS::CallArgs& args); - static void finalize_impl(JSFreeOp* fop, cairo_t* cr); + static void finalize_impl(JS::GCContext*, cairo_t* cr); static const JSFunctionSpec proto_funcs[]; static const JSPropertySpec proto_props[]; @@ -133,7 +133,7 @@ class CairoPath : public CWrapper<CairoPath, cairo_path_t> { GjsGlobalSlot::PROTOTYPE_cairo_path; static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO; - static void finalize_impl(JSFreeOp* fop, cairo_path_t* path); + static void finalize_impl(JS::GCContext*, cairo_path_t* path); static const JSPropertySpec proto_props[]; static constexpr js::ClassSpec class_spec = { @@ -174,7 +174,7 @@ class CairoSurface : public CWrapper<CairoSurface, cairo_surface_t> { static GType gtype() { return CAIRO_GOBJECT_TYPE_SURFACE; } - static void finalize_impl(JSFreeOp* fop, cairo_surface_t* surface); + static void finalize_impl(JS::GCContext*, cairo_surface_t* surface); static const JSFunctionSpec proto_funcs[]; static const JSPropertySpec proto_props[]; @@ -240,7 +240,7 @@ class CairoImageSurface : public CWrapper<CairoImageSurface, cairo_surface_t> { return cairo_surface_reference(surface); } - static void finalize_impl(JSFreeOp*, cairo_surface_t*) {} + static void finalize_impl(JS::GCContext*, cairo_surface_t*) {} GJS_JSAPI_RETURN_CONVENTION static cairo_surface_t* constructor_impl(JSContext* cx, @@ -280,7 +280,7 @@ class CairoPSSurface : public CWrapper<CairoPSSurface, cairo_surface_t> { return cairo_surface_reference(surface); } - static void finalize_impl(JSFreeOp*, cairo_surface_t*) {} + static void finalize_impl(JS::GCContext*, cairo_surface_t*) {} GJS_JSAPI_RETURN_CONVENTION static cairo_surface_t* constructor_impl(JSContext* cx, @@ -326,7 +326,7 @@ class CairoPDFSurface : public CWrapper<CairoPDFSurface, cairo_surface_t> { return cairo_surface_reference(surface); } - static void finalize_impl(JSFreeOp*, cairo_surface_t*) {} + static void finalize_impl(JS::GCContext*, cairo_surface_t*) {} GJS_JSAPI_RETURN_CONVENTION static cairo_surface_t* constructor_impl(JSContext* cx, @@ -372,7 +372,7 @@ class CairoSVGSurface : public CWrapper<CairoSVGSurface, cairo_surface_t> { return cairo_surface_reference(surface); } - static void finalize_impl(JSFreeOp*, cairo_surface_t*) {} + static void finalize_impl(JS::GCContext*, cairo_surface_t*) {} GJS_JSAPI_RETURN_CONVENTION static cairo_surface_t* constructor_impl(JSContext* cx, @@ -430,7 +430,7 @@ class CairoPattern : public CWrapper<CairoPattern, cairo_pattern_t> { static bool getType_func(JSContext* context, unsigned argc, JS::Value* vp); protected: - static void finalize_impl(JSFreeOp* fop, cairo_pattern_t* pattern); + static void finalize_impl(JS::GCContext*, cairo_pattern_t* pattern); public: static cairo_pattern_t* for_js(JSContext* cx, @@ -469,7 +469,7 @@ class CairoGradient : public CWrapper<CairoGradient, cairo_pattern_t> { "Gradient", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE, &CairoPattern::class_ops, &CairoGradient::class_spec}; - static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {} + static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {} }; class CairoLinearGradient @@ -509,7 +509,7 @@ class CairoLinearGradient static cairo_pattern_t* constructor_impl(JSContext* cx, const JS::CallArgs& args); - static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {} + static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {} }; class CairoRadialGradient @@ -549,7 +549,7 @@ class CairoRadialGradient static cairo_pattern_t* constructor_impl(JSContext* cx, const JS::CallArgs& args); - static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {} + static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {} }; class CairoSurfacePattern @@ -589,7 +589,7 @@ class CairoSurfacePattern static cairo_pattern_t* constructor_impl(JSContext* cx, const JS::CallArgs& args); - static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {} + static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {} }; class CairoSolidPattern : public CWrapper<CairoSolidPattern, cairo_pattern_t> { @@ -623,7 +623,7 @@ class CairoSolidPattern : public CWrapper<CairoSolidPattern, cairo_pattern_t> { return cairo_pattern_reference(pattern); } - static void finalize_impl(JSFreeOp*, cairo_pattern_t*) {} + static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {} }; #endif // MODULES_CAIRO_PRIVATE_H_ diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp index a6333f77..2490dabc 100644 --- a/modules/cairo-region.cpp +++ b/modules/cairo-region.cpp @@ -9,12 +9,13 @@ #include <js/CallArgs.h> #include <js/Conversions.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_READONLY #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Value.h> -#include <jsapi.h> // for JS_GetPropertyById, JS_SetPropert... +#include <jsapi.h> // for JS_NewPlainObject #include "gi/arg-inl.h" #include "gi/arg.h" @@ -219,7 +220,7 @@ cairo_region_t* CairoRegion::constructor_impl(JSContext* context, return cairo_region_create(); } -void CairoRegion::finalize_impl(JSFreeOp*, cairo_region_t* region) { +void CairoRegion::finalize_impl(JS::GCContext*, cairo_region_t* region) { if (!region) return; diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp index 51661c3c..87718643 100644 --- a/modules/cairo-surface.cpp +++ b/modules/cairo-surface.cpp @@ -207,14 +207,13 @@ const JSFunctionSpec CairoSurface::proto_funcs[] = { /** * CairoSurface::finalize_impl: - * @fop: the free op * @surface: the pointer to finalize * * Destroys the resources associated with a surface wrapper. * * This is mainly used for subclasses. */ -void CairoSurface::finalize_impl(JSFreeOp*, cairo_surface_t* surface) { +void CairoSurface::finalize_impl(JS::GCContext*, cairo_surface_t* surface) { if (!surface) return; cairo_surface_destroy(surface); @@ -272,8 +271,8 @@ cairo_surface_t* CairoSurface::for_js(JSContext* cx, return nullptr; } - return Gjs::maybe_get_private<cairo_surface_t>(surface_wrapper, - CairoSurface::POINTER); + return JS::GetMaybePtrFromReservedSlot<cairo_surface_t>( + surface_wrapper, CairoSurface::POINTER); } [[nodiscard]] static bool surface_to_g_argument( diff --git a/modules/console.cpp b/modules/console.cpp index 33c189f9..228ee413 100644 --- a/modules/console.cpp +++ b/modules/console.cpp @@ -27,12 +27,14 @@ #include <glib.h> #include <glib/gprintf.h> // for g_fprintf +#include <js/CallAndConstruct.h> #include <js/CallArgs.h> #include <js/CharacterEncoding.h> // for JS_EncodeStringToUTF8 #include <js/CompilationAndEvaluation.h> #include <js/CompileOptions.h> #include <js/ErrorReport.h> #include <js/Exception.h> +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> #include <js/SourceText.h> #include <js/TypeDecls.h> @@ -40,7 +42,7 @@ #include <js/Value.h> #include <js/ValueArray.h> #include <js/Warnings.h> -#include <jsapi.h> // for JS_IsExceptionPending, Exce... +#include <jsapi.h> // for JS_NewPlainObject #include "gjs/atoms.h" #include "gjs/context-private.h" diff --git a/modules/print.cpp b/modules/print.cpp index e483446c..7e0504f8 100644 --- a/modules/print.cpp +++ b/modules/print.cpp @@ -13,12 +13,13 @@ #include <js/CharacterEncoding.h> // for JS_EncodeStringToUTF8 #include <js/Conversions.h> #include <js/Exception.h> +#include <js/PropertyAndElement.h> // for JS_DefineFunctions #include <js/PropertySpec.h> // for JS_FN, JSFunctionSpec, JS_FS_END #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> -#include <jsapi.h> +#include <jsapi.h> // for JS_NewPlainObject #include "gjs/global.h" #include "gjs/jsapi-util.h" diff --git a/modules/system.cpp b/modules/system.cpp index 0f441096..9c43830e 100644 --- a/modules/system.cpp +++ b/modules/system.cpp @@ -18,13 +18,14 @@ #include <js/Date.h> // for ResetTimeZone #include <js/GCAPI.h> // for JS_GC #include <js/JSON.h> +#include <js/PropertyAndElement.h> #include <js/PropertyDescriptor.h> // for JSPROP_READONLY #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/TypeDecls.h> #include <js/Value.h> // for NullValue #include <js/friend/DumpFunctions.h> -#include <jsapi.h> // for JS_DefinePropertyById, JS_DefineF... +#include <jsapi.h> // for JS_GetFunctionObject, JS_NewPlainObject #include <jsfriendapi.h> // for GetFunctionNativeReserved, NewFunctionByIdW... #include "gi/object.h" diff --git a/test/gjs-test-call-args.cpp b/test/gjs-test-call-args.cpp index fccd9c22..15454d2d 100644 --- a/test/gjs-test-call-args.cpp +++ b/test/gjs-test-call-args.cpp @@ -11,13 +11,13 @@ #include <js/CallArgs.h> #include <js/CompilationAndEvaluation.h> #include <js/CompileOptions.h> +#include <js/PropertyAndElement.h> #include <js/PropertySpec.h> #include <js/RootingAPI.h> #include <js/SourceText.h> #include <js/String.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars -#include <jsapi.h> // for JS_DefineFunctions #include "gjs/jsapi-util-args.h" #include "gjs/jsapi-util.h" diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp index 077f4508..7a96ba1e 100644 --- a/test/gjs-test-rooting.cpp +++ b/test/gjs-test-rooting.cpp @@ -16,9 +16,10 @@ #include "gjs/context-private.h" #include "gjs/jsapi-util-root.h" -#include "gjs/jsapi-util.h" // for maybe_get_private #include "test/gjs-test-utils.h" +class JSTracer; + // COMPAT: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1553 #ifdef __clang_analyzer__ void g_assertion_message(const char*, const char*, int, const char*, @@ -42,8 +43,8 @@ struct GjsRootingFixture { GjsMaybeOwned<JSObject *> *obj; /* only used in callback test cases */ }; -static void test_obj_finalize(JSFreeOp*, JSObject* obj) { - bool* finalized_p = Gjs::maybe_get_private<bool>(obj, POINTER); +static void test_obj_finalize(JS::GCContext*, JSObject* obj) { + bool* finalized_p = JS::GetMaybePtrFromReservedSlot<bool>(obj, POINTER); g_assert_false(*finalized_p); *finalized_p = true; } @@ -148,10 +149,10 @@ static void test_maybe_owned_rooted_is_collected_after_reset( delete obj; } -static void update_weak_pointer(JSContext*, JS::Compartment*, void* data) { +static void update_weak_pointer(JSTracer* trc, JS::Compartment*, void* data) { auto* obj = static_cast<GjsMaybeOwned<JSObject*>*>(data); if (*obj) - obj->update_after_gc(); + obj->update_after_gc(trc); } static void test_maybe_owned_weak_pointer_is_collected_by_gc( diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp index ecf986fb..49011bba 100644 --- a/test/gjs-tests.cpp +++ b/test/gjs-tests.cpp @@ -21,12 +21,13 @@ #include <js/CharacterEncoding.h> #include <js/Exception.h> #include <js/Id.h> +#include <js/PropertyAndElement.h> #include <js/RootingAPI.h> #include <js/String.h> #include <js/TypeDecls.h> #include <js/Utility.h> // for UniqueChars #include <js/Value.h> -#include <jsapi.h> +#include <jsapi.h> // for JS_GetClassObject #include <jspubtd.h> // for JSProto_Number #include <mozilla/Span.h> // for MakeStringSpan diff --git a/tools/process_iwyu.py b/tools/process_iwyu.py index 6699f4ec..8b70517c 100755 --- a/tools/process_iwyu.py +++ b/tools/process_iwyu.py @@ -40,12 +40,12 @@ FWD_DECLS_IN_HEADER = ( 'struct JSContext;', 'struct JSClass;', 'class JSFunction;', - 'class JSFreeOp;', 'class JSObject;', 'struct JSRuntime;', 'class JSScript;', 'class JSString;', 'namespace js { class TempAllocPolicy; }', + 'namespace JS { class GCContext; }', 'namespace JS { struct PropertyKey; }', 'namespace JS { class Symbol; }', 'namespace JS { class BigInt; }', diff --git a/tools/run_iwyu.sh b/tools/run_iwyu.sh index 047281c0..2b7b87be 100755 --- a/tools/run_iwyu.sh +++ b/tools/run_iwyu.sh @@ -47,7 +47,7 @@ IWYU="python3 $(which iwyu_tool || which iwyu-tool || which iwyu_tool.py) -p ." IWYU_TOOL_ARGS="-I../gjs" IWYU_ARGS="-Wno-pragma-once-outside-header" IWYU_RAW="include-what-you-use -xc++ -std=c++17 -Xiwyu --keep=config.h $IWYU_ARGS" -IWYU_RAW_INC="-I. -I.. $(pkg-config --cflags gobject-introspection-1.0 mozjs-91)" +IWYU_RAW_INC="-I. -I.. $(pkg-config --cflags gobject-introspection-1.0 mozjs-102)" PRIVATE_MAPPING="-Xiwyu --mapping_file=$SRCDIR/tools/gjs-private-iwyu.imp -Xiwyu --keep=config.h" PUBLIC_MAPPING="-Xiwyu --mapping_file=$SRCDIR/tools/gjs-public-iwyu.imp" POSTPROCESS="python3 $SRCDIR/tools/process_iwyu.py" |