[JSCRIPT_WINETEST] Sync with Wine Staging 4.0. CORE-15682
[reactos.git] / modules / rostests / winetests / jscript / api.js
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 var tmp, i;
20
21 var bigInt = Math.pow(2,40);
22
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)");
28
29 function testNoEnumerables(expr) {
30 for(var iter in obj)
31 ok(false, expr + " has property " + iter);
32 }
33
34 testNoEnumerables("Object");
35 testNoEnumerables("Object.prototype");
36 testNoEnumerables("new Object()");
37 testNoEnumerables("Math");
38 testNoEnumerables("String");
39 testNoEnumerables("String.prototype");
40 testNoEnumerables("new String()");
41 testNoEnumerables("Number");
42 testNoEnumerables("Number.prototype");
43 testNoEnumerables("new Number(1)");
44 testNoEnumerables("ActiveXObject");
45 testNoEnumerables("Array");
46 testNoEnumerables("Array.prototype");
47 testNoEnumerables("new Array()");
48 testNoEnumerables("Boolean");
49 testNoEnumerables("Boolean.prototype");
50 testNoEnumerables("new Boolean()");
51 testNoEnumerables("Date");
52 testNoEnumerables("Date.prototype");
53 testNoEnumerables("new Date()");
54 testNoEnumerables("TypeError");
55 testNoEnumerables("TypeError.prototype");
56 testNoEnumerables("new TypeError()");
57 testNoEnumerables("Function");
58 testNoEnumerables("Function.prototype");
59 testNoEnumerables("testNoEnumerates");
60 testNoEnumerables("VBArray");
61
62 ok(Object.propertyIsEnumerable("prototype") === false, "Object.prototype is enumerable");
63 ok(Math.propertyIsEnumerable("E") === false, "Math.E is enumerable");
64 ok(Math.propertyIsEnumerable("SQRT2") === false, "Math.SQRT2 is enumerable");
65 ok(Math.propertyIsEnumerable("PI") === false, "Math.PI is enumerable");
66 ok("test".propertyIsEnumerable("length") === false, "'test'.length is enumerable");
67 ok([1].propertyIsEnumerable("length") === false, "[1].length is enumerable");
68 ok((new TypeError()).propertyIsEnumerable("message") === true, "(new TypeError()).message is not enumerable");
69 ok((new TypeError()).propertyIsEnumerable("description") === false, "(new TypeError()).description is enumerable");
70 ok((new TypeError()).propertyIsEnumerable("name") === false, "(new TypeError()).name is enumerable");
71 ok((new TypeError()).propertyIsEnumerable("number") === false, "(new TypeError()).number is enumerable");
72 ok(Object.propertyIsEnumerable.propertyIsEnumerable("length") === false, "Object.propertyIsEnumerable.length is enumerable");
73
74 tmp = new Object();
75 tmp.test = "1";
76 ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable");
77
78 tmp = { test: 1 };
79 ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable");
80
81 ok([1].concat([2]).propertyIsEnumerable("1"), "[1].concat([2]).1 is not enumerable");
82 ok("t.e.s.t".split(".").propertyIsEnumerable("0"), "'test'.split().0 is not enumerable");
83
84 (function() {
85 ok(arguments.propertyIsEnumerable("0") === false, "arguments.0 is enumerable");
86 ok(arguments.propertyIsEnumerable("length") === false, "arguments.length is enumerable");
87 ok(arguments.propertyIsEnumerable("calee") === false, "arguments.calee is enumerable");
88 })();
89
90 tmp = [1];
91 tmp.push("");
92 ok(tmp.propertyIsEnumerable("1"), "[1].push() ... 1 is not enumerable");
93
94 ok([1,2].reverse().propertyIsEnumerable("1"), "[1,2].rverse().1 is not enumerable");
95 ok([1,2].propertyIsEnumerable("0"), "[1,2].0 is not enumerable");
96
97 i = parseInt("0");
98 ok(i === 0, "parseInt('0') = " + i);
99 i = parseInt("123");
100 ok(i === 123, "parseInt('123') = " + i);
101 i = parseInt("-123");
102 ok(i === -123, "parseInt('-123') = " + i);
103 i = parseInt("0xff");
104 ok(i === 0xff, "parseInt('0xff') = " + i);
105 i = parseInt("11", 8);
106 ok(i === 9, "parseInt('11', 8) = " + i);
107 i = parseInt("1j", 22);
108 ok(i === 41, "parseInt('1j', 32) = " + i);
109 i = parseInt("123", 0);
110 ok(i === 123, "parseInt('123', 0) = " + i);
111 i = parseInt("123", 10, "test");
112 ok(i === 123, "parseInt('123', 10, 'test') = " + i);
113 i = parseInt("11", "8");
114 ok(i === 9, "parseInt('11', '8') = " + i);
115 i = parseInt("010");
116 ok(i === 8, "parseInt('010') = " + i);
117 i = parseInt("");
118 ok(isNaN(i), "parseInt('') = " + i);
119 i = parseInt("0x");
120 ok(isNaN(i), "parseInt('0x') = " + i);
121 i = parseInt("+");
122 ok(isNaN(i), "parseInt('+') = " + i);
123 i = parseInt("-");
124 ok(isNaN(i), "parseInt('-') = " + i);
125 i = parseInt("0x10", 11);
126 ok(i === 0, "parseInt('0x10', 11) = " + i);
127 i = parseInt("010", 7);
128 ok(i === 7, "parseInt('010', 7) = " + i);
129 i = parseInt("123abc");
130 ok(i === 123, "parseInt('123abc') = " + i);
131 i = parseInt(" \t123abc");
132 ok(i === 123, "parseInt(' \\t123abc') = " + i);
133 i = parseInt("abc");
134 ok(isNaN(i), "parseInt('123abc') = " + i);
135 i = parseInt("-12", 11);
136 ok(i === -13, "parseInt('-12') = " + i);
137 i = parseInt("-0x10");
138 ok(i === -16, "parseInt('-0x10') = " + i);
139 i = parseInt("-010");
140 ok(i === -8, "parseInt('-010') = " + i);
141 i = parseInt("123", 0);
142 ok(i === 123, "parseInt('123', 0) = " + i);
143 i = parseInt("0x10", 0);
144 ok(i === 16, "parseInt('123', 0) = " + i);
145 i = parseInt("0x10", 10);
146 ok(i === 0, "parseInt('0x10', 10) = " + i);
147 i = parseInt("0xz");
148 ok(isNaN(i), "parseInt('0xz') = " + i);
149 i = parseInt("1", 1);
150 ok(isNaN(i), "parseInt('1', 1) = " + i);
151 i = parseInt("1", -1);
152 ok(isNaN(i), "parseInt('1', -1) = " + i);
153 i = parseInt("1", 37);
154 ok(isNaN(i), "parseInt('1', 37) = " + i);
155 i = parseInt("1", 36);
156 ok(i === 1, "parseInt('1', 36) = " + i);
157
158 tmp = encodeURI("abc");
159 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
160 tmp = encodeURI("{abc}");
161 ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp);
162 tmp = encodeURI("");
163 ok(tmp === "", "encodeURI('') = " + tmp);
164 tmp = encodeURI("\01\02\03\04");
165 ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp);
166 tmp = encodeURI("{#@}");
167 ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp);
168 tmp = encodeURI("\xa1 ");
169 ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp);
170 tmp = encodeURI("\xffff");
171 ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length);
172 tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
173 ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
174 tmp = encodeURI("%");
175 ok(tmp === "%25", "encodeURI('%') = " + tmp);
176 tmp = encodeURI();
177 ok(tmp === "undefined", "encodeURI() = " + tmp);
178 tmp = encodeURI("abc", "test");
179 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
180
181 tmp = decodeURI("abc");
182 ok(tmp === "abc", "decodeURI('abc') = " + tmp);
183 tmp = decodeURI("{abc}");
184 ok(tmp === "{abc}", "decodeURI('{abc}') = " + tmp);
185 tmp = decodeURI("");
186 ok(tmp === "", "decodeURI('') = " + tmp);
187 tmp = decodeURI("\01\02\03\04");
188 ok(tmp === "\01\02\03\04", "decodeURI('\\01\\02\\03\\04') = " + tmp);
189 tmp = decodeURI();
190 ok(tmp === "undefined", "decodeURI() = " + tmp);
191 tmp = decodeURI("abc", "test");
192 ok(tmp === "abc", "decodeURI('abc') = " + tmp);
193 tmp = decodeURI("%7babc%7d");
194 ok(tmp === "{abc}", "decodeURI('%7Babc%7D') = " + tmp);
195 tmp = decodeURI("%01%02%03%04");
196 ok(tmp === "\01\02\03\04", "decodeURI('%01%02%03%04') = " + tmp);
197 tmp = decodeURI("%C2%A1%20");
198 ok(tmp === "\xa1 ", "decodeURI('%C2%A1%20') = " + tmp);
199 tmp = decodeURI("%C3%BFff");
200 ok(tmp.length === 3, "decodeURI('%C3%BFff').length = " + tmp.length);
201
202 tmp = encodeURIComponent("abc");
203 ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
204 dec = decodeURIComponent(tmp);
205 ok(dec === "abc", "decodeURIComponent('" + tmp + "') = " + dec);
206 tmp = encodeURIComponent("{abc}");
207 ok(tmp === "%7Babc%7D", "encodeURIComponent('{abc}') = " + tmp);
208 dec = decodeURIComponent(tmp);
209 ok(dec === "{abc}", "decodeURIComponent('" + tmp + "') = " + dec);
210 tmp = encodeURIComponent("");
211 ok(tmp === "", "encodeURIComponent('') = " + tmp);
212 dec = decodeURIComponent(tmp);
213 ok(dec === "", "decodeURIComponent('" + tmp + "') = " + dec);
214 tmp = encodeURIComponent("\01\02\03\04");
215 ok(tmp === "%01%02%03%04", "encodeURIComponent('\\01\\02\\03\\04') = " + tmp);
216 dec = decodeURIComponent(tmp);
217 ok(dec === "\01\02\03\04", "decodeURIComponent('" + tmp + "') = " + dec);
218 tmp = encodeURIComponent("{#@}");
219 ok(tmp === "%7B%23%40%7D", "encodeURIComponent('{#@}') = " + tmp);
220 dec = decodeURIComponent(tmp);
221 ok(dec === "{#@}", "decodeURIComponent('" + tmp + "') = " + dec);
222 tmp = encodeURIComponent("\xa1 ");
223 ok(tmp === "%C2%A1%20", "encodeURIComponent(\\xa1 ) = " + tmp);
224 dec = decodeURIComponent(tmp);
225 ok(dec === "\xa1 ", "decodeURIComponent('" + tmp + "') = " + dec);
226 tmp = encodeURIComponent("\xffff");
227 ok(tmp.length === 8, "encodeURIComponent('\\xffff').length = " + tmp.length);
228 dec = decodeURIComponent(tmp);
229 ok(dec === "\xffff", "decodeURIComponent('" + tmp + "') = " + dec);
230 tmp = encodeURIComponent("abcABC123;/?:@&=+$,-_.!~*'()");
231 ok(tmp === "abcABC123%3B%2F%3F%3A%40%26%3D%2B%24%2C-_.!~*'()", "encodeURIComponent('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
232 dec = decodeURIComponent(tmp);
233 ok(dec === "abcABC123;/?:@&=+$,-_.!~*'()", "decodeURIComponent('" + tmp + "') = " + dec);
234 tmp = encodeURIComponent();
235 ok(tmp === "undefined", "encodeURIComponent() = " + tmp);
236 tmp = encodeURIComponent("abc", "test");
237 ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
238 dec = decodeURIComponent();
239 ok(dec === "undefined", "decodeURIComponent() = " + dec);
240 dec = decodeURIComponent("abc", "test");
241 ok(dec === "abc", "decodeURIComponent('abc') = " + dec);
242
243 tmp = escape("abc");
244 ok(tmp === "abc", "escape('abc') = " + tmp);
245 tmp = escape("");
246 ok(tmp === "", "escape('') = " + tmp);
247 tmp = escape("a1b c!d+e@*-_+./,");
248 ok(tmp === "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp);
249 tmp = escape();
250 ok(tmp === "undefined", "escape() = " + tmp);
251 tmp = escape('\u1234\123\xf3');
252 ok(tmp == "%u1234S%F3", "escape('\u1234\123\xf3') = " + tmp);
253
254 tmp = unescape("abc");
255 ok(tmp === "abc", "unescape('abc') = " + tmp);
256 tmp = unescape("");
257 ok(tmp === "", "unescape('') = " + tmp);
258 tmp = unescape("%%%");
259 ok(tmp === "%%%", "unescape('%%%') = " + tmp);
260 tmp = unescape();
261 ok(tmp === "undefined", "unescape() = " + tmp);
262 tmp = unescape("%54%65s%u0074");
263 ok(tmp === "Test", "unescape('%54%65s%u0074') = " + tmp);
264
265 tmp = "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|";
266 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));
267 ok(unescape(escape(tmp)) === tmp, "unescape(escape('" + tmp + "')) = " + unescape(escape(tmp)));
268
269 ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty('toString') is false");
270 ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false");
271 ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false");
272
273 obj = new Object();
274
275 ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
276 ok(!obj.hasOwnProperty('isPrototypeOf'), "obj.hasOwnProperty('isPrototypeOf') is true");
277 ok(!Object.hasOwnProperty('toString'), "Object.hasOwnProperty('toString') is true");
278 ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeOf') is true");
279 ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true");
280 ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true");
281
282 obj = new Array();
283 ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false");
284 ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false");
285 ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true");
286 ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true");
287
288 obj = new Boolean(false);
289 ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
290 ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true");
291 ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false");
292
293 obj = new Date();
294 ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
295 ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
296 ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
297 ok(!("now" in Date), "now found in Date");
298
299 obj = new Number();
300 ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
301 ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true");
302 ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false");
303
304 obj = /x/;
305 ok(!obj.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true");
306 ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false");
307 ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true");
308 ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true");
309 ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false");
310
311 obj = new String();
312 ok(!obj.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true");
313 ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false");
314 ok(!String.hasOwnProperty('charAt'), "String.hasOwnProperty('charAt') is true");
315 ok(String.prototype.hasOwnProperty('charAt'), "String.prototype.hasOwnProperty('charAt') is false");
316 ok(String.prototype.hasOwnProperty('length'), "String.prototype.hasOwnProperty('length') is false");
317
318 tmp = "" + new Object();
319 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
320 (tmp = new Array).f = Object.prototype.toString;
321 ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f());
322 (tmp = new Boolean).f = Object.prototype.toString;
323 ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f());
324 (tmp = new Date).f = Object.prototype.toString;
325 ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f());
326 (tmp = function() {}).f = Object.prototype.toString;
327 ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f());
328 Math.f = Object.prototype.toString;
329 ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f());
330 (tmp = new Number).f = Object.prototype.toString;
331 ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
332 (tmp = new RegExp("")).f = Object.prototype.toString;
333 ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
334 (tmp = new String).f = Object.prototype.toString;
335 ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f());
336 tmp = Object.prototype.toString.call(testObj);
337 ok(tmp === "[object Object]", "toString.call(testObj) = " + tmp);
338 tmp = Object.prototype.toString.call(this);
339 ok(tmp === "[object Object]", "toString.call(this) = " + tmp);
340 (function () { tmp = Object.prototype.toString.call(arguments); })();
341 ok(tmp === "[object Object]", "toString.call(arguments) = " + tmp);
342 tmp = Object.prototype.toString.call(new VBArray(createArray()));
343 ok(tmp === "[object Object]", "toString.call(new VBArray()) = " + tmp);
344
345 function TSTestConstr() {}
346 TSTestConstr.prototype = { toString: function() { return "test"; } };
347 obj = new TSTestConstr();
348 ok(obj.toString() === "test", "obj.toString() = " + obj.toString());
349
350 ok(Object(1) instanceof Number, "Object(1) is not instance of Number");
351 ok(Object("") instanceof String, "Object('') is not instance of String");
352 ok(Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
353
354 ok(new Object(1) instanceof Number, "Object(1) is not instance of Number");
355 ok(new Object("") instanceof String, "Object('') is not instance of String");
356 ok(new Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
357
358 obj = new Object();
359 ok(Object(obj) === obj, "Object(obj) !== obj");
360
361 ok(typeof(Object()) === "object", "typeof(Object()) !== 'object'");
362 ok(typeof(Object(undefined)) === "object", "typeof(Object(undefined)) !== 'object'");
363 ok(typeof(Object(null)) === "object", "typeof(Object(null)) !== 'object'");
364 ok(typeof(Object(nullDisp)) === "object", "typeof(Object(nullDisp)) !== 'object'");
365
366 ok(Object(nullDisp) != nullDisp, "Object(nullDisp) == nullDisp");
367 ok(new Object(nullDisp) != nullDisp, "new Object(nullDisp) == nullDisp");
368
369 ok(Object(testObj) === testObj, "Object(testObj) != testObj\n");
370 ok(new Object(testObj) === testObj, "new Object(testObj) != testObj\n");
371
372 tmp = new Object();
373 ok(Object(tmp) === tmp, "Object(tmp) != tmp");
374 ok(new Object(tmp) === tmp, "new Object(tmp) != tmp");
375
376 var obj = new Object();
377 obj.toString = function (x) {
378 ok(arguments.length === 0, "arguments.length = " + arguments.length);
379 return "test";
380 };
381 ok((tmp = obj.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp);
382 ok((tmp = obj.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp);
383 ok(obj === obj.valueOf(), "obj !== obj.valueOf");
384
385 ok("".length === 0, "\"\".length = " + "".length);
386 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
387 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
388 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
389
390 tmp = "".toString();
391 ok(tmp === "", "''.toString() = " + tmp);
392 tmp = "test".toString();
393 ok(tmp === "test", "''.toString() = " + tmp);
394 tmp = "test".toString(3);
395 ok(tmp === "test", "''.toString(3) = " + tmp);
396
397 tmp = "".valueOf();
398 ok(tmp === "", "''.valueOf() = " + tmp);
399 tmp = "test".valueOf();
400 ok(tmp === "test", "''.valueOf() = " + tmp);
401 tmp = "test".valueOf(3);
402 ok(tmp === "test", "''.valueOf(3) = " + tmp);
403
404 var str = new String("test");
405 ok(str.toString() === "test", "str.toString() = " + str.toString());
406 var str = new String();
407 ok(str.toString() === "", "str.toString() = " + str.toString());
408 var str = new String("test", "abc");
409 ok(str.toString() === "test", "str.toString() = " + str.toString());
410
411 str = new String("test");
412 ok(str.length === 4, "str.length = " + str.length);
413 str.length = 3;
414 str.length = 5;
415 ok(str.length === 4, "str.length = " + str.length);
416
417 var strObj = new Object();
418 strObj.toString = function() { return "abcd" };
419 strObj.substr = String.prototype.substr;
420 strObj.lastIndexOf = String.prototype.lastIndexOf;
421
422 tmp = "value " + str;
423 ok(tmp === "value test", "'value ' + str = " + tmp);
424
425 tmp = String();
426 ok(tmp === "", "String() = " + tmp);
427 tmp = String(false);
428 ok(tmp === "false", "String(false) = " + tmp);
429 tmp = String(null);
430 ok(tmp === "null", "String(null) = " + tmp);
431 tmp = String("test");
432 ok(tmp === "test", "String('test') = " + tmp);
433 tmp = String("test", "abc");
434 ok(tmp === "test", "String('test','abc') = " + tmp);
435
436 tmp = "abc".charAt(0);
437 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
438 tmp = "abc".charAt(1);
439 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
440 tmp = "abc".charAt(2);
441 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
442 tmp = "abc".charAt(3);
443 ok(tmp === "", "'abc',charAt(3) = " + tmp);
444 tmp = "abc".charAt(4);
445 ok(tmp === "", "'abc',charAt(4) = " + tmp);
446 tmp = "abc".charAt();
447 ok(tmp === "a", "'abc',charAt() = " + tmp);
448 tmp = "abc".charAt(-1);
449 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
450 tmp = "abc".charAt(0,2);
451 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
452 tmp = "abc".charAt(NaN);
453 ok(tmp === "a", "'abc',charAt(NaN) = " + tmp);
454 tmp = "abc".charAt(bigInt);
455 ok(tmp === "", "'abc',charAt(bigInt) = " + tmp);
456
457 tmp = "abc".charCodeAt(0);
458 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
459 tmp = "abc".charCodeAt(1);
460 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
461 tmp = "abc".charCodeAt(2);
462 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
463 tmp = "abc".charCodeAt();
464 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
465 tmp = "abc".charCodeAt(true);
466 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
467 tmp = "abc".charCodeAt(0,2);
468 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
469 tmp = "\u49F4".charCodeAt(0);
470 ok(tmp === 0x49F4, "'\u49F4'.charCodeAt(0) = " + tmp);
471 tmp = "\052".charCodeAt(0);
472 ok(tmp === 0x2A, "'\052'.charCodeAt(0) = " + tmp);
473 tmp = "\xa2".charCodeAt(0);
474 ok(tmp === 0xA2, "'\xa2'.charCodeAt(0) = " + tmp);
475 tmp = "abc".charCodeAt(bigInt);
476 ok(isNaN(tmp), "'abc'.charCodeAt(bigInt) = " + tmp);
477
478 tmp = "abcd".substring(1,3);
479 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
480 tmp = "abcd".substring(-1,3);
481 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
482 tmp = "abcd".substring(1,6);
483 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
484 tmp = "abcd".substring(3,1);
485 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
486 tmp = "abcd".substring(2,2);
487 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
488 tmp = "abcd".substring(true,"3");
489 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
490 tmp = "abcd".substring(1,3,2);
491 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
492 tmp = "abcd".substring();
493 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
494
495 tmp = "abcd".substr(1,3);
496 ok(tmp === "bcd", "'abcd'.substr(1,3) = " + tmp);
497 tmp = "abcd".substr(-1,3);
498 ok(tmp === "abc", "'abcd'.substr(-1,3) = " + tmp);
499 tmp = "abcd".substr(1,6);
500 ok(tmp === "bcd", "'abcd'.substr(1,6) = " + tmp);
501 tmp = "abcd".substr(2,-1);
502 ok(tmp === "", "'abcd'.substr(3,1) = " + tmp);
503 tmp = "abcd".substr(2,0);
504 ok(tmp === "", "'abcd'.substr(2,2) = " + tmp);
505 tmp = "abcd".substr(true,"3");
506 ok(tmp === "bcd", "'abcd'.substr(true,'3') = " + tmp);
507 tmp = "abcd".substr(1,3,2);
508 ok(tmp === "bcd", "'abcd'.substr(1,3,2) = " + tmp);
509 tmp = "abcd".substr();
510 ok(tmp === "abcd", "'abcd'.substr() = " + tmp);
511 tmp = strObj.substr(1,1);
512 ok(tmp === "b", "'abcd'.substr(1,3) = " + tmp);
513
514 tmp = "abcd".slice(1,3);
515 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
516 tmp = "abcd".slice(1,-1);
517 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
518 tmp = "abcd".slice(-3,3);
519 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
520 tmp = "abcd".slice(-6,3);
521 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
522 tmp = "abcd".slice(3,1);
523 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
524 tmp = "abcd".slice(true,3);
525 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
526 tmp = "abcd".slice();
527 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
528 tmp = "abcd".slice(1);
529 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
530
531 tmp = "abc".concat(["d",1],2,false);
532 ok(tmp === "abcd,12false", "concat returned " + tmp);
533 var arr = new Array(2,"a");
534 arr.concat = String.prototype.concat;
535 tmp = arr.concat("d");
536 ok(tmp === "2,ad", "arr.concat = " + tmp);
537
538 m = "a+bcabc".match("a+");
539 ok(typeof(m) === "object", "typeof m is not object");
540 ok(m.length === 1, "m.length is not 1");
541 ok(m["0"] === "a", "m[0] is not \"a\"");
542
543 r = "- [test] -".replace("[test]", "success");
544 ok(r === "- success -", "r = " + r + " expected '- success -'");
545
546 r = "- [test] -".replace("[test]", "success", "test");
547 ok(r === "- success -", "r = " + r + " expected '- success -'");
548
549 r = "test".replace();
550 ok(r === "test", "r = " + r + " expected 'test'");
551
552 function replaceFunc3(m, off, str) {
553 ok(arguments.length === 3, "arguments.length = " + arguments.length);
554 ok(m === "[test]", "m = " + m + " expected [test]");
555 ok(off === 1, "off = " + off + " expected 0");
556 ok(str === "-[test]-", "str = " + arguments[3]);
557 return "ret";
558 }
559
560 r = "-[test]-".replace("[test]", replaceFunc3);
561 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
562
563 r = "-[test]-".replace("[test]", replaceFunc3, "test");
564 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
565
566 r = "x,x,x".replace("x", "y");
567 ok(r === "y,x,x", "r = " + r + " expected 'y,x,x'");
568
569 r = "x,x,x".replace("", "y");
570 ok(r === "yx,x,x", "r = " + r + " expected 'yx,x,x'");
571
572 r = "x,x,x".replace("", "");
573 ok(r === "x,x,x", "r = " + r + " expected 'x,x,x'");
574
575 r = "1,2,3".split(",");
576 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
577 ok(r.length === 3, "r.length = " + r.length);
578 ok(r[0] === "1", "r[0] = " + r[0]);
579 ok(r[1] === "2", "r[1] = " + r[1]);
580 ok(r[2] === "3", "r[2] = " + r[2]);
581
582 r = "1,2,3".split(",*");
583 ok(r.length === 1, "r.length = " + r.length);
584 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
585
586 r = "123".split("");
587 ok(r.length === 3, "r.length = " + r.length);
588 ok(r[0] === "1", "r[0] = " + r[0]);
589 ok(r[1] === "2", "r[1] = " + r[1]);
590 ok(r[2] === "3", "r[2] = " + r[2]);
591
592 r = "123".split(2);
593 ok(r.length === 2, "r.length = " + r.length);
594 ok(r[0] === "1", "r[0] = " + r[0]);
595 ok(r[1] === "3", "r[1] = " + r[1]);
596
597 r = "1,2,".split(",");
598 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
599 ok(r.length === 3, "r.length = " + r.length);
600 ok(r[0] === "1", "r[0] = " + r[0]);
601 ok(r[1] === "2", "r[1] = " + r[1]);
602 ok(r[2] === "", "r[2] = " + r[2]);
603
604 r = "1,2,3".split(",", 2);
605 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
606 ok(r.length === 2, "r.length = " + r.length);
607 ok(r[0] === "1", "r[0] = " + r[0]);
608 ok(r[1] === "2", "r[1] = " + r[1]);
609
610 r = "1,2,3".split(",", 0);
611 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
612 ok(r.length === 0, "r.length = " + r.length);
613
614 r = "1,2,3".split(",", -1);
615 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
616 ok(r.length === 3, "r.length = " + r.length);
617 ok(r[0] === "1", "r[0] = " + r[0]);
618 ok(r[1] === "2", "r[1] = " + r[1]);
619 ok(r[2] === "3", "r[1] = " + r[1]);
620
621 r = "1,2,3".split(undefined);
622 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
623 ok(r.length === 1, "r.length = " + r.length);
624 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
625
626 r = "1,undefined2undefined,3".split(undefined);
627 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
628 ok(r.length === 3, "r.length = " + r.length);
629 ok(r[0] === "1,", "r[0] = " + r[0]);
630 ok(r[1] === "2", "r[1] = " + r[1]);
631 ok(r[2] === ",3", "r[2] = " + r[2]);
632
633 r = "1,undefined2undefined,3".split();
634 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
635 ok(r.length === 1, "r.length = " + r.length);
636 ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
637
638 r = "".split();
639 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
640 ok(r.length === 1, "r.length = " + r.length);
641 ok(r[0] === "", "r[0] = " + r[0]);
642
643 tmp = "abcd".indexOf("bc",0);
644 ok(tmp === 1, "indexOf = " + tmp);
645 tmp = "abcd".indexOf("bc",1);
646 ok(tmp === 1, "indexOf = " + tmp);
647 tmp = "abcd".indexOf("bc");
648 ok(tmp === 1, "indexOf = " + tmp);
649 tmp = "abcd".indexOf("ac");
650 ok(tmp === -1, "indexOf = " + tmp);
651 tmp = "abcd".indexOf("bc",2);
652 ok(tmp === -1, "indexOf = " + tmp);
653 tmp = "abcd".indexOf("a",0);
654 ok(tmp === 0, "indexOf = " + tmp);
655 tmp = "abcd".indexOf("bc",0,"test");
656 ok(tmp === 1, "indexOf = " + tmp);
657 tmp = "abcd".indexOf();
658 ok(tmp == -1, "indexOf = " + tmp);
659 tmp = "abcd".indexOf("b", bigInt);
660 ok(tmp == -1, "indexOf = " + tmp);
661 tmp = "abcd".indexOf("abcd",0);
662 ok(tmp === 0, "indexOf = " + tmp);
663 tmp = "abcd".indexOf("abcd",1);
664 ok(tmp === -1, "indexOf = " + tmp);
665 tmp = ("ab" + String.fromCharCode(0) + "cd").indexOf(String.fromCharCode(0));
666 ok(tmp === 2, "indexOf = " + tmp);
667
668 tmp = "abcd".lastIndexOf("bc",1);
669 ok(tmp === 1, "lastIndexOf = " + tmp);
670 tmp = "abcd".lastIndexOf("bc",2);
671 ok(tmp === 1, "lastIndexOf = " + tmp);
672 tmp = "abcd".lastIndexOf("bc");
673 ok(tmp === 1, "lastIndexOf = " + tmp);
674 tmp = "abcd".lastIndexOf("ac");
675 ok(tmp === -1, "lastIndexOf = " + tmp);
676 tmp = "abcd".lastIndexOf("d",10);
677 ok(tmp === 3, "lastIndexOf = " + tmp);
678 tmp = "abcd".lastIndexOf("bc",0,"test");
679 ok(tmp === -1, "lastIndexOf = " + tmp);
680 tmp = "abcd".lastIndexOf();
681 ok(tmp === -1, "lastIndexOf = " + tmp);
682 tmp = "aaaa".lastIndexOf("a",2);
683 ok(tmp == 2, "lastIndexOf = " + tmp);
684 tmp = strObj.lastIndexOf("b");
685 ok(tmp === 1, "lastIndexOf = " + tmp);
686 tmp = "bbb".lastIndexOf("b", bigInt);
687 ok(tmp === 2, "lastIndexOf = " + tmp);
688 tmp = "abcd".lastIndexOf("abcd",4);
689 ok(tmp === 0, "lastIndexOf = " + tmp);
690 tmp = "abcd".lastIndexOf("abcd",0);
691 ok(tmp === 0, "lastIndexOf = " + tmp);
692 tmp = ("ab" + String.fromCharCode(0) + "cd").lastIndexOf(String.fromCharCode(0));
693 ok(tmp === 2, "lastIndexOf = " + tmp);
694
695 tmp = "".toLowerCase();
696 ok(tmp === "", "''.toLowerCase() = " + tmp);
697 tmp = "test".toLowerCase();
698 ok(tmp === "test", "''.toLowerCase() = " + tmp);
699 tmp = "test".toLowerCase(3);
700 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
701 tmp = "tEsT".toLowerCase();
702 ok(tmp === "test", "''.toLowerCase() = " + tmp);
703 tmp = "tEsT".toLowerCase(3);
704 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
705 tmp = ("tE" + String.fromCharCode(0) + "sT").toLowerCase();
706 ok(tmp === "te" + String.fromCharCode(0) + "st", "''.toLowerCase() = " + tmp);
707
708 tmp = "".toUpperCase();
709 ok(tmp === "", "''.toUpperCase() = " + tmp);
710 tmp = "TEST".toUpperCase();
711 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
712 tmp = "TEST".toUpperCase(3);
713 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
714 tmp = "tEsT".toUpperCase();
715 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
716 tmp = "tEsT".toUpperCase(3);
717 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
718 tmp = ("tE" + String.fromCharCode(0) + "sT").toUpperCase();
719 ok(tmp === "TE" + String.fromCharCode(0) + "ST", "''.toUpperCase() = " + tmp);
720
721 tmp = "".anchor();
722 ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp);
723 tmp = "".anchor(3);
724 ok(tmp === "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp);
725 tmp = "".anchor("red");
726 ok(tmp === "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp);
727 tmp = "test".anchor();
728 ok(tmp === "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp);
729 tmp = "test".anchor(3);
730 ok(tmp === "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp);
731 tmp = "test".anchor("green");
732 ok(tmp === "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp);
733
734 tmp = "".big();
735 ok(tmp === "<BIG></BIG>", "''.big() = " + tmp);
736 tmp = "".big(3);
737 ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp);
738 tmp = "test".big();
739 ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp);
740 tmp = "test".big(3);
741 ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp);
742
743 tmp = "".blink();
744 ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp);
745 tmp = "".blink(3);
746 ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp);
747 tmp = "test".blink();
748 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp);
749 tmp = "test".blink(3);
750 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp);
751
752 tmp = "".bold();
753 ok(tmp === "<B></B>", "''.bold() = " + tmp);
754 tmp = "".bold(3);
755 ok(tmp === "<B></B>", "''.bold(3) = " + tmp);
756 tmp = "test".bold();
757 ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp);
758 tmp = "test".bold(3);
759 ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp);
760
761 tmp = "".fixed();
762 ok(tmp === "<TT></TT>", "''.fixed() = " + tmp);
763 tmp = "".fixed(3);
764 ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp);
765 tmp = "test".fixed();
766 ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp);
767 tmp = "test".fixed(3);
768 ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp);
769
770 tmp = "".fontcolor();
771 ok(tmp === "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp);
772 tmp = "".fontcolor(3);
773 ok(tmp === "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp);
774 tmp = "".fontcolor("red");
775 ok(tmp === "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp);
776 tmp = "test".fontcolor();
777 ok(tmp === "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp);
778 tmp = "test".fontcolor(3);
779 ok(tmp === "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp);
780 tmp = "test".fontcolor("green");
781 ok(tmp === "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp);
782
783 tmp = "".fontsize();
784 ok(tmp === "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp);
785 tmp = "".fontsize(3);
786 ok(tmp === "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp);
787 tmp = "".fontsize("red");
788 ok(tmp === "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp);
789 tmp = "test".fontsize();
790 ok(tmp === "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp);
791 tmp = "test".fontsize(3);
792 ok(tmp === "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp);
793 tmp = "test".fontsize("green");
794 ok(tmp === "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp);
795
796 tmp = ("".fontcolor()).fontsize();
797 ok(tmp === "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp);
798
799 tmp = "".italics();
800 ok(tmp === "<I></I>", "''.italics() = " + tmp);
801 tmp = "".italics(3);
802 ok(tmp === "<I></I>", "''.italics(3) = " + tmp);
803 tmp = "test".italics();
804 ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp);
805 tmp = "test".italics(3);
806 ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp);
807
808 tmp = "".link();
809 ok(tmp === "<A HREF=\"undefined\"></A>", "''.link() = " + tmp);
810 tmp = "".link(3);
811 ok(tmp === "<A HREF=\"3\"></A>", "''.link(3) = " + tmp);
812 tmp = "".link("red");
813 ok(tmp === "<A HREF=\"red\"></A>", "''.link('red') = " + tmp);
814 tmp = "test".link();
815 ok(tmp === "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp);
816 tmp = "test".link(3);
817 ok(tmp === "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp);
818 tmp = "test".link("green");
819 ok(tmp === "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp);
820
821 tmp = "".small();
822 ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp);
823 tmp = "".small(3);
824 ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp);
825 tmp = "test".small();
826 ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp);
827 tmp = "test".small(3);
828 ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp);
829
830 tmp = "".strike();
831 ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp);
832 tmp = "".strike(3);
833 ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp);
834 tmp = "test".strike();
835 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp);
836 tmp = "test".strike(3);
837 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp);
838
839 tmp = "".sub();
840 ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp);
841 tmp = "".sub(3);
842 ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp);
843 tmp = "test".sub();
844 ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp);
845 tmp = "test".sub(3);
846 ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp);
847
848 tmp = "".sup();
849 ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp);
850 tmp = "".sup(3);
851 ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp);
852 tmp = "test".sup();
853 ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
854 tmp = "test".sup(3);
855 ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
856
857 ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
858 ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
859 ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
860 "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
861 ok(String.fromCharCode(65, NaN, undefined).length === 3,
862 "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
863
864 var arr = new Array();
865 ok(typeof(arr) === "object", "arr () is not object");
866 ok((arr.length === 0), "arr.length is not 0");
867 ok(arr["0"] === undefined, "arr[0] is not undefined");
868
869 var arr = new Array(1, 2, "test");
870 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
871 ok((arr.length === 3), "arr.length is not 3");
872 ok(arr["0"] === 1, "arr[0] is not 1");
873 ok(arr["1"] === 2, "arr[1] is not 2");
874 ok(arr["2"] === "test", "arr[2] is not \"test\"");
875
876 arr["7"] = true;
877 ok((arr.length === 8), "arr.length is not 8");
878
879 tmp = "" + [];
880 ok(tmp === "", "'' + [] = " + tmp);
881 tmp = "" + [1,true];
882 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
883
884 var arr = new Array(6);
885 ok(typeof(arr) === "object", "arr (6) is not object");
886 ok((arr.length === 6), "arr.length is not 6");
887 ok(arr["0"] === undefined, "arr[0] is not undefined");
888
889 ok(arr.push() === 6, "arr.push() !== 6");
890 ok(arr.push(1) === 7, "arr.push(1) !== 7");
891 ok(arr[6] === 1, "arr[6] != 1");
892 ok(arr.length === 7, "arr.length != 10");
893 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
894 ok(arr[8] === "b", "arr[8] != 'b'");
895 ok(arr.length === 10, "arr.length != 10");
896
897 var arr = new Object();
898 arr.push = Array.prototype.push;
899
900 arr.length = 6;
901
902 ok(arr.push() === 6, "arr.push() !== 6");
903 ok(arr.push(1) === 7, "arr.push(1) !== 7");
904 ok(arr[6] === 1, "arr[6] != 1");
905 ok(arr.length === 7, "arr.length != 10");
906 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
907 ok(arr[8] === "b", "arr[8] != 'b'");
908 ok(arr.length === 10, "arr.length != 10");
909
910 arr.pop = Array.prototype.pop;
911 ok(arr.pop() === false, "arr.pop() !== false");
912 ok(arr[8] === "b", "arr[8] !== 'b'");
913 ok(arr.pop() === 'b', "arr.pop() !== 'b'");
914 ok(arr[8] === undefined, "arr[8] !== undefined");
915
916 arr = [3,4,5];
917 tmp = arr.pop();
918 ok(arr.length === 2, "arr.length = " + arr.length);
919 ok(tmp === 5, "pop() = " + tmp);
920 tmp = arr.pop(2);
921 ok(arr.length === 1, "arr.length = " + arr.length);
922 ok(tmp === 4, "pop() = " + tmp);
923 tmp = arr.pop();
924 ok(arr.length === 0, "arr.length = " + arr.length);
925 ok(tmp === 3, "pop() = " + tmp);
926 for(tmp in arr)
927 ok(false, "not deleted " + tmp);
928 tmp = arr.pop();
929 ok(arr.length === 0, "arr.length = " + arr.length);
930 ok(tmp === undefined, "tmp = " + tmp);
931 arr = new Object();
932 arr.pop = Array.prototype.pop;
933 tmp = arr.pop();
934 ok(arr.length === 0, "arr.length = " + arr.length);
935 ok(tmp === undefined, "tmp = " + tmp);
936 arr = [,,,,,];
937 tmp = arr.pop();
938 ok(arr.length === 5, "arr.length = " + arr.length);
939 ok(tmp === undefined, "tmp = " + tmp);
940 tmp = [1,2,,,].pop();
941 ok(tmp === undefined, "tmp = " + tmp);
942
943 function PseudoArray() {
944 this[0] = 0;
945 }
946 PseudoArray.prototype = {length: 1};
947 arr = new PseudoArray();
948 Array.prototype.push.call(arr, 2);
949 ok(arr.propertyIsEnumerable("length"), "arr.length is not enumerable");
950
951 arr = [1,2,null,false,undefined,,"a"];
952
953 tmp = arr.join();
954 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
955 tmp = arr.join(";");
956 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
957 tmp = arr.join(";","test");
958 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
959 tmp = arr.join("");
960 ok(tmp === "12falsea", "arr.join('') = " + tmp);
961
962 tmp = arr.toString();
963 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
964 tmp = arr.toString("test");
965 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
966
967 arr = ["a", "b"];
968
969 tmp = arr.join(String.fromCharCode(0));
970 ok(tmp === "a" + String.fromCharCode(0) + "b", "arr.join(String.fromCharCode(0)) = " + tmp);
971
972 arr = new Object();
973 arr.length = 3;
974 arr[0] = "aa";
975 arr[2] = 2;
976 arr[7] = 3;
977 arr.join = Array.prototype.join;
978 tmp = arr.join(",");
979 ok(arr.length === 3, "arr.length = " + arr.length);
980 ok(tmp === "aa,,2", "tmp = " + tmp);
981
982 arr = [5,true,2,-1,3,false,"2.5"];
983 tmp = arr.sort(function(x,y) { return y-x; });
984 ok(tmp === arr, "tmp !== arr");
985 tmp = [5,3,"2.5",2,true,false,-1];
986 for(var i=0; i < arr.length; i++)
987 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
988
989 arr = [5,false,2,0,"abc",3,"a",-1];
990 tmp = arr.sort();
991 ok(tmp === arr, "tmp !== arr");
992 tmp = [-1,0,2,3,5,"a","abc",false];
993 for(var i=0; i < arr.length; i++)
994 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
995
996 arr = ["a", "b", "ab"];
997 tmp = ["a", "ab", "b"];
998 ok(arr.sort() === arr, "arr.sort() !== arr");
999 for(var i=0; i < arr.length; i++)
1000 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
1001
1002 arr = new Object();
1003 arr.length = 3;
1004 arr[0] = 1;
1005 arr[2] = "aa";
1006 arr.sort = Array.prototype.sort;
1007 tmp = arr.sort();
1008 ok(arr === tmp, "tmp !== arr");
1009 ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorrectly");
1010
1011 tmp = [["bb","aa"],["ab","aa"]].sort().toString();
1012 ok(tmp === "ab,aa,bb,aa", "sort() = " + tmp);
1013
1014 tmp = [["bb","aa"],"ab"].sort().toString();
1015 ok(tmp === "ab,bb,aa", "sort() = " + tmp);
1016
1017 tmp = [["bb","aa"],"cc"].sort().toString();
1018 ok(tmp === "bb,aa,cc", "sort() = " + tmp);
1019
1020 tmp = [2,"1"].sort().toString();
1021 ok(tmp === "1,2", "sort() = " + tmp);
1022
1023 tmp = ["2",1].sort().toString();
1024 ok(tmp === "1,2", "sort() = " + tmp);
1025
1026 tmp = [,,0,"z"].sort().toString();
1027 ok(tmp === "0,z,,", "sort() = " + tmp);
1028
1029 tmp = ["a,b",["a","a"],["a","c"]].sort().toString();
1030 ok(tmp === "a,a,a,b,a,c", "sort() = " + tmp);
1031
1032 arr = ["1", "2", "3"];
1033 arr.length = 1;
1034 ok(arr.length === 1, "arr.length = " + arr.length);
1035 arr.length = 3;
1036 ok(arr.length === 3, "arr.length = " + arr.length);
1037 ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
1038
1039 arr = Array("a","b","c");
1040 ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
1041
1042 ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
1043 ok(arr === arr.valueOf(), "arr !== arr.valueOf");
1044
1045 arr = [1,2,3];
1046 tmp = arr.reverse();
1047 ok(tmp === arr, "tmp !== arr");
1048 ok(arr.length === 3, "arr.length = " + arr.length);
1049 ok(arr.toString() === "3,2,1", "arr.toString() = " + arr.toString());
1050
1051 arr = [];
1052 arr[3] = 5;
1053 arr[5] = 1;
1054 tmp = arr.reverse();
1055 ok(tmp === arr, "tmp !== arr");
1056 ok(arr.length === 6, "arr.length = " + arr.length);
1057 ok(arr.toString() === "1,,5,,,", "arr.toString() = " + arr.toString());
1058
1059 arr = new Object();
1060 arr.length = 3;
1061 arr[0] = "aa";
1062 arr[2] = 2;
1063 arr[7] = 3;
1064 arr.reverse = Array.prototype.reverse;
1065 tmp = arr.reverse();
1066 ok(tmp === arr, "tmp !== arr");
1067 ok(arr.length === 3, "arr.length = " + arr.length);
1068 ok(arr[0] === 2 && arr[1] === undefined && arr[2] === "aa", "unexpected array");
1069
1070 arr = [1,2,3];
1071 tmp = arr.unshift(0);
1072 ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp);
1073 ok(arr.length === 4, "arr.length = " + arr.length);
1074 ok(arr.toString() === "0,1,2,3", "arr.toString() = " + arr.toString());
1075
1076 arr = new Array(3);
1077 arr[0] = 1;
1078 arr[2] = 3;
1079 tmp = arr.unshift(-1,0);
1080 ok(tmp === (invokeVersion < 2 ? undefined : 5), "unshift returned " +tmp);
1081 ok(arr.length === 5, "arr.length = " + arr.length);
1082 ok(arr.toString() === "-1,0,1,,3", "arr.toString() = " + arr.toString());
1083
1084 arr = [1,2,3];
1085 tmp = arr.unshift();
1086 ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
1087 ok(arr.length === 3, "arr.length = " + arr.length);
1088 ok(arr.toString() === "1,2,3", "arr.toString() = " + arr.toString());
1089
1090 arr = new Object();
1091 arr.length = 2;
1092 arr[0] = 1;
1093 arr[1] = 2;
1094 tmp = Array.prototype.unshift.call(arr, 0);
1095 ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
1096 ok(arr.length === 3, "arr.length = " + arr.length);
1097 ok(arr[0] === 0 && arr[1] === 1 && arr[2] === 2, "unexpected array");
1098
1099 arr = [1,2,,4];
1100 tmp = arr.shift();
1101 ok(tmp === 1, "[1,2,,4].shift() = " + tmp);
1102 ok(arr.toString() === "2,,4", "arr = " + arr.toString());
1103
1104 arr = [];
1105 tmp = arr.shift();
1106 ok(tmp === undefined, "[].shift() = " + tmp);
1107 ok(arr.toString() === "", "arr = " + arr.toString());
1108
1109 arr = [1,2,,4];
1110 tmp = arr.shift(2);
1111 ok(tmp === 1, "[1,2,,4].shift(2) = " + tmp);
1112 ok(arr.toString() === "2,,4", "arr = " + arr.toString());
1113
1114 arr = [1,];
1115 tmp = arr.shift();
1116 ok(tmp === 1, "[1,].shift() = " + tmp);
1117 ok(arr.toString() === "", "arr = " + arr.toString());
1118
1119 obj = new Object();
1120 obj[0] = "test";
1121 obj[2] = 3;
1122 obj.length = 3;
1123 tmp = Array.prototype.shift.call(obj);
1124 ok(tmp === "test", "obj.shift() = " + tmp);
1125 ok(obj.length == 2, "obj.length = " + obj.length);
1126 ok(obj[1] === 3, "obj[1] = " + obj[1]);
1127
1128 var num = new Number(6);
1129 arr = [0,1,2];
1130 tmp = arr.concat(3, [4,5], num);
1131 ok(tmp !== arr, "tmp === arr");
1132 for(var i=0; i<6; i++)
1133 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
1134 ok(tmp[6] === num, "tmp[6] !== num");
1135 ok(tmp.length === 7, "tmp.length = " + tmp.length);
1136
1137 arr = [].concat();
1138 ok(arr.length === 0, "arr.length = " + arr.length);
1139
1140 arr = [1,];
1141 tmp = arr.concat([2]);
1142 ok(tmp.length === 3, "tmp.length = " + tmp.length);
1143 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
1144
1145 arr = [1,false,'a',null,undefined,'a'];
1146 ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6));
1147 ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length);
1148 ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice());
1149 ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc"));
1150 ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8));
1151 ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length);
1152 ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1));
1153 ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2));
1154 ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1));
1155 tmp = arr.slice(0,6);
1156 for(var i=0; i < arr.length; i++)
1157 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
1158 arr[12] = 2;
1159 ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString());
1160 ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length);
1161
1162 arr = [1,2,3,4,5];
1163 tmp = arr.splice(2,2);
1164 ok(tmp.toString() == "3,4", "arr.splice(2,2) returned " + tmp.toString());
1165 ok(arr.toString() == "1,2,5", "arr.splice(2,2) is " + arr.toString());
1166
1167 arr = [1,2,3,4,5];
1168 tmp = arr.splice(2,2,"a");
1169 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a') returned " + tmp.toString());
1170 ok(arr.toString() == "1,2,a,5", "arr.splice(2,2,'a') is " + arr.toString());
1171
1172 arr = [1,2,3,4,5];
1173 tmp = arr.splice(2,2,'a','b','c');
1174 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
1175 ok(arr.toString() == "1,2,a,b,c,5", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1176
1177 arr = [1,2,3,4,];
1178 tmp = arr.splice(2,2,'a','b','c');
1179 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
1180 ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1181
1182 arr = [1,2,3,4,];
1183 arr.splice(2,2,'a','b','c');
1184 ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1185
1186 arr = [1,2,3,4,5];
1187 tmp = arr.splice(2,2,'a','b');
1188 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b') returned " + tmp.toString());
1189 ok(arr.toString() == "1,2,a,b,5", "arr.splice(2,2,'a','b') is " + arr.toString());
1190
1191 arr = [1,2,3,4,5];
1192 tmp = arr.splice(-1,2);
1193 ok(tmp.toString() == "5", "arr.splice(-1,2) returned " + tmp.toString());
1194 ok(arr.toString() == "1,2,3,4", "arr.splice(-1,2) is " + arr.toString());
1195
1196 arr = [1,2,3,4,5];
1197 tmp = arr.splice(-10,3);
1198 ok(tmp.toString() == "1,2,3", "arr.splice(-10,3) returned " + tmp.toString());
1199 ok(arr.toString() == "4,5", "arr.splice(-10,3) is " + arr.toString());
1200
1201 arr = [1,2,3,4,5];
1202 tmp = arr.splice(-10,100);
1203 ok(tmp.toString() == "1,2,3,4,5", "arr.splice(-10,100) returned " + tmp.toString());
1204 ok(arr.toString() == "", "arr.splice(-10,100) is " + arr.toString());
1205
1206 arr = [1,2,3,4,5];
1207 tmp = arr.splice(2,-1);
1208 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1209 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1210
1211 arr = [1,2,3,4,5];
1212 tmp = arr.splice(2);
1213 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1214 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1215
1216 arr = [1,2,3,4,5];
1217 tmp = arr.splice();
1218 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1219 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1220
1221 arr = [1,2,3,4,5];
1222 tmp = arr.splice(bigInt);
1223 ok(tmp.toString() == "", "arr.splice(bigInt) returned " + tmp.toString());
1224 ok(arr.toString() == "1,2,3,4,5", "arr.splice(bigInt) is " + arr.toString());
1225
1226 arr = [1,2,3,4,5];
1227 tmp = arr.splice(-bigInt);
1228 ok(tmp.toString() == "", "arr.splice(-bigInt) returned " + tmp.toString());
1229 ok(arr.toString() == "1,2,3,4,5", "arr.splice(-bigInt) is " + arr.toString());
1230
1231 if(invokeVersion >= 2) {
1232 arr = [1,2,3,4,5];
1233 tmp = arr.splice(2, bigInt);
1234 ok(tmp.toString() == "3,4,5", "arr.splice(2, bigInt) returned " + tmp.toString());
1235 ok(arr.toString() == "1,2", "arr.splice(2, bigInt) is " + arr.toString());
1236 }
1237
1238 arr = [1,2,3,4,5];
1239 tmp = arr.splice(2, -bigInt);
1240 ok(tmp.toString() == "", "arr.splice(2, -bigInt) returned " + tmp.toString());
1241 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2, -bigInt) is " + arr.toString());
1242
1243 obj = new Object();
1244 obj.length = 3;
1245 obj[0] = 1;
1246 obj[1] = 2;
1247 obj[2] = 3;
1248 tmp = Array.prototype.splice.call(obj, 1, 1, 'a', 'b');
1249 ok(tmp.toString() === "2", "obj.splice returned " + tmp);
1250 ok(obj.length === 4, "obj.length = " + obj.length);
1251 ok(obj[0] === 1, "obj[0] = " + obj[0]);
1252 ok(obj[1] === 'a', "obj[1] = " + obj[1]);
1253 ok(obj[2] === 'b', "obj[2] = " + obj[2]);
1254 ok(obj[3] === 3, "obj[3] = " + obj[3]);
1255
1256 obj = new Object();
1257 obj.length = 3;
1258 obj[0] = 1;
1259 obj[1] = 2;
1260 obj[2] = 3;
1261 tmp = Array.prototype.slice.call(obj, 1, 2);
1262 ok(tmp.length === 1, "tmp.length = " + tmp.length);
1263 ok(tmp[0] === 2, "tmp[0] = " + tmp[0]);
1264
1265 tmp = (new Number(2)).toString();
1266 ok(tmp === "2", "num(2).toString = " + tmp);
1267 tmp = (new Number()).toString();
1268 ok(tmp === "0", "num().toString = " + tmp);
1269 tmp = (new Number(5.5)).toString(2);
1270 ok(tmp === "101.1", "num(5.5).toString(2) = " + tmp);
1271
1272 tmp = (new Number(3)).toFixed(3);
1273 ok(tmp === "3.000", "num(3).toFixed(3) = " + tmp);
1274 tmp = (new Number(3)).toFixed();
1275 ok(tmp === "3", "Number(3).toFixed() = " + tmp);
1276 tmp = (new Number(0)).toFixed();
1277 ok(tmp === "0", "Number(0).toFixed() = " + tmp);
1278 tmp = (new Number(0)).toFixed(1);
1279 ok(tmp === "0.0", "Number(0).toFixed(1) = " + tmp);
1280 tmp = (new Number(0)).toFixed(2);
1281 ok(tmp === "0.00", "Number(0).toFixed(2) = " + tmp);
1282 tmp = (new Number(1.76)).toFixed(1);
1283 ok(tmp === "1.8", "num(1.76).toFixed(1) = " + tmp);
1284 tmp = (new Number(7.92)).toFixed(5);
1285 ok(tmp === "7.92000", "num(7.92).toFixed(5) = " + tmp);
1286 tmp = (new Number(2.88)).toFixed();
1287 ok(tmp === "3", "num(2.88).toFixed = " + tmp);
1288 tmp = (new Number(-2.5)).toFixed();
1289 ok(tmp === "-3", "num(-2.5).toFixed = " + tmp);
1290 tmp = (new Number(1000000000000000128)).toFixed(0);
1291 //todo_wine ok(tmp === "1000000000000000100", "num(1000000000000000128) = " + tmp);
1292 tmp = (new Number(3.14).toFixed(NaN));
1293 ok(tmp === "3", "num(3.14).toFixed = " + tmp);
1294 tmp = (new Number(0.95).toFixed(1));
1295 ok(tmp === "1.0", "num(0.95).toFixed(1) = " + tmp);
1296 tmp = (new Number(1e900)).toFixed(0);
1297 ok(tmp === "Infinity", "num(1000000000000000128) = " + tmp);
1298 tmp = (new Number(0.12345678901234567890123)).toFixed(20);
1299 ok(tmp === "0.12345678901234568000", "num(0.12345678901234567890123) = " + tmp);
1300
1301 tmp = (new Number(2)).toExponential(3);
1302 ok(tmp === "2.000e+0", "num(2).toExponential(3) = " + tmp);
1303 tmp = (new Number(1.17e-32)).toExponential(20);
1304 ok(tmp === "1.17000000000000000000e-32", "num(1.17e-32).toExponential(20) = " + tmp);
1305 tmp = (new Number(0)).toExponential(7);
1306 ok(tmp === "0.0000000e+0", "num(0).toExponential(7) = " + tmp);
1307 tmp = (new Number(0)).toExponential(0);
1308 ok(tmp === "0e+0", "num(0).toExponential() = " + tmp);
1309 tmp = (new Number(-13.7567)).toExponential();
1310 ok(tmp === "-1.37567e+1", "num(-13.7567).toExponential() = " + tmp);
1311 tmp = (new Number(-32.1)).toExponential();
1312 ok(tmp === "-3.21e+1", "num(-32.1).toExponential() = " + tmp);
1313 tmp = (new Number(4723.4235)).toExponential();
1314 ok(tmp === "4.7234235e+3", "num(4723.4235).toExponential() = " + tmp);
1315
1316 tmp = (new Number(5)).toPrecision(12);
1317 ok(tmp == "5.00000000000", "num(5).toPrecision(12) = " + tmp);
1318 tmp = (new Number(7.73)).toPrecision(7);
1319 ok(tmp == "7.730000", "num(7.73).toPrecision(7) = " + tmp);
1320 tmp = (new Number(-127547.47472)).toPrecision(17);
1321 ok(tmp == "-127547.47472000000", "num(-127547.47472).toPrecision(17) = " + tmp);
1322 tmp = (new Number(0)).toPrecision(3);
1323 ok(tmp == "0.00", "num(0).toPrecision(3) = " + tmp);
1324 tmp = (new Number(42345.52342465464562334)).toPrecision(15);
1325 ok(tmp == "42345.5234246546", "num(42345.52342465464562334).toPrecision(15) = " + tmp);
1326 tmp = (new Number(1.182e30)).toPrecision(5);
1327 ok(tmp == "1.1820e+30", "num(1.182e30)).toPrecision(5) = " + tmp);
1328 tmp = (new Number(1.123)).toPrecision();
1329 ok(tmp == "1.123", "num(1.123).toPrecision() = " + tmp);
1330
1331 ok(Number() === 0, "Number() = " + Number());
1332 ok(Number(false) === 0, "Number(false) = " + Number(false));
1333 ok(Number("43") === 43, "Number('43') = " + Number("43"));
1334
1335 tmp = (new Number(1)).valueOf();
1336 ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
1337 tmp = (new Number(1,2)).valueOf();
1338 ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
1339 tmp = (new Number()).valueOf();
1340 ok(tmp === 0, "(new Number()).valueOf = " + tmp);
1341 tmp = Number.prototype.valueOf();
1342 ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
1343
1344 function equals(val, base) {
1345 var i;
1346 var num = 0;
1347 var str = val.toString(base);
1348
1349 for(i=0; i<str.length; i++) {
1350 if(str.substring(i, i+1) == '(') break;
1351 if(str.substring(i, i+1) == '.') break;
1352 num = num*base + parseInt(str.substring(i, i+1));
1353 }
1354
1355 if(str.substring(i, i+1) == '.') {
1356 var mult = base;
1357 for(i++; i<str.length; i++) {
1358 if(str.substring(i, i+1) == '(') break;
1359 num += parseInt(str.substring(i, i+1))/mult;
1360 mult *= base;
1361 }
1362 }
1363
1364 if(str.substring(i, i+1) == '(') {
1365 exp = parseInt(str.substring(i+2));
1366 num *= Math.pow(base, exp);
1367 }
1368
1369 ok(num>val-val/1000 && num<val+val/1000, "equals: num = " + num);
1370 }
1371
1372 ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11));
1373 ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17));
1374 ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33));
1375 ok((NaN).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN).toString(11));
1376 ok((Infinity).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity).toString(11));
1377 for(i=2; i<10; i++) {
1378 equals(1.123, i);
1379 equals(2305843009200000000, i);
1380 equals(5.123, i);
1381 equals(21711, i);
1382 equals(1024*1024*1024*1024*1024*1024*1.9999, i);
1383 equals(748382, i);
1384 equals(0.6, i);
1385 equals(4.65661287308e-10, i);
1386 ok((0).toString(i) === "0", "(0).toString("+i+") = " + (0).toString(i));
1387 }
1388
1389 ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123'));
1390 ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7'));
1391 ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2'));
1392 ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5'));
1393 ok(parseFloat('1E5 not parsed') === 1E5, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed'));
1394 ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
1395 ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
1396 ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
1397 ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
1398
1399 tmp = Math.min(1);
1400 ok(tmp === 1, "Math.min(1) = " + tmp);
1401
1402 tmp = Math.min(1, false);
1403 ok(tmp === 0, "Math.min(1, false) = " + tmp);
1404
1405 tmp = Math.min();
1406 ok(tmp === Infinity, "Math.min() = " + tmp);
1407
1408 tmp = Math.min(1, NaN, -Infinity, false);
1409 ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
1410
1411 tmp = Math.min(1, false, true, null, -3);
1412 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
1413
1414 tmp = Math.max(1);
1415 ok(tmp === 1, "Math.max(1) = " + tmp);
1416
1417 tmp = Math.max(true, 0);
1418 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
1419
1420 tmp = Math.max(-2, false, true, null, 1);
1421 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
1422
1423 tmp = Math.max();
1424 ok(tmp === -Infinity, "Math.max() = " + tmp);
1425
1426 tmp = Math.max(true, NaN, 0);
1427 ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
1428
1429 tmp = Math.round(0.5);
1430 ok(tmp === 1, "Math.round(0.5) = " + tmp);
1431
1432 tmp = Math.round(-0.5);
1433 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
1434
1435 tmp = Math.round(1.1);
1436 ok(tmp === 1, "Math.round(1.1) = " + tmp);
1437
1438 tmp = Math.round(true);
1439 ok(tmp === 1, "Math.round(true) = " + tmp);
1440
1441 tmp = Math.round(1.1, 3, 4);
1442 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
1443
1444 tmp = Math.round();
1445 ok(isNaN(tmp), "Math.round() is not NaN");
1446
1447 tmp = Math.ceil(0.5);
1448 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
1449
1450 tmp = Math.ceil(-0.5);
1451 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
1452
1453 tmp = Math.ceil(1.1);
1454 ok(tmp === 2, "Math.round(1.1) = " + tmp);
1455
1456 tmp = Math.ceil(true);
1457 ok(tmp === 1, "Math.ceil(true) = " + tmp);
1458
1459 tmp = Math.ceil(1.1, 3, 4);
1460 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
1461
1462 tmp = Math.ceil();
1463 ok(isNaN(tmp), "ceil() is not NaN");
1464
1465 tmp = Math.floor(0.5);
1466 ok(tmp === 0, "Math.floor(0.5) = " + tmp);
1467
1468 tmp = Math.floor(-0.5);
1469 ok(tmp === -1, "Math.floor(-0.5) = " + tmp);
1470
1471 tmp = Math.floor(1.1);
1472 ok(tmp === 1, "Math.floor(1.1) = " + tmp);
1473
1474 tmp = Math.floor(true);
1475 ok(tmp === 1, "Math.floor(true) = " + tmp);
1476
1477 tmp = Math.floor(1.1, 3, 4);
1478 ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp);
1479
1480 tmp = Math.floor();
1481 ok(isNaN(tmp), "floor is not NaN");
1482
1483 tmp = Math.abs(3);
1484 ok(tmp === 3, "Math.abs(3) = " + tmp);
1485
1486 tmp = Math.abs(-3);
1487 ok(tmp === 3, "Math.abs(-3) = " + tmp);
1488
1489 tmp = Math.abs(true);
1490 ok(tmp === 1, "Math.abs(true) = " + tmp);
1491
1492 tmp = Math.abs();
1493 ok(isNaN(tmp), "Math.abs() is not NaN");
1494
1495 tmp = Math.abs(NaN);
1496 ok(isNaN(tmp), "Math.abs() is not NaN");
1497
1498 tmp = Math.abs(-Infinity);
1499 ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp);
1500
1501 tmp = Math.abs(-3, 2);
1502 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
1503
1504 tmp = Math.cos(0);
1505 ok(tmp === 1, "Math.cos(0) = " + tmp);
1506
1507 tmp = Math.cos(Math.PI/2);
1508 ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp);
1509
1510 tmp = Math.cos(-Math.PI/2);
1511 ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp);
1512
1513 tmp = Math.cos(Math.PI/3, 2);
1514 ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp);
1515
1516 tmp = Math.cos(true);
1517 ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp);
1518
1519 tmp = Math.cos(false);
1520 ok(tmp === 1, "Math.cos(false) = " + tmp);
1521
1522 tmp = Math.cos();
1523 ok(isNaN(tmp), "Math.cos() is not NaN");
1524
1525 tmp = Math.cos(NaN);
1526 ok(isNaN(tmp), "Math.cos(NaN) is not NaN");
1527
1528 tmp = Math.cos(Infinity);
1529 ok(isNaN(tmp), "Math.cos(Infinity) is not NaN");
1530
1531 tmp = Math.cos(-Infinity);
1532 ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN");
1533
1534 tmp = Math.pow(2, 2);
1535 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
1536
1537 tmp = Math.pow(4, 0.5);
1538 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
1539
1540 tmp = Math.pow(2, 2, 3);
1541 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
1542
1543 tmp = Math.pow(2);
1544 ok(isNaN(tmp), "Math.pow(2) is not NaN");
1545
1546 tmp = Math.pow();
1547 ok(isNaN(tmp), "Math.pow() is not NaN");
1548
1549 tmp = Math.random();
1550 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
1551 ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp);
1552
1553 tmp = Math.random(100);
1554 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
1555 ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp);
1556
1557 tmp = Math.acos(0);
1558 ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp);
1559
1560 tmp = Math.acos(1);
1561 ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp);
1562
1563 tmp = Math.acos(-1);
1564 ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp);
1565
1566 tmp = Math.acos(Math.PI/4, 2);
1567 ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp);
1568
1569 tmp = Math.acos(true);
1570 ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp);
1571
1572 tmp = Math.acos(false);
1573 ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp);
1574
1575 tmp = Math.acos(1.1);
1576 ok(isNaN(tmp), "Math.acos(1.1) is not NaN");
1577
1578 tmp = Math.acos();
1579 ok(isNaN(tmp), "Math.acos() is not NaN");
1580
1581 tmp = Math.acos(NaN);
1582 ok(isNaN(tmp), "Math.acos(NaN) is not NaN");
1583
1584 tmp = Math.acos(Infinity);
1585 ok(isNaN(tmp), "Math.acos(Infinity) is not NaN");
1586
1587 tmp = Math.acos(-Infinity);
1588 ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN");
1589
1590 tmp = Math.asin(0);
1591 ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp);
1592
1593 tmp = Math.asin(1);
1594 ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp);
1595
1596 tmp = Math.asin(-1);
1597 ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp);
1598
1599 tmp = Math.asin(Math.PI/4, 2);
1600 ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp);
1601
1602 tmp = Math.asin(true);
1603 ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp);
1604
1605 tmp = Math.asin(false);
1606 ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp);
1607
1608 tmp = Math.asin(1.1);
1609 ok(isNaN(tmp), "Math.asin(1.1) is not NaN");
1610
1611 tmp = Math.asin();
1612 ok(isNaN(tmp), "Math.asin() is not NaN");
1613
1614 tmp = Math.asin(NaN);
1615 ok(isNaN(tmp), "Math.asin(NaN) is not NaN");
1616
1617 tmp = Math.asin(Infinity);
1618 ok(isNaN(tmp), "Math.asin(Infinity) is not NaN");
1619
1620 tmp = Math.asin(-Infinity);
1621 ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN");
1622
1623 tmp = Math.atan(0);
1624 ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp);
1625
1626 tmp = Math.atan(1);
1627 ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp);
1628
1629 tmp = Math.atan(-1);
1630 ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp);
1631
1632 tmp = Math.atan(true);
1633 ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp);
1634
1635 tmp = Math.atan(false);
1636 ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp);
1637
1638 tmp = Math.atan();
1639 ok(isNaN(tmp), "Math.atan() is not NaN");
1640
1641 tmp = Math.atan(NaN);
1642 ok(isNaN(tmp), "Math.atan(NaN) is not NaN");
1643
1644 tmp = Math.atan(Infinity);
1645 ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp);
1646
1647 tmp = Math.atan(-Infinity);
1648 ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp);
1649
1650 tmp = Math.atan2(0, 0);
1651 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp);
1652
1653 tmp = Math.atan2(0, 1);
1654 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp);
1655
1656 tmp = Math.atan2(0, Infinity);
1657 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp);
1658
1659 tmp = Math.atan2(0, -1);
1660 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp);
1661
1662 tmp = Math.atan2(0, -Infinity);
1663 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp);
1664
1665 tmp = Math.atan2(1, 0);
1666 ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp);
1667
1668 tmp = Math.atan2(Infinity, 0);
1669 ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp);
1670
1671 tmp = Math.atan2(-1, 0);
1672 ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp);
1673
1674 tmp = Math.atan2(-Infinity, 0);
1675 ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp);
1676
1677 tmp = Math.atan2(1, 1);
1678 ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp);
1679
1680 tmp = Math.atan2(-1, -1);
1681 ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp);
1682
1683 tmp = Math.atan2(-1, 1);
1684 ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp);
1685
1686 tmp = Math.atan2(Infinity, Infinity);
1687 ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp);
1688
1689 tmp = Math.atan2(Infinity, -Infinity, 1);
1690 ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp);
1691
1692 tmp = Math.atan2();
1693 ok(isNaN(tmp), "Math.atan2() is not NaN");
1694
1695 tmp = Math.atan2(1);
1696 ok(isNaN(tmp), "Math.atan2(1) is not NaN");
1697
1698 tmp = Math.exp(0);
1699 ok(tmp === 1, "Math.exp(0) = " + tmp);
1700
1701 tmp = Math.exp(1);
1702 ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp);
1703
1704 tmp = Math.exp(-1);
1705 ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp);
1706
1707 tmp = Math.exp(true);
1708 ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp);
1709
1710 tmp = Math.exp(1, 1);
1711 ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp);
1712
1713 tmp = Math.exp();
1714 ok(isNaN(tmp), "Math.exp() is not NaN");
1715
1716 tmp = Math.exp(NaN);
1717 ok(isNaN(tmp), "Math.exp(NaN) is not NaN");
1718
1719 tmp = Math.exp(Infinity);
1720 ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp);
1721
1722 tmp = Math.exp(-Infinity);
1723 ok(tmp === 0, "Math.exp(-Infinity) = " + tmp);
1724
1725 tmp = Math.log(1);
1726 ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp);
1727
1728 tmp = Math.log(-1);
1729 ok(isNaN(tmp), "Math.log(-1) is not NaN");
1730
1731 tmp = Math.log(true);
1732 ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp);
1733
1734 tmp = Math.log(1, 1);
1735 ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp);
1736
1737 tmp = Math.log();
1738 ok(isNaN(tmp), "Math.log() is not NaN");
1739
1740 tmp = Math.log(NaN);
1741 ok(isNaN(tmp), "Math.log(NaN) is not NaN");
1742
1743 tmp = Math.log(Infinity);
1744 ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
1745
1746 tmp = Math.log(-Infinity);
1747 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
1748
1749 tmp = Math.sin(0);
1750 ok(tmp === 0, "Math.sin(0) = " + tmp);
1751
1752 tmp = Math.sin(Math.PI/2);
1753 ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
1754
1755 tmp = Math.sin(-Math.PI/2);
1756 ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
1757
1758 tmp = Math.sin(Math.PI/3, 2);
1759 ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
1760
1761 tmp = Math.sin(true);
1762 ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
1763
1764 tmp = Math.sin(false);
1765 ok(tmp === 0, "Math.sin(false) = " + tmp);
1766
1767 tmp = Math.sin();
1768 ok(isNaN(tmp), "Math.sin() is not NaN");
1769
1770 tmp = Math.sin(NaN);
1771 ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
1772
1773 tmp = Math.sin(Infinity);
1774 ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
1775
1776 tmp = Math.sin(-Infinity);
1777 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
1778
1779 tmp = Math.sqrt(0);
1780 ok(tmp === 0, "Math.sqrt(0) = " + tmp);
1781
1782 tmp = Math.sqrt(4);
1783 ok(tmp === 2, "Math.sqrt(4) = " + tmp);
1784
1785 tmp = Math.sqrt(-1);
1786 ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
1787
1788 tmp = Math.sqrt(2, 2);
1789 ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
1790
1791 tmp = Math.sqrt(true);
1792 ok(tmp === 1, "Math.sqrt(true) = " + tmp);
1793
1794 tmp = Math.sqrt(false);
1795 ok(tmp === 0, "Math.sqrt(false) = " + tmp);
1796
1797 tmp = Math.sqrt();
1798 ok(isNaN(tmp), "Math.sqrt() is not NaN");
1799
1800 tmp = Math.sqrt(NaN);
1801 ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
1802
1803 tmp = Math.sqrt(Infinity);
1804 ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
1805
1806 tmp = Math.sqrt(-Infinity);
1807 ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
1808
1809 tmp = Math.tan(0);
1810 ok(tmp === 0, "Math.tan(0) = " + tmp);
1811
1812 tmp = Math.tan(Math.PI);
1813 ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp);
1814
1815 tmp = Math.tan(2, 2);
1816 ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp);
1817
1818 tmp = Math.tan(true);
1819 ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp);
1820
1821 tmp = Math.tan(false);
1822 ok(tmp === 0, "Math.tan(false) = " + tmp);
1823
1824 tmp = Math.tan();
1825 ok(isNaN(tmp), "Math.tan() is not NaN");
1826
1827 tmp = Math.tan(NaN);
1828 ok(isNaN(tmp), "Math.tan(NaN) is not NaN");
1829
1830 tmp = Math.tan(Infinity);
1831 ok(isNaN(tmp), "Math.tan(Infinity) is not NaN");
1832
1833 tmp = Math.tan(-Infinity);
1834 ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
1835
1836 (function() {
1837 if(invokeVersion < 2)
1838 return;
1839
1840 var stringify_tests = [
1841 [[], undefined],
1842 [[true], "true"],
1843 [[false], "false"],
1844 [[null], "null"],
1845 [[1], "1"],
1846 [["test"], "\"test\""],
1847 [["test\"\\\b\f\n\r\t\u0002 !"], "\"test\\\"\\\\\\b\\f\\n\\r\\t\\u0002 !\""],
1848 [[NaN], "null"],
1849 [[Infinity], "null"],
1850 [[-Infinity], "null"],
1851 [[{prop1: true, prop2: "string"}], "{\"prop1\":true,\"prop2\":\"string\"}"],
1852 [[{prop1: true, prop2: testObj, prop3: undefined}], "{\"prop1\":true}"],
1853 [[{prop1: true, prop2: {prop: "string"}},undefined," "],
1854 "{\n \"prop1\": true,\n \"prop2\": {\n \"prop\": \"string\"\n }\n}"],
1855 [[{ },undefined," "], "{}"],
1856 [[[,2,undefined,3,{ },]],"[null,2,null,3,{},null]"],
1857 [[[,2,undefined,3,{prop:0},],undefined," "],"[\n null,\n 2,\n null,\n 3,\n {\n \"prop\": 0\n },\n null\n]"]
1858 ];
1859
1860 var i, s, v;
1861
1862 for(i=0; i < stringify_tests.length; i++) {
1863 s = JSON.stringify.apply(null, stringify_tests[i][0]);
1864 ok(s === stringify_tests[i][1],
1865 "["+i+"] stringify(" + stringify_tests[i][0] + ") returned " + s + " expected " + stringify_tests[i][1]);
1866 }
1867
1868 s = JSON.stringify();
1869 ok(s === undefined, "stringify() returned " + s + " expected undefined");
1870
1871 s = JSON.stringify(testObj);
1872 ok(s === undefined || s === "undefined" /* broken on some old versions */,
1873 "stringify(testObj) returned " + s + " expected undfined");
1874
1875 s = JSON.stringify(undefined);
1876 ok(s === undefined || s === "undefined" /* broken on some old versions */,
1877 "stringify(undefined) returned " + s + " expected undfined");
1878
1879 var parse_tests = [
1880 ["true", true],
1881 [" \nnull ", null],
1882 ["{}", {}],
1883 ["\"\\r\\n test\\u1111\"", "\r\n test\u1111"],
1884 ["{\"x\" :\n true}", {x:true}],
1885 ["{\"x y\": {}, \"z\": {\"x\":null}}", {"x y":{}, z:{x:null}}],
1886 ["[]", []],
1887 ["[false,{},{\"x\": []}]", [false,{},{x:[]}]],
1888 ["0", 0],
1889 ["- 1", -1],
1890 ["1e2147483648", Infinity]
1891 ];
1892
1893 function json_cmp(x, y) {
1894 if(x === y)
1895 return true;
1896
1897 if(!(x instanceof Object) || !(y instanceof Object))
1898 return false;
1899
1900 for(var prop in x) {
1901 if(!x.hasOwnProperty(prop))
1902 continue;
1903 if(!x.hasOwnProperty(prop))
1904 return false;
1905 if(!json_cmp(x[prop], y[prop]))
1906 return false;
1907 }
1908
1909 for(var prop in y) {
1910 if(!x.hasOwnProperty(prop) && y.hasOwnProperty(prop))
1911 return false;
1912 }
1913
1914 return true;
1915 }
1916
1917 for(i=0; i < parse_tests.length; i++) {
1918 v = JSON.parse(parse_tests[i][0]);
1919 ok(json_cmp(v, parse_tests[i][1]), "parse[" + i + "] returned " + v + ", expected " + parse_tests[i][1]);
1920 }
1921 })();
1922
1923 var func = function (a) {
1924 var a = 1;
1925 if(a) return;
1926 };
1927 ok(func.toString() === "function (a) {\n var a = 1;\n if(a) return;\n }",
1928 "func.toString() = " + func.toString());
1929 ok("" + func === "function (a) {\n var a = 1;\n if(a) return;\n }",
1930 "'' + func.toString() = " + func);
1931
1932 ok(func.valueOf === Object.prototype.valueOf, "func.valueOf !== Object.prototype.valueOf");
1933 ok(func === func.valueOf(), "func !== func.valueOf()");
1934
1935 function testFuncToString(x,y) {
1936 return x+y;
1937 }
1938 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n return x+y;\n}",
1939 "testFuncToString.toString() = " + testFuncToString.toString());
1940 ok("" + testFuncToString === "function testFuncToString(x,y) {\n return x+y;\n}",
1941 "'' + testFuncToString = " + testFuncToString);
1942
1943 tmp = new Object();
1944
1945 function callTest(argc) {
1946 ok(this === tmp, "this !== tmp\n");
1947 ok(arguments.length === argc+1, "arguments.length = " + arguments.length + " expected " + (argc+1));
1948 for(var i=1; i <= argc; i++)
1949 ok(arguments[i] === i, "arguments[i] = " + arguments[i]);
1950 var a = arguments;
1951 for(var i=1; i <= argc; i++)
1952 ok(a[i] === i, "a[i] = " + a[i]);
1953 }
1954
1955 callTest.call(tmp, 1, 1);
1956 callTest.call(tmp, 2, 1, 2);
1957 callTest.call(tmp, 3, 1, 2, 3);
1958
1959 callTest.apply(tmp, [1, 1]);
1960 callTest.apply(tmp, [2, 1, 2]);
1961 callTest.apply(tmp, [3, 1, 2, 3]);
1962 (function () { callTest.apply(tmp, arguments); })(2,1,2);
1963
1964 function callTest2() {
1965 ok(this === tmp, "this !== tmp\n");
1966 ok(arguments.length === 0, "callTest2: arguments.length = " + arguments.length + " expected 0");
1967 }
1968
1969 callTest2.call(tmp);
1970 callTest2.apply(tmp, []);
1971 callTest2.apply(tmp);
1972 (function () { callTest2.apply(tmp, arguments); })();
1973
1974 function callTest3() {
1975 testThis(this);
1976 ok(arguments.length === 0, "arguments.length = " + arguments.length + " expected 0");
1977 }
1978
1979 callTest3.call();
1980 callTest3.call(undefined);
1981 callTest3.call(null);
1982 callTest3.apply();
1983 callTest3.apply(undefined);
1984 callTest3.apply(null);
1985
1986 tmp = Number.prototype.toString.call(3);
1987 ok(tmp === "3", "Number.prototype.toString.call(3) = " + tmp);
1988
1989 var func = new Function("return 3;");
1990
1991 tmp = func();
1992 ok(tmp === 3, "func() = " + tmp);
1993 ok(func.call() === 3, "func.call() = " + tmp);
1994 ok(func.length === 0, "func.length = " + func.length);
1995 tmp = func.toString();
1996 ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp);
1997
1998 func = new Function("x", "return x+2;");
1999 tmp = func(1);
2000 ok(tmp === 3, "func(1) = " + tmp);
2001 tmp = func.toString();
2002 ok(tmp === "function anonymous(x) {\nreturn x+2;\n}", "func.toString() = " + tmp);
2003
2004 tmp = (new Function("x ", "return x+2;")).toString();
2005 ok(tmp === "function anonymous(x ) {\nreturn x+2;\n}", "func.toString() = " + tmp);
2006
2007 func = new Function("x", "y", "return x+y");
2008 tmp = func(1,3);
2009 ok(tmp === 4, "func(1,3) = " + tmp);
2010 tmp = func.toString();
2011 ok(tmp === "function anonymous(x, y) {\nreturn x+y\n}", "func.toString() = " + tmp);
2012
2013 func = new Function(" x, \ty", "\tz", "return x+y+z;");
2014 tmp = func(1,3,2);
2015 ok(tmp === 6, "func(1,3,2) = " + tmp);
2016 ok(func.length === 3, "func.length = " + func.length);
2017 tmp = func.toString();
2018 ok(tmp === "function anonymous( x, \ty, \tz) {\nreturn x+y+z;\n}", "func.toString() = " + tmp);
2019
2020 func = new Function();
2021 tmp = func();
2022 ok(tmp === undefined, "func() = " + tmp);
2023 tmp = func.toString();
2024 ok(tmp == "function anonymous() {\n\n}", "func.toString() = " + tmp);
2025
2026 // Function constructor called as function
2027 func = Function("return 3;");
2028
2029 tmp = func();
2030 ok(tmp === 3, "func() = " + tmp);
2031 ok(func.call() === 3, "func.call() = " + tmp);
2032 ok(func.length === 0, "func.length = " + func.length);
2033 tmp = func.toString();
2034 ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp);
2035
2036 func = (function() {
2037 var tmp = 3;
2038 return new Function("return tmp;");
2039 })();
2040 tmp = 2;
2041 tmp = func();
2042 ok(tmp === 2, "func() = " + tmp);
2043
2044 var date = new Date();
2045
2046 date = new Date(100);
2047 ok(date.getTime() === 100, "date.getTime() = " + date.getTime());
2048 ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime());
2049 date = new Date(8.64e15);
2050 ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime());
2051 date = new Date(8.64e15+1);
2052 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
2053 date = new Date(Infinity);
2054 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
2055 date = new Date("3 July 2009 22:28:00 UTC+0100");
2056 ok(date.getTime() === 1246656480000, "date.getTime() = " + date.getTime());
2057 date = new Date(1984, 11, 29, 13, 51, 24, 120);
2058 ok(date.getFullYear() === 1984, "date.getFullYear() = " + date.getFullYear());
2059 ok(date.getMonth() === 11, "date.getMonth() = " + date.getMonth());
2060 ok(date.getDate() === 29, "date.getDate() = " + date.getDate());
2061 ok(date.getHours() === 13, "date.getHours() = " + date.getHours());
2062 ok(date.getMinutes() === 51, "date.getMinutes() = " + date.getMinutes());
2063 ok(date.getSeconds() === 24, "date.getSeconds() = " + date.getSeconds());
2064 ok(date.getMilliseconds() === 120, "date.getMilliseconds() = " + date.getMilliseconds());
2065 date = new Date(731, -32, 40, -1, 70, 65, -13);
2066 ok(date.getFullYear() === 728, "date.getFullYear() = " + date.getFullYear());
2067 ok(date.getMonth() === 5, "date.getMonth() = " + date.getMonth());
2068 ok(date.getDate() === 9, "date.getDate() = " + date.getDate());
2069 ok(date.getHours() === 0, "date.getHours() = " + date.getHours());
2070 ok(date.getMinutes() === 11, "date.getMinutes() = " + date.getMinutes());
2071 ok(date.getSeconds() === 4, "date.getSeconds() = " + date.getSeconds());
2072 ok(date.getMilliseconds() === 987, "date.getMilliseconds() = " + date.getMilliseconds());
2073
2074 ok(date.setTime(123) === 123, "date.setTime(123) !== 123");
2075 ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123");
2076 ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
2077
2078 ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
2079 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
2080 ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
2081 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
2082 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
2083 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
2084 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
2085 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
2086 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2087
2088 date.setTime(60*24*60*60*1000);
2089 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
2090 ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
2091 ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
2092 ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay());
2093 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
2094 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
2095 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
2096 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2097
2098 date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
2099 ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
2100 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2101 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2102 ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
2103 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
2104 ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours());
2105 ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes());
2106 ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds());
2107 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2108
2109 tmp = date.setYear(96);
2110 ok(date.getYear() === 96, "date.getYear() = " + date.getYear());
2111 ok(date.getFullYear() === 1996, "date.getFullYear() = " + date.getYear());
2112 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2113 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2114 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2115
2116 tmp = date.setYear(2010);
2117 ok(tmp === date.getTime(), "date.setYear(2010) = " + tmp);
2118 ok(date.getYear() === 2010, "date.getYear() = " + date.getYear());
2119 ok(date.getFullYear() === 2010, "date.getFullYear() = " + date.getYear());
2120 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2121 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2122 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2123
2124 date.setTime(Infinity);
2125 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
2126 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
2127 ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
2128 ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN");
2129 ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN");
2130 ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
2131 ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN");
2132 ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN");
2133 ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN");
2134
2135 date.setTime(0);
2136 tmp = date.setYear(NaN);
2137 ok(isNaN(tmp), "date.setYear(NaN) = " + tmp);
2138 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
2139 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
2140
2141 date.setTime(0);
2142 date.setUTCMilliseconds(-10, 2);
2143 ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2144 date.setUTCMilliseconds(10);
2145 ok(date.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2146 date.setUTCSeconds(-10);
2147 ok(date.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date.getUTCSeconds());
2148 date.setUTCMinutes(-10);
2149 ok(date.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date.getUTCMinutes());
2150 date.setUTCHours(-10);
2151 ok(date.getUTCHours() === 14, "date.getUTCHours() = " + date.getUTCHours());
2152 date.setUTCHours(-123);
2153 ok(date.getTime() === -612549990, "date.getTime() = " + date.getTime());
2154 date.setUTCHours(20);
2155 ok(date.getUTCHours() === 20, "date.getUTCHours() = " + date.getUTCHours());
2156 date.setUTCDate(32);
2157 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
2158 date.setUTCMonth(22, 37);
2159 ok(date.getTime() === 60987050010, "date.getTime() = " + date.getTime());
2160 date.setUTCFullYear(83, 21, 321);
2161 ok(date.getTime() === -59464984149990, "date.getTime() = " + date.getTime());
2162 ok(Math.abs(date) === 59464984149990, "Math.abs(date) = " + Math.abs(date));
2163 ok(getVT(date+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date+1));
2164
2165 ok(isNaN(Date.parse()), "Date.parse() is not NaN");
2166 ok(isNaN(Date.parse("")), "Date.parse(\"\") is not NaN");
2167 ok(isNaN(Date.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN");
2168 ok(Date.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date.parse("Jan 20 2009 UTC"));
2169 ok(Date.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date.parse("Jan 20 2009 GMT"));
2170 ok(Date.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date.parse("Jan 20 2009 UTC-0"));
2171 ok(Date.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date.parse("Jan 20 2009 UTC+0000"));
2172 ok(Date.parse("Jan 20 2009 UTC-1") === 1232413200000, "Date.parse(\"Jan 20 2009 UTC-1\") = " + Date.parse("Jan 20 2009 UTC-1"));
2173 ok(Date.parse("Jan 20 2009 UTC+1") === 1232406000000, "Date.parse(\"Jan 20 2009 UTC+1\") = " + Date.parse("Jan 20 2009 UTC+1"));
2174 ok(Date.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date.parse("Ju 13 79 UTC"));
2175 ok(Date.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date.parse("12Au91 UTC"));
2176 ok(Date.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date.parse("7/02/17 UTC"));
2177 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"));
2178 ok(Date.parse("February 31 UTC, 2000 12:31:17 PM") === 952000277000,
2179 "Date.parse(\"February 31 UTC, 2000 12:31:17 PM\") = " + Date.parse("February 31 UTC, 2000 12:31:17 PM"));
2180 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 "));
2181 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"));
2182 ok(Date.parse("1970/01/01") === Date.parse("01/01/1970"), "Date.parse(\"1970/01/01\") = " + Date.parse("1970/01/01"));
2183 ok(Date.parse("71/12/14") === Date.parse("12/14/1971"), "Date.parse(\"71/12/14\") = " + Date.parse("71/12/14"));
2184 ok(Date.parse("Tue, 22 Mar 2016 09:57:55 -0300") === Date.parse("Tue, 22 Mar 2016 09:57:55 GMT-0300"),
2185 "Date.parse(\"Tue, 22 Mar 2016 09:57:55 -0300\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 -0300"));
2186 ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 2016 09:57:55 UTC+0400"),
2187 "Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 +0400"));
2188
2189 tmp = (new Date()).toGMTString();
2190 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2191 tmp = (new Date()).toLocaleDateString();
2192 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2193 tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleDateString();
2194 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2195 tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleString();
2196 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2197 tmp = (new Date()).toLocaleTimeString();
2198 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2199 tmp = (new Date()).toString();
2200 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2201 tmp = (new Date()).toTimeString();
2202 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2203 tmp = (new Date()).toUTCString();
2204 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2205
2206 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
2207 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
2208 Math.PI = "test";
2209 ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI);
2210
2211 ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E));
2212 ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E);
2213 Math.E = "test";
2214 ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E);
2215
2216 ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E));
2217 ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E);
2218 Math.LOG2E = "test";
2219 ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E);
2220
2221 ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E));
2222 ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E);
2223 Math.LOG10E = "test";
2224 ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E);
2225
2226 ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2));
2227 ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2);
2228 Math.LN2 = "test";
2229 ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2);
2230
2231 ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10));
2232 ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10);
2233 Math.LN10 = "test";
2234 ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10);
2235
2236 ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2));
2237 ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2);
2238 Math.SQRT2 = "test";
2239 ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2);
2240
2241 ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2));
2242 ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
2243 Math.SQRT1_2 = "test";
2244 ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);
2245
2246 ok(isNaN.toString() === "\nfunction isNaN() {\n [native code]\n}\n",
2247 "isNaN.toString = '" + isNaN.toString() + "'");
2248 ok(Array.toString() === "\nfunction Array() {\n [native code]\n}\n",
2249 "isNaN.toString = '" + Array.toString() + "'");
2250 ok(Function.toString() === "\nfunction Function() {\n [native code]\n}\n",
2251 "isNaN.toString = '" + Function.toString() + "'");
2252 ok(Function.prototype.toString() === "\nfunction prototype() {\n [native code]\n}\n",
2253 "isNaN.toString = '" + Function.prototype.toString() + "'");
2254 ok("".substr.toString() === "\nfunction substr() {\n [native code]\n}\n",
2255 "''.substr.toString = '" + "".substr.toString() + "'");
2256
2257 var bool = new Boolean();
2258 ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
2259 var bool = new Boolean("false");
2260 ok(bool.toString() === "true", "bool.toString() = " + bool.toString());
2261 ok(bool.valueOf() === Boolean(1), "bool.valueOf() = " + bool.valueOf());
2262 ok(bool.toLocaleString() === bool.toString(), "bool.toLocaleString() = " + bool.toLocaleString());
2263
2264 ok(ActiveXObject instanceof Function, "ActiveXObject is not instance of Function");
2265 ok(ActiveXObject.prototype instanceof Object, "ActiveXObject.prototype is not instance of Object");
2266
2267 ok(Error.prototype !== TypeError.prototype, "Error.prototype === TypeError.prototype");
2268 ok(RangeError.prototype !== TypeError.prototype, "RangeError.prototype === TypeError.prototype");
2269 ok(Error.prototype.toLocaleString === Object.prototype.toLocaleString,
2270 "Error.prototype.toLocaleString !== Object.prototype.toLocaleString");
2271 err = new Error();
2272 ok(err.valueOf === Object.prototype.valueOf, "err.valueOf !== Object.prototype.valueOf");
2273 ok(Error.prototype.name === "Error", "Error.prototype.name = " + Error.prototype.name);
2274 ok(err.name === "Error", "err.name = " + err.name);
2275 EvalError.prototype.message = "test";
2276 ok(EvalError.prototype.message === "test", "EvalError.prototype.message = " + EvalError.prototype.message);
2277 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
2278 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error"), "err.toString() = " + err.toString());
2279 err = new EvalError();
2280 ok(EvalError.prototype.name === "EvalError", "EvalError.prototype.name = " + EvalError.prototype.name);
2281 ok(err.name === "EvalError", "err.name = " + err.name);
2282 ok(err.toString === Error.prototype.toString, "err.toString !== Error.prototype.toString");
2283 ok(err.message === "", "err.message != ''");
2284 err.message = date;
2285 ok(err.message === date, "err.message != date");
2286 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "EvalError: "+err.message),
2287 "err.toString() = " + err.toString());
2288 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
2289 err = new RangeError();
2290 ok(RangeError.prototype.name === "RangeError", "RangeError.prototype.name = " + RangeError.prototype.name);
2291 ok(err.name === "RangeError", "err.name = " + err.name);
2292 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "RangeError"), "err.toString() = " + err.toString());
2293 err = new ReferenceError();
2294 ok(ReferenceError.prototype.name === "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError.prototype.name);
2295 ok(err.name === "ReferenceError", "err.name = " + err.name);
2296 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "ReferenceError"), "err.toString() = " + err.toString());
2297 err = new SyntaxError();
2298 ok(SyntaxError.prototype.name === "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError.prototype.name);
2299 ok(err.name === "SyntaxError", "err.name = " + err.name);
2300 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "SyntaxError"), "err.toString() = " + err.toString());
2301 err = new TypeError();
2302 ok(TypeError.prototype.name === "TypeError", "TypeError.prototype.name = " + TypeError.prototype.name);
2303 ok(err.name === "TypeError", "err.name = " + err.name);
2304 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "TypeError"), "err.toString() = " + err.toString());
2305 err = new URIError();
2306 ok(URIError.prototype.name === "URIError", "URIError.prototype.name = " + URIError.prototype.name);
2307 ok(err.name === "URIError", "err.name = " + err.name);
2308 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "URIError"), "err.toString() = " + err.toString());
2309 err = new Error("message");
2310 ok(err.message === "message", "err.message !== 'message'");
2311 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error: message"), "err.toString() = " + err.toString());
2312 err = new Error(123);
2313 ok(err.number === 123, "err.number = " + err.number);
2314 err.number = 254;
2315 ok(err.number === 254, "err.number = " + err.number);
2316 err = new Error(0, "message");
2317 ok(err.number === 0, "err.number = " + err.number);
2318 ok(err.message === "message", "err.message = " + err.message);
2319 ok(err.description === "message", "err.description = " + err.description);
2320 err = new Error();
2321 ok(err.number === 0, "err.number = " + err.number);
2322 ok(err.description === "", "err.description = " + err.description);
2323 err.description = 5;
2324 ok(err.description === 5, "err.description = " + err.description);
2325 ok(err.message === "", "err.message = " + err.message);
2326 err.message = 4;
2327 ok(err.message === 4, "err.message = " + err.message);
2328
2329 ok(!("number" in Error), "number is in Error");
2330
2331 tmp = new Object();
2332 ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited");
2333 tmp.toString = function() { return "test"; };
2334 ok(tmp.hasOwnProperty("toString") === true, "toString own property should exist");
2335 ok(tmp.hasOwnProperty("nonExisting") === false, "nonExisting property should not exist");
2336
2337 tmp = Error.prototype.toString.call(tmp);
2338 ok(tmp === "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp);
2339
2340 tmp = function() { return 0; };
2341 tmp[0] = true;
2342 ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited");
2343 ok(tmp.hasOwnProperty("0") === true, "hasOwnProperty(0) returned false");
2344 ok(tmp.hasOwnProperty() === false, "hasOwnProperty() returned true");
2345
2346 ok(Object.prototype.hasOwnProperty.call(testObj) === false, "hasOwnProperty without name returned true");
2347
2348 if(invokeVersion >= 2) {
2349 obj = new Object();
2350 obj.name = "test";
2351 tmp = Error.prototype.toString.call(obj);
2352 ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2353
2354 obj = new Object();
2355 obj.name = 6;
2356 obj.message = false;
2357 tmp = Error.prototype.toString.call(obj);
2358 ok(tmp === "6: false", "Error.prototype.toString.call(obj) = " + tmp);
2359
2360 obj = new Object();
2361 obj.message = "test";
2362 tmp = Error.prototype.toString.call(obj);
2363 ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2364
2365 obj = new Object();
2366 obj.name = "";
2367 obj.message = "test";
2368 tmp = Error.prototype.toString.call(obj);
2369 ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2370 }
2371
2372 tmp = Error.prototype.toString.call(testObj);
2373 ok(tmp === "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp);
2374
2375 err = new Error();
2376 err.name = null;
2377 ok(err.name === null, "err.name = " + err.name + " expected null");
2378 if(invokeVersion >= 2)
2379 ok(err.toString() === "null", "err.toString() = " + err.toString());
2380
2381 err = new Error();
2382 err.message = false;
2383 ok(err.message === false, "err.message = " + err.message + " expected false");
2384 if(invokeVersion >= 2)
2385 ok(err.toString() === "Error: false", "err.toString() = " + err.toString());
2386
2387 err = new Error();
2388 err.message = new Object();
2389 err.message.toString = function() { return ""; };
2390 if(invokeVersion >= 2)
2391 ok(err.toString() === "Error", "err.toString() = " + err.toString());
2392
2393 err = new Error();
2394 err.message = undefined;
2395 if(invokeVersion >= 2)
2396 ok(err.toString() === "Error", "err.toString() = " + err.toString());
2397
2398 var exception_array = {
2399 E_INVALID_LENGTH: { type: "RangeError", number: -2146823259 },
2400
2401 E_NOT_DATE: { type: "TypeError", number: -2146823282 },
2402 E_NOT_BOOL: { type: "TypeError", number: -2146823278 },
2403 E_ARG_NOT_OPT: { type: "TypeError", number: -2146827839 },
2404 E_NO_PROPERTY: { type: "TypeError", number: -2146827850 },
2405 E_NOT_NUM: { type: "TypeError", number: -2146823287 },
2406 E_INVALID_CALL_ARG: { type: "TypeError", number: -2146828283 },
2407 E_NOT_FUNC: { type: "TypeError", number: -2146823286 },
2408 E_OBJECT_EXPECTED: { type: "TypeError", number: -2146823281 },
2409 E_OBJECT_REQUIRED: { type: "TypeError", number: -2146827864 },
2410 E_UNSUPPORTED_ACTION: { type: "TypeError", number: -2146827843 },
2411 E_NOT_VBARRAY: { type: "TypeError", number: -2146823275 },