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 ok(true, "true is not true?");
22 ok(!false, "!false is not true");
23 ok(!undefined, "!undefined is not true");
24 ok(!null, "!null is not true");
25 ok(!0, "!0 is not true");
26 ok(!0.0, "!0.0 is not true");
28 ok(1 === 1, "1 === 1 is false");
29 ok(!(1 === 2), "!(1 === 2) is false");
30 ok(1.0 === 1, "1.0 === 1 is false");
31 ok("abc" === "abc", "\"abc\" === \"abc\" is false");
32 ok(true === true, "true === true is false");
33 ok(null === null, "null === null is false");
34 ok(undefined === undefined, "undefined === undefined is false");
35 ok(!(undefined === null), "!(undefined === null) is false");
36 ok(1E0 === 1, "1E0 === 1 is false");
37 ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
38 ok(8.64e15 === 8640000000000000, "8.64e15 !== 8640000000000000");
39 ok(1e2147483648 === Infinity, "1e2147483648 !== Infinity");
41 ok(1 !== 2, "1 !== 2 is false");
42 ok(null !== undefined, "null !== undefined is false");
44 ok(1 == 1, "1 == 1 is false");
45 ok(!(1 == 2), "!(1 == 2) is false");
46 ok(1.0 == 1, "1.0 == 1 is false");
47 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
48 ok(true == true, "true == true is false");
49 ok(null == null, "null == null is false");
50 ok(undefined == undefined, "undefined == undefined is false");
51 ok(undefined == null, "undefined == null is false");
52 ok(true == 1, "true == 1 is false");
53 ok(!(true == 2), "true == 2");
54 ok(0 == false, "0 == false is false");
56 ok(1 != 2, "1 != 2 is false");
57 ok(false != 1, "false != 1 is false");
59 ok(this === test, "this !== test");
60 eval('ok(this === test, "this !== test");');
63 ok(trueVar, "trueVar is not true");
65 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
67 function testFunc1(x, y) {
68 ok(this !== undefined, "this is undefined");
69 ok(x === true, "x is not true");
70 ok(y === "test", "y is not \"test\"");
71 ok(arguments.length === 2, "arguments.length is not 2");
72 ok(arguments["0"] === true, "arguments[0] is not true");
73 ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
74 ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
75 ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
78 ok(arguments[0] === false, "arguments[0] is not false");
80 ok(y === "x", "y = " + y);
81 ok(arguments[1] === "x", "arguments[1] = " + arguments[1]);
83 ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
84 ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);
86 ok(this === test, "this !== test");
87 eval('ok(this === test, "this !== test");');
89 tmp = delete arguments;
90 ok(tmp === false, "arguments deleted");
91 ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
96 ok(testFunc1.length === 2, "testFunc1.length is not 2");
97 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
99 ok(Object.prototype !== undefined, "Object.prototype is undefined");
100 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
101 ok(String.prototype !== undefined, "String.prototype is undefined");
102 ok(Array.prototype !== undefined, "Array.prototype is undefined");
103 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
104 ok(Number.prototype !== undefined, "Number.prototype is undefined");
105 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
106 ok(Math !== undefined, "Math is undefined");
107 ok(Math.prototype === undefined, "Math.prototype is not undefined");
108 ok(Function.prototype !== undefined, "Function.prototype is undefined");
109 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
110 ok(Date.prototype !== undefined, "Date.prototype is undefined");
111 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
113 function testConstructor(constr, name, inst) {
114 ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
115 ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");
120 ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
121 ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
124 testConstructor(Object, "Object");
125 testConstructor(String, "String");
126 testConstructor(Array, "Array");
127 testConstructor(Boolean, "Boolean");
128 testConstructor(Number, "Number");
129 testConstructor(RegExp, "RegExp", /x/);
130 testConstructor(Function, "Function");
131 testConstructor(Date, "Date");
132 testConstructor(VBArray, "VBArray", new VBArray(createArray()));
133 testConstructor(Error, "Error");
134 testConstructor(EvalError, "EvalError");
135 testConstructor(RangeError, "RangeError");
136 testConstructor(ReferenceError, "ReferenceError");
137 testConstructor(RegExpError, "RegExpError");
138 testConstructor(SyntaxError, "SyntaxError");
139 testConstructor(TypeError, "TypeError");
140 testConstructor(URIError, "URIError");
142 Function.prototype.test = true;
143 ok(testFunc1.test === true, "testFunc1.test !== true");
144 ok(Function.test === true, "Function.test !== true");
146 ok(typeof(0) === "number", "typeof(0) is not number");
147 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
148 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
149 ok(typeof("") === "string", "typeof(\"\") is not string");
150 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
151 ok(typeof(null) === "object", "typeof(null) is not object");
152 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
153 ok(typeof(Math) === "object", "typeof(Math) is not object");
154 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
155 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
156 ok(typeof(String) === "function", "typeof(String) is not function");
157 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
158 ok(typeof(this) === "object", "typeof(this) is not object");
159 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
160 tmp = typeof((new Object()).doesnotexist);
161 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
162 tmp = typeof(testObj.onlyDispID);
163 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
165 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
167 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
170 ok(tmp === 3, "tmp = " + tmp);
172 function testRecFunc(x) {
173 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
176 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
177 ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
181 testRecFunc.arguments = 5;
182 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
184 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
186 tmp = (function() {1;})();
187 ok(tmp === undefined, "tmp = " + tmp);
189 ok(tmp === 1, "tmp = " + tmp);
191 ok(tmp === 2, "tmp = " + tmp);
192 tmp = eval("if(true) {3}");
193 ok(tmp === 3, "tmp = " + tmp);
195 var obj1 = new Object();
196 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
197 ok(obj1.constructor === Object, "unexpected obj1.constructor");
199 obj1.func = function () {
200 ok(this === obj1, "this is not obj1");
201 ok(this.test === true, "this.test is not true");
202 ok(arguments.length === 1, "arguments.length is not 1");
203 ok(arguments["0"] === true, "arguments[0] is not true");
204 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
209 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
211 function testConstr1() {
214 ok(this !== undefined, "this is undefined");
215 ok(arguments.length === 1, "arguments.length is not 1");
216 ok(arguments["0"] === true, "arguments[0] is not 1");
217 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
222 testConstr1.prototype.pvar = 1;
223 ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
225 var obj2 = new testConstr1(true);
226 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
227 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
228 ok(obj2.pvar === 1, "obj2.pvar is not 1");
229 ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
231 testConstr1.prototype.pvar = 2;
232 ok(obj2.pvar === 2, "obj2.pvar is not 2");
235 testConstr1.prototype.pvar = 1;
236 ok(obj2.pvar === 3, "obj2.pvar is not 3");
239 function testConstr3() {
243 obj2 = new testConstr3();
244 ok(obj1 === obj2, "obj1 != obj2");
246 function testConstr4() {
250 obj2 = new testConstr3();
251 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
253 var obj3 = new Object;
254 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
256 for(var iter in "test")
257 ok(false, "unexpected forin call, test = " + iter);
259 for(var iter in null)
260 ok(false, "unexpected forin call, test = " + iter);
262 for(var iter in false)
263 ok(false, "unexpected forin call, test = " + iter);
265 for(var iter in pureDisp)
266 ok(false, "unexpected forin call in pureDisp object");
269 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
270 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
273 ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
274 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
277 ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
278 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
281 tmp[tmp.nonexistent];
282 ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
288 ok(false, "else evaluated");
289 ok(tmp === 1, "tmp !== 1, if not evaluated?");
293 ok(false, "if evaluated");
296 ok(tmp === 1, "tmp !== 1, if not evaluated?");
299 ok(false, "if(false) evaluated");
304 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
310 var obj3 = { prop1: 1, prop2: typeof(false) };
311 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
312 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
313 ok(obj3.constructor === Object, "unexpected obj3.constructor");
319 ok(blockVar === 2, "blockVar !== 2");
321 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
322 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
324 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
325 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
326 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
327 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
328 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
329 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
330 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
333 ok(tmp === 4, "2+2 !== 4");
334 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
337 ok(tmp === 4.5, "2+2.5 !== 4.5");
338 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
341 ok(tmp === 4, "1.4+2.5 !== 4");
342 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
345 ok(tmp === 2, "4-2 !== 2");
346 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
349 ok(tmp === 2.5, "4.5-2 !== 2.5");
350 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
353 ok(tmp === 0-2, "-2 !== 0-2");
354 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
357 ok(tmp === 6, "2*3 !== 6");
358 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
361 ok(tmp === 7, "2*3.5 !== 7");
362 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
365 /* FIXME: the parser loses precision */
366 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
367 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
368 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
371 ok(tmp === 2, "4/2 !== 2");
372 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
375 ok(tmp === 3, "4.5/1.5 !== 3");
376 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
379 ok(tmp === 1.5, "3/2 !== 1.5");
380 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
383 ok(tmp === 1, "3%2 = " + tmp);
386 ok(tmp ===0, "4%2 = " + tmp);
389 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
392 ok(tmp === 0, "3%true = " + tmp);
395 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
398 ok((tmp += 1) === 2, "tmp += 1 !== 2");
399 ok(tmp === 2, "tmp !== 2");
402 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
403 ok(tmp === 1, "tmp !=== 1");
406 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
407 ok(tmp === 3, "tmp !=== 3");
410 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
411 ok(tmp === 2.5, "tmp !=== 2.5");
414 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
415 ok(tmp === 1, "tmp !== 1");
418 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
421 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
424 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
426 tmp = 3 || ok(false, "second or expression called");
427 ok(tmp === 3, "3 || (...) is not 3");
430 ok(tmp === 2, "false || 2 is not 2");
432 tmp = 0 && ok(false, "second and expression called");
433 ok(tmp === 0, "0 && (...) is not 0");
435 tmp = true && "test";
436 ok(tmp === "test", "true && \"test\" is not \"test\"");
439 ok(tmp === 0, "true && 0 is not 0");
442 ok(tmp === 7, "3 | 4 !== 7");
443 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
446 ok(tmp === 3, "3.5 | 0 !== 3");
447 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
450 ok(tmp === -3, "-3.5 | 0 !== -3");
451 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
454 ok(tmp === 0, "0 | NaN = " + tmp);
457 ok(tmp === 0, "0 | NaN = " + tmp);
459 tmp = 0 | (-Infinity);
460 ok(tmp === 0, "0 | NaN = " + tmp);
463 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
464 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
467 ok(tmp === 1, "3 & 5 !== 1");
468 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
471 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
472 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
474 tmp = (-3.5) & 0xffffffff;
475 ok(tmp === -3, "-3.5 & 0xffff !== -3");
476 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
479 ok(tmp === 16, "2 << 3 = " + tmp);
482 ok(tmp === 16, "2 << 35 = " + tmp);
485 ok(tmp === 2, "8 >> 2 = " + tmp);
488 ok(tmp === -4, "-64 >> 4 = " + tmp);
491 ok(tmp === 2, "8 >> 2 = " + tmp);
494 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
497 ok(tmp === 4, "4 >>> NaN = " + tmp);
500 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
501 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
504 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
505 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
508 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
509 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
512 ok(tmp === -2, "~1 !== -2");
513 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
515 ok((3,4) === 4, "(3,4) !== 4");
517 ok(+3 === 3, "+3 !== 3");
518 ok(+true === 1, "+true !== 1");
519 ok(+false === 0, "+false !== 0");
520 ok(+null === 0, "+null !== 0");
521 ok(+"0" === 0, "+'0' !== 0");
522 ok(+"3" === 3, "+'3' !== 3");
523 ok(+"-3" === -3, "+'-3' !== -3");
524 ok(+"0xff" === 255, "+'0xff' !== 255");
525 ok(+"3e3" === 3000, "+'3e3' !== 3000");
528 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
529 ok(tmp.constructor === Number, "unexpected tmp.constructor");
530 tmp = new String("1");
531 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
532 ok(tmp.constructor === String, "unexpected tmp.constructor");
534 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
535 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
536 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
537 ok("" + null === "null", "\"\" + null !== \"null\"");
538 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
539 ok("" + true === "true", "\"\" + true !== \"true\"");
540 ok("" + false === "false", "\"\" + false !== \"false\"");
541 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
542 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
544 ok(1 < 3.4, "1 < 3.4 failed");
545 ok(!(3.4 < 1), "3.4 < 1");
546 ok("abc" < "abcd", "abc < abcd failed");
547 ok("abcd" < "abce", "abce < abce failed");
548 ok("" < "x", "\"\" < \"x\" failed");
549 ok(!(0 < 0), "0 < 0");
551 ok(1 <= 3.4, "1 <= 3.4 failed");
552 ok(!(3.4 <= 1), "3.4 <= 1");
553 ok("abc" <= "abcd", "abc <= abcd failed");
554 ok("abcd" <= "abce", "abce <= abce failed");
555 ok("" <= "x", "\"\" <= \"x\" failed");
556 ok(0 <= 0, "0 <= 0 failed");
558 ok(3.4 > 1, "3.4 > 1 failed");
559 ok(!(1 > 3.4), "1 > 3.4");
560 ok("abcd" > "abc", "abc > abcd failed");
561 ok("abce" > "abcd", "abce > abce failed");
562 ok("x" > "", "\"x\" > \"\" failed");
563 ok(!(0 > 0), "0 > 0");
565 ok(3.4 >= 1, "3.4 >= 1 failed");
566 ok(!(1 >= 3.4), "1 >= 3.4");
567 ok("abcd" >= "abc", "abc >= abcd failed");
568 ok("abce" >= "abcd", "abce >= abce failed");
569 ok("x" >= "", "\"x\" >= \"\" failed");
570 ok(0 >= 0, "0 >= 0");
573 ok(++tmp === 2, "++tmp (1) is not 2");
574 ok(tmp === 2, "incremented tmp is not 2");
575 ok(--tmp === 1, "--tmp (2) is not 1");
576 ok(tmp === 1, "decremented tmp is not 1");
577 ok(tmp++ === 1, "tmp++ (1) is not 1");
578 ok(tmp === 2, "incremented tmp(1) is not 2");
579 ok(tmp-- === 2, "tmp-- (2) is not 2");
580 ok(tmp === 1, "decremented tmp is not 1");
584 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
586 String.prototype.test = true;
587 ok("".test === true, "\"\".test is not true");
589 Boolean.prototype.test = true;
590 ok(true.test === true, "true.test is not true");
592 Number.prototype.test = true;
593 ok((0).test === true, "(0).test is not true");
594 ok((0.5).test === true, "(0.5).test is not true");
598 ok(state === "", "try: state = " + state);
601 ok(false, "unexpected catch");
603 ok(state === "try", "state = " + state + " expected try");
607 ok(state === "", "try: state = " + state);
610 ok(state === "try", "finally: state = " + state);
613 ok(state === "finally", "state = " + state + " expected finally");
623 ok(state === "finally", "state = " + state + " expected finally");
626 ok(state === "catch", "state = " + state + " expected catch");
635 ok(e === 1, "e = " + e);
640 ok(state === "", "try: state = " + state);
643 ok(false, "unexpected catch");
645 ok(state === "try", "finally: state = " + state);
648 ok(state === "finally", "state = " + state + " expected finally");
652 ok(state === "", "try: state = " + state);
656 ok(state === "try", "catch: state = " + state);
657 ok(ex === "except", "ex is not \"except\"");
660 ok(state === "catch", "state = " + state + " expected catch");
664 ok(state === "", "try: state = " + state);
668 ok(state === "try", "catch: state = " + state);
669 ok(ex === true, "ex is not true");
672 ok(state === "catch", "finally: state = " + state);
675 ok(state === "finally", "state = " + state + " expected finally");
679 ok(state === "", "try: state = " + state);
681 try { throw true; } finally {}
683 ok(state === "try", "catch: state = " + state);
684 ok(ex === true, "ex is not true");
687 ok(state === "catch", "finally: state = " + state);
690 ok(state === "finally", "state = " + state + " expected finally");
694 ok(state === "", "try: state = " + state);
696 try { throw "except"; } catch(ex) { throw true; }
698 ok(state === "try", "catch: state = " + state);
699 ok(ex === true, "ex is not true");
702 ok(state === "catch", "finally: state = " + state);
705 ok(state === "finally", "state = " + state + " expected finally");
707 function throwFunc(x) {
713 ok(state === "", "try: state = " + state);
717 ok(state === "try", "catch: state = " + state);
718 ok(ex === true, "ex is not true");
721 ok(state === "catch", "finally: state = " + state);
724 ok(state === "finally", "state = " + state + " expected finally");
729 ok(false, "unexpected case \"1\"");
731 ok(state === "", "case 1: state = " + state);
734 ok(state === "1", "default: state = " + state);
737 ok(state === "default", "case false: state = " + state);
740 ok(state === "false", "state = " + state);
746 ok(false, "unexpected case 1");
748 ok(state === "", "default: state = " + state);
751 ok(state === "default", "case false: state = " + state);
754 ok(state === "false", "state = " + state);
759 ok(false, "unexpected case \"1\"");
761 ok(state === "", "case 1: state = " + state);
764 ok(state === "1", "default: state = " + state);
768 ok(false, "unexpected case false");
770 ok(state === "default", "state = " + state);
774 ok(false, "unexpected case 2");
776 ok(false, "unexpected case 3");
781 ok(false, "unexpected case 2");
789 ok(false, "unexpected default");
797 ok(false, "unexpected default");
816 ok(tmp === 1, "eval(\"1\") !== 1");
817 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
818 ok(tmp === 2, "tmp !== 2");
820 ok(eval(false) === false, "eval(false) !== false");
821 ok(eval() === undefined, "eval() !== undefined");
823 tmp = eval("1", "2");
824 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
828 ok(state === "", "try: state = " + state);
830 eval("throwFunc(true);");
832 ok(state === "try", "catch: state = " + state);
833 ok(ex === true, "ex is not true");
836 ok(state === "catch", "finally: state = " + state);
839 ok(state === "finally", "state = " + state + " expected finally");
841 tmp = [,,1,2,,,true];
842 ok(tmp.length === 7, "tmp.length !== 7");
843 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
844 ok(tmp["3"] === 2, "tmp[3] !== 2");
845 ok(tmp["6"] === true, "tmp[6] !== true");
846 ok(tmp[2] === 1, "tmp[2] !== 1");
848 ok([1,].length === 2, "[1,].length !== 2");
849 ok([,,].length === 3, "[,,].length !== 3");
850 ok([,].length === 2, "[].length != 2");
851 ok([].length === 0, "[].length != 0");
855 ok(tmp < 4, "tmp >= 4");
858 ok(tmp === 4, "tmp !== 4");
862 ok(tmp < 4, "tmp >= 4");
866 ok(false, "break did not break");
869 ok(tmp === 4, "tmp !== 4");
873 ok(tmp < 4, "tmp >= 4");
876 ok(tmp === 4, "tmp !== 4");
880 ok(tmp === 0, "tmp !=== 0");
883 ok(tmp === 1, "tmp !== 1");
887 ok(tmp < 4, "tmp >= 4");
890 ok(tmp === 4, "tmp !== 4")
897 ok(false, "break did not break");
899 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
901 ok(tmp === 4, "tmp !== 4");
903 for(tmp=0; tmp < 4; tmp++)
904 ok(tmp < 4, "tmp = " + tmp);
905 ok(tmp === 4, "tmp !== 4");
907 for(tmp=0; tmp < 4; tmp++) {
910 ok(tmp < 2, "tmp = " + tmp);
912 ok(tmp === 2, "tmp !== 2");
914 for(tmp=0; tmp < 4; tmp++) {
917 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
919 ok(tmp === 4, "tmp !== 4");
921 for(var fi=0; fi < 4; fi++)
922 ok(fi < 4, "fi = " + fi);
923 ok(fi === 4, "fi !== 4");
927 for(obj1.nonexistent; tmp; tmp = false)
928 ok(!("nonexistent" in obj1), "nonexistent added to obj1");
931 for(tmp in obj1.nonexistent)
932 ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
933 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
938 /* Previous versions have broken finally block implementation */
939 if(ScriptEngineMinorVersion() >= 8) {
944 for(i = 1; i < 3; i++) {
958 ok(false, "unexpected state");
967 ok(tmp === "123456", "tmp = " + tmp);
985 ok(false, "unexpected state");
993 ok(tmp === "1234", "tmp = " + tmp);
996 for(var iter in [1,2,3]) {
1000 ok(tmp === 3, "tmp = " + tmp);
1003 for(var iter in [1,2,3]) {
1014 ok(tmp, "tmp = " + tmp);
1028 ok(false, "unexpected evaluation 1");
1033 ok(false, "unexpected evaluation 2");
1036 just_label: tmp = 1;
1037 ok(tmp === 1, "tmp != 1");
1039 some_label: break some_label;
1043 ok(false, "unexpected evaluation 3");
1049 continue loop_label;
1053 for(i = 0; i < 3; i++) {
1055 continue loop_label;
1060 for(i = 0; i < 3; i++) {
1062 continue loop_label;
1066 for(tmp in {prop: false}) {
1068 continue loop_label;
1071 ok((void 1) === undefined, "(void 1) !== undefined");
1073 var inobj = new Object();
1075 for(var iter in inobj)
1076 ok(false, "unexpected iter = " + iter);
1080 for(iter in inobj) {
1081 ok(iter == "test", "unexpected iter = " + iter);
1084 ok(tmp === 1, "for..in tmp = " + tmp);
1086 function forinTestObj() {}
1088 forinTestObj.prototype.test3 = true;
1090 var arr = new Array();
1091 inobj = new forinTestObj();
1096 for(iter in inobj) {
1101 ok(tmp === 3, "for..in tmp = " + tmp);
1102 ok(arr["test1"] === true, "arr[test1] !== true");
1103 ok(arr["test2"] === true, "arr[test2] !== true");
1104 ok(arr["test3"] === true, "arr[test3] !== true");
1108 ok((delete tmp.test) === true, "delete returned false");
1109 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1110 ok(!("test" in tmp), "test is still in tmp after delete?");
1112 ok(false, "tmp has prop " + iter);
1116 ok((delete tmp["test"]) === true, "delete returned false");
1117 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1118 ok(!("test" in tmp), "test is still in tmp after delete?");
1120 tmp.testWith = true;
1122 ok(testWith === true, "testWith !== true");
1125 var varTest1 = true;
1128 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1129 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1133 function varTestFunc(varTest3) {
1136 ok(varTest3 === 3, "varTest3 = " + varTest3);
1137 ok(varTest4 === undefined, "varTest4 = " + varTest4);
1148 ok(false, "deleteTest not throwed exception?");
1153 ok(false, "if evaluated");
1155 ok(false, "else should be associated with nearest if statement");
1159 ok(false, "if evaluated");
1161 ok(true, "else should be associated with nearest if statement");
1163 function instanceOfTest() {}
1164 tmp = new instanceOfTest();
1166 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1167 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1168 ok((tmp instanceof String) === false, "tmp is instance of String");
1170 instanceOfTest.prototype = new Object();
1171 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1172 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1174 ok((1 instanceof Object) === false, "1 is instance of Object");
1175 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1176 ok(("" instanceof Object) === false, "'' is instance of Object");
1179 ok((arguments instanceof Object) === true, "argument is not instance of Object");
1180 ok((arguments instanceof Array) === false, "argument is not instance of Array");
1181 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1185 ok(("length" in obj) === true, "length is not in obj");
1186 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1187 ok(("abc" in obj) === false, "test is in obj");
1189 ok(("abc" in obj) === true, "test is not in obj");
1190 ok(("1" in obj) === false, "1 is in obj");
1193 ok((1 in obj) === true, "1 is not in obj");
1198 ok(false, "expected exception");
1200 ok(!("prop" in obj), "prop in obj");
1202 if(invokeVersion >= 2) {
1203 ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1204 ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1207 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1209 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1210 ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1211 ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1213 ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1216 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1217 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1218 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1219 ok(isNaN() === true, "isNaN() !== true");
1220 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1221 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1222 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1224 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1225 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1226 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1227 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1228 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1229 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1230 ok(isFinite() === false, "isFinite() !== false");
1232 ok((1 < NaN) === false, "(1 < NaN) !== false");
1233 ok((1 > NaN) === false, "(1 > NaN) !== false");
1234 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1235 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1236 ok((NaN < 1) === false, "(NaN < 1) !== false");
1237 ok((NaN > 1) === false, "(NaN > 1) !== false");
1238 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1239 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1240 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1241 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1242 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1244 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1245 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1246 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1247 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1248 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1249 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1251 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1252 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1253 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1254 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1255 ok((0 === NaN) === false, "(0 === NaN) !== false");
1257 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1258 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1259 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1260 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1261 ok((0 == NaN) === false, "(0 === NaN) != false");
1274 ["\xf3", "\\xf3", 0xf3],
1275 ["\u1234", "\\u1234", 0x1234],
1280 for(i=0; i<escapeTests.length; i++) {
1281 tmp = escapeTests[i][0].charCodeAt(0);
1282 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1286 ok(tmp === true, '!+"\v1" = ' + tmp);
1288 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1290 ok(tmp === 2, "testFunc2(1) = " + tmp);
1291 function testFunc2(x) { return x+1; }
1293 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1295 ok(tmp === 3, "testFunc3(1) = " + tmp);
1296 tmp = function testFunc3(x) { return x+2; };
1299 ok(tmp === 5, "testFunc4(1) = " + tmp);
1300 tmp = function testFunc4(x) { return x+3; };
1303 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1304 ok(tmp === 5, "testFunc4(1) = " + tmp);
1305 tmp = function testFunc4(x) { return x+4; };
1306 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1308 function testEmbeddedFunctions() {
1309 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1311 ok(tmp === 3, "testFunc5(1) = " + tmp);
1312 tmp = function testFunc5(x) { return x+2; };
1315 ok(tmp === 5, "testFunc6(1) = " + tmp);
1316 tmp = function testFunc6(x) { return x+3; };
1318 ok(tmp === 5, "testFunc6(1) = " + tmp);
1319 tmp = function testFunc6(x) { return x+4; };
1321 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1324 testEmbeddedFunctions();
1327 date.toString = function() { return "toString"; }
1328 ok(""+date === "toString", "''+date = " + date);
1329 date.toString = function() { return this; }
1330 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1332 str = new String("test");
1333 str.valueOf = function() { return "valueOf"; }
1334 ok(""+str === "valueOf", "''+str = " + str);
1335 str.valueOf = function() { return new Date(); }
1336 ok(""+str === "test", "''+str = " + str);
1338 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1340 var re = /=(\?|%3F)/g;
1341 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1344 for(var i=0; i<2; i++)
1346 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1348 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1349 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1350 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1352 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1353 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1354 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1355 ok(nullDisp !== re, "nullDisp === re");
1356 ok(nullDisp === null, "nullDisp === null");
1357 ok(nullDisp == null, "nullDisp == null");
1358 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1359 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1360 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1361 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1362 ok(nullDisp != new Object(), "nullDisp == new Object()");
1363 ok(new Object() != nullDisp, "new Object() == nullDisp");
1364 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1365 tmp = getVT(Object(nullDisp));
1366 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1367 tmp = Object(nullDisp).toString();
1368 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1370 function do_test() {}
1371 function nosemicolon() {} nosemicolon();
1372 function () {} nosemicolon();
1375 function in_if_false() { return true; } ok(false, "!?");
1378 ok(in_if_false(), "in_if_false failed");
1380 (function() { newValue = 1; })();
1381 ok(newValue === 1, "newValue = " + newValue);
1383 obj = {undefined: 3};
1385 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1386 name_override_func = 3;
1387 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1388 function name_override_func() {};
1389 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1396 ok(tmp, "tmp = " + tmp);
1398 /* NoNewline rule parser tests */
1406 * no semicolon, but comment present */
1411 if(true) break // no semicolon, but comment present
1421 function returnTest() {
1426 ok(returnTest() === undefined, "returnTest = " + returnTest());
1428 /* Keep this test in the end of file */
1430 ok(undefined === 6, "undefined = " + undefined);
1433 ok(NaN === 6, "NaN !== 6");
1436 ok(Infinity === 6, "Infinity !== 6");
1439 ok(Math === 6, "NaN !== 6");