js/src/tests/js1_5/Regress/regress-104077.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Regress/regress-104077.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,473 @@
     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 + *
    1.11 + * Date: 10 October 2001
    1.12 + * SUMMARY: Regression test for Bugzilla bug 104077
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077
    1.14 + * "JS crash: with/finally/return"
    1.15 + *
    1.16 + * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571
    1.17 + * "JS crash: try/catch/continue."
    1.18 + *
    1.19 + * SpiderMonkey crashed on this code - it shouldn't.
    1.20 + *
    1.21 + * NOTE: the finally-blocks below should execute even if their try-blocks
    1.22 + * have return or throw statements in them:
    1.23 + *
    1.24 + * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 -------
    1.25 + * finally trumps return, and all other control-flow constructs that cause
    1.26 + * program execution to jump out of the try block: throw, break, etc.  Once you
    1.27 + * enter a try block, you will execute the finally block after leaving the try,
    1.28 + * regardless of what happens to make you leave the try.
    1.29 + *
    1.30 + */
    1.31 +//-----------------------------------------------------------------------------
    1.32 +var UBound = 0;
    1.33 +var BUGNUMBER = 104077;
    1.34 +var summary = "Just testing that we don't crash on with/finally/return -";
    1.35 +var status = '';
    1.36 +var statusitems = [];
    1.37 +var actual = '';
    1.38 +var actualvalues = [];
    1.39 +var expect= '';
    1.40 +var expectedvalues = [];
    1.41 +
    1.42 +
    1.43 +function addValues(obj)
    1.44 +{
    1.45 +  var sum;
    1.46 +  with (obj)
    1.47 +  {
    1.48 +    try
    1.49 +    {
    1.50 +      sum = arg1 + arg2;
    1.51 +    }
    1.52 +    finally
    1.53 +    {
    1.54 +      return sum;
    1.55 +    }
    1.56 +  }
    1.57 +}
    1.58 +
    1.59 +status = inSection(1);
    1.60 +var obj = new Object();
    1.61 +obj.arg1 = 1;
    1.62 +obj.arg2 = 2;
    1.63 +actual = addValues(obj);
    1.64 +expect = 3;
    1.65 +captureThis();
    1.66 +
    1.67 +
    1.68 +
    1.69 +function tryThis()
    1.70 +{
    1.71 +  var sum = 4 ;
    1.72 +  var i = 0;
    1.73 +
    1.74 +  while (sum < 10)
    1.75 +  {
    1.76 +    try
    1.77 +    {
    1.78 +      sum += 1;
    1.79 +      i += 1;
    1.80 +    }
    1.81 +    finally
    1.82 +    {
    1.83 +      print("In finally case of tryThis() function");
    1.84 +    }
    1.85 +  }
    1.86 +  return i;
    1.87 +}
    1.88 +
    1.89 +status = inSection(2);
    1.90 +actual = tryThis();
    1.91 +expect = 6;
    1.92 +captureThis();
    1.93 +
    1.94 +
    1.95 +
    1.96 +function myTest(x)
    1.97 +{
    1.98 +  var obj = new Object();
    1.99 +  var msg;
   1.100 +
   1.101 +  with (obj)
   1.102 +  {
   1.103 +    msg = (x != null) ? "NO" : "YES";
   1.104 +    print("Is the provided argument to myTest() null? : " + msg);
   1.105 +
   1.106 +    try
   1.107 +    {
   1.108 +      throw "ZZZ";
   1.109 +    }
   1.110 +    catch(e)
   1.111 +    {
   1.112 +      print("Caught thrown exception = " + e);
   1.113 +    }
   1.114 +  }
   1.115 +
   1.116 +  return 1;
   1.117 +}
   1.118 +
   1.119 +status = inSection(3);
   1.120 +actual = myTest(null);
   1.121 +expect = 1;
   1.122 +captureThis();
   1.123 +
   1.124 +
   1.125 +
   1.126 +function addValues_2(obj)
   1.127 +{
   1.128 +  var sum = 0;
   1.129 +  with (obj)
   1.130 +  {
   1.131 +    try
   1.132 +    {
   1.133 +      sum = arg1 + arg2;
   1.134 +      with (arg3)
   1.135 +      {
   1.136 +        while (sum < 10)
   1.137 +        {
   1.138 +          try
   1.139 +          {
   1.140 +            if (sum > 5)
   1.141 +              return sum;
   1.142 +            sum += 1;
   1.143 +          }
   1.144 +          catch(e)
   1.145 +          {
   1.146 +            print('Caught an exception in addValues_2() function: ' + e);
   1.147 +          }
   1.148 +        }
   1.149 +      }
   1.150 +    }
   1.151 +    finally
   1.152 +    {
   1.153 +      return sum;
   1.154 +    }
   1.155 +  }
   1.156 +}
   1.157 +
   1.158 +status = inSection(4);
   1.159 +obj = new Object();
   1.160 +obj.arg1 = 1;
   1.161 +obj.arg2 = 2;
   1.162 +obj.arg3 = new Object();
   1.163 +obj.arg3.a = 10;
   1.164 +obj.arg3.b = 20;
   1.165 +actual = addValues_2(obj);
   1.166 +expect = 6;
   1.167 +captureThis();
   1.168 +
   1.169 +
   1.170 +
   1.171 +status = inSection(5);
   1.172 +try
   1.173 +{
   1.174 +  throw new A();
   1.175 +}
   1.176 +catch(e)
   1.177 +{
   1.178 +}
   1.179 +finally
   1.180 +{
   1.181 +  try
   1.182 +  {
   1.183 +    throw new A();
   1.184 +  }
   1.185 +  catch(e)
   1.186 +  {
   1.187 +  }
   1.188 +  finally
   1.189 +  {
   1.190 +    actual = 'a';
   1.191 +  }
   1.192 +  actual = 'b';
   1.193 +}
   1.194 +expect = 'b';
   1.195 +captureThis();
   1.196 +
   1.197 +
   1.198 +
   1.199 +
   1.200 +function testfunc(mode)
   1.201 +{
   1.202 +  var obj = new Object();
   1.203 +  with (obj)
   1.204 +  {
   1.205 +    var num = 100;
   1.206 +    var str = "abc" ;
   1.207 +
   1.208 +    if (str == null)
   1.209 +    {
   1.210 +      try
   1.211 +      {
   1.212 +        throw "authentication.0";
   1.213 +      }
   1.214 +      catch(e)
   1.215 +      {
   1.216 +      }
   1.217 +      finally
   1.218 +      {
   1.219 +      }
   1.220 +
   1.221 +      return num;
   1.222 +    }
   1.223 +    else
   1.224 +    {
   1.225 +      try
   1.226 +      {
   1.227 +        if (mode == 0)
   1.228 +          throw "authentication.0";
   1.229 +        else
   1.230 +          mytest();
   1.231 +      }
   1.232 +      catch(e)
   1.233 +      {
   1.234 +      }
   1.235 +      finally
   1.236 +      {
   1.237 +      }
   1.238 +
   1.239 +      return num;
   1.240 +    }
   1.241 +  }
   1.242 +}
   1.243 +
   1.244 +status = inSection(6);
   1.245 +actual = testfunc(0);
   1.246 +expect = 100;
   1.247 +captureThis();
   1.248 +
   1.249 +status = inSection(7);
   1.250 +actual = testfunc();
   1.251 +expect = 100; 
   1.252 +captureThis();
   1.253 +
   1.254 +
   1.255 +
   1.256 +
   1.257 +function entry_menu()
   1.258 +{
   1.259 +  var document = new Object();
   1.260 +  var dialog = new Object();
   1.261 +  var num = 100;
   1.262 +
   1.263 +  with (document)
   1.264 +  {
   1.265 +    with (dialog)
   1.266 +    {
   1.267 +      try
   1.268 +      {
   1.269 +        while (true)
   1.270 +        {
   1.271 +          return num;
   1.272 +        }
   1.273 +      }
   1.274 +      finally
   1.275 +      {
   1.276 +      }
   1.277 +    }
   1.278 +  }
   1.279 +}
   1.280 +
   1.281 +status = inSection(8);
   1.282 +actual = entry_menu();
   1.283 +expect = 100;
   1.284 +captureThis();
   1.285 +
   1.286 +
   1.287 +
   1.288 +
   1.289 +function addValues_5(obj)
   1.290 +{
   1.291 +  var sum = 0;
   1.292 +
   1.293 +  with (obj)
   1.294 +  {
   1.295 +    try
   1.296 +    {
   1.297 +      sum = arg1 + arg2;
   1.298 +      with (arg3)
   1.299 +      {
   1.300 +        while (sum < 10)
   1.301 +        {
   1.302 +          try
   1.303 +          {
   1.304 +	    if (sum > 5)
   1.305 +	      return sum;
   1.306 +	    sum += 1;
   1.307 +          }
   1.308 +          catch (e)
   1.309 +          {
   1.310 +            sum += 1;
   1.311 +          }
   1.312 +        }
   1.313 +      }
   1.314 +    }
   1.315 +    finally
   1.316 +    {
   1.317 +      try
   1.318 +      {
   1.319 +        sum += 1;
   1.320 +        print("In finally block of addValues_5() function: sum = " + sum);
   1.321 +      }
   1.322 +      catch (e)
   1.323 +      {
   1.324 +        sum += 1;
   1.325 +        print("In finally catch block of addValues_5() function: sum = " + sum + ", e = " + e);
   1.326 +      }
   1.327 +      finally
   1.328 +      {
   1.329 +        sum += 1;
   1.330 +        print("In finally finally block of addValues_5() function: sum = " + sum);
   1.331 +        return sum;
   1.332 +      }
   1.333 +    }
   1.334 +  }
   1.335 +}
   1.336 +
   1.337 +status = inSection(11);
   1.338 +obj = new Object();
   1.339 +obj.arg1 = 1;
   1.340 +obj.arg2 = 2;
   1.341 +obj.arg3 = new Object();
   1.342 +obj.arg3.a = 10;
   1.343 +obj.arg3.b = 20;
   1.344 +actual = addValues_5(obj);
   1.345 +expect = 8;
   1.346 +captureThis();
   1.347 +
   1.348 +
   1.349 +
   1.350 +
   1.351 +function testObj(obj)
   1.352 +{
   1.353 +  var x = 42;
   1.354 +
   1.355 +  try
   1.356 +  {
   1.357 +    with (obj)
   1.358 +    {
   1.359 +      if (obj.p)
   1.360 +        throw obj.p;
   1.361 +      x = obj.q;
   1.362 +    }
   1.363 +  }
   1.364 +  finally
   1.365 +  {
   1.366 +    print("in finally block of testObj() function");
   1.367 +    return 999;
   1.368 +  }
   1.369 +}
   1.370 +
   1.371 +status = inSection(12);
   1.372 +obj = {p:43};
   1.373 +actual = testObj(obj);
   1.374 +expect = 999;
   1.375 +captureThis();
   1.376 +
   1.377 +
   1.378 +
   1.379 +/*
   1.380 + * Next two cases are from http://bugzilla.mozilla.org/show_bug.cgi?id=120571
   1.381 + */
   1.382 +function a120571()
   1.383 +{
   1.384 +  while(0)
   1.385 +  {
   1.386 +    try
   1.387 +    {
   1.388 +    }
   1.389 +    catch(e)
   1.390 +    {
   1.391 +      continue;
   1.392 +    }
   1.393 +  }
   1.394 +}
   1.395 +
   1.396 +// this caused a crash! Test to see that it doesn't now.
   1.397 +print(a120571);
   1.398 +
   1.399 +// Now test that we have a non-null value for a120571.toString()
   1.400 +status = inSection(13);
   1.401 +try
   1.402 +{
   1.403 +  actual = a120571.toString().match(/continue/)[0];
   1.404 +}
   1.405 +catch(e)
   1.406 +{
   1.407 +  actual = 'FAILED! Did not find "continue" in function body';
   1.408 +}
   1.409 +expect = 'continue';
   1.410 +captureThis();
   1.411 +
   1.412 +
   1.413 +
   1.414 +
   1.415 +function b()
   1.416 +{
   1.417 +  for(;;)
   1.418 +  {
   1.419 +    try
   1.420 +    {
   1.421 +    }
   1.422 +    catch(e)
   1.423 +    {
   1.424 +      continue;
   1.425 +    }
   1.426 +  }
   1.427 +}
   1.428 +
   1.429 +// this caused a crash!!! Test to see that it doesn't now.
   1.430 +print(b);
   1.431 +
   1.432 +// Now test that we have a non-null value for b.toString()
   1.433 +status = inSection(14);
   1.434 +try
   1.435 +{
   1.436 +  actual = b.toString().match(/continue/)[0];
   1.437 +}
   1.438 +catch(e)
   1.439 +{
   1.440 +  actual = 'FAILED! Did not find "continue" in function body';
   1.441 +}
   1.442 +expect = 'continue';
   1.443 +captureThis();
   1.444 +
   1.445 +
   1.446 +
   1.447 +
   1.448 +
   1.449 +//-----------------------------------------------------------------------------
   1.450 +test();
   1.451 +//-----------------------------------------------------------------------------
   1.452 +
   1.453 +
   1.454 +
   1.455 +function captureThis()
   1.456 +{
   1.457 +  statusitems[UBound] = status;
   1.458 +  actualvalues[UBound] = actual;
   1.459 +  expectedvalues[UBound] = expect;
   1.460 +  UBound++;
   1.461 +}
   1.462 +
   1.463 +
   1.464 +function test()
   1.465 +{
   1.466 +  enterFunc ('test');
   1.467 +  printBugNumber(BUGNUMBER);
   1.468 +  printStatus (summary);
   1.469 +
   1.470 +  for (var i=0; i<UBound; i++)
   1.471 +  {
   1.472 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.473 +  }
   1.474 +
   1.475 +  exitFunc ('test');
   1.476 +}

mercurial