tor-browser

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

regress-94506.js (2513B)


      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 * Date: 08 August 2001
      8 *
      9 * SUMMARY: When we invoke a function, the arguments object should take
     10 *          a back seat to any local identifier named "arguments".
     11 *
     12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=94506
     13 */
     14 //-----------------------------------------------------------------------------
     15 var UBound = 0;
     16 var BUGNUMBER = 94506;
     17 var summary = 'Testing functions employing identifiers named "arguments"';
     18 var status = '';
     19 var statusitems = [];
     20 var actual = '';
     21 var actualvalues = [];
     22 var expect= '';
     23 var expectedvalues = [];
     24 var TYPE_OBJECT = typeof new Object();
     25 var arguments = 5555;
     26 
     27 
     28 // use a parameter named "arguments"
     29 function F1(arguments)
     30 {
     31  return arguments;
     32 }
     33 
     34 
     35 // use a local variable named "arguments"
     36 function F2()
     37 {
     38  var arguments = 55;
     39  return arguments;
     40 }
     41 
     42 
     43 // same thing in a different order. CHANGES THE RESULT!
     44 function F3()
     45 {
     46  return arguments;
     47  var arguments = 555;
     48 }
     49 
     50 
     51 // use the global variable above named "arguments"
     52 function F4()
     53 {
     54  return arguments;
     55 }
     56 
     57 
     58 
     59 /*
     60 * In Sections 1 and 2, expect the local identifier, not the arguments object.
     61 * In Sections 3 and 4, expect the arguments object, not the the identifier.
     62 */
     63 
     64 status = 'Section 1 of test';
     65 actual = F1(5);
     66 expect = 5;
     67 addThis();
     68 
     69 
     70 status = 'Section 2 of test';
     71 actual = F2();
     72 expect = 55;
     73 addThis();
     74 
     75 
     76 status = 'Section 3 of test';
     77 actual = typeof F3();
     78 expect = TYPE_OBJECT;
     79 addThis();
     80 
     81 
     82 status = 'Section 4 of test';
     83 actual = typeof F4();
     84 expect = TYPE_OBJECT;
     85 addThis();
     86 
     87 
     88 // Let's try calling F1 without providing a parameter -
     89 status = 'Section 5 of test';
     90 actual = F1();
     91 expect = undefined;
     92 addThis();
     93 
     94 
     95 // Let's try calling F1 with too many parameters -
     96 status = 'Section 6 of test';
     97 actual = F1(3,33,333);
     98 expect = 3;
     99 addThis();
    100 
    101 
    102 
    103 //-----------------------------------------------------------------------------
    104 test();
    105 //-----------------------------------------------------------------------------
    106 
    107 
    108 function addThis()
    109 {
    110  statusitems[UBound] = status;
    111  actualvalues[UBound] = actual;
    112  expectedvalues[UBound] = expect;
    113  UBound++;
    114 }
    115 
    116 
    117 function test()
    118 {
    119  printBugNumber(BUGNUMBER);
    120  printStatus (summary);
    121 
    122  for (var i = 0; i < UBound; i++)
    123  {
    124    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    125  }
    126 }