File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,26 @@ function assert_trap(action, source) {
281281 . catch ( _ => { } ) ;
282282}
283283
284+ function assert_exception ( action , source ) {
285+ const test = `Test that a WebAssembly code throws an exception (${ source } )` ;
286+ const loc = new Error ( ) . stack . toString ( ) . replace ( "Error" , "" ) ;
287+ chain = Promise . all ( [ chain , action ( ) ] )
288+ . then (
289+ result => {
290+ uniqueTest ( _ => {
291+ assert_true ( false , loc ) ;
292+ } , test ) ;
293+ } ,
294+ error => {
295+ uniqueTest ( _ => {
296+ // Pass
297+ } , test ) ;
298+ }
299+ )
300+ // Clear all exceptions, so that subsequent tests get executed.
301+ . catch ( _ => { } ) ;
302+ }
303+
284304function assert_return ( action , source , ...expected ) {
285305 const test = `Test that a WebAssembly code returns a specific result (${ source } )` ;
286306 const loc = new Error ( ) . stack . toString ( ) . replace ( "Error" , "" ) ;
@@ -355,7 +375,7 @@ try {
355375}
356376
357377function assert_exhaustion ( action ) {
358- const test = "Test that a WebAssembly code exhauts the stack space" ;
378+ const test = "Test that a WebAssembly code exhausts the stack space" ;
359379 const loc = new Error ( ) . stack . toString ( ) . replace ( "Error" , "" ) ;
360380 chain = Promise . all ( [ action ( ) , chain ] )
361381 . then (
Original file line number Diff line number Diff line change @@ -339,6 +339,16 @@ function assert_trap(action, source) {
339339 } , `A wast module that must trap at runtime. (${ source } )` ) ;
340340}
341341
342+ function assert_exception ( action , source ) {
343+ let result = action ( ) ;
344+
345+ _assert ( result instanceof Result ) ;
346+
347+ uniqueTest ( ( ) => {
348+ assert_true ( result . isError ( ) , 'expected error result' ) ;
349+ } , `A wast module that must throw an exception at runtime. (${ source } )` ) ;
350+ }
351+
342352let StackOverflow ;
343353try { ( function f ( ) { 1 + f ( ) } ) ( ) } catch ( e ) { StackOverflow = e . constructor }
344354
You can’t perform that action at this time.
0 commit comments