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