diff --git a/js/public/GCPolicyAPI.h b/js/public/GCPolicyAPI.h index 62a7129eb837..6b369f923a74 100644 --- a/js/public/GCPolicyAPI.h +++ b/js/public/GCPolicyAPI.h @@ -54,27 +54,11 @@ #include "mozilla/Maybe.h" #include "mozilla/UniquePtr.h" +#include "js/GCTypeMacros.h" // JS_FOR_EACH_PUBLIC_GC_POINTER_TYPE #include "js/TraceKind.h" #include "js/TracingAPI.h" #include "js/TypeDecls.h" -// Expand the given macro D for each public GC pointer. -#define FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \ - D(JS::Symbol*) \ - D(JS::BigInt*) \ - D(JSAtom*) \ - D(JSFunction*) \ - D(JSObject*) \ - D(JSScript*) \ - D(JSString*) - -// Expand the given macro D for each public tagged GC pointer type. -#define FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(D) \ - D(JS::Value) \ - D(jsid) - -#define FOR_EACH_PUBLIC_AGGREGATE_GC_POINTER_TYPE(D) D(JSPropertyDescriptor) - namespace JS { // Defines a policy for container types with non-GC, i.e. C storage. This @@ -145,7 +129,7 @@ struct GCPointerPolicy { struct GCPolicy : public GCPointerPolicy {}; \ template <> \ struct GCPolicy : public GCPointerPolicy {}; -FOR_EACH_PUBLIC_GC_POINTER_TYPE(EXPAND_SPECIALIZE_GCPOLICY) +JS_FOR_EACH_PUBLIC_GC_POINTER_TYPE(EXPAND_SPECIALIZE_GCPOLICY) #undef EXPAND_SPECIALIZE_GCPOLICY template diff --git a/js/public/GCTypeMacros.h b/js/public/GCTypeMacros.h new file mode 100644 index 000000000000..17d35a318790 --- /dev/null +++ b/js/public/GCTypeMacros.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: set ts=8 sts=2 et sw=2 tw=80: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Higher-order macros enumerating public untagged and tagged GC pointer types. + */ + +#ifndef GCTypeMacros_h +#define GCTypeMacros_h + +#include "jstypes.h" // JS_PUBLIC_API + +class JS_PUBLIC_API JSAtom; +class JS_PUBLIC_API JSFunction; +class JS_PUBLIC_API JSObject; +class JS_PUBLIC_API JSScript; +class JS_PUBLIC_API JSString; + +namespace JS { +class JS_PUBLIC_API BigInt; +struct JS_PUBLIC_API PropertyKey; +class JS_PUBLIC_API Symbol; +class JS_PUBLIC_API Value; +} // namespace JS + +// Expand the given macro D for each public GC pointer. +#define JS_FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \ + D(JS::Symbol*) \ + D(JS::BigInt*) \ + D(JSAtom*) \ + D(JSFunction*) \ + D(JSObject*) \ + D(JSScript*) \ + D(JSString*) + +// Expand the given macro D for each public tagged GC pointer type. +#define JS_FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(D) \ + D(JS::Value) \ + D(JS::PropertyKey) // i.e. jsid + +#endif // GCTypeMacros_h diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index e9753808c0f5..bdb8dbb06f1b 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -20,6 +20,7 @@ #include "js/GCAnnotations.h" #include "js/GCPolicyAPI.h" +#include "js/GCTypeMacros.h" // JS_FOR_EACH_PUBLIC_{,TAGGED_}GC_POINTER_TYPE #include "js/HeapAPI.h" #include "js/ProfilingStack.h" #include "js/Realm.h" @@ -145,8 +146,8 @@ struct IsHeapConstructibleType { struct IsHeapConstructibleType { \ static constexpr bool value = true; \ }; -FOR_EACH_PUBLIC_GC_POINTER_TYPE(DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE) -FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE) +JS_FOR_EACH_PUBLIC_GC_POINTER_TYPE(DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE) +JS_FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE) #undef DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE template diff --git a/js/src/gc/Marking.cpp b/js/src/gc/Marking.cpp index 4d97b0a621b2..6034c021cd31 100644 --- a/js/src/gc/Marking.cpp +++ b/js/src/gc/Marking.cpp @@ -23,6 +23,7 @@ #include "gc/GCInternals.h" #include "gc/Policy.h" #include "jit/IonCode.h" +#include "js/GCTypeMacros.h" // JS_FOR_EACH_PUBLIC_{,TAGGED_}GC_POINTER_TYPE #include "js/SliceBudget.h" #include "util/DiagnosticAssertions.h" #include "util/Memory.h" @@ -461,8 +462,8 @@ class AbstractGeneratorObject; JSTracer*, type*, const char*); \ template JS_PUBLIC_API void js::gc::TraceExternalEdge( \ JSTracer*, type*, const char*); -FOR_EACH_PUBLIC_GC_POINTER_TYPE(INSTANTIATE_PUBLIC_TRACE_FUNCTIONS) -FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(INSTANTIATE_PUBLIC_TRACE_FUNCTIONS) +JS_FOR_EACH_PUBLIC_GC_POINTER_TYPE(INSTANTIATE_PUBLIC_TRACE_FUNCTIONS) +JS_FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(INSTANTIATE_PUBLIC_TRACE_FUNCTIONS) INSTANTIATE_PUBLIC_TRACE_FUNCTIONS(SavedFrame*); INSTANTIATE_PUBLIC_TRACE_FUNCTIONS(AbstractGeneratorObject*); #undef INSTANTIATE_PUBLIC_TRACE_FUNCTIONS @@ -479,7 +480,7 @@ namespace gc { INSTANTIATE_INTERNAL_TRACE_FUNCTIONS(type*) JS_FOR_EACH_TRACEKIND(INSTANTIATE_INTERNAL_TRACE_FUNCTIONS_FROM_TRACEKIND) -FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(INSTANTIATE_INTERNAL_TRACE_FUNCTIONS) +JS_FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(INSTANTIATE_INTERNAL_TRACE_FUNCTIONS) #undef INSTANTIATE_INTERNAL_TRACE_FUNCTIONS_FROM_TRACEKIND #undef INSTANTIATE_INTERNAL_TRACE_FUNCTIONS @@ -3531,8 +3532,8 @@ JS_PUBLIC_API bool EdgeNeedsSweepUnbarrieredSlow(T* thingp) { #define INSTANTIATE_ALL_VALID_HEAP_TRACE_FUNCTIONS(type) \ template JS_PUBLIC_API bool EdgeNeedsSweep(JS::Heap*); \ template JS_PUBLIC_API bool EdgeNeedsSweepUnbarrieredSlow(type*); -FOR_EACH_PUBLIC_GC_POINTER_TYPE(INSTANTIATE_ALL_VALID_HEAP_TRACE_FUNCTIONS) -FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE( +JS_FOR_EACH_PUBLIC_GC_POINTER_TYPE(INSTANTIATE_ALL_VALID_HEAP_TRACE_FUNCTIONS) +JS_FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE( INSTANTIATE_ALL_VALID_HEAP_TRACE_FUNCTIONS) #define INSTANTIATE_INTERNAL_MARKING_FUNCTIONS(type) \ @@ -3545,7 +3546,8 @@ FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE( INSTANTIATE_INTERNAL_MARKING_FUNCTIONS(type*) JS_FOR_EACH_TRACEKIND(INSTANTIATE_INTERNAL_MARKING_FUNCTIONS_FROM_TRACEKIND) -FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(INSTANTIATE_INTERNAL_MARKING_FUNCTIONS) +JS_FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE( + INSTANTIATE_INTERNAL_MARKING_FUNCTIONS) #undef INSTANTIATE_INTERNAL_MARKING_FUNCTIONS_FROM_TRACEKIND #undef INSTANTIATE_INTERNAL_MARKING_FUNCTIONS diff --git a/js/src/moz.build b/js/src/moz.build index f6f4c782355a..d9d16b3361ec 100755 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -144,6 +144,7 @@ EXPORTS.js += [ '../public/GCAPI.h', '../public/GCHashTable.h', '../public/GCPolicyAPI.h', + '../public/GCTypeMacros.h', '../public/GCVariant.h', '../public/GCVector.h', '../public/HashTable.h',