tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

completion-values-fn-finally-normal.js (2122B)


      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(Normal) 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 // 1: try Return, catch Return, finally Normal; Completion: try
     20 var count = {
     21  catch: 0,
     22  finally: 0
     23 };
     24 
     25 var fn = function() {
     26  try {
     27    return 'try';
     28  } catch(e) {
     29    count.catch += 1;
     30    return 'catch';
     31  } finally {
     32    count.finally += 1;
     33    'normal';
     34  }
     35  return 'wat';
     36 };
     37 
     38 assert.sameValue(fn(), 'try', '1: try Return, catch Return, finally Normal; Completion: try');
     39 assert.sameValue(count.catch, 0, '1');
     40 assert.sameValue(count.finally, 1, '1');
     41 
     42 // 2: try Abrupt, catch Return, finally Normal; Completion: catch
     43 count.catch = 0;
     44 count.finally = 0;
     45 fn = function() {
     46  try {
     47    throw 'try';
     48  } catch(e) {
     49    count.catch += 1;
     50    return 'catch';
     51  } finally {
     52    count.finally += 1;
     53    'finally';
     54  }
     55  return 'wat';
     56 };
     57 
     58 assert.sameValue(fn(), 'catch', '2: try Abrupt, catch Return, finally Normal; Completion: catch');
     59 assert.sameValue(count.catch, 1, '2: catch count');
     60 assert.sameValue(count.finally, 1, '2: fiinally count');
     61 
     62 // 3: try Abrupt, catch Abrupt, finally Normal; Completion: catch
     63 count.catch = 0;
     64 count.finally = 0;
     65 fn = function() {
     66  try {
     67    throw 'try';
     68  } catch(e) {
     69    count.catch += 1;
     70    throw new Test262Error('catch');
     71  } finally {
     72    count.finally += 1;
     73    'finally';
     74  }
     75  return 'wat';
     76 };
     77 
     78 assert.throws(Test262Error, fn, '3: try Abrupt, catch Abrupt, finally Normal; Completion: catch');
     79 assert.sameValue(count.catch, 1, '3: catch count');
     80 assert.sameValue(count.finally, 1, '3: fiinally count');
     81 
     82 reportCompare(0, 0);