jscript: Added Array.unshift implementation.
[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 var strObj = new Object();
115 strObj.toString = function() { return "abcd" };
116 strObj.substr = String.prototype.substr;
117 strObj.lastIndexOf = String.prototype.lastIndexOf;
118
119 tmp = "value " + str;
120 ok(tmp === "value test", "'value ' + str = " + tmp);
121
122 tmp = String();
123 ok(tmp === "", "String() = " + tmp);
124 tmp = String(false);
125 ok(tmp === "false", "String(false) = " + tmp);
126 tmp = String(null);
127 ok(tmp === "null", "String(null) = " + tmp);
128 tmp = String("test");
129 ok(tmp === "test", "String('test') = " + tmp);
130 tmp = String("test", "abc");
131 ok(tmp === "test", "String('test','abc') = " + tmp);
132
133 tmp = "abc".charAt(0);
134 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
135 tmp = "abc".charAt(1);
136 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
137 tmp = "abc".charAt(2);
138 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
139 tmp = "abc".charAt(3);
140 ok(tmp === "", "'abc',charAt(3) = " + tmp);
141 tmp = "abc".charAt(4);
142 ok(tmp === "", "'abc',charAt(4) = " + tmp);
143 tmp = "abc".charAt();
144 ok(tmp === "a", "'abc',charAt() = " + tmp);
145 tmp = "abc".charAt(-1);
146 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
147 tmp = "abc".charAt(0,2);
148 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
149
150 tmp = "abc".charCodeAt(0);
151 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
152 tmp = "abc".charCodeAt(1);
153 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
154 tmp = "abc".charCodeAt(2);
155 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
156 tmp = "abc".charCodeAt();
157 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
158 tmp = "abc".charCodeAt(true);
159 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
160 tmp = "abc".charCodeAt(0,2);
161 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
162
163 tmp = "abcd".substring(1,3);
164 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
165 tmp = "abcd".substring(-1,3);
166 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
167 tmp = "abcd".substring(1,6);
168 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
169 tmp = "abcd".substring(3,1);
170 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
171 tmp = "abcd".substring(2,2);
172 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
173 tmp = "abcd".substring(true,"3");
174 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
175 tmp = "abcd".substring(1,3,2);
176 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
177 tmp = "abcd".substring();
178 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
179
180 tmp = "abcd".substr(1,3);
181 ok(tmp === "bcd", "'abcd'.substr(1,3) = " + tmp);
182 tmp = "abcd".substr(-1,3);
183 ok(tmp === "abc", "'abcd'.substr(-1,3) = " + tmp);
184 tmp = "abcd".substr(1,6);
185 ok(tmp === "bcd", "'abcd'.substr(1,6) = " + tmp);
186 tmp = "abcd".substr(2,-1);
187 ok(tmp === "", "'abcd'.substr(3,1) = " + tmp);
188 tmp = "abcd".substr(2,0);
189 ok(tmp === "", "'abcd'.substr(2,2) = " + tmp);
190 tmp = "abcd".substr(true,"3");
191 ok(tmp === "bcd", "'abcd'.substr(true,'3') = " + tmp);
192 tmp = "abcd".substr(1,3,2);
193 ok(tmp === "bcd", "'abcd'.substr(1,3,2) = " + tmp);
194 tmp = "abcd".substr();
195 ok(tmp === "abcd", "'abcd'.substr() = " + tmp);
196 tmp = strObj.substr(1,1);
197 ok(tmp === "b", "'abcd'.substr(1,3) = " + tmp);
198
199 tmp = "abcd".slice(1,3);
200 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
201 tmp = "abcd".slice(1,-1);
202 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
203 tmp = "abcd".slice(-3,3);
204 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
205 tmp = "abcd".slice(-6,3);
206 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
207 tmp = "abcd".slice(3,1);
208 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
209 tmp = "abcd".slice(true,3);
210 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
211 tmp = "abcd".slice();
212 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
213 tmp = "abcd".slice(1);
214 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
215
216 tmp = "abc".concat(["d",1],2,false);
217 ok(tmp === "abcd,12false", "concat returned " + tmp);
218 var arr = new Array(2,"a");
219 arr.concat = String.prototype.concat;
220 tmp = arr.concat("d");
221 ok(tmp === "2,ad", "arr.concat = " + tmp);
222
223 m = "a+bcabc".match("a+");
224 ok(typeof(m) === "object", "typeof m is not object");
225 ok(m.length === 1, "m.length is not 1");
226 ok(m["0"] === "a", "m[0] is not \"ab\"");
227
228 r = "- [test] -".replace("[test]", "success");
229 ok(r === "- success -", "r = " + r + " expected '- success -'");
230
231 r = "- [test] -".replace("[test]", "success", "test");
232 ok(r === "- success -", "r = " + r + " expected '- success -'");
233
234 r = "test".replace();
235 ok(r === "test", "r = " + r + " expected 'test'");
236
237 function replaceFunc3(m, off, str) {
238     ok(arguments.length === 3, "arguments.length = " + arguments.length);
239     ok(m === "[test]", "m = " + m + " expected [test1]");
240     ok(off === 1, "off = " + off + " expected 0");
241     ok(str === "-[test]-", "str = " + arguments[3]);
242     return "ret";
243 }
244
245 r = "-[test]-".replace("[test]", replaceFunc3);
246 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
247
248 r = "-[test]-".replace("[test]", replaceFunc3, "test");
249 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
250
251 r = "1,2,3".split(",");
252 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
253 ok(r.length === 3, "r.length = " + r.length);
254 ok(r[0] === "1", "r[0] = " + r[0]);
255 ok(r[1] === "2", "r[1] = " + r[1]);
256 ok(r[2] === "3", "r[2] = " + r[2]);
257
258
259 r = "1,2,3".split(",*");
260 ok(r.length === 1, "r.length = " + r.length);
261 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
262
263 r = "123".split("");
264 ok(r.length === 3, "r.length = " + r.length);
265 ok(r[0] === "1", "r[0] = " + r[0]);
266 ok(r[1] === "2", "r[1] = " + r[1]);
267 ok(r[2] === "3", "r[2] = " + r[2]);
268
269 r = "123".split(2);
270 ok(r.length === 2, "r.length = " + r.length);
271 ok(r[0] === "1", "r[0] = " + r[0]);
272 ok(r[1] === "3", "r[1] = " + r[1]);
273
274 r = "1,2,".split(",");
275 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
276 ok(r.length === 3, "r.length = " + r.length);
277 ok(r[0] === "1", "r[0] = " + r[0]);
278 ok(r[1] === "2", "r[1] = " + r[1]);
279 ok(r[2] === "", "r[2] = " + r[2]);
280
281 tmp = "abcd".indexOf("bc",0);
282 ok(tmp === 1, "indexOf = " + tmp);
283 tmp = "abcd".indexOf("bc",1);
284 ok(tmp === 1, "indexOf = " + tmp);
285 tmp = "abcd".indexOf("bc");
286 ok(tmp === 1, "indexOf = " + tmp);
287 tmp = "abcd".indexOf("ac");
288 ok(tmp === -1, "indexOf = " + tmp);
289 tmp = "abcd".indexOf("bc",2);
290 ok(tmp === -1, "indexOf = " + tmp);
291 tmp = "abcd".indexOf("a",0);
292 ok(tmp === 0, "indexOf = " + tmp);
293 tmp = "abcd".indexOf("bc",0,"test");
294 ok(tmp === 1, "indexOf = " + tmp);
295 tmp = "abcd".indexOf();
296 ok(tmp == -1, "indexOf = " + tmp);
297
298 tmp = "abcd".lastIndexOf("bc",1);
299 ok(tmp === 1, "lastIndexOf = " + tmp);
300 tmp = "abcd".lastIndexOf("bc",2);
301 ok(tmp === 1, "lastIndexOf = " + tmp);
302 tmp = "abcd".lastIndexOf("bc");
303 ok(tmp === 1, "lastIndexOf = " + tmp);
304 tmp = "abcd".lastIndexOf("ac");
305 ok(tmp === -1, "lastIndexOf = " + tmp);
306 tmp = "abcd".lastIndexOf("d",10);
307 ok(tmp === 3, "lastIndexOf = " + tmp);
308 tmp = "abcd".lastIndexOf("bc",0,"test");
309 ok(tmp === -1, "lastIndexOf = " + tmp);
310 tmp = "abcd".lastIndexOf();
311 ok(tmp === -1, "lastIndexOf = " + tmp);
312 tmp = "aaaa".lastIndexOf("a",2);
313 ok(tmp == 2, "lastIndexOf = " + tmp);
314 tmp = strObj.lastIndexOf("b");
315 ok(tmp === 1, "lastIndexOf = " + tmp);
316
317 tmp = "".toLowerCase();
318 ok(tmp === "", "''.toLowerCase() = " + tmp);
319 tmp = "test".toLowerCase();
320 ok(tmp === "test", "''.toLowerCase() = " + tmp);
321 tmp = "test".toLowerCase(3);
322 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
323 tmp = "tEsT".toLowerCase();
324 ok(tmp === "test", "''.toLowerCase() = " + tmp);
325 tmp = "tEsT".toLowerCase(3);
326 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
327
328 tmp = "".toUpperCase();
329 ok(tmp === "", "''.toUpperCase() = " + tmp);
330 tmp = "TEST".toUpperCase();
331 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
332 tmp = "TEST".toUpperCase(3);
333 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
334 tmp = "tEsT".toUpperCase();
335 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
336 tmp = "tEsT".toUpperCase(3);
337 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
338
339 tmp = "".anchor();
340 ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp);
341 tmp = "".anchor(3);
342 ok(tmp === "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp);
343 tmp = "".anchor("red");
344 ok(tmp === "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp);
345 tmp = "test".anchor();
346 ok(tmp === "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp);
347 tmp = "test".anchor(3);
348 ok(tmp === "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp);
349 tmp = "test".anchor("green");
350 ok(tmp === "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp);
351
352 tmp = "".big();
353 ok(tmp === "<BIG></BIG>", "''.big() = " + tmp);
354 tmp = "".big(3);
355 ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp);
356 tmp = "test".big();
357 ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp);
358 tmp = "test".big(3);
359 ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp);
360
361 tmp = "".blink();
362 ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp);
363 tmp = "".blink(3);
364 ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp);
365 tmp = "test".blink();
366 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp);
367 tmp = "test".blink(3);
368 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp);
369
370 tmp = "".bold();
371 ok(tmp === "<B></B>", "''.bold() = " + tmp);
372 tmp = "".bold(3);
373 ok(tmp === "<B></B>", "''.bold(3) = " + tmp);
374 tmp = "test".bold();
375 ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp);
376 tmp = "test".bold(3);
377 ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp);
378
379 tmp = "".fixed();
380 ok(tmp === "<TT></TT>", "''.fixed() = " + tmp);
381 tmp = "".fixed(3);
382 ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp);
383 tmp = "test".fixed();
384 ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp);
385 tmp = "test".fixed(3);
386 ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp);
387
388 tmp = "".fontcolor();
389 ok(tmp === "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp);
390 tmp = "".fontcolor(3);
391 ok(tmp === "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp);
392 tmp = "".fontcolor("red");
393 ok(tmp === "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp);
394 tmp = "test".fontcolor();
395 ok(tmp === "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp);
396 tmp = "test".fontcolor(3);
397 ok(tmp === "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp);
398 tmp = "test".fontcolor("green");
399 ok(tmp === "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp);
400
401 tmp = "".fontsize();
402 ok(tmp === "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp);
403 tmp = "".fontsize(3);
404 ok(tmp === "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp);
405 tmp = "".fontsize("red");
406 ok(tmp === "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp);
407 tmp = "test".fontsize();
408 ok(tmp === "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp);
409 tmp = "test".fontsize(3);
410 ok(tmp === "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp);
411 tmp = "test".fontsize("green");
412 ok(tmp === "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp);
413
414 tmp = ("".fontcolor()).fontsize();
415 ok(tmp === "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp);
416
417 tmp = "".italics();
418 ok(tmp === "<I></I>", "''.italics() = " + tmp);
419 tmp = "".italics(3);
420 ok(tmp === "<I></I>", "''.italics(3) = " + tmp);
421 tmp = "test".italics();
422 ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp);
423 tmp = "test".italics(3);
424 ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp);
425
426 tmp = "".link();
427 ok(tmp === "<A HREF=\"undefined\"></A>", "''.link() = " + tmp);
428 tmp = "".link(3);
429 ok(tmp === "<A HREF=\"3\"></A>", "''.link(3) = " + tmp);
430 tmp = "".link("red");
431 ok(tmp === "<A HREF=\"red\"></A>", "''.link('red') = " + tmp);
432 tmp = "test".link();
433 ok(tmp === "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp);
434 tmp = "test".link(3);
435 ok(tmp === "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp);
436 tmp = "test".link("green");
437 ok(tmp === "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp);
438
439 tmp = "".small();
440 ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp);
441 tmp = "".small(3);
442 ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp);
443 tmp = "test".small();
444 ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp);
445 tmp = "test".small(3);
446 ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp);
447
448 tmp = "".strike();
449 ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp);
450 tmp = "".strike(3);
451 ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp);
452 tmp = "test".strike();
453 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp);
454 tmp = "test".strike(3);
455 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp);
456
457 tmp = "".sub();
458 ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp);
459 tmp = "".sub(3);
460 ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp);
461 tmp = "test".sub();
462 ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp);
463 tmp = "test".sub(3);
464 ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp);
465
466 tmp = "".sup();
467 ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp);
468 tmp = "".sup(3);
469 ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp);
470 tmp = "test".sup();
471 ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
472 tmp = "test".sup(3);
473 ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
474
475 ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
476 ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
477 ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
478         "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
479 ok(String.fromCharCode(65, NaN, undefined).length === 3,
480         "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
481
482 var arr = new Array();
483 ok(typeof(arr) === "object", "arr () is not object");
484 ok((arr.length === 0), "arr.length is not 0");
485 ok(arr["0"] === undefined, "arr[0] is not undefined");
486
487 var arr = new Array(1, 2, "test");
488 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
489 ok((arr.length === 3), "arr.length is not 3");
490 ok(arr["0"] === 1, "arr[0] is not 1");
491 ok(arr["1"] === 2, "arr[1] is not 2");
492 ok(arr["2"] === "test", "arr[2] is not \"test\"");
493
494 arr["7"] = true;
495 ok((arr.length === 8), "arr.length is not 8");
496
497 tmp = "" + [];
498 ok(tmp === "", "'' + [] = " + tmp);
499 tmp = "" + [1,true];
500 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
501
502 var arr = new Array(6);
503 ok(typeof(arr) === "object", "arr (6) is not object");
504 ok((arr.length === 6), "arr.length is not 6");
505 ok(arr["0"] === undefined, "arr[0] is not undefined");
506
507 ok(arr.push() === 6, "arr.push() !== 6");
508 ok(arr.push(1) === 7, "arr.push(1) !== 7");
509 ok(arr[6] === 1, "arr[6] != 1");
510 ok(arr.length === 7, "arr.length != 10");
511 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
512 ok(arr[8] === "b", "arr[8] != 'b'");
513 ok(arr.length === 10, "arr.length != 10");
514
515 var arr = new Object();
516 arr.push = Array.prototype.push;
517
518 arr.length = 6;
519
520 ok(arr.push() === 6, "arr.push() !== 6");
521 ok(arr.push(1) === 7, "arr.push(1) !== 7");
522 ok(arr[6] === 1, "arr[6] != 1");
523 ok(arr.length === 7, "arr.length != 10");
524 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
525 ok(arr[8] === "b", "arr[8] != 'b'");
526 ok(arr.length === 10, "arr.length != 10");
527
528 arr = [3,4,5];
529 tmp = arr.pop();
530 ok(arr.length === 2, "arr.length = " + arr.length);
531 ok(tmp === 5, "pop() = " + tmp);
532 tmp = arr.pop(2);
533 ok(arr.length === 1, "arr.length = " + arr.length);
534 ok(tmp === 4, "pop() = " + tmp);
535 tmp = arr.pop();
536 ok(arr.length === 0, "arr.length = " + arr.length);
537 ok(tmp === 3, "pop() = " + tmp);
538 for(tmp in arr)
539     ok(false, "not deleted " + tmp);
540 tmp = arr.pop();
541 ok(arr.length === 0, "arr.length = " + arr.length);
542 ok(tmp === undefined, "tmp = " + tmp);
543 arr = [,,,,,];
544 tmp = arr.pop();
545 ok(arr.length === 5, "arr.length = " + arr.length);
546 ok(tmp === undefined, "tmp = " + tmp);
547
548 arr = [1,2,null,false,undefined,,"a"];
549
550 tmp = arr.join();
551 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
552 tmp = arr.join(";");
553 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
554 tmp = arr.join(";","test");
555 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
556 tmp = arr.join("");
557 ok(tmp === "12falsea", "arr.join('') = " + tmp);
558
559 tmp = arr.toString();
560 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
561 tmp = arr.toString("test");
562 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
563
564 arr = [5,true,2,-1,3,false,"2.5"];
565 tmp = arr.sort(function(x,y) { return y-x; });
566 ok(tmp === arr, "tmp !== arr");
567 tmp = [5,3,"2.5",2,true,false,-1];
568 for(var i=0; i < arr.length; i++)
569     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
570
571 arr = [5,false,2,0,"abc",3,"a",-1];
572 tmp = arr.sort();
573 ok(tmp === arr, "tmp !== arr");
574 tmp = [-1,0,2,3,5,"a","abc",false];
575 for(var i=0; i < arr.length; i++)
576     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
577
578 arr = ["a", "b", "ab"];
579 tmp = ["a", "ab", "b"];
580 ok(arr.sort() === arr, "arr.sort() !== arr");
581 for(var i=0; i < arr.length; i++)
582     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
583
584 arr = ["1", "2", "3"];
585 arr.length = 1;
586 ok(arr.length === 1, "arr.length = " + arr.length);
587 arr.length = 3;
588 ok(arr.length === 3, "arr.length = " + arr.length);
589 ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
590
591 arr = Array("a","b","c");
592 ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
593
594 ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
595 ok(arr === arr.valueOf(), "arr !== arr.valueOf");
596
597 arr = [1,2,3];
598 tmp = arr.unshift(0);
599 ok(tmp === undefined, "[1,2,3].unshift(0) returned " +tmp);
600 ok(arr.length === 4, "arr.length = " + arr.length);
601 ok(arr.toString() === "0,1,2,3", "arr.toString() = " + arr.toString());
602
603 arr = new Array(3);
604 arr[0] = 1;
605 arr[2] = 3;
606 tmp = arr.unshift(-1,0);
607 ok(tmp === undefined, "unshift returned " +tmp);
608 ok(arr.length === 5, "arr.length = " + arr.length);
609 ok(arr.toString() === "-1,0,1,,3", "arr.toString() = " + arr.toString());
610
611 arr = [1,2,3];
612 tmp = arr.unshift();
613 ok(tmp === undefined, "unshift returned " +tmp);
614 ok(arr.length === 3, "arr.length = " + arr.length);
615 ok(arr.toString() === "1,2,3", "arr.toString() = " + arr.toString());
616
617 arr = new Object();
618 arr.length = 2;
619 arr[0] = 1;
620 arr[1] = 2;
621 tmp = Array.prototype.unshift.call(arr, 0);
622 ok(tmp === undefined, "unshift returned " +tmp);
623 ok(arr.length === 3, "arr.length = " + arr.length);
624 ok(arr[0] === 0 && arr[1] === 1 && arr[2] === 2, "unexpected array");
625
626 var num = new Number(6);
627 arr = [0,1,2];
628 tmp = arr.concat(3, [4,5], num);
629 ok(tmp !== arr, "tmp === arr");
630 for(var i=0; i<6; i++)
631     ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
632 ok(tmp[6] === num, "tmp[6] !== num");
633 ok(tmp.length === 7, "tmp.length = " + tmp.length);
634
635 arr = [].concat();
636 ok(arr.length === 0, "arr.length = " + arr.length);
637
638 arr = [1,];
639 tmp = arr.concat([2]);
640 ok(tmp.length === 3, "tmp.length = " + tmp.length);
641 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
642
643 arr = [1,false,'a',null,undefined,'a'];
644 ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6));
645 ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length);
646 ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice());
647 ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc"));
648 ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8));
649 ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length);
650 ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1));
651 ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2));
652 ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1));
653 tmp = arr.slice(0,6);
654 for(var i=0; i < arr.length; i++)
655     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
656 arr[12] = 2;
657 ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString());
658 ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length);
659
660 obj = new Object();
661 obj.length = 3;
662 obj[0] = 1;
663 obj[1] = 2;
664 obj[2] = 3;
665 tmp = Array.prototype.slice.call(obj, 1, 2);
666 ok(tmp.length === 1, "tmp.length = " + tmp.length);
667 ok(tmp[0] === 2, "tmp[0] = " + tmp[0]);
668
669 var num = new Number(2);
670 ok(num.toString() === "2", "num(2).toString !== 2");
671 var num = new Number();
672 ok(num.toString() === "0", "num().toString !== 0");
673
674 ok(Number() === 0, "Number() = " + Number());
675 ok(Number(false) === 0, "Number(false) = " + Number(false));
676 ok(Number("43") === 43, "Number('43') = " + Number("43"));
677
678 tmp = (new Number(1)).valueOf();
679 ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
680 tmp = (new Number(1,2)).valueOf();
681 ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
682 tmp = (new Number()).valueOf();
683 ok(tmp === 0, "(new Number()).valueOf = " + tmp);
684 tmp = Number.prototype.valueOf();
685 ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
686
687 function equals(val, base) {
688     var i;
689     var num = 0;
690     var str = val.toString(base);
691
692     for(i=0; i<str.length; i++) {
693         if(str.substring(i, i+1) == '(') break;
694         if(str.substring(i, i+1) == '.') break;
695         num = num*base + parseInt(str.substring(i, i+1));
696     }
697
698     if(str.substring(i, i+1) == '.') {
699         var mult = base;
700         for(i++; i<str.length; i++) {
701             if(str.substring(i, i+1) == '(') break;
702             num += parseInt(str.substring(i, i+1))/mult;
703             mult *= base;
704         }
705     }
706
707     if(str.substring(i, i+1) == '(') {
708         exp = parseInt(str.substring(i+2));
709         num *= Math.pow(base, exp);
710     }
711
712     ok(num>val-val/1000 && num<val+val/1000, "equals: num = " + num);
713 }
714
715 ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11));
716 ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17));
717 ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33));
718 ok((NaN).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN).toString(11));
719 ok((Infinity).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity).toString(11));
720 for(i=2; i<10; i++) {
721     equals(1.123, i);
722     equals(2305843009200000000, i);
723     equals(5.123, i);
724     equals(21711, i);
725     equals(1024*1024*1024*1024*1024*1024*1.9999, i);
726     equals(748382, i);
727     equals(0.6, i);
728     equals(4.65661287308e-10, i);
729     ok((0).toString(i) === "0", "(0).toString("+i+") = " + (0).toString(i));
730 }
731
732 ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123'));
733 ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7'));
734 ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2'));
735 ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5'));
736 ok(parseFloat('1E5 not parsed') === 1E5, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed'));
737 ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
738 ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
739 ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
740 ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
741
742 tmp = Math.min(1);
743 ok(tmp === 1, "Math.min(1) = " + tmp);
744
745 tmp = Math.min(1, false);
746 ok(tmp === 0, "Math.min(1, false) = " + tmp);
747
748 tmp = Math.min();
749 ok(tmp === Infinity, "Math.min() = " + tmp);
750
751 tmp = Math.min(1, NaN, -Infinity, false);
752 ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
753
754 tmp = Math.min(1, false, true, null, -3);
755 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
756
757 tmp = Math.max(1);
758 ok(tmp === 1, "Math.max(1) = " + tmp);
759
760 tmp = Math.max(true, 0);
761 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
762
763 tmp = Math.max(-2, false, true, null, 1);
764 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
765
766 tmp = Math.max();
767 ok(tmp === -Infinity, "Math.max() = " + tmp);
768
769 tmp = Math.max(true, NaN, 0);
770 ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
771
772 tmp = Math.round(0.5);
773 ok(tmp === 1, "Math.round(0.5) = " + tmp);
774
775 tmp = Math.round(-0.5);
776 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
777
778 tmp = Math.round(1.1);
779 ok(tmp === 1, "Math.round(1.1) = " + tmp);
780
781 tmp = Math.round(true);
782 ok(tmp === 1, "Math.round(true) = " + tmp);
783
784 tmp = Math.round(1.1, 3, 4);
785 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
786
787 tmp = Math.round();
788 ok(isNaN(tmp), "Math.round() is not NaN");
789
790 tmp = Math.ceil(0.5);
791 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
792
793 tmp = Math.ceil(-0.5);
794 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
795
796 tmp = Math.ceil(1.1);
797 ok(tmp === 2, "Math.round(1.1) = " + tmp);
798
799 tmp = Math.ceil(true);
800 ok(tmp === 1, "Math.ceil(true) = " + tmp);
801
802 tmp = Math.ceil(1.1, 3, 4);
803 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
804
805 tmp = Math.ceil();
806 ok(isNaN(tmp), "ceil() is not NaN");
807
808 tmp = Math.floor(0.5);
809 ok(tmp === 0, "Math.floor(0.5) = " + tmp);
810
811 tmp = Math.floor(-0.5);
812 ok(tmp === -1, "Math.floor(-0.5) = " + tmp);
813
814 tmp = Math.floor(1.1);
815 ok(tmp === 1, "Math.floor(1.1) = " + tmp);
816
817 tmp = Math.floor(true);
818 ok(tmp === 1, "Math.floor(true) = " + tmp);
819
820 tmp = Math.floor(1.1, 3, 4);
821 ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp);
822
823 tmp = Math.floor();
824 ok(isNaN(tmp), "floor is not NaN");
825
826 tmp = Math.abs(3);
827 ok(tmp === 3, "Math.abs(3) = " + tmp);
828
829 tmp = Math.abs(-3);
830 ok(tmp === 3, "Math.abs(-3) = " + tmp);
831
832 tmp = Math.abs(true);
833 ok(tmp === 1, "Math.abs(true) = " + tmp);
834
835 tmp = Math.abs();
836 ok(isNaN(tmp), "Math.abs() is not NaN");
837
838 tmp = Math.abs(NaN);
839 ok(isNaN(tmp), "Math.abs() is not NaN");
840
841 tmp = Math.abs(-Infinity);
842 ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp);
843
844 tmp = Math.abs(-3, 2);
845 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
846
847 tmp = Math.cos(0);
848 ok(tmp === 1, "Math.cos(0) = " + tmp);
849
850 tmp = Math.cos(Math.PI/2);
851 ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp);
852
853 tmp = Math.cos(-Math.PI/2);
854 ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp);
855
856 tmp = Math.cos(Math.PI/3, 2);
857 ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp);
858
859 tmp = Math.cos(true);
860 ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp);
861
862 tmp = Math.cos(false);
863 ok(tmp === 1, "Math.cos(false) = " + tmp);
864
865 tmp = Math.cos();
866 ok(isNaN(tmp), "Math.cos() is not NaN");
867
868 tmp = Math.cos(NaN);
869 ok(isNaN(tmp), "Math.cos(NaN) is not NaN");
870
871 tmp = Math.cos(Infinity);
872 ok(isNaN(tmp), "Math.cos(Infinity) is not NaN");
873
874 tmp = Math.cos(-Infinity);
875 ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN");
876
877 tmp = Math.pow(2, 2);
878 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
879
880 tmp = Math.pow(4, 0.5);
881 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
882
883 tmp = Math.pow(2, 2, 3);
884 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
885
886 tmp = Math.pow(2);
887 ok(isNaN(tmp), "Math.pow(2) is not NaN");
888
889 tmp = Math.pow();
890 ok(isNaN(tmp), "Math.pow() is not NaN");
891
892 tmp = Math.random();
893 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
894 ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp);
895
896 tmp = Math.random(100);
897 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
898 ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp);
899
900 tmp = Math.acos(0);
901 ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp);
902
903 tmp = Math.acos(1);
904 ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp);
905
906 tmp = Math.acos(-1);
907 ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp);
908
909 tmp = Math.acos(Math.PI/4, 2);
910 ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp);
911
912 tmp = Math.acos(true);
913 ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp);
914
915 tmp = Math.acos(false);
916 ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp);
917
918 tmp = Math.acos(1.1);
919 ok(isNaN(tmp), "Math.acos(1.1) is not NaN");
920
921 tmp = Math.acos();
922 ok(isNaN(tmp), "Math.acos() is not NaN");
923
924 tmp = Math.acos(NaN);
925 ok(isNaN(tmp), "Math.acos(NaN) is not NaN");
926
927 tmp = Math.acos(Infinity);
928 ok(isNaN(tmp), "Math.acos(Infinity) is not NaN");
929
930 tmp = Math.acos(-Infinity);
931 ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN");
932
933 tmp = Math.asin(0);
934 ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp);
935
936 tmp = Math.asin(1);
937 ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp);
938
939 tmp = Math.asin(-1);
940 ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp);
941
942 tmp = Math.asin(Math.PI/4, 2);
943 ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp);
944
945 tmp = Math.asin(true);
946 ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp);
947
948 tmp = Math.asin(false);
949 ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp);
950
951 tmp = Math.asin(1.1);
952 ok(isNaN(tmp), "Math.asin(1.1) is not NaN");
953
954 tmp = Math.asin();
955 ok(isNaN(tmp), "Math.asin() is not NaN");
956
957 tmp = Math.asin(NaN);
958 ok(isNaN(tmp), "Math.asin(NaN) is not NaN");
959
960 tmp = Math.asin(Infinity);
961 ok(isNaN(tmp), "Math.asin(Infinity) is not NaN");
962
963 tmp = Math.asin(-Infinity);
964 ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN");
965
966 tmp = Math.atan(0);
967 ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp);
968
969 tmp = Math.atan(1);
970 ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp);
971
972 tmp = Math.atan(-1);
973 ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp);
974
975 tmp = Math.atan(true);
976 ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp);
977
978 tmp = Math.atan(false);
979 ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp);
980
981 tmp = Math.atan();
982 ok(isNaN(tmp), "Math.atan() is not NaN");
983
984 tmp = Math.atan(NaN);
985 ok(isNaN(tmp), "Math.atan(NaN) is not NaN");
986
987 tmp = Math.atan(Infinity);
988 ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp);
989
990 tmp = Math.atan(-Infinity);
991 ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp);
992
993 tmp = Math.atan2(0, 0);
994 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp);
995
996 tmp = Math.atan2(0, 1);
997 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp);
998
999 tmp = Math.atan2(0, Infinity);
1000 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp);
1001
1002 tmp = Math.atan2(0, -1);
1003 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp);
1004
1005 tmp = Math.atan2(0, -Infinity);
1006 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp);
1007
1008 tmp = Math.atan2(1, 0);
1009 ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp);
1010
1011 tmp = Math.atan2(Infinity, 0);
1012 ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp);
1013
1014 tmp = Math.atan2(-1, 0);
1015 ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp);
1016
1017 tmp = Math.atan2(-Infinity, 0);
1018 ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp);
1019
1020 tmp = Math.atan2(1, 1);
1021 ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp);
1022
1023 tmp = Math.atan2(-1, -1);
1024 ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp);
1025
1026 tmp = Math.atan2(-1, 1);
1027 ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp);
1028
1029 tmp = Math.atan2(Infinity, Infinity);
1030 ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp);
1031
1032 tmp = Math.atan2(Infinity, -Infinity, 1);
1033 ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp);
1034
1035 tmp = Math.atan2();
1036 ok(isNaN(tmp), "Math.atan2() is not NaN");
1037
1038 tmp = Math.atan2(1);
1039 ok(isNaN(tmp), "Math.atan2(1) is not NaN");
1040
1041 tmp = Math.exp(0);
1042 ok(tmp === 1, "Math.exp(0) = " + tmp);
1043
1044 tmp = Math.exp(1);
1045 ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp);
1046
1047 tmp = Math.exp(-1);
1048 ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp);
1049
1050 tmp = Math.exp(true);
1051 ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp);
1052
1053 tmp = Math.exp(1, 1);
1054 ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp);
1055
1056 tmp = Math.exp();
1057 ok(isNaN(tmp), "Math.exp() is not NaN");
1058
1059 tmp = Math.exp(NaN);
1060 ok(isNaN(tmp), "Math.exp(NaN) is not NaN");
1061
1062 tmp = Math.exp(Infinity);
1063 ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp);
1064
1065 tmp = Math.exp(-Infinity);
1066 ok(tmp === 0, "Math.exp(-Infinity) = " + tmp);
1067
1068 tmp = Math.log(1);
1069 ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp);
1070
1071 tmp = Math.log(-1);
1072 ok(isNaN(tmp), "Math.log(-1) is not NaN");
1073
1074 tmp = Math.log(true);
1075 ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp);
1076
1077 tmp = Math.log(1, 1);
1078 ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp);
1079
1080 tmp = Math.log();
1081 ok(isNaN(tmp), "Math.log() is not NaN");
1082
1083 tmp = Math.log(NaN);
1084 ok(isNaN(tmp), "Math.log(NaN) is not NaN");
1085
1086 tmp = Math.log(Infinity);
1087 ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
1088
1089 tmp = Math.log(-Infinity);
1090 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
1091
1092 tmp = Math.sin(0);
1093 ok(tmp === 0, "Math.sin(0) = " + tmp);
1094
1095 tmp = Math.sin(Math.PI/2);
1096 ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
1097
1098 tmp = Math.sin(-Math.PI/2);
1099 ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
1100
1101 tmp = Math.sin(Math.PI/3, 2);
1102 ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
1103
1104 tmp = Math.sin(true);
1105 ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
1106
1107 tmp = Math.sin(false);
1108 ok(tmp === 0, "Math.sin(false) = " + tmp);
1109
1110 tmp = Math.sin();
1111 ok(isNaN(tmp), "Math.sin() is not NaN");
1112
1113 tmp = Math.sin(NaN);
1114 ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
1115
1116 tmp = Math.sin(Infinity);
1117 ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
1118
1119 tmp = Math.sin(-Infinity);
1120 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
1121
1122 tmp = Math.sqrt(0);
1123 ok(tmp === 0, "Math.sqrt(0) = " + tmp);
1124
1125 tmp = Math.sqrt(4);
1126 ok(tmp === 2, "Math.sqrt(4) = " + tmp);
1127
1128 tmp = Math.sqrt(-1);
1129 ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
1130
1131 tmp = Math.sqrt(2, 2);
1132 ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
1133
1134 tmp = Math.sqrt(true);
1135 ok(tmp === 1, "Math.sqrt(true) = " + tmp);
1136
1137 tmp = Math.sqrt(false);
1138 ok(tmp === 0, "Math.sqrt(false) = " + tmp);
1139
1140 tmp = Math.sqrt();
1141 ok(isNaN(tmp), "Math.sqrt() is not NaN");
1142
1143 tmp = Math.sqrt(NaN);
1144 ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
1145
1146 tmp = Math.sqrt(Infinity);
1147 ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
1148
1149 tmp = Math.sqrt(-Infinity);
1150 ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
1151
1152 tmp = Math.tan(0);
1153 ok(tmp === 0, "Math.tan(0) = " + tmp);
1154
1155 tmp = Math.tan(Math.PI);
1156 ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp);
1157
1158 tmp = Math.tan(2, 2);
1159 ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp);
1160
1161 tmp = Math.tan(true);
1162 ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp);
1163
1164 tmp = Math.tan(false);
1165 ok(tmp === 0, "Math.tan(false) = " + tmp);
1166
1167 tmp = Math.tan();
1168 ok(isNaN(tmp), "Math.tan() is not NaN");
1169
1170 tmp = Math.tan(NaN);
1171 ok(isNaN(tmp), "Math.tan(NaN) is not NaN");
1172
1173 tmp = Math.tan(Infinity);
1174 ok(isNaN(tmp), "Math.tan(Infinity) is not NaN");
1175
1176 tmp = Math.tan(-Infinity);
1177 ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
1178
1179 var func = function  (a) {
1180         var a = 1;
1181         if(a) return;
1182     };
1183 ok(func.toString() === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
1184    "func.toString() = " + func.toString());
1185 ok("" + func === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
1186    "'' + func.toString() = " + func);
1187
1188 ok(func.valueOf === Object.prototype.valueOf, "func.valueOf !== Object.prototype.valueOf");
1189 ok(func === func.valueOf(), "func !== func.valueOf()");
1190
1191 function testFuncToString(x,y) {
1192     return x+y;
1193 }
1194 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n    return x+y;\n}",
1195    "testFuncToString.toString() = " + testFuncToString.toString());
1196 ok("" + testFuncToString === "function testFuncToString(x,y) {\n    return x+y;\n}",
1197    "'' + testFuncToString = " + testFuncToString);
1198
1199 tmp = new Object();
1200
1201 function callTest(argc) {
1202     ok(this === tmp, "this !== tmp\n");
1203     ok(arguments.length === argc+1, "arguments.length = " + arguments.length + " expected " + (argc+1));
1204     for(var i=1; i <= argc; i++)
1205         ok(arguments[i] === i, "arguments[i] = " + arguments[i]);
1206 }
1207
1208 callTest.call(tmp, 1, 1);
1209 callTest.call(tmp, 2, 1, 2);
1210
1211 callTest.apply(tmp, [1, 1]);
1212 callTest.apply(tmp, [2, 1, 2]);
1213 (function () { callTest.apply(tmp, arguments); })(2,1,2);
1214
1215 function callTest2() {
1216     ok(this === tmp, "this !== tmp\n");
1217     ok(arguments.length === 0, "callTest2: arguments.length = " + arguments.length + " expected 0");
1218 }
1219
1220 callTest2.call(tmp);
1221 callTest2.apply(tmp, []);
1222 callTest2.apply(tmp);
1223 (function () { callTest2.apply(tmp, arguments); })();
1224
1225 function callTest3() {
1226     ok(arguments.length === 0, "arguments.length = " + arguments.length + " expected 0");
1227 }
1228
1229 callTest3.call();
1230
1231 tmp = Number.prototype.toString.call(3);
1232 ok(tmp === "3", "Number.prototype.toString.call(3) = " + tmp);
1233
1234 var date = new Date();
1235
1236 date = new Date(100);
1237 ok(date.getTime() === 100, "date.getTime() = " + date.getTime());
1238 ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime());
1239 date = new Date(8.64e15);
1240 ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime());
1241 date = new Date(8.64e15+1);
1242 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
1243 date = new Date(Infinity);
1244 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
1245 date = new Date("3 July 2009 22:28:00 UTC+0100");
1246 ok(date.getTime() === 1246656480000, "date.getTime() = " + date.getTime());
1247 date = new Date(1984, 11, 29, 13, 51, 24, 120);
1248 ok(date.getFullYear() === 1984, "date.getFullYear() = " + date.getFullYear());
1249 ok(date.getMonth() === 11, "date.getMonth() = " + date.getMonth());
1250 ok(date.getDate() === 29, "date.getDate() = " + date.getDate());
1251 ok(date.getHours() === 13, "date.getHours() = " + date.getHours());
1252 ok(date.getMinutes() === 51, "date.getMinutes() = " + date.getMinutes());
1253 ok(date.getSeconds() === 24, "date.getSeconds() = " + date.getSeconds());
1254 ok(date.getMilliseconds() === 120, "date.getMilliseconds() = " + date.getMilliseconds());
1255 date = new Date(731, -32, 40, -1, 70, 65, -13);
1256 ok(date.getFullYear() === 728, "date.getFullYear() = " + date.getFullYear());
1257 ok(date.getMonth() === 5, "date.getMonth() = " + date.getMonth());
1258 ok(date.getDate() === 9, "date.getDate() = " + date.getDate());
1259 ok(date.getHours() === 0, "date.getHours() = " + date.getHours());
1260 ok(date.getMinutes() === 11, "date.getMinutes() = " + date.getMinutes());
1261 ok(date.getSeconds() === 4, "date.getSeconds() = " + date.getSeconds());
1262 ok(date.getMilliseconds() === 987, "date.getMilliseconds() = " + date.getMilliseconds());
1263
1264 ok(date.setTime(123) === 123, "date.setTime(123) !== 123");
1265 ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123");
1266 ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
1267
1268 ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
1269 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
1270 ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
1271 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
1272 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
1273 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
1274 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
1275 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
1276 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1277 date.setTime(60*24*60*60*1000);
1278 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
1279 ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
1280 ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
1281 ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay());
1282 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
1283 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
1284 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
1285 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1286 date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
1287 ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
1288 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1289 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1290 ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
1291 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
1292 ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours());
1293 ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes());
1294 ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds());
1295 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1296 date.setTime(Infinity);
1297 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
1298 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
1299 ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
1300 ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN");
1301 ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN");
1302 ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
1303 ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN");
1304 ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN");
1305 ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN");
1306
1307 date.setTime(0);
1308 date.setUTCMilliseconds(-10, 2);
1309 ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1310 date.setUTCMilliseconds(10);
1311 ok(date.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1312 date.setUTCSeconds(-10);
1313 ok(date.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date.getUTCSeconds());
1314 date.setUTCMinutes(-10);
1315 ok(date.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date.getUTCMinutes());
1316 date.setUTCHours(-10);
1317 ok(date.getUTCHours() === 14, "date.getUTCHours() = " + date.getUTCHours());
1318 date.setUTCHours(-123);
1319 ok(date.getTime() === -612549990, "date.getTime() = " + date.getTime());
1320 date.setUTCHours(20);
1321 ok(date.getUTCHours() === 20, "date.getUTCHours() = " + date.getUTCHours());
1322 date.setUTCDate(32);
1323 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
1324 date.setUTCMonth(22, 37);
1325 ok(date.getTime() === 60987050010, "date.getTime() = " + date.getTime());
1326 date.setUTCFullYear(83, 21, 321);
1327 ok(date.getTime() === -59464984149990, "date.getTime() = " + date.getTime());
1328 ok(Math.abs(date) === 59464984149990, "Math.abs(date) = " + Math.abs(date));
1329 ok(getVT(date+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date+1));
1330
1331 ok(isNaN(Date.parse()), "Date.parse() is not NaN");
1332 ok(isNaN(Date.parse("")), "Date.parse(\"\") is not NaN");
1333 ok(isNaN(Date.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN");
1334 ok(Date.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date.parse("Jan 20 2009 UTC"));
1335 ok(Date.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date.parse("Jan 20 2009 GMT"));
1336 ok(Date.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date.parse("Jan 20 2009 UTC-0"));
1337 ok(Date.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date.parse("Jan 20 2009 UTC+0000"));
1338 ok(Date.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date.parse("Ju 13 79 UTC"));
1339 ok(Date.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date.parse("12Au91 UTC"));
1340 ok(Date.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date.parse("7/02/17 UTC"));
1341 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"));
1342 ok(Date.parse("February 31   UTC, 2000 12:31:17 PM") === 952000277000,
1343         "Date.parse(\"February 31   UTC, 2000 12:31:17 PM\") = " + Date.parse("February 31   UTC, 2000 12:31:17 PM"));
1344 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 "));
1345 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"));
1346
1347 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
1348 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
1349 Math.PI = "test";
1350 ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI);
1351
1352 ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E));
1353 ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E);
1354 Math.E = "test";
1355 ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E);
1356
1357 ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E));
1358 ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E);
1359 Math.LOG2E = "test";
1360 ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E);
1361
1362 ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E));
1363 ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E);
1364 Math.LOG10E = "test";
1365 ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E);
1366
1367 ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2));
1368 ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2);
1369 Math.LN2 = "test";
1370 ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2);
1371
1372 ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10));
1373 ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10);
1374 Math.LN10 = "test";
1375 ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10);
1376
1377 ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2));
1378 ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2);
1379 Math.SQRT2 = "test";
1380 ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2);
1381
1382 ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2));
1383 ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
1384 Math.SQRT1_2 = "test";
1385 ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);
1386
1387 var bool = new Boolean();
1388 ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
1389 var bool = new Boolean("false");
1390 ok(bool.toString() === "true", "bool.toString() = " + bool.toString());
1391 ok(bool.valueOf() === Boolean(1), "bool.valueOf() = " + bool.valueOf());
1392 ok(bool.toLocaleString() === bool.toString(), "bool.toLocaleString() = " + bool.toLocaleString());
1393
1394 ok(Error.prototype !== TypeError.prototype, "Error.prototype === TypeError.prototype");
1395 ok(RangeError.prototype !== TypeError.prototype, "RangeError.prototype === TypeError.prototype");
1396 ok(Error.prototype.toLocaleString === Object.prototype.toLocaleString,
1397         "Error.prototype.toLocaleString !== Object.prototype.toLocaleString");
1398 err = new Error();
1399 ok(err.valueOf === Object.prototype.valueOf, "err.valueOf !== Object.prototype.valueOf");
1400 ok(Error.prototype.name === "Error", "Error.prototype.name = " + Error.prototype.name);
1401 ok(err.name === "Error", "err.name = " + err.name);
1402 EvalError.prototype.message = "test";
1403 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
1404 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1405 err = new EvalError();
1406 ok(EvalError.prototype.name === "EvalError", "EvalError.prototype.name = " + EvalError.prototype.name);
1407 ok(err.name === "EvalError", "err.name = " + err.name);
1408 ok(err.toString === Error.prototype.toString, "err.toString !== Error.prototype.toString");
1409 ok(err.message === "", "err.message != ''");
1410 err.message = date;
1411 ok(err.message === date, "err.message != date");
1412 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1413 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
1414 err = new RangeError();
1415 ok(RangeError.prototype.name === "RangeError", "RangeError.prototype.name = " + RangeError.prototype.name);
1416 ok(err.name === "RangeError", "err.name = " + err.name);
1417 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1418 err = new ReferenceError();
1419 ok(ReferenceError.prototype.name === "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError.prototype.name);
1420 ok(err.name === "ReferenceError", "err.name = " + err.name);
1421 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1422 err = new SyntaxError();
1423 ok(SyntaxError.prototype.name === "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError.prototype.name);
1424 ok(err.name === "SyntaxError", "err.name = " + err.name);
1425 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1426 err = new TypeError();
1427 ok(TypeError.prototype.name === "TypeError", "TypeError.prototype.name = " + TypeError.prototype.name);
1428 ok(err.name === "TypeError", "err.name = " + err.name);
1429 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1430 err = new URIError();
1431 ok(URIError.prototype.name === "URIError", "URIError.prototype.name = " + URIError.prototype.name);
1432 ok(err.name === "URIError", "err.name = " + err.name);
1433 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1434 err = new Error("message");
1435 ok(err.message === "message", "err.message !== 'message'");
1436 ok(err.toString() === "[object Error]", "err.toString() = " + err.toString());
1437 err = new Error(123);
1438 ok(err.number === 123, "err.number = " + err.number);
1439 err = new Error(0, "message");
1440 ok(err.number === 0, "err.number = " + err.number);
1441 ok(err.message === "message", "err.message = " + err.message);
1442 ok(err.description === "message", "err.description = " + err.description);
1443
1444 function exception_test(func, type, number) {
1445     ret = "";
1446     num = "";
1447     try {
1448         func();
1449     } catch(e) {
1450         ret = e.name;
1451         num = e.number;
1452     }
1453     ok(ret === type, "Exception test, ret = " + ret + ", expected " + type +". Executed function: " + func.toString());
1454     ok(num === number, "Exception test, num = " + num + ", expected " + number + ". Executed function: " + func.toString());
1455 }
1456 exception_test(function() {arr.toString = Date.prototype.toString; arr.toString();}, "TypeError", -2146823282);
1457 exception_test(function() {Array(-3);}, "RangeError", -2146823259);
1458 exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError", -2146823278);
1459 exception_test(function() {date.setTime();}, "TypeError", -2146827839);
1460 exception_test(function() {arr.test();}, "TypeError", -2146827850);
1461 exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError", -2146823287);
1462 exception_test(function() {(new Number(3)).toString(1);}, "TypeError", -2146828283);
1463 exception_test(function() {not_existing_variable.something();}, "TypeError", -2146823279);
1464 exception_test(function() {arr.toString = Function.prototype.toString; arr.toString();}, "TypeError", -2146823286);
1465 exception_test(function() {date();}, "TypeError", -2146823286);
1466 exception_test(function() {arr();}, "TypeError", -2146823286);
1467 exception_test(function() {eval("for(i=0;) {}");}, "SyntaxError", -2146827286);
1468 exception_test(function() {eval("function {};");}, "SyntaxError", -2146827283);
1469 exception_test(function() {eval("if");}, "SyntaxError", -2146827283);
1470 exception_test(function() {eval("do i=0; while");}, "SyntaxError", -2146827283);
1471 exception_test(function() {eval("while");}, "SyntaxError", -2146827283);
1472 exception_test(function() {eval("for");}, "SyntaxError", -2146827283);
1473 exception_test(function() {eval("with");}, "SyntaxError", -2146827283);
1474 exception_test(function() {eval("switch");}, "SyntaxError", -2146827283);
1475 exception_test(function() {eval("if(false");}, "SyntaxError", -2146827282);
1476 exception_test(function() {eval("for(i=0; i<10; i++");}, "SyntaxError", -2146827282);
1477 exception_test(function() {eval("while(true");}, "SyntaxError", -2146827282);
1478 exception_test(function() {test = function() {}}, "ReferenceError", -2146823280);
1479 exception_test(function() {eval("for(i=0")}, "SyntaxError", -2146827284);
1480 exception_test(function() {eval("for(i=0;i<10")}, "SyntaxError", -2146827284);
1481 exception_test(function() {eval("while(")}, "SyntaxError", -2146827286);
1482 exception_test(function() {eval("if(")}, "SyntaxError", -2146827286);
1483 exception_test(function() {eval("'unterminated")}, "SyntaxError", -2146827273);
1484
1485 function testObjectInherit(obj, constr, ts, tls, vo) {
1486     ok(obj instanceof Object, "obj is not instance of Object");
1487     ok(obj instanceof constr, "obj is not instance of its constructor");
1488
1489     ok(obj.hasOwnProperty === Object.prototype.hasOwnProperty,
1490        "obj.hasOwnProperty !== Object.prototype.hasOwnProprty");
1491     ok(obj.isPrototypeOf === Object.prototype.isPrototypeOf,
1492        "obj.isPrototypeOf !== Object.prototype.isPrototypeOf");
1493     ok(obj.propertyIsEnumerable === Object.prototype.propertyIsEnumerable,
1494        "obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable");
1495
1496     if(ts)
1497         ok(obj.toString === Object.prototype.toString,
1498            "obj.toString !== Object.prototype.toString");
1499     else
1500         ok(obj.toString != Object.prototype.toString,
1501            "obj.toString == Object.prototype.toString");
1502
1503     if(tls)
1504         ok(obj.toLocaleString === Object.prototype.toLocaleString,
1505            "obj.toLocaleString !== Object.prototype.toLocaleString");
1506     else
1507         ok(obj.toLocaleString != Object.prototype.toLocaleString,
1508            "obj.toLocaleString == Object.prototype.toLocaleString");
1509
1510     if(vo)
1511         ok(obj.valueOf === Object.prototype.valueOf,
1512            "obj.valueOf !== Object.prototype.valueOf");
1513     else
1514         ok(obj.valueOf != Object.prototype.valueOf,
1515            "obj.valueOf == Object.prototype.valueOf");
1516
1517     ok(obj._test === "test", "obj.test = " + obj._test);
1518 }
1519
1520 Object.prototype._test = "test";
1521 testObjectInherit(new String("test"), String, false, true, false);
1522 testObjectInherit(/test/g, RegExp, false, true, true);
1523 testObjectInherit(new Number(1), Number, false, false, false);
1524 testObjectInherit(new Date(), Date, false, false, false);
1525 testObjectInherit(new Boolean(true), Boolean, false, true, false);
1526 testObjectInherit(new Array(), Array, false, false, true);
1527 testObjectInherit(new Error(), Error, false, true, true);
1528 testObjectInherit(testObjectInherit, Function, false, true, true);
1529 testObjectInherit(Math, Object, true, true, true);
1530
1531 (function() { testObjectInherit(arguments, Object, true, true, true); })();
1532
1533 function testFunctions(obj, arr) {
1534     var l;
1535
1536     for(var i=0; i<arr.length; i++) {
1537         l = obj[arr[i][0]].length;
1538         ok(l === arr[i][1], arr[i][0] + ".length = " + l);
1539     }
1540 }
1541
1542 testFunctions(Boolean.prototype, [
1543         ["valueOf", 0],
1544         ["toString", 0]
1545     ]);
1546
1547 testFunctions(Number.prototype, [
1548         ["valueOf", 0],
1549         ["toString", 1],
1550         ["toExponential", 1],
1551         ["toLocaleString", 0],
1552         ["toPrecision", 1]
1553     ]);
1554
1555 testFunctions(String.prototype, [
1556         ["valueOf", 0],
1557         ["toString", 0],
1558         ["anchor", 1],
1559         ["big", 0],
1560         ["blink", 0],
1561         ["bold", 0],
1562         ["charAt", 1],
1563         ["charCodeAt", 1],
1564         ["concat", 1],
1565         ["fixed", 0],
1566         ["fontcolor", 1],
1567         ["fontsize", 1],
1568         ["indexOf", 2],
1569         ["italics", 0],
1570         ["lastIndexOf", 2],
1571         ["link", 1],
1572         ["localeCompare", 1],
1573         ["match", 1],
1574         ["replace", 1],
1575         ["search", 0],
1576         ["slice", 0],
1577         ["small", 0],
1578         ["split", 2],
1579         ["strike", 0],
1580         ["sub", 0],
1581         ["substr", 2],
1582         ["substring", 2],
1583         ["sup", 0],
1584         ["toLocaleLowerCase", 0],
1585         ["toLocaleUpperCase", 0],
1586         ["toLowerCase", 0],
1587         ["toUpperCase", 0]
1588     ]);
1589
1590 testFunctions(RegExp.prototype, [
1591         ["toString", 0],
1592         ["exec", 1],
1593         ["test", 1]
1594     ]);
1595
1596 testFunctions(Date.prototype, [
1597         ["getDate", 0],
1598         ["getDay", 0],
1599         ["getFullYear", 0],
1600         ["getHours", 0],
1601         ["getMilliseconds", 0],
1602         ["getMinutes", 0],
1603         ["getMonth", 0],
1604         ["getSeconds", 0],
1605         ["getTime", 0],
1606         ["getTimezoneOffset", 0],
1607         ["getUTCDate", 0],
1608         ["getUTCDay", 0],
1609         ["getUTCFullYear", 0],
1610         ["getUTCHours", 0],
1611         ["getUTCMilliseconds", 0],
1612         ["getUTCMinutes", 0],
1613         ["getUTCMonth", 0],
1614         ["getUTCSeconds", 0],
1615         ["setDate", 1],
1616         ["setFullYear", 3],
1617         ["setHours", 4],
1618         ["setMilliseconds", 1],
1619         ["setMinutes", 3],
1620         ["setMonth", 2],
1621         ["setSeconds", 2],
1622         ["setTime", 1],
1623         ["setUTCDate", 1],
1624         ["setUTCFullYear", 3],
1625         ["setUTCHours", 4],
1626         ["setUTCMilliseconds", 1],
1627         ["setUTCMinutes", 3],
1628         ["setUTCMonth", 2],
1629         ["setUTCSeconds", 2],
1630         ["toDateString", 0],
1631         ["toLocaleDateString", 0],
1632         ["toLocaleString", 0],
1633         ["toLocaleTimeString", 0],
1634         ["toString", 0],
1635         ["toTimeString", 0],
1636         ["toUTCString", 0],
1637         ["valueOf", 0]
1638     ]);
1639
1640 testFunctions(Array.prototype, [
1641         ["concat", 1],
1642         ["join", 1],
1643         ["push", 1],
1644         ["pop", 0],
1645         ["reverse", 0],
1646         ["shift", 0],
1647         ["slice", 2],
1648         ["sort", 1],
1649         ["splice", 2],
1650         ["toLocaleString", 0],
1651         ["toString", 0],
1652         ["unshift", 1]
1653     ]);
1654
1655 testFunctions(Error.prototype, [
1656         ["toString", 0]
1657     ]);
1658
1659 testFunctions(Math, [
1660         ["abs", 1],
1661         ["acos", 1],
1662         ["asin", 1],
1663         ["atan", 1],
1664         ["atan2", 2],
1665         ["ceil", 1],
1666         ["cos", 1],
1667         ["exp", 1],
1668         ["floor", 1],
1669         ["log", 1],
1670         ["max", 2],
1671         ["min", 2],
1672         ["pow", 2],
1673         ["random", 0],
1674         ["round", 1],
1675         ["sin", 1],
1676         ["sqrt", 1],
1677         ["tan", 1]
1678     ]);
1679
1680 testFunctions(Object.prototype, [
1681         ["hasOwnProperty", 1],
1682         ["isPrototypeOf", 1],
1683         ["propertyIsEnumerable", 1],
1684         ["toLocaleString", 0],
1685         ["toString", 0],
1686         ["valueOf", 0]
1687     ]);
1688
1689 testFunctions(Function.prototype, [
1690         ["apply", 2],
1691         ["call", 1],
1692         ["toString", 0]
1693     ]);
1694
1695 reportSuccess();