ladybird/Libraries/LibJS
InvalidUsernameException b2d9fd3352 LibJS: Also initialize constants and arguments of ExecutionContext
When allocating ExecutionContext, we were skipping allocating constants,
because they are filled in shortly after. However, there is still some
code executing between allocating the ExecutionContext and assigning
constants. This code may allocate GC-aware objects before the
assignment.  Allocating any GC object may cause a garbage collection to
be triggered.  And running garbage collection on uninitialized objects
might have all kinds of unintended effects.

To avoid that, simply initialize constants right away. To be safe, also
initialize arguments, but I haven't checked more closely if it is needed
for them or not.

The specific case where this bug manifested was JetStream3's
raytrace-private-class-fields.js, which was triggering a segmentation
fault when trying to visit a functions constant during GC marking phase.
The offending allocation triggering the garbage collection is the
corresponding FunctionEnvironment being created.

This crash was exposed as a combination of multiple things coming
together. In particular, both of 1179e40d3f and 61e6dbe4e7 combined
were exposing the problem, but is seems neither commit is at fault. Most
likely the crash happening or not is sensitive to the exact amount of GC
pressure being present or size of individual execution contexts. And so
any change that affects those might make it appear or go away.

To put in an additional wrinkle, this could only be observed using the
ASM JS interpreter. The CPP interpreter was using a fast path for
function calls that has a different allocation pattern and did not run
into the crash.

No explicit regression test for this change because:
* The problem is very sensitive to implementation details and a
  reproduction that stays valid with code changes in the interpreter is
  probably impossible to come by.
* The bug was exposed by the JS benchmarks, which already are as good as
  a regression test as we are going to get here realistically.
2026-03-27 19:31:17 +01:00
..
AsmIntGen LibJS: Re-box double arithmetic results as Int32 when possible 2026-03-19 09:42:04 +01:00
Bytecode LibJS+LibRegex: Switch RegExp over to the Rust engine 2026-03-27 17:32:19 +01:00
BytecodeDef LibJS: Use the 2024 Rust edition for AsmIntGen and ByteCodeDef 2026-03-11 16:57:09 -04:00
Contrib/Test262 LibJS: Make more use of Value::is and Value::as_if 2026-02-28 10:24:37 -05:00
Heap LibJS: Eliminate GeneratorResult GC cell allocation on yield/await 2026-03-20 15:57:23 -05:00
Runtime LibJS: Also initialize constants and arguments of ExecutionContext 2026-03-27 19:31:17 +01:00
Rust LibJS: Validate regex literals during parsing 2026-03-27 17:32:19 +01:00
CMakeLists.txt LibJS: Re-enable AddressSanitizer for LibJS on Windows 2026-03-25 00:57:49 +01:00
Console.cpp LibJS: Replace IndexedProperties with inline Packed/Holey/Dictionary 2026-03-17 22:28:35 -05:00
Console.h LibJS: Add source locations to console.trace() 2026-02-06 11:58:07 +00:00
CyclicModule.cpp LibJS: Align async module rejection order with fulfillment order 2025-12-17 15:33:26 +01:00
CyclicModule.h LibJS: Sync additional Import Attributes spec changes 2025-10-22 10:58:19 +02:00
Forward.h LibJS: Remove remaining C++ pipeline artifacts 2026-03-19 21:55:10 -05:00
LocalVariable.h LibJS: Port the Identifier AST (and related) nodes to UTF-16 2025-08-13 09:56:13 -04:00
Module.cpp LibGC: Enforce that a Cell type must declare the allocator to use 2026-01-20 12:00:11 +01:00
Module.h LibGC: Enforce that a Cell type must declare the allocator to use 2026-01-20 12:00:11 +01:00
ModuleEntry.h LibJS: Remove C++ AST 2026-03-19 21:55:10 -05:00
ModuleLoading.h LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
ParserError.cpp LibJS: Port the JS lexer and parser to UTF-16 2025-08-13 09:56:13 -04:00
ParserError.h LibJS: Port the JS lexer and parser to UTF-16 2025-08-13 09:56:13 -04:00
Position.h LibJS: Store full realized SourceRange with each AST node 2025-12-29 13:36:01 +01:00
Print.cpp LibJS: Replace IndexedProperties with inline Packed/Holey/Dictionary 2026-03-17 22:28:35 -05:00
Print.h LibJS: Enable EXPLICIT_SYMBOL_EXPORT and annotate minimum symbol set 2025-07-22 11:51:29 -04:00
RustIntegration.cpp LibJS: Validate regex literals during parsing 2026-03-27 17:32:19 +01:00
RustIntegration.h LibJS: Remove C++ AST 2026-03-19 21:55:10 -05:00
Script.cpp LibJS: Remove C++ compiler pipeline fallback paths 2026-03-19 21:55:10 -05:00
Script.h LibJS: Remove C++ compiler pipeline fallback paths 2026-03-19 21:55:10 -05:00
SourceCode.cpp LibJS: Cache ASCII-to-UTF-16 source conversion for Rust compilation 2026-02-25 00:00:52 +01:00
SourceCode.h LibJS: Cache ASCII-to-UTF-16 source conversion for Rust compilation 2026-02-25 00:00:52 +01:00
SourceRange.h LibJS: Remove C++ AST 2026-03-19 21:55:10 -05:00
SourceTextModule.cpp LibJS: Remove C++ compiler pipeline fallback paths 2026-03-19 21:55:10 -05:00
SourceTextModule.h LibJS: Remove C++ AST 2026-03-19 21:55:10 -05:00
SyntaxHighlighter.cpp LibJS: Fix syntax highlighter position starting at invalid sentinel 2026-03-20 15:32:33 +01:00
SyntaxHighlighter.h LibJS: Enable EXPLICIT_SYMBOL_EXPORT and annotate minimum symbol set 2025-07-22 11:51:29 -04:00
SyntheticModule.cpp Revert "LibJS: Shrink ExecutionContext by replacing ScriptOrModule …" 2026-03-11 23:13:18 +00:00
SyntheticModule.h LibJS+LibWeb+WebContent: Port JS::PropertyKey to UTF-16 2025-08-05 07:07:15 -04:00
Token.h LibJS: Remove C++ lexer, use Rust tokenizer for syntax highlighting 2026-03-19 21:55:10 -05:00