#1063: report an undefined name at its first use inside a function wrapper

Inside a function wrapper such as (function () { ... })(), boa places a ReferenceError at the start of
the function, so a script's error was reported at the wrapper's first line rather than the line that
failed. The first use of the undefined name in the code is now the position, and boa's frames remain
the fallback. Thrown errors and object-model errors already report their own lines. A regression
test covers a thrown error, an undefined name, and an object-model error inside a wrapper.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Kristian Myram
2026-10-13 01:44:14 +02:00
co-authored by Claude Haiku 5.5
parent 470ea7a3af
commit 64945f2ef9
2 changed files with 47 additions and 18 deletions
+18
View File
@@ -142,6 +142,24 @@ fn errors_report_line_and_column() {
assert_eq!(e.line, Some(3), "{e:?}");
}
/// A script wrapped in a function (the usual `(function () { ... })();` shape) reports the line
/// that failed, not the wrapper's line (#1063).
#[test]
fn errors_inside_a_function_wrapper_report_the_failing_line() {
let mut s = session();
let o = run_code(&mut s, "(function () {\n var a = 1;\n throw new Error('inside');\n})();\n", "thrown.jsx");
let e = o.error.expect("thrown");
assert_eq!(e.message, "inside");
assert_eq!(e.line, Some(3), "{e:?}");
let o = run_code(&mut s, "(function () {\n var a = 1;\n nope.call();\n})();\n", "reference.jsx");
let e = o.error.expect("reference error");
assert_eq!(e.line, Some(3), "{e:?}");
let o = run_code(&mut s, "(function () {\n var c = app.project.items.addComp('C', 10, 10, 1, 1, 24);\n c.layer(5);\n})();\n", "range.jsx");
let e = o.error.expect("range error");
assert!(e.message.contains("out of range"), "{e:?}");
assert_eq!(e.line, Some(3), "{e:?}");
}
#[test]
fn match_names_and_lookups() {
let mut s = session();