jscript: Use prototype for builtin Number properties.
[wine/multimedia.git] / dlls / jscript / tests / api.js
blobfc787a9ffbf549eb91830074ed4df3289b9de10f
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  */
19 var tmp, i;
21 var bigInt = Math.pow(2,40);
23 ok(ScriptEngine() === "JScript", "ScriptEngine() = " + ScriptEngine());
24 ok(ScriptEngine(3) === "JScript", "ScriptEngine(3) = " + ScriptEngine(3));
25 ok(ScriptEngineMajorVersion() === ScriptEngineMajorVersion(2), "ScriptEngineMajorVersion() !== ScriptEngineMajorVersion(2)");
26 ok(ScriptEngineMinorVersion() === ScriptEngineMinorVersion(2), "ScriptEngineMinorVersion() !== ScriptEngineMinorVersion(2)");
27 ok(ScriptEngineBuildVersion() === ScriptEngineBuildVersion(2), "ScriptEngineBuildVersion() !== ScriptEngineBuildVersion(2)");
29 i = parseInt("0");
30 ok(i === 0, "parseInt('0') = " + i);
31 i = parseInt("123");
32 ok(i === 123, "parseInt('123') = " + i);
33 i = parseInt("-123");
34 ok(i === -123, "parseInt('-123') = " + i);
35 i = parseInt("0xff");
36 ok(i === 0xff, "parseInt('0xff') = " + i);
37 i = parseInt("11", 8);
38 ok(i === 9, "parseInt('11', 8) = " + i);
39 i = parseInt("1j", 22);
40 ok(i === 41, "parseInt('1j', 32) = " + i);
41 i = parseInt("123", 0);
42 ok(i === 123, "parseInt('123', 0) = " + i);
43 i = parseInt("123", 10, "test");
44 ok(i === 123, "parseInt('123', 10, 'test') = " + i);
45 i = parseInt("11", "8");
46 ok(i === 9, "parseInt('11', '8') = " + i);
47 i = parseInt("010");
48 ok(i === 8, "parseInt('010') = " + i);
49 i = parseInt("");
50 ok(isNaN(i), "parseInt('') = " + i);
51 i = parseInt("0x");
52 ok(isNaN(i), "parseInt('0x') = " + i);
53 i = parseInt("+");
54 ok(isNaN(i), "parseInt('+') = " + i);
55 i = parseInt("-");
56 ok(isNaN(i), "parseInt('-') = " + i);
57 i = parseInt("0x10", 11);
58 ok(i === 0, "parseInt('0x10', 11) = " + i);
59 i = parseInt("010", 7);
60 ok(i === 7, "parseInt('010', 7) = " + i);
61 i = parseInt("123abc");
62 ok(i === 123, "parseInt('123abc') = " + i);
63 i = parseInt("   \t123abc");
64 ok(i === 123, "parseInt('   \\t123abc') = " + i);
65 i = parseInt("abc");
66 ok(isNaN(i), "parseInt('123abc') = " + i);
67 i = parseInt("-12", 11);
68 ok(i === -13, "parseInt('-12') = " + i);
69 i = parseInt("-0x10");
70 ok(i === -16, "parseInt('-0x10') = " + i);
71 i = parseInt("-010");
72 ok(i === -8, "parseInt('-010') = " + i);
73 i = parseInt("123", 0);
74 ok(i === 123, "parseInt('123', 0) = " + i);
75 i = parseInt("0x10", 0);
76 ok(i === 16, "parseInt('123', 0) = " + i);
77 i = parseInt("0x10", 10);
78 ok(i === 0, "parseInt('0x10', 10) = " + i);
79 i = parseInt("0xz");
80 ok(isNaN(i), "parseInt('0xz') = " + i);
81 i = parseInt("1", 1);
82 ok(isNaN(i), "parseInt('1', 1) = " + i);
83 i = parseInt("1", -1);
84 ok(isNaN(i), "parseInt('1', -1) = " + i);
85 i = parseInt("1", 37);
86 ok(isNaN(i), "parseInt('1', 37) = " + i);
87 i = parseInt("1", 36);
88 ok(i === 1, "parseInt('1', 36) = " + i);
90 tmp = encodeURI("abc");
91 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
92 tmp = encodeURI("{abc}");
93 ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp);
94 tmp = encodeURI("");
95 ok(tmp === "", "encodeURI('') = " + tmp);
96 tmp = encodeURI("\01\02\03\04");
97 ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp);
98 tmp = encodeURI("{#@}");
99 ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp);
100 tmp = encodeURI("\xa1 ");
101 ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp);
102 tmp = encodeURI("\xffff");
103 ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length);
104 tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
105 ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
106 tmp = encodeURI("%");
107 ok(tmp === "%25", "encodeURI('%') = " + tmp);
108 tmp = encodeURI();
109 ok(tmp === "undefined", "encodeURI() = " + tmp);
110 tmp = encodeURI("abc", "test");
111 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
113 tmp = decodeURI("abc");
114 ok(tmp === "abc", "decodeURI('abc') = " + tmp);
115 tmp = decodeURI("{abc}");
116 ok(tmp === "{abc}", "decodeURI('{abc}') = " + tmp);
117 tmp = decodeURI("");
118 ok(tmp === "", "decodeURI('') = " + tmp);
119 tmp = decodeURI("\01\02\03\04");
120 ok(tmp === "\01\02\03\04", "decodeURI('\\01\\02\\03\\04') = " + tmp);
121 tmp = decodeURI();
122 ok(tmp === "undefined", "decodeURI() = " + tmp);
123 tmp = decodeURI("abc", "test");
124 ok(tmp === "abc", "decodeURI('abc') = " + tmp);
125 tmp = decodeURI("%7babc%7d");
126 ok(tmp === "{abc}", "decodeURI('%7Babc%7D') = " + tmp);
127 tmp = decodeURI("%01%02%03%04");
128 ok(tmp === "\01\02\03\04", "decodeURI('%01%02%03%04') = " + tmp);
129 tmp = decodeURI("%C2%A1%20");
130 ok(tmp === "\xa1 ", "decodeURI('%C2%A1%20') = " + tmp);
131 tmp = decodeURI("%C3%BFff");
132 ok(tmp.length === 3, "decodeURI('%C3%BFff').length = " + tmp.length);
134 tmp = encodeURIComponent("abc");
135 ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
136 dec = decodeURIComponent(tmp);
137 ok(dec === "abc", "decodeURIComponent('" + tmp + "') = " + dec);
138 tmp = encodeURIComponent("{abc}");
139 ok(tmp === "%7Babc%7D", "encodeURIComponent('{abc}') = " + tmp);
140 dec = decodeURIComponent(tmp);
141 ok(dec === "{abc}", "decodeURIComponent('" + tmp + "') = " + dec);
142 tmp = encodeURIComponent("");
143 ok(tmp === "", "encodeURIComponent('') = " + tmp);
144 dec = decodeURIComponent(tmp);
145 ok(dec === "", "decodeURIComponent('" + tmp + "') = " + dec);
146 tmp = encodeURIComponent("\01\02\03\04");
147 ok(tmp === "%01%02%03%04", "encodeURIComponent('\\01\\02\\03\\04') = " + tmp);
148 dec = decodeURIComponent(tmp);
149 ok(dec === "\01\02\03\04", "decodeURIComponent('" + tmp + "') = " + dec);
150 tmp = encodeURIComponent("{#@}");
151 ok(tmp === "%7B%23%40%7D", "encodeURIComponent('{#@}') = " + tmp);
152 dec = decodeURIComponent(tmp);
153 ok(dec === "{#@}", "decodeURIComponent('" + tmp + "') = " + dec);
154 tmp = encodeURIComponent("\xa1 ");
155 ok(tmp === "%C2%A1%20", "encodeURIComponent(\\xa1 ) = " + tmp);
156 dec = decodeURIComponent(tmp);
157 ok(dec === "\xa1 ", "decodeURIComponent('" + tmp + "') = " + dec);
158 tmp = encodeURIComponent("\xffff");
159 ok(tmp.length === 8, "encodeURIComponent('\\xffff').length = " + tmp.length);
160 dec = decodeURIComponent(tmp);
161 ok(dec === "\xffff", "decodeURIComponent('" + tmp + "') = " + dec);
162 tmp = encodeURIComponent("abcABC123;/?:@&=+$,-_.!~*'()");
163 ok(tmp === "abcABC123%3B%2F%3F%3A%40%26%3D%2B%24%2C-_.!~*'()", "encodeURIComponent('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
164 dec = decodeURIComponent(tmp);
165 ok(dec === "abcABC123;/?:@&=+$,-_.!~*'()", "decodeURIComponent('" + tmp + "') = " + dec);
166 tmp = encodeURIComponent();
167 ok(tmp === "undefined", "encodeURIComponent() = " + tmp);
168 tmp = encodeURIComponent("abc", "test");
169 ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
170 dec = decodeURIComponent();
171 ok(dec === "undefined", "decodeURIComponent() = " + dec);
172 dec = decodeURIComponent("abc", "test");
173 ok(dec === "abc", "decodeURIComponent('abc') = " + dec);
175 tmp = escape("abc");
176 ok(tmp === "abc", "escape('abc') = " + tmp);
177 tmp = escape("");
178 ok(tmp === "", "escape('') = " + tmp);
179 tmp = escape("a1b c!d+e@*-_+./,");
180 ok(tmp === "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp);
181 tmp = escape();
182 ok(tmp === "undefined", "escape() = " + tmp);
183 tmp = escape('\u1234\123\xf3');
184 ok(tmp == "%u1234S%F3", "escape('\u1234\123\xf3') = " + tmp);
186 tmp = unescape("abc");
187 ok(tmp === "abc", "unescape('abc') = " + tmp);
188 tmp = unescape("");
189 ok(tmp === "", "unescape('') = " + tmp);
190 tmp = unescape("%%%");
191 ok(tmp === "%%%", "unescape('%%%') = " + tmp);
192 tmp = unescape();
193 ok(tmp === "undefined", "unescape() = " + tmp);
194 tmp = unescape("%54%65s%u0074");
195 ok(tmp === "Test", "unescape('%54%65s%u0074') = " + tmp);
197 tmp = "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|";
198 ok(escape(tmp) === "aA1%7E%60%21@%23%24%25%5E%26*%28%29_+%3D-%5D%5B%7B%7D%27%3B%3A/.%2C%3C%3E%3F%7C", "escape('" + tmp + "') = " + escape(tmp));
199 ok(unescape(escape(tmp)) === tmp, "unescape(escape('" + tmp + "')) = " + unescape(escape(tmp)));
201 ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty('toString') is false");
202 ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false");
203 ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false");
205 obj = new Object();
207 ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
208 ok(!obj.hasOwnProperty('isPrototypeOf'), "obj.hasOwnProperty('isPrototypeOf') is true");
209 ok(!Object.hasOwnProperty('toString'), "Object.hasOwnProperty('toString') is true");
210 ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeOf') is true");
211 ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true");
212 ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true");
214 obj = new Array();
215 ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false");
216 ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false");
217 ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true");
218 ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true");
220 obj = new Boolean(false);
221 ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
222 ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true");
223 ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false");
225 obj = new Date();
226 ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
227 ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
228 ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
230 obj = new Number();
231 ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
232 ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true");
233 ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false");
235 tmp = "" + new Object();
236 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
237 (tmp = new Array).f = Object.prototype.toString;
238 ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f());
239 (tmp = new Boolean).f = Object.prototype.toString;
240 ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f());
241 (tmp = new Date).f = Object.prototype.toString;
242 ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f());
243 (tmp = function() {}).f = Object.prototype.toString;
244 ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f());
245 Math.f = Object.prototype.toString;
246 ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f());
247 (tmp = new Number).f = Object.prototype.toString;
248 ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
249 (tmp = new RegExp("")).f = Object.prototype.toString;
250 ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
251 (tmp = new String).f = Object.prototype.toString;
252 ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f());
253 tmp = Object.prototype.toString.call(testObj);
254 ok(tmp === "[object Object]", "toString.call(testObj) = " + tmp);
255 tmp = Object.prototype.toString.call(this);
256 ok(tmp === "[object Object]", "toString.call(this) = " + tmp);
257 (function () { tmp = Object.prototype.toString.call(arguments); })();
258 ok(tmp === "[object Object]", "toString.call(arguments) = " + tmp);
259 tmp = Object.prototype.toString.call(new VBArray(createArray()));
260 ok(tmp === "[object Object]", "toString.call(new VBArray()) = " + tmp);
262 function TSTestConstr() {}
263 TSTestConstr.prototype = { toString: function() { return "test"; } };
264 obj = new TSTestConstr();
265 ok(obj.toString() === "test", "obj.toString() = " + obj.toString());
267 ok(Object(1) instanceof Number, "Object(1) is not instance of Number");
268 ok(Object("") instanceof String, "Object('') is not instance of String");
269 ok(Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
271 obj = new Object();
272 ok(Object(obj) === obj, "Object(obj) !== obj");
274 ok(typeof(Object()) === "object", "typeof(Object()) !== 'object'");
275 ok(typeof(Object(undefined)) === "object", "typeof(Object(undefined)) !== 'object'");
276 ok(typeof(Object(null)) === "object", "typeof(Object(null)) !== 'object'");
278 var obj = new Object();
279 obj.toString = function (x) {
280     ok(arguments.length === 0, "arguments.length = " + arguments.length);
281     return "test";
283 ok((tmp = obj.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp);
284 ok((tmp = obj.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp);
285 ok(obj === obj.valueOf(), "obj !== obj.valueOf");
287 ok("".length === 0, "\"\".length = " + "".length);
288 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
289 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
290 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
292 tmp = "".toString();
293 ok(tmp === "", "''.toString() = " + tmp);
294 tmp = "test".toString();
295 ok(tmp === "test", "''.toString() = " + tmp);
296 tmp = "test".toString(3);
297 ok(tmp === "test", "''.toString(3) = " + tmp);
299 tmp = "".valueOf();
300 ok(tmp === "", "''.valueOf() = " + tmp);
301 tmp = "test".valueOf();
302 ok(tmp === "test", "''.valueOf() = " + tmp);
303 tmp = "test".valueOf(3);
304 ok(tmp === "test", "''.valueOf(3) = " + tmp);
306 var str = new String("test");
307 ok(str.toString() === "test", "str.toString() = " + str.toString());
308 var str = new String();
309 ok(str.toString() === "", "str.toString() = " + str.toString());
310 var str = new String("test", "abc");
311 ok(str.toString() === "test", "str.toString() = " + str.toString());
313 var strObj = new Object();
314 strObj.toString = function() { return "abcd" };
315 strObj.substr = String.prototype.substr;
316 strObj.lastIndexOf = String.prototype.lastIndexOf;
318 tmp = "value " + str;
319 ok(tmp === "value test", "'value ' + str = " + tmp);
321 tmp = String();
322 ok(tmp === "", "String() = " + tmp);
323 tmp = String(false);
324 ok(tmp === "false", "String(false) = " + tmp);
325 tmp = String(null);
326 ok(tmp === "null", "String(null) = " + tmp);
327 tmp = String("test");
328 ok(tmp === "test", "String('test') = " + tmp);
329 tmp = String("test", "abc");
330 ok(tmp === "test", "String('test','abc') = " + tmp);
332 tmp = "abc".charAt(0);
333 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
334 tmp = "abc".charAt(1);
335 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
336 tmp = "abc".charAt(2);
337 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
338 tmp = "abc".charAt(3);
339 ok(tmp === "", "'abc',charAt(3) = " + tmp);
340 tmp = "abc".charAt(4);
341 ok(tmp === "", "'abc',charAt(4) = " + tmp);
342 tmp = "abc".charAt();
343 ok(tmp === "a", "'abc',charAt() = " + tmp);
344 tmp = "abc".charAt(-1);
345 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
346 tmp = "abc".charAt(0,2);
347 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
348 tmp = "abc".charAt(NaN);
349 ok(tmp === "a", "'abc',charAt(NaN) = " + tmp);
350 tmp = "abc".charAt(bigInt);
351 ok(tmp === "", "'abc',charAt(bigInt) = " + tmp);
353 tmp = "abc".charCodeAt(0);
354 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
355 tmp = "abc".charCodeAt(1);
356 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
357 tmp = "abc".charCodeAt(2);
358 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
359 tmp = "abc".charCodeAt();
360 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
361 tmp = "abc".charCodeAt(true);
362 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
363 tmp = "abc".charCodeAt(0,2);
364 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
365 tmp = "\u49F4".charCodeAt(0);
366 ok(tmp === 0x49F4, "'\u49F4'.charCodeAt(0) = " + tmp);
367 tmp = "\052".charCodeAt(0);
368 ok(tmp === 0x2A, "'\052'.charCodeAt(0) = " + tmp);
369 tmp = "\xa2".charCodeAt(0);
370 ok(tmp === 0xA2, "'\xa2'.charCodeAt(0) = " + tmp);
371 tmp = "abc".charCodeAt(bigInt);
372 ok(isNaN(tmp), "'abc'.charCodeAt(bigInt) = " + tmp);
374 tmp = "abcd".substring(1,3);
375 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
376 tmp = "abcd".substring(-1,3);
377 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
378 tmp = "abcd".substring(1,6);
379 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
380 tmp = "abcd".substring(3,1);
381 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
382 tmp = "abcd".substring(2,2);
383 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
384 tmp = "abcd".substring(true,"3");
385 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
386 tmp = "abcd".substring(1,3,2);
387 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
388 tmp = "abcd".substring();
389 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
391 tmp = "abcd".substr(1,3);
392 ok(tmp === "bcd", "'abcd'.substr(1,3) = " + tmp);
393 tmp = "abcd".substr(-1,3);
394 ok(tmp === "abc", "'abcd'.substr(-1,3) = " + tmp);
395 tmp = "abcd".substr(1,6);
396 ok(tmp === "bcd", "'abcd'.substr(1,6) = " + tmp);
397 tmp = "abcd".substr(2,-1);
398 ok(tmp === "", "'abcd'.substr(3,1) = " + tmp);
399 tmp = "abcd".substr(2,0);
400 ok(tmp === "", "'abcd'.substr(2,2) = " + tmp);
401 tmp = "abcd".substr(true,"3");
402 ok(tmp === "bcd", "'abcd'.substr(true,'3') = " + tmp);
403 tmp = "abcd".substr(1,3,2);
404 ok(tmp === "bcd", "'abcd'.substr(1,3,2) = " + tmp);
405 tmp = "abcd".substr();
406 ok(tmp === "abcd", "'abcd'.substr() = " + tmp);
407 tmp = strObj.substr(1,1);
408 ok(tmp === "b", "'abcd'.substr(1,3) = " + tmp);
410 tmp = "abcd".slice(1,3);
411 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
412 tmp = "abcd".slice(1,-1);
413 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
414 tmp = "abcd".slice(-3,3);
415 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
416 tmp = "abcd".slice(-6,3);
417 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
418 tmp = "abcd".slice(3,1);
419 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
420 tmp = "abcd".slice(true,3);
421 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
422 tmp = "abcd".slice();
423 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
424 tmp = "abcd".slice(1);
425 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
427 tmp = "abc".concat(["d",1],2,false);
428 ok(tmp === "abcd,12false", "concat returned " + tmp);
429 var arr = new Array(2,"a");
430 arr.concat = String.prototype.concat;
431 tmp = arr.concat("d");
432 ok(tmp === "2,ad", "arr.concat = " + tmp);
434 m = "a+bcabc".match("a+");
435 ok(typeof(m) === "object", "typeof m is not object");
436 ok(m.length === 1, "m.length is not 1");
437 ok(m["0"] === "a", "m[0] is not \"a\"");
439 r = "- [test] -".replace("[test]", "success");
440 ok(r === "- success -", "r = " + r + " expected '- success -'");
442 r = "- [test] -".replace("[test]", "success", "test");
443 ok(r === "- success -", "r = " + r + " expected '- success -'");
445 r = "test".replace();
446 ok(r === "test", "r = " + r + " expected 'test'");
448 function replaceFunc3(m, off, str) {
449     ok(arguments.length === 3, "arguments.length = " + arguments.length);
450     ok(m === "[test]", "m = " + m + " expected [test]");
451     ok(off === 1, "off = " + off + " expected 0");
452     ok(str === "-[test]-", "str = " + arguments[3]);
453     return "ret";
456 r = "-[test]-".replace("[test]", replaceFunc3);
457 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
459 r = "-[test]-".replace("[test]", replaceFunc3, "test");
460 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
462 r = "x,x,x".replace("x", "y");
463 ok(r === "y,x,x", "r = " + r + " expected 'y,x,x'");
465 r = "x,x,x".replace("", "y");
466 ok(r === "yx,x,x", "r = " + r + " expected 'yx,x,x'");
468 r = "x,x,x".replace("", "");
469 ok(r === "x,x,x", "r = " + r + " expected 'x,x,x'");
471 r = "1,2,3".split(",");
472 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
473 ok(r.length === 3, "r.length = " + r.length);
474 ok(r[0] === "1", "r[0] = " + r[0]);
475 ok(r[1] === "2", "r[1] = " + r[1]);
476 ok(r[2] === "3", "r[2] = " + r[2]);
479 r = "1,2,3".split(",*");
480 ok(r.length === 1, "r.length = " + r.length);
481 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
483 r = "123".split("");
484 ok(r.length === 3, "r.length = " + r.length);
485 ok(r[0] === "1", "r[0] = " + r[0]);
486 ok(r[1] === "2", "r[1] = " + r[1]);
487 ok(r[2] === "3", "r[2] = " + r[2]);
489 r = "123".split(2);
490 ok(r.length === 2, "r.length = " + r.length);
491 ok(r[0] === "1", "r[0] = " + r[0]);
492 ok(r[1] === "3", "r[1] = " + r[1]);
494 r = "1,2,".split(",");
495 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
496 ok(r.length === 3, "r.length = " + r.length);
497 ok(r[0] === "1", "r[0] = " + r[0]);
498 ok(r[1] === "2", "r[1] = " + r[1]);
499 ok(r[2] === "", "r[2] = " + r[2]);
501 tmp = "abcd".indexOf("bc",0);
502 ok(tmp === 1, "indexOf = " + tmp);
503 tmp = "abcd".indexOf("bc",1);
504 ok(tmp === 1, "indexOf = " + tmp);
505 tmp = "abcd".indexOf("bc");
506 ok(tmp === 1, "indexOf = " + tmp);
507 tmp = "abcd".indexOf("ac");
508 ok(tmp === -1, "indexOf = " + tmp);
509 tmp = "abcd".indexOf("bc",2);
510 ok(tmp === -1, "indexOf = " + tmp);
511 tmp = "abcd".indexOf("a",0);
512 ok(tmp === 0, "indexOf = " + tmp);
513 tmp = "abcd".indexOf("bc",0,"test");
514 ok(tmp === 1, "indexOf = " + tmp);
515 tmp = "abcd".indexOf();
516 ok(tmp == -1, "indexOf = " + tmp);
517 tmp = "abcd".indexOf("b", bigInt);
518 ok(tmp == -1, "indexOf = " + tmp);
520 tmp = "abcd".lastIndexOf("bc",1);
521 ok(tmp === 1, "lastIndexOf = " + tmp);
522 tmp = "abcd".lastIndexOf("bc",2);
523 ok(tmp === 1, "lastIndexOf = " + tmp);
524 tmp = "abcd".lastIndexOf("bc");
525 ok(tmp === 1, "lastIndexOf = " + tmp);
526 tmp = "abcd".lastIndexOf("ac");
527 ok(tmp === -1, "lastIndexOf = " + tmp);
528 tmp = "abcd".lastIndexOf("d",10);
529 ok(tmp === 3, "lastIndexOf = " + tmp);
530 tmp = "abcd".lastIndexOf("bc",0,"test");
531 ok(tmp === -1, "lastIndexOf = " + tmp);
532 tmp = "abcd".lastIndexOf();
533 ok(tmp === -1, "lastIndexOf = " + tmp);
534 tmp = "aaaa".lastIndexOf("a",2);
535 ok(tmp == 2, "lastIndexOf = " + tmp);
536 tmp = strObj.lastIndexOf("b");
537 ok(tmp === 1, "lastIndexOf = " + tmp);
538 tmp = "bbb".lastIndexOf("b", bigInt);
539 ok(tmp === 2, "lastIndexOf = " + tmp);
541 tmp = "".toLowerCase();
542 ok(tmp === "", "''.toLowerCase() = " + tmp);
543 tmp = "test".toLowerCase();
544 ok(tmp === "test", "''.toLowerCase() = " + tmp);
545 tmp = "test".toLowerCase(3);
546 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
547 tmp = "tEsT".toLowerCase();
548 ok(tmp === "test", "''.toLowerCase() = " + tmp);
549 tmp = "tEsT".toLowerCase(3);
550 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
552 tmp = "".toUpperCase();
553 ok(tmp === "", "''.toUpperCase() = " + tmp);
554 tmp = "TEST".toUpperCase();
555 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
556 tmp = "TEST".toUpperCase(3);
557 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
558 tmp = "tEsT".toUpperCase();
559 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
560 tmp = "tEsT".toUpperCase(3);
561 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
563 tmp = "".anchor();
564 ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp);
565 tmp = "".anchor(3);
566 ok(tmp === "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp);
567 tmp = "".anchor("red");
568 ok(tmp === "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp);
569 tmp = "test".anchor();
570 ok(tmp === "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp);
571 tmp = "test".anchor(3);
572 ok(tmp === "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp);
573 tmp = "test".anchor("green");
574 ok(tmp === "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp);
576 tmp = "".big();
577 ok(tmp === "<BIG></BIG>", "''.big() = " + tmp);
578 tmp = "".big(3);
579 ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp);
580 tmp = "test".big();
581 ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp);
582 tmp = "test".big(3);
583 ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp);
585 tmp = "".blink();
586 ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp);
587 tmp = "".blink(3);
588 ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp);
589 tmp = "test".blink();
590 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp);
591 tmp = "test".blink(3);
592 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp);
594 tmp = "".bold();
595 ok(tmp === "<B></B>", "''.bold() = " + tmp);
596 tmp = "".bold(3);
597 ok(tmp === "<B></B>", "''.bold(3) = " + tmp);
598 tmp = "test".bold();
599 ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp);
600 tmp = "test".bold(3);
601 ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp);
603 tmp = "".fixed();
604 ok(tmp === "<TT></TT>", "''.fixed() = " + tmp);
605 tmp = "".fixed(3);
606 ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp);
607 tmp = "test".fixed();
608 ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp);
609 tmp = "test".fixed(3);
610 ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp);
612 tmp = "".fontcolor();
613 ok(tmp === "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp);
614 tmp = "".fontcolor(3);
615 ok(tmp === "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp);
616 tmp = "".fontcolor("red");
617 ok(tmp === "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp);
618 tmp = "test".fontcolor();
619 ok(tmp === "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp);
620 tmp = "test".fontcolor(3);
621 ok(tmp === "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp);
622 tmp = "test".fontcolor("green");
623 ok(tmp === "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp);
625 tmp = "".fontsize();
626 ok(tmp === "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp);
627 tmp = "".fontsize(3);
628 ok(tmp === "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp);
629 tmp = "".fontsize("red");
630 ok(tmp === "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp);
631 tmp = "test".fontsize();
632 ok(tmp === "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp);
633 tmp = "test".fontsize(3);
634 ok(tmp === "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp);
635 tmp = "test".fontsize("green");
636 ok(tmp === "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp);
638 tmp = ("".fontcolor()).fontsize();
639 ok(tmp === "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp);
641 tmp = "".italics();
642 ok(tmp === "<I></I>", "''.italics() = " + tmp);
643 tmp = "".italics(3);
644 ok(tmp === "<I></I>", "''.italics(3) = " + tmp);
645 tmp = "test".italics();
646 ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp);
647 tmp = "test".italics(3);
648 ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp);
650 tmp = "".link();
651 ok(tmp === "<A HREF=\"undefined\"></A>", "''.link() = " + tmp);
652 tmp = "".link(3);
653 ok(tmp === "<A HREF=\"3\"></A>", "''.link(3) = " + tmp);
654 tmp = "".link("red");
655 ok(tmp === "<A HREF=\"red\"></A>", "''.link('red') = " + tmp);
656 tmp = "test".link();
657 ok(tmp === "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp);
658 tmp = "test".link(3);
659 ok(tmp === "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp);
660 tmp = "test".link("green");
661 ok(tmp === "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp);
663 tmp = "".small();
664 ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp);
665 tmp = "".small(3);
666 ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp);
667 tmp = "test".small();
668 ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp);
669 tmp = "test".small(3);
670 ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp);
672 tmp = "".strike();
673 ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp);
674 tmp = "".strike(3);
675 ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp);
676 tmp = "test".strike();
677 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp);
678 tmp = "test".strike(3);
679 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp);
681 tmp = "".sub();
682 ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp);
683 tmp = "".sub(3);
684 ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp);
685 tmp = "test".sub();
686 ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp);
687 tmp = "test".sub(3);
688 ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp);
690 tmp = "".sup();
691 ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp);
692 tmp = "".sup(3);
693 ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp);
694 tmp = "test".sup();
695 ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
696 tmp = "test".sup(3);
697 ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
699 ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
700 ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
701 ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
702         "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
703 ok(String.fromCharCode(65, NaN, undefined).length === 3,
704         "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
706 var arr = new Array();
707 ok(typeof(arr) === "object", "arr () is not object");
708 ok((arr.length === 0), "arr.length is not 0");
709 ok(arr["0"] === undefined, "arr[0] is not undefined");
711 var arr = new Array(1, 2, "test");
712 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
713 ok((arr.length === 3), "arr.length is not 3");
714 ok(arr["0"] === 1, "arr[0] is not 1");
715 ok(arr["1"] === 2, "arr[1] is not 2");
716 ok(arr["2"] === "test", "arr[2] is not \"test\"");
718 arr["7"] = true;
719 ok((arr.length === 8), "arr.length is not 8");
721 tmp = "" + [];
722 ok(tmp === "", "'' + [] = " + tmp);
723 tmp = "" + [1,true];
724 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
726 var arr = new Array(6);
727 ok(typeof(arr) === "object", "arr (6) is not object");
728 ok((arr.length === 6), "arr.length is not 6");
729 ok(arr["0"] === undefined, "arr[0] is not undefined");
731 ok(arr.push() === 6, "arr.push() !== 6");
732 ok(arr.push(1) === 7, "arr.push(1) !== 7");
733 ok(arr[6] === 1, "arr[6] != 1");
734 ok(arr.length === 7, "arr.length != 10");
735 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
736 ok(arr[8] === "b", "arr[8] != 'b'");
737 ok(arr.length === 10, "arr.length != 10");
739 var arr = new Object();
740 arr.push = Array.prototype.push;
742 arr.length = 6;
744 ok(arr.push() === 6, "arr.push() !== 6");
745 ok(arr.push(1) === 7, "arr.push(1) !== 7");
746 ok(arr[6] === 1, "arr[6] != 1");
747 ok(arr.length === 7, "arr.length != 10");
748 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
749 ok(arr[8] === "b", "arr[8] != 'b'");
750 ok(arr.length === 10, "arr.length != 10");
752 arr.pop = Array.prototype.pop;
753 ok(arr.pop() === false, "arr.pop() !== false");
754 ok(arr[8] === "b", "arr[8] !== 'b'");
755 ok(arr.pop() === 'b', "arr.pop() !== 'b'");
756 ok(arr[8] === undefined, "arr[8] !== undefined");
758 arr = [3,4,5];
759 tmp = arr.pop();
760 ok(arr.length === 2, "arr.length = " + arr.length);
761 ok(tmp === 5, "pop() = " + tmp);
762 tmp = arr.pop(2);
763 ok(arr.length === 1, "arr.length = " + arr.length);
764 ok(tmp === 4, "pop() = " + tmp);
765 tmp = arr.pop();
766 ok(arr.length === 0, "arr.length = " + arr.length);
767 ok(tmp === 3, "pop() = " + tmp);
768 for(tmp in arr)
769     ok(false, "not deleted " + tmp);
770 tmp = arr.pop();
771 ok(arr.length === 0, "arr.length = " + arr.length);
772 ok(tmp === undefined, "tmp = " + tmp);
773 arr = new Object();
774 arr.pop = Array.prototype.pop;
775 tmp = arr.pop();
776 ok(arr.length === 0, "arr.length = " + arr.length);
777 ok(tmp === undefined, "tmp = " + tmp);
778 arr = [,,,,,];
779 tmp = arr.pop();
780 ok(arr.length === 5, "arr.length = " + arr.length);
781 ok(tmp === undefined, "tmp = " + tmp);
783 arr = [1,2,null,false,undefined,,"a"];
785 tmp = arr.join();
786 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
787 tmp = arr.join(";");
788 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
789 tmp = arr.join(";","test");
790 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
791 tmp = arr.join("");
792 ok(tmp === "12falsea", "arr.join('') = " + tmp);
794 tmp = arr.toString();
795 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
796 tmp = arr.toString("test");
797 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
799 arr = new Object();
800 arr.length = 3;
801 arr[0] = "aa";
802 arr[2] = 2;
803 arr[7] = 3;
804 arr.join = Array.prototype.join;
805 tmp = arr.join(",");
806 ok(arr.length === 3, "arr.length = " + arr.length);
807 ok(tmp === "aa,,2", "tmp = " + tmp);
809 arr = [5,true,2,-1,3,false,"2.5"];
810 tmp = arr.sort(function(x,y) { return y-x; });
811 ok(tmp === arr, "tmp !== arr");
812 tmp = [5,3,"2.5",2,true,false,-1];
813 for(var i=0; i < arr.length; i++)
814     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
816 arr = [5,false,2,0,"abc",3,"a",-1];
817 tmp = arr.sort();
818 ok(tmp === arr, "tmp !== arr");
819 tmp = [-1,0,2,3,5,"a","abc",false];
820 for(var i=0; i < arr.length; i++)
821     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
823 arr = ["a", "b", "ab"];
824 tmp = ["a", "ab", "b"];
825 ok(arr.sort() === arr, "arr.sort() !== arr");
826 for(var i=0; i < arr.length; i++)
827     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
829 arr = new Object();
830 arr.length = 3;
831 arr[0] = 1;
832 arr[2] = "aa";
833 arr.sort = Array.prototype.sort;
834 tmp = arr.sort();
835 ok(arr === tmp, "tmp !== arr");
836 ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorrectly");
838 tmp = [["bb","aa"],["ab","aa"]].sort().toString();
839 ok(tmp === "ab,aa,bb,aa", "sort() = " + tmp);
841 tmp = [["bb","aa"],"ab"].sort().toString();
842 ok(tmp === "ab,bb,aa", "sort() = " + tmp);
844 tmp = [["bb","aa"],"cc"].sort().toString();
845 ok(tmp === "bb,aa,cc", "sort() = " + tmp);
847 tmp = [2,"1"].sort().toString();
848 ok(tmp === "1,2", "sort() = " + tmp);
850 tmp = ["2",1].sort().toString();
851 ok(tmp === "1,2", "sort() = " + tmp);
853 tmp = [,,0,"z"].sort().toString();
854 ok(tmp === "0,z,,", "sort() = " + tmp);
856 tmp = ["a,b",["a","a"],["a","c"]].sort().toString();
857 ok(tmp === "a,a,a,b,a,c", "sort() = " + tmp);
859 arr = ["1", "2", "3"];
860 arr.length = 1;
861 ok(arr.length === 1, "arr.length = " + arr.length);
862 arr.length = 3;
863 ok(arr.length === 3, "arr.length = " + arr.length);
864 ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
866 arr = Array("a","b","c");
867 ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
869 ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
870 ok(arr === arr.valueOf(), "arr !== arr.valueOf");
872 arr = [1,2,3];
873 tmp = arr.reverse();
874 ok(tmp === arr, "tmp !== arr");
875 ok(arr.length === 3, "arr.length = " + arr.length);
876 ok(arr.toString() === "3,2,1", "arr.toString() = " + arr.toString());
878 arr = [];
879 arr[3] = 5;
880 arr[5] = 1;
881 tmp = arr.reverse();
882 ok(tmp === arr, "tmp !== arr");
883 ok(arr.length === 6, "arr.length = " + arr.length);
884 ok(arr.toString() === "1,,5,,,", "arr.toString() = " + arr.toString());
886 arr = new Object();
887 arr.length = 3;
888 arr[0] = "aa";
889 arr[2] = 2;
890 arr[7] = 3;
891 arr.reverse = Array.prototype.reverse;
892 tmp = arr.reverse();
893 ok(tmp === arr, "tmp !== arr");
894 ok(arr.length === 3, "arr.length = " + arr.length);
895 ok(arr[0] === 2 && arr[1] === undefined && arr[2] === "aa", "unexpected array");
897 arr = [1,2,3];
898 tmp = arr.unshift(0);
899 ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp);
900 ok(arr.length === 4, "arr.length = " + arr.length);
901 ok(arr.toString() === "0,1,2,3", "arr.toString() = " + arr.toString());
903 arr = new Array(3);
904 arr[0] = 1;
905 arr[2] = 3;
906 tmp = arr.unshift(-1,0);
907 ok(tmp === (invokeVersion < 2 ? undefined : 5), "unshift returned " +tmp);
908 ok(arr.length === 5, "arr.length = " + arr.length);
909 ok(arr.toString() === "-1,0,1,,3", "arr.toString() = " + arr.toString());
911 arr = [1,2,3];
912 tmp = arr.unshift();
913 ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
914 ok(arr.length === 3, "arr.length = " + arr.length);
915 ok(arr.toString() === "1,2,3", "arr.toString() = " + arr.toString());
917 arr = new Object();
918 arr.length = 2;
919 arr[0] = 1;
920 arr[1] = 2;
921 tmp = Array.prototype.unshift.call(arr, 0);
922 ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
923 ok(arr.length === 3, "arr.length = " + arr.length);
924 ok(arr[0] === 0 && arr[1] === 1 && arr[2] === 2, "unexpected array");
926 arr = [1,2,,4];
927 tmp = arr.shift();
928 ok(tmp === 1, "[1,2,,4].shift() = " + tmp);
929 ok(arr.toString() === "2,,4", "arr = " + arr.toString());
931 arr = [];
932 tmp = arr.shift();
933 ok(tmp === undefined, "[].shift() = " + tmp);
934 ok(arr.toString() === "", "arr = " + arr.toString());
936 arr = [1,2,,4];
937 tmp = arr.shift(2);
938 ok(tmp === 1, "[1,2,,4].shift(2) = " + tmp);
939 ok(arr.toString() === "2,,4", "arr = " + arr.toString());
941 arr = [1,];
942 tmp = arr.shift();
943 ok(tmp === 1, "[1,].shift() = " + tmp);
944 ok(arr.toString() === "", "arr = " + arr.toString());
946 obj = new Object();
947 obj[0] = "test";
948 obj[2] = 3;
949 obj.length = 3;
950 tmp = Array.prototype.shift.call(obj);
951 ok(tmp === "test", "obj.shift() = " + tmp);
952 ok(obj.length == 2, "obj.length = " + obj.length);
953 ok(obj[1] === 3, "obj[1] = " + obj[1]);
955 var num = new Number(6);
956 arr = [0,1,2];
957 tmp = arr.concat(3, [4,5], num);
958 ok(tmp !== arr, "tmp === arr");
959 for(var i=0; i<6; i++)
960     ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
961 ok(tmp[6] === num, "tmp[6] !== num");
962 ok(tmp.length === 7, "tmp.length = " + tmp.length);
964 arr = [].concat();
965 ok(arr.length === 0, "arr.length = " + arr.length);
967 arr = [1,];
968 tmp = arr.concat([2]);
969 ok(tmp.length === 3, "tmp.length = " + tmp.length);
970 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
972 arr = [1,false,'a',null,undefined,'a'];
973 ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6));
974 ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length);
975 ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice());
976 ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc"));
977 ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8));
978 ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length);
979 ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1));
980 ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2));
981 ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1));
982 tmp = arr.slice(0,6);
983 for(var i=0; i < arr.length; i++)
984     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
985 arr[12] = 2;
986 ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString());
987 ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length);
989 arr = [1,2,3,4,5];
990 tmp = arr.splice(2,2);
991 ok(tmp.toString() == "3,4", "arr.splice(2,2) returned " + tmp.toString());
992 ok(arr.toString() == "1,2,5", "arr.splice(2,2) is " + arr.toString());
994 arr = [1,2,3,4,5];
995 tmp = arr.splice(2,2,"a");
996 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a') returned " + tmp.toString());
997 ok(arr.toString() == "1,2,a,5", "arr.splice(2,2,'a') is " + arr.toString());
999 arr = [1,2,3,4,5];
1000 tmp = arr.splice(2,2,'a','b','c');
1001 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
1002 ok(arr.toString() == "1,2,a,b,c,5", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1004 arr = [1,2,3,4,];
1005 tmp = arr.splice(2,2,'a','b','c');
1006 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
1007 ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1009 arr = [1,2,3,4,];
1010 arr.splice(2,2,'a','b','c');
1011 ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1013 arr = [1,2,3,4,5];
1014 tmp = arr.splice(2,2,'a','b');
1015 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b') returned " + tmp.toString());
1016 ok(arr.toString() == "1,2,a,b,5", "arr.splice(2,2,'a','b') is " + arr.toString());
1018 arr = [1,2,3,4,5];
1019 tmp = arr.splice(-1,2);
1020 ok(tmp.toString() == "5", "arr.splice(-1,2) returned " + tmp.toString());
1021 ok(arr.toString() == "1,2,3,4", "arr.splice(-1,2) is " + arr.toString());
1023 arr = [1,2,3,4,5];
1024 tmp = arr.splice(-10,3);
1025 ok(tmp.toString() == "1,2,3", "arr.splice(-10,3) returned " + tmp.toString());
1026 ok(arr.toString() == "4,5", "arr.splice(-10,3) is " + arr.toString());
1028 arr = [1,2,3,4,5];
1029 tmp = arr.splice(-10,100);
1030 ok(tmp.toString() == "1,2,3,4,5", "arr.splice(-10,100) returned " + tmp.toString());
1031 ok(arr.toString() == "", "arr.splice(-10,100) is " + arr.toString());
1033 arr = [1,2,3,4,5];
1034 tmp = arr.splice(2,-1);
1035 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1036 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1038 arr = [1,2,3,4,5];
1039 tmp = arr.splice(2);
1040 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1041 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1043 arr = [1,2,3,4,5];
1044 tmp = arr.splice();
1045 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1046 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1048 arr = [1,2,3,4,5];
1049 tmp = arr.splice(bigInt);
1050 ok(tmp.toString() == "", "arr.splice(bigInt) returned " + tmp.toString());
1051 ok(arr.toString() == "1,2,3,4,5", "arr.splice(bigInt) is " + arr.toString());
1053 arr = [1,2,3,4,5];
1054 tmp = arr.splice(-bigInt);
1055 ok(tmp.toString() == "", "arr.splice(-bigInt) returned " + tmp.toString());
1056 ok(arr.toString() == "1,2,3,4,5", "arr.splice(-bigInt) is " + arr.toString());
1058 if(invokeVersion >= 2) {
1059     arr = [1,2,3,4,5];
1060     tmp = arr.splice(2, bigInt);
1061     ok(tmp.toString() == "3,4,5", "arr.splice(2, bigInt) returned " + tmp.toString());
1062     ok(arr.toString() == "1,2", "arr.splice(2, bigInt) is " + arr.toString());
1065 arr = [1,2,3,4,5];
1066 tmp = arr.splice(2, -bigInt);
1067 ok(tmp.toString() == "", "arr.splice(2, -bigInt) returned " + tmp.toString());
1068 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2, -bigInt) is " + arr.toString());
1070 obj = new Object();
1071 obj.length = 3;
1072 obj[0] = 1;
1073 obj[1] = 2;
1074 obj[2] = 3;
1075 tmp = Array.prototype.splice.call(obj, 1, 1, 'a', 'b');
1076 ok(tmp.toString() === "2", "obj.splice returned " + tmp);
1077 ok(obj.length === 4, "obj.length = " + obj.length);
1078 ok(obj[0] === 1, "obj[0] = " + obj[0]);
1079 ok(obj[1] === 'a', "obj[1] = " + obj[1]);
1080 ok(obj[2] === 'b', "obj[2] = " + obj[2]);
1081 ok(obj[3] === 3, "obj[3] = " + obj[3]);
1083 obj = new Object();
1084 obj.length = 3;
1085 obj[0] = 1;
1086 obj[1] = 2;
1087 obj[2] = 3;
1088 tmp = Array.prototype.slice.call(obj, 1, 2);
1089 ok(tmp.length === 1, "tmp.length = " + tmp.length);
1090 ok(tmp[0] === 2, "tmp[0] = " + tmp[0]);
1092 tmp = (new Number(2)).toString();
1093 ok(tmp === "2", "num(2).toString = " + tmp);
1094 tmp = (new Number()).toString();
1095 ok(tmp === "0", "num().toString = " + tmp);
1096 tmp = (new Number(5.5)).toString(2);
1097 ok(tmp === "101.1", "num(5.5).toString(2) = " + tmp);
1099 tmp = (new Number(3)).toFixed(3);
1100 ok(tmp === "3.000", "num(3).toFixed(3) = " + tmp);
1101 tmp = (new Number(1.76)).toFixed(1);
1102 ok(tmp === "1.8", "num(1.76).toFixed(1) = " + tmp);
1103 tmp = (new Number(7.92)).toFixed(5);
1104 ok(tmp === "7.92000", "num(7.92).toFixed(5) = " + tmp);
1105 tmp = (new Number(2.88)).toFixed();
1106 ok(tmp === "3", "num(2.88).toFixed = " + tmp);
1107 tmp = (new Number(-2.5)).toFixed();
1108 ok(tmp === "-3", "num(-2.5).toFixed = " + tmp);
1109 tmp = (new Number(1000000000000000128)).toFixed(0);
1110 //todo_wine ok(tmp === "1000000000000000100", "num(1000000000000000128) = " + tmp);
1111 tmp = (new Number(3.14).toFixed(NaN));
1112 ok(tmp === "3", "num(3.14).toFixed = " + tmp);
1113 tmp = (new Number(0.95).toFixed(1));
1114 ok(tmp === "1.0", "num(0.95).toFixed(1) = " + tmp);
1115 tmp = (new Number(1e900)).toFixed(0);
1116 ok(tmp === "Infinity", "num(1000000000000000128) = " + tmp);
1117 tmp = (new Number(0.12345678901234567890123)).toFixed(20);
1118 ok(tmp === "0.12345678901234568000", "num(0.12345678901234567890123) = " + tmp);
1120 tmp = (new Number(2)).toExponential(3);
1121 ok(tmp === "2.000e+0", "num(2).toExponential(3) = " + tmp);
1122 tmp = (new Number(1.17e-32)).toExponential(20);
1123 ok(tmp === "1.17000000000000000000e-32", "num(1.17e-32).toExponential(20) = " + tmp);
1124 tmp = (new Number(0)).toExponential(7);
1125 ok(tmp === "0.0000000e+0", "num(0).toExponential(7) = " + tmp);
1126 tmp = (new Number(0)).toExponential(0);
1127 ok(tmp === "0e+0", "num(0).toExponential() = " + tmp);
1128 tmp = (new Number(-13.7567)).toExponential();
1129 ok(tmp === "-1.37567e+1", "num(-13.7567).toExponential() = " + tmp);
1130 tmp = (new Number(-32.1)).toExponential();
1131 ok(tmp === "-3.21e+1", "num(-32.1).toExponential() = " + tmp);
1132 tmp = (new Number(4723.4235)).toExponential();
1133 ok(tmp === "4.7234235e+3", "num(4723.4235).toExponential() = " + tmp);
1135 tmp = (new Number(5)).toPrecision(12);
1136 ok(tmp == "5.00000000000", "num(5).toPrecision(12) = " + tmp);
1137 tmp = (new Number(7.73)).toPrecision(7);
1138 ok(tmp == "7.730000", "num(7.73).toPrecision(7) = " + tmp);
1139 tmp = (new Number(-127547.47472)).toPrecision(17);
1140 ok(tmp == "-127547.47472000000", "num(-127547.47472).toPrecision(17) = " + tmp);
1141 tmp = (new Number(0)).toPrecision(3);
1142 ok(tmp == "0.00", "num(0).toPrecision(3) = " + tmp);
1143 tmp = (new Number(42345.52342465464562334)).toPrecision(15);
1144 ok(tmp == "42345.5234246546", "num(42345.52342465464562334).toPrecision(15) = " + tmp);
1145 tmp = (new Number(1.182e30)).toPrecision(5);
1146 ok(tmp == "1.1820e+30", "num(1.182e30)).toPrecision(5) = " + tmp);
1147 tmp = (new Number(1.123)).toPrecision();
1148 ok(tmp == "1.123", "num(1.123).toPrecision() = " + tmp);
1150 ok(Number() === 0, "Number() = " + Number());
1151 ok(Number(false) === 0, "Number(false) = " + Number(false));
1152 ok(Number("43") === 43, "Number('43') = " + Number("43"));
1154 tmp = (new Number(1)).valueOf();
1155 ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
1156 tmp = (new Number(1,2)).valueOf();
1157 ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
1158 tmp = (new Number()).valueOf();
1159 ok(tmp === 0, "(new Number()).valueOf = " + tmp);
1160 tmp = Number.prototype.valueOf();
1161 ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
1163 function equals(val, base) {
1164     var i;
1165     var num = 0;
1166     var str = val.toString(base);
1168     for(i=0; i<str.length; i++) {
1169         if(str.substring(i, i+1) == '(') break;
1170         if(str.substring(i, i+1) == '.') break;
1171         num = num*base + parseInt(str.substring(i, i+1));
1172     }
1174     if(str.substring(i, i+1) == '.') {
1175         var mult = base;
1176         for(i++; i<str.length; i++) {
1177             if(str.substring(i, i+1) == '(') break;
1178             num += parseInt(str.substring(i, i+1))/mult;
1179             mult *= base;
1180         }
1181     }
1183     if(str.substring(i, i+1) == '(') {
1184         exp = parseInt(str.substring(i+2));
1185         num *= Math.pow(base, exp);
1186     }
1188     ok(num>val-val/1000 && num<val+val/1000, "equals: num = " + num);
1191 ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11));
1192 ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17));
1193 ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33));
1194 ok((NaN).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN).toString(11));
1195 ok((Infinity).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity).toString(11));
1196 for(i=2; i<10; i++) {
1197     equals(1.123, i);
1198     equals(2305843009200000000, i);
1199     equals(5.123, i);
1200     equals(21711, i);
1201     equals(1024*1024*1024*1024*1024*1024*1.9999, i);
1202     equals(748382, i);
1203     equals(0.6, i);
1204     equals(4.65661287308e-10, i);
1205     ok((0).toString(i) === "0", "(0).toString("+i+") = " + (0).toString(i));
1208 ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123'));
1209 ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7'));
1210 ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2'));
1211 ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5'));
1212 ok(parseFloat('1E5 not parsed') === 1E5, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed'));
1213 ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
1214 ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
1215 ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
1216 ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
1218 tmp = Math.min(1);
1219 ok(tmp === 1, "Math.min(1) = " + tmp);
1221 tmp = Math.min(1, false);
1222 ok(tmp === 0, "Math.min(1, false) = " + tmp);
1224 tmp = Math.min();
1225 ok(tmp === Infinity, "Math.min() = " + tmp);
1227 tmp = Math.min(1, NaN, -Infinity, false);
1228 ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
1230 tmp = Math.min(1, false, true, null, -3);
1231 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
1233 tmp = Math.max(1);
1234 ok(tmp === 1, "Math.max(1) = " + tmp);
1236 tmp = Math.max(true, 0);
1237 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
1239 tmp = Math.max(-2, false, true, null, 1);
1240 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
1242 tmp = Math.max();
1243 ok(tmp === -Infinity, "Math.max() = " + tmp);
1245 tmp = Math.max(true, NaN, 0);
1246 ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
1248 tmp = Math.round(0.5);
1249 ok(tmp === 1, "Math.round(0.5) = " + tmp);
1251 tmp = Math.round(-0.5);
1252 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
1254 tmp = Math.round(1.1);
1255 ok(tmp === 1, "Math.round(1.1) = " + tmp);
1257 tmp = Math.round(true);
1258 ok(tmp === 1, "Math.round(true) = " + tmp);
1260 tmp = Math.round(1.1, 3, 4);
1261 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
1263 tmp = Math.round();
1264 ok(isNaN(tmp), "Math.round() is not NaN");
1266 tmp = Math.ceil(0.5);
1267 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
1269 tmp = Math.ceil(-0.5);
1270 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
1272 tmp = Math.ceil(1.1);
1273 ok(tmp === 2, "Math.round(1.1) = " + tmp);
1275 tmp = Math.ceil(true);
1276 ok(tmp === 1, "Math.ceil(true) = " + tmp);
1278 tmp = Math.ceil(1.1, 3, 4);
1279 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
1281 tmp = Math.ceil();
1282 ok(isNaN(tmp), "ceil() is not NaN");
1284 tmp = Math.floor(0.5);
1285 ok(tmp === 0, "Math.floor(0.5) = " + tmp);
1287 tmp = Math.floor(-0.5);
1288 ok(tmp === -1, "Math.floor(-0.5) = " + tmp);
1290 tmp = Math.floor(1.1);
1291 ok(tmp === 1, "Math.floor(1.1) = " + tmp);
1293 tmp = Math.floor(true);
1294 ok(tmp === 1, "Math.floor(true) = " + tmp);
1296 tmp = Math.floor(1.1, 3, 4);
1297 ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp);
1299 tmp = Math.floor();
1300 ok(isNaN(tmp), "floor is not NaN");
1302 tmp = Math.abs(3);
1303 ok(tmp === 3, "Math.abs(3) = " + tmp);
1305 tmp = Math.abs(-3);
1306 ok(tmp === 3, "Math.abs(-3) = " + tmp);
1308 tmp = Math.abs(true);
1309 ok(tmp === 1, "Math.abs(true) = " + tmp);
1311 tmp = Math.abs();
1312 ok(isNaN(tmp), "Math.abs() is not NaN");
1314 tmp = Math.abs(NaN);
1315 ok(isNaN(tmp), "Math.abs() is not NaN");
1317 tmp = Math.abs(-Infinity);
1318 ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp);
1320 tmp = Math.abs(-3, 2);
1321 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
1323 tmp = Math.cos(0);
1324 ok(tmp === 1, "Math.cos(0) = " + tmp);
1326 tmp = Math.cos(Math.PI/2);
1327 ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp);
1329 tmp = Math.cos(-Math.PI/2);
1330 ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp);
1332 tmp = Math.cos(Math.PI/3, 2);
1333 ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp);
1335 tmp = Math.cos(true);
1336 ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp);
1338 tmp = Math.cos(false);
1339 ok(tmp === 1, "Math.cos(false) = " + tmp);
1341 tmp = Math.cos();
1342 ok(isNaN(tmp), "Math.cos() is not NaN");
1344 tmp = Math.cos(NaN);
1345 ok(isNaN(tmp), "Math.cos(NaN) is not NaN");
1347 tmp = Math.cos(Infinity);
1348 ok(isNaN(tmp), "Math.cos(Infinity) is not NaN");
1350 tmp = Math.cos(-Infinity);
1351 ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN");
1353 tmp = Math.pow(2, 2);
1354 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
1356 tmp = Math.pow(4, 0.5);
1357 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
1359 tmp = Math.pow(2, 2, 3);
1360 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
1362 tmp = Math.pow(2);
1363 ok(isNaN(tmp), "Math.pow(2) is not NaN");
1365 tmp = Math.pow();
1366 ok(isNaN(tmp), "Math.pow() is not NaN");
1368 tmp = Math.random();
1369 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
1370 ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp);
1372 tmp = Math.random(100);
1373 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
1374 ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp);
1376 tmp = Math.acos(0);
1377 ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp);
1379 tmp = Math.acos(1);
1380 ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp);
1382 tmp = Math.acos(-1);
1383 ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp);
1385 tmp = Math.acos(Math.PI/4, 2);
1386 ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp);
1388 tmp = Math.acos(true);
1389 ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp);
1391 tmp = Math.acos(false);
1392 ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp);
1394 tmp = Math.acos(1.1);
1395 ok(isNaN(tmp), "Math.acos(1.1) is not NaN");
1397 tmp = Math.acos();
1398 ok(isNaN(tmp), "Math.acos() is not NaN");
1400 tmp = Math.acos(NaN);
1401 ok(isNaN(tmp), "Math.acos(NaN) is not NaN");
1403 tmp = Math.acos(Infinity);
1404 ok(isNaN(tmp), "Math.acos(Infinity) is not NaN");
1406 tmp = Math.acos(-Infinity);
1407 ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN");
1409 tmp = Math.asin(0);
1410 ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp);
1412 tmp = Math.asin(1);
1413 ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp);
1415 tmp = Math.asin(-1);
1416 ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp);
1418 tmp = Math.asin(Math.PI/4, 2);
1419 ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp);
1421 tmp = Math.asin(true);
1422 ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp);
1424 tmp = Math.asin(false);
1425 ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp);
1427 tmp = Math.asin(1.1);
1428 ok(isNaN(tmp), "Math.asin(1.1) is not NaN");
1430 tmp = Math.asin();
1431 ok(isNaN(tmp), "Math.asin() is not NaN");
1433 tmp = Math.asin(NaN);
1434 ok(isNaN(tmp), "Math.asin(NaN) is not NaN");
1436 tmp = Math.asin(Infinity);
1437 ok(isNaN(tmp), "Math.asin(Infinity) is not NaN");
1439 tmp = Math.asin(-Infinity);
1440 ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN");
1442 tmp = Math.atan(0);
1443 ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp);
1445 tmp = Math.atan(1);
1446 ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp);
1448 tmp = Math.atan(-1);
1449 ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp);
1451 tmp = Math.atan(true);
1452 ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp);
1454 tmp = Math.atan(false);
1455 ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp);
1457 tmp = Math.atan();
1458 ok(isNaN(tmp), "Math.atan() is not NaN");
1460 tmp = Math.atan(NaN);
1461 ok(isNaN(tmp), "Math.atan(NaN) is not NaN");
1463 tmp = Math.atan(Infinity);
1464 ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp);
1466 tmp = Math.atan(-Infinity);
1467 ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp);
1469 tmp = Math.atan2(0, 0);
1470 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp);
1472 tmp = Math.atan2(0, 1);
1473 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp);
1475 tmp = Math.atan2(0, Infinity);
1476 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp);
1478 tmp = Math.atan2(0, -1);
1479 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp);
1481 tmp = Math.atan2(0, -Infinity);
1482 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp);
1484 tmp = Math.atan2(1, 0);
1485 ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp);
1487 tmp = Math.atan2(Infinity, 0);
1488 ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp);
1490 tmp = Math.atan2(-1, 0);
1491 ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp);
1493 tmp = Math.atan2(-Infinity, 0);
1494 ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp);
1496 tmp = Math.atan2(1, 1);
1497 ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp);
1499 tmp = Math.atan2(-1, -1);
1500 ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp);
1502 tmp = Math.atan2(-1, 1);
1503 ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp);
1505 tmp = Math.atan2(Infinity, Infinity);
1506 ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp);
1508 tmp = Math.atan2(Infinity, -Infinity, 1);
1509 ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp);
1511 tmp = Math.atan2();
1512 ok(isNaN(tmp), "Math.atan2() is not NaN");
1514 tmp = Math.atan2(1);
1515 ok(isNaN(tmp), "Math.atan2(1) is not NaN");
1517 tmp = Math.exp(0);
1518 ok(tmp === 1, "Math.exp(0) = " + tmp);
1520 tmp = Math.exp(1);
1521 ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp);
1523 tmp = Math.exp(-1);
1524 ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp);
1526 tmp = Math.exp(true);
1527 ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp);
1529 tmp = Math.exp(1, 1);
1530 ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp);
1532 tmp = Math.exp();
1533 ok(isNaN(tmp), "Math.exp() is not NaN");
1535 tmp = Math.exp(NaN);
1536 ok(isNaN(tmp), "Math.exp(NaN) is not NaN");
1538 tmp = Math.exp(Infinity);
1539 ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp);
1541 tmp = Math.exp(-Infinity);
1542 ok(tmp === 0, "Math.exp(-Infinity) = " + tmp);
1544 tmp = Math.log(1);
1545 ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp);
1547 tmp = Math.log(-1);
1548 ok(isNaN(tmp), "Math.log(-1) is not NaN");
1550 tmp = Math.log(true);
1551 ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp);
1553 tmp = Math.log(1, 1);
1554 ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp);
1556 tmp = Math.log();
1557 ok(isNaN(tmp), "Math.log() is not NaN");
1559 tmp = Math.log(NaN);
1560 ok(isNaN(tmp), "Math.log(NaN) is not NaN");
1562 tmp = Math.log(Infinity);
1563 ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
1565 tmp = Math.log(-Infinity);
1566 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
1568 tmp = Math.sin(0);
1569 ok(tmp === 0, "Math.sin(0) = " + tmp);
1571 tmp = Math.sin(Math.PI/2);
1572 ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
1574 tmp = Math.sin(-Math.PI/2);
1575 ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
1577 tmp = Math.sin(Math.PI/3, 2);
1578 ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
1580 tmp = Math.sin(true);
1581 ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
1583 tmp = Math.sin(false);
1584 ok(tmp === 0, "Math.sin(false) = " + tmp);
1586 tmp = Math.sin();
1587 ok(isNaN(tmp), "Math.sin() is not NaN");
1589 tmp = Math.sin(NaN);
1590 ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
1592 tmp = Math.sin(Infinity);
1593 ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
1595 tmp = Math.sin(-Infinity);
1596 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
1598 tmp = Math.sqrt(0);
1599 ok(tmp === 0, "Math.sqrt(0) = " + tmp);
1601 tmp = Math.sqrt(4);
1602 ok(tmp === 2, "Math.sqrt(4) = " + tmp);
1604 tmp = Math.sqrt(-1);
1605 ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
1607 tmp = Math.sqrt(2, 2);
1608 ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
1610 tmp = Math.sqrt(true);
1611 ok(tmp === 1, "Math.sqrt(true) = " + tmp);
1613 tmp = Math.sqrt(false);
1614 ok(tmp === 0, "Math.sqrt(false) = " + tmp);
1616 tmp = Math.sqrt();
1617 ok(isNaN(tmp), "Math.sqrt() is not NaN");
1619 tmp = Math.sqrt(NaN);
1620 ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
1622 tmp = Math.sqrt(Infinity);
1623 ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
1625 tmp = Math.sqrt(-Infinity);
1626 ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
1628 tmp = Math.tan(0);
1629 ok(tmp === 0, "Math.tan(0) = " + tmp);
1631 tmp = Math.tan(Math.PI);
1632 ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp);
1634 tmp = Math.tan(2, 2);
1635 ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp);
1637 tmp = Math.tan(true);
1638 ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp);
1640 tmp = Math.tan(false);
1641 ok(tmp === 0, "Math.tan(false) = " + tmp);
1643 tmp = Math.tan();
1644 ok(isNaN(tmp), "Math.tan() is not NaN");
1646 tmp = Math.tan(NaN);
1647 ok(isNaN(tmp), "Math.tan(NaN) is not NaN");
1649 tmp = Math.tan(Infinity);
1650 ok(isNaN(tmp), "Math.tan(Infinity) is not NaN");
1652 tmp = Math.tan(-Infinity);
1653 ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
1655 var func = function  (a) {
1656         var a = 1;
1657         if(a) return;
1658     };
1659 ok(func.toString() === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
1660    "func.toString() = " + func.toString());
1661 ok("" + func === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
1662    "'' + func.toString() = " + func);
1664 ok(func.valueOf === Object.prototype.valueOf, "func.valueOf !== Object.prototype.valueOf");
1665 ok(func === func.valueOf(), "func !== func.valueOf()");
1667 function testFuncToString(x,y) {
1668     return x+y;
1670 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n    return x+y;\n}",
1671    "testFuncToString.toString() = " + testFuncToString.toString());
1672 ok("" + testFuncToString === "function testFuncToString(x,y) {\n    return x+y;\n}",
1673    "'' + testFuncToString = " + testFuncToString);
1675 tmp = new Object();
1677 function callTest(argc) {
1678     ok(this === tmp, "this !== tmp\n");
1679     ok(arguments.length === argc+1, "arguments.length = " + arguments.length + " expected " + (argc+1));
1680     for(var i=1; i <= argc; i++)
1681         ok(arguments[i] === i, "arguments[i] = " + arguments[i]);
1684 callTest.call(tmp, 1, 1);
1685 callTest.call(tmp, 2, 1, 2);
1686 callTest.call(tmp, 3, 1, 2, 3);
1688 callTest.apply(tmp, [1, 1]);
1689 callTest.apply(tmp, [2, 1, 2]);
1690 callTest.apply(tmp, [3, 1, 2, 3]);
1691 (function () { callTest.apply(tmp, arguments); })(2,1,2);
1693 function callTest2() {
1694     ok(this === tmp, "this !== tmp\n");
1695     ok(arguments.length === 0, "callTest2: arguments.length = " + arguments.length + " expected 0");
1698 callTest2.call(tmp);
1699 callTest2.apply(tmp, []);
1700 callTest2.apply(tmp);
1701 (function () { callTest2.apply(tmp, arguments); })();
1703 function callTest3() {
1704     testThis(this);
1705     ok(arguments.length === 0, "arguments.length = " + arguments.length + " expected 0");
1708 callTest3.call();
1709 callTest3.call(undefined);
1710 callTest3.call(null);
1711 callTest3.apply();
1712 callTest3.apply(undefined);
1713 callTest3.apply(null);
1715 tmp = Number.prototype.toString.call(3);
1716 ok(tmp === "3", "Number.prototype.toString.call(3) = " + tmp);
1718 var func = new Function("return 3;");
1720 tmp = func();
1721 ok(tmp === 3, "func() = " + tmp);
1722 ok(func.call() === 3, "func.call() = " + tmp);
1723 ok(func.length === 0, "func.length = " + func.length);
1724 tmp = func.toString();
1725 ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp);
1727 func = new Function("x", "return x+2;");
1728 tmp = func(1);
1729 ok(tmp === 3, "func(1) = " + tmp);
1730 tmp = func.toString();
1731 ok(tmp === "function anonymous(x) {\nreturn x+2;\n}", "func.toString() = " + tmp);
1733 tmp = (new Function("x ", "return x+2;")).toString();
1734 ok(tmp === "function anonymous(x ) {\nreturn x+2;\n}", "func.toString() = " + tmp);
1736 func = new Function("x", "y", "return x+y");
1737 tmp = func(1,3);
1738 ok(tmp === 4, "func(1,3) = " + tmp);
1739 tmp = func.toString();
1740 ok(tmp === "function anonymous(x, y) {\nreturn x+y\n}", "func.toString() = " + tmp);
1742 func = new Function(" x, \ty", "\tz", "return x+y+z;");
1743 tmp = func(1,3,2);
1744 ok(tmp === 6, "func(1,3,2) = " + tmp);
1745 ok(func.length === 3, "func.length = " + func.length);
1746 tmp = func.toString();
1747 ok(tmp === "function anonymous( x, \ty, \tz) {\nreturn x+y+z;\n}", "func.toString() = " + tmp);
1749 func = new Function();
1750 tmp = func();
1751 ok(tmp === undefined, "func() = " + tmp);
1752 tmp = func.toString();
1753 ok(tmp == "function anonymous() {\n\n}", "func.toString() = " + tmp);
1755 func = (function() {
1756         var tmp = 3;
1757         return new Function("return tmp;");
1758     })();
1759 tmp = 2;
1760 tmp = func();
1761 ok(tmp === 2, "func() = " + tmp);
1763 var date = new Date();
1765 date = new Date(100);
1766 ok(date.getTime() === 100, "date.getTime() = " + date.getTime());
1767 ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime());
1768 date = new Date(8.64e15);
1769 ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime());
1770 date = new Date(8.64e15+1);
1771 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
1772 date = new Date(Infinity);
1773 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
1774 date = new Date("3 July 2009 22:28:00 UTC+0100");
1775 ok(date.getTime() === 1246656480000, "date.getTime() = " + date.getTime());
1776 date = new Date(1984, 11, 29, 13, 51, 24, 120);
1777 ok(date.getFullYear() === 1984, "date.getFullYear() = " + date.getFullYear());
1778 ok(date.getMonth() === 11, "date.getMonth() = " + date.getMonth());
1779 ok(date.getDate() === 29, "date.getDate() = " + date.getDate());
1780 ok(date.getHours() === 13, "date.getHours() = " + date.getHours());
1781 ok(date.getMinutes() === 51, "date.getMinutes() = " + date.getMinutes());
1782 ok(date.getSeconds() === 24, "date.getSeconds() = " + date.getSeconds());
1783 ok(date.getMilliseconds() === 120, "date.getMilliseconds() = " + date.getMilliseconds());
1784 date = new Date(731, -32, 40, -1, 70, 65, -13);
1785 ok(date.getFullYear() === 728, "date.getFullYear() = " + date.getFullYear());
1786 ok(date.getMonth() === 5, "date.getMonth() = " + date.getMonth());
1787 ok(date.getDate() === 9, "date.getDate() = " + date.getDate());
1788 ok(date.getHours() === 0, "date.getHours() = " + date.getHours());
1789 ok(date.getMinutes() === 11, "date.getMinutes() = " + date.getMinutes());
1790 ok(date.getSeconds() === 4, "date.getSeconds() = " + date.getSeconds());
1791 ok(date.getMilliseconds() === 987, "date.getMilliseconds() = " + date.getMilliseconds());
1793 ok(date.setTime(123) === 123, "date.setTime(123) !== 123");
1794 ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123");
1795 ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
1797 ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
1798 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
1799 ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
1800 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
1801 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
1802 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
1803 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
1804 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
1805 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1807 date.setTime(60*24*60*60*1000);
1808 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
1809 ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
1810 ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
1811 ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay());
1812 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
1813 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
1814 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
1815 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1817 date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
1818 ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
1819 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1820 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1821 ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
1822 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
1823 ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours());
1824 ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes());
1825 ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds());
1826 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1828 tmp = date.setYear(96);
1829 ok(date.getYear() === 96, "date.getYear() = " + date.getYear());
1830 ok(date.getFullYear() === 1996, "date.getFullYear() = " + date.getYear());
1831 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1832 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1833 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1835 tmp = date.setYear(2010);
1836 ok(tmp === date.getTime(), "date.setYear(2010) = " + tmp);
1837 ok(date.getYear() === 2010, "date.getYear() = " + date.getYear());
1838 ok(date.getFullYear() === 2010, "date.getFullYear() = " + date.getYear());
1839 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1840 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
1841 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1843 date.setTime(Infinity);
1844 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
1845 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
1846 ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
1847 ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN");
1848 ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN");
1849 ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
1850 ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN");
1851 ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN");
1852 ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN");
1854 date.setTime(0);
1855 tmp = date.setYear(NaN);
1856 ok(isNaN(tmp), "date.setYear(NaN) = " + tmp);
1857 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
1858 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
1860 date.setTime(0);
1861 date.setUTCMilliseconds(-10, 2);
1862 ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1863 date.setUTCMilliseconds(10);
1864 ok(date.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
1865 date.setUTCSeconds(-10);
1866 ok(date.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date.getUTCSeconds());
1867 date.setUTCMinutes(-10);
1868 ok(date.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date.getUTCMinutes());
1869 date.setUTCHours(-10);
1870 ok(date.getUTCHours() === 14, "date.getUTCHours() = " + date.getUTCHours());
1871 date.setUTCHours(-123);
1872 ok(date.getTime() === -612549990, "date.getTime() = " + date.getTime());
1873 date.setUTCHours(20);
1874 ok(date.getUTCHours() === 20, "date.getUTCHours() = " + date.getUTCHours());
1875 date.setUTCDate(32);
1876 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
1877 date.setUTCMonth(22, 37);
1878 ok(date.getTime() === 60987050010, "date.getTime() = " + date.getTime());
1879 date.setUTCFullYear(83, 21, 321);
1880 ok(date.getTime() === -59464984149990, "date.getTime() = " + date.getTime());
1881 ok(Math.abs(date) === 59464984149990, "Math.abs(date) = " + Math.abs(date));
1882 ok(getVT(date+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date+1));
1884 ok(isNaN(Date.parse()), "Date.parse() is not NaN");
1885 ok(isNaN(Date.parse("")), "Date.parse(\"\") is not NaN");
1886 ok(isNaN(Date.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN");
1887 ok(Date.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date.parse("Jan 20 2009 UTC"));
1888 ok(Date.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date.parse("Jan 20 2009 GMT"));
1889 ok(Date.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date.parse("Jan 20 2009 UTC-0"));
1890 ok(Date.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date.parse("Jan 20 2009 UTC+0000"));
1891 ok(Date.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date.parse("Ju 13 79 UTC"));
1892 ok(Date.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date.parse("12Au91 UTC"));
1893 ok(Date.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date.parse("7/02/17 UTC"));
1894 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"));
1895 ok(Date.parse("February 31   UTC, 2000 12:31:17 PM") === 952000277000,
1896         "Date.parse(\"February 31   UTC, 2000 12:31:17 PM\") = " + Date.parse("February 31   UTC, 2000 12:31:17 PM"));
1897 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 "));
1898 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"));
1900 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
1901 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
1902 Math.PI = "test";
1903 ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI);
1905 ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E));
1906 ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E);
1907 Math.E = "test";
1908 ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E);
1910 ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E));
1911 ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E);
1912 Math.LOG2E = "test";
1913 ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E);
1915 ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E));
1916 ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E);
1917 Math.LOG10E = "test";
1918 ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E);
1920 ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2));
1921 ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2);
1922 Math.LN2 = "test";
1923 ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2);
1925 ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10));
1926 ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10);
1927 Math.LN10 = "test";
1928 ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10);
1930 ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2));
1931 ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2);
1932 Math.SQRT2 = "test";
1933 ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2);
1935 ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2));
1936 ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
1937 Math.SQRT1_2 = "test";
1938 ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);
1940 ok(isNaN.toString() === "\nfunction isNaN() {\n    [native code]\n}\n",
1941    "isNaN.toString = '" + isNaN.toString() + "'");
1942 ok(Array.toString() === "\nfunction Array() {\n    [native code]\n}\n",
1943    "isNaN.toString = '" + Array.toString() + "'");
1944 ok(Function.toString() === "\nfunction Function() {\n    [native code]\n}\n",
1945    "isNaN.toString = '" + Function.toString() + "'");
1946 ok(Function.prototype.toString() === "\nfunction prototype() {\n    [native code]\n}\n",
1947    "isNaN.toString = '" + Function.prototype.toString() + "'");
1948 ok("".substr.toString() === "\nfunction substr() {\n    [native code]\n}\n",
1949    "''.substr.toString = '" + "".substr.toString() + "'");
1951 var bool = new Boolean();
1952 ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
1953 var bool = new Boolean("false");
1954 ok(bool.toString() === "true", "bool.toString() = " + bool.toString());
1955 ok(bool.valueOf() === Boolean(1), "bool.valueOf() = " + bool.valueOf());
1956 ok(bool.toLocaleString() === bool.toString(), "bool.toLocaleString() = " + bool.toLocaleString());
1958 ok(ActiveXObject instanceof Function, "ActiveXObject is not instance of Function");
1959 ok(ActiveXObject.prototype instanceof Object, "ActiveXObject.prototype is not instance of Object");
1961 ok(Error.prototype !== TypeError.prototype, "Error.prototype === TypeError.prototype");
1962 ok(RangeError.prototype !== TypeError.prototype, "RangeError.prototype === TypeError.prototype");
1963 ok(Error.prototype.toLocaleString === Object.prototype.toLocaleString,
1964         "Error.prototype.toLocaleString !== Object.prototype.toLocaleString");
1965 err = new Error();
1966 ok(err.valueOf === Object.prototype.valueOf, "err.valueOf !== Object.prototype.valueOf");
1967 ok(Error.prototype.name === "Error", "Error.prototype.name = " + Error.prototype.name);
1968 ok(err.name === "Error", "err.name = " + err.name);
1969 EvalError.prototype.message = "test";
1970 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
1971 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error"), "err.toString() = " + err.toString());
1972 err = new EvalError();
1973 ok(EvalError.prototype.name === "EvalError", "EvalError.prototype.name = " + EvalError.prototype.name);
1974 ok(err.name === "EvalError", "err.name = " + err.name);
1975 ok(err.toString === Error.prototype.toString, "err.toString !== Error.prototype.toString");
1976 ok(err.message === "", "err.message != ''");
1977 err.message = date;
1978 ok(err.message === date, "err.message != date");
1979 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "EvalError: "+err.message),
1980    "err.toString() = " + err.toString());
1981 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
1982 err = new RangeError();
1983 ok(RangeError.prototype.name === "RangeError", "RangeError.prototype.name = " + RangeError.prototype.name);
1984 ok(err.name === "RangeError", "err.name = " + err.name);
1985 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "RangeError"), "err.toString() = " + err.toString());
1986 err = new ReferenceError();
1987 ok(ReferenceError.prototype.name === "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError.prototype.name);
1988 ok(err.name === "ReferenceError", "err.name = " + err.name);
1989 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "ReferenceError"), "err.toString() = " + err.toString());
1990 err = new SyntaxError();
1991 ok(SyntaxError.prototype.name === "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError.prototype.name);
1992 ok(err.name === "SyntaxError", "err.name = " + err.name);
1993 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "SyntaxError"), "err.toString() = " + err.toString());
1994 err = new TypeError();
1995 ok(TypeError.prototype.name === "TypeError", "TypeError.prototype.name = " + TypeError.prototype.name);
1996 ok(err.name === "TypeError", "err.name = " + err.name);
1997 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "TypeError"), "err.toString() = " + err.toString());
1998 err = new URIError();
1999 ok(URIError.prototype.name === "URIError", "URIError.prototype.name = " + URIError.prototype.name);
2000 ok(err.name === "URIError", "err.name = " + err.name);
2001 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "URIError"), "err.toString() = " + err.toString());
2002 err = new Error("message");
2003 ok(err.message === "message", "err.message !== 'message'");
2004 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error: message"), "err.toString() = " + err.toString());
2005 err = new Error(123);
2006 ok(err.number === 123, "err.number = " + err.number);
2007 err.number = 254;
2008 ok(err.number === 254, "err.number = " + err.number);
2009 err = new Error(0, "message");
2010 ok(err.number === 0, "err.number = " + err.number);
2011 ok(err.message === "message", "err.message = " + err.message);
2012 ok(err.description === "message", "err.description = " + err.description);
2013 err = new Error();
2014 ok(err.number === 0, "err.number = " + err.number);
2015 ok(err.description === "", "err.description = " + err.description);
2016 err.description = 5;
2017 ok(err.description === 5, "err.description = " + err.description);
2018 ok(err.message === "", "err.message = " + err.message);
2019 err.message = 4;
2020 ok(err.message === 4, "err.message = " + err.message);
2022 ok(!("number" in Error), "number is in Error");
2024 tmp = new Object();
2025 ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited");
2026 tmp.toString = function() { return "test"; };
2027 ok(tmp.hasOwnProperty("toString") === true, "toString own property should exist");
2028 ok(tmp.hasOwnProperty("nonExisting") === false, "nonExisting property should not exist");
2030 tmp = Error.prototype.toString.call(tmp);
2031 ok(tmp === "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp);
2033 tmp = function() { return 0; };
2034 tmp[0] = true;
2035 ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited");
2036 ok(tmp.hasOwnProperty("0") === true, "hasOwnProperty(0) returned false");
2037 ok(tmp.hasOwnProperty() === false, "hasOwnProperty() returned true");
2039 ok(Object.prototype.hasOwnProperty.call(testObj) === false, "hasOwnProperty without name returned true");
2041 if(invokeVersion >= 2) {
2042     obj = new Object();
2043     obj.name = "test";
2044     tmp = Error.prototype.toString.call(obj);
2045     ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2047     obj = new Object();
2048     obj.name = 6;
2049     obj.message = false;
2050     tmp = Error.prototype.toString.call(obj);
2051     ok(tmp === "6: false", "Error.prototype.toString.call(obj) = " + tmp);
2053     obj = new Object();
2054     obj.message = "test";
2055     tmp = Error.prototype.toString.call(obj);
2056     ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2058     obj = new Object();
2059     obj.name = "";
2060     obj.message = "test";
2061     tmp = Error.prototype.toString.call(obj);
2062     ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2065 tmp = Error.prototype.toString.call(testObj);
2066 ok(tmp === "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp);
2068 err = new Error();
2069 err.name = null;
2070 ok(err.name === null, "err.name = " + err.name + " expected null");
2071 if(invokeVersion >= 2)
2072     ok(err.toString() === "null", "err.toString() = " + err.toString());
2074 err = new Error();
2075 err.message = false;
2076 ok(err.message === false, "err.message = " + err.message + " expected false");
2077 if(invokeVersion >= 2)
2078     ok(err.toString() === "Error: false", "err.toString() = " + err.toString());
2080 err = new Error();
2081 err.message = new Object();
2082 err.message.toString = function() { return ""; };
2083 if(invokeVersion >= 2)
2084     ok(err.toString() === "Error", "err.toString() = " + err.toString());
2086 err = new Error();
2087 err.message = undefined;
2088 if(invokeVersion >= 2)
2089     ok(err.toString() === "Error", "err.toString() = " + err.toString());
2091 var exception_array = {
2092     E_INVALID_LENGTH:  { type: "RangeError",  number: -2146823259 },
2094     E_NOT_DATE:            { type: "TypeError",   number: -2146823282 },
2095     E_NOT_BOOL:            { type: "TypeError",   number: -2146823278 },
2096     E_ARG_NOT_OPT:         { type: "TypeError",   number: -2146827839 },
2097     E_NO_PROPERTY:         { type: "TypeError",   number: -2146827850 },
2098     E_NOT_NUM:             { type: "TypeError",   number: -2146823287 },
2099     E_INVALID_CALL_ARG:    { type: "TypeError",   number: -2146828283 },
2100     E_NOT_FUNC:            { type: "TypeError",   number: -2146823286 },
2101     E_OBJECT_EXPECTED:     { type: "TypeError", number: -2146823281 },
2102     E_OBJECT_REQUIRED:     { type: "TypeError", number: -2146827864 },
2103     E_UNSUPPORTED_ACTION:  { type: "TypeError", number: -2146827843 },
2104     E_NOT_VBARRAY:         { type: "TypeError", number: -2146823275 },
2105     E_INVALID_DELETE:      { type: "TypeError", number: -2146823276 },
2106     E_UNDEFINED:           { type: "TypeError", number: -2146823279 },
2107     E_JSCRIPT_EXPECTED:    { type: "TypeError", number: -2146823274 },
2108     E_NOT_ARRAY:           { type: "TypeError", number: -2146823257 },
2110     E_SYNTAX_ERROR:      { type: "SyntaxError",  number: -2146827286 },
2111     E_LBRACKET:          { type: "SyntaxError",  number: -2146827283 },
2112     E_RBRACKET:          { type: "SyntaxError",  number: -2146827282 },
2113     E_SEMICOLON:         { type: "SyntaxError",  number: -2146827284 },
2114     E_UNTERMINATED_STR:  { type: "SyntaxError",  number: -2146827273 },
2115     E_DISABLED_CC:       { type: "SyntaxError",  number: -2146827258 },
2116     E_INVALID_BREAK:     { type: "SyntaxError",  number: -2146827269 },
2117     E_INVALID_CONTINUE:  { type: "SyntaxError",  number: -2146827268 },
2118     E_LABEL_NOT_FOUND:   { type: "SyntaxError",  number: -2146827262 },
2119     E_LABEL_REDEFINED:   { type: "SyntaxError",  number: -2146827263 },
2121     E_ILLEGAL_ASSIGN:  { type: "ReferenceError", number: -2146823280 },
2123     E_PRECISION_OUT_OF_RANGE:        {type: "RangeError", number: -2146823261 },
2124     E_FRACTION_DIGITS_OUT_OF_RANGE:  {type: "RangeError", number: -2146823262 },
2125     E_SUBSCRIPT_OUT_OF_RANGE:        {type: "RangeError", number: -2146828279 },
2127     E_REGEXP_SYNTAX_ERROR:  { type: "RegExpError", number: -2146823271 },
2129     E_URI_INVALID_CHAR:     { type: "URIError", number: -2146823264 },
2130     E_URI_INVALID_CODING:   { type: "URIError", number: -2146823263 }
2133 function testException(func, id) {
2134     var ex = exception_array[id];
2135     var ret = "", num = "";
2137     try {
2138         func();
2139     } catch(e) {
2140         ret = e.name;
2141         num = e.number;
2142     }
2144     ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed function: " + func.toString());
2145     ok(num === ex.number, "Exception test, num = " + num + ", expected " + ex.number + ". Executed function: " + func.toString());
2148 // RangeError tests
2149 testException(function() {Array(-3);}, "E_INVALID_LENGTH");
2150 testException(function() {createArray().lbound("aaa");}, "E_SUBSCRIPT_OUT_OF_RANGE");
2151 testException(function() {createArray().lbound(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
2152 testException(function() {createArray().getItem(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
2154 // TypeError tests
2155 testException(function() {date.setTime();}, "E_ARG_NOT_OPT");
2156 testException(function() {date.setYear();}, "E_ARG_NOT_OPT");
2157 testException(function() {arr.test();}, "E_NO_PROPERTY");
2158 testException(function() {Number.prototype.toString.call(arr);}, "E_NOT_NUM");
2159 testException(function() {Number.prototype.toFixed.call(arr);}, "E_NOT_NUM");
2160 testException(function() {(new Number(3)).toString(1);}, "E_INVALID_CALL_ARG");
2161 testException(function() {(new Number(3)).toFixed(21);}, "E_FRACTION_DIGITS_OUT_OF_RANGE");
2162 testException(function() {(new Number(1)).toPrecision(0);}, "E_PRECISION_OUT_OF_RANGE");
2163 testException(function() {not_existing_variable.something();}, "E_UNDEFINED");
2164 testException(function() {date();}, "E_NOT_FUNC");
2165 testException(function() {arr();}, "E_NOT_FUNC");
2166 testException(function() {(new Object) instanceof (new Object);}, "E_NOT_FUNC");
2167 testException(function() {eval("nonexistingfunc()")}, "E_OBJECT_EXPECTED");
2168 testException(function() {(new Object()) instanceof 3;}, "E_NOT_FUNC");
2169 testException(function() {(new Object()) instanceof null;}, "E_NOT_FUNC");
2170 testException(function() {(new Object()) instanceof nullDisp;}, "E_NOT_FUNC");
2171 testException(function() {"test" in 3;}, "E_OBJECT_EXPECTED");
2172 testException(function() {"test" in null;}, "E_OBJECT_EXPECTED");
2173 testException(function() {"test" in nullDisp;}, "E_OBJECT_EXPECTED");
2174 testException(function() {new 3;}, "E_UNSUPPORTED_ACTION");
2175 testException(function() {new null;}, "E_OBJECT_EXPECTED");
2176 testException(function() {new nullDisp;}, "E_NO_PROPERTY");
2177 testException(function() {new VBArray();}, "E_NOT_VBARRAY");
2178 testException(function() {new VBArray(new VBArray(createArray()));}, "E_NOT_VBARRAY");
2179 testException(function() {VBArray.prototype.lbound.call(new Object());}, "E_NOT_VBARRAY");
2180 testException(function() {+nullDisp.prop;}, "E_OBJECT_REQUIRED");
2181 testException(function() {+nullDisp["prop"];}, "E_OBJECT_REQUIRED");
2182 testException(function() {delete (new Object());}, "E_INVALID_DELETE");
2183 testException(function() {delete false;}, "E_INVALID_DELETE");
2185 obj = new Object();
2186 obj.prop = 1;
2187 tmp = false;
2188 testException(function() {delete ((tmp = true) ? obj.prop : obj.prop);}, "E_INVALID_DELETE");
2189 ok(tmp, "delete (..) expression not evaluated");
2191 //FIXME: testException(function() {nonexistent++;}, "E_OBJECT_EXPECTED");
2192 //FIXME: testException(function() {undefined.nonexistent++;}, "E_OBJECT_EXPECTED");
2195 // SyntaxError tests
2196 function testSyntaxError(code, id) {
2197     var ex = exception_array[id];
2198     var ret = "", num = "";
2200     try {
2201         eval(code);
2202     } catch(e) {
2203         ret = e.name;
2204         num = e.number;
2205     }
2207     ok(ret === ex.type, "Syntax exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + code);
2208     ok(num === ex.number, "Syntax exception test, num = " + num + ", expected " + ex.number + ". Executed code: " + code);
2211 testSyntaxError("for(i=0;) {}", "E_SYNTAX_ERROR");
2212 testSyntaxError("function {};", "E_LBRACKET");
2213 testSyntaxError("if", "E_LBRACKET");
2214 testSyntaxError("do i=0; while", "E_LBRACKET");
2215 testSyntaxError("while", "E_LBRACKET");
2216 testSyntaxError("for", "E_LBRACKET");
2217 testSyntaxError("with", "E_LBRACKET");
2218 testSyntaxError("switch", "E_LBRACKET");
2219 testSyntaxError("if(false", "E_RBRACKET");
2220 testSyntaxError("for(i=0; i<10; i++", "E_RBRACKET");
2221 testSyntaxError("while(true", "E_RBRACKET");
2222 testSyntaxError("for(i=0", "E_SEMICOLON");
2223 testSyntaxError("for(i=0;i<10", "E_SEMICOLON");
2224 testSyntaxError("while(", "E_SYNTAX_ERROR");
2225 testSyntaxError("if(", "E_SYNTAX_ERROR");
2226 testSyntaxError("'unterminated", "E_UNTERMINATED_STR");
2227 testSyntaxError("*", "E_SYNTAX_ERROR");
2228 testSyntaxError("@_jscript_version", "E_DISABLED_CC");
2229 testSyntaxError("@a", "E_DISABLED_CC");
2230 testSyntaxError("/* @cc_on @*/ @_jscript_version", "E_DISABLED_CC");
2231 testSyntaxError("ok(false, 'unexpected execution'); break;", "E_INVALID_BREAK");
2232 testSyntaxError("ok(false, 'unexpected execution'); continue;", "E_INVALID_CONTINUE");
2233 testSyntaxError("ok(false, 'unexpected execution'); while(true) break unknown_label;", "E_LABEL_NOT_FOUND");
2234 testSyntaxError("ok(false, 'unexpected execution'); some_label: continue some_label;", "E_INVALID_CONTINUE");
2235 testSyntaxError("ok(false, 'unexpected execution'); while(true) continue some_label;", "E_LABEL_NOT_FOUND");
2236 testSyntaxError("ok(false, 'unexpected execution'); some_label: { while(true) continue some_label; }", "E_INVALID_CONTINUE");
2237 testSyntaxError("ok(false, 'unexpected execution'); some_label: { some_label: while(true); }", "E_LABEL_REDEFINED");
2239 // ReferenceError tests
2240 testException(function() {test = function() {}}, "E_ILLEGAL_ASSIGN");
2242 tmp = false;
2243 testException(function() {test = (tmp = true);}, "E_ILLEGAL_ASSIGN");
2244 ok(tmp, "expr value on invalid assign not evaluated");
2246 tmp = false;
2247 testException(function() {(tmp = true) = false;}, "E_ILLEGAL_ASSIGN");
2248 ok(tmp, "expr assign not evaluated");
2250 tmp = false;
2251 testException(function() {true = (tmp = true);}, "E_ILLEGAL_ASSIGN");
2252 ok(tmp, "expr value assign not evaluated");
2254 tmp = "";
2255 testException(function() {(tmp = tmp+"1") = (tmp = tmp+"2");}, "E_ILLEGAL_ASSIGN");
2256 ok(tmp === "12", "assign evaluated in unexpected order");
2258 tmp = false;
2259 testException(function() { ((tmp = true) && false)++; }, "E_ILLEGAL_ASSIGN")
2260 ok(tmp, "incremented expression not evaluated");
2262 // RegExpError tests
2263 testException(function() {RegExp(/a/, "g");}, "E_REGEXP_SYNTAX_ERROR");
2265 // URIError tests
2266 testException(function() {encodeURI('\udcaa');}, "E_URI_INVALID_CHAR");
2267 testException(function() {encodeURIComponent('\udcaa');}, "E_URI_INVALID_CHAR");
2268 testException(function() {decodeURI('%');}, "E_URI_INVALID_CODING");
2269 testException(function() {decodeURI('%aaaa');}, "E_URI_INVALID_CODING");
2271 function testThisExcept(func, e) {
2272     testException(function() {func.call(new Object())}, e);
2275 function testBoolThis(func) {
2276     testThisExcept(Boolean.prototype[func], "E_NOT_BOOL");
2279 testBoolThis("toString");
2280 testBoolThis("valueOf");
2282 function testDateThis(func) {
2283     testThisExcept(Date.prototype[func], "E_NOT_DATE");
2286 testDateThis("getDate");
2287 testDateThis("getDay");
2288 testDateThis("getFullYear");
2289 testDateThis("getHours");
2290 testDateThis("getMilliseconds");
2291 testDateThis("getMinutes");
2292 testDateThis("getMonth");
2293 testDateThis("getSeconds");
2294 testDateThis("getTime");
2295 testDateThis("getTimezoneOffset");
2296 testDateThis("getUTCDate");
2297 testDateThis("getUTCDay");
2298 testDateThis("getUTCFullYear");
2299 testDateThis("getUTCHours");
2300 testDateThis("getUTCMilliseconds");
2301 testDateThis("getUTCMinutes");
2302 testDateThis("getUTCMonth");
2303 testDateThis("getUTCSeconds");
2304 testDateThis("getYear");
2305 testDateThis("setDate");
2306 testDateThis("setFullYear");
2307 testDateThis("setHours");
2308 testDateThis("setMilliseconds");
2309 testDateThis("setMinutes");
2310 testDateThis("setMonth");
2311 testDateThis("setSeconds");
2312 testDateThis("setTime");
2313 testDateThis("setUTCDate");
2314 testDateThis("setUTCFullYear");
2315 testDateThis("setUTCHours");
2316 testDateThis("setUTCMilliseconds");
2317 testDateThis("setUTCMinutes");
2318 testDateThis("setUTCMonth");
2319 testDateThis("setUTCSeconds");
2320 testDateThis("setYear");
2321 testDateThis("toDateString");
2322 testDateThis("toLocaleDateString");
2323 testDateThis("toLocaleString");
2324 testDateThis("toLocaleTimeString");
2325 testDateThis("toString");
2326 testDateThis("toTimeString");
2327 testDateThis("toUTCString");
2328 testDateThis("valueOf");
2330 function testArrayThis(func) {
2331     testThisExcept(Array.prototype[func], "E_NOT_ARRAY");
2334 testArrayThis("toString");
2336 function testFunctionThis(func) {
2337     testThisExcept(Function.prototype[func], "E_NOT_FUNC");
2340 testFunctionThis("toString");
2341 testFunctionThis("call");
2342 testFunctionThis("apply");
2344 function testArrayHostThis(func) {
2345     testException(function() { Array.prototype[func].call(testObj); }, "E_JSCRIPT_EXPECTED");
2348 testArrayHostThis("push");
2349 testArrayHostThis("shift");
2350 testArrayHostThis("slice");
2351 testArrayHostThis("splice");
2352 testArrayHostThis("unshift");
2353 testArrayHostThis("reverse");
2354 testArrayHostThis("join");
2355 testArrayHostThis("pop");
2356 testArrayHostThis("sort");
2358 function testObjectInherit(obj, constr, ts, tls, vo) {
2359     ok(obj instanceof Object, "obj is not instance of Object");
2360     ok(obj instanceof constr, "obj is not instance of its constructor");
2362     ok(obj.hasOwnProperty === Object.prototype.hasOwnProperty,
2363        "obj.hasOwnProperty !== Object.prototype.hasOwnProprty");
2364     ok(obj.isPrototypeOf === Object.prototype.isPrototypeOf,
2365        "obj.isPrototypeOf !== Object.prototype.isPrototypeOf");
2366     ok(obj.propertyIsEnumerable === Object.prototype.propertyIsEnumerable,
2367        "obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable");
2369     if(ts)
2370         ok(obj.toString === Object.prototype.toString,
2371            "obj.toString !== Object.prototype.toString");
2372     else
2373         ok(obj.toString != Object.prototype.toString,
2374            "obj.toString == Object.prototype.toString");
2376     if(tls)
2377         ok(obj.toLocaleString === Object.prototype.toLocaleString,
2378            "obj.toLocaleString !== Object.prototype.toLocaleString");
2379     else
2380         ok(obj.toLocaleString != Object.prototype.toLocaleString,
2381            "obj.toLocaleString == Object.prototype.toLocaleString");
2383     if(vo)
2384         ok(obj.valueOf === Object.prototype.valueOf,
2385            "obj.valueOf !== Object.prototype.valueOf");
2386     else
2387         ok(obj.valueOf != Object.prototype.valueOf,
2388            "obj.valueOf == Object.prototype.valueOf");
2390     ok(obj._test === "test", "obj.test = " + obj._test);
2393 Object.prototype._test = "test";
2394 testObjectInherit(new String("test"), String, false, true, false);
2395 testObjectInherit(/test/g, RegExp, false, true, true);
2396 testObjectInherit(new Number(1), Number, false, false, false);
2397 testObjectInherit(new Date(), Date, false, false, false);
2398 testObjectInherit(new Boolean(true), Boolean, false, true, false);
2399 testObjectInherit(new Array(), Array, false, false, true);
2400 testObjectInherit(new Error(), Error, false, true, true);
2401 testObjectInherit(testObjectInherit, Function, false, true, true);
2402 testObjectInherit(Math, Object, true, true, true);
2404 (function() { testObjectInherit(arguments, Object, true, true, true); })();
2406 function testFunctions(obj, arr) {
2407     var l;
2409     for(var i=0; i<arr.length; i++) {
2410         l = obj[arr[i][0]].length;
2411         ok(l === arr[i][1], arr[i][0] + ".length = " + l);
2412     }
2415 testFunctions(Boolean.prototype, [
2416         ["valueOf", 0],
2417         ["toString", 0]
2418     ]);
2420 testFunctions(Number.prototype, [
2421         ["valueOf", 0],
2422         ["toString", 1],
2423         ["toExponential", 1],
2424         ["toLocaleString", 0],
2425         ["toPrecision", 1]
2426     ]);
2428 testFunctions(String.prototype, [
2429         ["valueOf", 0],
2430         ["toString", 0],
2431         ["anchor", 1],
2432         ["big", 0],
2433         ["blink", 0],
2434         ["bold", 0],
2435         ["charAt", 1],
2436         ["charCodeAt", 1],
2437         ["concat", 1],
2438         ["fixed", 0],
2439         ["fontcolor", 1],
2440         ["fontsize", 1],
2441         ["indexOf", 2],
2442         ["italics", 0],
2443         ["lastIndexOf", 2],
2444         ["link", 1],
2445         ["localeCompare", 1],
2446         ["match", 1],
2447         ["replace", 1],
2448         ["search", 0],
2449         ["slice", 0],
2450         ["small", 0],
2451         ["split", 2],
2452         ["strike", 0],
2453         ["sub", 0],
2454         ["substr", 2],
2455         ["substring", 2],
2456         ["sup", 0],
2457         ["toLocaleLowerCase", 0],
2458         ["toLocaleUpperCase", 0],
2459         ["toLowerCase", 0],
2460         ["toUpperCase", 0]
2461     ]);
2463 testFunctions(RegExp.prototype, [
2464         ["toString", 0],
2465         ["exec", 1],
2466         ["test", 1]
2467     ]);
2469 testFunctions(Date.prototype, [
2470         ["getDate", 0],
2471         ["getDay", 0],
2472         ["getFullYear", 0],
2473         ["getHours", 0],
2474         ["getMilliseconds", 0],
2475         ["getMinutes", 0],
2476         ["getMonth", 0],
2477         ["getSeconds", 0],
2478         ["getTime", 0],
2479         ["getTimezoneOffset", 0],
2480         ["getUTCDate", 0],
2481         ["getUTCDay", 0],
2482         ["getUTCFullYear", 0],
2483         ["getUTCHours", 0],
2484         ["getUTCMilliseconds", 0],
2485         ["getUTCMinutes", 0],
2486         ["getUTCMonth", 0],
2487         ["getUTCSeconds", 0],
2488         ["getYear", 0],
2489         ["setDate", 1],
2490         ["setFullYear", 3],
2491         ["setHours", 4],
2492         ["setMilliseconds", 1],
2493         ["setMinutes", 3],
2494         ["setMonth", 2],
2495         ["setSeconds", 2],
2496         ["setTime", 1],
2497         ["setUTCDate", 1],
2498         ["setUTCFullYear", 3],
2499         ["setUTCHours", 4],
2500         ["setUTCMilliseconds", 1],
2501         ["setUTCMinutes", 3],
2502         ["setUTCMonth", 2],
2503         ["setUTCSeconds", 2],
2504         ["setYear", 1],
2505         ["toDateString", 0],
2506         ["toLocaleDateString", 0],
2507         ["toLocaleString", 0],
2508         ["toLocaleTimeString", 0],
2509         ["toString", 0],
2510         ["toTimeString", 0],
2511         ["toUTCString", 0],
2512         ["toGMTString", 0],
2513         ["valueOf", 0]
2514     ]);
2516 testFunctions(Array.prototype, [
2517         ["concat", 1],
2518         ["join", 1],
2519         ["push", 1],
2520         ["pop", 0],
2521         ["reverse", 0],
2522         ["shift", 0],
2523         ["slice", 2],
2524         ["sort", 1],
2525         ["splice", 2],
2526         ["toLocaleString", 0],
2527         ["toString", 0],
2528         ["unshift", 1]
2529     ]);
2531 testFunctions(Error.prototype, [
2532         ["toString", 0]
2533     ]);
2535 testFunctions(Math, [
2536         ["abs", 1],
2537         ["acos", 1],
2538         ["asin", 1],
2539         ["atan", 1],
2540         ["atan2", 2],
2541         ["ceil", 1],
2542         ["cos", 1],
2543         ["exp", 1],
2544         ["floor", 1],
2545         ["log", 1],
2546         ["max", 2],
2547         ["min", 2],
2548         ["pow", 2],
2549         ["random", 0],
2550         ["round", 1],
2551         ["sin", 1],
2552         ["sqrt", 1],
2553         ["tan", 1]
2554     ]);
2556 testFunctions(Object.prototype, [
2557         ["hasOwnProperty", 1],
2558         ["isPrototypeOf", 1],
2559         ["propertyIsEnumerable", 1],
2560         ["toLocaleString", 0],
2561         ["toString", 0],
2562         ["valueOf", 0]
2563     ]);
2565 testFunctions(Function.prototype, [
2566         ["apply", 2],
2567         ["call", 1],
2568         ["toString", 0]
2569     ]);
2571 testFunctions(VBArray.prototype, [
2572         ["dimensions", 0],
2573         ["getItem", 1],
2574         ["lbound", 0],
2575         ["toArray", 0],
2576         ["ubound", 0]
2577     ]);
2579 ok(ActiveXObject.length == 1, "ActiveXObject.length = " + ActiveXObject.length);
2580 ok(Array.length == 1, "Array.length = " + Array.length);
2581 ok(Boolean.length == 1, "Boolean.length = " + Boolean.length);
2582 ok(CollectGarbage.length == 0, "CollectGarbage.length = " + CollectGarbage.length);
2583 ok(Date.length == 7, "Date.length = " + Date.length);
2584 ok(Enumerator.length == 7, "Enumerator.length = " + Enumerator.length);
2585 ok(Error.length == 1, "Error.length = " + Error.length);
2586 ok(EvalError.length == 1, "EvalError.length = " + EvalError.length);
2587 ok(RegExpError.length == 1, "RegExpError.length = " + RegExpError.length);
2588 ok(Function.length == 1, "Function.length = " + Function.length);
2589 ok(GetObject.length == 2, "GetObject.length = " + GetObject.length);
2590 ok(Number.length == 1, "Number.length = " + Number.length);
2591 ok(Object.length == 0, "Object.length = " + Object.length);
2592 ok(RangeError.length == 1, "RangeError.length = " + RangeError.length);
2593 ok(ReferenceError.length == 1, "ReferenceError.length = " + ReferenceError.length);
2594 ok(RegExp.length == 2, "RegExp.length = " + RegExp.length);
2595 ok(ScriptEngine.length == 0, "ScriptEngine.length = " + ScriptEngine.length);
2596 ok(ScriptEngineBuildVersion.length == 0,
2597     "ScriptEngineBuildVersion.length = " + ScriptEngineBuildVersion.length);
2598 ok(ScriptEngineMajorVersion.length == 0,
2599     "ScriptEngineMajorVersion.length = " + ScriptEngineMajorVersion.length);
2600 ok(ScriptEngineMinorVersion.length == 0,
2601     "ScriptEngineMinorVersion.length = " + ScriptEngineMinorVersion.length);
2602 ok(String.length == 1, "String.length = " + String.length);
2603 ok(SyntaxError.length == 1, "SyntaxError.length = " + SyntaxError.length);
2604 ok(TypeError.length == 1, "TypeError.length = " + TypeError.length);
2605 ok(URIError.length == 1, "URIError.length = " + URIError.length);
2606 ok(VBArray.length == 1, "VBArray.length = " + VBArray.length);
2607 ok(decodeURI.length == 1, "decodeURI.length = " + decodeURI.length);
2608 ok(decodeURIComponent.length == 1, "decodeURIComponent.length = " + decodeURIComponent.length);
2609 ok(encodeURI.length == 1, "encodeURI.length = " + encodeURI.length);
2610 ok(encodeURIComponent.length == 1, "encodeURIComponent.length = " + encodeURIComponent.length);
2611 ok(escape.length == 1, "escape.length = " + escape.length);
2612 ok(eval.length == 1, "eval.length = " + eval.length);
2613 ok(isFinite.length == 1, "isFinite.length = " + isFinite.length);
2614 ok(isNaN.length == 1, "isNaN.length = " + isNaN.length);
2615 ok(parseFloat.length == 1, "parseFloat.length = " + parseFloat.length);
2616 ok(parseInt.length == 2, "parseInt.length = " + parseInt.length);
2617 ok(unescape.length == 1, "unescape.length = " + unescape.length);
2619 String.length = 3;
2620 ok(String.length == 1, "String.length = " + String.length);
2622 var tmp = createArray();
2623 ok(getVT(tmp) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp));
2624 ok(getVT(VBArray(tmp)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp)));
2625 tmp = new VBArray(tmp);
2626 tmp = new VBArray(VBArray(createArray()));
2627 ok(tmp.dimensions() == 2, "tmp.dimensions() = " + tmp.dimensions());
2628 ok(tmp.lbound() == 0, "tmp.lbound() = " + tmp.lbound());
2629 ok(tmp.lbound(1) == 0, "tmp.lbound(1) = " + tmp.lbound(1));
2630 ok(tmp.lbound(2, 1) == 2, "tmp.lbound(2, 1) = " + tmp.lbound(2, 1));
2631 ok(tmp.ubound() == 4, "tmp.ubound() = " + tmp.ubound());
2632 ok(tmp.ubound("2") == 3, "tmp.ubound(\"2\") = " + tmp.ubound("2"));
2633 ok(tmp.getItem(1, 2) == 3, "tmp.getItem(1, 2) = " + tmp.getItem(1, 2));
2634 ok(tmp.getItem(2, 3) == 33, "tmp.getItem(2, 3) = " + tmp.getItem(2, 3));
2635 ok(tmp.getItem(3, 2) == 13, "tmp.getItem(3, 2) = " + tmp.getItem(3, 2));
2636 ok(tmp.toArray() == "2,3,12,13,22,23,32,33,42,43", "tmp.toArray() = " + tmp.toArray());
2637 ok(createArray().toArray() == "2,3,12,13,22,23,32,33,42,43",
2638         "createArray.toArray()=" + createArray().toArray());
2640 reportSuccess();