js/src/tests/js1_5/Scope/regress-77578-001.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Scope/regress-77578-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,150 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Date: 2001-07-11
    1.11 + *
    1.12 + * SUMMARY: Testing eval scope inside a function.
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=77578
    1.14 + */
    1.15 +//-----------------------------------------------------------------------------
    1.16 +var UBound = 0;
    1.17 +var BUGNUMBER = 77578;
    1.18 +var summary = 'Testing eval scope inside a function';
    1.19 +var cnEquals = '=';
    1.20 +var status = '';
    1.21 +var statusitems = [];
    1.22 +var actual = '';
    1.23 +var actualvalues = [];
    1.24 +var expect= '';
    1.25 +var expectedvalues = [];
    1.26 +
    1.27 +
    1.28 +// various versions of JavaScript -
    1.29 +var JS_VER = [100, 110, 120, 130, 140, 150];
    1.30 +
    1.31 +// Note contrast with local variables i,j,k defined below -
    1.32 +var i = 999;
    1.33 +var j = 999;
    1.34 +var k = 999;
    1.35 +
    1.36 +
    1.37 +//--------------------------------------------------
    1.38 +test();
    1.39 +//--------------------------------------------------
    1.40 +
    1.41 +
    1.42 +function test()
    1.43 +{
    1.44 +  enterFunc ('test');
    1.45 +  printBugNumber(BUGNUMBER);
    1.46 +  printStatus (summary);
    1.47 +
    1.48 +  // Run tests A,B,C on each version of JS and store results
    1.49 +  for (var n=0; n!=JS_VER.length; n++)
    1.50 +  {
    1.51 +    testA(JS_VER[n]);
    1.52 +  }
    1.53 +  for (var n=0; n!=JS_VER.length; n++)
    1.54 +  {
    1.55 +    testB(JS_VER[n]);
    1.56 +  }
    1.57 +  for (var n=0; n!=JS_VER.length; n++)
    1.58 +  {
    1.59 +    testC(JS_VER[n]);
    1.60 +  }
    1.61 +
    1.62 +
    1.63 +  // Compare actual values to expected values -
    1.64 +  for (var i=0; i<UBound; i++)
    1.65 +  {
    1.66 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    1.67 +  }
    1.68 +
    1.69 +  exitFunc ('test');
    1.70 +}
    1.71 +
    1.72 +
    1.73 +function testA(ver)
    1.74 +{
    1.75 +  // Set the version of JS to test -
    1.76 +  if (typeof version == 'function')
    1.77 +  {
    1.78 +    version(ver);
    1.79 +  }
    1.80 +
    1.81 +  // eval the test, so it compiles AFTER version() has executed -
    1.82 +  var sTestScript = "";
    1.83 +
    1.84 +  // Define a local variable i
    1.85 +  sTestScript += "status = 'Section A of test; JS ' + ver/100;";
    1.86 +  sTestScript += "var i=1;";
    1.87 +  sTestScript += "actual = eval('i');";
    1.88 +  sTestScript += "expect = 1;";
    1.89 +  sTestScript += "captureThis('i');";
    1.90 +
    1.91 +  eval(sTestScript);
    1.92 +}
    1.93 +
    1.94 +
    1.95 +function testB(ver)
    1.96 +{
    1.97 +  // Set the version of JS to test -
    1.98 +  if (typeof version == 'function')
    1.99 +  {
   1.100 +    version(ver);
   1.101 +  }
   1.102 +
   1.103 +  // eval the test, so it compiles AFTER version() has executed -
   1.104 +  var sTestScript = "";
   1.105 +
   1.106 +  // Define a local for-loop iterator j
   1.107 +  sTestScript += "status = 'Section B of test; JS ' + ver/100;";
   1.108 +  sTestScript += "for(var j=1; j<2; j++)";
   1.109 +  sTestScript += "{";
   1.110 +  sTestScript += "  actual = eval('j');";
   1.111 +  sTestScript += "};";
   1.112 +  sTestScript += "expect = 1;";
   1.113 +  sTestScript += "captureThis('j');";
   1.114 +
   1.115 +  eval(sTestScript);
   1.116 +}
   1.117 +
   1.118 +
   1.119 +function testC(ver)
   1.120 +{
   1.121 +  // Set the version of JS to test -
   1.122 +  if (typeof version == 'function')
   1.123 +  {
   1.124 +    version(ver);
   1.125 +  }
   1.126 +
   1.127 +  // eval the test, so it compiles AFTER version() has executed -
   1.128 +  var sTestScript = "";
   1.129 +
   1.130 +  // Define a local variable k in a try-catch block -
   1.131 +  sTestScript += "status = 'Section C of test; JS ' + ver/100;";
   1.132 +  sTestScript += "try";
   1.133 +  sTestScript += "{";
   1.134 +  sTestScript += "  var k=1;";
   1.135 +  sTestScript += "  actual = eval('k');";
   1.136 +  sTestScript += "}";
   1.137 +  sTestScript += "catch(e)";
   1.138 +  sTestScript += "{";
   1.139 +  sTestScript += "};";
   1.140 +  sTestScript += "expect = 1;";
   1.141 +  sTestScript += "captureThis('k');";
   1.142 +
   1.143 +  eval(sTestScript);
   1.144 +}
   1.145 +
   1.146 +
   1.147 +function captureThis(varName)
   1.148 +{
   1.149 +  statusitems[UBound] = status;
   1.150 +  actualvalues[UBound] = varName + cnEquals + actual;
   1.151 +  expectedvalues[UBound] = varName + cnEquals + expect;
   1.152 +  UBound++;
   1.153 +}

mercurial