LibJS: Add JS_OBJECT_WITH_CUSTOM_CLASS_NAME

Some JS::Object subclasses need the GC-cell macro plumbing while still
computing their class_name() dynamically.

Add a GC_CELL helper that provides the Base alias and heap friendship
without defining class_name(), then expose it through LibJS. Teach the
LibJS GC Clang plugin to treat this helper as a JS_OBJECT-style macro so
the existing validation still checks the class name and base class
arguments.
This commit is contained in:
Andreas Kling 2026-05-09 13:25:59 +02:00 committed by Andreas Kling
parent c382e5d254
commit f80f52b710
3 changed files with 7 additions and 0 deletions

View file

@ -38,6 +38,11 @@ public: \
} \
friend class GC::Heap;
#define GC_CELL_WITH_CUSTOM_CLASS_NAME(class_, base_class) \
public: \
using Base = base_class; \
friend class GC::Heap;
class GC_API Cell {
AK_MAKE_NONCOPYABLE(Cell);
AK_MAKE_NONMOVABLE(Cell);

View file

@ -26,6 +26,7 @@
namespace JS {
#define JS_OBJECT(class_, base_class) GC_CELL(class_, base_class)
#define JS_OBJECT_WITH_CUSTOM_CLASS_NAME(class_, base_class) GC_CELL_WITH_CUSTOM_CLASS_NAME(class_, base_class)
struct PrivateElement {
enum class Kind {

View file

@ -944,6 +944,7 @@ void LibJSPPCallbacks::MacroExpands(clang::Token const& name_token, clang::Macro
static llvm::StringMap<LibJSCellMacro::Type> libjs_macro_types {
{ "GC_CELL", LibJSCellMacro::Type::GCCell },
{ "JS_OBJECT", LibJSCellMacro::Type::JSObject },
{ "JS_OBJECT_WITH_CUSTOM_CLASS_NAME", LibJSCellMacro::Type::JSObject },
{ "JS_ENVIRONMENT", LibJSCellMacro::Type::JSEnvironment },
{ "JS_PROTOTYPE_OBJECT", LibJSCellMacro::Type::JSPrototypeObject },
{ "WEB_PLATFORM_OBJECT", LibJSCellMacro::Type::WebPlatformObject },