e6ff4dd059bed3f58586c0f25fa17c05a630c61a
[reactos.git] / modules / rostests / winetests / jscript / lang.js
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 var tmp;
20
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");
27
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");
40
41 ok(00 === 0, "00 != 0");
42 ok(010 === 8, "010 != 8");
43 ok(077 === 63, "077 != 63");
44 ok(080 === 80, "080 != 80");
45 ok(090 === 90, "090 != 90");
46 ok(018 === 18, "018 != 18");
47 tmp = 07777777777777777777777;
48 ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
49 tmp = 07777777779777777777777;
50 ok(typeof(tmp) === "number" && tmp > 0xffffffff, "tmp = " + tmp);
51 ok(0xffffffff === 4294967295, "0xffffffff = " + 0xffffffff);
52 tmp = 0x10000000000000000000000000000000000000000000000000000000000000000;
53 ok(tmp === Math.pow(2, 256), "0x1000...00 != 2^256");
54
55 ok(1 !== 2, "1 !== 2 is false");
56 ok(null !== undefined, "null !== undefined is false");
57
58 ok(1 == 1, "1 == 1 is false");
59 ok(!(1 == 2), "!(1 == 2) is false");
60 ok(1.0 == 1, "1.0 == 1 is false");
61 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
62 ok(true == true, "true == true is false");
63 ok(null == null, "null == null is false");
64 ok(undefined == undefined, "undefined == undefined is false");
65 ok(undefined == null, "undefined == null is false");
66 ok(true == 1, "true == 1 is false");
67 ok(!(true == 2), "true == 2");
68 ok(0 == false, "0 == false is false");
69
70 ok(1 != 2, "1 != 2 is false");
71 ok(false != 1, "false != 1 is false");
72
73 ok(this === test, "this !== test");
74 eval('ok(this === test, "this !== test");');
75
76 var trueVar = true;
77 ok(trueVar, "trueVar is not true");
78
79 ok(ScriptEngine.length === 0, "ScriptEngine.length is not 0");
80
81 function testFunc1(x, y) {
82 ok(this !== undefined, "this is undefined");
83 ok(x === true, "x is not true");
84 ok(y === "test", "y is not \"test\"");
85 ok(arguments.length === 2, "arguments.length is not 2");
86 ok(arguments["0"] === true, "arguments[0] is not true");
87 ok(arguments["1"] === "test", "arguments[1] is not \"test\"");
88 ok(arguments.callee === testFunc1, "arguments.calee !== testFunc1");
89 ok(testFunc1.arguments === arguments, "testFunc1.arguments = " + testFunc1.arguments);
90
91 x = false;
92 ok(arguments[0] === false, "arguments[0] is not false");
93 arguments[1] = "x";
94 ok(y === "x", "y = " + y);
95 ok(arguments[1] === "x", "arguments[1] = " + arguments[1]);
96
97 ok(arguments["0x0"] === undefined, "arguments['0x0'] = " + arguments["0x0"]);
98 ok(arguments["x"] === undefined, "arguments['x'] = " + arguments["x"]);
99
100 ok(this === test, "this !== test");
101 eval('ok(this === test, "this !== test");');
102
103 tmp = delete arguments;
104 ok(tmp === false, "arguments deleted");
105 ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
106
107 x = 2;
108 ok(x === 2, "x = " + x);
109 ok(arguments[0] === 2, "arguments[0] = " + arguments[0]);
110
111 return true;
112 }
113
114 ok(testFunc1.length === 2, "testFunc1.length is not 2");
115 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
116
117 ok(Object.prototype !== undefined, "Object.prototype is undefined");
118 ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined");
119 ok(String.prototype !== undefined, "String.prototype is undefined");
120 ok(Array.prototype !== undefined, "Array.prototype is undefined");
121 ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined");
122 ok(Number.prototype !== undefined, "Number.prototype is undefined");
123 ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined");
124 ok(Math !== undefined, "Math is undefined");
125 ok(Math.prototype === undefined, "Math.prototype is not undefined");
126 ok(Function.prototype !== undefined, "Function.prototype is undefined");
127 ok(Function.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
128 ok(Date.prototype !== undefined, "Date.prototype is undefined");
129 ok(Date.prototype.prototype === undefined, "Date.prototype is not undefined");
130
131 function testConstructor(constr, name, inst) {
132 ok(constr.prototype.constructor === constr, name + ".prototype.constructor !== " + name);
133 ok(constr.prototype.hasOwnProperty("constructor"), name + ".prototype.hasOwnProperty('constructor')");
134
135 if(!inst)
136 inst = new constr();
137
138 ok(inst.constructor === constr, "(new " + name + "()).constructor !== " + name);
139 ok(!inst.hasOwnProperty("constructor"), "(new " + name + "()).hasOwnProperty('constructor')");
140 }
141
142 testConstructor(Object, "Object");
143 testConstructor(String, "String");
144 testConstructor(Array, "Array");
145 testConstructor(Boolean, "Boolean");
146 testConstructor(Number, "Number");
147 testConstructor(RegExp, "RegExp", /x/);
148 testConstructor(Function, "Function");
149 testConstructor(Date, "Date");
150 testConstructor(VBArray, "VBArray", new VBArray(createArray()));
151 testConstructor(Error, "Error");
152 testConstructor(EvalError, "EvalError");
153 testConstructor(RangeError, "RangeError");
154 testConstructor(ReferenceError, "ReferenceError");
155 testConstructor(RegExpError, "RegExpError");
156 testConstructor(SyntaxError, "SyntaxError");
157 testConstructor(TypeError, "TypeError");
158 testConstructor(URIError, "URIError");
159
160 Function.prototype.test = true;
161 ok(testFunc1.test === true, "testFunc1.test !== true");
162 ok(Function.test === true, "Function.test !== true");
163
164 ok(typeof(0) === "number", "typeof(0) is not number");
165 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
166 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
167 ok(typeof("") === "string", "typeof(\"\") is not string");
168 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
169 ok(typeof(null) === "object", "typeof(null) is not object");
170 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
171 ok(typeof(Math) === "object", "typeof(Math) is not object");
172 ok(typeof(String.prototype) === "object", "typeof(String.prototype) is not object");
173 ok(typeof(testFunc1) === "function", "typeof(testFunc1) is not function");
174 ok(typeof(String) === "function", "typeof(String) is not function");
175 ok(typeof(ScriptEngine) === "function", "typeof(ScriptEngine) is not function");
176 ok(typeof(this) === "object", "typeof(this) is not object");
177 ok(typeof(doesnotexist) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist));
178 tmp = typeof((new Object()).doesnotexist);
179 ok(tmp === "undefined", "typeof((new Object).doesnotexist = " + tmp);
180 tmp = typeof(testObj.onlyDispID);
181 ok(tmp === "unknown", "typeof(testObj.onlyDispID) = " + tmp);
182
183 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
184
185 ok(testFunc1.arguments === null, "testFunc1.arguments = " + testFunc1.arguments);
186
187 (tmp) = 3;
188 ok(tmp === 3, "tmp = " + tmp);
189
190 function testRecFunc(x) {
191 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
192 if(x) {
193 testRecFunc(false);
194 ok(testRecFunc.arguments === arguments, "testRecFunc.arguments = " + testRecFunc.arguments);
195 ok(testRecFunc.arguments[0] === true, "testRecFunc.arguments.x = " + testRecFunc.arguments[0]);
196 }
197 }
198
199 testRecFunc.arguments = 5;
200 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
201 testRecFunc(true);
202 ok(testRecFunc.arguments === null, "testRecFunc.arguments = " + testRecFunc.arguments);
203
204 function argumentsTest() {
205 var save = arguments;
206 with({arguments: 1}) {
207 ok(arguments === 1, "arguments = " + arguments);
208 (function() {
209 ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
210 })();
211 }
212 eval('ok(arguments === save, "unexpected arguments");');
213 [1,2].sort(function() {
214 ok(argumentsTest.arguments === save, "unexpected argumentsTest.arguments");
215 return 1;
216 });
217 }
218
219 argumentsTest();
220
221 // arguments object detached from its execution context
222 (function() {
223 var args, get_x, set_x;
224
225 function test_args(detached) {
226 ok(args[0] === 1, "args[0] = " + args[0]);
227 set_x(2);
228 ok(args[0] === (detached ? 1 : 2), "args[0] = " + args[0] + " expected " + (detached ? 1 : 2));
229 args[0] = 3;
230 ok(get_x() === (detached ? 2 : 3), "get_x() = " + get_x());
231 ok(args[0] === 3, "args[0] = " + args[0]);
232 }
233
234 (function(x) {
235 args = arguments;
236 get_x = function() { return x; };
237 set_x = function(v) { x = v; };
238
239 test_args(false);
240 x = 1;
241 })(1);
242
243 test_args(true);
244 })();
245
246 // arguments is a regular variable, it may be overwritten
247 (function() {
248 ok(typeof(arguments) === "object", "typeof(arguments) = " + typeof(arguments));
249 arguments = 1;
250 ok(arguments === 1, "arguments = " + arguments);
251 })();
252
253 (function callAsExprTest() {
254 ok(callAsExprTest.arguments === null, "callAsExprTest.arguments = " + callAsExprTest.arguments);
255 })(1,2);
256
257 tmp = (function() {1;})();
258 ok(tmp === undefined, "tmp = " + tmp);
259 tmp = eval("1;");
260 ok(tmp === 1, "tmp = " + tmp);
261 tmp = eval("1,2;");
262 ok(tmp === 2, "tmp = " + tmp);
263 tmp = eval("testNoRes(),2;");
264 ok(tmp === 2, "tmp = " + tmp);
265 tmp = eval("if(true) {3}");
266 ok(tmp === 3, "tmp = " + tmp);
267 eval("testRes(); testRes()");
268 tmp = eval("3; if(false) {4;} else {};;;")
269 ok(tmp === 3, "tmp = " + tmp);
270 tmp = eval("try { 1; } finally { 2; }")
271 ok(tmp === 2, "tmp = " + tmp);
272
273 testNoRes();
274 testRes() && testRes();
275 testNoRes(), testNoRes();
276
277 (function() {
278 eval("var x=1;");
279 ok(x === 1, "x = " + x);
280 })();
281
282 (function() {
283 var e = eval;
284 var r = e(1);
285 ok(r === 1, "r = " + r);
286 (function(x, a) { x(a); })(eval, "2");
287 })();
288
289 (function(r) {
290 r = eval("1");
291 ok(r === 1, "r = " + r);
292 (function(x, a) { x(a); })(eval, "2");
293 })();
294
295 tmp = (function(){ return testNoRes(), testRes();})();
296
297 var f1, f2;
298
299 ok(funcexpr() == 2, "funcexpr() = " + funcexpr());
300
301 f1 = function funcexpr() { return 1; }
302 ok(f1 != funcexpr, "f1 == funcexpr");
303 ok(f1() === 1, "f1() = " + f1());
304
305 f2 = function funcexpr() { return 2; }
306 ok(f2 != funcexpr, "f2 != funcexpr");
307 ok(f2() === 2, "f2() = " + f2());
308
309 f1 = null;
310 for(i = 0; i < 3; i++) {
311 f2 = function funcexpr2() {};
312 ok(f1 != f2, "f1 == f2");
313 f1 = f2;
314 }
315
316 f1 = null;
317 for(i = 0; i < 3; i++) {
318 f2 = function() {};
319 ok(f1 != f2, "f1 == f2");
320 f1 = f2;
321 }
322
323 (function() {
324 ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr());
325
326 f1 = function infuncexpr() { return 1; }
327 ok(f1 != funcexpr, "f1 == funcexpr");
328 ok(f1() === 1, "f1() = " + f1());
329
330 f2 = function infuncexpr() { return 2; }
331 ok(f2 != funcexpr, "f2 != funcexpr");
332 ok(f2() === 2, "f2() = " + f2());
333
334 f1 = null;
335 for(i = 0; i < 3; i++) {
336 f2 = function infuncexpr2() {};
337 ok(f1 != f2, "f1 == f2");
338 f1 = f2;
339 }
340
341 f1 = null;
342 for(i = 0; i < 3; i++) {
343 f2 = function() {};
344 ok(f1 != f2, "f1 == f2");
345 f1 = f2;
346 }
347 })();
348
349 var obj1 = new Object();
350 ok(typeof(obj1) === "object", "typeof(obj1) is not object");
351 ok(obj1.constructor === Object, "unexpected obj1.constructor");
352 obj1.test = true;
353 obj1.func = function () {
354 ok(this === obj1, "this is not obj1");
355 ok(this.test === true, "this.test is not true");
356 ok(arguments.length === 1, "arguments.length is not 1");
357 ok(arguments["0"] === true, "arguments[0] is not true");
358 ok(typeof(arguments.callee) === "function", "typeof(arguments.calee) = " + typeof(arguments.calee));
359
360 return "test";
361 };
362
363 ok(obj1.func(true) === "test", "obj1.func(true) is not \"test\"");
364
365 function testConstr1() {
366 this.var1 = 1;
367
368 ok(this !== undefined, "this is undefined");
369 ok(arguments.length === 1, "arguments.length is not 1");
370 ok(arguments["0"] === true, "arguments[0] is not 1");
371 ok(arguments.callee === testConstr1, "arguments.calee !== testConstr1");
372
373 return false;
374 }
375
376 testConstr1.prototype.pvar = 1;
377 ok(testConstr1.prototype.constructor === testConstr1, "testConstr1.prototype.constructor !== testConstr1");
378
379 var obj2 = new testConstr1(true);
380 ok(typeof(obj2) === "object", "typeof(obj2) is not object");
381 ok(obj2.constructor === testConstr1, "unexpected obj2.constructor");
382 ok(obj2.pvar === 1, "obj2.pvar is not 1");
383 ok(!obj2.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
384
385 testConstr1.prototype.pvar = 2;
386 ok(obj2.pvar === 2, "obj2.pvar is not 2");
387
388 obj2.pvar = 3;
389 testConstr1.prototype.pvar = 1;
390 ok(obj2.pvar === 3, "obj2.pvar is not 3");
391
392 obj1 = new Object();
393 function testConstr3() {
394 return obj1;
395 }
396
397 obj2 = new testConstr3();
398 ok(obj1 === obj2, "obj1 != obj2");
399
400 function testConstr4() {
401 return 2;
402 }
403
404 obj2 = new testConstr3();
405 ok(typeof(obj2) === "object", "typeof(obj2) = " + typeof(obj2));
406
407 var obj3 = new Object;
408 ok(typeof(obj3) === "object", "typeof(obj3) is not object");
409
410 (function() {
411 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
412 function func() {}
413 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
414 func = 0;
415 ok(typeof(func) === "number", "typeof(func) = " + typeof(func));
416 })();
417
418 (function(f) {
419 ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
420 function f() {};
421 ok(typeof(f) === "function", "typeof(f) = " + typeof(f));
422 })(1);
423
424 for(var iter in "test")
425 ok(false, "unexpected forin call, test = " + iter);
426
427 for(var iter in null)
428 ok(false, "unexpected forin call, test = " + iter);
429
430 for(var iter in false)
431 ok(false, "unexpected forin call, test = " + iter);
432
433 for(var iter in pureDisp)
434 ok(false, "unexpected forin call in pureDisp object");
435
436 tmp = new Object();
437 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
438 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
439
440 tmp = new Object();
441 ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
442 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
443
444 tmp = new Object();
445 ok(isNaN(+tmp.nonexistent), "!tmp.nonexistent = " + (+tmp.nonexistent));
446 ok(!("nonexistent" in tmp), "nonexistent is in tmp after '+' expression")
447
448 tmp = new Object();
449 tmp[tmp.nonexistent];
450 ok(!("nonexistent" in tmp), "nonexistent is in tmp after array expression")
451
452 tmp = 0;
453 if(true)
454 tmp = 1;
455 else
456 ok(false, "else evaluated");
457 ok(tmp === 1, "tmp !== 1, if not evaluated?");
458
459 tmp = 0;
460 if(1 === 0)
461 ok(false, "if evaluated");
462 else
463 tmp = 1;
464 ok(tmp === 1, "tmp !== 1, if not evaluated?");
465
466 if(false)
467 ok(false, "if(false) evaluated");
468
469 tmp = 0;
470 if(true)
471 tmp = 1;
472 ok(tmp === 1, "tmp !== 1, if(true) not evaluated?");
473
474 if(false) {
475 }else {
476 }
477
478 var obj3 = { prop1: 1, prop2: typeof(false) };
479 ok(obj3.prop1 === 1, "obj3.prop1 is not 1");
480 ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\"");
481 ok(obj3.constructor === Object, "unexpected obj3.constructor");
482
483 {
484 var blockVar = 1;
485 blockVar = 2;
486 }
487 ok(blockVar === 2, "blockVar !== 2");
488
489 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
490 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
491
492 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
493 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
494 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
495 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
496 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
497 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
498 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
499
500 tmp = 2+2;
501 ok(tmp === 4, "2+2 !== 4");
502 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
503
504 tmp = 2+2.5;
505 ok(tmp === 4.5, "2+2.5 !== 4.5");
506 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
507
508 tmp = 1.5+2.5;
509 ok(tmp === 4, "1.4+2.5 !== 4");
510 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
511
512 tmp = 4-2;
513 ok(tmp === 2, "4-2 !== 2");
514 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
515
516 tmp = 4.5-2;
517 ok(tmp === 2.5, "4.5-2 !== 2.5");
518 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
519
520 tmp = -2;
521 ok(tmp === 0-2, "-2 !== 0-2");
522 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
523
524 tmp = 2*3;
525 ok(tmp === 6, "2*3 !== 6");
526 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
527
528 tmp = 2*3.5;
529 ok(tmp === 7, "2*3.5 !== 7");
530 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
531
532 tmp = 2.5*3.5;
533 /* FIXME: the parser loses precision */
534 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
535 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
536 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
537
538 tmp = 2*.5;
539 ok(tmp === 1, "2*.5 !== 1");
540 ok(getVT(tmp) == "VT_I4", "getVT(2*.5) !== VT_I4");
541
542 tmp = 4/2;
543 ok(tmp === 2, "4/2 !== 2");
544 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
545
546 tmp = 4.5/1.5;
547 ok(tmp === 3, "4.5/1.5 !== 3");
548 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
549
550 tmp = 3/2;
551 ok(tmp === 1.5, "3/2 !== 1.5");
552 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
553
554 tmp = 3%2;
555 ok(tmp === 1, "3%2 = " + tmp);
556
557 tmp = 4%2;
558 ok(tmp ===0, "4%2 = " + tmp);
559
560 tmp = 3.5%1.5;
561 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
562
563 tmp = 3%true;
564 ok(tmp === 0, "3%true = " + tmp);
565
566 tmp = "ab" + "cd";
567 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
568
569 tmp = 1;
570 ok((tmp += 1) === 2, "tmp += 1 !== 2");
571 ok(tmp === 2, "tmp !== 2");
572
573 tmp = 2;
574 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
575 ok(tmp === 1, "tmp !=== 1");
576
577 tmp = 2;
578 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
579 ok(tmp === 3, "tmp !=== 3");
580
581 tmp = 5;
582 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
583 ok(tmp === 2.5, "tmp !=== 2.5");
584
585 tmp = 3;
586 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
587 ok(tmp === 1, "tmp !== 1");
588
589 tmp = 8;
590 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
591
592 tmp = 8;
593 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
594
595 tmp = 8;
596 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
597
598 tmp = 3 || ok(false, "second or expression called");
599 ok(tmp === 3, "3 || (...) is not 3");
600
601 tmp = false || 2;
602 ok(tmp === 2, "false || 2 is not 2");
603
604 tmp = 0 && ok(false, "second and expression called");
605 ok(tmp === 0, "0 && (...) is not 0");
606
607 tmp = true && "test";
608 ok(tmp === "test", "true && \"test\" is not \"test\"");
609
610 tmp = true && 0;
611 ok(tmp === 0, "true && 0 is not 0");
612
613 tmp = 3 | 4;
614 ok(tmp === 7, "3 | 4 !== 7");
615 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
616
617 tmp = 3.5 | 0;
618 ok(tmp === 3, "3.5 | 0 !== 3");
619 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
620
621 tmp = -3.5 | 0;
622 ok(tmp === -3, "-3.5 | 0 !== -3");
623 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
624
625 tmp = 0 | NaN;
626 ok(tmp === 0, "0 | NaN = " + tmp);
627
628 tmp = 0 | Infinity;
629 ok(tmp === 0, "0 | NaN = " + tmp);
630
631 tmp = 0 | (-Infinity);
632 ok(tmp === 0, "0 | NaN = " + tmp);
633
634 tmp = 10;
635 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
636 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
637
638 tmp = (123 * Math.pow(2,32) + 2) | 0;
639 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
640
641 tmp = (-123 * Math.pow(2,32) + 2) | 0;
642 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
643
644 tmp = 3 & 5;
645 ok(tmp === 1, "3 & 5 !== 1");
646 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
647
648 tmp = 3.5 & 0xffff;
649 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
650 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
651
652 tmp = (-3.5) & 0xffffffff;
653 ok(tmp === -3, "-3.5 & 0xffff !== -3");
654 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
655
656 tmp = 2 << 3;
657 ok(tmp === 16, "2 << 3 = " + tmp);
658
659 tmp = 2 << 35;
660 ok(tmp === 16, "2 << 35 = " + tmp);
661
662 tmp = 8 >> 2;
663 ok(tmp === 2, "8 >> 2 = " + tmp);
664
665 tmp = -64 >> 4;
666 ok(tmp === -4, "-64 >> 4 = " + tmp);
667
668 tmp = 8 >>> 2;
669 ok(tmp === 2, "8 >> 2 = " + tmp);
670
671 tmp = -64 >>> 4;
672 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
673
674 tmp = 4 >>> NaN;
675 ok(tmp === 4, "4 >>> NaN = " + tmp);
676
677 tmp = 10;
678 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
679 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
680
681 tmp = 0xf0f0^0xff00;
682 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
683 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
684
685 tmp = 5;
686 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
687 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
688
689 tmp = ~1;
690 ok(tmp === -2, "~1 !== -2");
691 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
692
693 ok((3,4) === 4, "(3,4) !== 4");
694
695 ok(+3 === 3, "+3 !== 3");
696 ok(+true === 1, "+true !== 1");
697 ok(+false === 0, "+false !== 0");
698 ok(+null === 0, "+null !== 0");
699 ok(+"0" === 0, "+'0' !== 0");
700 ok(+"3" === 3, "+'3' !== 3");
701 ok(+"-3" === -3, "+'-3' !== -3");
702 ok(+"0xff" === 255, "+'0xff' !== 255");
703 ok(+"3e3" === 3000, "+'3e3' !== 3000");
704
705 tmp = new Number(1);
706 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
707 ok(tmp.constructor === Number, "unexpected tmp.constructor");
708 tmp = new String("1");
709 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
710 ok(tmp.constructor === String, "unexpected tmp.constructor");
711
712 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
713 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
714 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
715 ok("" + null === "null", "\"\" + null !== \"null\"");
716 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
717 ok("" + true === "true", "\"\" + true !== \"true\"");
718 ok("" + false === "false", "\"\" + false !== \"false\"");
719 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
720 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
721
722 ok(1 < 3.4, "1 < 3.4 failed");
723 ok(!(3.4 < 1), "3.4 < 1");
724 ok("abc" < "abcd", "abc < abcd failed");
725 ok("abcd" < "abce", "abce < abce failed");
726 ok("" < "x", "\"\" < \"x\" failed");
727 ok(!(0 < 0), "0 < 0");
728
729 ok(1 <= 3.4, "1 <= 3.4 failed");
730 ok(!(3.4 <= 1), "3.4 <= 1");
731 ok("abc" <= "abcd", "abc <= abcd failed");
732 ok("abcd" <= "abce", "abce <= abce failed");
733 ok("" <= "x", "\"\" <= \"x\" failed");
734 ok(0 <= 0, "0 <= 0 failed");
735
736 ok(3.4 > 1, "3.4 > 1 failed");
737 ok(!(1 > 3.4), "1 > 3.4");
738 ok("abcd" > "abc", "abc > abcd failed");
739 ok("abce" > "abcd", "abce > abce failed");
740 ok("x" > "", "\"x\" > \"\" failed");
741 ok(!(0 > 0), "0 > 0");
742
743 ok(3.4 >= 1, "3.4 >= 1 failed");
744 ok(!(1 >= 3.4), "1 >= 3.4");
745 ok("abcd" >= "abc", "abc >= abcd failed");
746 ok("abce" >= "abcd", "abce >= abce failed");
747 ok("x" >= "", "\"x\" >= \"\" failed");
748 ok(0 >= 0, "0 >= 0");
749
750 tmp = 1;
751 ok(++tmp === 2, "++tmp (1) is not 2");
752 ok(tmp === 2, "incremented tmp is not 2");
753 ok(--tmp === 1, "--tmp (2) is not 1");
754 ok(tmp === 1, "decremented tmp is not 1");
755 ok(tmp++ === 1, "tmp++ (1) is not 1");
756 ok(tmp === 2, "incremented tmp(1) is not 2");
757 ok(tmp-- === 2, "tmp-- (2) is not 2");
758 ok(tmp === 1, "decremented tmp is not 1");
759
760 tmp = new Object();
761 tmp.iii++;
762 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
763
764 String.prototype.test = true;
765 ok("".test === true, "\"\".test is not true");
766
767 Boolean.prototype.test = true;
768 ok(true.test === true, "true.test is not true");
769
770 Number.prototype.test = true;
771 ok((0).test === true, "(0).test is not true");
772 ok((0.5).test === true, "(0.5).test is not true");
773
774 var state = "";
775 try {
776 ok(state === "", "try: state = " + state);
777 state = "try";
778 }catch(ex) {
779 ok(false, "unexpected catch");
780 }
781 ok(state === "try", "state = " + state + " expected try");
782
783 state = "";
784 try {
785 ok(state === "", "try: state = " + state);
786 state = "try";
787 }finally {
788 ok(state === "try", "finally: state = " + state);
789 state = "finally";
790 }
791 ok(state === "finally", "state = " + state + " expected finally");
792
793 state = "";
794 try {
795 try {
796 throw 0;
797 }finally {
798 state = "finally";
799 }
800 }catch(e) {
801 ok(state === "finally", "state = " + state + " expected finally");
802 state = "catch";
803 }
804 ok(state === "catch", "state = " + state + " expected catch");
805
806 try {
807 try {
808 throw 0;
809 }finally {
810 throw 1;
811 }
812 }catch(e) {
813 ok(e === 1, "e = " + e);
814 }
815
816 state = "";
817 try {
818 ok(state === "", "try: state = " + state);
819 state = "try";
820 }catch(ex) {
821 ok(false, "unexpected catch");
822 }finally {
823 ok(state === "try", "finally: state = " + state);
824 state = "finally";
825 }
826 ok(state === "finally", "state = " + state + " expected finally");
827
828 var state = "";
829 try {
830 ok(state === "", "try: state = " + state);
831 state = "try";
832 throw "except";
833 }catch(ex) {
834 ok(state === "try", "catch: state = " + state);
835 ok(ex === "except", "ex is not \"except\"");
836 state = "catch";
837 }
838 ok(state === "catch", "state = " + state + " expected catch");
839
840 var state = "";
841 try {
842 ok(state === "", "try: state = " + state);
843 state = "try";
844 throw true;
845 }catch(ex) {
846 ok(state === "try", "catch: state = " + state);
847 ok(ex === true, "ex is not true");
848 state = "catch";
849 }finally {
850 ok(state === "catch", "finally: state = " + state);
851 state = "finally";
852 }
853 ok(state === "finally", "state = " + state + " expected finally");
854
855 var state = "";
856 try {
857 ok(state === "", "try: state = " + state);
858 state = "try";
859 try { throw true; } finally {}
860 }catch(ex) {
861 ok(state === "try", "catch: state = " + state);
862 ok(ex === true, "ex is not true");
863 state = "catch";
864 }finally {
865 ok(state === "catch", "finally: state = " + state);
866 state = "finally";
867 }
868 ok(state === "finally", "state = " + state + " expected finally");
869
870 var state = "";
871 try {
872 ok(state === "", "try: state = " + state);
873 state = "try";
874 try { throw "except"; } catch(ex) { throw true; }
875 }catch(ex) {
876 ok(state === "try", "catch: state = " + state);
877 ok(ex === true, "ex is not true");
878 state = "catch";
879 }finally {
880 ok(state === "catch", "finally: state = " + state);
881 state = "finally";
882 }
883 ok(state === "finally", "state = " + state + " expected finally");
884
885 function throwFunc(x) {
886 throw x;
887 }
888
889 var state = "";
890 try {
891 ok(state === "", "try: state = " + state);
892 state = "try";
893 throwFunc(true);
894 }catch(ex) {
895 ok(state === "try", "catch: state = " + state);
896 ok(ex === true, "ex is not true");
897 state = "catch";
898 }finally {
899 ok(state === "catch", "finally: state = " + state);
900 state = "finally";
901 }
902 ok(state === "finally", "state = " + state + " expected finally");
903
904 state = "";
905 switch(1) {
906 case "1":
907 ok(false, "unexpected case \"1\"");
908 case 1:
909 ok(state === "", "case 1: state = " + state);
910 state = "1";
911 default:
912 ok(state === "1", "default: state = " + state);
913 state = "default";
914 case false:
915 ok(state === "default", "case false: state = " + state);
916 state = "false";
917 }
918 ok(state === "false", "state = " + state);
919
920 state = "";
921 switch("") {
922 case "1":
923 case 1:
924 ok(false, "unexpected case 1");
925 default:
926 ok(state === "", "default: state = " + state);
927 state = "default";
928 case false:
929 ok(state === "default", "case false: state = " + state);
930 state = "false";
931 }
932 ok(state === "false", "state = " + state);
933
934 state = "";
935 switch(1) {
936 case "1":
937 ok(false, "unexpected case \"1\"");
938 case 1:
939 ok(state === "", "case 1: state = " + state);
940 state = "1";
941 default:
942 ok(state === "1", "default: state = " + state);
943 state = "default";
944 break;
945 case false:
946 ok(false, "unexpected case false");
947 }
948 ok(state === "default", "state = " + state);
949
950 switch(1) {
951 case 2:
952 ok(false, "unexpected case 2");
953 case 3:
954 ok(false, "unexpected case 3");
955 }
956
957 switch(1) {
958 case 2:
959 ok(false, "unexpected case 2");
960 break;
961 default:
962 /* empty default */
963 }
964
965 switch(2) {
966 default:
967 ok(false, "unexpected default");
968 break;
969 case 2:
970 /* empty case */
971 };
972
973 switch(2) {
974 default:
975 ok(false, "unexpected default");
976 break;
977 case 1:
978 case 2:
979 case 3:
980 /* empty case */
981 };
982
983 (function() {
984 var i=0;
985
986 switch(1) {
987 case 1:
988 i++;
989 }
990 return i;
991 })();
992
993 (function() {
994 var ret, x;
995
996 function unreachable() {
997 ok(false, "unreachable");
998 }
999
1000 function expect(value, expect_value) {
1001 ok(value === expect_value, "got " + value + " expected " + expect_value);
1002 }
1003
1004 ret = (function() {
1005 try {
1006 return "try";
1007 unreachable();
1008 }catch(e) {
1009 unreachable();
1010 }finally {
1011 return "finally";
1012 unreachable();
1013 }
1014 unreachable();
1015 })();
1016 expect(ret, "finally");
1017
1018 x = "";
1019 ret = (function() {
1020 try {
1021 x += "try,";
1022 return x;
1023 unreachable();
1024 }catch(e) {
1025 unreachable();
1026 }finally {
1027 x += "finally,";
1028 }
1029 unreachable();
1030 })();
1031 expect(ret, "try,");
1032 expect(x, "try,finally,");
1033
1034 x = "";
1035 ret = (function() {
1036 try {
1037 x += "try,"
1038 throw 1;
1039 unreachable();
1040 }catch(e) {
1041 x += "catch,";
1042 return "catch";
1043 unreachable();
1044 }finally {
1045 x += "finally,";
1046 return "finally";
1047 unreachable();
1048 }
1049 unreachable();
1050 })();
1051 expect(ret, "finally");
1052 expect(x, "try,catch,finally,");
1053
1054 x = "";
1055 ret = (function() {
1056 try {
1057 x += "try,"
1058 throw 1;
1059 unreachable();
1060 }catch(e) {
1061 x += "catch,";
1062 return "catch";
1063 unreachable();
1064 }finally {
1065 x += "finally,";
1066 }
1067 unreachable();
1068 })();
1069 expect(ret, "catch");
1070 expect(x, "try,catch,finally,");
1071
1072 x = "";
1073 ret = (function() {
1074 try {
1075 x += "try,"
1076 try {
1077 x += "try2,";
1078 return "try2";
1079 }catch(e) {
1080 unreachable();
1081 }finally {
1082 x += "finally2,";
1083 }
1084 unreachable();
1085 }catch(e) {
1086 unreachable();
1087 }finally {
1088 x += "finally,";
1089 }
1090 unreachable();
1091 })();
1092 expect(ret, "try2");
1093 expect(x, "try,try2,finally2,finally,");
1094
1095 x = "";
1096 ret = (function() {
1097 while(true) {
1098 try {
1099 x += "try,"
1100 try {
1101 x += "try2,";
1102 break;
1103 }catch(e) {
1104 unreachable();
1105 }finally {
1106 x += "finally2,";
1107 }
1108 unreachable();
1109 }catch(e) {
1110 unreachable();
1111 }finally {
1112 x += "finally,";
1113 }
1114 unreachable();
1115 }
1116 x += "ret";
1117 return "ret";
1118 })();
1119 expect(ret, "ret");
1120 expect(x, "try,try2,finally2,finally,ret");
1121
1122 x = "";
1123 ret = (function() {
1124 while(true) {
1125 try {
1126 x += "try,"
1127 try {
1128 x += "try2,";
1129 continue;
1130 }catch(e) {
1131 unreachable();
1132 }finally {
1133 x += "finally2,";
1134 }
1135 unreachable();
1136 }catch(e) {
1137 unreachable();
1138 }finally {
1139 x += "finally,";
1140 break;
1141 }
1142 unreachable();
1143 }
1144 x += "ret";
1145 return "ret";
1146 })();
1147 expect(ret, "ret");
1148 expect(x, "try,try2,finally2,finally,ret");
1149 })();
1150
1151 tmp = eval("1");
1152 ok(tmp === 1, "eval(\"1\") !== 1");
1153 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
1154 ok(tmp === 2, "tmp !== 2");
1155
1156 ok(eval(false) === false, "eval(false) !== false");
1157 ok(eval() === undefined, "eval() !== undefined");
1158
1159 tmp = eval("1", "2");
1160 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
1161
1162 var state = "";
1163 try {
1164 ok(state === "", "try: state = " + state);
1165 state = "try";
1166 eval("throwFunc(true);");
1167 }catch(ex) {
1168 ok(state === "try", "catch: state = " + state);
1169 ok(ex === true, "ex is not true");
1170 state = "catch";
1171 }finally {
1172 ok(state === "catch", "finally: state = " + state);
1173 state = "finally";
1174 }
1175 ok(state === "finally", "state = " + state + " expected finally");
1176
1177 tmp = [,,1,2,,,true];
1178 ok(tmp.length === 7, "tmp.length !== 7");
1179 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
1180 ok(tmp["3"] === 2, "tmp[3] !== 2");
1181 ok(tmp["6"] === true, "tmp[6] !== true");
1182 ok(tmp[2] === 1, "tmp[2] !== 1");
1183 ok(!("0" in tmp), "0 found in array");
1184 ok(!("1" in tmp), "1 found in array");
1185 ok("2" in tmp, "2 not found in array");
1186 ok(!("2" in [1,,,,]), "2 found in [1,,,,]");
1187
1188 ok([1,].length === 2, "[1,].length !== 2");
1189 ok([,,].length === 3, "[,,].length !== 3");
1190 ok([,].length === 2, "[].length != 2");
1191 ok([].length === 0, "[].length != 0");
1192
1193 tmp = 0;
1194 while(tmp < 4) {
1195 ok(tmp < 4, "tmp >= 4");
1196 tmp++;
1197 }
1198 ok(tmp === 4, "tmp !== 4");
1199
1200 tmp = 0;
1201 while(true) {
1202 ok(tmp < 4, "tmp >= 4");
1203 tmp++;
1204 if(tmp === 4) {
1205 break;
1206 ok(false, "break did not break");
1207 }
1208 }
1209 ok(tmp === 4, "tmp !== 4");
1210
1211 tmp = 0;
1212 do {
1213 ok(tmp < 4, "tmp >= 4");
1214 tmp++;
1215 } while(tmp < 4);
1216 ok(tmp === 4, "tmp !== 4");
1217
1218 tmp = 0;
1219 do {
1220 ok(tmp === 0, "tmp !=== 0");
1221 tmp++;
1222 } while(false);
1223 ok(tmp === 1, "tmp !== 1");
1224
1225 tmp = 0;
1226 do {
1227 ok(tmp < 4, "tmp >= 4");
1228 tmp++;
1229 } while(tmp < 4)
1230 ok(tmp === 4, "tmp !== 4")
1231
1232 tmp = 0;
1233 while(tmp < 4) {
1234 tmp++;
1235 if(tmp === 2) {
1236 continue;
1237 ok(false, "break did not break");
1238 }
1239 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
1240 }
1241 ok(tmp === 4, "tmp !== 4");
1242
1243 for(tmp=0; tmp < 4; tmp++)
1244 ok(tmp < 4, "tmp = " + tmp);
1245 ok(tmp === 4, "tmp !== 4");
1246
1247 for(tmp=0; tmp < 4; tmp++) {
1248 if(tmp === 2)
1249 break;
1250 ok(tmp < 2, "tmp = " + tmp);
1251 }
1252 ok(tmp === 2, "tmp !== 2");
1253
1254 for(tmp=0; tmp < 4; tmp++) {
1255 if(tmp === 2)
1256 continue;
1257 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
1258 }
1259 ok(tmp === 4, "tmp !== 4");
1260
1261 for(var fi=0; fi < 4; fi++)
1262 ok(fi < 4, "fi = " + fi);
1263 ok(fi === 4, "fi !== 4");
1264
1265 tmp = true;
1266 obj1 = new Object();
1267 for(obj1.nonexistent; tmp; tmp = false)
1268 ok(!("nonexistent" in obj1), "nonexistent added to obj1");
1269
1270 obj1 = new Object();
1271 for(tmp in obj1.nonexistent)
1272 ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
1273 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
1274
1275
1276 var i, j;
1277
1278 /* Previous versions have broken finally block implementation */
1279 if(ScriptEngineMinorVersion() >= 8) {
1280 tmp = "";
1281 i = 0;
1282 while(true) {
1283 tmp += "1";
1284 for(i = 1; i < 3; i++) {
1285 switch(i) {
1286 case 1:
1287 tmp += "2";
1288 continue;
1289 case 2:
1290 tmp += "3";
1291 try {
1292 throw null;
1293 }finally {
1294 tmp += "4";
1295 break;
1296 }
1297 default:
1298 ok(false, "unexpected state");
1299 }
1300 tmp += "5";
1301 }
1302 with({prop: "6"}) {
1303 tmp += prop;
1304 break;
1305 }
1306 }
1307 ok(tmp === "123456", "tmp = " + tmp);
1308 }
1309
1310 tmp = "";
1311 i = 0;
1312 for(j in [1,2,3]) {
1313 tmp += "1";
1314 for(;;) {
1315 with({prop: "2"}) {
1316 tmp += prop;
1317 try {
1318 throw "3";
1319 }catch(e) {
1320 tmp += e;
1321 with([0])
1322 break;
1323 }
1324 }
1325 ok(false, "unexpected state");
1326 }
1327 while(true) {
1328 tmp += "4";
1329 break;
1330 }
1331 break;
1332 }
1333 ok(tmp === "1234", "tmp = " + tmp);
1334
1335 tmp = 0;
1336 for(var iter in [1,2,3]) {
1337 tmp += +iter;
1338 continue;
1339 }
1340 ok(tmp === 3, "tmp = " + tmp);
1341
1342 tmp = false;
1343 for(var iter in [1,2,3]) {
1344 switch(+iter) {
1345 case 1:
1346 tmp = true;
1347 try {
1348 continue;
1349 }finally {}
1350 default:
1351 continue;
1352 }
1353 }
1354 ok(tmp, "tmp = " + tmp);
1355
1356 loop_label:
1357 while(true) {
1358 while(true)
1359 break loop_label;
1360 }
1361
1362 loop_label: {
1363 tmp = 0;
1364 while(true) {
1365 while(true)
1366 break loop_label;
1367 }
1368 ok(false, "unexpected evaluation 1");
1369 }
1370
1371 while(true) {
1372 some_label: break;
1373 ok(false, "unexpected evaluation 2");
1374 }
1375
1376 just_label: tmp = 1;
1377 ok(tmp === 1, "tmp != 1");
1378
1379 some_label: break some_label;
1380
1381 other_label: {
1382 break other_label;
1383 ok(false, "unexpected evaluation 3");
1384 }
1385
1386 loop_label:
1387 do {
1388 while(true)
1389 continue loop_label;
1390 }while(false);
1391
1392 loop_label:
1393 for(i = 0; i < 3; i++) {
1394 while(true)
1395 continue loop_label;
1396 }
1397
1398 loop_label:
1399 other_label:
1400 for(i = 0; i < 3; i++) {
1401 while(true)
1402 continue loop_label;
1403 }
1404
1405 loop_label:
1406 for(tmp in {prop: false}) {
1407 while(true)
1408 continue loop_label;
1409 }
1410
1411 ok((void 1) === undefined, "(void 1) !== undefined");
1412
1413 var inobj = new Object();
1414
1415 for(var iter in inobj)
1416 ok(false, "unexpected iter = " + iter);
1417
1418 inobj.test = true;
1419 tmp = 0;
1420 for(iter in inobj) {
1421 ok(iter == "test", "unexpected iter = " + iter);
1422 tmp++;
1423 }
1424 ok(tmp === 1, "for..in tmp = " + tmp);
1425
1426 function forinTestObj() {}
1427
1428 forinTestObj.prototype.test3 = true;
1429
1430 var arr = new Array();
1431 inobj = new forinTestObj();
1432 inobj.test1 = true;
1433 inobj.test2 = true;
1434
1435 tmp = 0;
1436 for(iter in inobj) {
1437 arr[iter] = true;
1438 tmp++;
1439 }
1440
1441 ok(tmp === 3, "for..in tmp = " + tmp);
1442 ok(arr["test1"] === true, "arr[test1] !== true");
1443 ok(arr["test2"] === true, "arr[test2] !== true");
1444 ok(arr["test3"] === true, "arr[test3] !== true");
1445
1446 tmp = new Object();
1447 tmp.test = false;
1448 ok((delete tmp.test) === true, "delete returned false");
1449 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1450 ok(!("test" in tmp), "test is still in tmp after delete?");
1451 for(iter in tmp)
1452 ok(false, "tmp has prop " + iter);
1453 ok((delete tmp.test) === true, "deleting test didn't return true");
1454 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1455 ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1456
1457 tmp = new Object();
1458 tmp.test = false;
1459 ok((delete tmp["test"]) === true, "delete returned false");
1460 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1461 ok(!("test" in tmp), "test is still in tmp after delete?");
1462
1463 tmp.testWith = true;
1464 with(tmp)
1465 ok(testWith === true, "testWith !== true");
1466
1467 if(false) {
1468 var varTest1 = true;
1469 }
1470
1471 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1472 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1473
1474 var varTest2;
1475
1476 function varTestFunc(varTest3) {
1477 var varTest3;
1478
1479 ok(varTest3 === 3, "varTest3 = " + varTest3);
1480 ok(varTest4 === undefined, "varTest4 = " + varTest4);
1481
1482 var varTest4;
1483 }
1484
1485 varTestFunc(3);
1486
1487 deleteTest = 1;
1488 delete deleteTest;
1489 try {
1490 tmp = deleteTest;
1491 ok(false, "deleteTest not throwed exception?");
1492 }catch(ex) {}
1493
1494 (function() {
1495 var to_delete = 2;
1496 var r = delete to_delete;
1497 ok(r === false, "delete 1 returned " + r);
1498 if(r)
1499 return;
1500 ok(to_delete === 2, "to_delete = " + to_delete);
1501
1502 to_delete = new Object();
1503 r = delete to_delete;
1504 ok(r === false, "delete 2 returned " + r);
1505 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1506 })();
1507
1508 (function(to_delete) {
1509 var r = delete to_delete;
1510 ok(r === false, "delete 3 returned " + r);
1511 ok(to_delete === 2, "to_delete = " + to_delete);
1512
1513 to_delete = new Object();
1514 r = delete to_delete;
1515 ok(r === false, "delete 4 returned " + r);
1516 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1517 })(2);
1518
1519 (function() {
1520 with({to_delete: new Object()}) {
1521 var r = delete to_delete;
1522 ok(r === true, "delete returned " + r);
1523 }
1524 })();
1525
1526 if (false)
1527 if (true)
1528 ok(false, "if evaluated");
1529 else
1530 ok(false, "else should be associated with nearest if statement");
1531
1532 if (true)
1533 if (false)
1534 ok(false, "if evaluated");
1535 else
1536 ok(true, "else should be associated with nearest if statement");
1537
1538 function instanceOfTest() {}
1539 tmp = new instanceOfTest();
1540
1541 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1542 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1543 ok((tmp instanceof String) === false, "tmp is instance of String");
1544
1545 instanceOfTest.prototype = new Object();
1546 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1547 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1548
1549 ok((1 instanceof Object) === false, "1 is instance of Object");
1550 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1551 ok(("" instanceof Object) === false, "'' is instance of Object");
1552
1553 (function () {
1554 ok((arguments instanceof Object) === true, "argument is not instance of Object");
1555 ok((arguments instanceof Array) === false, "argument is not instance of Array");
1556 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1557 })(1,2);
1558
1559 obj = new String();
1560 ok(("length" in obj) === true, "length is not in obj");
1561 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1562 ok(("abc" in obj) === false, "test is in obj");
1563 obj.abc = 1;
1564 ok(("abc" in obj) === true, "test is not in obj");
1565 ok(("1" in obj) === false, "1 is in obj");
1566
1567 obj = [1,2,3];
1568 ok((1 in obj) === true, "1 is not in obj");
1569
1570 obj = new Object();
1571 try {
1572 obj.prop["test"];
1573 ok(false, "expected exception");
1574 }catch(e) {}
1575 ok(!("prop" in obj), "prop in obj");
1576
1577 if(invokeVersion >= 2) {
1578 ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1579 ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1580
1581 tmp = "test";
1582 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1583 tmp[1] = "x";
1584 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1585 ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1586 ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1587 }else {
1588 ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1589 }
1590
1591 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1592 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1593 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1594 ok(isNaN() === true, "isNaN() !== true");
1595 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1596 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1597 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1598
1599 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1600 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1601 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1602 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1603 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1604 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1605 ok(isFinite() === false, "isFinite() !== false");
1606
1607 ok((1 < NaN) === false, "(1 < NaN) !== false");
1608 ok((1 > NaN) === false, "(1 > NaN) !== false");
1609 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1610 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1611 ok((NaN < 1) === false, "(NaN < 1) !== false");
1612 ok((NaN > 1) === false, "(NaN > 1) !== false");
1613 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1614 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1615 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1616 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1617 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1618
1619 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1620 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1621 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1622 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1623 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1624 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1625
1626 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1627 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1628 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1629 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1630 ok((0 === NaN) === false, "(0 === NaN) !== false");
1631
1632 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1633 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1634 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1635 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1636 ok((0 == NaN) === false, "(0 === NaN) != false");
1637
1638 // escape tests
1639 var escapeTests = [
1640 ["\'", "\\'", 39],
1641 ["\"", "\\\"", 34],
1642 ["\\", "\\\\", 92],
1643 ["\b", "\\b", 8],
1644 ["\t", "\\t", 9],
1645 ["\n", "\\n", 10],
1646 ["\v", "\\v", 118],
1647 ["\f", "\\f", 12],
1648 ["\r", "\\r", 13],
1649 ["\xf3", "\\xf3", 0xf3],
1650 ["\u1234", "\\u1234", 0x1234],
1651 ["\a", "\\a", 97],
1652 ["\?", "\\?", 63]
1653 ];
1654
1655 for(i=0; i<escapeTests.length; i++) {
1656 tmp = escapeTests[i][0].charCodeAt(0);
1657 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1658 }
1659
1660 tmp = !+"\v1";
1661 ok(tmp === true, '!+"\v1" = ' + tmp);
1662
1663 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1664 tmp = testFunc2(1);
1665 ok(tmp === 2, "testFunc2(1) = " + tmp);
1666 function testFunc2(x) { return x+1; }
1667
1668 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1669 tmp = testFunc3(1);
1670 ok(tmp === 3, "testFunc3(1) = " + tmp);
1671 tmp = function testFunc3(x) { return x+2; };
1672
1673 tmp = testFunc4(1);
1674 ok(tmp === 5, "testFunc4(1) = " + tmp);
1675 tmp = function testFunc4(x) { return x+3; };
1676 tmp = testFunc4(1);
1677 testFunc4 = 1;
1678 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1679 ok(tmp === 5, "testFunc4(1) = " + tmp);
1680 tmp = function testFunc4(x) { return x+4; };
1681 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1682
1683 function testEmbeddedFunctions() {
1684 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1685 tmp = testFunc5(1);
1686 ok(tmp === 3, "testFunc5(1) = " + tmp);
1687 tmp = function testFunc5(x) { return x+2; };
1688
1689 tmp = testFunc6(1);
1690 ok(tmp === 5, "testFunc6(1) = " + tmp);
1691 tmp = function testFunc6(x) { return x+3; };
1692 tmp = testFunc6(1);
1693 ok(tmp === 5, "testFunc6(1) = " + tmp);
1694 tmp = function testFunc6(x) { return x+4; };
1695 testFunc6 = 1;
1696 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1697 }
1698
1699 testEmbeddedFunctions();
1700
1701 date = new Date();
1702 date.toString = function() { return "toString"; }
1703 ok(""+date === "toString", "''+date = " + date);
1704 date.toString = function() { return this; }
1705 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1706
1707 str = new String("test");
1708 str.valueOf = function() { return "valueOf"; }
1709 ok(""+str === "valueOf", "''+str = " + str);
1710 str.valueOf = function() { return new Date(); }
1711 ok(""+str === "test", "''+str = " + str);
1712
1713 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1714
1715 var re = /=(\?|%3F)/g;
1716 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1717
1718 tmp = new Array();
1719 for(var i=0; i<2; i++)
1720 tmp[i] = /b/;
1721 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1722
1723 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1724 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1725 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1726
1727 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1728 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1729 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1730 ok(nullDisp !== re, "nullDisp === re");
1731 ok(nullDisp === null, "nullDisp === null");
1732 ok(nullDisp == null, "nullDisp == null");
1733 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1734 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1735 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1736 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1737 ok(nullDisp != new Object(), "nullDisp == new Object()");
1738 ok(new Object() != nullDisp, "new Object() == nullDisp");
1739 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1740 tmp = getVT(Object(nullDisp));
1741 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1742 tmp = Object(nullDisp).toString();
1743 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1744
1745 function do_test() {}
1746 function nosemicolon() {} nosemicolon();
1747 function () {} nosemicolon();
1748
1749 if(false) {
1750 function in_if_false() { return true; } ok(false, "!?");
1751 }
1752
1753 ok(in_if_false(), "in_if_false failed");
1754
1755 (function() { newValue = 1; })();
1756 ok(newValue === 1, "newValue = " + newValue);
1757
1758 obj = {undefined: 3};
1759
1760 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1761 name_override_func = 3;
1762 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1763 function name_override_func() {};
1764 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1765
1766 tmp = (function() {
1767 var ret = false;
1768 with({ret: true})
1769 return ret;
1770 })();
1771 ok(tmp, "tmp = " + tmp);
1772
1773 tmp = (function() {
1774 for(var iter in [1,2,3,4]) {
1775 var ret = false;
1776 with({ret: true})
1777 return ret;
1778 }
1779 })();
1780 ok(tmp, "tmp = " + tmp);
1781
1782 (function() {
1783 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
1784 with(new Object()) {
1785 var x = false && function func() {};
1786 }
1787 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
1788 })();
1789
1790 (function() {
1791 ok(x === undefined, "x = " + x); // x is declared, but never initialized
1792 with({x: 1}) {
1793 ok(x === 1, "x = " + x);
1794 var x = 2;
1795 ok(x === 2, "x = " + x);
1796 }
1797 ok(x === undefined, "x = " + x);
1798 })();
1799
1800 /* NoNewline rule parser tests */
1801 while(true) {
1802 if(true) break
1803 tmp = false
1804 }
1805
1806 while(true) {
1807 if(true) break /*
1808 * no semicolon, but comment present */
1809 tmp = false
1810 }
1811
1812 while(true) {
1813 if(true) break // no semicolon, but comment present
1814 tmp = false
1815 }
1816
1817 while(true) {
1818 break
1819 continue
1820 tmp = false
1821 }
1822
1823 function returnTest() {
1824 return
1825 true;
1826 }
1827
1828 ok(returnTest() === undefined, "returnTest = " + returnTest());
1829
1830 ActiveXObject = 1;
1831 ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);
1832
1833 Boolean = 1;
1834 ok(Boolean === 1, "Boolean = " + Boolean);
1835
1836 Object = 1;
1837 ok(Object === 1, "Object = " + Object);
1838
1839 Array = 1;
1840 ok(Array === 1, "Array = " + Array);
1841
1842 Date = 1;
1843 ok(Date === 1, "Date = " + Date);
1844
1845 Error = 1;
1846 ok(Error === 1, "Error = " + Error);
1847
1848 /* Keep this test in the end of file */
1849 undefined = 6;
1850 ok(undefined === 6, "undefined = " + undefined);
1851
1852 NaN = 6;
1853 ok(NaN === 6, "NaN !== 6");
1854
1855 Infinity = 6;
1856 ok(Infinity === 6, "Infinity !== 6");
1857
1858 Math = 6;
1859 ok(Math === 6, "NaN !== 6");
1860
1861 reportSuccess();