test: re-introduce js source name

Having a js source name is useful to detect where the error comes from.

Using `null` generates messages with `<anonymous>` source name.
eg. `ReferenceError: report is not defined\n    at <anonymous>:1:1`
vs. `ReferenceError: report is not defined\n    at teststatus:1:1`
This commit is contained in:
Pierre Tachoire
2025-04-17 10:02:18 +02:00
parent f4e8bb6c66
commit 7f308f59b4
3 changed files with 11 additions and 11 deletions

View File

@@ -468,16 +468,16 @@ pub const JsRunner = struct {
}
}
pub fn exec(self: *JsRunner, src: []const u8, err_msg: *?[]const u8) !void {
_ = try self.eval(src, err_msg);
pub fn exec(self: *JsRunner, src: []const u8, name: ?[]const u8, err_msg: *?[]const u8) !void {
_ = try self.eval(src, name, err_msg);
}
pub fn eval(self: *JsRunner, src: []const u8, err_msg: *?[]const u8) !Env.Value {
pub fn eval(self: *JsRunner, src: []const u8, name: ?[]const u8, err_msg: *?[]const u8) !Env.Value {
var try_catch: Env.TryCatch = undefined;
try_catch.init(self.executor);
defer try_catch.deinit();
return self.executor.exec(src, null) catch |err| {
return self.executor.exec(src, name) catch |err| {
if (try try_catch.err(self.arena)) |msg| {
err_msg.* = msg;
std.debug.print("Error running script: {s}\n", .{msg});