@@ -151,7 +151,7 @@ pub const Case = struct {
151151};
152152
153153// a shorthand function to run a script within a JS env
154- // without providing a JS result
154+ // with local TryCatch
155155// - on success, do nothing
156156// - on error, log error the JS result and JS stack if available
157157pub fn runScript (
@@ -161,18 +161,21 @@ pub fn runScript(
161161 name : []const u8 ,
162162) ! void {
163163
164- // init result
165- var res = public.JSResult {};
166- defer res .deinit (alloc );
167-
168- try js_env .execWait (alloc , script , name , & res , null );
164+ // local try catch
165+ var try_catch : public.TryCatch = undefined ;
166+ try_catch .init (js_env .* );
167+ defer try_catch .deinit ();
169168
170169 // check result
171- if ( ! res . success ) {
172- std . log . err ( "script {s} error: {s} \n " , .{ name , res . result });
173- if ( res . stack ) | stack | {
174- std .log .err ("script {s} stack : {s}\n " , .{ name , stack });
170+ _ = js_env . execWait ( script , name ) catch | err | {
171+ if ( try try_catch . exception ( alloc , js_env .* )) | msg | {
172+ defer alloc . free ( msg );
173+ std .log .err ("script {s} error : {s}\n " , .{ name , msg });
175174 }
176- return error .Script ;
177- }
175+ if (try try_catch .stack (alloc , js_env .* )) | msg | {
176+ defer alloc .free (msg );
177+ std .log .err ("script {s} stack: {s}\n " , .{ name , msg });
178+ }
179+ return err ;
180+ };
178181}
0 commit comments