completion-values-fn-finally-abrupt.js (2353B)
1 // Copyright (C) 2020 Salesforce.com. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-try-statement-runtime-semantics-evaluation 6 description: > 7 Returns the correct completion values of try-catch-finally(Abrupt) in functions 8 info: | 9 TryStatement : try Block Catch Finally 10 11 Let B be the result of evaluating Block. 12 If B.[[Type]] is throw, let C be CatchClauseEvaluation of Catch with argument B.[[Value]]. 13 Else, let C be B. 14 Let F be the result of evaluating Finally. 15 If F.[[Type]] is normal, set F to C. 16 Return Completion(UpdateEmpty(F, undefined)). 17 ---*/ 18 19 var fn, count = {}; 20 21 // 1: try Abrupt, catch Abrupt, finally Abrupt; Completion: finally 22 count.catch = 0; 23 count.finally = 0; 24 fn = function() { 25 try { 26 throw 'try'; 27 } catch(e) { 28 count.catch += 1; 29 throw 'catch'; 30 } finally { 31 count.finally += 1; 32 throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C. 33 } 34 return 'wat'; 35 }; 36 37 assert.throws(Test262Error, fn, '1: try Abrupt, catch Abrupt, finally Abrupt; Completion: finally'); 38 assert.sameValue(count.catch, 1, '1: catch count'); 39 assert.sameValue(count.finally, 1, '1: finally count'); 40 41 // 2: try Abrupt, catch Return, finally Abrupt; Completion: finally 42 count.catch = 0; 43 count.finally = 0; 44 fn = function() { 45 try { 46 throw 'try'; 47 } catch(e) { 48 count.catch += 1; 49 return 'catch'; 50 } finally { 51 count.finally += 1; 52 throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C. 53 } 54 return 'wat'; 55 }; 56 57 assert.throws(Test262Error, fn, '2: try Abrupt, catch Return, finally Abrupt; Completion: finally'); 58 assert.sameValue(count.catch, 1, '2: catch count'); 59 assert.sameValue(count.finally, 1, '2: fiinally count'); 60 61 // 3: try Return, catch Return, finally Abrupt; Completion: finally 62 count.catch = 0; 63 count.finally = 0; 64 fn = function() { 65 try { 66 return 'try'; 67 } catch(e) { 68 count.catch += 1; 69 return 'catch'; 70 } finally { 71 count.finally += 1; 72 throw new Test262Error('finally'); // If F.[[Type]] is normal, set F to C. 73 } 74 return 'wat'; 75 }; 76 77 assert.throws(Test262Error, fn, '3: try Normal, catch Normal, finally Abrupt; Completion: finally'); 78 assert.sameValue(count.catch, 0, '3: catch count'); 79 assert.sameValue(count.finally, 1, '3: fiinally count'); 80 81 reportCompare(0, 0);