IDLGenerators: Add a callback for when a setlike's set is modified

For simplicity, this requires that the setlike Foo class has a
`void on_set_modified_from_js(Badge<Bindings::FooPrototype>)` method.

This will be called after the set is modified from a generated `add()`,
`delete()`, or `clear()` method.
This commit is contained in:
Sam Atkins 2025-07-04 15:15:46 +01:00 committed by Tim Ledbetter
commit bc94431b99
Notes: github-actions[bot] 2025-07-04 17:12:01 +00:00
2 changed files with 7 additions and 1 deletions

View file

@ -45,6 +45,8 @@ public:
void resolve_ready_promise();
void on_set_modified_from_js(Badge<Bindings::FontFaceSetPrototype>) { }
private:
FontFaceSet(JS::Realm&, GC::Ref<WebIDL::Promise> ready_promise, GC::Ref<JS::Set> set_entries);

View file

@ -4639,6 +4639,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::add)
// What? Which interfaces have a number as their set type?
set->set_add(value_arg);
impl->on_set_modified_from_js({});
return impl;
}
@ -4660,7 +4661,9 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::delete_)
// FIXME: If value is -0, set value to +0.
// What? Which interfaces have a number as their set type?
return set->set_remove(value_arg);
auto result = set->set_remove(value_arg);
impl->on_set_modified_from_js({});
return result;
}
)~~~");
}
@ -4675,6 +4678,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::clear)
GC::Ref<JS::Set> set = impl->set_entries();
set->set_clear();
impl->on_set_modified_from_js({});
return JS::js_undefined();
}