1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

LibJS: Add JS::SafeFunction, like Function but protects captures from GC

SafeFunction automatically registers its closure memory area in a place
where the JS garbage collector can find it.

This means that you can capture JS::Value and arbitrary pointers into
the GC heap in closures, as long as you're using a SafeFunction, and the
GC will not zap those values!

There's probably some performance impact from this, and there's a lot of
things that could be nicer/smarter about it, but let's build something
that ensures safety first, and we can worry about performance later. :^)
This commit is contained in:
Andreas Kling 2022-09-24 11:56:43 +02:00
parent 585072fce3
commit 131c3f50de
3 changed files with 282 additions and 0 deletions

View file

@ -22,6 +22,7 @@ GOOD_LICENSE_HEADER_PATTERN = re.compile(
LICENSE_HEADER_CHECK_EXCLUDES = {
'AK/Checked.h',
'AK/Function.h',
'Userland/Libraries/LibJS/SafeFunction.h',
'Userland/Libraries/LibC/elf.h',
'Userland/Libraries/LibCodeComprehension/Cpp/Tests/',
'Userland/Libraries/LibCpp/Tests/parser/',