Truly independent web browser
LibJS: Don't look up a default constructor after a failed reparse
Shannon Booth0c2b872f932f
diff --git a/Libraries/LibJS/Parser/Rust/src/stmt.rs b/Libraries/LibJS/Parser/Rust/src/stmt.rsindex 78e09240d58..9da24c92308 100644--- a/Libraries/LibJS/Parser/Rust/src/stmt.rs+++ b/Libraries/LibJS/Parser/Rust/src/stmt.rs@@ -1718,6 +1718,10 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {/// of the class, so that nothing else ever reads the row but the compilation of the function.fn class_function_row(&mut self, key: u32, start: u32, flags: u32, name: u32, reserved_row: u32) -> u32 {if self.is_reparsing() {+ // NB: A parse that has failed may not have come across what the first parse made the row for.+ if self.err.is_some() {+ return NONE;+ }return self.first_pass_row_at(key).expect("the first parse made a row for the code of a class");diff --git a/Tests/LibJS/Runtime/function-compile-near-stack-limit.js b/Tests/LibJS/Runtime/function-compile-near-stack-limit.jsnew file mode 100644index 00000000000..800ed91e385--- /dev/null+++ b/Tests/LibJS/Runtime/function-compile-near-stack-limit.js@@ -0,0 +1,20 @@+// Calls `callback` with less and less of the native stack in use, starting from where the stack runs out.+function callAtEveryStackDepth(callback) {+ function recurse() {+ try {+ Reflect.apply(recurse, null, []);+ } catch {}+ try {+ callback();+ } catch {}+ }+ recurse();+}++const deeplyNested = "(".repeat(1900) + "1" + ")".repeat(1900);++test("compiling a function that runs out of stack before the constructor of a class", () => {+ const lazy = new Function(`class C { static x = ${deeplyNested}; constructor() {} } return C;`);+ callAtEveryStackDepth(lazy);+ expect(lazy().x).toBe(1);+});