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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 *
michael@0 8 * Date: 08 November 2003
michael@0 9 * SUMMARY: |expr()| should cause a TypeError if |typeof expr| != 'function'
michael@0 10 *
michael@0 11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=224956
michael@0 12 *
michael@0 13 */
michael@0 14 //-----------------------------------------------------------------------------
michael@0 15 var UBound = 0;
michael@0 16 var BUGNUMBER = 224956;
michael@0 17 var summary = "|expr()| should cause TypeError if |typeof expr| != 'function'";
michael@0 18 var TEST_PASSED = 'TypeError';
michael@0 19 var TEST_FAILED = 'Generated an error, but NOT a TypeError! ';
michael@0 20 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
michael@0 21 var CHECK_PASSED = 'Should not generate an error';
michael@0 22 var CHECK_FAILED = 'Generated an error!';
michael@0 23 var status = '';
michael@0 24 var statusitems = [];
michael@0 25 var actual = '';
michael@0 26 var actualvalues = [];
michael@0 27 var expect= '';
michael@0 28 var expectedvalues = [];
michael@0 29 var x;
michael@0 30
michael@0 31
michael@0 32 /*
michael@0 33 * All the following contain invalid uses of the call operator ()
michael@0 34 * and should generate TypeErrors. That's what we're testing for.
michael@0 35 *
michael@0 36 * To save writing try...catch over and over, we hide all the
michael@0 37 * errors inside eval strings, and let testThis() catch them.
michael@0 38 */
michael@0 39 status = inSection(1);
michael@0 40 x = 'abc';
michael@0 41 testThis('x()');
michael@0 42
michael@0 43 status = inSection(2);
michael@0 44 testThis('"abc"()');
michael@0 45
michael@0 46 status = inSection(3);
michael@0 47 x = new Date();
michael@0 48 testThis('x()');
michael@0 49
michael@0 50 status = inSection(4);
michael@0 51 testThis('Date(12345)()');
michael@0 52
michael@0 53 status = inSection(5);
michael@0 54 x = Number(1);
michael@0 55 testThis('x()');
michael@0 56
michael@0 57 status = inSection(6);
michael@0 58 testThis('1()');
michael@0 59
michael@0 60 status = inSection(7);
michael@0 61 x = void(0);
michael@0 62 testThis('x()');
michael@0 63
michael@0 64 status = inSection(8);
michael@0 65 testThis('void(0)()');
michael@0 66
michael@0 67 status = inSection(9);
michael@0 68 x = Math;
michael@0 69 testThis('x()');
michael@0 70
michael@0 71 status = inSection(10);
michael@0 72 testThis('Math()');
michael@0 73
michael@0 74 status = inSection(11);
michael@0 75 x = Array(5);
michael@0 76 testThis('x()');
michael@0 77
michael@0 78 status = inSection(12);
michael@0 79 testThis('[1,2,3,4,5]()');
michael@0 80
michael@0 81 status = inSection(13);
michael@0 82 x = [1,2,3].splice(1,2);
michael@0 83 testThis('x()');
michael@0 84
michael@0 85
michael@0 86 /*
michael@0 87 * Same as above, but with non-empty call parentheses
michael@0 88 */
michael@0 89 status = inSection(14);
michael@0 90 x = 'abc';
michael@0 91 testThis('x(1)');
michael@0 92
michael@0 93 status = inSection(15);
michael@0 94 testThis('"abc"(1)');
michael@0 95
michael@0 96 status = inSection(16);
michael@0 97 x = new Date();
michael@0 98 testThis('x(1)');
michael@0 99
michael@0 100 status = inSection(17);
michael@0 101 testThis('Date(12345)(1)');
michael@0 102
michael@0 103 status = inSection(18);
michael@0 104 x = Number(1);
michael@0 105 testThis('x(1)');
michael@0 106
michael@0 107 status = inSection(19);
michael@0 108 testThis('1(1)');
michael@0 109
michael@0 110 status = inSection(20);
michael@0 111 x = void(0);
michael@0 112 testThis('x(1)');
michael@0 113
michael@0 114 status = inSection(21);
michael@0 115 testThis('void(0)(1)');
michael@0 116
michael@0 117 status = inSection(22);
michael@0 118 x = Math;
michael@0 119 testThis('x(1)');
michael@0 120
michael@0 121 status = inSection(23);
michael@0 122 testThis('Math(1)');
michael@0 123
michael@0 124 status = inSection(24);
michael@0 125 x = Array(5);
michael@0 126 testThis('x(1)');
michael@0 127
michael@0 128 status = inSection(25);
michael@0 129 testThis('[1,2,3,4,5](1)');
michael@0 130
michael@0 131 status = inSection(26);
michael@0 132 x = [1,2,3].splice(1,2);
michael@0 133 testThis('x(1)');
michael@0 134
michael@0 135
michael@0 136 /*
michael@0 137 * Expression from website in original bug report above -
michael@0 138 */
michael@0 139 status = inSection(27);
michael@0 140 var A = 1, C=2, Y=3, T=4, I=5;
michael@0 141 testThis('(((C/A-0.3)/0.2)+((Y/A-3)/4)+((T/A)/0.05)+((0.095-I/A)/0.4))(100/6)');
michael@0 142
michael@0 143
michael@0 144 status = inSection(28);
michael@0 145 x = /a()/;
michael@0 146 testThis('x("abc")');
michael@0 147
michael@0 148 status = inSection(29);
michael@0 149 x = /a()/gi;
michael@0 150 testThis('x("abc")');
michael@0 151
michael@0 152 status = inSection(30);
michael@0 153 x = RegExp('a()');
michael@0 154 testThis('x("abc")');
michael@0 155
michael@0 156 status = inSection(31);
michael@0 157 x = new RegExp('a()', 'gi');
michael@0 158 testThis('x("")');
michael@0 159
michael@0 160
michael@0 161 /*
michael@0 162 * Functions have |typeof| == 'function'.
michael@0 163 *
michael@0 164 * Therefore these expressions should not cause any errors.
michael@0 165 * Note we use checkThis() instead of testThis()
michael@0 166 *
michael@0 167 */
michael@0 168 status = inSection(32);
michael@0 169 x = function (y) {return y+1;};
michael@0 170 checkThis('x("abc")');
michael@0 171
michael@0 172 status = inSection(33);
michael@0 173 checkThis('(function (y) {return y+1;})("abc")');
michael@0 174
michael@0 175 status = inSection(34);
michael@0 176 function f(y) { function g() {return y;}; return g();};
michael@0 177 checkThis('f("abc")');
michael@0 178
michael@0 179
michael@0 180
michael@0 181 //-----------------------------------------------------------------------------
michael@0 182 test();
michael@0 183 //-----------------------------------------------------------------------------
michael@0 184
michael@0 185
michael@0 186
michael@0 187
michael@0 188 /*
michael@0 189 * |expr()| should generate a TypeError if |expr| is not a function
michael@0 190 */
michael@0 191 function testThis(sInvalidSyntax)
michael@0 192 {
michael@0 193 expect = TEST_PASSED;
michael@0 194 actual = TEST_FAILED_BADLY;
michael@0 195
michael@0 196 try
michael@0 197 {
michael@0 198 eval(sInvalidSyntax);
michael@0 199 }
michael@0 200 catch(e)
michael@0 201 {
michael@0 202 if (e instanceof TypeError)
michael@0 203 actual = TEST_PASSED;
michael@0 204 else
michael@0 205 actual = TEST_FAILED + e;
michael@0 206 }
michael@0 207
michael@0 208 statusitems[UBound] = status;
michael@0 209 expectedvalues[UBound] = expect;
michael@0 210 actualvalues[UBound] = actual;
michael@0 211 UBound++;
michael@0 212 }
michael@0 213
michael@0 214
michael@0 215 /*
michael@0 216 * Valid syntax shouldn't generate any errors
michael@0 217 */
michael@0 218 function checkThis(sValidSyntax)
michael@0 219 {
michael@0 220 expect = CHECK_PASSED;
michael@0 221 actual = CHECK_PASSED;
michael@0 222
michael@0 223 try
michael@0 224 {
michael@0 225 eval(sValidSyntax);
michael@0 226 }
michael@0 227 catch(e)
michael@0 228 {
michael@0 229 actual = CHECK_FAILED;
michael@0 230 }
michael@0 231
michael@0 232 statusitems[UBound] = status;
michael@0 233 expectedvalues[UBound] = expect;
michael@0 234 actualvalues[UBound] = actual;
michael@0 235 UBound++;
michael@0 236 }
michael@0 237
michael@0 238
michael@0 239 function test()
michael@0 240 {
michael@0 241 enterFunc('test');
michael@0 242 printBugNumber(BUGNUMBER);
michael@0 243 printStatus(summary);
michael@0 244
michael@0 245 for (var i=0; i<UBound; i++)
michael@0 246 {
michael@0 247 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 248 }
michael@0 249
michael@0 250 exitFunc ('test');
michael@0 251 }

mercurial