Userland: Add ESCAPING annotations to a bunch of places

This isn't comprehensive; just a result of a simple grep search.
This commit is contained in:
Matthew Olsson 2024-05-17 17:14:06 -07:00 committed by Andrew Kaster
parent e0d6afbabe
commit a98ad191c7
Notes: sideshowbarker 2024-07-17 07:25:39 +09:00
29 changed files with 60 additions and 59 deletions

View file

@ -11,7 +11,7 @@
TEST_CASE(deferred_invoke)
{
Core::EventLoop event_loop;
IGNORE_USE_IN_ESCAPING_LAMBDA Core::EventLoop event_loop;
auto reaper = Core::Timer::create_single_shot(250, [] {
warnln("I waited for the deferred_invoke to happen, but it never did!");
VERIFY_NOT_REACHED();

View file

@ -155,7 +155,7 @@ TEST_CASE(threaded_promise_resolved_later)
{
Core::EventLoop loop;
bool unblock_thread = false;
IGNORE_USE_IN_ESCAPING_LAMBDA bool unblock_thread = false;
bool resolved = false;
bool rejected = true;
Optional<pthread_t> thread_id;

View file

@ -43,7 +43,7 @@ TEST_CASE(simple_dequeue)
// There is one parallel consumer, but nobody is producing at the same time.
TEST_CASE(simple_multithread)
{
auto queue = MUST(TestQueue::create());
IGNORE_USE_IN_ESCAPING_LAMBDA auto queue = MUST(TestQueue::create());
auto const test_count = 10;
for (int i = 0; i < test_count; ++i)
@ -73,11 +73,11 @@ TEST_CASE(simple_multithread)
// There is one parallel consumer and one parallel producer.
TEST_CASE(producer_consumer_multithread)
{
auto queue = MUST(TestQueue::create());
IGNORE_USE_IN_ESCAPING_LAMBDA auto queue = MUST(TestQueue::create());
// Ensure that we have the possibility of filling the queue up.
auto const test_count = queue.size() * 4;
Atomic<bool> other_thread_running { false };
IGNORE_USE_IN_ESCAPING_LAMBDA Atomic<bool> other_thread_running { false };
auto second_thread = Threading::Thread::construct([&queue, &other_thread_running]() {
auto copied_queue = queue;

View file

@ -27,7 +27,7 @@ static void sleep_until_thread_exits(Threading::Thread const& thread)
TEST_CASE(threads_can_detach)
{
Atomic<int> should_be_42 = 0;
IGNORE_USE_IN_ESCAPING_LAMBDA Atomic<int> should_be_42 = 0;
auto thread = Threading::Thread::construct([&should_be_42]() {
usleep(10 * 1000);
@ -43,7 +43,7 @@ TEST_CASE(threads_can_detach)
TEST_CASE(detached_threads_do_not_need_to_be_joined)
{
Atomic<bool> should_exit { false };
IGNORE_USE_IN_ESCAPING_LAMBDA Atomic<bool> should_exit { false };
auto thread = Threading::Thread::construct([&]() {
while (!should_exit.load())
usleep(10 * 1000);

View file

@ -37,7 +37,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No);
parser.parse(arguments);
Optional<ByteString> path = {};
IGNORE_USE_IN_ESCAPING_LAMBDA Optional<ByteString> path = {};
if (auto error_or_path = FileSystem::absolute_path(file_to_edit); !file_to_edit.is_empty() && !error_or_path.is_error())
path = error_or_path.release_value();
@ -48,9 +48,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::unveil(nullptr, nullptr));
auto app_icon = GUI::Icon::default_icon("app-theme-editor"sv);
auto window = GUI::Window::construct();
IGNORE_USE_IN_ESCAPING_LAMBDA auto window = GUI::Window::construct();
auto main_widget = TRY(ThemeEditor::MainWidget::try_create());
IGNORE_USE_IN_ESCAPING_LAMBDA auto main_widget = TRY(ThemeEditor::MainWidget::try_create());
window->set_main_widget(main_widget);
if (path.has_value()) {

View file

@ -67,7 +67,7 @@ public:
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<EventReceiver>>> job_promise);
void deferred_invoke(Function<void()>);
void deferred_invoke(ESCAPING Function<void()>);
void wake();
@ -82,7 +82,7 @@ public:
static void register_notifier(Badge<Notifier>, Notifier&);
static void unregister_notifier(Badge<Notifier>, Notifier&);
static int register_signal(int signo, Function<void(int)> handler);
static int register_signal(int signo, ESCAPING Function<void(int)> handler);
static void unregister_signal(int handler_id);
// Note: Boost uses Parent/Child/Prepare, but we don't really have anything
@ -101,6 +101,6 @@ private:
NonnullOwnPtr<EventLoopImplementation> m_impl;
};
void deferred_invoke(Function<void()>);
void deferred_invoke(ESCAPING Function<void()>);
}

View file

@ -21,8 +21,8 @@ class NativeFunction : public FunctionObject {
JS_DECLARE_ALLOCATOR(NativeFunction);
public:
static NonnullGCPtr<NativeFunction> create(Realm&, Function<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
static NonnullGCPtr<NativeFunction> create(Realm&, DeprecatedFlyString const& name, Function<ThrowCompletionOr<Value>(VM&)>);
static NonnullGCPtr<NativeFunction> create(Realm&, ESCAPING Function<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
static NonnullGCPtr<NativeFunction> create(Realm&, DeprecatedFlyString const& name, ESCAPING Function<ThrowCompletionOr<Value>(VM&)>);
virtual ~NativeFunction() override = default;

View file

@ -187,8 +187,8 @@ public:
using IntrinsicAccessor = Value (*)(Realm&);
void define_intrinsic_accessor(PropertyKey const&, PropertyAttributes attributes, IntrinsicAccessor accessor);
void define_native_function(Realm&, PropertyKey const&, Function<ThrowCompletionOr<Value>(VM&)>, i32 length, PropertyAttributes attributes, Optional<Bytecode::Builtin> builtin = {});
void define_native_accessor(Realm&, PropertyKey const&, Function<ThrowCompletionOr<Value>(VM&)> getter, Function<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attributes);
void define_native_function(Realm&, PropertyKey const&, ESCAPING Function<ThrowCompletionOr<Value>(VM&)>, i32 length, PropertyAttributes attributes, Optional<Bytecode::Builtin> builtin = {});
void define_native_accessor(Realm&, PropertyKey const&, ESCAPING Function<ThrowCompletionOr<Value>(VM&)> getter, ESCAPING Function<ThrowCompletionOr<Value>(VM&)> setter, PropertyAttributes attributes);
virtual bool is_dom_node() const { return false; }
virtual bool is_function() const { return false; }

View file

@ -30,12 +30,13 @@ class BackgroundActionBase {
private:
BackgroundActionBase() = default;
static void enqueue_work(Function<void()>);
static void enqueue_work(ESCAPING Function<void()>);
static Thread& background_thread();
};
template<typename Result>
class BackgroundAction final : public Core::EventReceiver
class BackgroundAction final
: public Core::EventReceiver
, private BackgroundActionBase {
C_OBJECT(BackgroundAction);
@ -54,7 +55,7 @@ public:
bool is_canceled() const { return m_canceled; }
private:
BackgroundAction(Function<ErrorOr<Result>(BackgroundAction&)> action, Function<ErrorOr<void>(Result)> on_complete, Optional<Function<void(Error)>> on_error = {})
BackgroundAction(ESCAPING Function<ErrorOr<Result>(BackgroundAction&)> action, ESCAPING Function<ErrorOr<void>(Result)> on_complete, ESCAPING Optional<Function<void(Error)>> on_error = {})
: m_promise(Promise::try_create().release_value_but_fixme_should_propagate_errors())
, m_action(move(action))
, m_on_complete(move(on_complete))

View file

@ -46,11 +46,11 @@ class Thread final
: public AtomicRefCounted<Thread>
, public Weakable<Thread> {
public:
static NonnullRefPtr<Thread> construct(Function<intptr_t()> action, StringView thread_name = {})
static NonnullRefPtr<Thread> construct(ESCAPING Function<intptr_t()> action, StringView thread_name = {})
{
return adopt_ref(*new Thread(move(action), thread_name));
}
static ErrorOr<NonnullRefPtr<Thread>> try_create(Function<intptr_t()> action, StringView thread_name = {})
static ErrorOr<NonnullRefPtr<Thread>> try_create(ESCAPING Function<intptr_t()> action, StringView thread_name = {})
{
return adopt_nonnull_ref_or_enomem(new (nothrow) Thread(move(action), thread_name));
}
@ -77,7 +77,7 @@ public:
bool has_exited() const;
private:
explicit Thread(Function<intptr_t()> action, StringView thread_name = {});
explicit Thread(ESCAPING Function<intptr_t()> action, StringView thread_name = {});
Function<intptr_t()> m_action;
pthread_t m_tid { 0 };
ByteString m_thread_name;

View file

@ -138,7 +138,7 @@ public:
void did_load_font(FlyString const& family_name);
Optional<FontLoader&> load_font_face(ParsedFontFace const&, Function<void(FontLoader const&)> on_load = {}, Function<void()> on_fail = {});
Optional<FontLoader&> load_font_face(ParsedFontFace const&, ESCAPING Function<void(FontLoader const&)> on_load = {}, ESCAPING Function<void()> on_fail = {});
void load_fonts_from_sheet(CSSStyleSheet const&);
@ -232,7 +232,7 @@ private:
class FontLoader : public ResourceClient {
public:
FontLoader(StyleComputer& style_computer, FlyString family_name, Vector<Gfx::UnicodeRange> unicode_ranges, Vector<URL::URL> urls, Function<void(FontLoader const&)> on_load = {}, Function<void()> on_fail = {});
FontLoader(StyleComputer& style_computer, FlyString family_name, Vector<Gfx::UnicodeRange> unicode_ranges, Vector<URL::URL> urls, ESCAPING Function<void(FontLoader const&)> on_load = {}, ESCAPING Function<void()> on_fail = {});
virtual ~FontLoader() override;

View file

@ -26,7 +26,7 @@ public:
virtual ~AbortSignal() override = default;
void add_abort_algorithm(Function<void()>);
void add_abort_algorithm(ESCAPING Function<void()>);
// https://dom.spec.whatwg.org/#dom-abortsignal-aborted
// An AbortSignal object is aborted when its abort reason is not undefined.

View file

@ -30,7 +30,7 @@ public:
Children,
Descendants,
};
[[nodiscard]] static JS::NonnullGCPtr<HTMLCollection> create(ParentNode& root, Scope, Function<bool(Element const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<HTMLCollection> create(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter);
virtual ~HTMLCollection() override;
@ -46,7 +46,7 @@ public:
virtual bool is_supported_property_index(u32) const override;
protected:
HTMLCollection(ParentNode& root, Scope, Function<bool(Element const&)> filter);
HTMLCollection(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter);
virtual void initialize(JS::Realm&) override;

View file

@ -16,7 +16,7 @@ class HTMLFormControlsCollection : public HTMLCollection {
JS_DECLARE_ALLOCATOR(HTMLFormControlsCollection);
public:
[[nodiscard]] static JS::NonnullGCPtr<HTMLFormControlsCollection> create(ParentNode& root, Scope, Function<bool(Element const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<HTMLFormControlsCollection> create(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter);
virtual ~HTMLFormControlsCollection() override;
@ -28,7 +28,7 @@ protected:
virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const final;
private:
HTMLFormControlsCollection(ParentNode& root, Scope, Function<bool(Element const&)> filter);
HTMLFormControlsCollection(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter);
};
}

View file

@ -24,7 +24,7 @@ public:
Descendants,
};
[[nodiscard]] static JS::NonnullGCPtr<NodeList> create(JS::Realm&, Node const& root, Scope, Function<bool(Node const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<NodeList> create(JS::Realm&, Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter);
virtual ~LiveNodeList() override;
virtual u32 length() const override;
@ -33,7 +33,7 @@ public:
virtual bool is_supported_property_index(u32) const override;
protected:
LiveNodeList(JS::Realm&, Node const& root, Scope, Function<bool(Node const&)> filter);
LiveNodeList(JS::Realm&, Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter);
Node* first_matching(Function<bool(Node const&)> const& filter) const;

View file

@ -16,7 +16,7 @@ class RadioNodeList : public LiveNodeList {
JS_DECLARE_ALLOCATOR(RadioNodeList);
public:
[[nodiscard]] static JS::NonnullGCPtr<RadioNodeList> create(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<RadioNodeList> create(JS::Realm& realm, Node const& root, Scope scope, ESCAPING Function<bool(Node const&)> filter);
virtual ~RadioNodeList() override;
@ -27,7 +27,7 @@ protected:
virtual void initialize(JS::Realm&) override;
private:
explicit RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter);
explicit RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, ESCAPING Function<bool(Node const&)> filter);
};
}

View file

@ -24,7 +24,7 @@ public:
Children,
Descendants,
};
[[nodiscard]] static JS::NonnullGCPtr<HTMLAllCollection> create(DOM::ParentNode& root, Scope, Function<bool(DOM::Element const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<HTMLAllCollection> create(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
virtual ~HTMLAllCollection() override;
@ -40,7 +40,7 @@ public:
virtual bool is_supported_property_index(u32) const override;
protected:
HTMLAllCollection(DOM::ParentNode& root, Scope, Function<bool(DOM::Element const&)> filter);
HTMLAllCollection(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
virtual void initialize(JS::Realm&) override;

View file

@ -162,7 +162,7 @@ private:
Task::Source media_element_event_task_source() const { return m_media_element_event_task_source.source; }
WebIDL::ExceptionOr<void> load_element();
WebIDL::ExceptionOr<void> fetch_resource(URL::URL const&, Function<void(String)> failure_callback);
WebIDL::ExceptionOr<void> fetch_resource(URL::URL const&, ESCAPING Function<void(String)> failure_callback);
static bool verify_response(JS::NonnullGCPtr<Fetch::Infrastructure::Response>, ByteRange const&);
WebIDL::ExceptionOr<void> process_media_data(Function<void(String)> failure_callback);
WebIDL::ExceptionOr<void> handle_media_source_failure(Span<JS::NonnullGCPtr<WebIDL::Promise>> promises, String error_message);

View file

@ -21,7 +21,7 @@ class HTMLOptionsCollection final : public DOM::HTMLCollection {
JS_DECLARE_ALLOCATOR(HTMLOptionsCollection);
public:
[[nodiscard]] static JS::NonnullGCPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
virtual ~HTMLOptionsCollection() override;
WebIDL::ExceptionOr<void> set_length(WebIDL::UnsignedLong);
@ -34,7 +34,7 @@ public:
void set_selected_index(WebIDL::Long);
private:
HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter);
HTMLOptionsCollection(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
virtual void initialize(JS::Realm&) override;
};

View file

@ -69,12 +69,12 @@ public:
void close_top_level_traversable();
void destroy_top_level_traversable();
void append_session_history_traversal_steps(Function<void()> steps)
void append_session_history_traversal_steps(ESCAPING Function<void()> steps)
{
m_session_history_traversal_queue->append(move(steps));
}
void append_session_history_synchronous_navigation_steps(JS::NonnullGCPtr<Navigable> target_navigable, Function<void()> steps)
void append_session_history_synchronous_navigation_steps(JS::NonnullGCPtr<Navigable> target_navigable, ESCAPING Function<void()> steps)
{
m_session_history_traversal_queue->append_sync(move(steps), target_navigable);
}

View file

@ -83,7 +83,7 @@ void run_animation_frame_callbacks(DOM::Document& document, double now)
class IdleCallback : public RefCounted<IdleCallback> {
public:
explicit IdleCallback(Function<JS::Completion(JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline>)> handler, u32 handle)
explicit IdleCallback(ESCAPING Function<JS::Completion(JS::NonnullGCPtr<RequestIdleCallback::IdleDeadline>)> handler, u32 handle)
: m_handler(move(handler))
, m_handle(handle)
{

View file

@ -135,7 +135,7 @@ private:
current_collapsible_margins.append(margin);
}
void register_block_container_y_position_update_callback(Function<void(CSSPixels)> callback)
void register_block_container_y_position_update_callback(ESCAPING Function<void(CSSPixels)> callback)
{
block_container_y_position_update_callback = move(callback);
}

View file

@ -14,7 +14,7 @@ namespace Web {
class FileRequest {
public:
FileRequest(ByteString path, Function<void(ErrorOr<i32>)> on_file_request_finish);
FileRequest(ByteString path, ESCAPING Function<void(ErrorOr<i32>)> on_file_request_finish);
ByteString path() const;

View file

@ -20,7 +20,7 @@ public:
virtual ~EventLoopPlugin();
virtual void spin_until(JS::SafeFunction<bool()> goal_condition) = 0;
virtual void deferred_invoke(JS::SafeFunction<void()>) = 0;
virtual void deferred_invoke(ESCAPING JS::SafeFunction<void()>) = 0;
virtual NonnullRefPtr<Timer> create_timer() = 0;
virtual void quit() = 0;
};

View file

@ -32,7 +32,7 @@ public:
virtual ~ImageCodecPlugin();
virtual NonnullRefPtr<Core::Promise<DecodedImage>> decode_image(ReadonlyBytes, Function<ErrorOr<void>(DecodedImage&)> on_resolved, Function<void(Error&)> on_rejected) = 0;
virtual NonnullRefPtr<Core::Promise<DecodedImage>> decode_image(ReadonlyBytes, ESCAPING Function<ErrorOr<void>(DecodedImage&)> on_resolved, ESCAPING Function<void(Error&)> on_rejected) = 0;
};
}

View file

@ -34,7 +34,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto server = TRY(Core::TCPServer::try_create());
TRY(server->listen({}, port));
HashMap<int, NonnullRefPtr<Client>> clients;
IGNORE_USE_IN_ESCAPING_LAMBDA HashMap<int, NonnullRefPtr<Client>> clients;
int next_id = 0;
server->on_ready_to_accept = [&next_id, &clients, &server] {

View file

@ -102,7 +102,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto server = TRY(Core::TCPServer::try_create());
TRY(server->listen({}, port));
HashMap<int, NonnullRefPtr<Client>> clients;
IGNORE_USE_IN_ESCAPING_LAMBDA HashMap<int, NonnullRefPtr<Client>> clients;
int next_id = 0;
server->on_ready_to_accept = [&next_id, &clients, &server, command] {

View file

@ -21,7 +21,7 @@ public:
ImageCodecPluginSerenity();
virtual ~ImageCodecPluginSerenity() override;
virtual NonnullRefPtr<Core::Promise<Web::Platform::DecodedImage>> decode_image(ReadonlyBytes, Function<ErrorOr<void>(Web::Platform::DecodedImage&)> on_resolved, Function<void(Error&)> on_rejected) override;
virtual NonnullRefPtr<Core::Promise<Web::Platform::DecodedImage>> decode_image(ReadonlyBytes, ESCAPING Function<ErrorOr<void>(Web::Platform::DecodedImage&)> on_resolved, ESCAPING Function<void(Error&)> on_rejected) override;
private:
RefPtr<ImageDecoderClient::Client> m_client;

View file

@ -18,7 +18,7 @@ static ErrorOr<void> test_once()
static Vector<int> v;
v.clear();
pthread_once_t once = PTHREAD_ONCE_INIT;
IGNORE_USE_IN_ESCAPING_LAMBDA pthread_once_t once = PTHREAD_ONCE_INIT;
Vector<NonnullRefPtr<Threading::Thread>, threads_count> threads;
for (size_t i = 0; i < threads_count; i++) {
@ -44,9 +44,9 @@ static ErrorOr<void> test_mutex()
constexpr size_t threads_count = 10;
constexpr size_t num_times = 100;
Vector<int> v;
IGNORE_USE_IN_ESCAPING_LAMBDA Vector<int> v;
Vector<NonnullRefPtr<Threading::Thread>, threads_count> threads;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
IGNORE_USE_IN_ESCAPING_LAMBDA pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
for (size_t i = 0; i < threads_count; i++) {
threads.unchecked_append(TRY(Threading::Thread::try_create([&] {
@ -77,9 +77,9 @@ static ErrorOr<void> test_semaphore_as_lock()
constexpr size_t threads_count = 10;
constexpr size_t num_times = 100;
Vector<int> v;
IGNORE_USE_IN_ESCAPING_LAMBDA Vector<int> v;
Vector<NonnullRefPtr<Threading::Thread>, threads_count> threads;
sem_t semaphore;
IGNORE_USE_IN_ESCAPING_LAMBDA sem_t semaphore;
sem_init(&semaphore, 0, 1);
for (size_t i = 0; i < threads_count; i++) {
@ -109,8 +109,8 @@ static ErrorOr<void> test_semaphore_as_lock()
static ErrorOr<void> test_semaphore_as_event()
{
Vector<int> v;
sem_t semaphore;
IGNORE_USE_IN_ESCAPING_LAMBDA Vector<int> v;
IGNORE_USE_IN_ESCAPING_LAMBDA sem_t semaphore;
sem_init(&semaphore, 0, 0);
auto reader = TRY(Threading::Thread::try_create([&] {
@ -144,11 +144,11 @@ static ErrorOr<void> test_semaphore_nonbinary()
constexpr size_t num_times = 100;
Vector<NonnullRefPtr<Threading::Thread>, threads_count> threads;
sem_t semaphore;
IGNORE_USE_IN_ESCAPING_LAMBDA sem_t semaphore;
sem_init(&semaphore, 0, num);
Atomic<u32, AK::memory_order_relaxed> value = 0;
Atomic<bool, AK::memory_order_relaxed> seen_more_than_two = false;
IGNORE_USE_IN_ESCAPING_LAMBDA Atomic<u32, AK::memory_order_relaxed> value = 0;
IGNORE_USE_IN_ESCAPING_LAMBDA Atomic<bool, AK::memory_order_relaxed> seen_more_than_two = false;
for (size_t i = 0; i < threads_count; i++) {
threads.unchecked_append(TRY(Threading::Thread::try_create([&] {