tor-browser

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

regress-118849.js (3401B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 *
      8 * Date:    08 Jan 2002
      9 * SUMMARY: Just testing that we don't crash on this code
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=118849
     11 *
     12 * http://developer.netscape.com:80/docs/manuals/js/core/jsref/function.htm
     13 * The Function constructor:
     14 * Function ([arg1[, arg2[, ... argN]],] functionBody)
     15 *
     16 * Parameters
     17 * arg1, arg2, ... argN
     18 *   (Optional) Names to be used by the function as formal argument names.
     19 *   Each must be a string that corresponds to a valid JavaScript identifier.
     20 *
     21 * functionBody
     22 *   A string containing JS statements comprising the function definition.
     23 */
     24 //-----------------------------------------------------------------------------
     25 var UBound = 0;
     26 var BUGNUMBER = 118849;
     27 var summary = 'Should not crash if we provide Function() with bad arguments'
     28  var status = '';
     29 var statusitems = [];
     30 var actual = '';
     31 var actualvalues = [];
     32 var expect= '';
     33 var expectedvalues = [];
     34 var cnFAIL_1 = 'LEGAL call to Function() caused an ERROR!!!';
     35 var cnFAIL_2 = 'ILLEGAL call to Function() FAILED to cause an error';
     36 var cnSTRING = 'ASDF';
     37 var cnNUMBER = 123;
     38 
     39 
     40 /***********************************************************/
     41 /****  THESE ARE LEGITMATE CALLS AND SHOULD ALL SUCCEED  ***/
     42 /***********************************************************/
     43 status = inSection(1);
     44 actual = cnFAIL_1; // initialize to failure
     45 try
     46 {
     47  Function(cnSTRING);
     48  Function(cnNUMBER);  // cnNUMBER is a valid functionBody       
     49  Function(cnSTRING,cnSTRING);
     50  Function(cnSTRING,cnNUMBER);
     51  Function(cnSTRING,cnSTRING,cnNUMBER);
     52 
     53  new Function(cnSTRING);
     54  new Function(cnNUMBER);
     55  new Function(cnSTRING,cnSTRING);
     56  new Function(cnSTRING,cnNUMBER);
     57  new Function(cnSTRING,cnSTRING,cnNUMBER);
     58 
     59  actual = expect;
     60 }
     61 catch(e)
     62 {
     63 }
     64 addThis();
     65 
     66 
     67 
     68 /**********************************************************/
     69 /***  EACH CASE THAT FOLLOWS SHOULD TRIGGER AN ERROR    ***/
     70 /***               (BUT NOT A CRASH)                    ***/
     71 /***  NOTE WE NOW USE cnFAIL_2 INSTEAD OF cnFAIL_1      ***/
     72 /**********************************************************/
     73 status = inSection(2);
     74 actual = cnFAIL_2;
     75 try
     76 {
     77  Function(cnNUMBER,cnNUMBER); // cnNUMBER is an invalid JS identifier name
     78 }
     79 catch(e)
     80 {
     81  actual = expect;
     82 }
     83 addThis();
     84 
     85 
     86 status = inSection(3);
     87 actual = cnFAIL_2;
     88 try
     89 {
     90  Function(cnNUMBER,cnSTRING,cnSTRING);
     91 }
     92 catch(e)
     93 {
     94  actual = expect;
     95 }
     96 addThis();
     97 
     98 
     99 status = inSection(4);
    100 actual = cnFAIL_2;
    101 try
    102 {
    103  new Function(cnNUMBER,cnNUMBER);
    104 }
    105 catch(e)
    106 {
    107  actual = expect;
    108 }
    109 addThis();
    110 
    111 
    112 status = inSection(5);
    113 actual = cnFAIL_2;
    114 try
    115 {
    116  new Function(cnNUMBER,cnSTRING,cnSTRING);
    117 }
    118 catch(e)
    119 {
    120  actual = expect;
    121 }
    122 addThis();
    123 
    124 
    125 
    126 //-----------------------------------------------------------------------------
    127 test();
    128 //-----------------------------------------------------------------------------
    129 
    130 
    131 function addThis()
    132 {
    133  statusitems[UBound] = status;
    134  actualvalues[UBound] = actual;
    135  expectedvalues[UBound] = expect;
    136  UBound++;
    137 }
    138 
    139 
    140 function test()
    141 {
    142  printBugNumber(BUGNUMBER);
    143  printStatus (summary);
    144 
    145  for (var i = 0; i < UBound; i++)
    146  {
    147    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    148  }
    149 }