michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 418641; michael@0: var summary = '++ and -- correctness'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: function get_pre_check(operand, op) michael@0: { michael@0: return "{\n"+ michael@0: " "+operand+" = I;\n"+ michael@0: " let tmp = "+op+op+operand+";\n"+ michael@0: " if ("+operand+" !== Number(I) "+op+" 1)\n"+ michael@0: " throw Error('"+op+op+operand+" case 1 for '+uneval(I));\n"+ michael@0: " if (tmp !== "+operand+")\n"+ michael@0: " throw Error('"+op+op+operand+" case 2 for '+uneval(I));\n"+ michael@0: "}\n"; michael@0: } michael@0: michael@0: function get_post_check(operand, op) michael@0: { michael@0: return "{\n"+ michael@0: " "+operand+" = I;\n"+ michael@0: " let tmp = "+operand+op+op+";\n"+ michael@0: " if ("+operand+" !== Number(I) "+op+" 1)\n"+ michael@0: " throw Error('"+operand+op+op+" case 1 for '+uneval(I));\n"+ michael@0: " if (tmp !== Number(I))\n"+ michael@0: " throw Error('"+op+op+operand+" case 2 for '+uneval(I));\n"+ michael@0: "}\n"; michael@0: } michael@0: michael@0: function get_check_source(operand) michael@0: { michael@0: return get_pre_check(operand, '+')+ michael@0: get_pre_check(operand, '-')+ michael@0: get_post_check(operand, '+')+ michael@0: get_post_check(operand, '-'); michael@0: } michael@0: michael@0: var arg_check = Function('I', 'a', get_check_source('a')); michael@0: var let_check = Function('I', 'let a;'+get_check_source('a')); michael@0: var var_check = Function('I', 'var a;'+get_check_source('a')); michael@0: michael@0: var my_name; michael@0: var my_obj = {}; michael@0: var my_index = 0; michael@0: var name_check = Function('I', get_check_source('my_name')); michael@0: var prop_check = Function('I', get_check_source('my_obj.x')); michael@0: var elem_check = Function('I', get_check_source('my_obj[my_index]')); michael@0: michael@0: var test_values = [0 , 0.5, -0.0, (1 << 30) - 1, 1 - (1 << 30)]; michael@0: michael@0: for (let i = 0; i != test_values.length; i = i + 1) { michael@0: let x = [test_values[i], String(test_values[i])]; michael@0: for (let j = 0; j != x.length; j = j + 1) { michael@0: try michael@0: { michael@0: expect = actual = 'No Error'; michael@0: let test_value = x[j]; michael@0: arg_check(test_value, 0); michael@0: let_check(test_value); michael@0: var_check(test_value); michael@0: name_check(test_value); michael@0: prop_check(test_value); michael@0: elem_check(test_value); michael@0: } michael@0: catch(ex) michael@0: { michael@0: actual = ex + ''; michael@0: } michael@0: reportCompare(expect, actual, summary + ': ' + i + ', ' + j); michael@0: } michael@0: }