Skip to content

Truly independent web browser

LibGC: Reject polymorphic values as GC::Function captures

Andreas Kling48a226e35fd2
diff --git a/Libraries/LibGC/Function.h b/Libraries/LibGC/Function.h
index 71676f3014b..ff1d4a73bdb 100644
--- a/Libraries/LibGC/Function.h
+++ b/Libraries/LibGC/Function.h
@@ -43,6 +43,9 @@ struct CapturedCellPointer {
template<typename T>
struct CapturedValue {
static_assert(IsCapturable<T>, "A GC::Function capture must be traced, or hold no cell edges");
+ // NB: A value is copied into the function. A polymorphic one may be part of a larger object, such as the mixin of a
+ // cell captured as *this, and the function would act on a copy of it.
+ static_assert(!__is_polymorphic(T), "A GC::Function can't capture a polymorphic value, which would be copied out of the object it is part of");
T value;