js/src/tests/js1_7/regress/regress-418641.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_7/regress/regress-418641.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     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 +var BUGNUMBER = 418641;
    1.11 +var summary = '++ and -- correctness';
    1.12 +var actual = '';
    1.13 +var expect = '';
    1.14 +
    1.15 +printBugNumber(BUGNUMBER);
    1.16 +printStatus (summary);
    1.17 + 
    1.18 +function get_pre_check(operand, op)
    1.19 +{
    1.20 +  return "{\n"+
    1.21 +    "    "+operand+" = I;\n"+
    1.22 +    "    let tmp = "+op+op+operand+";\n"+
    1.23 +    "    if ("+operand+" !== Number(I) "+op+" 1)\n"+
    1.24 +    "        throw Error('"+op+op+operand+" case 1 for '+uneval(I));\n"+
    1.25 +    "    if (tmp !== "+operand+")\n"+
    1.26 +    "        throw Error('"+op+op+operand+" case 2 for '+uneval(I));\n"+
    1.27 +    "}\n";    
    1.28 +}
    1.29 +
    1.30 +function get_post_check(operand, op)
    1.31 +{
    1.32 +  return "{\n"+
    1.33 +    "    "+operand+" = I;\n"+
    1.34 +    "    let tmp = "+operand+op+op+";\n"+
    1.35 +    "    if ("+operand+" !== Number(I) "+op+" 1)\n"+
    1.36 +    "        throw Error('"+operand+op+op+" case 1 for '+uneval(I));\n"+
    1.37 +    "    if (tmp !== Number(I))\n"+
    1.38 +    "        throw Error('"+op+op+operand+" case 2 for '+uneval(I));\n"+
    1.39 +    "}\n";    
    1.40 +}
    1.41 +
    1.42 +function get_check_source(operand)
    1.43 +{
    1.44 +  return get_pre_check(operand, '+')+
    1.45 +    get_pre_check(operand, '-')+
    1.46 +    get_post_check(operand, '+')+
    1.47 +    get_post_check(operand, '-');
    1.48 +}
    1.49 +
    1.50 +var arg_check = Function('I', 'a', get_check_source('a'));
    1.51 +var let_check = Function('I', 'let a;'+get_check_source('a'));
    1.52 +var var_check = Function('I', 'var a;'+get_check_source('a'));
    1.53 +
    1.54 +var my_name;
    1.55 +var my_obj = {};
    1.56 +var my_index = 0;
    1.57 +var name_check = Function('I', get_check_source('my_name'));
    1.58 +var prop_check = Function('I', get_check_source('my_obj.x'));
    1.59 +var elem_check = Function('I', get_check_source('my_obj[my_index]'));
    1.60 +
    1.61 +var test_values = [0 , 0.5, -0.0, (1 << 30) - 1, 1 - (1 << 30)];
    1.62 +
    1.63 +for (let i = 0; i != test_values.length; i = i + 1) {
    1.64 +  let x = [test_values[i], String(test_values[i])];
    1.65 +  for (let j = 0; j != x.length; j = j + 1) {
    1.66 +    try
    1.67 +    {
    1.68 +      expect = actual = 'No Error';
    1.69 +      let test_value = x[j];
    1.70 +      arg_check(test_value, 0);
    1.71 +      let_check(test_value);
    1.72 +      var_check(test_value);
    1.73 +      name_check(test_value);
    1.74 +      prop_check(test_value);
    1.75 +      elem_check(test_value);
    1.76 +    }
    1.77 +    catch(ex)
    1.78 +    {
    1.79 +      actual = ex + '';
    1.80 +    }
    1.81 +    reportCompare(expect, actual, summary + ': ' + i + ', ' + j);
    1.82 +  }
    1.83 +}

mercurial