gdi32/uniscribe: Ensure the cache is initialised.
[wine.git] / dlls / jscript / tests / api.js
blobaea412347b9f0efaac886a25426f6eda4ff6ed0f
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
19 var JS_E_NUMBER_EXPECTED = 0x800a1389;
20 var JS_E_FUNCTION_EXPECTED = 0x800a138a;
21 var JS_E_DATE_EXPECTED = 0x800a138e;
22 var JS_E_OBJECT_EXPECTED = 0x800a138f;
23 var JS_E_BOOLEAN_EXPECTED = 0x800a1392;
24 var JS_E_VBARRAY_EXPECTED = 0x800a1395;
25 var JS_E_ENUMERATOR_EXPECTED = 0x800a1397;
26 var JS_E_REGEXP_EXPECTED = 0x800a1398;
28 var tmp, i;
30 var bigInt = Math.pow(2,40);
32 ok(ScriptEngine() === "JScript", "ScriptEngine() = " + ScriptEngine());
33 ok(ScriptEngine(3) === "JScript", "ScriptEngine(3) = " + ScriptEngine(3));
34 ok(ScriptEngineMajorVersion() === ScriptEngineMajorVersion(2), "ScriptEngineMajorVersion() !== ScriptEngineMajorVersion(2)");
35 ok(ScriptEngineMinorVersion() === ScriptEngineMinorVersion(2), "ScriptEngineMinorVersion() !== ScriptEngineMinorVersion(2)");
36 ok(ScriptEngineBuildVersion() === ScriptEngineBuildVersion(2), "ScriptEngineBuildVersion() !== ScriptEngineBuildVersion(2)");
38 function testNoEnumerables(expr) {
39     for(var iter in obj)
40         ok(false, expr + " has property " + iter);
43 testNoEnumerables("Object");
44 testNoEnumerables("Object.prototype");
45 testNoEnumerables("new Object()");
46 testNoEnumerables("Math");
47 testNoEnumerables("String");
48 testNoEnumerables("String.prototype");
49 testNoEnumerables("new String()");
50 testNoEnumerables("Number");
51 testNoEnumerables("Number.prototype");
52 testNoEnumerables("new Number(1)");
53 testNoEnumerables("ActiveXObject");
54 testNoEnumerables("Array");
55 testNoEnumerables("Array.prototype");
56 testNoEnumerables("new Array()");
57 testNoEnumerables("Boolean");
58 testNoEnumerables("Boolean.prototype");
59 testNoEnumerables("new Boolean()");
60 testNoEnumerables("Date");
61 testNoEnumerables("Date.prototype");
62 testNoEnumerables("new Date()");
63 testNoEnumerables("TypeError");
64 testNoEnumerables("TypeError.prototype");
65 testNoEnumerables("new TypeError()");
66 testNoEnumerables("Function");
67 testNoEnumerables("Function.prototype");
68 testNoEnumerables("testNoEnumerates");
69 testNoEnumerables("VBArray");
70 testNoEnumerables("new Enumerator()");
71 testNoEnumerables("Enumerator()");
73 ok(Object.propertyIsEnumerable("prototype") === false, "Object.prototype is enumerable");
74 ok(Math.propertyIsEnumerable("E") === false, "Math.E is enumerable");
75 ok(Math.propertyIsEnumerable("SQRT2") === false, "Math.SQRT2 is enumerable");
76 ok(Math.propertyIsEnumerable("PI") === false, "Math.PI is enumerable");
77 ok("test".propertyIsEnumerable("length") === false, "'test'.length is enumerable");
78 ok([1].propertyIsEnumerable("length") === false, "[1].length is enumerable");
79 ok((new TypeError()).propertyIsEnumerable("message") === true, "(new TypeError()).message is not enumerable");
80 ok((new TypeError()).propertyIsEnumerable("description") === false, "(new TypeError()).description is enumerable");
81 ok((new TypeError()).propertyIsEnumerable("name") === false, "(new TypeError()).name is enumerable");
82 ok((new TypeError()).propertyIsEnumerable("number") === false, "(new TypeError()).number is enumerable");
83 ok(Object.propertyIsEnumerable.propertyIsEnumerable("length") === false, "Object.propertyIsEnumerable.length is enumerable");
85 tmp = new Object();
86 tmp.test = "1";
87 ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable");
89 tmp = { test: 1 };
90 ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable");
92 ok([1].concat([2]).propertyIsEnumerable("1"), "[1].concat([2]).1 is not enumerable");
93 ok("t.e.s.t".split(".").propertyIsEnumerable("0"), "'test'.split().0 is not enumerable");
95 (function() {
96     ok(arguments.propertyIsEnumerable("0") === false, "arguments.0 is enumerable");
97     ok(arguments.propertyIsEnumerable("length") === false, "arguments.length is enumerable");
98     ok(arguments.propertyIsEnumerable("calee") === false, "arguments.calee is enumerable");
99 })();
101 tmp = [1];
102 tmp.push("");
103 ok(tmp.propertyIsEnumerable("1"), "[1].push() ... 1 is not enumerable");
105 ok([1,2].reverse().propertyIsEnumerable("1"), "[1,2].rverse().1 is not enumerable");
106 ok([1,2].propertyIsEnumerable("0"), "[1,2].0 is not enumerable");
108 i = parseInt("0");
109 ok(i === 0, "parseInt('0') = " + i);
110 i = parseInt("123");
111 ok(i === 123, "parseInt('123') = " + i);
112 i = parseInt("-123");
113 ok(i === -123, "parseInt('-123') = " + i);
114 i = parseInt("0xff");
115 ok(i === 0xff, "parseInt('0xff') = " + i);
116 i = parseInt("11", 8);
117 ok(i === 9, "parseInt('11', 8) = " + i);
118 i = parseInt("1j", 22);
119 ok(i === 41, "parseInt('1j', 32) = " + i);
120 i = parseInt("123", 0);
121 ok(i === 123, "parseInt('123', 0) = " + i);
122 i = parseInt("123", 10, "test");
123 ok(i === 123, "parseInt('123', 10, 'test') = " + i);
124 i = parseInt("11", "8");
125 ok(i === 9, "parseInt('11', '8') = " + i);
126 i = parseInt("010");
127 ok(i === 8, "parseInt('010') = " + i);
128 i = parseInt("");
129 ok(isNaN(i), "parseInt('') = " + i);
130 i = parseInt("0x");
131 ok(isNaN(i), "parseInt('0x') = " + i);
132 i = parseInt("+");
133 ok(isNaN(i), "parseInt('+') = " + i);
134 i = parseInt("-");
135 ok(isNaN(i), "parseInt('-') = " + i);
136 i = parseInt("0x10", 11);
137 ok(i === 0, "parseInt('0x10', 11) = " + i);
138 i = parseInt("010", 7);
139 ok(i === 7, "parseInt('010', 7) = " + i);
140 i = parseInt("123abc");
141 ok(i === 123, "parseInt('123abc') = " + i);
142 i = parseInt("   \t123abc");
143 ok(i === 123, "parseInt('   \\t123abc') = " + i);
144 i = parseInt("abc");
145 ok(isNaN(i), "parseInt('123abc') = " + i);
146 i = parseInt("-12", 11);
147 ok(i === -13, "parseInt('-12') = " + i);
148 i = parseInt("-0x10");
149 ok(i === -16, "parseInt('-0x10') = " + i);
150 i = parseInt("-010");
151 ok(i === -8, "parseInt('-010') = " + i);
152 i = parseInt("123", 0);
153 ok(i === 123, "parseInt('123', 0) = " + i);
154 i = parseInt("0x10", 0);
155 ok(i === 16, "parseInt('123', 0) = " + i);
156 i = parseInt("0x10", 10);
157 ok(i === 0, "parseInt('0x10', 10) = " + i);
158 i = parseInt("0xz");
159 ok(isNaN(i), "parseInt('0xz') = " + i);
160 i = parseInt("1", 1);
161 ok(isNaN(i), "parseInt('1', 1) = " + i);
162 i = parseInt("1", -1);
163 ok(isNaN(i), "parseInt('1', -1) = " + i);
164 i = parseInt("1", 37);
165 ok(isNaN(i), "parseInt('1', 37) = " + i);
166 i = parseInt("1", 36);
167 ok(i === 1, "parseInt('1', 36) = " + i);
168 i = parseInt("0x1f", 16);
169 ok(i === 31, "parseInt('0xf', 16) = " + i);
170 i = parseInt("0x", 16);
171 ok(isNaN(i), "parseInt('0x', 16) = " + i);
172 i = parseInt("0x1f", 17);
173 ok(i === 0, "parseInt('0xf', 16) = " + i);
175 tmp = encodeURI("abc");
176 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
177 tmp = encodeURI("{abc}");
178 ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp);
179 tmp = encodeURI("");
180 ok(tmp === "", "encodeURI('') = " + tmp);
181 tmp = encodeURI("\01\02\03\04");
182 ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp);
183 tmp = encodeURI("{#@}");
184 ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp);
185 tmp = encodeURI("\xa1 ");
186 ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp);
187 tmp = encodeURI("\xffff");
188 ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length);
189 tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
190 ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
191 tmp = encodeURI("%");
192 ok(tmp === "%25", "encodeURI('%') = " + tmp);
193 tmp = encodeURI();
194 ok(tmp === "undefined", "encodeURI() = " + tmp);
195 tmp = encodeURI("abc", "test");
196 ok(tmp === "abc", "encodeURI('abc') = " + tmp);
198 tmp = decodeURI("abc");
199 ok(tmp === "abc", "decodeURI('abc') = " + tmp);
200 tmp = decodeURI("{abc}");
201 ok(tmp === "{abc}", "decodeURI('{abc}') = " + tmp);
202 tmp = decodeURI("");
203 ok(tmp === "", "decodeURI('') = " + tmp);
204 tmp = decodeURI("\01\02\03\04");
205 ok(tmp === "\01\02\03\04", "decodeURI('\\01\\02\\03\\04') = " + tmp);
206 tmp = decodeURI();
207 ok(tmp === "undefined", "decodeURI() = " + tmp);
208 tmp = decodeURI("abc", "test");
209 ok(tmp === "abc", "decodeURI('abc') = " + tmp);
210 tmp = decodeURI("%7babc%7d");
211 ok(tmp === "{abc}", "decodeURI('%7Babc%7D') = " + tmp);
212 tmp = decodeURI("%01%02%03%04");
213 ok(tmp === "\01\02\03\04", "decodeURI('%01%02%03%04') = " + tmp);
214 tmp = decodeURI("%C2%A1%20");
215 ok(tmp === "\xa1 ", "decodeURI('%C2%A1%20') = " + tmp);
216 tmp = decodeURI("%C3%BFff");
217 ok(tmp.length === 3, "decodeURI('%C3%BFff').length = " + tmp.length);
219 tmp = encodeURIComponent("abc");
220 ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
221 dec = decodeURIComponent(tmp);
222 ok(dec === "abc", "decodeURIComponent('" + tmp + "') = " + dec);
223 tmp = encodeURIComponent("{abc}");
224 ok(tmp === "%7Babc%7D", "encodeURIComponent('{abc}') = " + tmp);
225 dec = decodeURIComponent(tmp);
226 ok(dec === "{abc}", "decodeURIComponent('" + tmp + "') = " + dec);
227 tmp = encodeURIComponent("");
228 ok(tmp === "", "encodeURIComponent('') = " + tmp);
229 dec = decodeURIComponent(tmp);
230 ok(dec === "", "decodeURIComponent('" + tmp + "') = " + dec);
231 tmp = encodeURIComponent("\01\02\03\04");
232 ok(tmp === "%01%02%03%04", "encodeURIComponent('\\01\\02\\03\\04') = " + tmp);
233 dec = decodeURIComponent(tmp);
234 ok(dec === "\01\02\03\04", "decodeURIComponent('" + tmp + "') = " + dec);
235 tmp = encodeURIComponent("{#@}");
236 ok(tmp === "%7B%23%40%7D", "encodeURIComponent('{#@}') = " + tmp);
237 dec = decodeURIComponent(tmp);
238 ok(dec === "{#@}", "decodeURIComponent('" + tmp + "') = " + dec);
239 tmp = encodeURIComponent("\xa1 ");
240 ok(tmp === "%C2%A1%20", "encodeURIComponent(\\xa1 ) = " + tmp);
241 dec = decodeURIComponent(tmp);
242 ok(dec === "\xa1 ", "decodeURIComponent('" + tmp + "') = " + dec);
243 tmp = encodeURIComponent("\xffff");
244 ok(tmp.length === 8, "encodeURIComponent('\\xffff').length = " + tmp.length);
245 dec = decodeURIComponent(tmp);
246 ok(dec === "\xffff", "decodeURIComponent('" + tmp + "') = " + dec);
247 tmp = encodeURIComponent("abcABC123;/?:@&=+$,-_.!~*'()");
248 ok(tmp === "abcABC123%3B%2F%3F%3A%40%26%3D%2B%24%2C-_.!~*'()", "encodeURIComponent('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
249 dec = decodeURIComponent(tmp);
250 ok(dec === "abcABC123;/?:@&=+$,-_.!~*'()", "decodeURIComponent('" + tmp + "') = " + dec);
251 tmp = encodeURIComponent();
252 ok(tmp === "undefined", "encodeURIComponent() = " + tmp);
253 tmp = encodeURIComponent("abc", "test");
254 ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
255 dec = decodeURIComponent();
256 ok(dec === "undefined", "decodeURIComponent() = " + dec);
257 dec = decodeURIComponent("abc", "test");
258 ok(dec === "abc", "decodeURIComponent('abc') = " + dec);
260 tmp = escape("abc");
261 ok(tmp === "abc", "escape('abc') = " + tmp);
262 tmp = escape("");
263 ok(tmp === "", "escape('') = " + tmp);
264 tmp = escape("a1b c!d+e@*-_+./,");
265 ok(tmp === "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp);
266 tmp = escape();
267 ok(tmp === "undefined", "escape() = " + tmp);
268 tmp = escape('\u1234\123\xf3');
269 ok(tmp == "%u1234S%F3", "escape('\u1234\123\xf3') = " + tmp);
271 tmp = unescape("abc");
272 ok(tmp === "abc", "unescape('abc') = " + tmp);
273 tmp = unescape("");
274 ok(tmp === "", "unescape('') = " + tmp);
275 tmp = unescape("%%%");
276 ok(tmp === "%%%", "unescape('%%%') = " + tmp);
277 tmp = unescape();
278 ok(tmp === "undefined", "unescape() = " + tmp);
279 tmp = unescape("%54%65s%u0074");
280 ok(tmp === "Test", "unescape('%54%65s%u0074') = " + tmp);
282 tmp = "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|";
283 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));
284 ok(unescape(escape(tmp)) === tmp, "unescape(escape('" + tmp + "')) = " + unescape(escape(tmp)));
286 ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty('toString') is false");
287 ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false");
288 ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false");
289 ok(!Function.prototype.hasOwnProperty('caller'), "Function.prototype.hasOwnProperty('caller') is true");
290 ok(!Function.prototype.hasOwnProperty('arguments'), "Function.prototype.hasOwnProperty('arguments') is true");
292 Object();
293 new Object();
294 obj = new Object();
296 ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
297 ok(!obj.hasOwnProperty('isPrototypeOf'), "obj.hasOwnProperty('isPrototypeOf') is true");
298 ok(!Object.hasOwnProperty('toString'), "Object.hasOwnProperty('toString') is true");
299 ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeOf') is true");
300 ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true");
301 ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true");
303 Array();
304 new Array();
305 obj = new Array();
306 ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false");
307 ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false");
308 ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true");
309 ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true");
311 Boolean();
312 new Boolean();
313 obj = new Boolean(false);
314 ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
315 ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true");
316 ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false");
318 Date();
319 new Date();
320 obj = new Date();
321 ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
322 ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
323 ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
324 ok(!("now" in Date), "now found in Date");
326 Number();
327 new Number();
328 obj = new Number();
329 ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
330 ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true");
331 ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false");
333 /x/;
334 obj = /x/;
335 ok(!obj.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true");
336 ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false");
337 ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true");
338 ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true");
339 ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false");
340 ok(RegExp.prototype.source === "", "RegExp.prototype.source = " + RegExp.prototype.source);
341 ok(RegExp.prototype.lastIndex === 0, "RegExp.prototype.lastIndex = " + RegExp.prototype.lastIndex);
343 String();
344 new String();
345 obj = new String();
346 ok(!obj.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true");
347 ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false");
348 ok(!String.hasOwnProperty('charAt'), "String.hasOwnProperty('charAt') is true");
349 ok(String.prototype.hasOwnProperty('charAt'), "String.prototype.hasOwnProperty('charAt') is false");
350 ok(String.prototype.hasOwnProperty('length'), "String.prototype.hasOwnProperty('length') is false");
352 tmp = "" + new Object();
353 ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
354 (tmp = new Array).f = Object.prototype.toString;
355 ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f());
356 (tmp = new Boolean).f = Object.prototype.toString;
357 ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f());
358 (tmp = new Date).f = Object.prototype.toString;
359 ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f());
360 (tmp = function() {}).f = Object.prototype.toString;
361 ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f());
362 Math.f = Object.prototype.toString;
363 ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f());
364 (tmp = new Number).f = Object.prototype.toString;
365 ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
366 (tmp = new RegExp("")).f = Object.prototype.toString;
367 ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
368 (tmp = new String).f = Object.prototype.toString;
369 ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f());
370 tmp = Object.prototype.toString.call(testObj);
371 ok(tmp === "[object Object]", "toString.call(testObj) = " + tmp);
372 tmp = Object.prototype.toString.call(this);
373 ok(tmp === "[object Object]", "toString.call(this) = " + tmp);
374 (function () { tmp = Object.prototype.toString.call(arguments); })();
375 ok(tmp === "[object Object]", "toString.call(arguments) = " + tmp);
376 tmp = Object.prototype.toString.call(new VBArray(createArray()));
377 ok(tmp === "[object Object]", "toString.call(new VBArray()) = " + tmp);
378 (tmp = new Enumerator()).f = Object.prototype.toString;
379 ok(tmp.f() === "[object Object]", "tmp.f() = " + tmp.f());
380 tmp = Object.prototype.toString.call(null);
381 ok(tmp === "[object Object]", "toString.call(null) = " + tmp);
382 tmp = Object.prototype.toString.call(undefined);
383 ok(tmp === "[object Object]", "toString.call(undefined) = " + tmp);
384 tmp = Object.prototype.toString.call();
385 ok(tmp === "[object Object]", "toString.call() = " + tmp);
387 function TSTestConstr() {}
388 TSTestConstr.prototype = { toString: function() { return "test"; } };
389 obj = new TSTestConstr();
390 ok(obj.toString() === "test", "obj.toString() = " + obj.toString());
392 ok(Object(1) instanceof Number, "Object(1) is not instance of Number");
393 ok(Object("") instanceof String, "Object('') is not instance of String");
394 ok(Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
396 ok(new Object(1) instanceof Number, "Object(1) is not instance of Number");
397 ok(new Object("") instanceof String, "Object('') is not instance of String");
398 ok(new Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
400 obj = new Object();
401 ok(Object(obj) === obj, "Object(obj) !== obj");
403 ok(typeof(Object()) === "object", "typeof(Object()) !== 'object'");
404 ok(typeof(Object(undefined)) === "object", "typeof(Object(undefined)) !== 'object'");
405 ok(typeof(Object(null)) === "object", "typeof(Object(null)) !== 'object'");
406 ok(typeof(Object(nullDisp)) === "object", "typeof(Object(nullDisp)) !== 'object'");
408 ok(Object(nullDisp) != nullDisp, "Object(nullDisp) == nullDisp");
409 ok(new Object(nullDisp) != nullDisp, "new Object(nullDisp) == nullDisp");
411 ok(Object(testObj) === testObj, "Object(testObj) != testObj\n");
412 ok(new Object(testObj) === testObj, "new Object(testObj) != testObj\n");
414 tmp = new Object();
415 ok(Object(tmp) === tmp, "Object(tmp) != tmp");
416 ok(new Object(tmp) === tmp, "new Object(tmp) != tmp");
418 var obj = new Object();
419 obj.toString = function (x) {
420     ok(arguments.length === 0, "arguments.length = " + arguments.length);
421     return "test";
423 ok((tmp = obj.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp);
424 ok((tmp = obj.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp);
425 ok(obj === obj.valueOf(), "obj !== obj.valueOf");
427 ok("".length === 0, "\"\".length = " + "".length);
428 ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
429 ok("abc".length === 3, "\"abc\".length = " + "abc".length);
430 ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
432 tmp = "".toString();
433 ok(tmp === "", "''.toString() = " + tmp);
434 tmp = "test".toString();
435 ok(tmp === "test", "''.toString() = " + tmp);
436 tmp = "test".toString(3);
437 ok(tmp === "test", "''.toString(3) = " + tmp);
439 tmp = "".valueOf();
440 ok(tmp === "", "''.valueOf() = " + tmp);
441 tmp = "test".valueOf();
442 ok(tmp === "test", "''.valueOf() = " + tmp);
443 tmp = "test".valueOf(3);
444 ok(tmp === "test", "''.valueOf(3) = " + tmp);
446 var str = new String("test");
447 ok(str.toString() === "test", "str.toString() = " + str.toString());
448 var str = new String();
449 ok(str.toString() === "", "str.toString() = " + str.toString());
450 var str = new String("test", "abc");
451 ok(str.toString() === "test", "str.toString() = " + str.toString());
453 str = new String("test");
454 ok(str.length === 4, "str.length = " + str.length);
455 str.length = 3;
456 str.length = 5;
457 ok(str.length === 4, "str.length = " + str.length);
459 var strObj = new Object();
460 strObj.toString = function() { return "abcd" };
461 strObj.substr = String.prototype.substr;
462 strObj.lastIndexOf = String.prototype.lastIndexOf;
464 tmp = "value " + str;
465 ok(tmp === "value test", "'value ' + str = " + tmp);
467 tmp = String();
468 ok(tmp === "", "String() = " + tmp);
469 tmp = String(false);
470 ok(tmp === "false", "String(false) = " + tmp);
471 tmp = String(null);
472 ok(tmp === "null", "String(null) = " + tmp);
473 tmp = String("test");
474 ok(tmp === "test", "String('test') = " + tmp);
475 tmp = String("test", "abc");
476 ok(tmp === "test", "String('test','abc') = " + tmp);
478 tmp = "abc".charAt(0);
479 ok(tmp === "a", "'abc',charAt(0) = " + tmp);
480 tmp = "abc".charAt(1);
481 ok(tmp === "b", "'abc',charAt(1) = " + tmp);
482 tmp = "abc".charAt(2);
483 ok(tmp === "c", "'abc',charAt(2) = " + tmp);
484 tmp = "abc".charAt(3);
485 ok(tmp === "", "'abc',charAt(3) = " + tmp);
486 tmp = "abc".charAt(4);
487 ok(tmp === "", "'abc',charAt(4) = " + tmp);
488 tmp = "abc".charAt();
489 ok(tmp === "a", "'abc',charAt() = " + tmp);
490 tmp = "abc".charAt(-1);
491 ok(tmp === "", "'abc',charAt(-1) = " + tmp);
492 tmp = "abc".charAt(0,2);
493 ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
494 tmp = "abc".charAt(NaN);
495 ok(tmp === "a", "'abc',charAt(NaN) = " + tmp);
496 tmp = "abc".charAt(bigInt);
497 ok(tmp === "", "'abc',charAt(bigInt) = " + tmp);
499 tmp = "abc".charCodeAt(0);
500 ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
501 tmp = "abc".charCodeAt(1);
502 ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
503 tmp = "abc".charCodeAt(2);
504 ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
505 tmp = "abc".charCodeAt();
506 ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
507 tmp = "abc".charCodeAt(true);
508 ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
509 tmp = "abc".charCodeAt(0,2);
510 ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
511 tmp = "\u49F4".charCodeAt(0);
512 ok(tmp === 0x49F4, "'\u49F4'.charCodeAt(0) = " + tmp);
513 tmp = "\052".charCodeAt(0);
514 ok(tmp === 0x2A, "'\052'.charCodeAt(0) = " + tmp);
515 tmp = "\xa2".charCodeAt(0);
516 ok(tmp === 0xA2, "'\xa2'.charCodeAt(0) = " + tmp);
517 tmp = "abc".charCodeAt(bigInt);
518 ok(isNaN(tmp), "'abc'.charCodeAt(bigInt) = " + tmp);
520 tmp = "abcd".substring(1,3);
521 ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
522 tmp = "abcd".substring(-1,3);
523 ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
524 tmp = "abcd".substring(1,6);
525 ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
526 tmp = "abcd".substring(3,1);
527 ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
528 tmp = "abcd".substring(2,2);
529 ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
530 tmp = "abcd".substring(true,"3");
531 ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
532 tmp = "abcd".substring(1,3,2);
533 ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
534 tmp = "abcd".substring();
535 ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
537 tmp = "abcd".substr(1,3);
538 ok(tmp === "bcd", "'abcd'.substr(1,3) = " + tmp);
539 tmp = "abcd".substr(-1,3);
540 ok(tmp === "abc", "'abcd'.substr(-1,3) = " + tmp);
541 tmp = "abcd".substr(1,6);
542 ok(tmp === "bcd", "'abcd'.substr(1,6) = " + tmp);
543 tmp = "abcd".substr(2,-1);
544 ok(tmp === "", "'abcd'.substr(3,1) = " + tmp);
545 tmp = "abcd".substr(2,0);
546 ok(tmp === "", "'abcd'.substr(2,2) = " + tmp);
547 tmp = "abcd".substr(true,"3");
548 ok(tmp === "bcd", "'abcd'.substr(true,'3') = " + tmp);
549 tmp = "abcd".substr(1,3,2);
550 ok(tmp === "bcd", "'abcd'.substr(1,3,2) = " + tmp);
551 tmp = "abcd".substr();
552 ok(tmp === "abcd", "'abcd'.substr() = " + tmp);
553 tmp = strObj.substr(1,1);
554 ok(tmp === "b", "'abcd'.substr(1,3) = " + tmp);
556 tmp = "abcd".slice(1,3);
557 ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
558 tmp = "abcd".slice(1,-1);
559 ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
560 tmp = "abcd".slice(-3,3);
561 ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
562 tmp = "abcd".slice(-6,3);
563 ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
564 tmp = "abcd".slice(3,1);
565 ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
566 tmp = "abcd".slice(true,3);
567 ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
568 tmp = "abcd".slice();
569 ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
570 tmp = "abcd".slice(1);
571 ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
573 tmp = "abc".concat(["d",1],2,false);
574 ok(tmp === "abcd,12false", "concat returned " + tmp);
575 var arr = new Array(2,"a");
576 arr.concat = String.prototype.concat;
577 tmp = arr.concat("d");
578 ok(tmp === "2,ad", "arr.concat = " + tmp);
580 m = "a+bcabc".match("a+");
581 ok(typeof(m) === "object", "typeof m is not object");
582 ok(m.length === 1, "m.length is not 1");
583 ok(m["0"] === "a", "m[0] is not \"a\"");
585 r = "- [test] -".replace("[test]", "success");
586 ok(r === "- success -", "r = " + r + " expected '- success -'");
588 r = "- [test] -".replace("[test]", "success", "test");
589 ok(r === "- success -", "r = " + r + " expected '- success -'");
591 r = "test".replace();
592 ok(r === "test", "r = " + r + " expected 'test'");
594 function replaceFunc3(m, off, str) {
595     ok(arguments.length === 3, "arguments.length = " + arguments.length);
596     ok(m === "[test]", "m = " + m + " expected [test]");
597     ok(off === 1, "off = " + off + " expected 0");
598     ok(str === "-[test]-", "str = " + arguments[3]);
599     return "ret";
602 r = "-[test]-".replace("[test]", replaceFunc3);
603 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
605 r = "-[test]-".replace("[test]", replaceFunc3, "test");
606 ok(r === "-ret-", "r = " + r + " expected '-ret-'");
608 r = "x,x,x".replace("x", "y");
609 ok(r === "y,x,x", "r = " + r + " expected 'y,x,x'");
611 r = "x,x,x".replace("", "y");
612 ok(r === "yx,x,x", "r = " + r + " expected 'yx,x,x'");
614 r = "x,x,x".replace("", "");
615 ok(r === "x,x,x", "r = " + r + " expected 'x,x,x'");
617 r = "1,2,3".split(",");
618 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
619 ok(r.length === 3, "r.length = " + r.length);
620 ok(r[0] === "1", "r[0] = " + r[0]);
621 ok(r[1] === "2", "r[1] = " + r[1]);
622 ok(r[2] === "3", "r[2] = " + r[2]);
624 r = "1,2,3".split(",*");
625 ok(r.length === 1, "r.length = " + r.length);
626 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
628 r = "123".split("");
629 ok(r.length === 3, "r.length = " + r.length);
630 ok(r[0] === "1", "r[0] = " + r[0]);
631 ok(r[1] === "2", "r[1] = " + r[1]);
632 ok(r[2] === "3", "r[2] = " + r[2]);
634 r = "123".split(2);
635 ok(r.length === 2, "r.length = " + r.length);
636 ok(r[0] === "1", "r[0] = " + r[0]);
637 ok(r[1] === "3", "r[1] = " + r[1]);
639 r = "1,2,".split(",");
640 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
641 ok(r.length === 3, "r.length = " + r.length);
642 ok(r[0] === "1", "r[0] = " + r[0]);
643 ok(r[1] === "2", "r[1] = " + r[1]);
644 ok(r[2] === "", "r[2] = " + r[2]);
646 r = "1,2,3".split(",", 2);
647 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
648 ok(r.length === 2, "r.length = " + r.length);
649 ok(r[0] === "1", "r[0] = " + r[0]);
650 ok(r[1] === "2", "r[1] = " + r[1]);
652 r = "1,2,3".split(",", 0);
653 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
654 ok(r.length === 0, "r.length = " + r.length);
656 r = "1,2,3".split(",", -1);
657 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
658 ok(r.length === 3, "r.length = " + r.length);
659 ok(r[0] === "1", "r[0] = " + r[0]);
660 ok(r[1] === "2", "r[1] = " + r[1]);
661 ok(r[2] === "3", "r[1] = " + r[1]);
663 r = "1,2,3".split(undefined);
664 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
665 ok(r.length === 1, "r.length = " + r.length);
666 ok(r[0] === "1,2,3", "r[0] = " + r[0]);
668 r = "1,undefined2undefined,3".split(undefined);
669 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
670 ok(r.length === 3, "r.length = " + r.length);
671 ok(r[0] === "1,", "r[0] = " + r[0]);
672 ok(r[1] === "2", "r[1] = " + r[1]);
673 ok(r[2] === ",3", "r[2] = " + r[2]);
675 r = "1,undefined2undefined,3".split();
676 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
677 ok(r.length === 1, "r.length = " + r.length);
678 ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
680 r = "".split();
681 ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
682 ok(r.length === 1, "r.length = " + r.length);
683 ok(r[0] === "", "r[0] = " + r[0]);
685 (function() {
686     function test(string, separator, result) {
687         var r = string.split(separator);
688         ok(r == result, "\"" + string + "\".split(" + separator + ") returned " + r + " expected " + result);
689     }
691     test("test", /^|\s+/, "test");
692     test("test", /$|\s+/, "test");
693     test("test", /^|./, "t");
694     test("test", /.*/, "");
695     test("test", /x*/, "t,e,s,t");
696     test("test", /$|x*/, "t,e,s,t");
697     test("test", /^|x*/, "t,e,s,t");
698     test("test", /t*/, "e,s");
699     test("xaabaax", /a*|b*/, "x,b,x");
700     test("xaabaax", /a+|b+/, "x,x");
701     test("xaabaax", /a+|b*/, "x,x");
702     test("xaaxbaax", /b+|a+/, "x,x,x");
703     test("test", /^|t/, "tes");
704     test("test", /^|t/, "tes");
705     test("a,,b", /,/, "a,b");
706     test("ab", /a*/, "b");
707     test("aab", "a", ",,b");
708     test("a", "a", ",");
710     function test_length(string, separator, len) {
711         var r = string.split(separator);
712         ok(r.length === len, "\"" + string + "\".split(" + separator + ").length = "
713            + r.length + " expected " + len);
714     }
716     test_length("", /a*/, 0);
717     test_length("", /a+/, 1);
718     test_length("", "", 0);
719     test_length("", "x", 1);
720 })();
722 tmp = "abcd".indexOf("bc",0);
723 ok(tmp === 1, "indexOf = " + tmp);
724 tmp = "abcd".indexOf("bc",1);
725 ok(tmp === 1, "indexOf = " + tmp);
726 tmp = "abcd".indexOf("bc");
727 ok(tmp === 1, "indexOf = " + tmp);
728 tmp = "abcd".indexOf("ac");
729 ok(tmp === -1, "indexOf = " + tmp);
730 tmp = "abcd".indexOf("bc",2);
731 ok(tmp === -1, "indexOf = " + tmp);
732 tmp = "abcd".indexOf("a",0);
733 ok(tmp === 0, "indexOf = " + tmp);
734 tmp = "abcd".indexOf("bc",0,"test");
735 ok(tmp === 1, "indexOf = " + tmp);
736 tmp = "abcd".indexOf();
737 ok(tmp == -1, "indexOf = " + tmp);
738 tmp = "abcd".indexOf("b", bigInt);
739 ok(tmp == -1, "indexOf = " + tmp);
740 tmp = "abcd".indexOf("abcd",0);
741 ok(tmp === 0, "indexOf = " + tmp);
742 tmp = "abcd".indexOf("abcd",1);
743 ok(tmp === -1, "indexOf = " + tmp);
744 tmp = ("ab" + String.fromCharCode(0) + "cd").indexOf(String.fromCharCode(0));
745 ok(tmp === 2, "indexOf = " + tmp);
747 tmp = "abcd".lastIndexOf("bc",1);
748 ok(tmp === 1, "lastIndexOf = " + tmp);
749 tmp = "abcd".lastIndexOf("bc",2);
750 ok(tmp === 1, "lastIndexOf = " + tmp);
751 tmp = "abcd".lastIndexOf("bc");
752 ok(tmp === 1, "lastIndexOf = " + tmp);
753 tmp = "abcd".lastIndexOf("ac");
754 ok(tmp === -1, "lastIndexOf = " + tmp);
755 tmp = "abcd".lastIndexOf("d",10);
756 ok(tmp === 3, "lastIndexOf = " + tmp);
757 tmp = "abcd".lastIndexOf("bc",0,"test");
758 ok(tmp === -1, "lastIndexOf = " + tmp);
759 tmp = "abcd".lastIndexOf();
760 ok(tmp === -1, "lastIndexOf = " + tmp);
761 tmp = "aaaa".lastIndexOf("a",2);
762 ok(tmp == 2, "lastIndexOf = " + tmp);
763 tmp = strObj.lastIndexOf("b");
764 ok(tmp === 1, "lastIndexOf = " + tmp);
765 tmp = "bbb".lastIndexOf("b", bigInt);
766 ok(tmp === 2, "lastIndexOf = " + tmp);
767 tmp = "abcd".lastIndexOf("abcd",4);
768 ok(tmp === 0, "lastIndexOf = " + tmp);
769 tmp = "abcd".lastIndexOf("abcd",0);
770 ok(tmp === 0, "lastIndexOf = " + tmp);
771 tmp = ("ab" + String.fromCharCode(0) + "cd").lastIndexOf(String.fromCharCode(0));
772 ok(tmp === 2, "lastIndexOf = " + tmp);
774 tmp = "".toLowerCase();
775 ok(tmp === "", "''.toLowerCase() = " + tmp);
776 tmp = "test".toLowerCase();
777 ok(tmp === "test", "''.toLowerCase() = " + tmp);
778 tmp = "test".toLowerCase(3);
779 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
780 tmp = "tEsT".toLowerCase();
781 ok(tmp === "test", "''.toLowerCase() = " + tmp);
782 tmp = "tEsT".toLocaleLowerCase();
783 ok(tmp === "test", "''.toLocaleLowerCase() = " + tmp);
784 tmp = "tEsT".toLowerCase(3);
785 ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
786 tmp = ("tE" + String.fromCharCode(0) + "sT").toLowerCase();
787 ok(tmp === "te" + String.fromCharCode(0) + "st", "''.toLowerCase() = " + tmp);
788 ok(String.prototype.toLocaleLowerCase != String.prototype.toLowerCase,
789    "String.prototype.toLocaleLowerCase == String.prototype.toLowerCase");
791 tmp = "".toUpperCase();
792 ok(tmp === "", "''.toUpperCase() = " + tmp);
793 tmp = "TEST".toUpperCase();
794 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
795 tmp = "TEST".toUpperCase(3);
796 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
797 tmp = "tEsT".toUpperCase();
798 ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
799 tmp = "tEsT".toUpperCase(3);
800 ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
801 tmp = "tEsT".toLocaleUpperCase(3);
802 ok(tmp === "TEST", "''.toLocaleUpperCase(3) = " + tmp);
803 tmp = ("tE" + String.fromCharCode(0) + "sT").toUpperCase();
804 ok(tmp === "TE" + String.fromCharCode(0) + "ST", "''.toUpperCase() = " + tmp);
805 ok(String.prototype.toLocaleUpperCase != String.prototype.toUpperCase,
806    "String.prototype.toLocaleUpperCase == String.prototype.toUpperCase");
808 tmp = "".anchor();
809 ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp);
810 tmp = "".anchor(3);
811 ok(tmp === "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp);
812 tmp = "".anchor("red");
813 ok(tmp === "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp);
814 tmp = "test".anchor();
815 ok(tmp === "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp);
816 tmp = "test".anchor(3);
817 ok(tmp === "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp);
818 tmp = "test".anchor("green");
819 ok(tmp === "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp);
821 tmp = "".big();
822 ok(tmp === "<BIG></BIG>", "''.big() = " + tmp);
823 tmp = "".big(3);
824 ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp);
825 tmp = "test".big();
826 ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp);
827 tmp = "test".big(3);
828 ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp);
830 tmp = "".blink();
831 ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp);
832 tmp = "".blink(3);
833 ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp);
834 tmp = "test".blink();
835 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp);
836 tmp = "test".blink(3);
837 ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp);
839 tmp = "".bold();
840 ok(tmp === "<B></B>", "''.bold() = " + tmp);
841 tmp = "".bold(3);
842 ok(tmp === "<B></B>", "''.bold(3) = " + tmp);
843 tmp = "test".bold();
844 ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp);
845 tmp = "test".bold(3);
846 ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp);
848 tmp = "".fixed();
849 ok(tmp === "<TT></TT>", "''.fixed() = " + tmp);
850 tmp = "".fixed(3);
851 ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp);
852 tmp = "test".fixed();
853 ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp);
854 tmp = "test".fixed(3);
855 ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp);
857 tmp = "".fontcolor();
858 ok(tmp === "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp);
859 tmp = "".fontcolor(3);
860 ok(tmp === "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp);
861 tmp = "".fontcolor("red");
862 ok(tmp === "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp);
863 tmp = "test".fontcolor();
864 ok(tmp === "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp);
865 tmp = "test".fontcolor(3);
866 ok(tmp === "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp);
867 tmp = "test".fontcolor("green");
868 ok(tmp === "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp);
870 tmp = "".fontsize();
871 ok(tmp === "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp);
872 tmp = "".fontsize(3);
873 ok(tmp === "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp);
874 tmp = "".fontsize("red");
875 ok(tmp === "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp);
876 tmp = "test".fontsize();
877 ok(tmp === "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp);
878 tmp = "test".fontsize(3);
879 ok(tmp === "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp);
880 tmp = "test".fontsize("green");
881 ok(tmp === "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp);
883 tmp = ("".fontcolor()).fontsize();
884 ok(tmp === "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp);
886 tmp = "".italics();
887 ok(tmp === "<I></I>", "''.italics() = " + tmp);
888 tmp = "".italics(3);
889 ok(tmp === "<I></I>", "''.italics(3) = " + tmp);
890 tmp = "test".italics();
891 ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp);
892 tmp = "test".italics(3);
893 ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp);
895 tmp = "".link();
896 ok(tmp === "<A HREF=\"undefined\"></A>", "''.link() = " + tmp);
897 tmp = "".link(3);
898 ok(tmp === "<A HREF=\"3\"></A>", "''.link(3) = " + tmp);
899 tmp = "".link("red");
900 ok(tmp === "<A HREF=\"red\"></A>", "''.link('red') = " + tmp);
901 tmp = "test".link();
902 ok(tmp === "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp);
903 tmp = "test".link(3);
904 ok(tmp === "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp);
905 tmp = "test".link("green");
906 ok(tmp === "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp);
908 tmp = "".small();
909 ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp);
910 tmp = "".small(3);
911 ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp);
912 tmp = "test".small();
913 ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp);
914 tmp = "test".small(3);
915 ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp);
917 tmp = "".strike();
918 ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp);
919 tmp = "".strike(3);
920 ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp);
921 tmp = "test".strike();
922 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp);
923 tmp = "test".strike(3);
924 ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp);
926 tmp = "".sub();
927 ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp);
928 tmp = "".sub(3);
929 ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp);
930 tmp = "test".sub();
931 ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp);
932 tmp = "test".sub(3);
933 ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp);
935 tmp = "".sup();
936 ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp);
937 tmp = "".sup(3);
938 ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp);
939 tmp = "test".sup();
940 ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp);
941 tmp = "test".sup(3);
942 ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp);
944 ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
945 ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
946 ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
947         "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
948 ok(String.fromCharCode(65, NaN, undefined).length === 3,
949         "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
951 var arr = new Array();
952 ok(typeof(arr) === "object", "arr () is not object");
953 ok((arr.length === 0), "arr.length is not 0");
954 ok(arr["0"] === undefined, "arr[0] is not undefined");
956 var arr = new Array(1, 2, "test");
957 ok(typeof(arr) === "object", "arr (1,2,test) is not object");
958 ok((arr.length === 3), "arr.length is not 3");
959 ok(arr["0"] === 1, "arr[0] is not 1");
960 ok(arr["1"] === 2, "arr[1] is not 2");
961 ok(arr["2"] === "test", "arr[2] is not \"test\"");
963 arr["7"] = true;
964 ok((arr.length === 8), "arr.length is not 8");
966 tmp = "" + [];
967 ok(tmp === "", "'' + [] = " + tmp);
968 tmp = "" + [1,true];
969 ok(tmp === "1,true", "'' + [1,true] = " + tmp);
971 var arr = new Array(6);
972 ok(typeof(arr) === "object", "arr (6) is not object");
973 ok((arr.length === 6), "arr.length is not 6");
974 ok(arr["0"] === undefined, "arr[0] is not undefined");
976 ok(arr.push() === 6, "arr.push() !== 6");
977 ok(arr.push(1) === 7, "arr.push(1) !== 7");
978 ok(arr[6] === 1, "arr[6] != 1");
979 ok(arr.length === 7, "arr.length != 10");
980 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
981 ok(arr[8] === "b", "arr[8] != 'b'");
982 ok(arr.length === 10, "arr.length != 10");
984 var arr = new Object();
985 arr.push = Array.prototype.push;
987 arr.length = 6;
989 ok(arr.push() === 6, "arr.push() !== 6");
990 ok(arr.push(1) === 7, "arr.push(1) !== 7");
991 ok(arr[6] === 1, "arr[6] != 1");
992 ok(arr.length === 7, "arr.length != 10");
993 ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
994 ok(arr[8] === "b", "arr[8] != 'b'");
995 ok(arr.length === 10, "arr.length != 10");
997 arr.pop = Array.prototype.pop;
998 ok(arr.pop() === false, "arr.pop() !== false");
999 ok(arr[8] === "b", "arr[8] !== 'b'");
1000 ok(arr.pop() === 'b', "arr.pop() !== 'b'");
1001 ok(arr[8] === undefined, "arr[8] !== undefined");
1003 arr = [3,4,5];
1004 tmp = arr.pop();
1005 ok(arr.length === 2, "arr.length = " + arr.length);
1006 ok(tmp === 5, "pop() = " + tmp);
1007 tmp = arr.pop(2);
1008 ok(arr.length === 1, "arr.length = " + arr.length);
1009 ok(tmp === 4, "pop() = " + tmp);
1010 tmp = arr.pop();
1011 ok(arr.length === 0, "arr.length = " + arr.length);
1012 ok(tmp === 3, "pop() = " + tmp);
1013 for(tmp in arr)
1014     ok(false, "not deleted " + tmp);
1015 tmp = arr.pop();
1016 ok(arr.length === 0, "arr.length = " + arr.length);
1017 ok(tmp === undefined, "tmp = " + tmp);
1018 arr = new Object();
1019 arr.pop = Array.prototype.pop;
1020 tmp = arr.pop();
1021 ok(arr.length === 0, "arr.length = " + arr.length);
1022 ok(tmp === undefined, "tmp = " + tmp);
1023 arr = [,,,,,];
1024 tmp = arr.pop();
1025 ok(arr.length === 5, "arr.length = " + arr.length);
1026 ok(tmp === undefined, "tmp = " + tmp);
1027 tmp = [1,2,,,].pop();
1028 ok(tmp === undefined, "tmp = " + tmp);
1030 function PseudoArray() {
1031     this[0] = 0;
1033 PseudoArray.prototype = {length: 1};
1034 arr = new PseudoArray();
1035 Array.prototype.push.call(arr, 2);
1036 ok(arr.propertyIsEnumerable("length"), "arr.length is not enumerable");
1038 arr = [1,2,null,false,undefined,,"a"];
1040 tmp = arr.join();
1041 ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
1042 tmp = arr.join(";");
1043 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
1044 tmp = arr.join(";","test");
1045 ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
1046 tmp = arr.join("");
1047 ok(tmp === "12falsea", "arr.join('') = " + tmp);
1049 tmp = arr.toString();
1050 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
1051 tmp = arr.toString("test");
1052 ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
1054 arr = ["a", "b"];
1056 tmp = arr.join(String.fromCharCode(0));
1057 ok(tmp === "a" + String.fromCharCode(0) + "b", "arr.join(String.fromCharCode(0)) = " + tmp);
1059 arr = new Object();
1060 arr.length = 3;
1061 arr[0] = "aa";
1062 arr[2] = 2;
1063 arr[7] = 3;
1064 arr.join = Array.prototype.join;
1065 tmp = arr.join(",");
1066 ok(arr.length === 3, "arr.length = " + arr.length);
1067 ok(tmp === "aa,,2", "tmp = " + tmp);
1069 arr = [5,true,2,-1,3,false,"2.5"];
1070 tmp = arr.sort(function(x,y) { return y-x; });
1071 ok(tmp === arr, "tmp !== arr");
1072 tmp = [5,3,"2.5",2,true,false,-1];
1073 for(var i=0; i < arr.length; i++)
1074     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
1076 tmp = [3,1,2].sort(function(x,y) { return y-x; }).join();
1077 ok(tmp === "3,2,1", "reverse sorted [3,1,2] = " + tmp);
1079 tmp = [3,1,2].sort(null).join();
1080 ok(tmp === "1,2,3", "null sorted [3,1,2] = " + tmp);
1082 try {
1083     tmp = [3,1,2].sort(function(x,y) { return y-x; }, 1, 2, 3);
1084     ok(false, "expected sort(undefined) exception");
1085 } catch(e) {
1086     ok(e.name === "TypeError", "got exception " + e.name);
1089 arr = [5,false,2,0,"abc",3,"a",-1];
1090 tmp = arr.sort();
1091 ok(tmp === arr, "tmp !== arr");
1092 tmp = [-1,0,2,3,5,"a","abc",false];
1093 for(var i=0; i < arr.length; i++)
1094     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
1096 arr = ["a", "b", "ab"];
1097 tmp = ["a", "ab", "b"];
1098 ok(arr.sort() === arr, "arr.sort() !== arr");
1099 for(var i=0; i < arr.length; i++)
1100     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
1102 arr = new Object();
1103 arr.length = 3;
1104 arr[0] = 1;
1105 arr[2] = "aa";
1106 arr.sort = Array.prototype.sort;
1107 tmp = arr.sort();
1108 ok(arr === tmp, "tmp !== arr");
1109 ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorrectly");
1111 tmp = [["bb","aa"],["ab","aa"]].sort().toString();
1112 ok(tmp === "ab,aa,bb,aa", "sort() = " + tmp);
1114 tmp = [["bb","aa"],"ab"].sort().toString();
1115 ok(tmp === "ab,bb,aa", "sort() = " + tmp);
1117 tmp = [["bb","aa"],"cc"].sort().toString();
1118 ok(tmp === "bb,aa,cc", "sort() = " + tmp);
1120 tmp = [2,"1"].sort().toString();
1121 ok(tmp === "1,2", "sort() = " + tmp);
1123 tmp = ["2",1].sort().toString();
1124 ok(tmp === "1,2", "sort() = " + tmp);
1126 tmp = [,,0,"z"].sort().toString();
1127 ok(tmp === "0,z,,", "sort() = " + tmp);
1129 tmp = ["a,b",["a","a"],["a","c"]].sort().toString();
1130 ok(tmp === "a,a,a,b,a,c", "sort() = " + tmp);
1132 arr = ["1", "2", "3"];
1133 arr.length = 1;
1134 ok(arr.length === 1, "arr.length = " + arr.length);
1135 arr.length = 3;
1136 ok(arr.length === 3, "arr.length = " + arr.length);
1137 ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
1139 arr = Array("a","b","c");
1140 ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
1142 ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
1143 ok(arr === arr.valueOf(), "arr !== arr.valueOf");
1145 arr = [1,2,3];
1146 tmp = arr.reverse();
1147 ok(tmp === arr, "tmp !== arr");
1148 ok(arr.length === 3, "arr.length = " + arr.length);
1149 ok(arr.toString() === "3,2,1", "arr.toString() = " + arr.toString());
1151 arr = [];
1152 arr[3] = 5;
1153 arr[5] = 1;
1154 tmp = arr.reverse();
1155 ok(tmp === arr, "tmp !== arr");
1156 ok(arr.length === 6, "arr.length = " + arr.length);
1157 ok(arr.toString() === "1,,5,,,", "arr.toString() = " + arr.toString());
1159 arr = new Object();
1160 arr.length = 3;
1161 arr[0] = "aa";
1162 arr[2] = 2;
1163 arr[7] = 3;
1164 arr.reverse = Array.prototype.reverse;
1165 tmp = arr.reverse();
1166 ok(tmp === arr, "tmp !== arr");
1167 ok(arr.length === 3, "arr.length = " + arr.length);
1168 ok(arr[0] === 2 && arr[1] === undefined && arr[2] === "aa", "unexpected array");
1170 arr = [1,2,3];
1171 tmp = arr.unshift(0);
1172 ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp);
1173 ok(arr.length === 4, "arr.length = " + arr.length);
1174 ok(arr.toString() === "0,1,2,3", "arr.toString() = " + arr.toString());
1176 arr = new Array(3);
1177 arr[0] = 1;
1178 arr[2] = 3;
1179 tmp = arr.unshift(-1,0);
1180 ok(tmp === (invokeVersion < 2 ? undefined : 5), "unshift returned " +tmp);
1181 ok(arr.length === 5, "arr.length = " + arr.length);
1182 ok(arr.toString() === "-1,0,1,,3", "arr.toString() = " + arr.toString());
1184 arr = [1,2,3];
1185 tmp = arr.unshift();
1186 ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
1187 ok(arr.length === 3, "arr.length = " + arr.length);
1188 ok(arr.toString() === "1,2,3", "arr.toString() = " + arr.toString());
1190 arr = new Object();
1191 arr.length = 2;
1192 arr[0] = 1;
1193 arr[1] = 2;
1194 tmp = Array.prototype.unshift.call(arr, 0);
1195 ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
1196 ok(arr.length === 3, "arr.length = " + arr.length);
1197 ok(arr[0] === 0 && arr[1] === 1 && arr[2] === 2, "unexpected array");
1199 arr = [1,2,,4];
1200 tmp = arr.shift();
1201 ok(tmp === 1, "[1,2,,4].shift() = " + tmp);
1202 ok(arr.toString() === "2,,4", "arr = " + arr.toString());
1204 arr = [];
1205 tmp = arr.shift();
1206 ok(tmp === undefined, "[].shift() = " + tmp);
1207 ok(arr.toString() === "", "arr = " + arr.toString());
1209 arr = [1,2,,4];
1210 tmp = arr.shift(2);
1211 ok(tmp === 1, "[1,2,,4].shift(2) = " + tmp);
1212 ok(arr.toString() === "2,,4", "arr = " + arr.toString());
1214 arr = [1,];
1215 tmp = arr.shift();
1216 ok(tmp === 1, "[1,].shift() = " + tmp);
1217 ok(arr.toString() === "", "arr = " + arr.toString());
1219 obj = new Object();
1220 obj[0] = "test";
1221 obj[2] = 3;
1222 obj.length = 3;
1223 tmp = Array.prototype.shift.call(obj);
1224 ok(tmp === "test", "obj.shift() = " + tmp);
1225 ok(obj.length == 2, "obj.length = " + obj.length);
1226 ok(obj[1] === 3, "obj[1] = " + obj[1]);
1228 var num = new Number(6);
1229 arr = [0,1,2];
1230 tmp = arr.concat(3, [4,5], num);
1231 ok(tmp !== arr, "tmp === arr");
1232 for(var i=0; i<6; i++)
1233     ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
1234 ok(tmp[6] === num, "tmp[6] !== num");
1235 ok(tmp.length === 7, "tmp.length = " + tmp.length);
1237 arr = [].concat();
1238 ok(arr.length === 0, "arr.length = " + arr.length);
1240 arr = [1,];
1241 tmp = arr.concat([2]);
1242 ok(tmp.length === 3, "tmp.length = " + tmp.length);
1243 ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
1245 arr = [1,false,'a',null,undefined,'a'];
1246 ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6));
1247 ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length);
1248 ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice());
1249 ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc"));
1250 ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8));
1251 ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length);
1252 ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1));
1253 ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2));
1254 ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1));
1255 tmp = arr.slice(0,6);
1256 for(var i=0; i < arr.length; i++)
1257     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
1258 arr[12] = 2;
1259 ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString());
1260 ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length);
1262 arr = [1,2,3,4,5];
1263 tmp = arr.splice(2,2);
1264 ok(tmp.toString() == "3,4", "arr.splice(2,2) returned " + tmp.toString());
1265 ok(arr.toString() == "1,2,5", "arr.splice(2,2) is " + arr.toString());
1267 arr = [1,2,3,4,5];
1268 tmp = arr.splice(2,2,"a");
1269 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a') returned " + tmp.toString());
1270 ok(arr.toString() == "1,2,a,5", "arr.splice(2,2,'a') is " + arr.toString());
1272 arr = [1,2,3,4,5];
1273 tmp = arr.splice(2,2,'a','b','c');
1274 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
1275 ok(arr.toString() == "1,2,a,b,c,5", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1277 arr = [1,2,3,4,];
1278 tmp = arr.splice(2,2,'a','b','c');
1279 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
1280 ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1282 arr = [1,2,3,4,];
1283 arr.splice(2,2,'a','b','c');
1284 ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
1286 arr = [1,2,3,4,5];
1287 tmp = arr.splice(2,2,'a','b');
1288 ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b') returned " + tmp.toString());
1289 ok(arr.toString() == "1,2,a,b,5", "arr.splice(2,2,'a','b') is " + arr.toString());
1291 arr = [1,2,3,4,5];
1292 tmp = arr.splice(-1,2);
1293 ok(tmp.toString() == "5", "arr.splice(-1,2) returned " + tmp.toString());
1294 ok(arr.toString() == "1,2,3,4", "arr.splice(-1,2) is " + arr.toString());
1296 arr = [1,2,3,4,5];
1297 tmp = arr.splice(-10,3);
1298 ok(tmp.toString() == "1,2,3", "arr.splice(-10,3) returned " + tmp.toString());
1299 ok(arr.toString() == "4,5", "arr.splice(-10,3) is " + arr.toString());
1301 arr = [1,2,3,4,5];
1302 tmp = arr.splice(-10,100);
1303 ok(tmp.toString() == "1,2,3,4,5", "arr.splice(-10,100) returned " + tmp.toString());
1304 ok(arr.toString() == "", "arr.splice(-10,100) is " + arr.toString());
1306 arr = [1,2,3,4,5];
1307 tmp = arr.splice(2,-1);
1308 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1309 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1311 arr = [1,2,3,4,5];
1312 tmp = arr.splice(2);
1313 ok(tmp.toString() == "", "arr.splice(2) returned " + tmp.toString());
1314 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2) is " + arr.toString());
1316 arr = [1,2,3,4,5];
1317 tmp = arr.splice();
1318 ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
1319 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
1321 arr = [1,2,3,4,5];
1322 tmp = arr.splice(bigInt);
1323 ok(tmp.toString() == "", "arr.splice(bigInt) returned " + tmp.toString());
1324 ok(arr.toString() == "1,2,3,4,5", "arr.splice(bigInt) is " + arr.toString());
1326 arr = [1,2,3,4,5];
1327 tmp = arr.splice(-bigInt);
1328 ok(tmp.toString() == "", "arr.splice(-bigInt) returned " + tmp.toString());
1329 ok(arr.toString() == "1,2,3,4,5", "arr.splice(-bigInt) is " + arr.toString());
1331 if(invokeVersion >= 2) {
1332     arr = [1,2,3,4,5];
1333     tmp = arr.splice(2, bigInt);
1334     ok(tmp.toString() == "3,4,5", "arr.splice(2, bigInt) returned " + tmp.toString());
1335     ok(arr.toString() == "1,2", "arr.splice(2, bigInt) is " + arr.toString());
1338 arr = [1,2,3,4,5];
1339 tmp = arr.splice(2, -bigInt);
1340 ok(tmp.toString() == "", "arr.splice(2, -bigInt) returned " + tmp.toString());
1341 ok(arr.toString() == "1,2,3,4,5", "arr.splice(2, -bigInt) is " + arr.toString());
1343 obj = new Object();
1344 obj.length = 3;
1345 obj[0] = 1;
1346 obj[1] = 2;
1347 obj[2] = 3;
1348 tmp = Array.prototype.splice.call(obj, 1, 1, 'a', 'b');
1349 ok(tmp.toString() === "2", "obj.splice returned " + tmp);
1350 ok(obj.length === 4, "obj.length = " + obj.length);
1351 ok(obj[0] === 1, "obj[0] = " + obj[0]);
1352 ok(obj[1] === 'a', "obj[1] = " + obj[1]);
1353 ok(obj[2] === 'b', "obj[2] = " + obj[2]);
1354 ok(obj[3] === 3, "obj[3] = " + obj[3]);
1356 obj = new Object();
1357 obj.length = 3;
1358 obj[0] = 1;
1359 obj[1] = 2;
1360 obj[2] = 3;
1361 tmp = Array.prototype.slice.call(obj, 1, 2);
1362 ok(tmp.length === 1, "tmp.length = " + tmp.length);
1363 ok(tmp[0] === 2, "tmp[0] = " + tmp[0]);
1365 tmp = (new Number(2)).toString();
1366 ok(tmp === "2", "num(2).toString = " + tmp);
1367 tmp = (new Number()).toString();
1368 ok(tmp === "0", "num().toString = " + tmp);
1369 tmp = (new Number(5.5)).toString(2);
1370 ok(tmp === "101.1", "num(5.5).toString(2) = " + tmp);
1372 tmp = (new Number(12)).toLocaleString();
1373 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
1374 tmp = Number.prototype.toLocaleString.call(NaN);
1375 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
1377 tmp = (new Number(3)).toFixed(3);
1378 ok(tmp === "3.000", "num(3).toFixed(3) = " + tmp);
1379 tmp = (new Number(3)).toFixed();
1380 ok(tmp === "3", "Number(3).toFixed() = " + tmp);
1381 tmp = (new Number(0)).toFixed();
1382 ok(tmp === "0", "Number(0).toFixed() = " + tmp);
1383 tmp = (new Number(0)).toFixed(1);
1384 ok(tmp === "0.0", "Number(0).toFixed(1) = " + tmp);
1385 tmp = (new Number(0)).toFixed(2);
1386 ok(tmp === "0.00", "Number(0).toFixed(2) = " + tmp);
1387 tmp = (new Number(1.76)).toFixed(1);
1388 ok(tmp === "1.8", "num(1.76).toFixed(1) = " + tmp);
1389 tmp = (new Number(7.92)).toFixed(5);
1390 ok(tmp === "7.92000", "num(7.92).toFixed(5) = " + tmp);
1391 tmp = (new Number(2.88)).toFixed();
1392 ok(tmp === "3", "num(2.88).toFixed = " + tmp);
1393 tmp = (new Number(-2.5)).toFixed();
1394 ok(tmp === "-3", "num(-2.5).toFixed = " + tmp);
1395 tmp = (new Number(1000000000000000128)).toFixed(0);
1396 //todo_wine ok(tmp === "1000000000000000100", "num(1000000000000000128) = " + tmp);
1397 tmp = (new Number(3.14).toFixed(NaN));
1398 ok(tmp === "3", "num(3.14).toFixed = " + tmp);
1399 tmp = (new Number(0.95).toFixed(1));
1400 ok(tmp === "1.0", "num(0.95).toFixed(1) = " + tmp);
1401 tmp = (new Number(1e900)).toFixed(0);
1402 ok(tmp === "Infinity", "num(1000000000000000128) = " + tmp);
1403 tmp = (new Number(0.12345678901234567890123)).toFixed(20);
1404 ok(tmp === "0.12345678901234568000", "num(0.12345678901234567890123) = " + tmp);
1406 tmp = (new Number(2)).toExponential(3);
1407 ok(tmp === "2.000e+0", "num(2).toExponential(3) = " + tmp);
1408 tmp = (new Number(1.17e-32)).toExponential(20);
1409 ok(tmp === "1.17000000000000000000e-32", "num(1.17e-32).toExponential(20) = " + tmp);
1410 tmp = (new Number(0)).toExponential(7);
1411 ok(tmp === "0.0000000e+0", "num(0).toExponential(7) = " + tmp);
1412 tmp = (new Number(0)).toExponential(0);
1413 ok(tmp === "0e+0", "num(0).toExponential() = " + tmp);
1414 tmp = (new Number(-13.7567)).toExponential();
1415 ok(tmp === "-1.37567e+1", "num(-13.7567).toExponential() = " + tmp);
1416 tmp = (new Number(-32.1)).toExponential();
1417 ok(tmp === "-3.21e+1", "num(-32.1).toExponential() = " + tmp);
1418 tmp = (new Number(4723.4235)).toExponential();
1419 ok(tmp === "4.7234235e+3", "num(4723.4235).toExponential() = " + tmp);
1421 tmp = (new Number(5)).toPrecision(12);
1422 ok(tmp == "5.00000000000", "num(5).toPrecision(12) = " + tmp);
1423 tmp = (new Number(7.73)).toPrecision(7);
1424 ok(tmp == "7.730000", "num(7.73).toPrecision(7) = " + tmp);
1425 tmp = (new Number(-127547.47472)).toPrecision(17);
1426 ok(tmp == "-127547.47472000000", "num(-127547.47472).toPrecision(17) = " + tmp);
1427 tmp = (new Number(0)).toPrecision(3);
1428 ok(tmp == "0.00", "num(0).toPrecision(3) = " + tmp);
1429 tmp = (new Number(42345.52342465464562334)).toPrecision(15);
1430 ok(tmp == "42345.5234246546", "num(42345.52342465464562334).toPrecision(15) = " + tmp);
1431 tmp = (new Number(1.182e30)).toPrecision(5);
1432 ok(tmp == "1.1820e+30", "num(1.182e30)).toPrecision(5) = " + tmp);
1433 tmp = (new Number(1.123)).toPrecision();
1434 ok(tmp == "1.123", "num(1.123).toPrecision() = " + tmp);
1435 if(invokeVersion >= 2) {
1436     tmp = (new Number(1.123)).toPrecision(undefined);
1437     ok(tmp == "1.123", "num(1.123).toPrecision(undefined) = " + tmp);
1440 ok(Number() === 0, "Number() = " + Number());
1441 ok(Number(false) === 0, "Number(false) = " + Number(false));
1442 ok(Number("43") === 43, "Number('43') = " + Number("43"));
1444 tmp = (new Number(1)).valueOf();
1445 ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
1446 tmp = (new Number(1,2)).valueOf();
1447 ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
1448 tmp = (new Number()).valueOf();
1449 ok(tmp === 0, "(new Number()).valueOf = " + tmp);
1450 tmp = Number.prototype.valueOf();
1451 ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
1453 function equals(val, base) {
1454     var i;
1455     var num = 0;
1456     var str = val.toString(base);
1458     for(i=0; i<str.length; i++) {
1459         if(str.substring(i, i+1) == '(') break;
1460         if(str.substring(i, i+1) == '.') break;
1461         num = num*base + parseInt(str.substring(i, i+1));
1462     }
1464     if(str.substring(i, i+1) == '.') {
1465         var mult = base;
1466         for(i++; i<str.length; i++) {
1467             if(str.substring(i, i+1) == '(') break;
1468             num += parseInt(str.substring(i, i+1))/mult;
1469             mult *= base;
1470         }
1471     }
1473     if(str.substring(i, i+1) == '(') {
1474         exp = parseInt(str.substring(i+2));
1475         num *= Math.pow(base, exp);
1476     }
1478     ok(num>val-val/1000 && num<val+val/1000, "equals: num = " + num);
1481 ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11));
1482 ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17));
1483 ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33));
1484 ok((NaN).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN).toString(11));
1485 ok((Infinity).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity).toString(11));
1486 for(i=2; i<10; i++) {
1487     equals(1.123, i);
1488     equals(2305843009200000000, i);
1489     equals(5.123, i);
1490     equals(21711, i);
1491     equals(1024*1024*1024*1024*1024*1024*1.9999, i);
1492     equals(748382, i);
1493     equals(0.6, i);
1494     equals(4.65661287308e-10, i);
1495     ok((0).toString(i) === "0", "(0).toString("+i+") = " + (0).toString(i));
1498 ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123'));
1499 ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7'));
1500 ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2'));
1501 ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5'));
1502 ok(parseFloat('1E5 not parsed') === 1E5, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed'));
1503 ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
1504 ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
1505 ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
1506 ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
1507 ok(isNaN(parseFloat('\uff16')), "parseFloat('\\uD835') is not NaN");
1509 tmp = Math.min(1);
1510 ok(tmp === 1, "Math.min(1) = " + tmp);
1512 tmp = Math.min(1, false);
1513 ok(tmp === 0, "Math.min(1, false) = " + tmp);
1515 tmp = Math.min();
1516 ok(tmp === Infinity, "Math.min() = " + tmp);
1518 tmp = Math.min(1, NaN, -Infinity, false);
1519 ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
1521 tmp = Math.min(1, false, true, null, -3);
1522 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
1524 tmp = Math.max(1);
1525 ok(tmp === 1, "Math.max(1) = " + tmp);
1527 tmp = Math.max(true, 0);
1528 ok(tmp === 1, "Math.max(true, 0) = " + tmp);
1530 tmp = Math.max(-2, false, true, null, 1);
1531 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
1533 tmp = Math.max();
1534 ok(tmp === -Infinity, "Math.max() = " + tmp);
1536 tmp = Math.max(true, NaN, 0);
1537 ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
1539 tmp = Math.round(0.5);
1540 ok(tmp === 1, "Math.round(0.5) = " + tmp);
1542 tmp = Math.round(-0.5);
1543 ok(tmp === 0, "Math.round(-0.5) = " + tmp);
1545 tmp = Math.round(1.1);
1546 ok(tmp === 1, "Math.round(1.1) = " + tmp);
1548 tmp = Math.round(true);
1549 ok(tmp === 1, "Math.round(true) = " + tmp);
1551 tmp = Math.round(1.1, 3, 4);
1552 ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
1554 tmp = Math.round();
1555 ok(isNaN(tmp), "Math.round() is not NaN");
1557 tmp = Math.ceil(0.5);
1558 ok(tmp === 1, "Math.ceil(0.5) = " + tmp);
1560 tmp = Math.ceil(-0.5);
1561 ok(tmp === 0, "Math.ceil(-0.5) = " + tmp);
1563 tmp = Math.ceil(1.1);
1564 ok(tmp === 2, "Math.round(1.1) = " + tmp);
1566 tmp = Math.ceil(true);
1567 ok(tmp === 1, "Math.ceil(true) = " + tmp);
1569 tmp = Math.ceil(1.1, 3, 4);
1570 ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp);
1572 tmp = Math.ceil();
1573 ok(isNaN(tmp), "ceil() is not NaN");
1575 tmp = Math.floor(0.5);
1576 ok(tmp === 0, "Math.floor(0.5) = " + tmp);
1578 tmp = Math.floor(-0.5);
1579 ok(tmp === -1, "Math.floor(-0.5) = " + tmp);
1581 tmp = Math.floor(1.1);
1582 ok(tmp === 1, "Math.floor(1.1) = " + tmp);
1584 tmp = Math.floor(true);
1585 ok(tmp === 1, "Math.floor(true) = " + tmp);
1587 tmp = Math.floor(1.1, 3, 4);
1588 ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp);
1590 tmp = Math.floor();
1591 ok(isNaN(tmp), "floor is not NaN");
1593 tmp = Math.abs(3);
1594 ok(tmp === 3, "Math.abs(3) = " + tmp);
1596 tmp = Math.abs(-3);
1597 ok(tmp === 3, "Math.abs(-3) = " + tmp);
1599 tmp = Math.abs(true);
1600 ok(tmp === 1, "Math.abs(true) = " + tmp);
1602 tmp = Math.abs();
1603 ok(isNaN(tmp), "Math.abs() is not NaN");
1605 tmp = Math.abs(NaN);
1606 ok(isNaN(tmp), "Math.abs() is not NaN");
1608 tmp = Math.abs(-Infinity);
1609 ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp);
1611 tmp = Math.abs(-3, 2);
1612 ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
1614 tmp = Math.cos(0);
1615 ok(tmp === 1, "Math.cos(0) = " + tmp);
1617 tmp = Math.cos(Math.PI/2);
1618 ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp);
1620 tmp = Math.cos(-Math.PI/2);
1621 ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp);
1623 tmp = Math.cos(Math.PI/3, 2);
1624 ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp);
1626 tmp = Math.cos(true);
1627 ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp);
1629 tmp = Math.cos(false);
1630 ok(tmp === 1, "Math.cos(false) = " + tmp);
1632 tmp = Math.cos();
1633 ok(isNaN(tmp), "Math.cos() is not NaN");
1635 tmp = Math.cos(NaN);
1636 ok(isNaN(tmp), "Math.cos(NaN) is not NaN");
1638 tmp = Math.cos(Infinity);
1639 ok(isNaN(tmp), "Math.cos(Infinity) is not NaN");
1641 tmp = Math.cos(-Infinity);
1642 ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN");
1644 tmp = Math.pow(2, 2);
1645 ok(tmp === 4, "Math.pow(2, 2) = " + tmp);
1647 tmp = Math.pow(4, 0.5);
1648 ok(tmp === 2, "Math.pow(2, 2) = " + tmp);
1650 tmp = Math.pow(2, 2, 3);
1651 ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
1653 tmp = Math.pow(2);
1654 ok(isNaN(tmp), "Math.pow(2) is not NaN");
1656 tmp = Math.pow();
1657 ok(isNaN(tmp), "Math.pow() is not NaN");
1659 tmp = Math.random();
1660 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
1661 ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp);
1663 tmp = Math.random(100);
1664 ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp));
1665 ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp);
1667 tmp = Math.acos(0);
1668 ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp);
1670 tmp = Math.acos(1);
1671 ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp);
1673 tmp = Math.acos(-1);
1674 ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp);
1676 tmp = Math.acos(Math.PI/4, 2);
1677 ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp);
1679 tmp = Math.acos(true);
1680 ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp);
1682 tmp = Math.acos(false);
1683 ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp);
1685 tmp = Math.acos(1.1);
1686 ok(isNaN(tmp), "Math.acos(1.1) is not NaN");
1688 tmp = Math.acos();
1689 ok(isNaN(tmp), "Math.acos() is not NaN");
1691 tmp = Math.acos(NaN);
1692 ok(isNaN(tmp), "Math.acos(NaN) is not NaN");
1694 tmp = Math.acos(Infinity);
1695 ok(isNaN(tmp), "Math.acos(Infinity) is not NaN");
1697 tmp = Math.acos(-Infinity);
1698 ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN");
1700 tmp = Math.asin(0);
1701 ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp);
1703 tmp = Math.asin(1);
1704 ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp);
1706 tmp = Math.asin(-1);
1707 ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp);
1709 tmp = Math.asin(Math.PI/4, 2);
1710 ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp);
1712 tmp = Math.asin(true);
1713 ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp);
1715 tmp = Math.asin(false);
1716 ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp);
1718 tmp = Math.asin(1.1);
1719 ok(isNaN(tmp), "Math.asin(1.1) is not NaN");
1721 tmp = Math.asin();
1722 ok(isNaN(tmp), "Math.asin() is not NaN");
1724 tmp = Math.asin(NaN);
1725 ok(isNaN(tmp), "Math.asin(NaN) is not NaN");
1727 tmp = Math.asin(Infinity);
1728 ok(isNaN(tmp), "Math.asin(Infinity) is not NaN");
1730 tmp = Math.asin(-Infinity);
1731 ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN");
1733 tmp = Math.atan(0);
1734 ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp);
1736 tmp = Math.atan(1);
1737 ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp);
1739 tmp = Math.atan(-1);
1740 ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp);
1742 tmp = Math.atan(true);
1743 ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp);
1745 tmp = Math.atan(false);
1746 ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp);
1748 tmp = Math.atan();
1749 ok(isNaN(tmp), "Math.atan() is not NaN");
1751 tmp = Math.atan(NaN);
1752 ok(isNaN(tmp), "Math.atan(NaN) is not NaN");
1754 tmp = Math.atan(Infinity);
1755 ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp);
1757 tmp = Math.atan(-Infinity);
1758 ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp);
1760 tmp = Math.atan2(0, 0);
1761 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp);
1763 tmp = Math.atan2(0, 1);
1764 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp);
1766 tmp = Math.atan2(0, Infinity);
1767 ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp);
1769 tmp = Math.atan2(0, -1);
1770 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp);
1772 tmp = Math.atan2(0, -Infinity);
1773 ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp);
1775 tmp = Math.atan2(1, 0);
1776 ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp);
1778 tmp = Math.atan2(Infinity, 0);
1779 ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp);
1781 tmp = Math.atan2(-1, 0);
1782 ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp);
1784 tmp = Math.atan2(-Infinity, 0);
1785 ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp);
1787 tmp = Math.atan2(1, 1);
1788 ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp);
1790 tmp = Math.atan2(-1, -1);
1791 ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp);
1793 tmp = Math.atan2(-1, 1);
1794 ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp);
1796 tmp = Math.atan2(Infinity, Infinity);
1797 ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp);
1799 tmp = Math.atan2(Infinity, -Infinity, 1);
1800 ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp);
1802 tmp = Math.atan2();
1803 ok(isNaN(tmp), "Math.atan2() is not NaN");
1805 tmp = Math.atan2(1);
1806 ok(isNaN(tmp), "Math.atan2(1) is not NaN");
1808 tmp = Math.exp(0);
1809 ok(tmp === 1, "Math.exp(0) = " + tmp);
1811 tmp = Math.exp(1);
1812 ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp);
1814 tmp = Math.exp(-1);
1815 ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp);
1817 tmp = Math.exp(true);
1818 ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp);
1820 tmp = Math.exp(1, 1);
1821 ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp);
1823 tmp = Math.exp();
1824 ok(isNaN(tmp), "Math.exp() is not NaN");
1826 tmp = Math.exp(NaN);
1827 ok(isNaN(tmp), "Math.exp(NaN) is not NaN");
1829 tmp = Math.exp(Infinity);
1830 ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp);
1832 tmp = Math.exp(-Infinity);
1833 ok(tmp === 0, "Math.exp(-Infinity) = " + tmp);
1835 tmp = Math.log(1);
1836 ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp);
1838 tmp = Math.log(-1);
1839 ok(isNaN(tmp), "Math.log(-1) is not NaN");
1841 tmp = Math.log(true);
1842 ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp);
1844 tmp = Math.log(1, 1);
1845 ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp);
1847 tmp = Math.log();
1848 ok(isNaN(tmp), "Math.log() is not NaN");
1850 tmp = Math.log(NaN);
1851 ok(isNaN(tmp), "Math.log(NaN) is not NaN");
1853 tmp = Math.log(Infinity);
1854 ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
1856 tmp = Math.log(-Infinity);
1857 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
1859 tmp = Math.sin(0);
1860 ok(tmp === 0, "Math.sin(0) = " + tmp);
1862 tmp = Math.sin(Math.PI/2);
1863 ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
1865 tmp = Math.sin(-Math.PI/2);
1866 ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
1868 tmp = Math.sin(Math.PI/3, 2);
1869 ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
1871 tmp = Math.sin(true);
1872 ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
1874 tmp = Math.sin(false);
1875 ok(tmp === 0, "Math.sin(false) = " + tmp);
1877 tmp = Math.sin();
1878 ok(isNaN(tmp), "Math.sin() is not NaN");
1880 tmp = Math.sin(NaN);
1881 ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
1883 tmp = Math.sin(Infinity);
1884 ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
1886 tmp = Math.sin(-Infinity);
1887 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
1889 tmp = Math.sqrt(0);
1890 ok(tmp === 0, "Math.sqrt(0) = " + tmp);
1892 tmp = Math.sqrt(4);
1893 ok(tmp === 2, "Math.sqrt(4) = " + tmp);
1895 tmp = Math.sqrt(-1);
1896 ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
1898 tmp = Math.sqrt(2, 2);
1899 ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
1901 tmp = Math.sqrt(true);
1902 ok(tmp === 1, "Math.sqrt(true) = " + tmp);
1904 tmp = Math.sqrt(false);
1905 ok(tmp === 0, "Math.sqrt(false) = " + tmp);
1907 tmp = Math.sqrt();
1908 ok(isNaN(tmp), "Math.sqrt() is not NaN");
1910 tmp = Math.sqrt(NaN);
1911 ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
1913 tmp = Math.sqrt(Infinity);
1914 ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
1916 tmp = Math.sqrt(-Infinity);
1917 ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
1919 tmp = Math.tan(0);
1920 ok(tmp === 0, "Math.tan(0) = " + tmp);
1922 tmp = Math.tan(Math.PI);
1923 ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp);
1925 tmp = Math.tan(2, 2);
1926 ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp);
1928 tmp = Math.tan(true);
1929 ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp);
1931 tmp = Math.tan(false);
1932 ok(tmp === 0, "Math.tan(false) = " + tmp);
1934 tmp = Math.tan();
1935 ok(isNaN(tmp), "Math.tan() is not NaN");
1937 tmp = Math.tan(NaN);
1938 ok(isNaN(tmp), "Math.tan(NaN) is not NaN");
1940 tmp = Math.tan(Infinity);
1941 ok(isNaN(tmp), "Math.tan(Infinity) is not NaN");
1943 tmp = Math.tan(-Infinity);
1944 ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN");
1946 (function() {
1947     if(invokeVersion < 2)
1948         return;
1950     var stringify_tests = [
1951         [[], undefined],
1952         [[true], "true"],
1953         [[false], "false"],
1954         [[null], "null"],
1955         [[nullDisp], undefined],
1956         [[1], "1"],
1957         [["test"], "\"test\""],
1958         [["test\"\\\b\f\n\r\t\u0002 !"], "\"test\\\"\\\\\\b\\f\\n\\r\\t\\u0002 !\""],
1959         [[NaN], "null"],
1960         [[Infinity], "null"],
1961         [[-Infinity], "null"],
1962         [[{prop1: true, prop2: "string", func1: function() {}}], "{\"prop1\":true,\"prop2\":\"string\"}"],
1963         [[{prop1: true, prop2: testObj, prop3: undefined}], "{\"prop1\":true}"],
1964         [[{prop1: true, prop2: {prop: "string"}},undefined,"  "],
1965                 "{\n  \"prop1\": true,\n  \"prop2\": {\n    \"prop\": \"string\"\n  }\n}"],
1966         [[{ },undefined," "], "{}"],
1967         [[[,2,undefined,3,{ },]],"[null,2,null,3,{},null]"],
1968         [[[,2,undefined,3,{prop:0},],undefined,"  "],"[\n  null,\n  2,\n  null,\n  3,\n  {\n    \"prop\": 0\n  },\n  null\n]"]
1969     ];
1971     var i, s, v, t;
1973     for(i=0; i < stringify_tests.length; i++) {
1974         s = JSON.stringify.apply(null, stringify_tests[i][0]);
1975         ok(s === stringify_tests[i][1],
1976            "["+i+"] stringify(" + stringify_tests[i][0] + ") returned " + s + " expected " + stringify_tests[i][1]);
1977     }
1979     s = JSON.stringify();
1980     ok(s === undefined, "stringify() returned " + s + " expected undefined");
1982     s = JSON.stringify(testObj);
1983     ok(s === undefined || s === "undefined" /* broken on some old versions */,
1984        "stringify(testObj) returned " + s + " expected undefined");
1986     s = JSON.stringify(undefined);
1987     ok(s === undefined || s === "undefined" /* broken on some old versions */,
1988        "stringify(undefined) returned " + s + " expected undefined");
1990     s = JSON.stringify(1, function(name, value) {
1991         ok(name === "", "name = " + name);
1992         ok(value === 1, "value = " + value);
1993         ok(this[name] === value, "this[" + name + "] = " + this[name] + " expected " + value);
1994         return 2;
1995     });
1996     ok(s == "2", "s = " + s);
1998     var o = { prop: 1 };
1999         s = JSON.stringify(1, function(name, value) {
2000         ok(name === "" || name === "prop", "name = " + name);
2001         ok(value === 1 || value === true, "value = " + value);
2002         ok(this[name] === value, "this[" + name + "] = " + this[name] + " expected " + value);
2003         if(name === "") return o;
2004         ok(this === o, "this != o");
2005         return value;
2006     });
2007     ok(s == "{\"prop\":1}", "s = " + s);
2009     var parse_tests = [
2010         ["true", true],
2011         ["   \nnull  ", null],
2012         ["{}", {}],
2013         ["\"\\r\\n test\\u1111\"", "\r\n test\u1111"],
2014         ["{\"x\" :\n true}", {x:true}],
2015         ["{\"x y\": {}, \"z\": {\"x\":null}}", {"x y":{}, z:{x:null}}],
2016         ["[]", []],
2017         ["[false,{},{\"x\": []}]", [false,{},{x:[]}]],
2018         ["0", 0],
2019         ["- 1", -1],
2020         ["1e2147483648", Infinity],
2021         ["0.5", 0.5],
2022         ["0e5", 0],
2023         [".5", 0.5]
2024     ];
2026     function json_cmp(x, y) {
2027         if(x === y)
2028             return true;
2030         if(!(x instanceof Object) || !(y instanceof Object))
2031             return false;
2033         for(var prop in x) {
2034             if(!x.hasOwnProperty(prop))
2035                 continue;
2036             if(!y.hasOwnProperty(prop))
2037                 return false;
2038             if(!json_cmp(x[prop], y[prop]))
2039                 return false;
2040         }
2042         for(var prop in y) {
2043             if(!x.hasOwnProperty(prop) && y.hasOwnProperty(prop))
2044                 return false;
2045         }
2047         return true;
2048     }
2050     for(i=0; i < parse_tests.length; i++) {
2051         v = JSON.parse(parse_tests[i][0]);
2052         ok(json_cmp(v, parse_tests[i][1]), "parse[" + i + "] returned " + v + ", expected " + parse_tests[i][1]);
2053     }
2055     v = [ [-1, "b"], {"length": -2, "0": -4, "1": -5}, [{}], [{"x": [null]}] ];
2056     s =
2057     '{' +
2058         '"foo": true,' +
2059         '"bar": [],' +
2060         '"baz": "remove_me",' +
2061         '"obj": {' +
2062         '    "arr": [ [1, "b"], {"length": 2, "0": 4, "1": 5}, [{}], [{"x": [null]}] ],' +
2063         '    "": "empty"' +
2064         '},' +
2065         '"last": false' +
2066     '}';
2067     o = JSON.parse(s), t = JSON.parse(s), i = new Object();
2068     i[""] = t;
2069     delete t.baz;   /* baz gets removed */
2070     t.obj.arr = v;  /* has negative values */
2072     var walk_expect = [
2073         [ o, "foo", true ],
2074         [ o, "bar", [] ],
2075         [ o, "baz", "remove_me" ],
2076         [ [1, "b"], "0", 1 ],
2077         [ [-1, "b"], "1", "b" ],
2078         [ [ [-1, "b"], {"length": 2, "0": 4, "1": 5}, [{}], [{"x": [null]}] ], "0", [-1, "b"] ],
2079         [ {"length": 2, "0": 4, "1": 5}, "length", 2 ],
2080         [ {"length": -2, "0": 4, "1": 5}, "0", 4 ],
2081         [ {"length": -2, "0": -4, "1": 5}, "1", 5 ],
2082         [ v, "1", {"length": -2, "0": -4, "1": -5} ],
2083         [ [{}], "0", {} ],
2084         [ v, "2", [{}] ],
2085         [ [null], "0", null ],
2086         [ {"x": [null]}, "x", [null] ],
2087         [ [{"x": [null]}], "0", {"x": [null]} ],
2088         [ v, "3", [{"x": [null]}] ],
2089         [ { "arr": v, "": "empty" }, "arr", v ],
2090         [ { "arr": v, "": "empty" }, "", "empty" ],
2091         [ t, "obj", { "arr": v, "": "empty" } ],
2092         [ t, "last", false ],
2093         [ i, "", t ]
2094     ];
2095     i = 0;
2096     v = JSON.parse(s, function(prop, value) {
2097         var a = [this, prop, value];
2098         ok(json_cmp(a, walk_expect[i]), "[walk step " + i + "] got [" + a + "], expected [" + walk_expect[i] + "]");
2099         i++;
2100         return (typeof value === 'number') ? -value : (value === "remove_me" ? undefined : value);
2101     });
2102     ok(i === walk_expect.length, "parse with reviver walked " + i + " steps, expected " + walk_expect.length);
2103     ok(json_cmp(v, t), "parse with reviver returned wrong object");
2105     v = JSON.parse('true', function(prop, value) { return prop === "" ? undefined : value; });
2106     ok(v === undefined, "parse with reviver removing last prop returned " + v);
2107     v = JSON.parse('true', function(prop, value) { return prop === "" ? false : value; });
2108     ok(v === false, "parse with reviver setting last prop to false returned " + v);
2109 })();
2111 var func = function  (a) {
2112         var a = 1;
2113         if(a) return;
2114     };
2115 ok(func.toString() === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
2116    "func.toString() = " + func.toString());
2117 ok("" + func === "function  (a) {\n        var a = 1;\n        if(a) return;\n    }",
2118    "'' + func.toString() = " + func);
2120 ok(func.valueOf === Object.prototype.valueOf, "func.valueOf !== Object.prototype.valueOf");
2121 ok(func === func.valueOf(), "func !== func.valueOf()");
2123 function testFuncToString(x,y) {
2124     return x+y;
2126 ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n    return x+y;\n}",
2127    "testFuncToString.toString() = " + testFuncToString.toString());
2128 ok("" + testFuncToString === "function testFuncToString(x,y) {\n    return x+y;\n}",
2129    "'' + testFuncToString = " + testFuncToString);
2131 tmp = new Object();
2133 function callTest(argc) {
2134     ok(this === tmp, "this !== tmp\n");
2135     ok(arguments.length === argc+1, "arguments.length = " + arguments.length + " expected " + (argc+1));
2136     for(var i=1; i <= argc; i++)
2137         ok(arguments[i] === i, "arguments[i] = " + arguments[i]);
2138     var a = arguments;
2139     for(var i=1; i <= argc; i++)
2140         ok(a[i] === i, "a[i] = " + a[i]);
2143 callTest.call(tmp, 1, 1);
2144 callTest.call(tmp, 2, 1, 2);
2145 callTest.call(tmp, 3, 1, 2, 3);
2147 callTest.apply(tmp, [1, 1]);
2148 callTest.apply(tmp, [2, 1, 2]);
2149 callTest.apply(tmp, [3, 1, 2, 3]);
2150 (function () { callTest.apply(tmp, arguments); })(2,1,2);
2152 function callTest2() {
2153     ok(this === tmp, "this !== tmp\n");
2154     ok(arguments.length === 0, "callTest2: arguments.length = " + arguments.length + " expected 0");
2157 callTest2.call(tmp);
2158 callTest2.apply(tmp, []);
2159 callTest2.apply(tmp);
2160 (function () { callTest2.apply(tmp, arguments); })();
2162 function callTest3() {
2163     testThis(this);
2164     ok(arguments.length === 0, "arguments.length = " + arguments.length + " expected 0");
2167 callTest3.call();
2168 callTest3.call(undefined);
2169 callTest3.call(null);
2170 callTest3.apply();
2171 callTest3.apply(undefined);
2172 callTest3.apply(null);
2174 tmp = Number.prototype.toString.call(3);
2175 ok(tmp === "3", "Number.prototype.toString.call(3) = " + tmp);
2177 var func = new Function("return 3;");
2179 tmp = func();
2180 ok(tmp === 3, "func() = " + tmp);
2181 ok(func.call() === 3, "func.call() = " + tmp);
2182 ok(func.length === 0, "func.length = " + func.length);
2183 tmp = func.toString();
2184 ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp);
2186 func = new Function("x", "return x+2;");
2187 tmp = func(1);
2188 ok(tmp === 3, "func(1) = " + tmp);
2189 tmp = func.toString();
2190 ok(tmp === "function anonymous(x) {\nreturn x+2;\n}", "func.toString() = " + tmp);
2192 tmp = (new Function("x ", "return x+2;")).toString();
2193 ok(tmp === "function anonymous(x ) {\nreturn x+2;\n}", "func.toString() = " + tmp);
2195 func = new Function("x", "y", "return x+y");
2196 tmp = func(1,3);
2197 ok(tmp === 4, "func(1,3) = " + tmp);
2198 tmp = func.toString();
2199 ok(tmp === "function anonymous(x, y) {\nreturn x+y\n}", "func.toString() = " + tmp);
2201 func = new Function(" x, \ty", "\tz", "return x+y+z;");
2202 tmp = func(1,3,2);
2203 ok(tmp === 6, "func(1,3,2) = " + tmp);
2204 ok(func.length === 3, "func.length = " + func.length);
2205 tmp = func.toString();
2206 ok(tmp === "function anonymous( x, \ty, \tz) {\nreturn x+y+z;\n}", "func.toString() = " + tmp);
2208 func = new Function();
2209 tmp = func();
2210 ok(tmp === undefined, "func() = " + tmp);
2211 tmp = func.toString();
2212 ok(tmp == "function anonymous() {\n\n}", "func.toString() = " + tmp);
2214 // Function constructor called as function
2215 func = Function("return 3;");
2217 tmp = func();
2218 ok(tmp === 3, "func() = " + tmp);
2219 ok(func.call() === 3, "func.call() = " + tmp);
2220 ok(func.length === 0, "func.length = " + func.length);
2221 tmp = func.toString();
2222 ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp);
2224 func = (function() {
2225         var tmp = 3;
2226         return new Function("return tmp;");
2227     })();
2228 tmp = 2;
2229 tmp = func();
2230 ok(tmp === 2, "func() = " + tmp);
2232 var date = new Date();
2234 date = new Date(100);
2235 ok(date.getTime() === 100, "date.getTime() = " + date.getTime());
2236 ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime());
2237 date = new Date(8.64e15);
2238 ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime());
2239 date = new Date(8.64e15+1);
2240 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
2241 date = new Date(Infinity);
2242 ok(isNaN(0+date.getTime()), "date.getTime() is not NaN");
2243 date = new Date("3 July 2009 22:28:00 UTC+0100");
2244 ok(date.getTime() === 1246656480000, "date.getTime() = " + date.getTime());
2245 date = new Date(1984, 11, 29, 13, 51, 24, 120);
2246 ok(date.getFullYear() === 1984, "date.getFullYear() = " + date.getFullYear());
2247 ok(date.getMonth() === 11, "date.getMonth() = " + date.getMonth());
2248 ok(date.getDate() === 29, "date.getDate() = " + date.getDate());
2249 ok(date.getHours() === 13, "date.getHours() = " + date.getHours());
2250 ok(date.getMinutes() === 51, "date.getMinutes() = " + date.getMinutes());
2251 ok(date.getSeconds() === 24, "date.getSeconds() = " + date.getSeconds());
2252 ok(date.getMilliseconds() === 120, "date.getMilliseconds() = " + date.getMilliseconds());
2253 date = new Date(731, -32, 40, -1, 70, 65, -13);
2254 ok(date.getFullYear() === 728, "date.getFullYear() = " + date.getFullYear());
2255 ok(date.getMonth() === 5, "date.getMonth() = " + date.getMonth());
2256 ok(date.getDate() === 9, "date.getDate() = " + date.getDate());
2257 ok(date.getHours() === 0, "date.getHours() = " + date.getHours());
2258 ok(date.getMinutes() === 11, "date.getMinutes() = " + date.getMinutes());
2259 ok(date.getSeconds() === 4, "date.getSeconds() = " + date.getSeconds());
2260 ok(date.getMilliseconds() === 987, "date.getMilliseconds() = " + date.getMilliseconds());
2262 ok(date.setTime(123) === 123, "date.setTime(123) !== 123");
2263 ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123");
2264 ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
2266 ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
2267 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
2268 ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
2269 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
2270 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
2271 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
2272 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
2273 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
2274 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2276 date.setTime(60*24*60*60*1000);
2277 ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
2278 ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
2279 ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
2280 ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay());
2281 ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours());
2282 ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes());
2283 ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds());
2284 ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2286 date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
2287 ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
2288 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2289 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2290 ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
2291 ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay());
2292 ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours());
2293 ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes());
2294 ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds());
2295 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2297 tmp = date.setYear(96);
2298 ok(date.getYear() === 96, "date.getYear() = " + date.getYear());
2299 ok(date.getFullYear() === 1996, "date.getFullYear() = " + date.getYear());
2300 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2301 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2302 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2304 tmp = date.setYear(2010);
2305 ok(tmp === date.getTime(), "date.setYear(2010) = " + tmp);
2306 ok(date.getYear() === 2010, "date.getYear() = " + date.getYear());
2307 ok(date.getFullYear() === 2010, "date.getFullYear() = " + date.getYear());
2308 ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2309 ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
2310 ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2312 date.setTime(Infinity);
2313 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
2314 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
2315 ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
2316 ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN");
2317 ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN");
2318 ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
2319 ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN");
2320 ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN");
2321 ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN");
2323 date.setTime(0);
2324 tmp = date.setYear(NaN);
2325 ok(isNaN(tmp), "date.setYear(NaN) = " + tmp);
2326 ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
2327 ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
2329 date.setTime(0);
2330 date.setUTCMilliseconds(-10, 2);
2331 ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2332 date.setUTCMilliseconds(10);
2333 ok(date.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds());
2334 date.setUTCSeconds(-10);
2335 ok(date.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date.getUTCSeconds());
2336 date.setUTCMinutes(-10);
2337 ok(date.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date.getUTCMinutes());
2338 date.setUTCHours(-10);
2339 ok(date.getUTCHours() === 14, "date.getUTCHours() = " + date.getUTCHours());
2340 date.setUTCHours(-123);
2341 ok(date.getTime() === -612549990, "date.getTime() = " + date.getTime());
2342 date.setUTCHours(20);
2343 ok(date.getUTCHours() === 20, "date.getUTCHours() = " + date.getUTCHours());
2344 date.setUTCDate(32);
2345 ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
2346 date.setUTCMonth(22, 37);
2347 ok(date.getTime() === 60987050010, "date.getTime() = " + date.getTime());
2348 date.setUTCFullYear(83, 21, 321);
2349 ok(date.getTime() === -59464984149990, "date.getTime() = " + date.getTime());
2350 ok(Math.abs(date) === 59464984149990, "Math.abs(date) = " + Math.abs(date));
2351 ok(getVT(date+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date+1));
2353 ok(isNaN(Date.parse()), "Date.parse() is not NaN");
2354 ok(isNaN(Date.parse("")), "Date.parse(\"\") is not NaN");
2355 ok(isNaN(Date.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN");
2356 ok(Date.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date.parse("Jan 20 2009 UTC"));
2357 ok(Date.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date.parse("Jan 20 2009 GMT"));
2358 ok(Date.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date.parse("Jan 20 2009 UTC-0"));
2359 ok(Date.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date.parse("Jan 20 2009 UTC+0000"));
2360 ok(Date.parse("Jan 20 2009 UTC-1") === 1232413200000, "Date.parse(\"Jan 20 2009 UTC-1\") = " + Date.parse("Jan 20 2009 UTC-1"));
2361 ok(Date.parse("Jan 20 2009 UTC+1") === 1232406000000, "Date.parse(\"Jan 20 2009 UTC+1\") = " + Date.parse("Jan 20 2009 UTC+1"));
2362 ok(Date.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date.parse("Ju 13 79 UTC"));
2363 ok(Date.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date.parse("12Au91 UTC"));
2364 ok(Date.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date.parse("7/02/17 UTC"));
2365 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"));
2366 ok(Date.parse("February 31   UTC, 2000 12:31:17 PM") === 952000277000,
2367         "Date.parse(\"February 31   UTC, 2000 12:31:17 PM\") = " + Date.parse("February 31   UTC, 2000 12:31:17 PM"));
2368 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 "));
2369 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"));
2370 ok(Date.parse("1970/01/01") === Date.parse("01/01/1970"), "Date.parse(\"1970/01/01\") = " + Date.parse("1970/01/01"));
2371 ok(Date.parse("71/12/14") === Date.parse("12/14/1971"), "Date.parse(\"71/12/14\") = " + Date.parse("71/12/14"));
2372 ok(Date.parse("Tue, 22 Mar 2016 09:57:55 -0300") === Date.parse("Tue, 22 Mar 2016 09:57:55 GMT-0300"),
2373         "Date.parse(\"Tue, 22 Mar 2016 09:57:55 -0300\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 -0300"));
2374 ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 2016 09:57:55 UTC+0400"),
2375         "Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 +0400"));
2377 tmp = (new Date()).toGMTString();
2378 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2379 tmp = (new Date()).toLocaleDateString();
2380 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2381 tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleDateString();
2382 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2383 tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleString();
2384 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2385 tmp = (new Date()).toLocaleTimeString();
2386 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2387 tmp = (new Date()).toString();
2388 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2389 tmp = (new Date()).toTimeString();
2390 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2391 tmp = (new Date()).toUTCString();
2392 ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
2394 ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
2395 ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
2396 Math.PI = "test";
2397 ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI);
2399 ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E));
2400 ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E);
2401 Math.E = "test";
2402 ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E);
2404 ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E));
2405 ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E);
2406 Math.LOG2E = "test";
2407 ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E);
2409 ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E));
2410 ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E);
2411 Math.LOG10E = "test";
2412 ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E);
2414 ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2));
2415 ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2);
2416 Math.LN2 = "test";
2417 ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2);
2419 ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10));
2420 ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10);
2421 Math.LN10 = "test";
2422 ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10);
2424 ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2));
2425 ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2);
2426 Math.SQRT2 = "test";
2427 ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2);
2429 ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2));
2430 ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2);
2431 Math.SQRT1_2 = "test";
2432 ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2);
2434 ok(isNaN.toString() === "\nfunction isNaN() {\n    [native code]\n}\n",
2435    "isNaN.toString = '" + isNaN.toString() + "'");
2436 ok(Array.toString() === "\nfunction Array() {\n    [native code]\n}\n",
2437    "Array.toString = '" + Array.toString() + "'");
2438 ok(Function.toString() === "\nfunction Function() {\n    [native code]\n}\n",
2439    "Function.toString = '" + Function.toString() + "'");
2440 ok(Function.prototype.toString() === "\nfunction prototype() {\n    [native code]\n}\n",
2441    "Function.prototype.toString = '" + Function.prototype.toString() + "'");
2442 ok("".substr.toString() === "\nfunction substr() {\n    [native code]\n}\n",
2443    "''.substr.toString = '" + "".substr.toString() + "'");
2445 var bool = new Boolean();
2446 ok(bool.toString() === "false", "bool.toString() = " + bool.toString());
2447 var bool = new Boolean("false");
2448 ok(bool.toString() === "true", "bool.toString() = " + bool.toString());
2449 ok(bool.valueOf() === Boolean(1), "bool.valueOf() = " + bool.valueOf());
2450 ok(bool.toLocaleString() === bool.toString(), "bool.toLocaleString() = " + bool.toLocaleString());
2452 tmp = Object.prototype.valueOf.call(nullDisp);
2453 ok(tmp === nullDisp, "nullDisp.valueOf != nullDisp");
2455 (function(global) {
2456     var i, context, code = "this.foobar = 1234";
2458     var direct = [
2459         function() { eval(code); },
2460         function() { (eval)(code); },
2461         function() { (function(eval) { eval(code); }).call(this, eval); },
2462         function() { eval("eval(" + code + ")"); }
2463     ];
2465     for(i = 0; i < direct.length; i++) {
2466         context = {};
2467         direct[i].call(context);
2468         ok(context.foobar === 1234, "direct[" + i + "] context foobar = " + context.foobar);
2469     }
2471     var indirect = [
2472         function() { (true, eval)(code); },
2473         function() { (eval, eval)(code); },
2474         function() { (true ? eval : false)(code); },
2475         function() { [eval][0](code); },
2476         function() { eval.call(this, code); },
2477         function() { var f; (f = eval)(code); },
2478         function() { var f = eval; f(code); },
2479         function() { (function(f) { f(code); }).call(this, eval); },
2480         function() { (function(f) { return f; }).call(this, eval)(code); },
2481         function() { (function() { arguments[0](code) }).call(this, eval); },
2482         function() { eval("eval")(code); }
2483     ];
2485     for(i = 0; i < indirect.length; i++) {
2486         context = {};
2487         ok(!("foobar" in global), "indirect[" + i + "] has global foobar before call");
2488         indirect[i].call(context);
2489         ok(context.foobar === 1234, "indirect[" + i + "] context foobar = " + context.foobar);
2490         ok(!("foobar" in global), "indirect[" + i + "] has global foobar");
2491     }
2493     context = {};
2494     (function(eval) { eval(code); })(function() { context.barfoo = 4321; });
2495     ok(context.barfoo === 4321, "context.barfoo = " + context.barfoo);
2496 })(this);
2498 ok(ActiveXObject instanceof Function, "ActiveXObject is not instance of Function");
2499 ok(ActiveXObject.prototype instanceof Object, "ActiveXObject.prototype is not instance of Object");
2501 ok(Error.prototype !== TypeError.prototype, "Error.prototype === TypeError.prototype");
2502 ok(RangeError.prototype !== TypeError.prototype, "RangeError.prototype === TypeError.prototype");
2503 ok(Error.prototype.toLocaleString === Object.prototype.toLocaleString,
2504         "Error.prototype.toLocaleString !== Object.prototype.toLocaleString");
2505 err = new Error();
2506 ok(err.valueOf === Object.prototype.valueOf, "err.valueOf !== Object.prototype.valueOf");
2507 ok(Error.prototype.name === "Error", "Error.prototype.name = " + Error.prototype.name);
2508 ok(err.name === "Error", "err.name = " + err.name);
2509 EvalError.prototype.message = "test";
2510 ok(EvalError.prototype.message === "test", "EvalError.prototype.message = " + EvalError.prototype.message);
2511 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
2512 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error"), "err.toString() = " + err.toString());
2513 err = new EvalError();
2514 ok(EvalError.prototype.name === "EvalError", "EvalError.prototype.name = " + EvalError.prototype.name);
2515 ok(err.name === "EvalError", "err.name = " + err.name);
2516 ok(err.toString === Error.prototype.toString, "err.toString !== Error.prototype.toString");
2517 ok(err.message === "", "err.message != ''");
2518 err.message = date;
2519 ok(err.message === date, "err.message != date");
2520 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "EvalError: "+err.message),
2521    "err.toString() = " + err.toString());
2522 ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString");
2523 err = new RangeError();
2524 ok(RangeError.prototype.name === "RangeError", "RangeError.prototype.name = " + RangeError.prototype.name);
2525 ok(err.name === "RangeError", "err.name = " + err.name);
2526 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "RangeError"), "err.toString() = " + err.toString());
2527 err = new ReferenceError();
2528 ok(ReferenceError.prototype.name === "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError.prototype.name);
2529 ok(err.name === "ReferenceError", "err.name = " + err.name);
2530 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "ReferenceError"), "err.toString() = " + err.toString());
2531 err = new SyntaxError();
2532 ok(SyntaxError.prototype.name === "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError.prototype.name);
2533 ok(err.name === "SyntaxError", "err.name = " + err.name);
2534 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "SyntaxError"), "err.toString() = " + err.toString());
2535 err = new TypeError();
2536 ok(TypeError.prototype.name === "TypeError", "TypeError.prototype.name = " + TypeError.prototype.name);
2537 ok(err.name === "TypeError", "err.name = " + err.name);
2538 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "TypeError"), "err.toString() = " + err.toString());
2539 err = new URIError();
2540 ok(URIError.prototype.name === "URIError", "URIError.prototype.name = " + URIError.prototype.name);
2541 ok(err.name === "URIError", "err.name = " + err.name);
2542 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "URIError"), "err.toString() = " + err.toString());
2543 err = new Error("message");
2544 ok(err.message === "message", "err.message !== 'message'");
2545 ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error: message"), "err.toString() = " + err.toString());
2546 err = new Error(123);
2547 ok(err.number === 123, "err.number = " + err.number);
2548 err.number = 254;
2549 ok(err.number === 254, "err.number = " + err.number);
2550 err = new Error(0, "message");
2551 ok(err.number === 0, "err.number = " + err.number);
2552 ok(err.message === "message", "err.message = " + err.message);
2553 ok(err.description === "message", "err.description = " + err.description);
2554 err = new Error();
2555 ok(err.number === 0, "err.number = " + err.number);
2556 ok(err.description === "", "err.description = " + err.description);
2557 err.description = 5;
2558 ok(err.description === 5, "err.description = " + err.description);
2559 ok(err.message === "", "err.message = " + err.message);
2560 err.message = 4;
2561 ok(err.message === 4, "err.message = " + err.message);
2563 ok(!("number" in Error), "number is in Error");
2565 tmp = new Object();
2566 ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited");
2567 tmp.toString = function() { return "test"; };
2568 ok(tmp.hasOwnProperty("toString") === true, "toString own property should exist");
2569 ok(tmp.hasOwnProperty("nonExisting") === false, "nonExisting property should not exist");
2571 tmp = Error.prototype.toString.call(tmp);
2572 ok(tmp === "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp);
2574 tmp = function() { return 0; };
2575 tmp[0] = true;
2576 ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited");
2577 ok(tmp.hasOwnProperty("0") === true, "hasOwnProperty(0) returned false");
2578 ok(tmp.hasOwnProperty() === false, "hasOwnProperty() returned true");
2580 ok(Object.prototype.hasOwnProperty.call(testObj) === false, "hasOwnProperty without name returned true");
2582 if(invokeVersion >= 2) {
2583     obj = new Object();
2584     obj.name = "test";
2585     tmp = Error.prototype.toString.call(obj);
2586     ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2588     obj = new Object();
2589     obj.name = 6;
2590     obj.message = false;
2591     tmp = Error.prototype.toString.call(obj);
2592     ok(tmp === "6: false", "Error.prototype.toString.call(obj) = " + tmp);
2594     obj = new Object();
2595     obj.message = "test";
2596     tmp = Error.prototype.toString.call(obj);
2597     ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2599     obj = new Object();
2600     obj.name = "";
2601     obj.message = "test";
2602     tmp = Error.prototype.toString.call(obj);
2603     ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
2606 tmp = Error.prototype.toString.call(testObj);
2607 ok(tmp === "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp);
2609 err = new Error();
2610 err.name = null;
2611 ok(err.name === null, "err.name = " + err.name + " expected null");
2612 if(invokeVersion >= 2)
2613     ok(err.toString() === "null", "err.toString() = " + err.toString());
2615 err = new Error();
2616 err.message = false;
2617 ok(err.message === false, "err.message = " + err.message + " expected false");
2618 if(invokeVersion >= 2)
2619     ok(err.toString() === "Error: false", "err.toString() = " + err.toString());
2621 err = new Error();
2622 err.message = new Object();
2623 err.message.toString = function() { return ""; };
2624 if(invokeVersion >= 2)
2625     ok(err.toString() === "Error", "err.toString() = " + err.toString());
2627 err = new Error();
2628 err.message = undefined;
2629 if(invokeVersion >= 2)
2630     ok(err.toString() === "Error", "err.toString() = " + err.toString());
2632 var exception_array = {
2633     E_INVALID_LENGTH:  { type: "RangeError",  number: -2146823259 },
2635     E_NOT_DATE:            { type: "TypeError",   number: -2146823282 },
2636     E_NOT_BOOL:            { type: "TypeError",   number: -2146823278 },
2637     E_ARG_NOT_OPT:         { type: "TypeError",   number: -2146827839 },
2638     E_NO_PROPERTY:         { type: "TypeError",   number: -2146827850 },
2639     E_NOT_NUM:             { type: "TypeError",   number: -2146823287 },
2640     E_INVALID_CALL_ARG:    { type: "TypeError",   number: -2146828283 },
2641     E_NOT_FUNC:            { type: "TypeError",   number: -2146823286 },
2642     E_OBJECT_EXPECTED:     { type: "TypeError", number: -2146823281 },
2643     E_OBJECT_REQUIRED:     { type: "TypeError", number: -2146827864 },
2644     E_UNSUPPORTED_ACTION:  { type: "TypeError", number: -2146827843 },
2645     E_REGEXP_EXPECTED:     { type: "TypeError", number: -2146823272 },
2646     E_NOT_ENUMERATOR:      { type: "TypeError", number: -2146823273 },
2647     E_NOT_VBARRAY:         { type: "TypeError", number: -2146823275 },
2648     E_INVALID_DELETE:      { type: "TypeError", number: -2146823276 },
2649     E_UNDEFINED:           { type: "TypeError", number: -2146823279 },
2650     E_JSCRIPT_EXPECTED:    { type: "TypeError", number: -2146823274 },
2651     E_NOT_ARRAY:           { type: "TypeError", number: -2146823257 },
2653     E_SYNTAX_ERROR:      { type: "SyntaxError",  number: -2146827286 },
2654     E_LBRACKET:          { type: "SyntaxError",  number: -2146827283 },
2655     E_RBRACKET:          { type: "SyntaxError",  number: -2146827282 },
2656     E_SEMICOLON:         { type: "SyntaxError",  number: -2146827284 },
2657     E_UNTERMINATED_STR:  { type: "SyntaxError",  number: -2146827273 },
2658     E_DISABLED_CC:       { type: "SyntaxError",  number: -2146827258 },
2659     E_INVALID_BREAK:     { type: "SyntaxError",  number: -2146827269 },
2660     E_INVALID_CONTINUE:  { type: "SyntaxError",  number: -2146827268 },
2661     E_LABEL_NOT_FOUND:   { type: "SyntaxError",  number: -2146827262 },
2662     E_LABEL_REDEFINED:   { type: "SyntaxError",  number: -2146827263 },
2663     E_MISPLACED_RETURN:  { type: "SyntaxError",  number: -2146827270 },
2665     E_ILLEGAL_ASSIGN:  { type: "ReferenceError", number: -2146823280 },
2667     E_PRECISION_OUT_OF_RANGE:        {type: "RangeError", number: -2146823261 },
2668     E_FRACTION_DIGITS_OUT_OF_RANGE:  {type: "RangeError", number: -2146823262 },
2669     E_SUBSCRIPT_OUT_OF_RANGE:        {type: "RangeError", number: -2146828279 },
2671     E_REGEXP_SYNTAX_ERROR:  { type: "RegExpError", number: -2146823271 },
2673     E_URI_INVALID_CHAR:     { type: "URIError", number: -2146823264 },
2674     E_URI_INVALID_CODING:   { type: "URIError", number: -2146823263 },
2676     E_STACK_OVERFLOW:       { type: "Error", number: -2146828260 }
2679 function testException(func, id) {
2680     var ex = exception_array[id];
2681     var ret = "", num = "";
2683     try {
2684         func();
2685     } catch(e) {
2686         ret = e.name;
2687         num = e.number;
2688     }
2690     ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed function: " + func.toString());
2691     ok(num === ex.number, "Exception test, num = " + num + " (" + (num + 0x80000000).toString(16) + "), expected " + ex.number
2692        + ". Executed function: " + func.toString());
2695 // RangeError tests
2696 testException(function() {Array(-3);}, "E_INVALID_LENGTH");
2697 testException(function() {createArray().lbound("aaa");}, "E_SUBSCRIPT_OUT_OF_RANGE");
2698 testException(function() {createArray().lbound(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
2699 testException(function() {createArray().getItem(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
2701 // TypeError tests
2702 testException(function() {date.setTime();}, "E_ARG_NOT_OPT");
2703 testException(function() {date.setYear();}, "E_ARG_NOT_OPT");
2704 testException(function() {arr.test();}, "E_NO_PROPERTY");
2705 testException(function() {[1,2,3].sort(nullDisp);}, "E_JSCRIPT_EXPECTED");
2706 testException(function() {var o = new Object(); o.length = 1; o[0] = "a"; Array.prototype.toLocaleString.call(o);}, "E_NOT_ARRAY");
2707 testException(function() {Number.prototype.toString.call(arr);}, "E_NOT_NUM");
2708 testException(function() {Number.prototype.toFixed.call(arr);}, "E_NOT_NUM");
2709 testException(function() {Number.prototype.toLocaleString.call(arr);}, "E_NOT_NUM");
2710 testException(function() {Number.prototype.toLocaleString.call(null);}, "E_NOT_NUM");
2711 testException(function() {(new Number(3)).toString(1);}, "E_INVALID_CALL_ARG");
2712 testException(function() {(new Number(3)).toString(undefined);}, "E_INVALID_CALL_ARG");
2713 testException(function() {(new Number(3)).toFixed(21);}, "E_FRACTION_DIGITS_OUT_OF_RANGE");
2714 testException(function() {(new Number(1)).toPrecision(0);}, "E_PRECISION_OUT_OF_RANGE");
2715 if(invokeVersion < 2)
2716     testException(function() {(new Number(1)).toPrecision(undefined);}, "E_PRECISION_OUT_OF_RANGE");
2717 testException(function() {not_existing_variable.something();}, "E_UNDEFINED");
2718 testException(function() {date();}, "E_NOT_FUNC");
2719 testException(function() {arr();}, "E_NOT_FUNC");
2720 testException(function() {(new Object) instanceof (new Object);}, "E_NOT_FUNC");
2721 testException(function() {eval("nonexistingfunc()")}, "E_OBJECT_EXPECTED");
2722 testException(function() {(new Object()) instanceof 3;}, "E_NOT_FUNC");
2723 testException(function() {(new Object()) instanceof null;}, "E_NOT_FUNC");
2724 testException(function() {(new Object()) instanceof nullDisp;}, "E_NOT_FUNC");
2725 testException(function() {nullDisp instanceof Object;}, "E_OBJECT_EXPECTED");
2726 testException(function() {Function.prototype.apply.call(nullDisp, Object, []);}, "E_OBJECT_REQUIRED");
2727 testException(function() {Function.prototype.call.call(nullDisp, Object);}, "E_OBJECT_REQUIRED");
2728 testException(function() {"test" in 3;}, "E_OBJECT_EXPECTED");
2729 testException(function() {"test" in null;}, "E_OBJECT_EXPECTED");
2730 testException(function() {"test" in nullDisp;}, "E_OBJECT_EXPECTED");
2731 testException(function() {new 3;}, "E_UNSUPPORTED_ACTION");
2732 testException(function() {new null;}, "E_OBJECT_EXPECTED");
2733 testException(function() {new nullDisp;}, "E_NO_PROPERTY");
2734 testException(function() {new Math.max(5);}, "E_UNSUPPORTED_ACTION");
2735 testException(function() {new VBArray();}, "E_NOT_VBARRAY");
2736 testException(function() {new VBArray(new VBArray(createArray()));}, "E_NOT_VBARRAY");
2737 testException(function() {VBArray.prototype.lbound.call(new Object());}, "E_NOT_VBARRAY");
2738 testException(function() {+nullDisp.prop;}, "E_OBJECT_REQUIRED");
2739 testException(function() {+nullDisp["prop"];}, "E_OBJECT_REQUIRED");
2740 testException(function() {delete (new Object());}, "E_INVALID_DELETE");
2741 testException(function() {delete false;}, "E_INVALID_DELETE");
2742 testException(function() {undefined.toString();}, "E_OBJECT_EXPECTED");
2743 testException(function() {null.toString();}, "E_OBJECT_EXPECTED");
2744 testException(function() {RegExp.prototype.toString.call(new Object());}, "E_REGEXP_EXPECTED");
2745 testException(function() {/a/.lastIndex();}, "E_NOT_FUNC");
2746 testException(function() {"a".length();}, "E_NOT_FUNC");
2747 testException(function() {((function() { var f = Number.prototype.toString; return (function() { return f(); }); })())();}, "E_NOT_NUM");
2748 testException(function() {((function() { var f = Object.prototype.hasOwnProperty; return (function() { return f("f"); }); })())();}, "E_OBJECT_EXPECTED");
2750 testException(function() { return arguments.callee(); }, "E_STACK_OVERFLOW");
2752 obj = new Object();
2753 obj.prop = 1;
2754 tmp = false;
2755 testException(function() {delete ((tmp = true) ? obj.prop : obj.prop);}, "E_INVALID_DELETE");
2756 ok(tmp, "delete (..) expression not evaluated");
2758 //FIXME: testException(function() {nonexistent++;}, "E_OBJECT_EXPECTED");
2759 //FIXME: testException(function() {undefined.nonexistent++;}, "E_OBJECT_EXPECTED");
2762 // SyntaxError tests
2763 function testSyntaxError(code, id) {
2764     var ex = exception_array[id];
2765     var ret = "", num = "";
2767     try {
2768         eval(code);
2769     } catch(e) {
2770         ret = e.name;
2771         num = e.number;
2772     }
2774     ok(ret === ex.type, "Syntax exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + code);
2775     ok(num === ex.number, "Syntax exception test, num = " + num + ", expected " + ex.number + ". Executed code: " + code);
2778 testSyntaxError("for(i=0;) {}", "E_SYNTAX_ERROR");
2779 testSyntaxError("function {};", "E_LBRACKET");
2780 testSyntaxError("if", "E_LBRACKET");
2781 testSyntaxError("do i=0; while", "E_LBRACKET");
2782 testSyntaxError("while", "E_LBRACKET");
2783 testSyntaxError("for", "E_LBRACKET");
2784 testSyntaxError("with", "E_LBRACKET");
2785 testSyntaxError("switch", "E_LBRACKET");
2786 testSyntaxError("if(false", "E_RBRACKET");
2787 testSyntaxError("for(i=0; i<10; i++", "E_RBRACKET");
2788 testSyntaxError("while(true", "E_RBRACKET");
2789 testSyntaxError("for(i=0", "E_SEMICOLON");
2790 testSyntaxError("for(i=0;i<10", "E_SEMICOLON");
2791 testSyntaxError("while(", "E_SYNTAX_ERROR");
2792 testSyntaxError("if(", "E_SYNTAX_ERROR");
2793 testSyntaxError("'unterminated", "E_UNTERMINATED_STR");
2794 testSyntaxError("*", "E_SYNTAX_ERROR");
2795 testSyntaxError("@_jscript_version", "E_DISABLED_CC");
2796 testSyntaxError("@a", "E_DISABLED_CC");
2797 testSyntaxError("/* @cc_on @*/ @_jscript_version", "E_DISABLED_CC");
2798 testSyntaxError("ok(false, 'unexpected execution'); break;", "E_INVALID_BREAK");
2799 testSyntaxError("ok(false, 'unexpected execution'); continue;", "E_INVALID_CONTINUE");
2800 testSyntaxError("ok(false, 'unexpected execution'); while(true) break unknown_label;", "E_LABEL_NOT_FOUND");
2801 testSyntaxError("ok(false, 'unexpected execution'); some_label: continue some_label;", "E_INVALID_CONTINUE");
2802 testSyntaxError("ok(false, 'unexpected execution'); while(true) continue some_label;", "E_LABEL_NOT_FOUND");
2803 testSyntaxError("ok(false, 'unexpected execution'); some_label: { while(true) continue some_label; }", "E_INVALID_CONTINUE");
2804 testSyntaxError("ok(false, 'unexpected execution'); some_label: { some_label: while(true); }", "E_LABEL_REDEFINED");
2805 testSyntaxError("return;", "E_MISPLACED_RETURN");
2806 testSyntaxError("001.5;", "E_SEMICOLON");
2807 testSyntaxError("001.5", "E_SEMICOLON");
2808 testSyntaxError("0a", "E_SEMICOLON");
2809 testSyntaxError("01a", "E_SEMICOLON");
2810 testSyntaxError("0x1r", "E_SEMICOLON");
2811 testSyntaxError("1a", "E_SEMICOLON");
2812 testSyntaxError("1_", "E_SEMICOLON");
2814 // ReferenceError tests
2815 testException(function() {test = function() {}}, "E_ILLEGAL_ASSIGN");
2817 tmp = false;
2818 testException(function() {test = (tmp = true);}, "E_ILLEGAL_ASSIGN");
2819 ok(tmp, "expr value on invalid assign not evaluated");
2821 tmp = false;
2822 testException(function() {(tmp = true) = false;}, "E_ILLEGAL_ASSIGN");
2823 ok(tmp, "expr assign not evaluated");
2825 tmp = false;
2826 testException(function() {true = (tmp = true);}, "E_ILLEGAL_ASSIGN");
2827 ok(tmp, "expr value assign not evaluated");
2829 tmp = "";
2830 testException(function() {(tmp = tmp+"1") = (tmp = tmp+"2");}, "E_ILLEGAL_ASSIGN");
2831 ok(tmp === "12", "assign evaluated in unexpected order");
2833 tmp = false;
2834 testException(function() { ((tmp = true) && false)++; }, "E_ILLEGAL_ASSIGN")
2835 ok(tmp, "incremented expression not evaluated");
2837 // RegExpError tests
2838 testException(function() {RegExp(/a/, "g");}, "E_REGEXP_SYNTAX_ERROR");
2840 // URIError tests
2841 testException(function() {encodeURI('\udcaa');}, "E_URI_INVALID_CHAR");
2842 testException(function() {encodeURIComponent('\udcaa');}, "E_URI_INVALID_CHAR");
2843 testException(function() {decodeURI('%');}, "E_URI_INVALID_CODING");
2844 testException(function() {decodeURI('%aaaa');}, "E_URI_INVALID_CODING");
2846 function testThisExcept(func, e) {
2847     testException(function() {func.call(new Object())}, e);
2850 function testBoolThis(func) {
2851     testThisExcept(Boolean.prototype[func], "E_NOT_BOOL");
2854 testBoolThis("toString");
2855 testBoolThis("valueOf");
2857 function testDateThis(func) {
2858     testThisExcept(Date.prototype[func], "E_NOT_DATE");
2861 testDateThis("getDate");
2862 testDateThis("getDay");
2863 testDateThis("getFullYear");
2864 testDateThis("getHours");
2865 testDateThis("getMilliseconds");
2866 testDateThis("getMinutes");
2867 testDateThis("getMonth");
2868 testDateThis("getSeconds");
2869 testDateThis("getTime");
2870 testDateThis("getTimezoneOffset");
2871 testDateThis("getUTCDate");
2872 testDateThis("getUTCDay");
2873 testDateThis("getUTCFullYear");
2874 testDateThis("getUTCHours");
2875 testDateThis("getUTCMilliseconds");
2876 testDateThis("getUTCMinutes");
2877 testDateThis("getUTCMonth");
2878 testDateThis("getUTCSeconds");
2879 testDateThis("getYear");
2880 testDateThis("setDate");
2881 testDateThis("setFullYear");
2882 testDateThis("setHours");
2883 testDateThis("setMilliseconds");
2884 testDateThis("setMinutes");
2885 testDateThis("setMonth");
2886 testDateThis("setSeconds");
2887 testDateThis("setTime");
2888 testDateThis("setUTCDate");
2889 testDateThis("setUTCFullYear");
2890 testDateThis("setUTCHours");
2891 testDateThis("setUTCMilliseconds");
2892 testDateThis("setUTCMinutes");
2893 testDateThis("setUTCMonth");
2894 testDateThis("setUTCSeconds");
2895 testDateThis("setYear");
2896 testDateThis("toDateString");
2897 testDateThis("toLocaleDateString");
2898 testDateThis("toLocaleString");
2899 testDateThis("toLocaleTimeString");
2900 testDateThis("toString");
2901 testDateThis("toTimeString");
2902 testDateThis("toUTCString");
2903 testDateThis("valueOf");
2905 function testArrayThis(func) {
2906     testThisExcept(Array.prototype[func], "E_NOT_ARRAY");
2909 testArrayThis("toString");
2911 function testFunctionThis(func) {
2912     testThisExcept(Function.prototype[func], "E_NOT_FUNC");
2915 testFunctionThis("toString");
2916 testFunctionThis("call");
2917 testFunctionThis("apply");
2919 function testArrayHostThis(func) {
2920     testException(function() { Array.prototype[func].call(testObj); }, "E_JSCRIPT_EXPECTED");
2923 testArrayHostThis("push");
2924 testArrayHostThis("shift");
2925 testArrayHostThis("slice");
2926 testArrayHostThis("splice");
2927 testArrayHostThis("unshift");
2928 testArrayHostThis("reverse");
2929 testArrayHostThis("join");
2930 testArrayHostThis("pop");
2931 testArrayHostThis("sort");
2933 function testEnumeratorThis(func) {
2934     testThisExcept(Enumerator.prototype[func], "E_NOT_ENUMERATOR");
2937 testEnumeratorThis("atEnd");
2938 testEnumeratorThis("item");
2939 testEnumeratorThis("moveFirst");
2940 testEnumeratorThis("moveNext");
2942 function testObjectInherit(obj, constr, ts, tls, vo) {
2943     ok(obj instanceof Object, "obj is not instance of Object");
2944     ok(obj instanceof constr, "obj is not instance of its constructor");
2946     ok(obj.hasOwnProperty === Object.prototype.hasOwnProperty,
2947        "obj.hasOwnProperty !== Object.prototype.hasOwnProprty");
2948     ok(obj.isPrototypeOf === Object.prototype.isPrototypeOf,
2949        "obj.isPrototypeOf !== Object.prototype.isPrototypeOf");
2950     ok(obj.propertyIsEnumerable === Object.prototype.propertyIsEnumerable,
2951        "obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable");
2953     if(ts)
2954         ok(obj.toString === Object.prototype.toString,
2955            "obj.toString !== Object.prototype.toString");
2956     else
2957         ok(obj.toString != Object.prototype.toString,
2958            "obj.toString == Object.prototype.toString");
2960     if(tls)
2961         ok(obj.toLocaleString === Object.prototype.toLocaleString,
2962            "obj.toLocaleString !== Object.prototype.toLocaleString");
2963     else
2964         ok(obj.toLocaleString != Object.prototype.toLocaleString,
2965            "obj.toLocaleString == Object.prototype.toLocaleString");
2967     if(vo)
2968         ok(obj.valueOf === Object.prototype.valueOf,
2969            "obj.valueOf !== Object.prototype.valueOf");
2970     else
2971         ok(obj.valueOf != Object.prototype.valueOf,
2972            "obj.valueOf == Object.prototype.valueOf");
2974     ok(obj._test === "test", "obj.test = " + obj._test);
2977 Object.prototype._test = "test";
2978 testObjectInherit(new String("test"), String, false, true, false);
2979 testObjectInherit(/test/g, RegExp, false, true, true);
2980 testObjectInherit(new Number(1), Number, false, false, false);
2981 testObjectInherit(new Date(), Date, false, false, false);
2982 testObjectInherit(new Boolean(true), Boolean, false, true, false);
2983 testObjectInherit(new Array(), Array, false, false, true);
2984 testObjectInherit(new Error(), Error, false, true, true);
2985 testObjectInherit(testObjectInherit, Function, false, true, true);
2986 testObjectInherit(Math, Object, true, true, true);
2988 (function() { testObjectInherit(arguments, Object, true, true, true); })();
2990 function testFunctions(obj, arr) {
2991     var l;
2993     for(var i=0; i<arr.length; i++) {
2994         l = obj[arr[i][0]].length;
2995         ok(l === arr[i][1], arr[i][0] + ".length = " + l);
2997         ok(obj.propertyIsEnumerable(arr[i][0]) === false, arr[i][0] + " is enumerable");
2998     }
3001 testFunctions(Boolean.prototype, [
3002         ["valueOf", 0],
3003         ["toString", 0]
3004     ]);
3006 testFunctions(Number.prototype, [
3007         ["valueOf", 0],
3008         ["toString", 1],
3009         ["toExponential", 1],
3010         ["toLocaleString", 0],
3011         ["toPrecision", 1]
3012     ]);
3014 testFunctions(String.prototype, [
3015         ["valueOf", 0],
3016         ["toString", 0],
3017         ["anchor", 1],
3018         ["big", 0],
3019         ["blink", 0],
3020         ["bold", 0],
3021         ["charAt", 1],
3022         ["charCodeAt", 1],
3023         ["concat", 1],
3024         ["fixed", 0],
3025         ["fontcolor", 1],
3026         ["fontsize", 1],
3027         ["indexOf", 2],
3028         ["italics", 0],
3029         ["lastIndexOf", 2],
3030         ["link", 1],
3031         ["localeCompare", 1],
3032         ["match", 1],
3033         ["replace", 1],
3034         ["search", 0],
3035         ["slice", 0],
3036         ["small", 0],
3037         ["split", 2],
3038         ["strike", 0],
3039         ["sub", 0],
3040         ["substr", 2],
3041         ["substring", 2],
3042         ["sup", 0],
3043         ["toLocaleLowerCase", 0],
3044         ["toLocaleUpperCase", 0],
3045         ["toLowerCase", 0],
3046         ["toUpperCase", 0]
3047     ]);
3049 testFunctions(RegExp.prototype, [
3050         ["toString", 0],
3051         ["exec", 1],
3052         ["test", 1]
3053     ]);
3055 testFunctions(Date.prototype, [
3056         ["getDate", 0],
3057         ["getDay", 0],
3058         ["getFullYear", 0],
3059         ["getHours", 0],
3060         ["getMilliseconds", 0],
3061         ["getMinutes", 0],
3062         ["getMonth", 0],
3063         ["getSeconds", 0],
3064         ["getTime", 0],
3065         ["getTimezoneOffset", 0],
3066         ["getUTCDate", 0],
3067         ["getUTCDay", 0],
3068         ["getUTCFullYear", 0],
3069         ["getUTCHours", 0],
3070         ["getUTCMilliseconds", 0],
3071         ["getUTCMinutes", 0],
3072         ["getUTCMonth", 0],
3073         ["getUTCSeconds", 0],
3074         ["getYear", 0],
3075         ["setDate", 1],
3076         ["setFullYear", 3],
3077         ["setHours", 4],
3078         ["setMilliseconds", 1],
3079         ["setMinutes", 3],
3080         ["setMonth", 2],
3081         ["setSeconds", 2],
3082         ["setTime", 1],
3083         ["setUTCDate", 1],
3084         ["setUTCFullYear", 3],
3085         ["setUTCHours", 4],
3086         ["setUTCMilliseconds", 1],
3087         ["setUTCMinutes", 3],
3088         ["setUTCMonth", 2],
3089         ["setUTCSeconds", 2],
3090         ["setYear", 1],
3091         ["toDateString", 0],
3092         ["toLocaleDateString", 0],
3093         ["toLocaleString", 0],
3094         ["toLocaleTimeString", 0],
3095         ["toString", 0],
3096         ["toTimeString", 0],
3097         ["toUTCString", 0],
3098         ["toGMTString", 0],
3099         ["valueOf", 0]
3100     ]);
3102 testFunctions(Array.prototype, [
3103         ["concat", 1],
3104         ["join", 1],
3105         ["push", 1],
3106         ["pop", 0],
3107         ["reverse", 0],
3108         ["shift", 0],
3109         ["slice", 2],
3110         ["sort", 1],
3111         ["splice", 2],
3112         ["toLocaleString", 0],
3113         ["toString", 0],
3114         ["unshift", 1]
3115     ]);
3117 testFunctions(Error.prototype, [
3118         ["toString", 0]
3119     ]);
3121 testFunctions(Math, [
3122         ["abs", 1],
3123         ["acos", 1],
3124         ["asin", 1],
3125         ["atan", 1],
3126         ["atan2", 2],
3127         ["ceil", 1],
3128         ["cos", 1],
3129         ["exp", 1],
3130         ["floor", 1],
3131         ["log", 1],
3132         ["max", 2],
3133         ["min", 2],
3134         ["pow", 2],
3135         ["random", 0],
3136         ["round", 1],
3137         ["sin", 1],
3138         ["sqrt", 1],
3139         ["tan", 1]
3140     ]);
3142 testFunctions(Object.prototype, [
3143         ["hasOwnProperty", 1],
3144         ["isPrototypeOf", 1],
3145         ["propertyIsEnumerable", 1],
3146         ["toLocaleString", 0],
3147         ["toString", 0],
3148         ["valueOf", 0]
3149     ]);
3151 testFunctions(Function.prototype, [
3152         ["apply", 2],
3153         ["call", 1],
3154         ["toString", 0]
3155     ]);
3157 testFunctions(VBArray.prototype, [
3158         ["dimensions", 0],
3159         ["getItem", 1],
3160         ["lbound", 0],
3161         ["toArray", 0],
3162         ["ubound", 0]
3165 if(invokeVersion < 2)
3166     ok(typeof(JSON) === "undefined", "JSON is not undefined");
3167 else
3168     testFunctions(JSON, [
3169         ["parse", 2],
3170         ["stringify", 3]
3171     ]);
3173 ok(ActiveXObject.length == 1, "ActiveXObject.length = " + ActiveXObject.length);
3174 ok(Array.length == 1, "Array.length = " + Array.length);
3175 ok(Boolean.length == 1, "Boolean.length = " + Boolean.length);
3176 ok(CollectGarbage.length == 0, "CollectGarbage.length = " + CollectGarbage.length);
3177 ok(Date.length == 7, "Date.length = " + Date.length);
3178 ok(Enumerator.length == 7, "Enumerator.length = " + Enumerator.length);
3179 ok(Error.length == 1, "Error.length = " + Error.length);
3180 ok(EvalError.length == 1, "EvalError.length = " + EvalError.length);
3181 ok(RegExpError.length == 1, "RegExpError.length = " + RegExpError.length);
3182 ok(Function.length == 1, "Function.length = " + Function.length);
3183 ok(GetObject.length == 2, "GetObject.length = " + GetObject.length);
3184 ok(Number.length == 1, "Number.length = " + Number.length);
3185 ok(Object.length == 0, "Object.length = " + Object.length);
3186 ok(RangeError.length == 1, "RangeError.length = " + RangeError.length);
3187 ok(ReferenceError.length == 1, "ReferenceError.length = " + ReferenceError.length);
3188 ok(RegExp.length == 2, "RegExp.length = " + RegExp.length);
3189 ok(ScriptEngine.length == 0, "ScriptEngine.length = " + ScriptEngine.length);
3190 ok(ScriptEngineBuildVersion.length == 0,
3191     "ScriptEngineBuildVersion.length = " + ScriptEngineBuildVersion.length);
3192 ok(ScriptEngineMajorVersion.length == 0,
3193     "ScriptEngineMajorVersion.length = " + ScriptEngineMajorVersion.length);
3194 ok(ScriptEngineMinorVersion.length == 0,
3195     "ScriptEngineMinorVersion.length = " + ScriptEngineMinorVersion.length);
3196 ok(String.length == 1, "String.length = " + String.length);
3197 ok(SyntaxError.length == 1, "SyntaxError.length = " + SyntaxError.length);
3198 ok(TypeError.length == 1, "TypeError.length = " + TypeError.length);
3199 ok(URIError.length == 1, "URIError.length = " + URIError.length);
3200 ok(VBArray.length == 1, "VBArray.length = " + VBArray.length);
3201 ok(decodeURI.length == 1, "decodeURI.length = " + decodeURI.length);
3202 ok(decodeURIComponent.length == 1, "decodeURIComponent.length = " + decodeURIComponent.length);
3203 ok(encodeURI.length == 1, "encodeURI.length = " + encodeURI.length);
3204 ok(encodeURIComponent.length == 1, "encodeURIComponent.length = " + encodeURIComponent.length);
3205 ok(escape.length == 1, "escape.length = " + escape.length);
3206 ok(eval.length == 1, "eval.length = " + eval.length);
3207 ok(isFinite.length == 1, "isFinite.length = " + isFinite.length);
3208 ok(isNaN.length == 1, "isNaN.length = " + isNaN.length);
3209 ok(parseFloat.length == 1, "parseFloat.length = " + parseFloat.length);
3210 ok(parseInt.length == 2, "parseInt.length = " + parseInt.length);
3211 ok(unescape.length == 1, "unescape.length = " + unescape.length);
3213 String.length = 3;
3214 ok(String.length == 1, "String.length = " + String.length);
3216 (function() {
3217     var tests = [
3218         [ "Array.sort",             JS_E_OBJECT_EXPECTED,        function(ctx) { Array.prototype.sort.call(ctx); } ],
3219         [ "Boolean.valueOf",        JS_E_BOOLEAN_EXPECTED,       function(ctx) { Boolean.prototype.valueOf.call(ctx); } ],
3220         [ "Date.getYear",           JS_E_DATE_EXPECTED,          function(ctx) { Date.prototype.getYear.call(ctx); } ],
3221         [ "Enumerator.atEnd",       JS_E_ENUMERATOR_EXPECTED,    function(ctx) { Enumerator.prototype.atEnd.call(ctx); } ],
3222         [ "Function.apply",         JS_E_FUNCTION_EXPECTED,      function(ctx) { Function.prototype.apply.call(ctx, [ function() {} ]); } ],
3223         [ "Number.toExponential",   JS_E_NUMBER_EXPECTED,        function(ctx) { Number.prototype.toExponential.call(ctx); } ],
3224         [ "Object.hasOwnProperty",  JS_E_OBJECT_EXPECTED,        function(ctx) { Object.prototype.hasOwnProperty.call(ctx, "toString"); } ],
3225         [ "RegExp.test",            JS_E_REGEXP_EXPECTED,        function(ctx) { RegExp.prototype.test.call(ctx, "foobar"); } ],
3226         [ "VBArray.lbound",         JS_E_VBARRAY_EXPECTED,       function(ctx) { VBArray.prototype.lbound.call(ctx); } ]
3227     ];
3229     for(var i = 0; i < tests.length; i++) {
3230         try {
3231             tests[i][2](null);
3232             ok(false, "expected exception calling " + tests[i][0] + " with null context");
3233         }catch(ex) {
3234             var n = ex.number >>> 0; /* make it unsigned like HRESULT */
3235             ok(n === tests[i][1], tests[i][0] + " with null context exception code = " + n);
3236         }
3237         try {
3238             tests[i][2](undefined);
3239             ok(false, "expected exception calling " + tests[i][0] + " with undefined context");
3240         }catch(ex) {
3241             var n = ex.number >>> 0;
3242             ok(n === tests[i][1], tests[i][0] + " with undefined context exception code = " + n);
3243         }
3244     }
3246     var r = Error.prototype.toString.call(undefined);
3247     ok(r === "[object Error]", "Error.toString with undefined context returned " + r);
3248     r = String.prototype.slice.call(null, 1, 3);
3249     ok(r === "ul", "String.slice with null context returned " + r);
3250     r = String.prototype.slice.call(undefined, 2, 5);
3251     ok(r === "def", "String.slice with undefined context returned " + r);
3252     r = (function() { return this; }).call(null);
3253     ok(r === test, "wrong 'this' of function with null context");
3254     r = (function() { return this; }).call(undefined);
3255     ok(r === test, "wrong 'this' of function with undefined context");
3256     r = (function() { return this; }).call(42);
3257     ok(r.valueOf() === 42, "'this' of function with 42 context = " + r);
3258 })();
3260 var tmp = createArray();
3261 ok(getVT(tmp) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp));
3262 ok(getVT(VBArray(tmp)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp)));
3263 VBArray(tmp);
3264 new VBArray(tmp);
3265 tmp = new VBArray(tmp);
3266 tmp = new VBArray(VBArray(createArray()));
3267 ok(tmp.dimensions() == 2, "tmp.dimensions() = " + tmp.dimensions());
3268 ok(tmp.lbound() == 0, "tmp.lbound() = " + tmp.lbound());
3269 ok(tmp.lbound(1) == 0, "tmp.lbound(1) = " + tmp.lbound(1));
3270 ok(tmp.lbound(2, 1) == 2, "tmp.lbound(2, 1) = " + tmp.lbound(2, 1));
3271 ok(tmp.ubound() == 4, "tmp.ubound() = " + tmp.ubound());
3272 ok(tmp.ubound("2") == 3, "tmp.ubound(\"2\") = " + tmp.ubound("2"));
3273 ok(tmp.getItem(1, 2) == 3, "tmp.getItem(1, 2) = " + tmp.getItem(1, 2));
3274 ok(tmp.getItem(2, 3) == 33, "tmp.getItem(2, 3) = " + tmp.getItem(2, 3));
3275 ok(tmp.getItem(3, 2) == 13, "tmp.getItem(3, 2) = " + tmp.getItem(3, 2));
3276 ok(tmp.toArray() == "2,3,12,13,22,23,32,33,42,43", "tmp.toArray() = " + tmp.toArray());
3277 ok(createArray().toArray() == "2,3,12,13,22,23,32,33,42,43",
3278         "createArray.toArray()=" + createArray().toArray());
3280 obj = new Enumerator();
3281 ok(obj.atEnd(), "atEnd() = " + obj.atEnd());
3282 obj.moveFirst();
3283 ok(obj.atEnd(), "atEnd() = " + obj.atEnd());
3285 reportSuccess();