2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
21 var bigInt
= Math
.pow(2,40);
23 ok(ScriptEngine() === "JScript", "ScriptEngine() = " + ScriptEngine());
24 ok(ScriptEngine(3) === "JScript", "ScriptEngine(3) = " + ScriptEngine(3));
25 ok(ScriptEngineMajorVersion() === ScriptEngineMajorVersion(2), "ScriptEngineMajorVersion() !== ScriptEngineMajorVersion(2)");
26 ok(ScriptEngineMinorVersion() === ScriptEngineMinorVersion(2), "ScriptEngineMinorVersion() !== ScriptEngineMinorVersion(2)");
27 ok(ScriptEngineBuildVersion() === ScriptEngineBuildVersion(2), "ScriptEngineBuildVersion() !== ScriptEngineBuildVersion(2)");
29 function testNoEnumerables(expr
) {
31 ok(false, expr
+ " has property " + iter
);
34 testNoEnumerables("Object");
35 testNoEnumerables("Object.prototype");
36 testNoEnumerables("new Object()");
37 testNoEnumerables("Math");
38 testNoEnumerables("String");
39 testNoEnumerables("String.prototype");
40 testNoEnumerables("new String()");
41 testNoEnumerables("Number");
42 testNoEnumerables("Number.prototype");
43 testNoEnumerables("new Number(1)");
44 testNoEnumerables("ActiveXObject");
45 testNoEnumerables("Array");
46 testNoEnumerables("Array.prototype");
47 testNoEnumerables("new Array()");
48 testNoEnumerables("Boolean");
49 testNoEnumerables("Boolean.prototype");
50 testNoEnumerables("new Boolean()");
51 testNoEnumerables("Date");
52 testNoEnumerables("Date.prototype");
53 testNoEnumerables("new Date()");
54 testNoEnumerables("TypeError");
55 testNoEnumerables("TypeError.prototype");
56 testNoEnumerables("new TypeError()");
57 testNoEnumerables("Function");
58 testNoEnumerables("Function.prototype");
59 testNoEnumerables("testNoEnumerates");
60 testNoEnumerables("VBArray");
62 ok(Object
.propertyIsEnumerable("prototype") === false, "Object.prototype is enumerable");
63 ok(Math
.propertyIsEnumerable("E") === false, "Math.E is enumerable");
64 ok(Math
.propertyIsEnumerable("SQRT2") === false, "Math.SQRT2 is enumerable");
65 ok(Math
.propertyIsEnumerable("PI") === false, "Math.PI is enumerable");
66 ok("test".propertyIsEnumerable("length") === false, "'test'.length is enumerable");
67 ok([1].propertyIsEnumerable("length") === false, "[1].length is enumerable");
68 ok((new TypeError()).propertyIsEnumerable("message") === true, "(new TypeError()).message is not enumerable");
69 ok((new TypeError()).propertyIsEnumerable("description") === false, "(new TypeError()).description is enumerable");
70 ok((new TypeError()).propertyIsEnumerable("name") === false, "(new TypeError()).name is enumerable");
71 ok((new TypeError()).propertyIsEnumerable("number") === false, "(new TypeError()).number is enumerable");
72 ok(Object
.propertyIsEnumerable
.propertyIsEnumerable("length") === false, "Object.propertyIsEnumerable.length is enumerable");
76 ok(tmp
.propertyIsEnumerable("test"), "tmp.test is not enumerable");
79 ok(tmp
.propertyIsEnumerable("test"), "tmp.test is not enumerable");
81 ok([1].concat([2]).propertyIsEnumerable("1"), "[1].concat([2]).1 is not enumerable");
82 ok("t.e.s.t".split(".").propertyIsEnumerable("0"), "'test'.split().0 is not enumerable");
85 ok(arguments
.propertyIsEnumerable("0") === false, "arguments.0 is enumerable");
86 ok(arguments
.propertyIsEnumerable("length") === false, "arguments.length is enumerable");
87 ok(arguments
.propertyIsEnumerable("calee") === false, "arguments.calee is enumerable");
92 ok(tmp
.propertyIsEnumerable("1"), "[1].push() ... 1 is not enumerable");
94 ok([1,2].reverse().propertyIsEnumerable("1"), "[1,2].rverse().1 is not enumerable");
95 ok([1,2].propertyIsEnumerable("0"), "[1,2].0 is not enumerable");
98 ok(i
=== 0, "parseInt('0') = " + i
);
100 ok(i
=== 123, "parseInt('123') = " + i
);
101 i
= parseInt("-123");
102 ok(i
=== -123, "parseInt('-123') = " + i
);
103 i
= parseInt("0xff");
104 ok(i
=== 0xff, "parseInt('0xff') = " + i
);
105 i
= parseInt("11", 8);
106 ok(i
=== 9, "parseInt('11', 8) = " + i
);
107 i
= parseInt("1j", 22);
108 ok(i
=== 41, "parseInt('1j', 32) = " + i
);
109 i
= parseInt("123", 0);
110 ok(i
=== 123, "parseInt('123', 0) = " + i
);
111 i
= parseInt("123", 10, "test");
112 ok(i
=== 123, "parseInt('123', 10, 'test') = " + i
);
113 i
= parseInt("11", "8");
114 ok(i
=== 9, "parseInt('11', '8') = " + i
);
116 ok(i
=== 8, "parseInt('010') = " + i
);
118 ok(isNaN(i
), "parseInt('') = " + i
);
120 ok(isNaN(i
), "parseInt('0x') = " + i
);
122 ok(isNaN(i
), "parseInt('+') = " + i
);
124 ok(isNaN(i
), "parseInt('-') = " + i
);
125 i
= parseInt("0x10", 11);
126 ok(i
=== 0, "parseInt('0x10', 11) = " + i
);
127 i
= parseInt("010", 7);
128 ok(i
=== 7, "parseInt('010', 7) = " + i
);
129 i
= parseInt("123abc");
130 ok(i
=== 123, "parseInt('123abc') = " + i
);
131 i
= parseInt(" \t123abc");
132 ok(i
=== 123, "parseInt(' \\t123abc') = " + i
);
134 ok(isNaN(i
), "parseInt('123abc') = " + i
);
135 i
= parseInt("-12", 11);
136 ok(i
=== -13, "parseInt('-12') = " + i
);
137 i
= parseInt("-0x10");
138 ok(i
=== -16, "parseInt('-0x10') = " + i
);
139 i
= parseInt("-010");
140 ok(i
=== -8, "parseInt('-010') = " + i
);
141 i
= parseInt("123", 0);
142 ok(i
=== 123, "parseInt('123', 0) = " + i
);
143 i
= parseInt("0x10", 0);
144 ok(i
=== 16, "parseInt('123', 0) = " + i
);
145 i
= parseInt("0x10", 10);
146 ok(i
=== 0, "parseInt('0x10', 10) = " + i
);
148 ok(isNaN(i
), "parseInt('0xz') = " + i
);
149 i
= parseInt("1", 1);
150 ok(isNaN(i
), "parseInt('1', 1) = " + i
);
151 i
= parseInt("1", -1);
152 ok(isNaN(i
), "parseInt('1', -1) = " + i
);
153 i
= parseInt("1", 37);
154 ok(isNaN(i
), "parseInt('1', 37) = " + i
);
155 i
= parseInt("1", 36);
156 ok(i
=== 1, "parseInt('1', 36) = " + i
);
158 tmp
= encodeURI("abc");
159 ok(tmp
=== "abc", "encodeURI('abc') = " + tmp
);
160 tmp
= encodeURI("{abc}");
161 ok(tmp
=== "%7Babc%7D", "encodeURI('{abc}') = " + tmp
);
163 ok(tmp
=== "", "encodeURI('') = " + tmp
);
164 tmp
= encodeURI("\01\02\03\04");
165 ok(tmp
=== "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp
);
166 tmp
= encodeURI("{#@}");
167 ok(tmp
=== "%7B#@%7D", "encodeURI('{#@}') = " + tmp
);
168 tmp
= encodeURI("\xa1 ");
169 ok(tmp
=== "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp
);
170 tmp
= encodeURI("\xffff");
171 ok(tmp
.length
=== 8, "encodeURI('\\xffff').length = " + tmp
.length
);
172 tmp
= encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
173 ok(tmp
=== "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp
);
174 tmp
= encodeURI("%");
175 ok(tmp
=== "%25", "encodeURI('%') = " + tmp
);
177 ok(tmp
=== "undefined", "encodeURI() = " + tmp
);
178 tmp
= encodeURI("abc", "test");
179 ok(tmp
=== "abc", "encodeURI('abc') = " + tmp
);
181 tmp
= decodeURI("abc");
182 ok(tmp
=== "abc", "decodeURI('abc') = " + tmp
);
183 tmp
= decodeURI("{abc}");
184 ok(tmp
=== "{abc}", "decodeURI('{abc}') = " + tmp
);
186 ok(tmp
=== "", "decodeURI('') = " + tmp
);
187 tmp
= decodeURI("\01\02\03\04");
188 ok(tmp
=== "\01\02\03\04", "decodeURI('\\01\\02\\03\\04') = " + tmp
);
190 ok(tmp
=== "undefined", "decodeURI() = " + tmp
);
191 tmp
= decodeURI("abc", "test");
192 ok(tmp
=== "abc", "decodeURI('abc') = " + tmp
);
193 tmp
= decodeURI("%7babc%7d");
194 ok(tmp
=== "{abc}", "decodeURI('%7Babc%7D') = " + tmp
);
195 tmp
= decodeURI("%01%02%03%04");
196 ok(tmp
=== "\01\02\03\04", "decodeURI('%01%02%03%04') = " + tmp
);
197 tmp
= decodeURI("%C2%A1%20");
198 ok(tmp
=== "\xa1 ", "decodeURI('%C2%A1%20') = " + tmp
);
199 tmp
= decodeURI("%C3%BFff");
200 ok(tmp
.length
=== 3, "decodeURI('%C3%BFff').length = " + tmp
.length
);
202 tmp
= encodeURIComponent("abc");
203 ok(tmp
=== "abc", "encodeURIComponent('abc') = " + tmp
);
204 dec
= decodeURIComponent(tmp
);
205 ok(dec
=== "abc", "decodeURIComponent('" + tmp
+ "') = " + dec
);
206 tmp
= encodeURIComponent("{abc}");
207 ok(tmp
=== "%7Babc%7D", "encodeURIComponent('{abc}') = " + tmp
);
208 dec
= decodeURIComponent(tmp
);
209 ok(dec
=== "{abc}", "decodeURIComponent('" + tmp
+ "') = " + dec
);
210 tmp
= encodeURIComponent("");
211 ok(tmp
=== "", "encodeURIComponent('') = " + tmp
);
212 dec
= decodeURIComponent(tmp
);
213 ok(dec
=== "", "decodeURIComponent('" + tmp
+ "') = " + dec
);
214 tmp
= encodeURIComponent("\01\02\03\04");
215 ok(tmp
=== "%01%02%03%04", "encodeURIComponent('\\01\\02\\03\\04') = " + tmp
);
216 dec
= decodeURIComponent(tmp
);
217 ok(dec
=== "\01\02\03\04", "decodeURIComponent('" + tmp
+ "') = " + dec
);
218 tmp
= encodeURIComponent("{#@}");
219 ok(tmp
=== "%7B%23%40%7D", "encodeURIComponent('{#@}') = " + tmp
);
220 dec
= decodeURIComponent(tmp
);
221 ok(dec
=== "{#@}", "decodeURIComponent('" + tmp
+ "') = " + dec
);
222 tmp
= encodeURIComponent("\xa1 ");
223 ok(tmp
=== "%C2%A1%20", "encodeURIComponent(\\xa1 ) = " + tmp
);
224 dec
= decodeURIComponent(tmp
);
225 ok(dec
=== "\xa1 ", "decodeURIComponent('" + tmp
+ "') = " + dec
);
226 tmp
= encodeURIComponent("\xffff");
227 ok(tmp
.length
=== 8, "encodeURIComponent('\\xffff').length = " + tmp
.length
);
228 dec
= decodeURIComponent(tmp
);
229 ok(dec
=== "\xffff", "decodeURIComponent('" + tmp
+ "') = " + dec
);
230 tmp
= encodeURIComponent("abcABC123;/?:@&=+$,-_.!~*'()");
231 ok(tmp
=== "abcABC123%3B%2F%3F%3A%40%26%3D%2B%24%2C-_.!~*'()", "encodeURIComponent('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp
);
232 dec
= decodeURIComponent(tmp
);
233 ok(dec
=== "abcABC123;/?:@&=+$,-_.!~*'()", "decodeURIComponent('" + tmp
+ "') = " + dec
);
234 tmp
= encodeURIComponent();
235 ok(tmp
=== "undefined", "encodeURIComponent() = " + tmp
);
236 tmp
= encodeURIComponent("abc", "test");
237 ok(tmp
=== "abc", "encodeURIComponent('abc') = " + tmp
);
238 dec
= decodeURIComponent();
239 ok(dec
=== "undefined", "decodeURIComponent() = " + dec
);
240 dec
= decodeURIComponent("abc", "test");
241 ok(dec
=== "abc", "decodeURIComponent('abc') = " + dec
);
244 ok(tmp
=== "abc", "escape('abc') = " + tmp
);
246 ok(tmp
=== "", "escape('') = " + tmp
);
247 tmp
= escape("a1b c!d+e@*-_+./,");
248 ok(tmp
=== "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp
);
250 ok(tmp
=== "undefined", "escape() = " + tmp
);
251 tmp
= escape('\u1234\123\xf3');
252 ok(tmp
== "%u1234S%F3", "escape('\u1234\123\xf3') = " + tmp
);
254 tmp
= unescape("abc");
255 ok(tmp
=== "abc", "unescape('abc') = " + tmp
);
257 ok(tmp
=== "", "unescape('') = " + tmp
);
258 tmp
= unescape("%%%");
259 ok(tmp
=== "%%%", "unescape('%%%') = " + tmp
);
261 ok(tmp
=== "undefined", "unescape() = " + tmp
);
262 tmp
= unescape("%54%65s%u0074");
263 ok(tmp
=== "Test", "unescape('%54%65s%u0074') = " + tmp
);
265 tmp
= "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|";
266 ok(escape(tmp
) === "aA1%7E%60%21@%23%24%25%5E%26*%28%29_+%3D-%5D%5B%7B%7D%27%3B%3A/.%2C%3C%3E%3F%7C", "escape('" + tmp
+ "') = " + escape(tmp
));
267 ok(unescape(escape(tmp
)) === tmp
, "unescape(escape('" + tmp
+ "')) = " + unescape(escape(tmp
)));
269 ok(Object
.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty('toString') is false");
270 ok(Object
.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false");
271 ok(Function
.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false");
275 ok(!obj
.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
276 ok(!obj
.hasOwnProperty('isPrototypeOf'), "obj.hasOwnProperty('isPrototypeOf') is true");
277 ok(!Object
.hasOwnProperty('toString'), "Object.hasOwnProperty('toString') is true");
278 ok(!Object
.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeOf') is true");
279 ok(!parseFloat
.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true");
280 ok(!Function
.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true");
283 ok(Array
.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false");
284 ok(Array
.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false");
285 ok(!obj
.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true");
286 ok(obj
.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true");
288 obj
= new Boolean(false);
289 ok(!obj
.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
290 ok(!Boolean
.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true");
291 ok(Boolean
.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false");
294 ok(!obj
.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
295 ok(!Date
.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
296 ok(Date
.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
297 ok(!("now" in Date
), "now found in Date");
300 ok(!obj
.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
301 ok(!Number
.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true");
302 ok(Number
.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false");
305 ok(!obj
.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true");
306 ok(obj
.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false");
307 ok(!RegExp
.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true");
308 ok(!RegExp
.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true");
309 ok(RegExp
.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false");
312 ok(!obj
.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true");
313 ok(obj
.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false");
314 ok(!String
.hasOwnProperty('charAt'), "String.hasOwnProperty('charAt') is true");
315 ok(String
.prototype.hasOwnProperty('charAt'), "String.prototype.hasOwnProperty('charAt') is false");
316 ok(String
.prototype.hasOwnProperty('length'), "String.prototype.hasOwnProperty('length') is false");
318 tmp
= "" + new Object();
319 ok(tmp
=== "[object Object]", "'' + new Object() = " + tmp
);
320 (tmp
= new Array
).f
= Object
.prototype.toString
;
321 ok(tmp
.f() === "[object Array]", "tmp.f() = " + tmp
.f());
322 (tmp
= new Boolean
).f
= Object
.prototype.toString
;
323 ok(tmp
.f() === "[object Boolean]", "tmp.f() = " + tmp
.f());
324 (tmp
= new Date
).f
= Object
.prototype.toString
;
325 ok(tmp
.f() === "[object Date]", "tmp.f() = " + tmp
.f());
326 (tmp = function() {}).f
= Object
.prototype.toString
;
327 ok(tmp
.f() === "[object Function]", "tmp.f() = " + tmp
.f());
328 Math
.f
= Object
.prototype.toString
;
329 ok(Math
.f() === "[object Math]", "tmp.f() = " + tmp
.f());
330 (tmp
= new Number
).f
= Object
.prototype.toString
;
331 ok(tmp
.f() === "[object Number]", "tmp.f() = " + tmp
.f());
332 (tmp
= new RegExp("")).f
= Object
.prototype.toString
;
333 ok(tmp
.f() === "[object RegExp]", "tmp.f() = " + tmp
.f());
334 (tmp
= new String
).f
= Object
.prototype.toString
;
335 ok(tmp
.f() === "[object String]", "tmp.f() = " + tmp
.f());
336 tmp
= Object
.prototype.toString
.call(testObj
);
337 ok(tmp
=== "[object Object]", "toString.call(testObj) = " + tmp
);
338 tmp
= Object
.prototype.toString
.call(this);
339 ok(tmp
=== "[object Object]", "toString.call(this) = " + tmp
);
340 (function () { tmp
= Object
.prototype.toString
.call(arguments
); })();
341 ok(tmp
=== "[object Object]", "toString.call(arguments) = " + tmp
);
342 tmp
= Object
.prototype.toString
.call(new VBArray(createArray()));
343 ok(tmp
=== "[object Object]", "toString.call(new VBArray()) = " + tmp
);
345 function TSTestConstr() {}
346 TSTestConstr
.prototype = { toString: function() { return "test"; } };
347 obj
= new TSTestConstr();
348 ok(obj
.toString() === "test", "obj.toString() = " + obj
.toString());
350 ok(Object(1) instanceof Number
, "Object(1) is not instance of Number");
351 ok(Object("") instanceof String
, "Object('') is not instance of String");
352 ok(Object(false) instanceof Boolean
, "Object(false) is not instance of Boolean");
354 ok(new Object(1) instanceof Number
, "Object(1) is not instance of Number");
355 ok(new Object("") instanceof String
, "Object('') is not instance of String");
356 ok(new Object(false) instanceof Boolean
, "Object(false) is not instance of Boolean");
359 ok(Object(obj
) === obj
, "Object(obj) !== obj");
361 ok(typeof(Object()) === "object", "typeof(Object()) !== 'object'");
362 ok(typeof(Object(undefined)) === "object", "typeof(Object(undefined)) !== 'object'");
363 ok(typeof(Object(null)) === "object", "typeof(Object(null)) !== 'object'");
364 ok(typeof(Object(nullDisp
)) === "object", "typeof(Object(nullDisp)) !== 'object'");
366 ok(Object(nullDisp
) != nullDisp
, "Object(nullDisp) == nullDisp");
367 ok(new Object(nullDisp
) != nullDisp
, "new Object(nullDisp) == nullDisp");
369 ok(Object(testObj
) === testObj
, "Object(testObj) != testObj\n");
370 ok(new Object(testObj
) === testObj
, "new Object(testObj) != testObj\n");
373 ok(Object(tmp
) === tmp
, "Object(tmp) != tmp");
374 ok(new Object(tmp
) === tmp
, "new Object(tmp) != tmp");
376 var obj
= new Object();
377 obj
.toString = function (x
) {
378 ok(arguments
.length
=== 0, "arguments.length = " + arguments
.length
);
381 ok((tmp
= obj
.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp
);
382 ok((tmp
= obj
.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp
);
383 ok(obj
=== obj
.valueOf(), "obj !== obj.valueOf");
385 ok("".length
=== 0, "\"\".length = " + "".length
);
386 ok(getVT("".length
) == "VT_I4", "\"\".length = " + "".length
);
387 ok("abc".length
=== 3, "\"abc\".length = " + "abc".length
);
388 ok(String
.prototype.length
=== 0, "String.prototype.length = " + String
.prototype.length
);
391 ok(tmp
=== "", "''.toString() = " + tmp
);
392 tmp
= "test".toString();
393 ok(tmp
=== "test", "''.toString() = " + tmp
);
394 tmp
= "test".toString(3);
395 ok(tmp
=== "test", "''.toString(3) = " + tmp
);
398 ok(tmp
=== "", "''.valueOf() = " + tmp
);
399 tmp
= "test".valueOf();
400 ok(tmp
=== "test", "''.valueOf() = " + tmp
);
401 tmp
= "test".valueOf(3);
402 ok(tmp
=== "test", "''.valueOf(3) = " + tmp
);
404 var str
= new String("test");
405 ok(str
.toString() === "test", "str.toString() = " + str
.toString());
406 var str
= new String();
407 ok(str
.toString() === "", "str.toString() = " + str
.toString());
408 var str
= new String("test", "abc");
409 ok(str
.toString() === "test", "str.toString() = " + str
.toString());
411 var strObj
= new Object();
412 strObj
.toString = function() { return "abcd" };
413 strObj
.substr
= String
.prototype.substr
;
414 strObj
.lastIndexOf
= String
.prototype.lastIndexOf
;
416 tmp
= "value " + str
;
417 ok(tmp
=== "value test", "'value ' + str = " + tmp
);
420 ok(tmp
=== "", "String() = " + tmp
);
422 ok(tmp
=== "false", "String(false) = " + tmp
);
424 ok(tmp
=== "null", "String(null) = " + tmp
);
425 tmp
= String("test");
426 ok(tmp
=== "test", "String('test') = " + tmp
);
427 tmp
= String("test", "abc");
428 ok(tmp
=== "test", "String('test','abc') = " + tmp
);
430 tmp
= "abc".charAt(0);
431 ok(tmp
=== "a", "'abc',charAt(0) = " + tmp
);
432 tmp
= "abc".charAt(1);
433 ok(tmp
=== "b", "'abc',charAt(1) = " + tmp
);
434 tmp
= "abc".charAt(2);
435 ok(tmp
=== "c", "'abc',charAt(2) = " + tmp
);
436 tmp
= "abc".charAt(3);
437 ok(tmp
=== "", "'abc',charAt(3) = " + tmp
);
438 tmp
= "abc".charAt(4);
439 ok(tmp
=== "", "'abc',charAt(4) = " + tmp
);
440 tmp
= "abc".charAt();
441 ok(tmp
=== "a", "'abc',charAt() = " + tmp
);
442 tmp
= "abc".charAt(-1);
443 ok(tmp
=== "", "'abc',charAt(-1) = " + tmp
);
444 tmp
= "abc".charAt(0,2);
445 ok(tmp
=== "a", "'abc',charAt(0.2) = " + tmp
);
446 tmp
= "abc".charAt(NaN
);
447 ok(tmp
=== "a", "'abc',charAt(NaN) = " + tmp
);
448 tmp
= "abc".charAt(bigInt
);
449 ok(tmp
=== "", "'abc',charAt(bigInt) = " + tmp
);
451 tmp
= "abc".charCodeAt(0);
452 ok(tmp
=== 0x61, "'abc'.charCodeAt(0) = " + tmp
);
453 tmp
= "abc".charCodeAt(1);
454 ok(tmp
=== 0x62, "'abc'.charCodeAt(1) = " + tmp
);
455 tmp
= "abc".charCodeAt(2);
456 ok(tmp
=== 0x63, "'abc'.charCodeAt(2) = " + tmp
);
457 tmp
= "abc".charCodeAt();
458 ok(tmp
=== 0x61, "'abc'.charCodeAt() = " + tmp
);
459 tmp
= "abc".charCodeAt(true);
460 ok(tmp
=== 0x62, "'abc'.charCodeAt(true) = " + tmp
);
461 tmp
= "abc".charCodeAt(0,2);
462 ok(tmp
=== 0x61, "'abc'.charCodeAt(0,2) = " + tmp
);
463 tmp
= "\u49F4".charCodeAt(0);
464 ok(tmp
=== 0x49F4, "'\u49F4'.charCodeAt(0) = " + tmp
);
465 tmp
= "\052".charCodeAt(0);
466 ok(tmp
=== 0x2A, "'\052'.charCodeAt(0) = " + tmp
);
467 tmp
= "\xa2".charCodeAt(0);
468 ok(tmp
=== 0xA2, "'\xa2'.charCodeAt(0) = " + tmp
);
469 tmp
= "abc".charCodeAt(bigInt
);
470 ok(isNaN(tmp
), "'abc'.charCodeAt(bigInt) = " + tmp
);
472 tmp
= "abcd".substring(1,3);
473 ok(tmp
=== "bc", "'abcd'.substring(1,3) = " + tmp
);
474 tmp
= "abcd".substring(-1,3);
475 ok(tmp
=== "abc", "'abcd'.substring(-1,3) = " + tmp
);
476 tmp
= "abcd".substring(1,6);
477 ok(tmp
=== "bcd", "'abcd'.substring(1,6) = " + tmp
);
478 tmp
= "abcd".substring(3,1);
479 ok(tmp
=== "bc", "'abcd'.substring(3,1) = " + tmp
);
480 tmp
= "abcd".substring(2,2);
481 ok(tmp
=== "", "'abcd'.substring(2,2) = " + tmp
);
482 tmp
= "abcd".substring(true,"3");
483 ok(tmp
=== "bc", "'abcd'.substring(true,'3') = " + tmp
);
484 tmp
= "abcd".substring(1,3,2);
485 ok(tmp
=== "bc", "'abcd'.substring(1,3,2) = " + tmp
);
486 tmp
= "abcd".substring();
487 ok(tmp
=== "abcd", "'abcd'.substring() = " + tmp
);
489 tmp
= "abcd".substr(1,3);
490 ok(tmp
=== "bcd", "'abcd'.substr(1,3) = " + tmp
);
491 tmp
= "abcd".substr(-1,3);
492 ok(tmp
=== "abc", "'abcd'.substr(-1,3) = " + tmp
);
493 tmp
= "abcd".substr(1,6);
494 ok(tmp
=== "bcd", "'abcd'.substr(1,6) = " + tmp
);
495 tmp
= "abcd".substr(2,-1);
496 ok(tmp
=== "", "'abcd'.substr(3,1) = " + tmp
);
497 tmp
= "abcd".substr(2,0);
498 ok(tmp
=== "", "'abcd'.substr(2,2) = " + tmp
);
499 tmp
= "abcd".substr(true,"3");
500 ok(tmp
=== "bcd", "'abcd'.substr(true,'3') = " + tmp
);
501 tmp
= "abcd".substr(1,3,2);
502 ok(tmp
=== "bcd", "'abcd'.substr(1,3,2) = " + tmp
);
503 tmp
= "abcd".substr();
504 ok(tmp
=== "abcd", "'abcd'.substr() = " + tmp
);
505 tmp
= strObj
.substr(1,1);
506 ok(tmp
=== "b", "'abcd'.substr(1,3) = " + tmp
);
508 tmp
= "abcd".slice(1,3);
509 ok(tmp
=== "bc", "'abcd'.slice(1,3) = " + tmp
);
510 tmp
= "abcd".slice(1,-1);
511 ok(tmp
=== "bc", "'abcd'.slice(1,-1) = " + tmp
);
512 tmp
= "abcd".slice(-3,3);
513 ok(tmp
=== "bc", "'abcd'.slice(-3,3) = " + tmp
);
514 tmp
= "abcd".slice(-6,3);
515 ok(tmp
=== "abc", "'abcd'.slice(-6,3) = " + tmp
);
516 tmp
= "abcd".slice(3,1);
517 ok(tmp
=== "", "'abcd'.slice(3,1) = " + tmp
);
518 tmp
= "abcd".slice(true,3);
519 ok(tmp
=== "bc", "'abcd'.slice(true,3) = " + tmp
);
520 tmp
= "abcd".slice();
521 ok(tmp
=== "abcd", "'abcd'.slice() = " + tmp
);
522 tmp
= "abcd".slice(1);
523 ok(tmp
=== "bcd", "'abcd'.slice(1) = " + tmp
);
525 tmp
= "abc".concat(["d",1],2,false);
526 ok(tmp
=== "abcd,12false", "concat returned " + tmp
);
527 var arr
= new Array(2,"a");
528 arr
.concat
= String
.prototype.concat
;
529 tmp
= arr
.concat("d");
530 ok(tmp
=== "2,ad", "arr.concat = " + tmp
);
532 m
= "a+bcabc".match("a+");
533 ok(typeof(m
) === "object", "typeof m is not object");
534 ok(m
.length
=== 1, "m.length is not 1");
535 ok(m
["0"] === "a", "m[0] is not \"a\"");
537 r
= "- [test] -".replace("[test]", "success");
538 ok(r
=== "- success -", "r = " + r
+ " expected '- success -'");
540 r
= "- [test] -".replace("[test]", "success", "test");
541 ok(r
=== "- success -", "r = " + r
+ " expected '- success -'");
543 r
= "test".replace();
544 ok(r
=== "test", "r = " + r
+ " expected 'test'");
546 function replaceFunc3(m
, off
, str
) {
547 ok(arguments
.length
=== 3, "arguments.length = " + arguments
.length
);
548 ok(m
=== "[test]", "m = " + m
+ " expected [test]");
549 ok(off
=== 1, "off = " + off
+ " expected 0");
550 ok(str
=== "-[test]-", "str = " + arguments
[3]);
554 r
= "-[test]-".replace("[test]", replaceFunc3
);
555 ok(r
=== "-ret-", "r = " + r
+ " expected '-ret-'");
557 r
= "-[test]-".replace("[test]", replaceFunc3
, "test");
558 ok(r
=== "-ret-", "r = " + r
+ " expected '-ret-'");
560 r
= "x,x,x".replace("x", "y");
561 ok(r
=== "y,x,x", "r = " + r
+ " expected 'y,x,x'");
563 r
= "x,x,x".replace("", "y");
564 ok(r
=== "yx,x,x", "r = " + r
+ " expected 'yx,x,x'");
566 r
= "x,x,x".replace("", "");
567 ok(r
=== "x,x,x", "r = " + r
+ " expected 'x,x,x'");
569 r
= "1,2,3".split(",");
570 ok(typeof(r
) === "object", "typeof(r) = " + typeof(r
));
571 ok(r
.length
=== 3, "r.length = " + r
.length
);
572 ok(r
[0] === "1", "r[0] = " + r
[0]);
573 ok(r
[1] === "2", "r[1] = " + r
[1]);
574 ok(r
[2] === "3", "r[2] = " + r
[2]);
576 r
= "1,2,3".split(",*");
577 ok(r
.length
=== 1, "r.length = " + r
.length
);
578 ok(r
[0] === "1,2,3", "r[0] = " + r
[0]);
581 ok(r
.length
=== 3, "r.length = " + r
.length
);
582 ok(r
[0] === "1", "r[0] = " + r
[0]);
583 ok(r
[1] === "2", "r[1] = " + r
[1]);
584 ok(r
[2] === "3", "r[2] = " + r
[2]);
587 ok(r
.length
=== 2, "r.length = " + r
.length
);
588 ok(r
[0] === "1", "r[0] = " + r
[0]);
589 ok(r
[1] === "3", "r[1] = " + r
[1]);
591 r
= "1,2,".split(",");
592 ok(typeof(r
) === "object", "typeof(r) = " + typeof(r
));
593 ok(r
.length
=== 3, "r.length = " + r
.length
);
594 ok(r
[0] === "1", "r[0] = " + r
[0]);
595 ok(r
[1] === "2", "r[1] = " + r
[1]);
596 ok(r
[2] === "", "r[2] = " + r
[2]);
598 r
= "1,2,3".split(",", 2);
599 ok(typeof(r
) === "object", "typeof(r) = " + typeof(r
));
600 ok(r
.length
=== 2, "r.length = " + r
.length
);
601 ok(r
[0] === "1", "r[0] = " + r
[0]);
602 ok(r
[1] === "2", "r[1] = " + r
[1]);
604 r
= "1,2,3".split(",", 0);
605 ok(typeof(r
) === "object", "typeof(r) = " + typeof(r
));
606 ok(r
.length
=== 0, "r.length = " + r
.length
);
608 r
= "1,2,3".split(",", -1);
609 ok(typeof(r
) === "object", "typeof(r) = " + typeof(r
));
610 ok(r
.length
=== 3, "r.length = " + r
.length
);
611 ok(r
[0] === "1", "r[0] = " + r
[0]);
612 ok(r
[1] === "2", "r[1] = " + r
[1]);
613 ok(r
[2] === "3", "r[1] = " + r
[1]);
615 tmp
= "abcd".indexOf("bc",0);
616 ok(tmp
=== 1, "indexOf = " + tmp
);
617 tmp
= "abcd".indexOf("bc",1);
618 ok(tmp
=== 1, "indexOf = " + tmp
);
619 tmp
= "abcd".indexOf("bc");
620 ok(tmp
=== 1, "indexOf = " + tmp
);
621 tmp
= "abcd".indexOf("ac");
622 ok(tmp
=== -1, "indexOf = " + tmp
);
623 tmp
= "abcd".indexOf("bc",2);
624 ok(tmp
=== -1, "indexOf = " + tmp
);
625 tmp
= "abcd".indexOf("a",0);
626 ok(tmp
=== 0, "indexOf = " + tmp
);
627 tmp
= "abcd".indexOf("bc",0,"test");
628 ok(tmp
=== 1, "indexOf = " + tmp
);
629 tmp
= "abcd".indexOf();
630 ok(tmp
== -1, "indexOf = " + tmp
);
631 tmp
= "abcd".indexOf("b", bigInt
);
632 ok(tmp
== -1, "indexOf = " + tmp
);
633 tmp
= "abcd".indexOf("abcd",0);
634 ok(tmp
=== 0, "indexOf = " + tmp
);
635 tmp
= "abcd".indexOf("abcd",1);
636 ok(tmp
=== -1, "indexOf = " + tmp
);
637 tmp
= ("ab" + String
.fromCharCode(0) + "cd").indexOf(String
.fromCharCode(0));
638 ok(tmp
=== 2, "indexOf = " + tmp
);
640 tmp
= "abcd".lastIndexOf("bc",1);
641 ok(tmp
=== 1, "lastIndexOf = " + tmp
);
642 tmp
= "abcd".lastIndexOf("bc",2);
643 ok(tmp
=== 1, "lastIndexOf = " + tmp
);
644 tmp
= "abcd".lastIndexOf("bc");
645 ok(tmp
=== 1, "lastIndexOf = " + tmp
);
646 tmp
= "abcd".lastIndexOf("ac");
647 ok(tmp
=== -1, "lastIndexOf = " + tmp
);
648 tmp
= "abcd".lastIndexOf("d",10);
649 ok(tmp
=== 3, "lastIndexOf = " + tmp
);
650 tmp
= "abcd".lastIndexOf("bc",0,"test");
651 ok(tmp
=== -1, "lastIndexOf = " + tmp
);
652 tmp
= "abcd".lastIndexOf();
653 ok(tmp
=== -1, "lastIndexOf = " + tmp
);
654 tmp
= "aaaa".lastIndexOf("a",2);
655 ok(tmp
== 2, "lastIndexOf = " + tmp
);
656 tmp
= strObj
.lastIndexOf("b");
657 ok(tmp
=== 1, "lastIndexOf = " + tmp
);
658 tmp
= "bbb".lastIndexOf("b", bigInt
);
659 ok(tmp
=== 2, "lastIndexOf = " + tmp
);
660 tmp
= "abcd".lastIndexOf("abcd",4);
661 ok(tmp
=== 0, "lastIndexOf = " + tmp
);
662 tmp
= "abcd".lastIndexOf("abcd",0);
663 ok(tmp
=== 0, "lastIndexOf = " + tmp
);
664 tmp
= ("ab" + String
.fromCharCode(0) + "cd").lastIndexOf(String
.fromCharCode(0));
665 ok(tmp
=== 2, "lastIndexOf = " + tmp
);
667 tmp
= "".toLowerCase();
668 ok(tmp
=== "", "''.toLowerCase() = " + tmp
);
669 tmp
= "test".toLowerCase();
670 ok(tmp
=== "test", "''.toLowerCase() = " + tmp
);
671 tmp
= "test".toLowerCase(3);
672 ok(tmp
=== "test", "''.toLowerCase(3) = " + tmp
);
673 tmp
= "tEsT".toLowerCase();
674 ok(tmp
=== "test", "''.toLowerCase() = " + tmp
);
675 tmp
= "tEsT".toLowerCase(3);
676 ok(tmp
=== "test", "''.toLowerCase(3) = " + tmp
);
677 tmp
= ("tE" + String
.fromCharCode(0) + "sT").toLowerCase();
678 ok(tmp
=== "te" + String
.fromCharCode(0) + "st", "''.toLowerCase() = " + tmp
);
680 tmp
= "".toUpperCase();
681 ok(tmp
=== "", "''.toUpperCase() = " + tmp
);
682 tmp
= "TEST".toUpperCase();
683 ok(tmp
=== "TEST", "''.toUpperCase() = " + tmp
);
684 tmp
= "TEST".toUpperCase(3);
685 ok(tmp
=== "TEST", "''.toUpperCase(3) = " + tmp
);
686 tmp
= "tEsT".toUpperCase();
687 ok(tmp
=== "TEST", "''.toUpperCase() = " + tmp
);
688 tmp
= "tEsT".toUpperCase(3);
689 ok(tmp
=== "TEST", "''.toUpperCase(3) = " + tmp
);
690 tmp
= ("tE" + String
.fromCharCode(0) + "sT").toUpperCase();
691 ok(tmp
=== "TE" + String
.fromCharCode(0) + "ST", "''.toUpperCase() = " + tmp
);
694 ok(tmp
=== "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp
);
696 ok(tmp
=== "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp
);
697 tmp
= "".anchor("red");
698 ok(tmp
=== "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp
);
699 tmp
= "test".anchor();
700 ok(tmp
=== "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp
);
701 tmp
= "test".anchor(3);
702 ok(tmp
=== "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp
);
703 tmp
= "test".anchor("green");
704 ok(tmp
=== "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp
);
707 ok(tmp
=== "<BIG></BIG>", "''.big() = " + tmp
);
709 ok(tmp
=== "<BIG></BIG>", "''.big(3) = " + tmp
);
711 ok(tmp
=== "<BIG>test</BIG>", "'test'.big() = " + tmp
);
713 ok(tmp
=== "<BIG>test</BIG>", "'test'.big(3) = " + tmp
);
716 ok(tmp
=== "<BLINK></BLINK>", "''.blink() = " + tmp
);
718 ok(tmp
=== "<BLINK></BLINK>", "''.blink(3) = " + tmp
);
719 tmp
= "test".blink();
720 ok(tmp
=== "<BLINK>test</BLINK>", "'test'.blink() = " + tmp
);
721 tmp
= "test".blink(3);
722 ok(tmp
=== "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp
);
725 ok(tmp
=== "<B></B>", "''.bold() = " + tmp
);
727 ok(tmp
=== "<B></B>", "''.bold(3) = " + tmp
);
729 ok(tmp
=== "<B>test</B>", "'test'.bold() = " + tmp
);
730 tmp
= "test".bold(3);
731 ok(tmp
=== "<B>test</B>", "'test'.bold(3) = " + tmp
);
734 ok(tmp
=== "<TT></TT>", "''.fixed() = " + tmp
);
736 ok(tmp
=== "<TT></TT>", "''.fixed(3) = " + tmp
);
737 tmp
= "test".fixed();
738 ok(tmp
=== "<TT>test</TT>", "'test'.fixed() = " + tmp
);
739 tmp
= "test".fixed(3);
740 ok(tmp
=== "<TT>test</TT>", "'test'.fixed(3) = " + tmp
);
742 tmp
= "".fontcolor();
743 ok(tmp
=== "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp
);
744 tmp
= "".fontcolor(3);
745 ok(tmp
=== "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp
);
746 tmp
= "".fontcolor("red");
747 ok(tmp
=== "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp
);
748 tmp
= "test".fontcolor();
749 ok(tmp
=== "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp
);
750 tmp
= "test".fontcolor(3);
751 ok(tmp
=== "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp
);
752 tmp
= "test".fontcolor("green");
753 ok(tmp
=== "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp
);
756 ok(tmp
=== "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp
);
757 tmp
= "".fontsize(3);
758 ok(tmp
=== "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp
);
759 tmp
= "".fontsize("red");
760 ok(tmp
=== "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp
);
761 tmp
= "test".fontsize();
762 ok(tmp
=== "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp
);
763 tmp
= "test".fontsize(3);
764 ok(tmp
=== "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp
);
765 tmp
= "test".fontsize("green");
766 ok(tmp
=== "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp
);
768 tmp
= ("".fontcolor()).fontsize();
769 ok(tmp
=== "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp
);
772 ok(tmp
=== "<I></I>", "''.italics() = " + tmp
);
774 ok(tmp
=== "<I></I>", "''.italics(3) = " + tmp
);
775 tmp
= "test".italics();
776 ok(tmp
=== "<I>test</I>", "'test'.italics() = " + tmp
);
777 tmp
= "test".italics(3);
778 ok(tmp
=== "<I>test</I>", "'test'.italics(3) = " + tmp
);
781 ok(tmp
=== "<A HREF=\"undefined\"></A>", "''.link() = " + tmp
);
783 ok(tmp
=== "<A HREF=\"3\"></A>", "''.link(3) = " + tmp
);
784 tmp
= "".link("red");
785 ok(tmp
=== "<A HREF=\"red\"></A>", "''.link('red') = " + tmp
);
787 ok(tmp
=== "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp
);
788 tmp
= "test".link(3);
789 ok(tmp
=== "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp
);
790 tmp
= "test".link("green");
791 ok(tmp
=== "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp
);
794 ok(tmp
=== "<SMALL></SMALL>", "''.small() = " + tmp
);
796 ok(tmp
=== "<SMALL></SMALL>", "''.small(3) = " + tmp
);
797 tmp
= "test".small();
798 ok(tmp
=== "<SMALL>test</SMALL>", "'test'.small() = " + tmp
);
799 tmp
= "test".small(3);
800 ok(tmp
=== "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp
);
803 ok(tmp
=== "<STRIKE></STRIKE>", "''.strike() = " + tmp
);
805 ok(tmp
=== "<STRIKE></STRIKE>", "''.strike(3) = " + tmp
);
806 tmp
= "test".strike();
807 ok(tmp
=== "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp
);
808 tmp
= "test".strike(3);
809 ok(tmp
=== "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp
);
812 ok(tmp
=== "<SUB></SUB>", "''.sub() = " + tmp
);
814 ok(tmp
=== "<SUB></SUB>", "''.sub(3) = " + tmp
);
816 ok(tmp
=== "<SUB>test</SUB>", "'test'.sub() = " + tmp
);
818 ok(tmp
=== "<SUB>test</SUB>", "'test'.sub(3) = " + tmp
);
821 ok(tmp
=== "<SUP></SUP>", "''.sup() = " + tmp
);
823 ok(tmp
=== "<SUP></SUP>", "''.sup(3) = " + tmp
);
825 ok(tmp
=== "<SUP>test</SUP>", "'test'.sup() = " + tmp
);
827 ok(tmp
=== "<SUP>test</SUP>", "'test'.sup(3) = " + tmp
);
829 ok(String
.fromCharCode() === "", "String.fromCharCode() = " + String
.fromCharCode());
830 ok(String
.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String
.fromCharCode(65,"66",67));
831 ok(String
.fromCharCode(1024*64+65, -1024*64+65) === "AA",
832 "String.fromCharCode(1024*64+65, -1024*64+65) = " + String
.fromCharCode(1024*64+65, -1024*64+65));
833 ok(String
.fromCharCode(65, NaN
, undefined).length
=== 3,
834 "String.fromCharCode(65, NaN, undefined).length = " + String
.fromCharCode(65, NaN
, undefined).length
);
836 var arr
= new Array();
837 ok(typeof(arr
) === "object", "arr () is not object");
838 ok((arr
.length
=== 0), "arr.length is not 0");
839 ok(arr
["0"] === undefined, "arr[0] is not undefined");
841 var arr
= new Array(1, 2, "test");
842 ok(typeof(arr
) === "object", "arr (1,2,test) is not object");
843 ok((arr
.length
=== 3), "arr.length is not 3");
844 ok(arr
["0"] === 1, "arr[0] is not 1");
845 ok(arr
["1"] === 2, "arr[1] is not 2");
846 ok(arr
["2"] === "test", "arr[2] is not \"test\"");
849 ok((arr
.length
=== 8), "arr.length is not 8");
852 ok(tmp
=== "", "'' + [] = " + tmp
);
854 ok(tmp
=== "1,true", "'' + [1,true] = " + tmp
);
856 var arr
= new Array(6);
857 ok(typeof(arr
) === "object", "arr (6) is not object");
858 ok((arr
.length
=== 6), "arr.length is not 6");
859 ok(arr
["0"] === undefined, "arr[0] is not undefined");
861 ok(arr
.push() === 6, "arr.push() !== 6");
862 ok(arr
.push(1) === 7, "arr.push(1) !== 7");
863 ok(arr
[6] === 1, "arr[6] != 1");
864 ok(arr
.length
=== 7, "arr.length != 10");
865 ok(arr
.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
866 ok(arr
[8] === "b", "arr[8] != 'b'");
867 ok(arr
.length
=== 10, "arr.length != 10");
869 var arr
= new Object();
870 arr
.push
= Array
.prototype.push
;
874 ok(arr
.push() === 6, "arr.push() !== 6");
875 ok(arr
.push(1) === 7, "arr.push(1) !== 7");
876 ok(arr
[6] === 1, "arr[6] != 1");
877 ok(arr
.length
=== 7, "arr.length != 10");
878 ok(arr
.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
879 ok(arr
[8] === "b", "arr[8] != 'b'");
880 ok(arr
.length
=== 10, "arr.length != 10");
882 arr
.pop
= Array
.prototype.pop
;
883 ok(arr
.pop() === false, "arr.pop() !== false");
884 ok(arr
[8] === "b", "arr[8] !== 'b'");
885 ok(arr
.pop() === 'b', "arr.pop() !== 'b'");
886 ok(arr
[8] === undefined, "arr[8] !== undefined");
890 ok(arr
.length
=== 2, "arr.length = " + arr
.length
);
891 ok(tmp
=== 5, "pop() = " + tmp
);
893 ok(arr
.length
=== 1, "arr.length = " + arr
.length
);
894 ok(tmp
=== 4, "pop() = " + tmp
);
896 ok(arr
.length
=== 0, "arr.length = " + arr
.length
);
897 ok(tmp
=== 3, "pop() = " + tmp
);
899 ok(false, "not deleted " + tmp
);
901 ok(arr
.length
=== 0, "arr.length = " + arr
.length
);
902 ok(tmp
=== undefined, "tmp = " + tmp
);
904 arr
.pop
= Array
.prototype.pop
;
906 ok(arr
.length
=== 0, "arr.length = " + arr
.length
);
907 ok(tmp
=== undefined, "tmp = " + tmp
);
910 ok(arr
.length
=== 5, "arr.length = " + arr
.length
);
911 ok(tmp
=== undefined, "tmp = " + tmp
);
912 tmp
= [1,2,,,].pop();
913 ok(tmp
=== undefined, "tmp = " + tmp
);
915 function PseudoArray() {
918 PseudoArray
.prototype = {length
: 1};
919 arr
= new PseudoArray();
920 Array
.prototype.push
.call(arr
, 2);
921 ok(arr
.propertyIsEnumerable("length"), "arr.length is not enumerable");
923 arr
= [1,2,null,false,undefined,,"a"];
926 ok(tmp
=== "1,2,,false,,,a", "arr.join() = " + tmp
);
928 ok(tmp
=== "1;2;;false;;;a", "arr.join(';') = " + tmp
);
929 tmp
= arr
.join(";","test");
930 ok(tmp
=== "1;2;;false;;;a", "arr.join(';') = " + tmp
);
932 ok(tmp
=== "12falsea", "arr.join('') = " + tmp
);
934 tmp
= arr
.toString();
935 ok(tmp
=== "1,2,,false,,,a", "arr.toString() = " + tmp
);
936 tmp
= arr
.toString("test");
937 ok(tmp
=== "1,2,,false,,,a", "arr.toString() = " + tmp
);
941 tmp
= arr
.join(String
.fromCharCode(0));
942 ok(tmp
=== "a" + String
.fromCharCode(0) + "b", "arr.join(String.fromCharCode(0)) = " + tmp
);
949 arr
.join
= Array
.prototype.join
;
951 ok(arr
.length
=== 3, "arr.length = " + arr
.length
);
952 ok(tmp
=== "aa,,2", "tmp = " + tmp
);
954 arr
= [5,true,2,-1,3,false,"2.5"];
955 tmp
= arr
.sort(function(x
,y
) { return y
-x
; });
956 ok(tmp
=== arr
, "tmp !== arr");
957 tmp
= [5,3,"2.5",2,true,false,-1];
958 for(var i
=0; i
< arr
.length
; i
++)
959 ok(arr
[i
] === tmp
[i
], "arr[" + i
+ "] = " + arr
[i
] + " expected " + tmp
[i
]);
961 arr
= [5,false,2,0,"abc",3,"a",-1];
963 ok(tmp
=== arr
, "tmp !== arr");
964 tmp
= [-1,0,2,3,5,"a","abc",false];
965 for(var i
=0; i
< arr
.length
; i
++)
966 ok(arr
[i
] === tmp
[i
], "arr[" + i
+ "] = " + arr
[i
] + " expected " + tmp
[i
]);
968 arr
= ["a", "b", "ab"];
969 tmp
= ["a", "ab", "b"];
970 ok(arr
.sort() === arr
, "arr.sort() !== arr");
971 for(var i
=0; i
< arr
.length
; i
++)
972 ok(arr
[i
] === tmp
[i
], "arr[" + i
+ "] = " + arr
[i
] + " expected " + tmp
[i
]);
978 arr
.sort
= Array
.prototype.sort
;
980 ok(arr
=== tmp
, "tmp !== arr");
981 ok(arr
[0]===1 && arr
[1]==="aa" && arr
[2]===undefined, "arr is sorted incorrectly");
983 tmp
= [["bb","aa"],["ab","aa"]].sort().toString();
984 ok(tmp
=== "ab,aa,bb,aa", "sort() = " + tmp
);
986 tmp
= [["bb","aa"],"ab"].sort().toString();
987 ok(tmp
=== "ab,bb,aa", "sort() = " + tmp
);
989 tmp
= [["bb","aa"],"cc"].sort().toString();
990 ok(tmp
=== "bb,aa,cc", "sort() = " + tmp
);
992 tmp
= [2,"1"].sort().toString();
993 ok(tmp
=== "1,2", "sort() = " + tmp
);
995 tmp
= ["2",1].sort().toString();
996 ok(tmp
=== "1,2", "sort() = " + tmp
);
998 tmp
= [,,0,"z"].sort().toString();
999 ok(tmp
=== "0,z,,", "sort() = " + tmp
);
1001 tmp
= ["a,b",["a","a"],["a","c"]].sort().toString();
1002 ok(tmp
=== "a,a,a,b,a,c", "sort() = " + tmp
);
1004 arr
= ["1", "2", "3"];
1006 ok(arr
.length
=== 1, "arr.length = " + arr
.length
);
1008 ok(arr
.length
=== 3, "arr.length = " + arr
.length
);
1009 ok(arr
.toString() === "1,,", "arr.toString() = " + arr
.toString());
1011 arr
= Array("a","b","c");
1012 ok(arr
.toString() === "a,b,c", "arr.toString() = " + arr
.toString());
1014 ok(arr
.valueOf
=== Object
.prototype.valueOf
, "arr.valueOf !== Object.prototype.valueOf");
1015 ok(arr
=== arr
.valueOf(), "arr !== arr.valueOf");
1018 tmp
= arr
.reverse();
1019 ok(tmp
=== arr
, "tmp !== arr");
1020 ok(arr
.length
=== 3, "arr.length = " + arr
.length
);
1021 ok(arr
.toString() === "3,2,1", "arr.toString() = " + arr
.toString());
1026 tmp
= arr
.reverse();
1027 ok(tmp
=== arr
, "tmp !== arr");
1028 ok(arr
.length
=== 6, "arr.length = " + arr
.length
);
1029 ok(arr
.toString() === "1,,5,,,", "arr.toString() = " + arr
.toString());
1036 arr
.reverse
= Array
.prototype.reverse
;
1037 tmp
= arr
.reverse();
1038 ok(tmp
=== arr
, "tmp !== arr");
1039 ok(arr
.length
=== 3, "arr.length = " + arr
.length
);
1040 ok(arr
[0] === 2 && arr
[1] === undefined && arr
[2] === "aa", "unexpected array");
1043 tmp
= arr
.unshift(0);
1044 ok(tmp
=== (invokeVersion
< 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp
);
1045 ok(arr
.length
=== 4, "arr.length = " + arr
.length
);
1046 ok(arr
.toString() === "0,1,2,3", "arr.toString() = " + arr
.toString());
1051 tmp
= arr
.unshift(-1,0);
1052 ok(tmp
=== (invokeVersion
< 2 ? undefined : 5), "unshift returned " +tmp
);
1053 ok(arr
.length
=== 5, "arr.length = " + arr
.length
);
1054 ok(arr
.toString() === "-1,0,1,,3", "arr.toString() = " + arr
.toString());
1057 tmp
= arr
.unshift();
1058 ok(tmp
=== (invokeVersion
< 2 ? undefined : 3), "unshift returned " +tmp
);
1059 ok(arr
.length
=== 3, "arr.length = " + arr
.length
);
1060 ok(arr
.toString() === "1,2,3", "arr.toString() = " + arr
.toString());
1066 tmp
= Array
.prototype.unshift
.call(arr
, 0);
1067 ok(tmp
=== (invokeVersion
< 2 ? undefined : 3), "unshift returned " +tmp
);
1068 ok(arr
.length
=== 3, "arr.length = " + arr
.length
);
1069 ok(arr
[0] === 0 && arr
[1] === 1 && arr
[2] === 2, "unexpected array");
1073 ok(tmp
=== 1, "[1,2,,4].shift() = " + tmp
);
1074 ok(arr
.toString() === "2,,4", "arr = " + arr
.toString());
1078 ok(tmp
=== undefined, "[].shift() = " + tmp
);
1079 ok(arr
.toString() === "", "arr = " + arr
.toString());
1083 ok(tmp
=== 1, "[1,2,,4].shift(2) = " + tmp
);
1084 ok(arr
.toString() === "2,,4", "arr = " + arr
.toString());
1088 ok(tmp
=== 1, "[1,].shift() = " + tmp
);
1089 ok(arr
.toString() === "", "arr = " + arr
.toString());
1095 tmp
= Array
.prototype.shift
.call(obj
);
1096 ok(tmp
=== "test", "obj.shift() = " + tmp
);
1097 ok(obj
.length
== 2, "obj.length = " + obj
.length
);
1098 ok(obj
[1] === 3, "obj[1] = " + obj
[1]);
1100 var num
= new Number(6);
1102 tmp
= arr
.concat(3, [4,5], num
);
1103 ok(tmp
!== arr
, "tmp === arr");
1104 for(var i
=0; i
<6; i
++)
1105 ok(tmp
[i
] === i
, "tmp[" + i
+ "] = " + tmp
[i
]);
1106 ok(tmp
[6] === num
, "tmp[6] !== num");
1107 ok(tmp
.length
=== 7, "tmp.length = " + tmp
.length
);
1110 ok(arr
.length
=== 0, "arr.length = " + arr
.length
);
1113 tmp
= arr
.concat([2]);
1114 ok(tmp
.length
=== 3, "tmp.length = " + tmp
.length
);
1115 ok(tmp
[1] === undefined, "tmp[1] = " + tmp
[1]);
1117 arr
= [1,false,'a',null,undefined,'a'];
1118 ok(arr
.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr
.slice(0,6));
1119 ok(arr
.slice(0,6).length
=== 6, "arr.slice(0,6).length = " + arr
.slice(0,6).length
);
1120 ok(arr
.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr
.slice());
1121 ok(arr
.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr
.slice("abc"));
1122 ok(arr
.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr
.slice(3,8));
1123 ok(arr
.slice(3,8).length
=== 3, "arr.slice(3,8).length = " + arr
.slice(3,8).length
);
1124 ok(arr
.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr
.slice(1));
1125 ok(arr
.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr
.slice(-2));
1126 ok(arr
.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr
.slice(3,1));
1127 tmp
= arr
.slice(0,6);
1128 for(var i
=0; i
< arr
.length
; i
++)
1129 ok(arr
[i
] === tmp
[i
], "arr[" + i
+ "] = " + arr
[i
] + " expected " + tmp
[i
]);
1131 ok(arr
.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr
.slice(5).toString());
1132 ok(arr
.slice(5).length
=== 8, "arr.slice(5).length = " + arr
.slice(5).length
);
1135 tmp
= arr
.splice(2,2);
1136 ok(tmp
.toString() == "3,4", "arr.splice(2,2) returned " + tmp
.toString());
1137 ok(arr
.toString() == "1,2,5", "arr.splice(2,2) is " + arr
.toString());
1140 tmp
= arr
.splice(2,2,"a");
1141 ok(tmp
.toString() == "3,4", "arr.splice(2,2,'a') returned " + tmp
.toString());
1142 ok(arr
.toString() == "1,2,a,5", "arr.splice(2,2,'a') is " + arr
.toString());
1145 tmp
= arr
.splice(2,2,'a','b','c');
1146 ok(tmp
.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp
.toString());
1147 ok(arr
.toString() == "1,2,a,b,c,5", "arr.splice(2,2,'a','b','c') is " + arr
.toString());
1150 tmp
= arr
.splice(2,2,'a','b','c');
1151 ok(tmp
.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp
.toString());
1152 ok(arr
.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr
.toString());
1155 arr
.splice(2,2,'a','b','c');
1156 ok(arr
.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr
.toString());
1159 tmp
= arr
.splice(2,2,'a','b');
1160 ok(tmp
.toString() == "3,4", "arr.splice(2,2,'a','b') returned " + tmp
.toString());
1161 ok(arr
.toString() == "1,2,a,b,5", "arr.splice(2,2,'a','b') is " + arr
.toString());
1164 tmp
= arr
.splice(-1,2);
1165 ok(tmp
.toString() == "5", "arr.splice(-1,2) returned " + tmp
.toString());
1166 ok(arr
.toString() == "1,2,3,4", "arr.splice(-1,2) is " + arr
.toString());
1169 tmp
= arr
.splice(-10,3);
1170 ok(tmp
.toString() == "1,2,3", "arr.splice(-10,3) returned " + tmp
.toString());
1171 ok(arr
.toString() == "4,5", "arr.splice(-10,3) is " + arr
.toString());
1174 tmp
= arr
.splice(-10,100);
1175 ok(tmp
.toString() == "1,2,3,4,5", "arr.splice(-10,100) returned " + tmp
.toString());
1176 ok(arr
.toString() == "", "arr.splice(-10,100) is " + arr
.toString());
1179 tmp
= arr
.splice(2,-1);
1180 ok(tmp
.toString() == "", "arr.splice(2,-1) returned " + tmp
.toString());
1181 ok(arr
.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr
.toString());
1184 tmp
= arr
.splice(2);
1185 ok(tmp
.toString() == "", "arr.splice(2,-1) returned " + tmp
.toString());
1186 ok(arr
.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr
.toString());
1190 ok(tmp
.toString() == "", "arr.splice(2,-1) returned " + tmp
.toString());
1191 ok(arr
.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr
.toString());
1194 tmp
= arr
.splice(bigInt
);
1195 ok(tmp
.toString() == "", "arr.splice(bigInt) returned " + tmp
.toString());
1196 ok(arr
.toString() == "1,2,3,4,5", "arr.splice(bigInt) is " + arr
.toString());
1199 tmp
= arr
.splice(-bigInt
);
1200 ok(tmp
.toString() == "", "arr.splice(-bigInt) returned " + tmp
.toString());
1201 ok(arr
.toString() == "1,2,3,4,5", "arr.splice(-bigInt) is " + arr
.toString());
1203 if(invokeVersion
>= 2) {
1205 tmp
= arr
.splice(2, bigInt
);
1206 ok(tmp
.toString() == "3,4,5", "arr.splice(2, bigInt) returned " + tmp
.toString());
1207 ok(arr
.toString() == "1,2", "arr.splice(2, bigInt) is " + arr
.toString());
1211 tmp
= arr
.splice(2, -bigInt
);
1212 ok(tmp
.toString() == "", "arr.splice(2, -bigInt) returned " + tmp
.toString());
1213 ok(arr
.toString() == "1,2,3,4,5", "arr.splice(2, -bigInt) is " + arr
.toString());
1220 tmp
= Array
.prototype.splice
.call(obj
, 1, 1, 'a', 'b');
1221 ok(tmp
.toString() === "2", "obj.splice returned " + tmp
);
1222 ok(obj
.length
=== 4, "obj.length = " + obj
.length
);
1223 ok(obj
[0] === 1, "obj[0] = " + obj
[0]);
1224 ok(obj
[1] === 'a', "obj[1] = " + obj
[1]);
1225 ok(obj
[2] === 'b', "obj[2] = " + obj
[2]);
1226 ok(obj
[3] === 3, "obj[3] = " + obj
[3]);
1233 tmp
= Array
.prototype.slice
.call(obj
, 1, 2);
1234 ok(tmp
.length
=== 1, "tmp.length = " + tmp
.length
);
1235 ok(tmp
[0] === 2, "tmp[0] = " + tmp
[0]);
1237 tmp
= (new Number(2)).toString();
1238 ok(tmp
=== "2", "num(2).toString = " + tmp
);
1239 tmp
= (new Number()).toString();
1240 ok(tmp
=== "0", "num().toString = " + tmp
);
1241 tmp
= (new Number(5.5)).toString(2);
1242 ok(tmp
=== "101.1", "num(5.5).toString(2) = " + tmp
);
1244 tmp
= (new Number(3)).toFixed(3);
1245 ok(tmp
=== "3.000", "num(3).toFixed(3) = " + tmp
);
1246 tmp
= (new Number(3)).toFixed();
1247 ok(tmp
=== "3", "Number(3).toFixed() = " + tmp
);
1248 tmp
= (new Number(0)).toFixed();
1249 ok(tmp
=== "0", "Number(0).toFixed() = " + tmp
);
1250 tmp
= (new Number(0)).toFixed(1);
1251 ok(tmp
=== "0.0", "Number(0).toFixed(1) = " + tmp
);
1252 tmp
= (new Number(0)).toFixed(2);
1253 ok(tmp
=== "0.00", "Number(0).toFixed(2) = " + tmp
);
1254 tmp
= (new Number(1.76)).toFixed(1);
1255 ok(tmp
=== "1.8", "num(1.76).toFixed(1) = " + tmp
);
1256 tmp
= (new Number(7.92)).toFixed(5);
1257 ok(tmp
=== "7.92000", "num(7.92).toFixed(5) = " + tmp
);
1258 tmp
= (new Number(2.88)).toFixed();
1259 ok(tmp
=== "3", "num(2.88).toFixed = " + tmp
);
1260 tmp
= (new Number(-2.5)).toFixed();
1261 ok(tmp
=== "-3", "num(-2.5).toFixed = " + tmp
);
1262 tmp
= (new Number(1000000000000000128)).toFixed(0);
1263 //todo_wine ok(tmp === "1000000000000000100", "num(1000000000000000128) = " + tmp);
1264 tmp
= (new Number(3.14).toFixed(NaN
));
1265 ok(tmp
=== "3", "num(3.14).toFixed = " + tmp
);
1266 tmp
= (new Number(0.95).toFixed(1));
1267 ok(tmp
=== "1.0", "num(0.95).toFixed(1) = " + tmp
);
1268 tmp
= (new Number(1e900
)).toFixed(0);
1269 ok(tmp
=== "Infinity", "num(1000000000000000128) = " + tmp
);
1270 tmp
= (new Number(0.12345678901234567890123)).toFixed(20);
1271 ok(tmp
=== "0.12345678901234568000", "num(0.12345678901234567890123) = " + tmp
);
1273 tmp
= (new Number(2)).toExponential(3);
1274 ok(tmp
=== "2.000e+0", "num(2).toExponential(3) = " + tmp
);
1275 tmp
= (new Number(1.17e-32)).toExponential(20);
1276 ok(tmp
=== "1.17000000000000000000e-32", "num(1.17e-32).toExponential(20) = " + tmp
);
1277 tmp
= (new Number(0)).toExponential(7);
1278 ok(tmp
=== "0.0000000e+0", "num(0).toExponential(7) = " + tmp
);
1279 tmp
= (new Number(0)).toExponential(0);
1280 ok(tmp
=== "0e+0", "num(0).toExponential() = " + tmp
);
1281 tmp
= (new Number(-13.7567)).toExponential();
1282 ok(tmp
=== "-1.37567e+1", "num(-13.7567).toExponential() = " + tmp
);
1283 tmp
= (new Number(-32.1)).toExponential();
1284 ok(tmp
=== "-3.21e+1", "num(-32.1).toExponential() = " + tmp
);
1285 tmp
= (new Number(4723.4235)).toExponential();
1286 ok(tmp
=== "4.7234235e+3", "num(4723.4235).toExponential() = " + tmp
);
1288 tmp
= (new Number(5)).toPrecision(12);
1289 ok(tmp
== "5.00000000000", "num(5).toPrecision(12) = " + tmp
);
1290 tmp
= (new Number(7.73)).toPrecision(7);
1291 ok(tmp
== "7.730000", "num(7.73).toPrecision(7) = " + tmp
);
1292 tmp
= (new Number(-127547.47472)).toPrecision(17);
1293 ok(tmp
== "-127547.47472000000", "num(-127547.47472).toPrecision(17) = " + tmp
);
1294 tmp
= (new Number(0)).toPrecision(3);
1295 ok(tmp
== "0.00", "num(0).toPrecision(3) = " + tmp
);
1296 tmp
= (new Number(42345.52342465464562334)).toPrecision(15);
1297 ok(tmp
== "42345.5234246546", "num(42345.52342465464562334).toPrecision(15) = " + tmp
);
1298 tmp
= (new Number(1.182e30
)).toPrecision(5);
1299 ok(tmp
== "1.1820e+30", "num(1.182e30)).toPrecision(5) = " + tmp
);
1300 tmp
= (new Number(1.123)).toPrecision();
1301 ok(tmp
== "1.123", "num(1.123).toPrecision() = " + tmp
);
1303 ok(Number() === 0, "Number() = " + Number());
1304 ok(Number(false) === 0, "Number(false) = " + Number(false));
1305 ok(Number("43") === 43, "Number('43') = " + Number("43"));
1307 tmp
= (new Number(1)).valueOf();
1308 ok(tmp
=== 1, "(new Number(1)).valueOf = " + tmp
);
1309 tmp
= (new Number(1,2)).valueOf();
1310 ok(tmp
=== 1, "(new Number(1,2)).valueOf = " + tmp
);
1311 tmp
= (new Number()).valueOf();
1312 ok(tmp
=== 0, "(new Number()).valueOf = " + tmp
);
1313 tmp
= Number
.prototype.valueOf();
1314 ok(tmp
=== 0, "Number.prototype.valueOf = " + tmp
);
1316 function equals(val
, base
) {
1319 var str
= val
.toString(base
);
1321 for(i
=0; i
<str
.length
; i
++) {
1322 if(str
.substring(i
, i
+1) == '(') break;
1323 if(str
.substring(i
, i
+1) == '.') break;
1324 num
= num
*base
+ parseInt(str
.substring(i
, i
+1));
1327 if(str
.substring(i
, i
+1) == '.') {
1329 for(i
++; i
<str
.length
; i
++) {
1330 if(str
.substring(i
, i
+1) == '(') break;
1331 num
+= parseInt(str
.substring(i
, i
+1))/mult
;
1336 if(str
.substring(i
, i
+1) == '(') {
1337 exp
= parseInt(str
.substring(i
+2));
1338 num
*= Math
.pow(base
, exp
);
1341 ok(num
>val
-val
/1000 && num<val+val/1000, "equals: num = " + num
);
1344 ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11));
1345 ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17));
1346 ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33));
1347 ok((NaN
).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN
).toString(11));
1348 ok((Infinity
).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity
).toString(11));
1349 for(i
=2; i
<10; i
++) {
1351 equals(2305843009200000000, i
);
1354 equals(1024*1024*1024*1024*1024*1024*1.9999, i
);
1357 equals(4.65661287308e-10, i
);
1358 ok((0).toString(i
) === "0", "(0).toString("+i
+") = " + (0).toString(i
));
1361 ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123'));
1362 ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7'));
1363 ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2'));
1364 ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5'));
1365 ok(parseFloat('1E5 not parsed') === 1E5
, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed'));
1366 ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN");
1367 ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3'));
1368 ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12'));
1369 ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e'));
1372 ok(tmp
=== 1, "Math.min(1) = " + tmp
);
1374 tmp
= Math
.min(1, false);
1375 ok(tmp
=== 0, "Math.min(1, false) = " + tmp
);
1378 ok(tmp
=== Infinity
, "Math.min() = " + tmp
);
1380 tmp
= Math
.min(1, NaN
, -Infinity
, false);
1381 ok(isNaN(tmp
), "Math.min(1, NaN, -Infinity, false) is not NaN");
1383 tmp
= Math
.min(1, false, true, null, -3);
1384 ok(tmp
=== -3, "Math.min(1, false, true, null, -3) = " + tmp
);
1387 ok(tmp
=== 1, "Math.max(1) = " + tmp
);
1389 tmp
= Math
.max(true, 0);
1390 ok(tmp
=== 1, "Math.max(true, 0) = " + tmp
);
1392 tmp
= Math
.max(-2, false, true, null, 1);
1393 ok(tmp
=== 1, "Math.max(-2, false, true, null, 1) = " + tmp
);
1396 ok(tmp
=== -Infinity
, "Math.max() = " + tmp
);
1398 tmp
= Math
.max(true, NaN
, 0);
1399 ok(isNaN(tmp
), "Math.max(true, NaN, 0) is not NaN");
1401 tmp
= Math
.round(0.5);
1402 ok(tmp
=== 1, "Math.round(0.5) = " + tmp
);
1404 tmp
= Math
.round(-0.5);
1405 ok(tmp
=== 0, "Math.round(-0.5) = " + tmp
);
1407 tmp
= Math
.round(1.1);
1408 ok(tmp
=== 1, "Math.round(1.1) = " + tmp
);
1410 tmp
= Math
.round(true);
1411 ok(tmp
=== 1, "Math.round(true) = " + tmp
);
1413 tmp
= Math
.round(1.1, 3, 4);
1414 ok(tmp
=== 1, "Math.round(1.1, 3, 4) = " + tmp
);
1417 ok(isNaN(tmp
), "Math.round() is not NaN");
1419 tmp
= Math
.ceil(0.5);
1420 ok(tmp
=== 1, "Math.ceil(0.5) = " + tmp
);
1422 tmp
= Math
.ceil(-0.5);
1423 ok(tmp
=== 0, "Math.ceil(-0.5) = " + tmp
);
1425 tmp
= Math
.ceil(1.1);
1426 ok(tmp
=== 2, "Math.round(1.1) = " + tmp
);
1428 tmp
= Math
.ceil(true);
1429 ok(tmp
=== 1, "Math.ceil(true) = " + tmp
);
1431 tmp
= Math
.ceil(1.1, 3, 4);
1432 ok(tmp
=== 2, "Math.ceil(1.1, 3, 4) = " + tmp
);
1435 ok(isNaN(tmp
), "ceil() is not NaN");
1437 tmp
= Math
.floor(0.5);
1438 ok(tmp
=== 0, "Math.floor(0.5) = " + tmp
);
1440 tmp
= Math
.floor(-0.5);
1441 ok(tmp
=== -1, "Math.floor(-0.5) = " + tmp
);
1443 tmp
= Math
.floor(1.1);
1444 ok(tmp
=== 1, "Math.floor(1.1) = " + tmp
);
1446 tmp
= Math
.floor(true);
1447 ok(tmp
=== 1, "Math.floor(true) = " + tmp
);
1449 tmp
= Math
.floor(1.1, 3, 4);
1450 ok(tmp
=== 1, "Math.floor(1.1, 3, 4) = " + tmp
);
1453 ok(isNaN(tmp
), "floor is not NaN");
1456 ok(tmp
=== 3, "Math.abs(3) = " + tmp
);
1459 ok(tmp
=== 3, "Math.abs(-3) = " + tmp
);
1461 tmp
= Math
.abs(true);
1462 ok(tmp
=== 1, "Math.abs(true) = " + tmp
);
1465 ok(isNaN(tmp
), "Math.abs() is not NaN");
1467 tmp
= Math
.abs(NaN
);
1468 ok(isNaN(tmp
), "Math.abs() is not NaN");
1470 tmp
= Math
.abs(-Infinity
);
1471 ok(tmp
=== Infinity
, "Math.abs(-Infinite) = " + tmp
);
1473 tmp
= Math
.abs(-3, 2);
1474 ok(tmp
=== 3, "Math.abs(-3, 2) = " + tmp
);
1477 ok(tmp
=== 1, "Math.cos(0) = " + tmp
);
1479 tmp
= Math
.cos(Math
.PI
/2);
1480 ok(Math
.floor(tmp
*100) === 0, "Math.cos(Math.PI/2) = " + tmp
);
1482 tmp
= Math
.cos(-Math
.PI
/2);
1483 ok(Math
.floor(tmp
*100) === 0, "Math.cos(-Math.PI/2) = " + tmp
);
1485 tmp
= Math
.cos(Math
.PI
/3, 2);
1486 ok(Math
.floor(tmp
*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp
);
1488 tmp
= Math
.cos(true);
1489 ok(Math
.floor(tmp
*100) === 54, "Math.cos(true) = " + tmp
);
1491 tmp
= Math
.cos(false);
1492 ok(tmp
=== 1, "Math.cos(false) = " + tmp
);
1495 ok(isNaN(tmp
), "Math.cos() is not NaN");
1497 tmp
= Math
.cos(NaN
);
1498 ok(isNaN(tmp
), "Math.cos(NaN) is not NaN");
1500 tmp
= Math
.cos(Infinity
);
1501 ok(isNaN(tmp
), "Math.cos(Infinity) is not NaN");
1503 tmp
= Math
.cos(-Infinity
);
1504 ok(isNaN(tmp
), "Math.cos(-Infinity) is not NaN");
1506 tmp
= Math
.pow(2, 2);
1507 ok(tmp
=== 4, "Math.pow(2, 2) = " + tmp
);
1509 tmp
= Math
.pow(4, 0.5);
1510 ok(tmp
=== 2, "Math.pow(2, 2) = " + tmp
);
1512 tmp
= Math
.pow(2, 2, 3);
1513 ok(tmp
=== 4, "Math.pow(2, 2, 3) = " + tmp
);
1516 ok(isNaN(tmp
), "Math.pow(2) is not NaN");
1519 ok(isNaN(tmp
), "Math.pow() is not NaN");
1521 tmp
= Math
.random();
1522 ok(typeof(tmp
) == "number", "typeof(tmp) = " + typeof(tmp
));
1523 ok(0 <= tmp
&& tmp
<= 1, "Math.random() = " + tmp
);
1525 tmp
= Math
.random(100);
1526 ok(typeof(tmp
) == "number", "typeof(tmp) = " + typeof(tmp
));
1527 ok(0 <= tmp
&& tmp
<= 1, "Math.random(100) = " + tmp
);
1530 ok(Math
.floor(tmp
*100) === 157, "Math.acos(0) = " + tmp
);
1533 ok(Math
.floor(tmp
*100) === 0, "Math.acos(1) = " + tmp
);
1535 tmp
= Math
.acos(-1);
1536 ok(Math
.floor(tmp
*100) === 314, "Math.acos(-1) = " + tmp
);
1538 tmp
= Math
.acos(Math
.PI
/4, 2);
1539 ok(Math
.floor(tmp
*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp
);
1541 tmp
= Math
.acos(true);
1542 ok(Math
.floor(tmp
*100) === 0, "Math.acos(true) = " + tmp
);
1544 tmp
= Math
.acos(false);
1545 ok(Math
.floor(tmp
*100) === 157, "Math.acos(false) = " + tmp
);
1547 tmp
= Math
.acos(1.1);
1548 ok(isNaN(tmp
), "Math.acos(1.1) is not NaN");
1551 ok(isNaN(tmp
), "Math.acos() is not NaN");
1553 tmp
= Math
.acos(NaN
);
1554 ok(isNaN(tmp
), "Math.acos(NaN) is not NaN");
1556 tmp
= Math
.acos(Infinity
);
1557 ok(isNaN(tmp
), "Math.acos(Infinity) is not NaN");
1559 tmp
= Math
.acos(-Infinity
);
1560 ok(isNaN(tmp
), "Math.acos(-Infinity) is not NaN");
1563 ok(Math
.floor(tmp
*100) === 0, "Math.asin(0) = " + tmp
);
1566 ok(Math
.floor(tmp
*100) === 157, "Math.asin(1) = " + tmp
);
1568 tmp
= Math
.asin(-1);
1569 ok(Math
.floor(tmp
*100) === -158, "Math.asin(-1) = " + tmp
);
1571 tmp
= Math
.asin(Math
.PI
/4, 2);
1572 ok(Math
.floor(tmp
*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp
);
1574 tmp
= Math
.asin(true);
1575 ok(Math
.floor(tmp
*100) === 157, "Math.asin(true) = " + tmp
);
1577 tmp
= Math
.asin(false);
1578 ok(Math
.floor(tmp
*100) === 0, "Math.asin(false) = " + tmp
);
1580 tmp
= Math
.asin(1.1);
1581 ok(isNaN(tmp
), "Math.asin(1.1) is not NaN");
1584 ok(isNaN(tmp
), "Math.asin() is not NaN");
1586 tmp
= Math
.asin(NaN
);
1587 ok(isNaN(tmp
), "Math.asin(NaN) is not NaN");
1589 tmp
= Math
.asin(Infinity
);
1590 ok(isNaN(tmp
), "Math.asin(Infinity) is not NaN");
1592 tmp
= Math
.asin(-Infinity
);
1593 ok(isNaN(tmp
), "Math.asin(-Infinity) is not NaN");
1596 ok(Math
.floor(tmp
*100) === 0, "Math.atan(0) = " + tmp
);
1599 ok(Math
.floor(tmp
*100) === 78, "Math.atan(1) = " + tmp
);
1601 tmp
= Math
.atan(-1);
1602 ok(Math
.floor(tmp
*100) === -79, "Math.atan(-1) = " + tmp
);
1604 tmp
= Math
.atan(true);
1605 ok(Math
.floor(tmp
*100) === 78, "Math.atan(true) = " + tmp
);
1607 tmp
= Math
.atan(false);
1608 ok(Math
.floor(tmp
*100) === 0, "Math.atan(false) = " + tmp
);
1611 ok(isNaN(tmp
), "Math.atan() is not NaN");
1613 tmp
= Math
.atan(NaN
);
1614 ok(isNaN(tmp
), "Math.atan(NaN) is not NaN");
1616 tmp
= Math
.atan(Infinity
);
1617 ok(Math
.floor(tmp
*100) === 157, "Math.atan(Infinity) = " + tmp
);
1619 tmp
= Math
.atan(-Infinity
);
1620 ok(Math
.floor(tmp
*100) === -158, "Math.atan(Infinity) = " + tmp
);
1622 tmp
= Math
.atan2(0, 0);
1623 ok(Math
.floor(tmp
*100) === 0, "Math.atan2(0, 0) = " + tmp
);
1625 tmp
= Math
.atan2(0, 1);
1626 ok(Math
.floor(tmp
*100) === 0, "Math.atan2(0, 1) = " + tmp
);
1628 tmp
= Math
.atan2(0, Infinity
);
1629 ok(Math
.floor(tmp
*100) === 0, "Math.atan2(0, Infinity) = " + tmp
);
1631 tmp
= Math
.atan2(0, -1);
1632 ok(Math
.floor(tmp
*100) === 314, "Math.atan2(0, -1) = " + tmp
);
1634 tmp
= Math
.atan2(0, -Infinity
);
1635 ok(Math
.floor(tmp
*100) === 314, "Math.atan2(0, -Infinity) = " + tmp
);
1637 tmp
= Math
.atan2(1, 0);
1638 ok(Math
.floor(tmp
*100) === 157, "Math.atan2(1, 0) = " + tmp
);
1640 tmp
= Math
.atan2(Infinity
, 0);
1641 ok(Math
.floor(tmp
*100) === 157, "Math.atan2(Infinity, 0) = " + tmp
);
1643 tmp
= Math
.atan2(-1, 0);
1644 ok(Math
.floor(tmp
*100) === -158, "Math.atan2(-1, 0) = " + tmp
);
1646 tmp
= Math
.atan2(-Infinity
, 0);
1647 ok(Math
.floor(tmp
*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp
);
1649 tmp
= Math
.atan2(1, 1);
1650 ok(Math
.floor(tmp
*100) === 78, "Math.atan2(1, 1) = " + tmp
);
1652 tmp
= Math
.atan2(-1, -1);
1653 ok(Math
.floor(tmp
*100) === -236, "Math.atan2(-1, -1) = " + tmp
);
1655 tmp
= Math
.atan2(-1, 1);
1656 ok(Math
.floor(tmp
*100) === -79, "Math.atan2(-1, 1) = " + tmp
);
1658 tmp
= Math
.atan2(Infinity
, Infinity
);
1659 ok(Math
.floor(tmp
*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp
);
1661 tmp
= Math
.atan2(Infinity
, -Infinity
, 1);
1662 ok(Math
.floor(tmp
*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp
);
1665 ok(isNaN(tmp
), "Math.atan2() is not NaN");
1667 tmp
= Math
.atan2(1);
1668 ok(isNaN(tmp
), "Math.atan2(1) is not NaN");
1671 ok(tmp
=== 1, "Math.exp(0) = " + tmp
);
1674 ok(Math
.floor(tmp
*100) === 271, "Math.exp(1) = " + tmp
);
1677 ok(Math
.floor(tmp
*100) === 36, "Math.exp(-1) = " + tmp
);
1679 tmp
= Math
.exp(true);
1680 ok(Math
.floor(tmp
*100) === 271, "Math.exp(true) = " + tmp
);
1682 tmp
= Math
.exp(1, 1);
1683 ok(Math
.floor(tmp
*100) === 271, "Math.exp(1, 1) = " + tmp
);
1686 ok(isNaN(tmp
), "Math.exp() is not NaN");
1688 tmp
= Math
.exp(NaN
);
1689 ok(isNaN(tmp
), "Math.exp(NaN) is not NaN");
1691 tmp
= Math
.exp(Infinity
);
1692 ok(tmp
=== Infinity
, "Math.exp(Infinity) = " + tmp
);
1694 tmp
= Math
.exp(-Infinity
);
1695 ok(tmp
=== 0, "Math.exp(-Infinity) = " + tmp
);
1698 ok(Math
.floor(tmp
*100) === 0, "Math.log(1) = " + tmp
);
1701 ok(isNaN(tmp
), "Math.log(-1) is not NaN");
1703 tmp
= Math
.log(true);
1704 ok(Math
.floor(tmp
*100) === 0, "Math.log(true) = " + tmp
);
1706 tmp
= Math
.log(1, 1);
1707 ok(Math
.floor(tmp
*100) === 0, "Math.log(1, 1) = " + tmp
);
1710 ok(isNaN(tmp
), "Math.log() is not NaN");
1712 tmp
= Math
.log(NaN
);
1713 ok(isNaN(tmp
), "Math.log(NaN) is not NaN");
1715 tmp
= Math
.log(Infinity
);
1716 ok(tmp
=== Infinity
, "Math.log(Infinity) = " + tmp
);
1718 tmp
= Math
.log(-Infinity
);
1719 ok(isNaN(tmp
), "Math.log(-Infinity) is not NaN");
1722 ok(tmp
=== 0, "Math.sin(0) = " + tmp
);
1724 tmp
= Math
.sin(Math
.PI
/2);
1725 ok(tmp
=== 1, "Math.sin(Math.PI/2) = " + tmp
);
1727 tmp
= Math
.sin(-Math
.PI
/2);
1728 ok(tmp
=== -1, "Math.sin(-Math.PI/2) = " + tmp
);
1730 tmp
= Math
.sin(Math
.PI
/3, 2);
1731 ok(Math
.floor(tmp
*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp
);
1733 tmp
= Math
.sin(true);
1734 ok(Math
.floor(tmp
*100) === 84, "Math.sin(true) = " + tmp
);
1736 tmp
= Math
.sin(false);
1737 ok(tmp
=== 0, "Math.sin(false) = " + tmp
);
1740 ok(isNaN(tmp
), "Math.sin() is not NaN");
1742 tmp
= Math
.sin(NaN
);
1743 ok(isNaN(tmp
), "Math.sin(NaN) is not NaN");
1745 tmp
= Math
.sin(Infinity
);
1746 ok(isNaN(tmp
), "Math.sin(Infinity) is not NaN");
1748 tmp
= Math
.sin(-Infinity
);
1749 ok(isNaN(tmp
), "Math.sin(-Infinity) is not NaN");
1752 ok(tmp
=== 0, "Math.sqrt(0) = " + tmp
);
1755 ok(tmp
=== 2, "Math.sqrt(4) = " + tmp
);
1757 tmp
= Math
.sqrt(-1);
1758 ok(isNaN(tmp
), "Math.sqrt(-1) is not NaN");
1760 tmp
= Math
.sqrt(2, 2);
1761 ok(Math
.floor(tmp
*100) === 141, "Math.sqrt(2, 2) = " + tmp
);
1763 tmp
= Math
.sqrt(true);
1764 ok(tmp
=== 1, "Math.sqrt(true) = " + tmp
);
1766 tmp
= Math
.sqrt(false);
1767 ok(tmp
=== 0, "Math.sqrt(false) = " + tmp
);
1770 ok(isNaN(tmp
), "Math.sqrt() is not NaN");
1772 tmp
= Math
.sqrt(NaN
);
1773 ok(isNaN(tmp
), "Math.sqrt(NaN) is not NaN");
1775 tmp
= Math
.sqrt(Infinity
);
1776 ok(tmp
=== Infinity
, "Math.sqrt(Infinity) = " + tmp
);
1778 tmp
= Math
.sqrt(-Infinity
);
1779 ok(isNaN(tmp
), "Math.sqrt(-Infinity) is not NaN");
1782 ok(tmp
=== 0, "Math.tan(0) = " + tmp
);
1784 tmp
= Math
.tan(Math
.PI
);
1785 ok(Math
.floor(tmp
*100) === -1, "Math.tan(Math.PI) = " + tmp
);
1787 tmp
= Math
.tan(2, 2);
1788 ok(Math
.floor(tmp
*100) === -219, "Math.tan(2, 2) = " + tmp
);
1790 tmp
= Math
.tan(true);
1791 ok(Math
.floor(tmp
*100) === 155, "Math.tan(true) = " + tmp
);
1793 tmp
= Math
.tan(false);
1794 ok(tmp
=== 0, "Math.tan(false) = " + tmp
);
1797 ok(isNaN(tmp
), "Math.tan() is not NaN");
1799 tmp
= Math
.tan(NaN
);
1800 ok(isNaN(tmp
), "Math.tan(NaN) is not NaN");
1802 tmp
= Math
.tan(Infinity
);
1803 ok(isNaN(tmp
), "Math.tan(Infinity) is not NaN");
1805 tmp
= Math
.tan(-Infinity
);
1806 ok(isNaN(tmp
), "Math.tan(-Infinity) is not NaN");
1809 if(invokeVersion
< 2)
1812 var stringify_tests
= [
1817 [["test"], "\"test\""],
1818 [["test\"\\\b\f\n\r\t\u0002 !"], "\"test\\\"\\\\\\b\\f\\n\\r\\t\\u0002 !\""],
1820 [[Infinity
], "null"],
1821 [[-Infinity
], "null"],
1822 [[{prop1
: true, prop2
: "string"}], "{\"prop1\":true,\"prop2\":\"string\"}"],
1823 [[{prop1
: true, prop2
: testObj
, prop3
: undefined}], "{\"prop1\":true}"],
1824 [[{prop1
: true, prop2
: {prop
: "string"}},undefined," "],
1825 "{\n \"prop1\": true,\n \"prop2\": {\n \"prop\": \"string\"\n }\n}"],
1826 [[{ },undefined," "], "{}"],
1827 [[[,2,undefined,3,{ },]],"[null,2,null,3,{},null]"],
1828 [[[,2,undefined,3,{prop
:0},],undefined," "],"[\n null,\n 2,\n null,\n 3,\n {\n \"prop\": 0\n },\n null\n]"]
1833 for(i
=0; i
< stringify_tests
.length
; i
++) {
1834 s
= JSON
.stringify
.apply(null, stringify_tests
[i
][0]);
1835 ok(s
=== stringify_tests
[i
][1],
1836 "["+i
+"] stringify(" + stringify_tests
[i
][0] + ") returned " + s
+ " expected " + stringify_tests
[i
][1]);
1839 s
= JSON
.stringify(testObj
);
1840 ok(s
=== undefined || s
=== "undefined" /* broken on some old versions */,
1841 "stringify(testObj) returned " + s
+ " expected undfined");
1843 s
= JSON
.stringify(undefined);
1844 ok(s
=== undefined || s
=== "undefined" /* broken on some old versions */,
1845 "stringify(undefined) returned " + s
+ " expected undfined");
1851 ["\"\\r\\n test\\u1111\"", "\r\n test\u1111"],
1852 ["{\"x\" :\n true}", {x
:true}],
1853 ["{\"x y\": {}, \"z\": {\"x\":null}}", {"x y":{}, z
:{x
:null}}],
1855 ["[false,{},{\"x\": []}]", [false,{},{x
:[]}]],
1858 ["1e2147483648", Infinity
]
1861 function json_cmp(x
, y
) {
1865 if(!(x
instanceof Object
) || !(y
instanceof Object
))
1868 for(var prop
in x
) {
1869 if(!x
.hasOwnProperty(prop
))
1871 if(!x
.hasOwnProperty(prop
))
1873 if(!json_cmp(x
[prop
], y
[prop
]))
1877 for(var prop
in y
) {
1878 if(!x
.hasOwnProperty(prop
) && y
.hasOwnProperty(prop
))
1885 for(i
=0; i
< parse_tests
.length
; i
++) {
1886 v
= JSON
.parse(parse_tests
[i
][0]);
1887 ok(json_cmp(v
, parse_tests
[i
][1]), "parse[" + i
+ "] returned " + v
+ ", expected " + parse_tests
[i
][1]);
1891 var func = function (a
) {
1895 ok(func
.toString() === "function (a) {\n var a = 1;\n if(a) return;\n }",
1896 "func.toString() = " + func
.toString());
1897 ok("" + func
=== "function (a) {\n var a = 1;\n if(a) return;\n }",
1898 "'' + func.toString() = " + func
);
1900 ok(func
.valueOf
=== Object
.prototype.valueOf
, "func.valueOf !== Object.prototype.valueOf");
1901 ok(func
=== func
.valueOf(), "func !== func.valueOf()");
1903 function testFuncToString(x
,y
) {
1906 ok(testFuncToString
.toString() === "function testFuncToString(x,y) {\n return x+y;\n}",
1907 "testFuncToString.toString() = " + testFuncToString
.toString());
1908 ok("" + testFuncToString
=== "function testFuncToString(x,y) {\n return x+y;\n}",
1909 "'' + testFuncToString = " + testFuncToString
);
1913 function callTest(argc
) {
1914 ok(this === tmp
, "this !== tmp\n");
1915 ok(arguments
.length
=== argc
+1, "arguments.length = " + arguments
.length
+ " expected " + (argc
+1));
1916 for(var i
=1; i
<= argc
; i
++)
1917 ok(arguments
[i
] === i
, "arguments[i] = " + arguments
[i
]);
1919 for(var i
=1; i
<= argc
; i
++)
1920 ok(a
[i
] === i
, "a[i] = " + a
[i
]);
1923 callTest
.call(tmp
, 1, 1);
1924 callTest
.call(tmp
, 2, 1, 2);
1925 callTest
.call(tmp
, 3, 1, 2, 3);
1927 callTest
.apply(tmp
, [1, 1]);
1928 callTest
.apply(tmp
, [2, 1, 2]);
1929 callTest
.apply(tmp
, [3, 1, 2, 3]);
1930 (function () { callTest
.apply(tmp
, arguments
); })(2,1,2);
1932 function callTest2() {
1933 ok(this === tmp
, "this !== tmp\n");
1934 ok(arguments
.length
=== 0, "callTest2: arguments.length = " + arguments
.length
+ " expected 0");
1937 callTest2
.call(tmp
);
1938 callTest2
.apply(tmp
, []);
1939 callTest2
.apply(tmp
);
1940 (function () { callTest2
.apply(tmp
, arguments
); })();
1942 function callTest3() {
1944 ok(arguments
.length
=== 0, "arguments.length = " + arguments
.length
+ " expected 0");
1948 callTest3
.call(undefined);
1949 callTest3
.call(null);
1951 callTest3
.apply(undefined);
1952 callTest3
.apply(null);
1954 tmp
= Number
.prototype.toString
.call(3);
1955 ok(tmp
=== "3", "Number.prototype.toString.call(3) = " + tmp
);
1957 var func
= new Function("return 3;");
1960 ok(tmp
=== 3, "func() = " + tmp
);
1961 ok(func
.call() === 3, "func.call() = " + tmp
);
1962 ok(func
.length
=== 0, "func.length = " + func
.length
);
1963 tmp
= func
.toString();
1964 ok(tmp
=== "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp
);
1966 func
= new Function("x", "return x+2;");
1968 ok(tmp
=== 3, "func(1) = " + tmp
);
1969 tmp
= func
.toString();
1970 ok(tmp
=== "function anonymous(x) {\nreturn x+2;\n}", "func.toString() = " + tmp
);
1972 tmp
= (new Function("x ", "return x+2;")).toString();
1973 ok(tmp
=== "function anonymous(x ) {\nreturn x+2;\n}", "func.toString() = " + tmp
);
1975 func
= new Function("x", "y", "return x+y");
1977 ok(tmp
=== 4, "func(1,3) = " + tmp
);
1978 tmp
= func
.toString();
1979 ok(tmp
=== "function anonymous(x, y) {\nreturn x+y\n}", "func.toString() = " + tmp
);
1981 func
= new Function(" x, \ty", "\tz", "return x+y+z;");
1983 ok(tmp
=== 6, "func(1,3,2) = " + tmp
);
1984 ok(func
.length
=== 3, "func.length = " + func
.length
);
1985 tmp
= func
.toString();
1986 ok(tmp
=== "function anonymous( x, \ty, \tz) {\nreturn x+y+z;\n}", "func.toString() = " + tmp
);
1988 func
= new Function();
1990 ok(tmp
=== undefined, "func() = " + tmp
);
1991 tmp
= func
.toString();
1992 ok(tmp
== "function anonymous() {\n\n}", "func.toString() = " + tmp
);
1994 // Function constructor called as function
1995 func
= Function("return 3;");
1998 ok(tmp
=== 3, "func() = " + tmp
);
1999 ok(func
.call() === 3, "func.call() = " + tmp
);
2000 ok(func
.length
=== 0, "func.length = " + func
.length
);
2001 tmp
= func
.toString();
2002 ok(tmp
=== "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp
);
2004 func
= (function() {
2006 return new Function("return tmp;");
2010 ok(tmp
=== 2, "func() = " + tmp
);
2012 var date
= new Date();
2014 date
= new Date(100);
2015 ok(date
.getTime() === 100, "date.getTime() = " + date
.getTime());
2016 ok(Date
.prototype.getTime() === 0, "date.prototype.getTime() = " + Date
.prototype.getTime());
2017 date
= new Date(8.64e15
);
2018 ok(date
.getTime() === 8.64e15
, "date.getTime() = " + date
.getTime());
2019 date
= new Date(8.64e15
+1);
2020 ok(isNaN(0+date
.getTime()), "date.getTime() is not NaN");
2021 date
= new Date(Infinity
);
2022 ok(isNaN(0+date
.getTime()), "date.getTime() is not NaN");
2023 date
= new Date("3 July 2009 22:28:00 UTC+0100");
2024 ok(date
.getTime() === 1246656480000, "date.getTime() = " + date
.getTime());
2025 date
= new Date(1984, 11, 29, 13, 51, 24, 120);
2026 ok(date
.getFullYear() === 1984, "date.getFullYear() = " + date
.getFullYear());
2027 ok(date
.getMonth() === 11, "date.getMonth() = " + date
.getMonth());
2028 ok(date
.getDate() === 29, "date.getDate() = " + date
.getDate());
2029 ok(date
.getHours() === 13, "date.getHours() = " + date
.getHours());
2030 ok(date
.getMinutes() === 51, "date.getMinutes() = " + date
.getMinutes());
2031 ok(date
.getSeconds() === 24, "date.getSeconds() = " + date
.getSeconds());
2032 ok(date
.getMilliseconds() === 120, "date.getMilliseconds() = " + date
.getMilliseconds());
2033 date
= new Date(731, -32, 40, -1, 70, 65, -13);
2034 ok(date
.getFullYear() === 728, "date.getFullYear() = " + date
.getFullYear());
2035 ok(date
.getMonth() === 5, "date.getMonth() = " + date
.getMonth());
2036 ok(date
.getDate() === 9, "date.getDate() = " + date
.getDate());
2037 ok(date
.getHours() === 0, "date.getHours() = " + date
.getHours());
2038 ok(date
.getMinutes() === 11, "date.getMinutes() = " + date
.getMinutes());
2039 ok(date
.getSeconds() === 4, "date.getSeconds() = " + date
.getSeconds());
2040 ok(date
.getMilliseconds() === 987, "date.getMilliseconds() = " + date
.getMilliseconds());
2042 ok(date
.setTime(123) === 123, "date.setTime(123) !== 123");
2043 ok(date
.setTime("123", NaN
) === 123, "date.setTime(\"123\") !== 123");
2044 ok(isNaN(date
.setTime(NaN
)), "date.setTime(NaN) is not NaN");
2046 ok(date
.setTime(0) === date
.getTime(), "date.setTime(0) !== date.getTime()");
2047 ok(date
.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date
.getUTCFullYear());
2048 ok(date
.getUTCMonth() === 0, "date.getUTCMonth() = " + date
.getUTCMonth());
2049 ok(date
.getUTCDate() === 1, "date.getUTCDate() = " + date
.getUTCDate());
2050 ok(date
.getUTCDay() === 4, "date.getUTCDay() = " + date
.getUTCDay());
2051 ok(date
.getUTCHours() === 0, "date.getUTCHours() = " + date
.getUTCHours());
2052 ok(date
.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date
.getUTCMinutes());
2053 ok(date
.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date
.getUTCSeconds());
2054 ok(date
.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2056 date
.setTime(60*24*60*60*1000);
2057 ok(date
.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date
.getUTCFullYear());
2058 ok(date
.getUTCMonth() === 2, "date.getUTCMonth() = " + date
.getUTCMonth());
2059 ok(date
.getUTCDate() === 2, "date.getUTCDate() = " + date
.getUTCDate());
2060 ok(date
.getUTCDay() === 1, "date.getUTCDay() = " + date
.getUTCDay());
2061 ok(date
.getUTCHours() === 0, "date.getUTCHours() = " + date
.getUTCHours());
2062 ok(date
.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date
.getUTCMinutes());
2063 ok(date
.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date
.getUTCSeconds());
2064 ok(date
.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2066 date
.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640);
2067 ok(date
.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date
.getUTCFullYear());
2068 ok(date
.getUTCMonth() === 1, "date.getUTCMonth() = " + date
.getUTCMonth());
2069 ok(date
.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date
.getUTCMonth());
2070 ok(date
.getUTCDate() === 28, "date.getUTCDate() = " + date
.getUTCDate());
2071 ok(date
.getUTCDay() === 4, "date.getUTCDay() = " + date
.getUTCDay());
2072 ok(date
.getUTCHours() === 1, "date.getUTCHours() = " + date
.getUTCHours());
2073 ok(date
.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date
.getUTCMinutes());
2074 ok(date
.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date
.getUTCSeconds());
2075 ok(date
.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2077 tmp
= date
.setYear(96);
2078 ok(date
.getYear() === 96, "date.getYear() = " + date
.getYear());
2079 ok(date
.getFullYear() === 1996, "date.getFullYear() = " + date
.getYear());
2080 ok(date
.getUTCMonth() === 1, "date.getUTCMonth() = " + date
.getUTCMonth());
2081 ok(date
.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date
.getUTCMonth());
2082 ok(date
.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2084 tmp
= date
.setYear(2010);
2085 ok(tmp
=== date
.getTime(), "date.setYear(2010) = " + tmp
);
2086 ok(date
.getYear() === 2010, "date.getYear() = " + date
.getYear());
2087 ok(date
.getFullYear() === 2010, "date.getFullYear() = " + date
.getYear());
2088 ok(date
.getUTCMonth() === 1, "date.getUTCMonth() = " + date
.getUTCMonth());
2089 ok(date
.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date
.getUTCMonth());
2090 ok(date
.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2092 date
.setTime(Infinity
);
2093 ok(isNaN(date
.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
2094 ok(isNaN(date
.getUTCMonth()), "date.getUTCMonth() is not NaN");
2095 ok(isNaN(date
.getUTCDate()), "date.getUTCDate() is not NaN");
2096 ok(isNaN(date
.getUTCDay()), "date.getUTCDay() is not NaN");
2097 ok(isNaN(date
.getUTCHours()), "date.getUTCHours() is not NaN");
2098 ok(isNaN(date
.getUTCMinutes()), "date.getUTCMinutes() is not NaN");
2099 ok(isNaN(date
.getUTCSeconds()), "date.getUTCSeconds() is not NaN");
2100 ok(isNaN(date
.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN");
2101 ok(isNaN(date
.setMilliseconds(0)), "date.setMilliseconds() is not NaN");
2104 tmp
= date
.setYear(NaN
);
2105 ok(isNaN(tmp
), "date.setYear(NaN) = " + tmp
);
2106 ok(isNaN(date
.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
2107 ok(isNaN(date
.getUTCMonth()), "date.getUTCMonth() is not NaN");
2110 date
.setUTCMilliseconds(-10, 2);
2111 ok(date
.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2112 date
.setUTCMilliseconds(10);
2113 ok(date
.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date
.getUTCMilliseconds());
2114 date
.setUTCSeconds(-10);
2115 ok(date
.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date
.getUTCSeconds());
2116 date
.setUTCMinutes(-10);
2117 ok(date
.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date
.getUTCMinutes());
2118 date
.setUTCHours(-10);
2119 ok(date
.getUTCHours() === 14, "date.getUTCHours() = " + date
.getUTCHours());
2120 date
.setUTCHours(-123);
2121 ok(date
.getTime() === -612549990, "date.getTime() = " + date
.getTime());
2122 date
.setUTCHours(20);
2123 ok(date
.getUTCHours() === 20, "date.getUTCHours() = " + date
.getUTCHours());
2124 date
.setUTCDate(32);
2125 ok(date
.getUTCDate() === 1, "date.getUTCDate() = " + date
.getUTCDate());
2126 date
.setUTCMonth(22, 37);
2127 ok(date
.getTime() === 60987050010, "date.getTime() = " + date
.getTime());
2128 date
.setUTCFullYear(83, 21, 321);
2129 ok(date
.getTime() === -59464984149990, "date.getTime() = " + date
.getTime());
2130 ok(Math
.abs(date
) === 59464984149990, "Math.abs(date) = " + Math
.abs(date
));
2131 ok(getVT(date
+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date
+1));
2133 ok(isNaN(Date
.parse()), "Date.parse() is not NaN");
2134 ok(isNaN(Date
.parse("")), "Date.parse(\"\") is not NaN");
2135 ok(isNaN(Date
.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN");
2136 ok(Date
.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date
.parse("Jan 20 2009 UTC"));
2137 ok(Date
.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date
.parse("Jan 20 2009 GMT"));
2138 ok(Date
.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date
.parse("Jan 20 2009 UTC-0"));
2139 ok(Date
.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date
.parse("Jan 20 2009 UTC+0000"));
2140 ok(Date
.parse("Jan 20 2009 UTC-1") === 1232413200000, "Date.parse(\"Jan 20 2009 UTC-1\") = " + Date
.parse("Jan 20 2009 UTC-1"));
2141 ok(Date
.parse("Jan 20 2009 UTC+1") === 1232406000000, "Date.parse(\"Jan 20 2009 UTC+1\") = " + Date
.parse("Jan 20 2009 UTC+1"));
2142 ok(Date
.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date
.parse("Ju 13 79 UTC"));
2143 ok(Date
.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date
.parse("12Au91 UTC"));
2144 ok(Date
.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date
.parse("7/02/17 UTC"));
2145 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"));
2146 ok(Date
.parse("February 31 UTC, 2000 12:31:17 PM") === 952000277000,
2147 "Date.parse(\"February 31 UTC, 2000 12:31:17 PM\") = " + Date
.parse("February 31 UTC, 2000 12:31:17 PM"));
2148 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 "));
2149 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"));
2150 ok(Date
.parse("1970/01/01") === Date
.parse("01/01/1970"), "Date.parse(\"1970/01/01\") = " + Date
.parse("1970/01/01"));
2151 ok(Date
.parse("71/12/14") === Date
.parse("12/14/1971"), "Date.parse(\"71/12/14\") = " + Date
.parse("71/12/14"));
2152 ok(Date
.parse("Tue, 22 Mar 2016 09:57:55 -0300") === Date
.parse("Tue, 22 Mar 2016 09:57:55 GMT-0300"),
2153 "Date.parse(\"Tue, 22 Mar 2016 09:57:55 -0300\") = " + Date
.parse("Tue, 22 Mar 2016 09:57:55 -0300"));
2154 ok(Date
.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date
.parse("Tue, 22 Mar 2016 09:57:55 UTC+0400"),
2155 "Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date
.parse("Tue, 22 Mar 2016 09:57:55 +0400"));
2157 tmp
= (new Date()).toGMTString();
2158 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2159 tmp
= (new Date()).toLocaleDateString();
2160 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2161 tmp
= (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleDateString();
2162 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2163 tmp
= (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleString();
2164 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2165 tmp
= (new Date()).toLocaleTimeString();
2166 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2167 tmp
= (new Date()).toString();
2168 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2169 tmp
= (new Date()).toTimeString();
2170 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2171 tmp
= (new Date()).toUTCString();
2172 ok(tmp
.indexOf(String
.fromCharCode(0)) == -1, "invalid null byte");
2174 ok(typeof(Math
.PI
) === "number", "typeof(Math.PI) = " + typeof(Math
.PI
));
2175 ok(Math
.floor(Math
.PI
*100) === 314, "Math.PI = " + Math
.PI
);
2177 ok(Math
.floor(Math
.PI
*100) === 314, "modified Math.PI = " + Math
.PI
);
2179 ok(typeof(Math
.E
) === "number", "typeof(Math.E) = " + typeof(Math
.E
));
2180 ok(Math
.floor(Math
.E
*100) === 271, "Math.E = " + Math
.E
);
2182 ok(Math
.floor(Math
.E
*100) === 271, "modified Math.E = " + Math
.E
);
2184 ok(typeof(Math
.LOG2E
) === "number", "typeof(Math.LOG2E) = " + typeof(Math
.LOG2E
));
2185 ok(Math
.floor(Math
.LOG2E
*100) === 144, "Math.LOG2E = " + Math
.LOG2E
);
2186 Math
.LOG2E
= "test";
2187 ok(Math
.floor(Math
.LOG2E
*100) === 144, "modified Math.LOG2E = " + Math
.LOG2E
);
2189 ok(typeof(Math
.LOG10E
) === "number", "typeof(Math.LOG10E) = " + typeof(Math
.LOG10E
));
2190 ok(Math
.floor(Math
.LOG10E
*100) === 43, "Math.LOG10E = " + Math
.LOG10E
);
2191 Math
.LOG10E
= "test";
2192 ok(Math
.floor(Math
.LOG10E
*100) === 43, "modified Math.LOG10E = " + Math
.LOG10E
);
2194 ok(typeof(Math
.LN2
) === "number", "typeof(Math.LN2) = " + typeof(Math
.LN2
));
2195 ok(Math
.floor(Math
.LN2
*100) === 69, "Math.LN2 = " + Math
.LN2
);
2197 ok(Math
.floor(Math
.LN2
*100) === 69, "modified Math.LN2 = " + Math
.LN2
);
2199 ok(typeof(Math
.LN10
) === "number", "typeof(Math.LN10) = " + typeof(Math
.LN10
));
2200 ok(Math
.floor(Math
.LN10
*100) === 230, "Math.LN10 = " + Math
.LN10
);
2202 ok(Math
.floor(Math
.LN10
*100) === 230, "modified Math.LN10 = " + Math
.LN10
);
2204 ok(typeof(Math
.SQRT2
) === "number", "typeof(Math.SQRT2) = " + typeof(Math
.SQRT2
));
2205 ok(Math
.floor(Math
.SQRT2
*100) === 141, "Math.SQRT2 = " + Math
.SQRT2
);
2206 Math
.SQRT2
= "test";
2207 ok(Math
.floor(Math
.SQRT2
*100) === 141, "modified Math.SQRT2 = " + Math
.SQRT2
);
2209 ok(typeof(Math
.SQRT1_2
) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math
.SQRT1_2
));
2210 ok(Math
.floor(Math
.SQRT1_2
*100) === 70, "Math.SQRT1_2 = " + Math
.SQRT1_2
);
2211 Math
.SQRT1_2
= "test";
2212 ok(Math
.floor(Math
.SQRT1_2
*100) === 70, "modified Math.SQRT1_2 = " + Math
.SQRT1_2
);
2214 ok(isNaN
.toString() === "\nfunction isNaN() {\n [native code]\n}\n",
2215 "isNaN.toString = '" + isNaN
.toString() + "'");
2216 ok(Array
.toString() === "\nfunction Array() {\n [native code]\n}\n",
2217 "isNaN.toString = '" + Array
.toString() + "'");
2218 ok(Function
.toString() === "\nfunction Function() {\n [native code]\n}\n",
2219 "isNaN.toString = '" + Function
.toString() + "'");
2220 ok(Function
.prototype.toString() === "\nfunction prototype() {\n [native code]\n}\n",
2221 "isNaN.toString = '" + Function
.prototype.toString() + "'");
2222 ok("".substr
.toString() === "\nfunction substr() {\n [native code]\n}\n",
2223 "''.substr.toString = '" + "".substr
.toString() + "'");
2225 var bool
= new Boolean();
2226 ok(bool
.toString() === "false", "bool.toString() = " + bool
.toString());
2227 var bool
= new Boolean("false");
2228 ok(bool
.toString() === "true", "bool.toString() = " + bool
.toString());
2229 ok(bool
.valueOf() === Boolean(1), "bool.valueOf() = " + bool
.valueOf());
2230 ok(bool
.toLocaleString() === bool
.toString(), "bool.toLocaleString() = " + bool
.toLocaleString());
2232 ok(ActiveXObject
instanceof Function
, "ActiveXObject is not instance of Function");
2233 ok(ActiveXObject
.prototype instanceof Object
, "ActiveXObject.prototype is not instance of Object");
2235 ok(Error
.prototype !== TypeError
.prototype, "Error.prototype === TypeError.prototype");
2236 ok(RangeError
.prototype !== TypeError
.prototype, "RangeError.prototype === TypeError.prototype");
2237 ok(Error
.prototype.toLocaleString
=== Object
.prototype.toLocaleString
,
2238 "Error.prototype.toLocaleString !== Object.prototype.toLocaleString");
2240 ok(err
.valueOf
=== Object
.prototype.valueOf
, "err.valueOf !== Object.prototype.valueOf");
2241 ok(Error
.prototype.name
=== "Error", "Error.prototype.name = " + Error
.prototype.name
);
2242 ok(err
.name
=== "Error", "err.name = " + err
.name
);
2243 EvalError
.prototype.message
= "test";
2244 ok(EvalError
.prototype.message
=== "test", "EvalError.prototype.message = " + EvalError
.prototype.message
);
2245 ok(err
.toString
!== Object
.prototype.toString
, "err.toString === Object.prototype.toString");
2246 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "Error"), "err.toString() = " + err
.toString());
2247 err
= new EvalError();
2248 ok(EvalError
.prototype.name
=== "EvalError", "EvalError.prototype.name = " + EvalError
.prototype.name
);
2249 ok(err
.name
=== "EvalError", "err.name = " + err
.name
);
2250 ok(err
.toString
=== Error
.prototype.toString
, "err.toString !== Error.prototype.toString");
2251 ok(err
.message
=== "", "err.message != ''");
2253 ok(err
.message
=== date
, "err.message != date");
2254 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "EvalError: "+err
.message
),
2255 "err.toString() = " + err
.toString());
2256 ok(err
.toString
!== Object
.prototype.toString
, "err.toString === Object.prototype.toString");
2257 err
= new RangeError();
2258 ok(RangeError
.prototype.name
=== "RangeError", "RangeError.prototype.name = " + RangeError
.prototype.name
);
2259 ok(err
.name
=== "RangeError", "err.name = " + err
.name
);
2260 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "RangeError"), "err.toString() = " + err
.toString());
2261 err
= new ReferenceError();
2262 ok(ReferenceError
.prototype.name
=== "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError
.prototype.name
);
2263 ok(err
.name
=== "ReferenceError", "err.name = " + err
.name
);
2264 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "ReferenceError"), "err.toString() = " + err
.toString());
2265 err
= new SyntaxError();
2266 ok(SyntaxError
.prototype.name
=== "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError
.prototype.name
);
2267 ok(err
.name
=== "SyntaxError", "err.name = " + err
.name
);
2268 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "SyntaxError"), "err.toString() = " + err
.toString());
2269 err
= new TypeError();
2270 ok(TypeError
.prototype.name
=== "TypeError", "TypeError.prototype.name = " + TypeError
.prototype.name
);
2271 ok(err
.name
=== "TypeError", "err.name = " + err
.name
);
2272 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "TypeError"), "err.toString() = " + err
.toString());
2273 err
= new URIError();
2274 ok(URIError
.prototype.name
=== "URIError", "URIError.prototype.name = " + URIError
.prototype.name
);
2275 ok(err
.name
=== "URIError", "err.name = " + err
.name
);
2276 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "URIError"), "err.toString() = " + err
.toString());
2277 err
= new Error("message");
2278 ok(err
.message
=== "message", "err.message !== 'message'");
2279 ok(err
.toString() === (invokeVersion
< 2 ? "[object Error]" : "Error: message"), "err.toString() = " + err
.toString());
2280 err
= new Error(123);
2281 ok(err
.number
=== 123, "err.number = " + err
.number
);
2283 ok(err
.number
=== 254, "err.number = " + err
.number
);
2284 err
= new Error(0, "message");
2285 ok(err
.number
=== 0, "err.number = " + err
.number
);
2286 ok(err
.message
=== "message", "err.message = " + err
.message
);
2287 ok(err
.description
=== "message", "err.description = " + err
.description
);
2289 ok(err
.number
=== 0, "err.number = " + err
.number
);
2290 ok(err
.description
=== "", "err.description = " + err
.description
);
2291 err
.description
= 5;
2292 ok(err
.description
=== 5, "err.description = " + err
.description
);
2293 ok(err
.message
=== "", "err.message = " + err
.message
);
2295 ok(err
.message
=== 4, "err.message = " + err
.message
);
2297 ok(!("number" in Error
), "number is in Error");
2300 ok(tmp
.hasOwnProperty("toString") === false, "toString property should be inherited");
2301 tmp
.toString = function() { return "test"; };
2302 ok(tmp
.hasOwnProperty("toString") === true, "toString own property should exist");
2303 ok(tmp
.hasOwnProperty("nonExisting") === false, "nonExisting property should not exist");
2305 tmp
= Error
.prototype.toString
.call(tmp
);
2306 ok(tmp
=== "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp
);
2308 tmp = function() { return 0; };
2310 ok(tmp
.hasOwnProperty("toString") === false, "toString property should be inherited");
2311 ok(tmp
.hasOwnProperty("0") === true, "hasOwnProperty(0) returned false");
2312 ok(tmp
.hasOwnProperty() === false, "hasOwnProperty() returned true");
2314 ok(Object
.prototype.hasOwnProperty
.call(testObj
) === false, "hasOwnProperty without name returned true");
2316 if(invokeVersion
>= 2) {
2319 tmp
= Error
.prototype.toString
.call(obj
);
2320 ok(tmp
=== "test", "Error.prototype.toString.call(obj) = " + tmp
);
2324 obj
.message
= false;
2325 tmp
= Error
.prototype.toString
.call(obj
);
2326 ok(tmp
=== "6: false", "Error.prototype.toString.call(obj) = " + tmp
);
2329 obj
.message
= "test";
2330 tmp
= Error
.prototype.toString
.call(obj
);
2331 ok(tmp
=== "test", "Error.prototype.toString.call(obj) = " + tmp
);
2335 obj
.message
= "test";
2336 tmp
= Error
.prototype.toString
.call(obj
);
2337 ok(tmp
=== "test", "Error.prototype.toString.call(obj) = " + tmp
);
2340 tmp
= Error
.prototype.toString
.call(testObj
);
2341 ok(tmp
=== "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp
);
2345 ok(err
.name
=== null, "err.name = " + err
.name
+ " expected null");
2346 if(invokeVersion
>= 2)
2347 ok(err
.toString() === "null", "err.toString() = " + err
.toString());
2350 err
.message
= false;
2351 ok(err
.message
=== false, "err.message = " + err
.message
+ " expected false");
2352 if(invokeVersion
>= 2)
2353 ok(err
.toString() === "Error: false", "err.toString() = " + err
.toString());
2356 err
.message
= new Object();
2357 err
.message
.toString = function() { return ""; };
2358 if(invokeVersion
>= 2)
2359 ok(err
.toString() === "Error", "err.toString() = " + err
.toString());
2362 err
.message
= undefined;
2363 if(invokeVersion
>= 2)
2364 ok(err
.toString() === "Error", "err.toString() = " + err
.toString());
2366 var exception_array
= {
2367 E_INVALID_LENGTH
: { type
: "RangeError", number
: -2146823259 },
2369 E_NOT_DATE
: { type
: "TypeError", number
: -2146823282 },
2370 E_NOT_BOOL
: { type
: "TypeError", number
: -2146823278 },
2371 E_ARG_NOT_OPT
: { type
: "TypeError", number
: -2146827839 },
2372 E_NO_PROPERTY
: { type
: "TypeError", number
: -2146827850 },
2373 E_NOT_NUM
: { type
: "TypeError", number
: -2146823287 },
2374 E_INVALID_CALL_ARG
: { type
: "TypeError", number
: -2146828283 },
2375 E_NOT_FUNC
: { type
: "TypeError", number
: -2146823286 },
2376 E_OBJECT_EXPECTED
: { type
: "TypeError", number
: -2146823281 },
2377 E_OBJECT_REQUIRED
: { type
: "TypeError", number
: -2146827864 },
2378 E_UNSUPPORTED_ACTION
: { type
: "TypeError", number
: -2146827843 },
2379 E_NOT_VBARRAY
: { type
: "TypeError", number
: -2146823275 },
2380 E_INVALID_DELETE
: { type
: "TypeError", number
: -2146823276 },
2381 E_UNDEFINED
: { type
: "TypeError", number
: -2146823279 },
2382 E_JSCRIPT_EXPECTED
: { type
: "TypeError", number
: -2146823274 },
2383 E_NOT_ARRAY
: { type
: "TypeError", number
: -2146823257 },
2385 E_SYNTAX_ERROR
: { type
: "SyntaxError", number
: -2146827286 },
2386 E_LBRACKET
: { type
: "SyntaxError", number
: -2146827283 },
2387 E_RBRACKET
: { type
: "SyntaxError", number
: -2146827282 },
2388 E_SEMICOLON
: { type
: "SyntaxError", number
: -2146827284 },
2389 E_UNTERMINATED_STR
: { type
: "SyntaxError", number
: -2146827273 },
2390 E_DISABLED_CC
: { type
: "SyntaxError", number
: -2146827258 },
2391 E_INVALID_BREAK
: { type
: "SyntaxError", number
: -2146827269 },
2392 E_INVALID_CONTINUE
: { type
: "SyntaxError", number
: -2146827268 },
2393 E_LABEL_NOT_FOUND
: { type
: "SyntaxError", number
: -2146827262 },
2394 E_LABEL_REDEFINED
: { type
: "SyntaxError", number
: -2146827263 },
2395 E_MISPLACED_RETURN
: { type
: "SyntaxError", number
: -2146827270 },
2397 E_ILLEGAL_ASSIGN
: { type
: "ReferenceError", number
: -2146823280 },
2399 E_PRECISION_OUT_OF_RANGE
: {type
: "RangeError", number
: -2146823261 },
2400 E_FRACTION_DIGITS_OUT_OF_RANGE
: {type
: "RangeError", number
: -2146823262 },
2401 E_SUBSCRIPT_OUT_OF_RANGE
: {type
: "RangeError", number
: -2146828279 },
2403 E_REGEXP_SYNTAX_ERROR
: { type
: "RegExpError", number
: -2146823271 },
2405 E_URI_INVALID_CHAR
: { type
: "URIError", number
: -2146823264 },
2406 E_URI_INVALID_CODING
: { type
: "URIError", number
: -2146823263 }
2409 function testException(func
, id
) {
2410 var ex
= exception_array
[id
];
2411 var ret
= "", num
= "";
2420 ok(ret
=== ex
.type
, "Exception test, ret = " + ret
+ ", expected " + ex
.type
+". Executed function: " + func
.toString());
2421 ok(num
=== ex
.number
, "Exception test, num = " + num
+ ", expected " + ex
.number
+ ". Executed function: " + func
.toString());
2425 testException(function() {Array(-3);}, "E_INVALID_LENGTH");
2426 testException(function() {createArray().lbound("aaa");}, "E_SUBSCRIPT_OUT_OF_RANGE");
2427 testException(function() {createArray().lbound(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
2428 testException(function() {createArray().getItem(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
2431 testException(function() {date
.setTime();}, "E_ARG_NOT_OPT");
2432 testException(function() {date
.setYear();}, "E_ARG_NOT_OPT");
2433 testException(function() {arr
.test();}, "E_NO_PROPERTY");
2434 testException(function() {Number
.prototype.toString
.call(arr
);}, "E_NOT_NUM");
2435 testException(function() {Number
.prototype.toFixed
.call(arr
);}, "E_NOT_NUM");
2436 testException(function() {(new Number(3)).toString(1);}, "E_INVALID_CALL_ARG");
2437 testException(function() {(new Number(3)).toFixed(21);}, "E_FRACTION_DIGITS_OUT_OF_RANGE");
2438 testException(function() {(new Number(1)).toPrecision(0);}, "E_PRECISION_OUT_OF_RANGE");
2439 testException(function() {not_existing_variable
.something();}, "E_UNDEFINED");
2440 testException(function() {date();}, "E_NOT_FUNC");
2441 testException(function() {arr();}, "E_NOT_FUNC");
2442 testException(function() {(new Object
) instanceof (new Object
);}, "E_NOT_FUNC");
2443 testException(function() {eval("nonexistingfunc()")}, "E_OBJECT_EXPECTED");
2444 testException(function() {(new Object()) instanceof 3;}, "E_NOT_FUNC");
2445 testException(function() {(new Object()) instanceof null;}, "E_NOT_FUNC");
2446 testException(function() {(new Object()) instanceof nullDisp
;}, "E_NOT_FUNC");
2447 testException(function() {"test" in 3;}, "E_OBJECT_EXPECTED");
2448 testException(function() {"test" in null;}, "E_OBJECT_EXPECTED");
2449 testException(function() {"test" in nullDisp
;}, "E_OBJECT_EXPECTED");
2450 testException(function() {new 3;}, "E_UNSUPPORTED_ACTION");
2451 testException(function() {new null;}, "E_OBJECT_EXPECTED");
2452 testException(function() {new nullDisp
;}, "E_NO_PROPERTY");
2453 testException(function() {new VBArray();}, "E_NOT_VBARRAY");
2454 testException(function() {new VBArray(new VBArray(createArray()));}, "E_NOT_VBARRAY");
2455 testException(function() {VBArray
.prototype.lbound
.call(new Object());}, "E_NOT_VBARRAY");
2456 testException(function() {+nullDisp
.prop
;}, "E_OBJECT_REQUIRED");
2457 testException(function() {+nullDisp
["prop"];}, "E_OBJECT_REQUIRED");
2458 testException(function() {delete (new Object());}, "E_INVALID_DELETE");
2459 testException(function() {delete false;}, "E_INVALID_DELETE");
2460 testException(function() {undefined.toString();}, "E_OBJECT_EXPECTED");
2461 testException(function() {null.toString();}, "E_OBJECT_EXPECTED");
2466 testException(function() {delete ((tmp
= true) ? obj
.prop
: obj
.prop
);}, "E_INVALID_DELETE");
2467 ok(tmp
, "delete (..) expression not evaluated");
2469 //FIXME: testException(function() {nonexistent++;}, "E_OBJECT_EXPECTED");
2470 //FIXME: testException(function() {undefined.nonexistent++;}, "E_OBJECT_EXPECTED");
2473 // SyntaxError tests
2474 function testSyntaxError(code
, id
) {
2475 var ex
= exception_array
[id
];
2476 var ret
= "", num
= "";
2485 ok(ret
=== ex
.type
, "Syntax exception test, ret = " + ret
+ ", expected " + ex
.type
+". Executed code: " + code
);
2486 ok(num
=== ex
.number
, "Syntax exception test, num = " + num
+ ", expected " + ex
.number
+ ". Executed code: " + code
);
2489 testSyntaxError("for(i=0;) {}", "E_SYNTAX_ERROR");
2490 testSyntaxError("function {};", "E_LBRACKET");
2491 testSyntaxError("if", "E_LBRACKET");
2492 testSyntaxError("do i=0; while", "E_LBRACKET");
2493 testSyntaxError("while", "E_LBRACKET");
2494 testSyntaxError("for", "E_LBRACKET");
2495 testSyntaxError("with", "E_LBRACKET");
2496 testSyntaxError("switch", "E_LBRACKET");
2497 testSyntaxError("if(false", "E_RBRACKET");
2498 testSyntaxError("for(i=0; i<10; i++", "E_RBRACKET");
2499 testSyntaxError("while(true", "E_RBRACKET");
2500 testSyntaxError("for(i=0", "E_SEMICOLON");
2501 testSyntaxError("for(i=0;i<10", "E_SEMICOLON");
2502 testSyntaxError("while(", "E_SYNTAX_ERROR");
2503 testSyntaxError("if(", "E_SYNTAX_ERROR");
2504 testSyntaxError("'unterminated", "E_UNTERMINATED_STR");
2505 testSyntaxError("*", "E_SYNTAX_ERROR");
2506 testSyntaxError("@_jscript_version", "E_DISABLED_CC");
2507 testSyntaxError("@a", "E_DISABLED_CC");
2508 testSyntaxError("/* @cc_on @*/ @_jscript_version", "E_DISABLED_CC");
2509 testSyntaxError("ok(false, 'unexpected execution'); break;", "E_INVALID_BREAK");
2510 testSyntaxError("ok(false, 'unexpected execution'); continue;", "E_INVALID_CONTINUE");
2511 testSyntaxError("ok(false, 'unexpected execution'); while(true) break unknown_label;", "E_LABEL_NOT_FOUND");
2512 testSyntaxError("ok(false, 'unexpected execution'); some_label: continue some_label;", "E_INVALID_CONTINUE");
2513 testSyntaxError("ok(false, 'unexpected execution'); while(true) continue some_label;", "E_LABEL_NOT_FOUND");
2514 testSyntaxError("ok(false, 'unexpected execution'); some_label: { while(true) continue some_label; }", "E_INVALID_CONTINUE");
2515 testSyntaxError("ok(false, 'unexpected execution'); some_label: { some_label: while(true); }", "E_LABEL_REDEFINED");
2516 testSyntaxError("return;", "E_MISPLACED_RETURN");
2517 testSyntaxError("001.5;", "E_SEMICOLON");
2518 testSyntaxError("001.5", "E_SEMICOLON");
2519 testSyntaxError("0a", "E_SEMICOLON");
2520 testSyntaxError("01a", "E_SEMICOLON");
2521 testSyntaxError("0x1r", "E_SEMICOLON");
2522 testSyntaxError("1a", "E_SEMICOLON");
2523 testSyntaxError("1_", "E_SEMICOLON");
2525 // ReferenceError tests
2526 testException(function() {test = function() {}}, "E_ILLEGAL_ASSIGN");
2529 testException(function() {test
= (tmp
= true);}, "E_ILLEGAL_ASSIGN");
2530 ok(tmp
, "expr value on invalid assign not evaluated");
2533 testException(function() {(tmp
= true) = false;}, "E_ILLEGAL_ASSIGN");
2534 ok(tmp
, "expr assign not evaluated");
2537 testException(function() {true = (tmp
= true);}, "E_ILLEGAL_ASSIGN");
2538 ok(tmp
, "expr value assign not evaluated");
2541 testException(function() {(tmp
= tmp
+"1") = (tmp
= tmp
+"2");}, "E_ILLEGAL_ASSIGN");
2542 ok(tmp
=== "12", "assign evaluated in unexpected order");
2545 testException(function() { ((tmp
= true) && false)++; }, "E_ILLEGAL_ASSIGN")
2546 ok(tmp
, "incremented expression not evaluated");
2548 // RegExpError tests
2549 testException(function() {RegExp(/a
/, "g");}, "E_REGEXP_SYNTAX_ERROR");
2552 testException(function() {encodeURI('\udcaa');}, "E_URI_INVALID_CHAR");
2553 testException(function() {encodeURIComponent('\udcaa');}, "E_URI_INVALID_CHAR");
2554 testException(function() {decodeURI('%');}, "E_URI_INVALID_CODING");
2555 testException(function() {decodeURI('%aaaa');}, "E_URI_INVALID_CODING");
2557 function testThisExcept(func
, e
) {
2558 testException(function() {func
.call(new Object())}, e
);
2561 function testBoolThis(func
) {
2562 testThisExcept(Boolean
.prototype[func
], "E_NOT_BOOL");
2565 testBoolThis("toString");
2566 testBoolThis("valueOf");
2568 function testDateThis(func
) {
2569 testThisExcept(Date
.prototype[func
], "E_NOT_DATE");
2572 testDateThis("getDate");
2573 testDateThis("getDay");
2574 testDateThis("getFullYear");
2575 testDateThis("getHours");
2576 testDateThis("getMilliseconds");
2577 testDateThis("getMinutes");
2578 testDateThis("getMonth");
2579 testDateThis("getSeconds");
2580 testDateThis("getTime");
2581 testDateThis("getTimezoneOffset");
2582 testDateThis("getUTCDate");
2583 testDateThis("getUTCDay");
2584 testDateThis("getUTCFullYear");
2585 testDateThis("getUTCHours");
2586 testDateThis("getUTCMilliseconds");
2587 testDateThis("getUTCMinutes");
2588 testDateThis("getUTCMonth");
2589 testDateThis("getUTCSeconds");
2590 testDateThis("getYear");
2591 testDateThis("setDate");
2592 testDateThis("setFullYear");
2593 testDateThis("setHours");
2594 testDateThis("setMilliseconds");
2595 testDateThis("setMinutes");
2596 testDateThis("setMonth");
2597 testDateThis("setSeconds");
2598 testDateThis("setTime");
2599 testDateThis("setUTCDate");
2600 testDateThis("setUTCFullYear");
2601 testDateThis("setUTCHours");
2602 testDateThis("setUTCMilliseconds");
2603 testDateThis("setUTCMinutes");
2604 testDateThis("setUTCMonth");
2605 testDateThis("setUTCSeconds");
2606 testDateThis("setYear");
2607 testDateThis("toDateString");
2608 testDateThis("toLocaleDateString");
2609 testDateThis("toLocaleString");
2610 testDateThis("toLocaleTimeString");
2611 testDateThis("toString");
2612 testDateThis("toTimeString");
2613 testDateThis("toUTCString");
2614 testDateThis("valueOf");
2616 function testArrayThis(func
) {
2617 testThisExcept(Array
.prototype[func
], "E_NOT_ARRAY");
2620 testArrayThis("toString");
2622 function testFunctionThis(func
) {
2623 testThisExcept(Function
.prototype[func
], "E_NOT_FUNC");
2626 testFunctionThis("toString");
2627 testFunctionThis("call");
2628 testFunctionThis("apply");
2630 function testArrayHostThis(func
) {
2631 testException(function() { Array
.prototype[func
].call(testObj
); }, "E_JSCRIPT_EXPECTED");
2634 testArrayHostThis("push");
2635 testArrayHostThis("shift");
2636 testArrayHostThis("slice");
2637 testArrayHostThis("splice");
2638 testArrayHostThis("unshift");
2639 testArrayHostThis("reverse");
2640 testArrayHostThis("join");
2641 testArrayHostThis("pop");
2642 testArrayHostThis("sort");
2644 function testObjectInherit(obj
, constr
, ts
, tls
, vo
) {
2645 ok(obj
instanceof Object
, "obj is not instance of Object");
2646 ok(obj
instanceof constr
, "obj is not instance of its constructor");
2648 ok(obj
.hasOwnProperty
=== Object
.prototype.hasOwnProperty
,
2649 "obj.hasOwnProperty !== Object.prototype.hasOwnProprty");
2650 ok(obj
.isPrototypeOf
=== Object
.prototype.isPrototypeOf
,
2651 "obj.isPrototypeOf !== Object.prototype.isPrototypeOf");
2652 ok(obj
.propertyIsEnumerable
=== Object
.prototype.propertyIsEnumerable
,
2653 "obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable");
2656 ok(obj
.toString
=== Object
.prototype.toString
,
2657 "obj.toString !== Object.prototype.toString");
2659 ok(obj
.toString
!= Object
.prototype.toString
,
2660 "obj.toString == Object.prototype.toString");
2663 ok(obj
.toLocaleString
=== Object
.prototype.toLocaleString
,
2664 "obj.toLocaleString !== Object.prototype.toLocaleString");
2666 ok(obj
.toLocaleString
!= Object
.prototype.toLocaleString
,
2667 "obj.toLocaleString == Object.prototype.toLocaleString");
2670 ok(obj
.valueOf
=== Object
.prototype.valueOf
,
2671 "obj.valueOf !== Object.prototype.valueOf");
2673 ok(obj
.valueOf
!= Object
.prototype.valueOf
,
2674 "obj.valueOf == Object.prototype.valueOf");
2676 ok(obj
._test
=== "test", "obj.test = " + obj
._test
);
2679 Object
.prototype._test
= "test";
2680 testObjectInherit(new String("test"), String
, false, true, false);
2681 testObjectInherit(/test/g, RegExp
, false, true, true);
2682 testObjectInherit(new Number(1), Number
, false, false, false);
2683 testObjectInherit(new Date(), Date
, false, false, false);
2684 testObjectInherit(new Boolean(true), Boolean
, false, true, false);
2685 testObjectInherit(new Array(), Array
, false, false, true);
2686 testObjectInherit(new Error(), Error
, false, true, true);
2687 testObjectInherit(testObjectInherit
, Function
, false, true, true);
2688 testObjectInherit(Math
, Object
, true, true, true);
2690 (function() { testObjectInherit(arguments
, Object
, true, true, true); })();
2692 function testFunctions(obj
, arr
) {
2695 for(var i
=0; i
<arr
.length
; i
++) {
2696 l
= obj
[arr
[i
][0]].length
;
2697 ok(l
=== arr
[i
][1], arr
[i
][0] + ".length = " + l
);
2699 ok(obj
.propertyIsEnumerable(arr
[i
][0]) === false, arr
[i
][0] + " is enumerable");
2703 testFunctions(Boolean
.prototype, [
2708 testFunctions(Number
.prototype, [
2711 ["toExponential", 1],
2712 ["toLocaleString", 0],
2716 testFunctions(String
.prototype, [
2733 ["localeCompare", 1],
2745 ["toLocaleLowerCase", 0],
2746 ["toLocaleUpperCase", 0],
2751 testFunctions(RegExp
.prototype, [
2757 testFunctions(Date
.prototype, [
2762 ["getMilliseconds", 0],
2767 ["getTimezoneOffset", 0],
2770 ["getUTCFullYear", 0],
2772 ["getUTCMilliseconds", 0],
2773 ["getUTCMinutes", 0],
2775 ["getUTCSeconds", 0],
2780 ["setMilliseconds", 1],
2786 ["setUTCFullYear", 3],
2788 ["setUTCMilliseconds", 1],
2789 ["setUTCMinutes", 3],
2791 ["setUTCSeconds", 2],
2793 ["toDateString", 0],
2794 ["toLocaleDateString", 0],
2795 ["toLocaleString", 0],
2796 ["toLocaleTimeString", 0],
2798 ["toTimeString", 0],
2804 testFunctions(Array
.prototype, [
2814 ["toLocaleString", 0],
2819 testFunctions(Error
.prototype, [
2823 testFunctions(Math
, [
2844 testFunctions(Object
.prototype, [
2845 ["hasOwnProperty", 1],
2846 ["isPrototypeOf", 1],
2847 ["propertyIsEnumerable", 1],
2848 ["toLocaleString", 0],
2853 testFunctions(Function
.prototype, [
2859 testFunctions(VBArray
.prototype, [
2867 if(invokeVersion
< 2)
2868 ok(typeof(JSON
) === "undefined", "JSON is not undefined");
2870 testFunctions(JSON
, [
2875 ok(ActiveXObject
.length
== 1, "ActiveXObject.length = " + ActiveXObject
.length
);
2876 ok(Array
.length
== 1, "Array.length = " + Array
.length
);
2877 ok(Boolean
.length
== 1, "Boolean.length = " + Boolean
.length
);
2878 ok(CollectGarbage
.length
== 0, "CollectGarbage.length = " + CollectGarbage
.length
);
2879 ok(Date
.length
== 7, "Date.length = " + Date
.length
);
2880 ok(Enumerator
.length
== 7, "Enumerator.length = " + Enumerator
.length
);
2881 ok(Error
.length
== 1, "Error.length = " + Error
.length
);
2882 ok(EvalError
.length
== 1, "EvalError.length = " + EvalError
.length
);
2883 ok(RegExpError
.length
== 1, "RegExpError.length = " + RegExpError
.length
);
2884 ok(Function
.length
== 1, "Function.length = " + Function
.length
);
2885 ok(GetObject
.length
== 2, "GetObject.length = " + GetObject
.length
);
2886 ok(Number
.length
== 1, "Number.length = " + Number
.length
);
2887 ok(Object
.length
== 0, "Object.length = " + Object
.length
);
2888 ok(RangeError
.length
== 1, "RangeError.length = " + RangeError
.length
);
2889 ok(ReferenceError
.length
== 1, "ReferenceError.length = " + ReferenceError
.length
);
2890 ok(RegExp
.length
== 2, "RegExp.length = " + RegExp
.length
);
2891 ok(ScriptEngine
.length
== 0, "ScriptEngine.length = " + ScriptEngine
.length
);
2892 ok(ScriptEngineBuildVersion
.length
== 0,
2893 "ScriptEngineBuildVersion.length = " + ScriptEngineBuildVersion
.length
);
2894 ok(ScriptEngineMajorVersion
.length
== 0,
2895 "ScriptEngineMajorVersion.length = " + ScriptEngineMajorVersion
.length
);
2896 ok(ScriptEngineMinorVersion
.length
== 0,
2897 "ScriptEngineMinorVersion.length = " + ScriptEngineMinorVersion
.length
);
2898 ok(String
.length
== 1, "String.length = " + String
.length
);
2899 ok(SyntaxError
.length
== 1, "SyntaxError.length = " + SyntaxError
.length
);
2900 ok(TypeError
.length
== 1, "TypeError.length = " + TypeError
.length
);
2901 ok(URIError
.length
== 1, "URIError.length = " + URIError
.length
);
2902 ok(VBArray
.length
== 1, "VBArray.length = " + VBArray
.length
);
2903 ok(decodeURI
.length
== 1, "decodeURI.length = " + decodeURI
.length
);
2904 ok(decodeURIComponent
.length
== 1, "decodeURIComponent.length = " + decodeURIComponent
.length
);
2905 ok(encodeURI
.length
== 1, "encodeURI.length = " + encodeURI
.length
);
2906 ok(encodeURIComponent
.length
== 1, "encodeURIComponent.length = " + encodeURIComponent
.length
);
2907 ok(escape
.length
== 1, "escape.length = " + escape
.length
);
2908 ok(eval
.length
== 1, "eval.length = " + eval
.length
);
2909 ok(isFinite
.length
== 1, "isFinite.length = " + isFinite
.length
);
2910 ok(isNaN
.length
== 1, "isNaN.length = " + isNaN
.length
);
2911 ok(parseFloat
.length
== 1, "parseFloat.length = " + parseFloat
.length
);
2912 ok(parseInt
.length
== 2, "parseInt.length = " + parseInt
.length
);
2913 ok(unescape
.length
== 1, "unescape.length = " + unescape
.length
);
2916 ok(String
.length
== 1, "String.length = " + String
.length
);
2918 var tmp
= createArray();
2919 ok(getVT(tmp
) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp
));
2920 ok(getVT(VBArray(tmp
)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp
)));
2921 tmp
= new VBArray(tmp
);
2922 tmp
= new VBArray(VBArray(createArray()));
2923 ok(tmp
.dimensions() == 2, "tmp.dimensions() = " + tmp
.dimensions());
2924 ok(tmp
.lbound() == 0, "tmp.lbound() = " + tmp
.lbound());
2925 ok(tmp
.lbound(1) == 0, "tmp.lbound(1) = " + tmp
.lbound(1));
2926 ok(tmp
.lbound(2, 1) == 2, "tmp.lbound(2, 1) = " + tmp
.lbound(2, 1));
2927 ok(tmp
.ubound() == 4, "tmp.ubound() = " + tmp
.ubound());
2928 ok(tmp
.ubound("2") == 3, "tmp.ubound(\"2\") = " + tmp
.ubound("2"));
2929 ok(tmp
.getItem(1, 2) == 3, "tmp.getItem(1, 2) = " + tmp
.getItem(1, 2));
2930 ok(tmp
.getItem(2, 3) == 33, "tmp.getItem(2, 3) = " + tmp
.getItem(2, 3));
2931 ok(tmp
.getItem(3, 2) == 13, "tmp.getItem(3, 2) = " + tmp
.getItem(3, 2));
2932 ok(tmp
.toArray() == "2,3,12,13,22,23,32,33,42,43", "tmp.toArray() = " + tmp
.toArray());
2933 ok(createArray().toArray() == "2,3,12,13,22,23,32,33,42,43",
2934 "createArray.toArray()=" + createArray().toArray());