@@ -36,7 +36,7 @@ const Client = @import("../async/Client.zig");
3636// runWPT parses the given HTML file, starts a js env and run the first script
3737// tags containing javascript sources.
3838// It loads first the js libs files.
39- pub fn run (arena : * std.heap.ArenaAllocator , comptime dir : []const u8 , f : []const u8 , loader : * FileLoader ) ! jsruntime.JSResult {
39+ pub fn run (arena : * std.heap.ArenaAllocator , comptime dir : []const u8 , f : []const u8 , loader : * FileLoader ) ! [] const u8 {
4040 const alloc = arena .allocator ();
4141 try parser .init ();
4242 defer parser .deinit ();
@@ -70,15 +70,15 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
7070 try js_env .load (& js_types );
7171
7272 // start JS env
73- try js_env .start (alloc );
73+ try js_env .start ();
7474 defer js_env .stop ();
7575
7676 // display console logs
7777 defer {
78- var res = evalJS (js_env , alloc , "console.join('\\ n');" , "console" ) catch unreachable ;
79- defer res .deinit (alloc ) ;
80- if (res . result .len > 0 ) {
81- std .debug .print ("-- CONSOLE LOG\n {s}\n --\n " , .{res . result });
78+ const res = evalJS (js_env , "console.join('\\ n');" , "console" ) catch unreachable ;
79+ const res_str = res .toString (alloc , js_env ) catch unreachable ;
80+ if (res_str .len > 0 ) {
81+ std .debug .print ("-- CONSOLE LOG\n {s}\n --\n " , .{res_str });
8282 }
8383 }
8484
@@ -89,7 +89,6 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
8989 try js_env .bindGlobal (& window );
9090
9191 // thanks to the arena, we don't need to deinit res.
92- var res : jsruntime.JSResult = undefined ;
9392
9493 const init =
9594 \\console = [];
@@ -100,11 +99,7 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
10099 \\ console.push("debug", ...arguments);
101100 \\};
102101 ;
103- res = try evalJS (js_env , alloc , init , "init" );
104- if (! res .success ) {
105- return res ;
106- }
107- res .deinit (alloc );
102+ _ = try evalJS (js_env , init , "init" );
108103
109104 // loop hover the scripts.
110105 const doc = parser .documentHTMLToDocument (html_doc );
@@ -121,22 +116,12 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
121116 path = try fspath .join (alloc , &.{ "/" , dirname , path });
122117 }
123118
124- res = try evalJS (js_env , alloc , try loader .get (path ), src );
125- if (! res .success ) {
126- return res ;
127- }
128- res .deinit (alloc );
119+ _ = try evalJS (js_env , try loader .get (path ), src );
129120 }
130121
131122 // If the script as a source text, execute it.
132123 const src = try parser .nodeTextContent (s ) orelse continue ;
133- res = try evalJS (js_env , alloc , src , "" );
134-
135- // return the first failure.
136- if (! res .success ) {
137- return res ;
138- }
139- res .deinit (alloc );
124+ _ = try evalJS (js_env , src , "" );
140125 }
141126
142127 // Mark tests as ready to run.
@@ -150,25 +135,18 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
150135 );
151136
152137 // wait for all async executions
153- res = try js_env .waitTryCatch (alloc );
154- if (! res .success ) {
155- return res ;
156- }
157- res .deinit (alloc );
138+ _ = try js_env .wait ();
158139
159140 // Check the final test status.
160- res = try evalJS (js_env , alloc , "report.status;" , "teststatus" );
161- if (! res .success ) {
162- return res ;
163- }
164- res .deinit (alloc );
141+ _ = try evalJS (js_env , "report.status;" , "teststatus" );
165142
166143 // return the detailed result.
167- return try evalJS (js_env , alloc , "report.log" , "teststatus" );
144+ const res = try evalJS (js_env , "report.log" , "teststatus" );
145+ return try res .toString (alloc , js_env );
168146}
169147
170- fn evalJS (env : jsruntime.Env , alloc : std.mem.Allocator , script : []const u8 , name : ? []const u8 ) ! jsruntime.JSResult {
171- return try env .execTryCatch ( alloc , script , name );
148+ fn evalJS (env : jsruntime.Env , script : []const u8 , name : ? []const u8 ) ! jsruntime.JSValue {
149+ return try env .exec ( script , name );
172150}
173151
174152// browse the path to find the tests list.
0 commit comments