Skip to content

Truly independent web browser

LibJS: Let catch parameters not block eval's Annex B hoisting

Shannon Boothda5a6b474062
diff --git a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
index 1301f2c35e7..5d4e9e7fe5a 100644
--- a/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
+++ b/Libraries/LibJS/Rust/src/runtime/abstract_operations.rs
@@ -1542,9 +1542,10 @@ pub fn eval_declaration_instantiation(
// a. If thisEnv is not the Environment Record for a Catch clause, set bindingExists to true.
// 2. Else,
// a. Set bindingExists to true.
- // FIXME: Leave out the environment of a Catch clause, as the web browser branch does.
+ // AD-HOC: We are a web browser, so we only implement the web browser branch.
if !this_environment.is_object_environment()
&& this_environment.has_binding(vm, function_name, None).must()
+ && !this_environment.is_catch_environment()
{
binding_exists = true;
break;
diff --git a/Tests/LibJS/Runtime/eval-catch-redeclare.js b/Tests/LibJS/Runtime/eval-catch-redeclare.js
index f1f6f05e739..8fb130b1508 100644
--- a/Tests/LibJS/Runtime/eval-catch-redeclare.js
+++ b/Tests/LibJS/Runtime/eval-catch-redeclare.js
@@ -71,3 +71,17 @@ describe("eval catch block redeclaration", () => {
}
});
});
+
+test("a function in a block of eval code hoists past a catch parameter of its name", () => {
+ function run() {
+ var read = () => x;
+ try {
+ throw 1;
+ } catch (x) {
+ eval("var before; try { before = read(); } catch (e) { before = e.name; } { function x() {} }");
+ }
+ return [before, typeof x];
+ }
+ expect(run()).toEqual([undefined, "function"]);
+ expect(Object.hasOwn(globalThis, "x")).toBeFalse();
+});