Skip to content

Truly independent web browser

LibJS: Hoist block functions named arguments in program code

Shannon Booth0b446ef1b19a
diff --git a/Libraries/LibJS/Rust/src/parser/base.rs b/Libraries/LibJS/Rust/src/parser/base.rs
index ed27b50b574..e951449c576 100644
--- a/Libraries/LibJS/Rust/src/parser/base.rs
+++ b/Libraries/LibJS/Rust/src/parser/base.rs
@@ -1265,14 +1265,7 @@ impl<'a, U: Unit> Parser<'a, U> {
if is_parameter {
continue;
}
- let reads_arguments = hoist.name == N_ARGUMENTS
- && (scope.arguments_access
- || (scope.flags & scope_flag::FUNCTION != 0
- && scope.flags & scope_flag::ARROW == 0
- && scope.eval_in_function));
- if !reads_arguments {
- self.decls[row as usize].flags |= decl::ANNEX_B_NAME;
- }
+ self.decls[row as usize].flags |= decl::ANNEX_B_NAME;
let binding = if hoist.declaration == NONE {
NONE
} else {
diff --git a/Tests/LibJS/Runtime/functions/annex-b-function-after-blocking-let.js b/Tests/LibJS/Runtime/functions/annex-b-function-after-blocking-let.js
index 163c2545500..0bf1a909819 100644
--- a/Tests/LibJS/Runtime/functions/annex-b-function-after-blocking-let.js
+++ b/Tests/LibJS/Runtime/functions/annex-b-function-after-blocking-let.js
@@ -98,3 +98,12 @@ test("a function expression's own name does not keep a function of that name fro
};
expect(f()).toEqual(["undefined", "block"]);
});
+
+test("a function named arguments hoists in script and eval code that reads arguments", () => {
+ try {
+ expect((0, eval)("{ function arguments() {} } typeof arguments")).toBe("function");
+ } finally {
+ delete globalThis.arguments;
+ }
+ expect(eval("{ function arguments() {} } typeof arguments")).toBe("function");
+});