@@ -287,74 +287,90 @@ test("return from nested finally", () => {
287287} ) ;
288288
289289test ( "throw and catch custom error object" , ( ) => {
290- const code = `
290+ util . testFunction `
291291 try {
292292 throw { x: "Hello error object!" };
293293 } catch (error) {
294294 return error.x;
295295 }
296- ` ;
297- expect ( util . transpileAndExecute ( code ) ) . toBe ( "Hello error object!" ) ;
296+ ` . expectToMatchJsResult ( ) ;
298297} ) ;
299298
300299test . each ( [ "Error" , "RangeError" , "ReferenceError" , "SyntaxError" , "TypeError" , "URIError" ] ) (
301300 "throw builtin Errors as classes" ,
302301 errorType => {
303- const code = `
302+ util . testFunction `
304303 try {
305304 throw new ${ errorType } ("message")
306305 } catch (error) {
307306 if (error instanceof Error) {
308307 return \`\${error}\`;
308+ } else {
309+ throw TypeError();
309310 }
310311 }
311- ` ;
312- expect ( util . transpileAndExecute ( code ) ) . toBe ( `${ errorType } : message` ) ;
312+ `
313+ . expectNoExecutionError ( )
314+ . expectToMatchJsResult ( ) ;
313315 }
314316) ;
315317
316318test . each ( [ "Error" , "RangeError" , "ReferenceError" , "SyntaxError" , "TypeError" , "URIError" ] ) (
317319 "throw builtin Errors as functions" ,
318320 errorType => {
319- const code = `
321+ util . testFunction `
320322 try {
321323 throw ${ errorType } ("message")
322324 } catch (error) {
323325 if (error instanceof Error) {
324326 return \`\${error}\`;
327+ } else {
328+ throw TypeError();
325329 }
326330 }
327- ` ;
328- expect ( util . transpileAndExecute ( code ) ) . toBe ( `${ errorType } : message` ) ;
331+ `
332+ . expectNoExecutionError ( )
333+ . expectToMatchJsResult ( ) ;
329334 }
330335) ;
331336
332337test ( "get stack from builtin error object" , ( ) => {
333- const code = `
338+ const stack = util . testFunction `
334339 function innerFunctionThatThrows() { throw RangeError(); }
335340 function outerFunctionThatThrows() { innerFunctionThatThrows(); }
336341 try {
337342 outerFunctionThatThrows();
338343 } catch (error) {
339344 if (error instanceof Error) {
340345 return error.stack;
346+ } else {
347+ throw TypeError();
341348 }
342349 }
343- ` ;
344- const stack = util . transpileAndExecute ( code ) ;
350+ `
351+ . expectNoExecutionError ( )
352+ . getLuaExecutionResult ( ) ;
353+
345354 expect ( stack ) . toMatch ( "innerFunctionThatThrows" ) ;
346355 expect ( stack ) . toMatch ( "outerFunctionThatThrows" ) ;
347356} ) ;
348357
349358test ( "subclass Error" , ( ) => {
350- const code = `
351- class MyError extends Error { }
359+ util . testFunction `
360+ class MyError extends Error {
361+ name: "MyError"
362+ }
352363
353364 try {
354365 throw new MyError();
355366 } catch (error) {
356- return error instanceof Error;
367+ if (error instanceof Error) {
368+ return error.name;
369+ } else {
370+ throw TypeError();
371+ }
357372 }
358- ` ;
359- expect ( util . transpileAndExecute ( code ) ) . toBe ( true ) ;
373+ `
374+ . expectNoExecutionError ( )
375+ . expectToMatchJsResult ( ) ;
360376} ) ;
0 commit comments