@@ -610,13 +610,12 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
610610
611611 // compile and eval a JS module
612612 // It doesn't wait for callbacks execution
613- pub fn module (self : * Scope , src : []const u8 , name : []const u8 ) ! Value {
613+ pub fn module (self : * Scope , src : []const u8 , name : []const u8 ) ! union ( enum ) { value : Value , exception : Exception } {
614614 const context = self .context ;
615615 const m = try compileModule (self .isolate , src , name );
616616
617617 // instantiate
618- // TODO handle ResolveModuleCallback parameters to load module's
619- // dependencies.
618+ // resolveModuleCallback loads module's dependencies.
620619 const ok = m .instantiate (context , resolveModuleCallback ) catch {
621620 return error .ExecutionError ;
622621 };
@@ -626,8 +625,18 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
626625 }
627626
628627 // evaluate
629- const value = m .evaluate (context ) catch return error .ExecutionError ;
630- return self .createValue (value );
628+ const value = m .evaluate (context ) catch {
629+ return .{ .exception = self .createException (m .getException ()) };
630+ };
631+ return .{ .value = self .createValue (value ) };
632+ }
633+
634+ // Wrap a v8.Exception
635+ fn createException (self : * const Scope , e : v8.Value ) Exception {
636+ return .{
637+ .inner = e ,
638+ .scope = self ,
639+ };
631640 }
632641
633642 // Wrap a v8.Value, largely so that we can provide a convenient
@@ -1133,6 +1142,17 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
11331142
11341143 pub const RemoteObject = v8 .RemoteObject ;
11351144
1145+ pub const Exception = struct {
1146+ inner : v8.Value ,
1147+ scope : * const Scope ,
1148+
1149+ // the caller needs to deinit the string returned
1150+ pub fn exception (self : Exception , allocator : Allocator ) ! []const u8 {
1151+ const scope = self .scope ;
1152+ return try valueToString (allocator , self .inner , scope .isolate , scope .context );
1153+ }
1154+ };
1155+
11361156 pub const Value = struct {
11371157 value : v8.Value ,
11381158 scope : * const Scope ,
0 commit comments