Skip to content

Commit e569f39

Browse files
authored
Add stack trace to Test262Error (#644)
Only enabled in verboser mode. Necessary because Test262Error doesn't subclass from Error. Make it tell not just _what_ but also _where_.
1 parent c53a0a8 commit e569f39

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

run-test262.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,15 @@ int run_test_buf(const char *filename, char *harness, namelist_t *ip,
17531753
if (eval_file(ctx, harness, ip->array[i], JS_EVAL_TYPE_GLOBAL)) {
17541754
fatal(1, "error including %s for %s", ip->array[i], filename);
17551755
}
1756+
// hack to get useful stack traces from Test262Error exceptions
1757+
if (verbose > 1 && str_equal(ip->array[i], "sta.js")) {
1758+
static const char hack[] =
1759+
";(function(C){"
1760+
"globalThis.Test262Error = class Test262Error extends Error {};"
1761+
"globalThis.Test262Error.thrower = C.thrower;"
1762+
"})(Test262Error)";
1763+
JS_FreeValue(ctx, JS_Eval(ctx, hack, sizeof(hack)-1, "sta.js", JS_EVAL_TYPE_GLOBAL));
1764+
}
17561765
}
17571766

17581767
ret = eval_buf(ctx, buf, buf_len, filename, TRUE, is_negative,

0 commit comments

Comments
 (0)