jscript: Inherit some Array functions from Object.
[wine] / dlls / jscript / tests / api.js
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 var tmp, i;
20
21 i = parseInt("0");
22 ok(i === 0, "parseInt('0') = " + i);
23 i = parseInt("123");
24 ok(i === 123, "parseInt('123') = " + i);
25 i = parseInt("-123");
26 ok(i === -123, "parseInt('-123') = " + i);
27 i = parseInt("0xff");
28 ok(i === 0xff, "parseInt('0xff') = " + i);
29 i = parseInt("11", 8);
30 ok(i === 9, "parseInt('11', 8) = " + i);
31 i = parseInt("1j", 22);
32 ok(i === 41, "parseInt('1j', 32) = " + i);
33 i = parseInt("123", 0);
34 ok(i === 123, "parseInt('123', 0) = " + i);
35 i = parseInt("123", 10, "test");
36 ok(i === 123, "parseInt('123', 10, 'test') = " + i);
37 i = parseInt("11", "8");
38 ok(i === 9, "parseInt('11', '8') = " + i);
39
40 tmp = encodeURI("abc");
41 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
42 tmp = encodeURI("{abc}");
43 ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp);
44 tmp = encodeURI("");
45 ok(tmp === "", "encodeURI('') = " + tmp);
46 tmp = encodeURI("\01\02\03\04");
47 ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp);
48 tmp = encodeURI("{#@}");
49 ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp);
50 tmp = encodeURI("\xa1 ");
51 ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp);
52 tmp = encodeURI("\xffff");
53 ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length);
54 tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
55 ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
56 tmp = encodeURI();
57 ok(tmp === "undefined", "encodeURI() = " + tmp);
58 tmp = encodeURI("abc", "test");
59 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
60
61 tmp = "" + new Object();
62 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
63 (tmp = new Array).f = Object.prototype.toString;
64 ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f());
65 (tmp = new Boolean).f = Object.prototype.toString;
66 ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f());
67 (tmp = new Date).f = Object.prototype.toString;
68 ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f());
69 (tmp = function() {}).f = Object.prototype.toString;
70 ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f());
71 Math.f = Object.prototype.toString;
72 ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f());
73 (tmp = new Number).f = Object.prototype.toString;
74 ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
75 (tmp = new RegExp("")).f = Object.prototype.toString;
76 ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
77 (tmp = new String).f = Object.prototype.toString;
78 ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f());
79
80 var obj = new Object();
81 obj.toString = function (x) {
82     ok(arguments.length === 0, "arguments.length = " + arguments.length);
83     return "test";
84 };
85 ok((tmp = obj.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp);
86 ok((tmp = obj.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp);
87
88 ok("".length === 0, "\"\".length = " + "".length);
89 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
90 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
91 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
92
93 tmp = "".toString();
94 ok(tmp === "", "''.toString() = " + tmp);
95 tmp = "test".toString();
96 ok(tmp === "test", "''.toString() = " + tmp);
97 tmp = "test".toString(3);
98 ok(tmp === "test", "''.toString(3) = " + tmp);
99
100 tmp = "".valueOf();
101 ok(tmp === "", "''.valueOf() = " + tmp);
102 tmp = "test".valueOf();
103 ok(tmp === "test", "''.valueOf() = " + tmp);
104 tmp = "test".valueOf(3);
105 ok(tmp === "test", "''.valueOf(3) = " + tmp);
106
107 var str = new String("test");
108 ok(str.toString() === "test", "str.toString() = " + str.toString());
109 var str = new String();
110 ok(str.toString() === "", "str.toString() = " + str.toString());
111 var str = new String("test", "abc");
112 ok(str.toString() === "test", "str.toString() = " + str.toString());
113
114 tmp = "value " + str;
115 ok(tmp === "value test", "'value ' + str = " + tmp);
116
117 tmp = String();
118 ok(tmp === "", "String() = " + tmp);
119 tmp = String(false);
120 ok(tmp === "false", "String(false) = " + tmp);
121 tmp = String(null);
122 ok(tmp === "null", "String(null) = " + tmp);
123 tmp = String("test");
124 ok(tmp === "test", "String('test') = " + tmp);
125 tmp = String("test", "abc");
126 ok(tmp === "test", "String('test','abc') = " + tmp);
127
128 tmp = "abc".charAt(0);
129 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
130 tmp = "abc".charAt(1);
131 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
132 tmp = "abc".charAt(2);
133 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
134 tmp = "abc".charAt(3);
135 ok(tmp === "", "'abc',charAt(3) = " + tmp);
136 tmp = "abc".charAt(4);
137 ok(tmp === "", "'abc',charAt(4) = " + tmp);
138 tmp = "abc".charAt();
139 ok(tmp === "a", "'abc',charAt() = " + tmp);
140 tmp = "abc".charAt(-1);
141 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
142 tmp = "abc".charAt(0,2);
143 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
144
145 tmp = "abc".charCodeAt(0);
146 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
147 tmp = "abc".charCodeAt(1);
148 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
149 tmp = "abc".charCodeAt(2);
150 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
151 tmp = "abc".charCodeAt();
152 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
153 tmp = "abc".charCodeAt(true);
154 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
155 tmp = "abc".charCodeAt(0,2);
156 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
157
158 tmp = "abcd".substring(1,3);
159 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
160 tmp = "abcd".substring(-1,3);
161 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
162 tmp = "abcd".substring(1,6);
163 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
164 tmp = "abcd".substring(3,1);
165 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
166 tmp = "abcd".substring(2,2);
167 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
168 tmp = "abcd".substring(true,"3");
169 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
170 tmp = "abcd".substring(1,3,2);
171 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
172 tmp = "abcd".substring();
173 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
174
175 tmp = "abcd".slice(1,3);
176 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
177 tmp = "abcd".slice(1,-1);
178 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
179 tmp = "abcd".slice(-3,3);
180 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
181 tmp = "abcd".slice(-6,3);
182 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
183 tmp = "abcd".slice(3,1);
184 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
185 tmp = "abcd".slice(true,3);
186 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
187 tmp = "abcd".slice();
188 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
189 tmp = "abcd".slice(1);
190 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
191
192 tmp = "abc".concat(["d",1],2,false);
193 ok(tmp === "abcd,12false", "concat returned " + tmp);
194 var arr = new Array(2,"a");
195 arr.concat = String.prototype.concat;
196 tmp = arr.concat("d");
197 ok(tmp === "2,ad", "arr.concat = " + tmp);
198
199 m = "a+bcabc".match("a+");
200 ok(typeof(m) === "object", "typeof m is not object");
201 ok(m.length === 1, "m.length is not 1");
202 ok(m["0"] === "a", "m[0] is not \"ab\"");
203
204 r = "- [test] -".replace("[test]", "success");
205 ok(r === "- success -", "r = " + r + " expected '- success -'");
206
207 r = "- [test] -".replace("[test]", "success", "test");
208 ok(r === "- success -", "r = " + r + " expected '- success -'");
209
210 r = "test".replace();
211 ok(r === "test", "r = " + r + " expected 'test'");
212
213 function replaceFunc3(m, off, str) {
214     ok(arguments.length === 3, "arguments.length = " + arguments.length);
215     ok(m === "[test]", "m = " + m + " expected [test1]");
216     ok(off === 1, "off = " + off + " expected 0");
217     ok(str === "-[test]-", "str = " + arguments[3]);
218     return "ret";
219 }
220
221 r = "-[test]-".replace("[test]", replaceFunc3);
222 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
223
224 r = "-[test]-".replace("[test]", replaceFunc3, "test");
225 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
226
227 r = "1,2,3".split(",");
228 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
229 ok(r.length === 3, "r.length = " + r.length);
230 ok(r[0] === "1", "r[0] = " + r[0]);
231 ok(r[1] === "2", "r[1] = " + r[1]);
232 ok(r[2] === "3", "r[2] = " + r[2]);
233
234
235 r = "1,2,3".split(",*");
236 ok(r.length === 1, "r.length = " + r.length);
237 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
238
239 r = "123".split("");
240 ok(r.length === 3, "r.length = " + r.length);
241 ok(r[0] === "1", "r[0] = " + r[0]);
242 ok(r[1] === "2", "r[1] = " + r[1]);
243 ok(r[2] === "3", "r[2] = " + r[2]);
244
245 r = "123".split(2);
246 ok(r.length === 2, "r.length = " + r.length);
247 ok(r[0] === "1", "r[0] = " + r[0]);
248 ok(r[1] === "3", "r[1] = " + r[1]);
249
250 r = "1,2,".split(",");
251 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
252 ok(r.length === 3, "r.length = " + r.length);
253 ok(r[0] === "1", "r[0] = " + r[0]);
254 ok(r[1] === "2", "r[1] = " + r[1]);
255 ok(r[2] === "", "r[2] = " + r[2]);
256
257 tmp = "abcd".indexOf("bc",0);
258 ok(tmp === 1, "indexOf = " + tmp);
259 tmp = "abcd".indexOf("bc",1);
260 ok(tmp === 1, "indexOf = " + tmp);
261 tmp = "abcd".indexOf("bc");
262 ok(tmp === 1, "indexOf = " + tmp);
263 tmp = "abcd".indexOf("ac");
264 ok(tmp === -1, "indexOf = " + tmp);
265 tmp = "abcd".indexOf("bc",2);
266 ok(tmp === -1, "indexOf = " + tmp);
267 tmp = "abcd".indexOf("a",0);
268 ok(tmp === 0, "indexOf = " + tmp);
269 tmp = "abcd".indexOf("bc",0,"test");
270 ok(tmp === 1, "indexOf = " + tmp);
271 tmp = "abcd".indexOf();
272 ok(tmp == -1, "indexOf = " + tmp);
273
274 tmp = "".toLowerCase();
275 ok(tmp === "", "''.toLowerCase() = " + tmp);
276 tmp = "test".toLowerCase();
277 ok(tmp === "test", "''.toLowerCase() = " + tmp);
278 tmp = "test".toLowerCase(3);
279 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
280 tmp = "tEsT".toLowerCase();
281 ok(tmp === "test", "''.toLowerCase() = " + tmp);
282 tmp = "tEsT".toLowerCase(3);
283 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
284
285 tmp = "".toUpperCase();
286 ok(tmp === "", "''.toUpperCase() = " + tmp);
287 tmp = "TEST".toUpperCase();
288 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
289 tmp = "TEST".toUpperCase(3);
290 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
291 tmp = "tEsT".toUpperCase();
292 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
293 tmp = "tEsT".toUpperCase(3);
294 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
295
296 tmp = "".anchor();
297 ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp);
298 tmp = "".anchor(3);
299 ok(tmp === "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp);
300 tmp = "".anchor("red");
301 ok(tmp === "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp);
302 tmp = "test".anchor();
303 ok(tmp === "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp);
304 tmp = "test".anchor(3);
305 ok(tmp === "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp);
306 tmp = "test".anchor("green");
307 ok(tmp === "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp);
308
309 tmp = "".big();
310 ok(tmp === "<BIG></BIG>", "''.big() = " + tmp);
311 tmp = "".big(3);
312 ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp);
313 tmp = "test".big();
314 ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp);
315 tmp = "test".big(3);
316 ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp);
317
318 tmp = "".blink();
319 ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp);
320 tmp = "".blink(3);
321 ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp);
322 tmp = "test".blink();
323 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp);
324 tmp = "test".blink(3);
325 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp);
326
327 tmp = "".bold();
328 ok(tmp === "<B></B>", "''.bold() = " + tmp);
329 tmp = "".bold(3);
330 ok(tmp === "<B></B>", "''.bold(3) = " + tmp);
331 tmp = "test".bold();
332 ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp);
333 tmp = "test".bold(3);
334 ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp);
335
336 tmp = "".fixed();
337 ok(tmp === "<TT></TT>", "''.fixed() = " + tmp);
338 tmp = "".fixed(3);
339 ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp);
340 tmp = "test".fixed();
341 ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp);
342 tmp = "test".fixed(3);
343 ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp);
344
345 tmp = "".fontcolor();
346 ok(tmp === "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp);
347 tmp = "".fontcolor(3);
348 ok(tmp === "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp);
349 tmp = "".fontcolor("red");
350 ok(tmp === "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp);
351 tmp = "test".fontcolor();
352 ok(tmp === "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp);
353 tmp = "test".fontcolor(3);
354 ok(tmp === "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp);
355 tmp = "test".fontcolor("green");
356 ok(tmp === "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp);
357
358 tmp = "".fontsize();
359 ok(tmp === "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp);
360 tmp = "".fontsize(3);
361 ok(tmp === "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp);
362 tmp = "".fontsize("red");
363 ok(tmp === "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp);
364 tmp = "test".fontsize();
365 ok(tmp === "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp);
366 tmp = "test".fontsize(3);
367 ok(tmp === "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp);
368 tmp = "test".fontsize("green");
369 ok(tmp === "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp);
370
371 tmp = ("".fontcolor()).fontsize();
372 ok(tmp === "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp);
373
374 tmp = "".italics();
375 ok(tmp === "<I></I>", "''.italics() = " + tmp);
376 tmp = "".italics(3);
377 ok(tmp === "<I></I>", "''.italics(3) = " + tmp);
378 tmp = "test".italics();
379 ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp);
380 tmp = "test".italics(3);
381 ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp);
382
383 tmp = "".link();
384 ok(tmp === "<A HREF=\"undefined\"></A>", "''.link() = " + tmp);
385 tmp = "".link(3);
386 ok(tmp === "<A HREF=\"3\"></A>", "''.link(3) = " + tmp);
387 tmp = "".link("red");
388 ok(tmp === "<A HREF=\"red\"></A>", "''.link('red') = " + tmp);
389 tmp = "test".link();
390 ok(tmp === "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp);
391 tmp = "test".link(3);
392 ok(tmp === "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp);
393 tmp = "test".link("green");
394 ok(tmp === "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp);
395
396 tmp = "".small();
397 ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp);
398 tmp = "".small(3);
399 ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp);
400 tmp = "test".small();
401 ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp);
402 tmp = "test".small(3);
403 ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp);
404
405 tmp = "".strike();
406 ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp);
407 tmp = "".strike(3);
408 ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp);
409 tmp = "test".strike();
410 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp);
411 tmp = "test".strike(3);
412 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp);
413
414 tmp = "".sub();
415 ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp);
416 tmp = "".sub(3);
417 ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp);
418 tmp = "test".sub();
419 ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp);
420 tmp = "test".sub(3);
421 ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp);
422
423 tmp = "".sup();
424 ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp);
425 tmp = "".sup(3);
426 ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp);
427 tmp = "test".sup();
428 ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
429 tmp = "test".sup(3);
430 ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
431
432 ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
433 ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
434 ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
435         "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
436 ok(String.fromCharCode(65, NaN, undefined).length === 3,
437         "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
438
439 var arr = new Array();
440 ok(typeof(arr) === "object", "arr () is not object");
441 ok((arr.length === 0), "arr.length is not 0");
442 ok(arr["0"] === undefined, "arr[0] is not undefined");
443
444 var arr = new Array(1, 2, "test");
445 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
446 ok((arr.length === 3), "arr.length is not 3");
447 ok(arr["0"] === 1, "arr[0] is not 1");
448 ok(arr["1"] === 2, "arr[1] is not 2");
449 ok(arr["2"] === "test", "arr[2] is not \"test\"");
450
451 arr["7"] = true;
452 ok((arr.length === 8), "arr.length is not 8");
453
454 tmp = "" + [];
455 ok(tmp === "", "'' + [] = " + tmp);
456 tmp = "" + [1,true];
457 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
458
459 var arr = new Array(6);
460 ok(typeof(arr) === "object", "arr (6) is not object");
461 ok((arr.length === 6), "arr.length is not 6");
462 ok(arr["0"] === undefined, "arr[0] is not undefined");
463
464 ok(arr.push() === 6, "arr.push() !== 6");
465 ok(arr.push(1) === 7, "arr.push(1) !== 7");
466 ok(arr[6] === 1, "arr[6] != 1");
467 ok(arr.length === 7, "arr.length != 10");
468 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
469 ok(arr[8] === "b", "arr[8] != 'b'");
470 ok(arr.length === 10, "arr.length != 10");
471
472 arr = [3,4,5];
473 tmp = arr.pop();
474 ok(arr.length === 2, "arr.length = " + arr.length);
475 ok(tmp === 5, "pop() = " + tmp);
476 tmp = arr.pop(2);
477 ok(arr.length === 1, "arr.length = " + arr.length);
478 ok(tmp === 4, "pop() = " + tmp);
479 tmp = arr.pop();
480 ok(arr.length === 0, "arr.length = " + arr.length);
481 ok(tmp === 3, "pop() = " + tmp);
482 for(tmp in arr)
483     ok(false, "not deleted " + tmp);
484 tmp = arr.pop();
485 ok(arr.length === 0, "arr.length = " + arr.length);
486 ok(tmp === undefined, "tmp = " + tmp);
487 arr = [,,,,,];
488 tmp = arr.pop();
489 ok(arr.length === 5, "arr.length = " + arr.length);
490 ok(tmp === undefined, "tmp = " + tmp);
491
492 arr = [1,2,null,false,undefined,,"a"];
493
494 tmp = arr.join();
495 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
496 tmp = arr.join(";");
497 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
498 tmp = arr.join(";","test");
499 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
500 tmp = arr.join("");
501 ok(tmp === "12falsea", "arr.join('') = " + tmp);
502
503 tmp = arr.toString();
504 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
505 tmp = arr.toString("test");
506 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
507
508 arr = [5,true,2,-1,3,false,"2.5"];
509 tmp = arr.sort(function(x,y) { return y-x; });
510 ok(tmp === arr, "tmp !== arr");
511 tmp = [5,3,"2.5",2,true,false,-1];
512 for(var i=0; i < arr.length; i++)
513     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
514
515 arr = [5,false,2,0,"abc",3,"a",-1];
516 tmp = arr.sort();
517 ok(tmp === arr, "tmp !== arr");
518 tmp = [-1,0,2,3,5,"a","abc",false];
519 for(var i=0; i < arr.length; i++)
520     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
521
522 arr = ["a", "b", "ab"];
523 tmp = ["a", "ab", "b"];
524 ok(arr.sort() === arr, "arr.sort() !== arr");
525 for(var i=0; i < arr.length; i++)
526     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
527
528 arr = ["1", "2", "3"];
529 arr.length = 1;
530 ok(arr.length === 1, "arr.length = " + arr.length);
531 arr.length = 3;
532 ok(arr.length === 3, "arr.length = " + arr.length);
533 ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
534
535 arr = Array("a","b","c");
536 ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
537
538 ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
539 ok(arr === arr.valueOf(), "arr !== arr.valueOf");
540
541 var num = new Number(6);
542 arr = [0,1,2];
543 tmp = arr.concat(3, [4,5], num);
544 ok(tmp !== arr, "tmp === arr");
545 for(var i=0; i<6; i++)
546     ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
547 ok(tmp[6] === num, "tmp[6] !== num");
548 ok(tmp.length === 7, "tmp.length = " + tmp.length);
549
550 arr = [].concat();
551 ok(arr.length === 0, "arr.length = " + arr.length);
552
553 arr = [1,];
554 tmp = arr.concat([2]);
555 ok(tmp.length === 3, "tmp.length = " + tmp.length);
556 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
557
558 arr = [1,false,'a',null,undefined,'a'];
559 ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6));
560 ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length);
561 ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice());
562 ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc"));
563 ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8));
564 ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length);
565 ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1));
566 ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2));
567 ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1));
568 tmp = arr.slice(0,6);
569 for(var i=0; i < arr.length; i++)
570     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
571 arr[12] = 2;
572 ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString());
573 ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length);
574
575 var num = new Number(2);
576 ok(num.toString() === "2", "num(2).toString !== 2");
577 var num = new Number();
578 ok(num.toString() === "0", "num().toString !== 0");
579
580 ok(Number() === 0, "Number() = " + Number());
581 ok(Number(false) === 0, "Number(false) = " + Number(false));
582 ok(Number("43") === 43, "Number('43') = " + Number("43"));
583
584 tmp = (new Number(1)).valueOf();
585 ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
586 tmp = (new Number(1,2)).valueOf();
587 ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
588 tmp = (new Number()).valueOf();
589 ok(tmp === 0, "(new Number()).valueOf = " + tmp);
590 tmp = Number.prototype.valueOf();
591 ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
592
593 function equals(val, base) {
594     var i;
595     var num = 0;
596     var str = val.toString(base);
597
598     for(i=0; i<str.length; i++) {
599         if(str.substring(i, i+1) == '(') break;
600         if(str.substring(i, i+1) == '.') break;
601         num = num*base + parseInt(str.substring(i, i+1));
602     }
603
604     if(str.substring(i, i+1) == '.') {
605         var mult = base;
606         for(i++; i<str.length; i++) {
607             if(str.substring(i, i+1) == '(') break;
608             num += parseInt(str.substring(i, i+1))/mult;
609             mult *= base;
610         }
611     }
612
613     if(str.substring(i, i+1) == '(') {
614         exp = parseInt(str.substring(i+2));
615         num *= Math.pow(base, exp);
616     }
617
618     ok(num>val-val/1000 && num<val+val/1000, "equals: num = " + num);
619 }
620
621 ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11));
622 ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17));
623 ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33));
624 ok((NaN).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN).toString(11));
625 ok((Infinity).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity).toString(11));
626 for(i=2; i<10; i++) {
627     equals(1.123, i);
628     equals(2305843009200000000, i);
629     equals(5.123, i);
630     equals(21711, i);
631     equals(1024*1024*1024*1024*1024*1024*1.9999, i);
632     equals(748382, i);
633     equals(0.6, i);
634     equals(4.65661287308e-10, i);
635     ok((0).toString(i) === "0", "(0).toString("+i+") = " + (0).toString(i));
636 }
637
638 ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123'));
639 ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7'));
640 ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2'));
641 ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5'));
642 ok(parseFloat('1E5 not parsed') === 1E5, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed'));
643 ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
644 ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
645 ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
646 ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
647
648 tmp = Math.min(1);
649 ok(tmp === 1, "Math.min(1) = " + tmp);
650
651 tmp = Math.min(1, false);
652 ok(tmp === 0, "Math.min(1, false) = " + tmp);
653
654 tmp = Math.min();
655 ok(tmp === Infinity, "Math.min() = " + tmp);
656
657 tmp = Math.min(1, NaN, -Infinity, false);
658 ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
659
660 tmp = Math.min(1, false, true, null, -3);
661 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
662
663 tmp = Math.max(1);
664 ok(tmp === 1, "Math.max(1) = " + tmp);
665
666 tmp = Math.max(true, 0);
667 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
668
669 tmp = Math.max(-2, false, true, null, 1);
670 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
671
672 tmp = Math.max();
673 ok(tmp === -Infinity, "Math.max() = " + tmp);
674
675 tmp = Math.max(true, NaN, 0);
676 ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
677
678 tmp = Math.round(0.5);
679 ok(tmp === 1, "Math.round(0.5) = " + tmp);
680
681 tmp = Math.round(-0.5);
682 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
683
684 tmp = Math.round(1.1);
685 ok(tmp === 1, "Math.round(1.1) = " + tmp);
686
687 tmp = Math.round(true);
688 ok(tmp === 1, "Math.round(true) = " + tmp);
689
690 tmp = Math.round(1.1, 3, 4);
691 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
692
693 tmp = Math.round();
694 ok(isNaN(tmp), "Math.round() is not NaN");
695
696 tmp = Math.ceil(0.5);
697 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
698
699 tmp = Math.ceil(-0.5);
700 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
701
702 tmp = Math.ceil(1.1);
703 ok(tmp === 2, "Math.round(1.1) = " + tmp);
704
705 tmp = Math.ceil(true);
706 ok(tmp === 1, "Math.ceil(true) = " + tmp);
707
708 tmp = Math.ceil(1.1, 3, 4);
709 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
710
711 tmp = Math.ceil();
712 ok(isNaN(tmp), "ceil() is not NaN");
713
714 tmp = Math.floor(0.5);
715 ok(tmp === 0, "Math.floor(0.5) = " + tmp);
716
717 tmp = Math.floor(-0.5);
718 ok(tmp === -1, "Math.floor(-0.5) = " + tmp);
719
720 tmp = Math.floor(1.1);
721 ok(tmp === 1, "Math.floor(1.1) = " + tmp);
722
723 tmp = Math.floor(true);
724 ok(tmp === 1, "Math.floor(true) = " + tmp);
725
726 tmp = Math.floor(1.1, 3, 4);
727 ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp);
728
729 tmp = Math.floor();
730 ok(isNaN(tmp), "floor is not NaN");
731
732 tmp = Math.abs(3);
733 ok(tmp === 3, "Math.abs(3) = " + tmp);
734
735 tmp = Math.abs(-3);
736 ok(tmp === 3, "Math.abs(-3) = " + tmp);
737
738 tmp = Math.abs(true);
739 ok(tmp === 1, "Math.abs(true) = " + tmp);
740
741 tmp = Math.abs();
742 ok(isNaN(tmp), "Math.abs() is not NaN");
743
744 tmp = Math.abs(NaN);
745 ok(isNaN(tmp), "Math.abs() is not NaN");
746
747 tmp = Math.abs(-Infinity);
748 ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp);
749
750 tmp = Math.abs(-3, 2);
751 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
752
753 tmp = Math.cos(0);
754 ok(tmp === 1, "Math.cos(0) = " + tmp);
755
756 tmp = Math.cos(Math.PI/2);
757 ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp);
758
759 tmp = Math.cos(-Math.PI/2);
760 ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp);
761
762 tmp = Math.cos(Math.PI/3, 2);
763 ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp);
764
765 tmp = Math.cos(true);
766 ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp);
767
768 tmp = Math.cos(false);
769 ok(tmp === 1, "Math.cos(false) = " + tmp);
770
771 tmp = Math.cos();
772 ok(isNaN(tmp), "Math.cos() is not NaN");
773
774 tmp = Math.cos(NaN);
775 ok(isNaN(tmp), "Math.cos(NaN) is not NaN");
776
777 tmp = Math.cos(Infinity);
778 ok(isNaN(tmp), "Math.cos(Infinity) is not NaN");
779
780 tmp = Math.cos(-Infinity);
781 ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN");
782
783 tmp = Math.pow(2, 2);
784 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
785
786 tmp = Math.pow(4, 0.5);
787 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
788
789 tmp = Math.pow(2, 2, 3);
790 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
791
792 tmp = Math.pow(2);
793 ok(isNaN(tmp), "Math.pow(2) is not NaN");
794
795 tmp = Math.pow();
796 ok(isNaN(tmp), "Math.pow() is not NaN");
797
798 tmp = Math.random();
799 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
800 ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp);
801
802 tmp = Math.random(100);
803 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
804 ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp);
805
806 tmp = Math.acos(0);
807 ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp);
808
809 tmp = Math.acos(1);
810 ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp);
811
812 tmp = Math.acos(-1);
813 ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp);
814
815 tmp = Math.acos(Math.PI/4, 2);
816 ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp);
817
818 tmp = Math.acos(true);
819 ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp);
820
821 tmp = Math.acos(false);
822 ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp);
823
824 tmp = Math.acos(1.1);
825 ok(isNaN(tmp), "Math.acos(1.1) is not NaN");
826
827 tmp = Math.acos();
828 ok(isNaN(tmp), "Math.acos() is not NaN");
829
830 tmp = Math.acos(NaN);
831 ok(isNaN(tmp), "Math.acos(NaN) is not NaN");
832
833 tmp = Math.acos(Infinity);
834 ok(isNaN(tmp), "Math.acos(Infinity) is not NaN");
835
836 tmp = Math.acos(-Infinity);
837 ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN");
838
839 tmp = Math.asin(0);
840 ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp);
841
842 tmp = Math.asin(1);
843 ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp);
844
845 tmp = Math.asin(-1);
846 ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp);
847
848 tmp = Math.asin(Math.PI/4, 2);
849 ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp);
850
851 tmp = Math.asin(true);
852 ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp);
853
854 tmp = Math.asin(false);
855 ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp);
856
857 tmp = Math.asin(1.1);
858 ok(isNaN(tmp), "Math.asin(1.1) is not NaN");
859
860 tmp = Math.asin();
861 ok(isNaN(tmp), "Math.asin() is not NaN");
862
863 tmp = Math.asin(NaN);
864 ok(isNaN(tmp), "Math.asin(NaN) is not NaN");
865
866 tmp = Math.asin(Infinity);
867 ok(isNaN(tmp), "Math.asin(Infinity) is not NaN");
868
869 tmp = Math.asin(-Infinity);
870 ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN");
871
872 tmp = Math.atan(0);
873 ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp);
874
875 tmp = Math.atan(1);
876 ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp);
877
878 tmp = Math.atan(-1);
879 ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp);
880
881 tmp = Math.atan(true);
882 ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp);
883
884 tmp = Math.atan(false);
885 ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp);
886
887 tmp = Math.atan();
888 ok(isNaN(tmp), "Math.atan() is not NaN");
889
890 tmp = Math.atan(NaN);
891 ok(isNaN(tmp), "Math.atan(NaN) is not NaN");
892
893 tmp = Math.atan(Infinity);
894 ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp);
895
896 tmp = Math.atan(-Infinity);
897 ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp);
898
899 tmp = Math.atan2(0, 0);
900 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp);
901
902 tmp = Math.atan2(0, 1);
903 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp);
904
905 tmp = Math.atan2(0, Infinity);
906 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp);
907
908 tmp = Math.atan2(0, -1);
909 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp);
910
911 tmp = Math.atan2(0, -Infinity);
912 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp);
913
914 tmp = Math.atan2(1, 0);
915 ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp);
916
917 tmp = Math.atan2(Infinity, 0);
918 ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp);
919
920 tmp = Math.atan2(-1, 0);
921 ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp);
922
923 tmp = Math.atan2(-Infinity, 0);
924 ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp);
925
926 tmp = Math.atan2(1, 1);
927 ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp);
928
929 tmp = Math.atan2(-1, -1);
930 ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp);
931
932 tmp = Math.atan2(-1, 1);
933 ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp);
934
935 tmp = Math.atan2(Infinity, Infinity);
936 ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp);
937
938 tmp = Math.atan2(Infinity, -Infinity, 1);
939 ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp);
940
941 tmp = Math.atan2();
942 ok(isNaN(tmp), "Math.atan2() is not NaN");
943
944 tmp = Math.atan2(1);
945 ok(isNaN(tmp), "Math.atan2(1) is not NaN");
946
947 tmp = Math.exp(0);
948 ok(tmp === 1, "Math.exp(0) = " + tmp);
949
950 tmp = Math.exp(1);
951 ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp);
952
953 tmp = Math.exp(-1);
954 ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp);
955
956 tmp = Math.exp(true);
957 ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp);
958
959 tmp = Math.exp(1, 1);
960 ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp);
961
962 tmp = Math.exp();
963 ok(isNaN(tmp), "Math.exp() is not NaN");
964
965 tmp = Math.exp(NaN);
966 ok(isNaN(tmp), "Math.exp(NaN) is not NaN");
967
968 tmp = Math.exp(Infinity);
969 ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp);
970
971 tmp = Math.exp(-Infinity);
972 ok(tmp === 0, "Math.exp(-Infinity) = " + tmp);
973
974 tmp = Math.log(1);
975 ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp);
976
977 tmp = Math.log(-1);
978 ok(isNaN(tmp), "Math.log(-1) is not NaN");
979
980 tmp = Math.log(true);
981 ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp);
982
983 tmp = Math.log(1, 1);
984 ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp);
985
986 tmp = Math.log();
987 ok(isNaN(tmp), "Math.log() is not NaN");
988
989 tmp = Math.log(NaN);
990 ok(isNaN(tmp), "Math.log(NaN) is not NaN");
991
992 tmp = Math.log(Infinity);
993 ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
994
995 tmp = Math.log(-Infinity);
996 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
997
998 tmp = Math.sin(0);
999 ok(tmp === 0, "Math.sin(0) = " + tmp);
1000
1001 tmp = Math.sin(Math.PI/2);
1002 ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
1003
1004 tmp = Math.sin(-Math.PI/2);
1005 ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
1006
1007 tmp = Math.sin(Math.PI/3, 2);
1008 ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
1009
1010 tmp = Math.sin(true);
1011 ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
1012
1013 tmp = Math.sin(false);
1014 ok(tmp === 0, "Math.sin(false) = " + tmp);
1015
1016 tmp = Math.sin();
1017 ok(isNaN(tmp), "Math.sin() is not NaN");
1018
1019 tmp = Math.sin(NaN);
1020 ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
1021
1022 tmp = Math.sin(Infinity);
1023 ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
1024
1025 tmp = Math.sin(-Infinity);
1026 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
1027
1028 tmp = Math.sqrt(0);
1029 ok(tmp === 0, "Math.sqrt(0) = " + tmp);
1030
1031 tmp = Math.sqrt(4);
1032 ok(tmp === 2, "Math.sqrt(4) = " + tmp);
1033
1034 tmp = Math.sqrt(-1);
1035 ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
1036
1037 tmp = Math.sqrt(2, 2);
1038 ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
1039
1040 tmp = Math.sqrt(true);
1041 ok(tmp === 1, "Math.sqrt(true) = " + tmp);
1042
1043 tmp = Math.sqrt(false);
1044 ok(tmp === 0, "Math.sqrt(false) = " + tmp);
1045
1046 tmp = Math.sqrt();
1047 ok(isNaN(tmp), "Math.sqrt() is not NaN");
1048
1049 tmp = Math.sqrt(NaN);
1050 ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
1051
1052 tmp = Math.sqrt(Infinity);
1053 ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
1054
1055 tmp = Math.sqrt(-Infinity);
1056 ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
1057
1058 tmp = Math.tan(0);
1059 ok(tmp === 0, "Math.tan(0) = " + tmp);
1060
1061 tmp = Math.tan(Math.PI);
1062 ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp);
1063
1064 tmp = Math.tan(2, 2);
1065 ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp);
1066
1067 tmp = Math.tan(true);
1068 ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp);
1069
1070 tmp = Math.tan(false);
1071 ok(tmp === 0, "Math.tan(false) = " + tmp);
1072
1073 tmp = Math.tan();
1074 ok(isNaN(tmp), "Math.tan() is not NaN");
1075
1076 tmp = Math.tan(NaN);
1077 ok(isNaN(tmp), "Math.tan(NaN) is not NaN");
1078
1079 tmp = Math.tan(Infinity);
1080 ok(isNaN(tmp), "Math.tan(Infinity) is not NaN");
1081
1082 tmp = Math.tan(-Infinity);
1083 ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
1084
1085 var func = function  (a) {
1086         var a = 1;
1087         if(a) return;
1088     };
1089 ok(func.toString() === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
1090    "func.toString() = " + func.toString());
1091 ok("" + func === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
1092    "'' + func.toString() = " + func);
1093
1094 ok(func.valueOf === Object.prototype.valueOf, "func.valueOf !== Object.prototype.valueOf");
1095 ok(func === func.valueOf(), "func !== func.valueOf()");
1096
1097 function testFuncToString(x,y) {
1098     return x+y;
1099 }
1100 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n    return x+y;\n}",
1101    "testFuncToString.toString() = " + testFuncToString.toString());
1102 ok("" + testFuncToString === "function testFuncToString(x,y) {\n    return x+y;\n}",
1103    "'' + testFuncToString = " + testFuncToString);
1104
1105 var date = new Date();
1106
1107 date = new Date(100);
1108 ok(date.getTime() === 100, "date.getTime() = " + date.getTime());
1109 ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime());
1110 date = new Date(8.64e15);
1111 ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime());
1112 date = new Date(8.64e15+1);
1113 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
1114 date = new Date(Infinity);
1115 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
1116 date = new Date("3 July 2009 22:28:00 UTC+0100");
1117 ok(date.getTime() === 1246656480000, "date.getTime() = " + date.getTime());
1118 date = new Date(1984, 11, 29, 13, 51, 24, 120);
1119 ok(date.getFullYear() === 1984, "date.getFullYear() = " + date.getFullYear());
1120 ok(date.getMonth() === 11, "date.getMonth() = " + date.getMonth());
1121 ok(date.getDate() === 29, "date.getDate() = " + date.getDate());
1122 ok(date.getHours() === 13, "date.getHours() = " + date.getHours());
1123 ok(date.getMinutes() === 51, "date.getMinutes() = " + date.getMinutes());
1124 ok(date.getSeconds() === 24, "date.getSeconds() = " + date.getSeconds());
1125 ok(date.getMilliseconds() === 120, "date.getMilliseconds() = " + date.getMilliseconds());
1126 date = new Date(731, -32, 40, -1, 70, 65, -13);
1127 ok(date.getFullYear() === 728, "date.getFullYear() = " + date.getFullYear());
1128 ok(date.getMonth() === 5, "date.getMonth() = " + date.getMonth());
1129 ok(date.getDate() === 9, "date.getDate() = " + date.getDate());
1130 ok(date.getHours() === 0, "date.getHours() = " + date.getHours());
1131 ok(date.getMinutes() === 11, "date.getMinutes() = " + date.getMinutes());
1132 ok(date.getSeconds() === 4, "date.getSeconds() = " + date.getSeconds());
1133 ok(date.getMilliseconds() === 987, "date.getMilliseconds() = " + date.getMilliseconds());
1134
1135 ok(date.setTime(123) === 123, "date.setTime(123) !== 123");
1136 ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123");
1137 ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
1138
1139 ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
1140 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
1141 ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
1142 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
1143 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
1144 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
1145 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
1146 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
1147 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1148 date.setTime(60*24*60*60*1000);
1149 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
1150 ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
1151 ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
1152 ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay());
1153 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
1154 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
1155 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
1156 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1157 date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
1158 ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
1159 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1160 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1161 ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
1162 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
1163 ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours());
1164 ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes());
1165 ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds());
1166 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1167 date.setTime(Infinity);
1168 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
1169 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
1170 ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
1171 ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN");
1172 ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN");
1173 ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
1174 ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN");
1175 ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN");
1176 ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN");
1177
1178 date.setTime(0);
1179 date.setUTCMilliseconds(-10, 2);
1180 ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1181 date.setUTCMilliseconds(10);
1182 ok(date.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1183 date.setUTCSeconds(-10);
1184 ok(date.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date.getUTCSeconds());
1185 date.setUTCMinutes(-10);
1186 ok(date.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date.getUTCMinutes());
1187 date.setUTCHours(-10);
1188 ok(date.getUTCHours() === 14, "date.getUTCHours() = " + date.getUTCHours());
1189 date.setUTCHours(-123);
1190 ok(date.getTime() === -612549990, "date.getTime() = " + date.getTime());
1191 date.setUTCHours(20);
1192 ok(date.getUTCHours() === 20, "date.getUTCHours() = " + date.getUTCHours());
1193 date.setUTCDate(32);
1194 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
1195 date.setUTCMonth(22, 37);
1196 ok(date.getTime() === 60987050010, "date.getTime() = " + date.getTime());
1197 date.setUTCFullYear(83, 21, 321);
1198 ok(date.getTime() === -59464984149990, "date.getTime() = " + date.getTime());
1199 ok(Math.abs(date) === 59464984149990, "Math.abs(date) = " + Math.abs(date));
1200 ok(getVT(date+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date+1));
1201
1202 ok(isNaN(Date.parse()), "Date.parse() is not NaN");
1203 ok(isNaN(Date.parse("")), "Date.parse(\"\") is not NaN");
1204 ok(isNaN(Date.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN");
1205 ok(Date.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date.parse("Jan 20 2009 UTC"));
1206 ok(Date.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date.parse("Jan 20 2009 GMT"));
1207 ok(Date.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date.parse("Jan 20 2009 UTC-0"));
1208 ok(Date.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date.parse("Jan 20 2009 UTC+0000"));
1209 ok(Date.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date.parse("Ju 13 79 UTC"));
1210 ok(Date.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date.parse("12Au91 UTC"));
1211 ok(Date.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date.parse("7/02/17 UTC"));
1212 ok(Date.parse("Se001   70 12:31:17 UTC") === 21040277000, "Date.parse(\"Se001   70 12:31:17 UTC\") = " + Date.parse("Se001   70 12:31:17 UTC"));
1213 ok(Date.parse("February 31   UTC, 2000 12:31:17 PM") === 952000277000,
1214         "Date.parse(\"February 31   UTC, 2000 12:31:17 PM\") = " + Date.parse("February 31   UTC, 2000 12:31:17 PM"));
1215 ok(Date.parse("71 11:32AM Dec 12 UTC BC ") === -64346358480000, "Date.parse(\"71 11:32AM Dec 12 UTC BC \") = " + Date.parse("71 11:32AM Dec 12 UTC BC "));
1216 ok(Date.parse("23/71/2000 11::32::UTC") === 1010662320000, "Date.parse(\"23/71/2000 11::32::UTC\") = " + Date.parse("23/71/2000 11::32::UTC"));
1217
1218 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
1219 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
1220 Math.PI = "test";
1221 ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI);
1222
1223 ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E));
1224 ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E);
1225 Math.E = "test";
1226 ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E);
1227
1228 ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E));
1229 ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E);
1230 Math.LOG2E = "test";
1231 ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E);
1232
1233 ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E));
1234 ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E);
1235 Math.LOG10E = "test";
1236 ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E);
1237
1238 ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2));
1239 ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2);
1240 Math.LN2 = "test";
1241 ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2);
1242
1243 ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10));
1244 ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10);
1245 Math.LN10 = "test";
1246 ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10);
1247
1248 ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2));
1249 ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2);
1250 Math.SQRT2 = "test";
1251 ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2);
1252
1253 ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2));
1254 ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
1255 Math.SQRT1_2 = "test";
1256 ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);
1257
1258 var bool = new Boolean();
1259 ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
1260 var bool = new Boolean("false");
1261 ok(bool.toString() === "true", "bool.toString() = " + bool.toString());
1262 ok(bool.valueOf() === Boolean(1), "bool.valueOf() = " + bool.valueOf());
1263 ok(bool.toLocaleString() === bool.toString(), "bool.toLocaleString() = " + bool.toLocaleString());
1264
1265 ok(Error.prototype !== TypeError.prototype, "Error.prototype === TypeError.prototype");
1266 ok(RangeError.prototype !== TypeError.prototype, "RangeError.prototype === TypeError.prototype");
1267 ok(Error.prototype.toLocaleString === Object.prototype.toLocaleString,
1268         "Error.prototype.toLocaleString !== Object.prototype.toLocaleString");
1269 err = new Error();
1270 ok(err.valueOf === Object.prototype.valueOf, "err.valueOf !== Object.prototype.valueOf");
1271 ok(Error.prototype.name === "Error", "Error.prototype.name = " + Error.prototype.name);
1272 ok(err.name === "Error", "err.name = " + err.name);
1273 EvalError.prototype.message = "test";
1274 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
1275 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1276 err = new EvalError();
1277 ok(EvalError.prototype.name === "EvalError", "EvalError.prototype.name = " + EvalError.prototype.name);
1278 ok(err.name === "EvalError", "err.name = " + err.name);
1279 ok(err.toString === Error.prototype.toString, "err.toString !== Error.prototype.toString");
1280 ok(err.message === "", "err.message != ''");
1281 err.message = date;
1282 ok(err.message === date, "err.message != date");
1283 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1284 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
1285 err = new RangeError();
1286 ok(RangeError.prototype.name === "RangeError", "RangeError.prototype.name = " + RangeError.prototype.name);
1287 ok(err.name === "RangeError", "err.name = " + err.name);
1288 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1289 err = new ReferenceError();
1290 ok(ReferenceError.prototype.name === "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError.prototype.name);
1291 ok(err.name === "ReferenceError", "err.name = " + err.name);
1292 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1293 err = new SyntaxError();
1294 ok(SyntaxError.prototype.name === "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError.prototype.name);
1295 ok(err.name === "SyntaxError", "err.name = " + err.name);
1296 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1297 err = new TypeError();
1298 ok(TypeError.prototype.name === "TypeError", "TypeError.prototype.name = " + TypeError.prototype.name);
1299 ok(err.name === "TypeError", "err.name = " + err.name);
1300 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1301 err = new URIError();
1302 ok(URIError.prototype.name === "URIError", "URIError.prototype.name = " + URIError.prototype.name);
1303 ok(err.name === "URIError", "err.name = " + err.name);
1304 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1305 err = new Error("message");
1306 ok(err.message === "message", "err.message !== 'message'");
1307 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1308 err = new Error(123);
1309 ok(err.number === 123, "err.number = " + err.number);
1310 err = new Error(0, "message");
1311 ok(err.number === 0, "err.number = " + err.number);
1312 ok(err.message === "message", "err.message = " + err.message);
1313 ok(err.description === "message", "err.description = " + err.description);
1314
1315 function exception_test(func, type, number) {
1316     ret = "";
1317     num = "";
1318     try {
1319         func();
1320     } catch(e) {
1321         ret = e.name;
1322         num = e.number;
1323     }
1324     ok(ret === type, "Exception test, ret = " + ret + ", expected " + type +". Executed function: " + func.toString());
1325     ok(num === number, "Exception test, num = " + num + ", expected " + number + ". Executed function: " + func.toString());
1326 }
1327 exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError", -2146823282);
1328 exception_test(function() {Array(-3);}, "RangeError", -2146823259);
1329 exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError", -2146823278);
1330 exception_test(function() {date.setTime();}, "TypeError", -2146827839);
1331 exception_test(function() {arr.test();}, "TypeError", -2146827850);
1332 exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError", -2146823287);
1333 exception_test(function() {(new Number(3)).toString(1);}, "TypeError", -2146828283);
1334 exception_test(function() {not_existing_variable.something();}, "TypeError", -2146823279);
1335 exception_test(function() {arr.toString = Function.prototype.toString; arr.toString();}, "TypeError", -2146823286);
1336 exception_test(function() {date();}, "TypeError", -2146823286);
1337 exception_test(function() {arr();}, "TypeError", -2146823286);
1338 exception_test(function() {eval("for(i=0;) {}");}, "SyntaxError", -2146827286);
1339 exception_test(function() {eval("function {};");}, "SyntaxError", -2146827283);
1340 exception_test(function() {eval("if");}, "SyntaxError", -2146827283);
1341 exception_test(function() {eval("do i=0; while");}, "SyntaxError", -2146827283);
1342 exception_test(function() {eval("while");}, "SyntaxError", -2146827283);
1343 exception_test(function() {eval("for");}, "SyntaxError", -2146827283);
1344 exception_test(function() {eval("with");}, "SyntaxError", -2146827283);
1345 exception_test(function() {eval("switch");}, "SyntaxError", -2146827283);
1346 exception_test(function() {eval("if(false");}, "SyntaxError", -2146827282);
1347 exception_test(function() {eval("for(i=0; i<10; i++");}, "SyntaxError", -2146827282);
1348 exception_test(function() {eval("while(true");}, "SyntaxError", -2146827282);
1349 exception_test(function() {test = function() {}}, "ReferenceError", -2146823280);
1350 exception_test(function() {eval("for(i=0")}, "SyntaxError", -2146827284);
1351 exception_test(function() {eval("for(i=0;i<10")}, "SyntaxError", -2146827284);
1352 exception_test(function() {eval("while(")}, "SyntaxError", -2146827286);
1353 exception_test(function() {eval("if(")}, "SyntaxError", -2146827286);
1354 exception_test(function() {eval("'unterminated")}, "SyntaxError", -2146827273);
1355
1356 function testObjectInherit(obj, ts, tls, vo) {
1357     ok(obj.hasOwnProperty === Object.prototype.hasOwnProperty,
1358        "obj.hasOwnProperty !== Object.prototype.hasOwnProprty");
1359     ok(obj.isPrototypeOf === Object.prototype.isPrototypeOf,
1360        "obj.isPrototypeOf !== Object.prototype.isPrototypeOf");
1361     ok(obj.propertyIsEnumerable === Object.prototype.propertyIsEnumerable,
1362        "obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable");
1363
1364     if(ts)
1365         ok(obj.toString === Object.prototype.toString,
1366            "obj.toString !== Object.prototype.toString");
1367     else
1368         ok(obj.toString != Object.prototype.toString,
1369            "obj.toString == Object.prototype.toString");
1370
1371     if(tls)
1372         ok(obj.toLocaleString === Object.prototype.toLocaleString,
1373            "obj.toLocaleString !== Object.prototype.toLocaleString");
1374     else
1375         ok(obj.toLocaleString != Object.prototype.toLocaleString,
1376            "obj.toLocaleString == Object.prototype.toLocaleString");
1377
1378     if(vo)
1379         ok(obj.valueOf === Object.prototype.valueOf,
1380            "obj.valueOf !== Object.prototype.valueOf");
1381     else
1382         ok(obj.valueOf != Object.prototype.valueOf,
1383            "obj.valueOf == Object.prototype.valueOf");
1384
1385     ok(obj._test === "test", "obj.test = " + obj._test);
1386 }
1387
1388 Object.prototype._test = "test";
1389 testObjectInherit(new String("test"), false, true, false);
1390 testObjectInherit(/test/g, false, true, true);
1391 testObjectInherit(new Number(1), false, false, false);
1392 testObjectInherit(new Date(), false, false, false);
1393 testObjectInherit(new Boolean(true), false, true, false);
1394 testObjectInherit(new Array(), false, false, true);
1395
1396 reportSuccess();