serenity/Meta
Matthew Olsson 76fa127cbf LibJSGCVerifier: Detect stack-allocated ref captures in lambdas
For example, consider the following code snippet:

    Vector<Function<void()>> m_callbacks;
    void add_callback(Function<void()> callback)
    {
    	m_callbacks.append(move(callback));
    }

    // Somewhere else...
    void do_something()
    {
    	int a = 10;
    	add_callback([&a] {
            dbgln("a is {}", a);
    	});
    } // Oops, "a" is now destroyed, but the callback in m_callbacks
      // has a reference to it!

We now statically detect the capture of "a" in the lambda above and flag
it as incorrect. Note that capturing the value implicitly with a capture
list of `[&]` would also be detected.

Of course, many functions that accept Function<...> don't store them
anywhere, instead immediately invoking them inside of the function. To
avoid a warning in this case, the parameter can be annotated with
NOESCAPE to indicate that capturing stack variables is fine:

    void do_something_now(NOESCAPE Function<...> callback)
    {
    	callback(...)
    }

Lastly, there are situations where the callback does generally escape,
but where the caller knows that it won't escape long enough to cause any
issues. For example, consider this fake example from LibWeb:

    void do_something()
    {
    	bool is_done = false;
    	HTML::queue_global_task([&] {
            do_some_work();
            is_done = true;
        });
    	HTML::main_thread_event_loop().spin_until([&] {
            return is_done;
        });
    }

In this case, we know that the lambda passed to queue_global_task will
be executed before the function returns, and will not persist
afterwards. To avoid this warning, annotate the type of the capture
with IGNORE_USE_IN_ESCAPING_LAMBDA:

    void do_something()
    {
   	IGNORE_USE_IN_ESCAPING_LAMBDA bool is_done = false;
    	// ...
    }
2024-04-09 09:10:44 +02:00
..
Azure CI: Revert ARCH_MMAP_RND_BITS libasan workaround 2024-03-25 14:16:55 -04:00
CMake Meta: Remove serenity_lib_static() CMake helper function 2024-03-26 12:25:21 -04:00
gn Documentation: Add more specific instructions on how to use the GN build 2024-04-08 18:49:41 -06:00
HeaderCheck HeaderCheck: Also check AK for broken headers 2022-09-18 13:27:24 -04:00
Lagom LibJSGCVerifier: Detect stack-allocated ref captures in lambdas 2024-04-09 09:10:44 +02:00
Screenshots README+Meta: Update the screenshot :^) 2023-07-14 23:40:58 +02:00
ShellCompletions/zsh Everywhere: Add RISC-V 64 target to the build system 2023-08-18 08:37:43 -06:00
Websites Meta: Add anchors to headings of man pages 2023-10-30 10:26:21 +00:00
analyze-qemu-coverage.sh Meta: Use absolute paths in Meta/analyze-qemu-coverage.sh 2022-12-10 11:51:16 +00:00
bochsrc Meta: Use BXSHARE instead of a hardcoded Bochs directory 2024-01-22 20:18:38 -07:00
build-image-extlinux.sh Meta: Pass -- to sudo instead of '$SHELL -c' in build scripts 2023-07-16 16:28:18 +01:00
build-image-grub.sh Meta: Pass -- to sudo instead of '$SHELL -c' in build scripts 2023-07-16 16:28:18 +01:00
build-image-limine.sh Meta: Pass -- to sudo instead of '$SHELL -c' in build scripts 2023-07-16 16:28:18 +01:00
build-image-qemu.sh Meta: Pass -- to sudo instead of '$SHELL -c' in build scripts 2023-07-16 16:28:18 +01:00
build-manpages-website.sh Meta: Add anchors to headings of man pages 2023-10-30 10:26:21 +00:00
build-native-partition.sh Meta: Pass -- to sudo instead of '$SHELL -c' in build scripts 2023-07-16 16:28:18 +01:00
build-root-filesystem.sh Tests/Kernel: Add tests for verifying proper loop device support 2024-03-13 15:33:47 -06:00
check-ak-test-files.sh Meta: Fix check for AK test inclusion 2022-09-13 08:29:09 +00:00
check-debug-flags.sh Meta: Fix typos in shell script comments 2023-10-26 15:45:31 -06:00
check-emoji.py Meta: Disallow emoji images with invalid code points in their file name 2022-10-26 18:40:20 +01:00
check-markdown.sh markdown-check: Allow generating a manpage link graph 2023-07-05 16:15:42 +01:00
check-newlines-at-eof.py Meta: Don't check for newlines at EOF in Tests/LibWeb/Layout/ 2023-03-11 13:05:35 +01:00
check-png-sizes.sh Meta: Add a PNG size check to CI and pre-commit checks 2022-06-18 21:58:43 +04:30
check-style.py JSSpecCompiler: Add our first test :^) 2023-12-07 10:13:21 -07:00
check-symbols.sh Meta: Make x86-64 target the default 2022-10-03 11:14:53 +02:00
convert-markdown-links.lua Meta/build-manpages-website: Use absolute paths for all links 2023-01-08 13:35:29 +01:00
debug-kernel.sh Revert "Kernel/x86: Bake the Prekernel and the Kernel into one image" 2023-04-28 23:24:19 +02:00
embed_as_string_view.py Meta: Make embed_as_string_view.py usable by CMake builds :^) 2023-08-24 07:42:12 +01:00
emoji-file-list.txt Base: Add and Rework Emoji 2024-04-06 13:40:45 -04:00
export-argsparser-manpages.sh CI: Ensure the manpage generation step shuts down the VM on failure 2022-10-31 22:10:14 +00:00
extlinux.conf Everywhere: Get rid of the fbdev kernel boot argument remainders 2022-08-14 01:03:23 +01:00
find_compiler.sh Meta: Do not spam "<compiler-name>: command not found" 2023-09-09 13:38:06 -06:00
generate-embedded-resource-assembly.sh Meta: Get building on NixOS (#5005) 2021-01-22 17:44:05 +01:00
generate-libwasm-spec-test.py LibWasm: Implement a few SIMD instructions 2023-08-21 13:39:32 +03:30
generate-libwasm-spec-test.sh Meta: Run the Wasm spec tests in CI 2021-05-27 17:28:41 +04:30
grub-ebr.cfg Meta: Use correct boot device selections when using GRUB images 2022-09-02 23:36:08 +01:00
grub-gpt.cfg Meta: Use correct boot device selections when using GRUB images 2022-09-02 23:36:08 +01:00
grub-mbr.cfg Meta: Use correct boot device selections when using GRUB images 2022-09-02 23:36:08 +01:00
install-ports-tree.sh Everywhere: Replace SERENITY_ROOT with SERENITY_SOURCE_DIR 2021-04-20 15:27:52 +02:00
jbig2_to_pdf.py Meta/jbig2_to_pdf.py: Read jbig2 dimensions from file 2024-04-02 15:00:23 -04:00
label-pull-requests.js CI: Automatically apply pull request labels for generic PR actions 2023-01-06 15:25:30 +01:00
limine.cfg Everywhere: Get rid of the fbdev kernel boot argument remainders 2022-08-14 01:03:23 +01:00
lint-ci.sh Meta+Utilities: Make pre-commit checks significantly less verbose 2023-07-26 06:21:39 -04:00
lint-clang-format.sh Meta: Lint .mm files with lint-clang-format.sh 2023-09-19 11:37:48 -06:00
lint-commit.sh CI: Add a check to report git merge commit 2022-12-10 12:07:06 +00:00
lint-executable-resources.sh Meta: Add special case for macOS 2021-11-02 12:23:30 +01:00
lint-gml-format.sh Meta: Fix typos in shell script comments 2023-10-26 15:45:31 -06:00
lint-gn.sh Meta: Add gn linter 2023-07-13 14:07:25 -06:00
lint-keymaps.py Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
lint-ports.py Meta: Dont finish lines with only one character in lint-ports.py 2023-07-18 00:17:34 +02:00
lint-prettier.sh LibJS: Implement ImportCall and HostImportModuleDynamically 2022-01-22 01:21:18 +00:00
lint-python.sh Meta: Get building on NixOS (#5005) 2021-01-22 17:44:05 +01:00
lint-shell-scripts.sh Meta: Allow shellcheck to search sourced files in the script directory 2022-10-16 23:39:45 +02:00
new-project.sh Meta: Add new-project.sh :^) 2021-08-13 21:12:17 +04:30
refresh-serenity-qtcreator.sh Meta: Make *.in files accessible to QtCreator 2023-05-14 16:01:57 -06:00
run.py Meta: Disable network hardware in run.py for RISC-V 2024-02-26 13:22:27 -07:00
run.sh Meta: Replace run.sh by run.py 2023-12-15 00:11:50 +01:00
serenity.sh Meta: Correct gdb example in serenity.sh 2024-03-17 20:44:18 -06:00
serenity_gdb.py Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
shell_include.sh Meta: Fix typos in shell script comments 2023-10-26 15:45:31 -06:00
test_pdf.py Meta: Let test_pdf.py be less dramatic about issue counts 2024-01-10 09:36:33 +01:00
toot-commits.js CI: Add script to post mastodon toots for commits on master 2023-02-10 13:54:07 +00:00
tweet-commits.js Meta: Ensure long messages fit in commit tweet 2021-06-18 13:34:17 +01:00