2a30ea35a71a371057ca9ee6afdc235a8fd6b2fc
[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 if(invokeVersion >= 2) {
484 eval("tmp = {prop: 'value',}");
485 ok(tmp.prop === "value", "tmp.prop = " + tmp.prop);
486 eval("tmp = {prop: 'value',second:2,}");
487 ok(tmp.prop === "value", "tmp.prop = " + tmp.prop);
488 }else {
489 try {
490 eval("tmp = {prop: 'value',}");
491 }catch(e) {
492 tmp = true;
493 }
494 ok(tmp === true, "exception not fired");
495 }
496
497 {
498 var blockVar = 1;
499 blockVar = 2;
500 }
501 ok(blockVar === 2, "blockVar !== 2");
502
503 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
504 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
505
506 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
507 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
508 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
509 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
510 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
511 ok(getVT(Math) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
512 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
513
514 tmp = 2+2;
515 ok(tmp === 4, "2+2 !== 4");
516 ok(getVT(tmp) === "VT_I4", "getVT(2+2) !== VT_I4");
517
518 tmp = 2+2.5;
519 ok(tmp === 4.5, "2+2.5 !== 4.5");
520 ok(getVT(tmp) === "VT_R8", "getVT(2+2.5) !== VT_R8");
521
522 tmp = 1.5+2.5;
523 ok(tmp === 4, "1.4+2.5 !== 4");
524 ok(getVT(tmp) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
525
526 tmp = 4-2;
527 ok(tmp === 2, "4-2 !== 2");
528 ok(getVT(tmp) === "VT_I4", "getVT(4-2) !== VT_I4");
529
530 tmp = 4.5-2;
531 ok(tmp === 2.5, "4.5-2 !== 2.5");
532 ok(getVT(tmp) === "VT_R8", "getVT(4.5-2) !== VT_R8");
533
534 tmp = -2;
535 ok(tmp === 0-2, "-2 !== 0-2");
536 ok(getVT(tmp) === "VT_I4", "getVT(-2) !== VT_I4");
537
538 tmp = 2*3;
539 ok(tmp === 6, "2*3 !== 6");
540 ok(getVT(tmp) === "VT_I4", "getVT(2*3) !== VT_I4");
541
542 tmp = 2*3.5;
543 ok(tmp === 7, "2*3.5 !== 7");
544 ok(getVT(tmp) === "VT_I4", "getVT(2*3.5) !== VT_I4");
545
546 tmp = 2.5*3.5;
547 /* FIXME: the parser loses precision */
548 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
549 ok(tmp > 8.749999 && tmp < 8.750001, "2.5*3.5 !== 8.75");
550 ok(getVT(tmp) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
551
552 tmp = 2*.5;
553 ok(tmp === 1, "2*.5 !== 1");
554 ok(getVT(tmp) == "VT_I4", "getVT(2*.5) !== VT_I4");
555
556 tmp = 4/2;
557 ok(tmp === 2, "4/2 !== 2");
558 ok(getVT(tmp) === "VT_I4", "getVT(4/2) !== VT_I4");
559
560 tmp = 4.5/1.5;
561 ok(tmp === 3, "4.5/1.5 !== 3");
562 ok(getVT(tmp) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
563
564 tmp = 3/2;
565 ok(tmp === 1.5, "3/2 !== 1.5");
566 ok(getVT(tmp) === "VT_R8", "getVT(3/2) !== VT_R8");
567
568 tmp = 3%2;
569 ok(tmp === 1, "3%2 = " + tmp);
570
571 tmp = 4%2;
572 ok(tmp ===0, "4%2 = " + tmp);
573
574 tmp = 3.5%1.5;
575 ok(tmp === 0.5, "3.5%1.5 = " + tmp);
576
577 tmp = 3%true;
578 ok(tmp === 0, "3%true = " + tmp);
579
580 tmp = "ab" + "cd";
581 ok(tmp === "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
582
583 tmp = 1;
584 ok((tmp += 1) === 2, "tmp += 1 !== 2");
585 ok(tmp === 2, "tmp !== 2");
586
587 tmp = 2;
588 ok((tmp -= 1) === 1, "tmp -= 1 !== 1");
589 ok(tmp === 1, "tmp !=== 1");
590
591 tmp = 2;
592 ok((tmp *= 1.5) === 3, "tmp *= 1.5 !== 3");
593 ok(tmp === 3, "tmp !=== 3");
594
595 tmp = 5;
596 ok((tmp /= 2) === 2.5, "tmp /= 2 !== 2.5");
597 ok(tmp === 2.5, "tmp !=== 2.5");
598
599 tmp = 3;
600 ok((tmp %= 2) === 1, "tmp %= 2 !== 1");
601 ok(tmp === 1, "tmp !== 1");
602
603 tmp = 8;
604 ok((tmp <<= 1) === 16, "tmp <<= 1 !== 16");
605
606 tmp = 8;
607 ok((tmp >>= 1) === 4, "tmp >>= 1 !== 4");
608
609 tmp = 8;
610 ok((tmp >>>= 1) === 4, "tmp >>>= 1 !== 4");
611
612 tmp = 3 || ok(false, "second or expression called");
613 ok(tmp === 3, "3 || (...) is not 3");
614
615 tmp = false || 2;
616 ok(tmp === 2, "false || 2 is not 2");
617
618 tmp = 0 && ok(false, "second and expression called");
619 ok(tmp === 0, "0 && (...) is not 0");
620
621 tmp = true && "test";
622 ok(tmp === "test", "true && \"test\" is not \"test\"");
623
624 tmp = true && 0;
625 ok(tmp === 0, "true && 0 is not 0");
626
627 tmp = 3 | 4;
628 ok(tmp === 7, "3 | 4 !== 7");
629 ok(getVT(tmp) === "VT_I4", "getVT(3|4) = " + getVT(tmp));
630
631 tmp = 3.5 | 0;
632 ok(tmp === 3, "3.5 | 0 !== 3");
633 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
634
635 tmp = -3.5 | 0;
636 ok(tmp === -3, "-3.5 | 0 !== -3");
637 ok(getVT(tmp) === "VT_I4", "getVT(3.5|0) = " + getVT(tmp));
638
639 tmp = 0 | NaN;
640 ok(tmp === 0, "0 | NaN = " + tmp);
641
642 tmp = 0 | Infinity;
643 ok(tmp === 0, "0 | NaN = " + tmp);
644
645 tmp = 0 | (-Infinity);
646 ok(tmp === 0, "0 | NaN = " + tmp);
647
648 tmp = 10;
649 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
650 ok(getVT(tmp) === "VT_I4", "getVT(tmp |= 10) = " + getVT(tmp));
651
652 tmp = (123 * Math.pow(2,32) + 2) | 0;
653 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
654
655 tmp = (-123 * Math.pow(2,32) + 2) | 0;
656 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
657
658 tmp = 3 & 5;
659 ok(tmp === 1, "3 & 5 !== 1");
660 ok(getVT(tmp) === "VT_I4", "getVT(3|5) = " + getVT(tmp));
661
662 tmp = 3.5 & 0xffff;
663 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
664 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
665
666 tmp = (-3.5) & 0xffffffff;
667 ok(tmp === -3, "-3.5 & 0xffff !== -3");
668 ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp));
669
670 tmp = 2 << 3;
671 ok(tmp === 16, "2 << 3 = " + tmp);
672
673 tmp = 2 << 35;
674 ok(tmp === 16, "2 << 35 = " + tmp);
675
676 tmp = 8 >> 2;
677 ok(tmp === 2, "8 >> 2 = " + tmp);
678
679 tmp = -64 >> 4;
680 ok(tmp === -4, "-64 >> 4 = " + tmp);
681
682 tmp = 8 >>> 2;
683 ok(tmp === 2, "8 >> 2 = " + tmp);
684
685 tmp = -64 >>> 4;
686 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
687
688 tmp = 4 >>> NaN;
689 ok(tmp === 4, "4 >>> NaN = " + tmp);
690
691 tmp = 10;
692 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
693 ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp));
694
695 tmp = 0xf0f0^0xff00;
696 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
697 ok(getVT(tmp) === "VT_I4", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
698
699 tmp = 5;
700 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
701 ok(getVT(tmp) === "VT_I4", "getVT(tmp ^= 3) = " + getVT(tmp));
702
703 tmp = ~1;
704 ok(tmp === -2, "~1 !== -2");
705 ok(getVT(tmp) === "VT_I4", "getVT(~1) = " + getVT(tmp));
706
707 ok((3,4) === 4, "(3,4) !== 4");
708
709 ok(+3 === 3, "+3 !== 3");
710 ok(+true === 1, "+true !== 1");
711 ok(+false === 0, "+false !== 0");
712 ok(+null === 0, "+null !== 0");
713 ok(+"0" === 0, "+'0' !== 0");
714 ok(+"3" === 3, "+'3' !== 3");
715 ok(+"-3" === -3, "+'-3' !== -3");
716 ok(+"0xff" === 255, "+'0xff' !== 255");
717 ok(+"3e3" === 3000, "+'3e3' !== 3000");
718
719 tmp = new Number(1);
720 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
721 ok(tmp.constructor === Number, "unexpected tmp.constructor");
722 tmp = new String("1");
723 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
724 ok(tmp.constructor === String, "unexpected tmp.constructor");
725
726 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
727 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
728 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
729 ok("" + null === "null", "\"\" + null !== \"null\"");
730 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
731 ok("" + true === "true", "\"\" + true !== \"true\"");
732 ok("" + false === "false", "\"\" + false !== \"false\"");
733 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
734 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
735
736 ok(1 < 3.4, "1 < 3.4 failed");
737 ok(!(3.4 < 1), "3.4 < 1");
738 ok("abc" < "abcd", "abc < abcd failed");
739 ok("abcd" < "abce", "abce < abce failed");
740 ok("" < "x", "\"\" < \"x\" failed");
741 ok(!(0 < 0), "0 < 0");
742
743 ok(1 <= 3.4, "1 <= 3.4 failed");
744 ok(!(3.4 <= 1), "3.4 <= 1");
745 ok("abc" <= "abcd", "abc <= abcd failed");
746 ok("abcd" <= "abce", "abce <= abce failed");
747 ok("" <= "x", "\"\" <= \"x\" failed");
748 ok(0 <= 0, "0 <= 0 failed");
749
750 ok(3.4 > 1, "3.4 > 1 failed");
751 ok(!(1 > 3.4), "1 > 3.4");
752 ok("abcd" > "abc", "abc > abcd failed");
753 ok("abce" > "abcd", "abce > abce failed");
754 ok("x" > "", "\"x\" > \"\" failed");
755 ok(!(0 > 0), "0 > 0");
756
757 ok(3.4 >= 1, "3.4 >= 1 failed");
758 ok(!(1 >= 3.4), "1 >= 3.4");
759 ok("abcd" >= "abc", "abc >= abcd failed");
760 ok("abce" >= "abcd", "abce >= abce failed");
761 ok("x" >= "", "\"x\" >= \"\" failed");
762 ok(0 >= 0, "0 >= 0");
763
764 tmp = 1;
765 ok(++tmp === 2, "++tmp (1) is not 2");
766 ok(tmp === 2, "incremented tmp is not 2");
767 ok(--tmp === 1, "--tmp (2) is not 1");
768 ok(tmp === 1, "decremented tmp is not 1");
769 ok(tmp++ === 1, "tmp++ (1) is not 1");
770 ok(tmp === 2, "incremented tmp(1) is not 2");
771 ok(tmp-- === 2, "tmp-- (2) is not 2");
772 ok(tmp === 1, "decremented tmp is not 1");
773
774 tmp = new Object();
775 tmp.iii++;
776 ok(isNaN(tmp.iii), "tmp.iii = " + tmp.iii);
777
778 String.prototype.test = true;
779 ok("".test === true, "\"\".test is not true");
780
781 Boolean.prototype.test = true;
782 ok(true.test === true, "true.test is not true");
783
784 Number.prototype.test = true;
785 ok((0).test === true, "(0).test is not true");
786 ok((0.5).test === true, "(0.5).test is not true");
787
788 var state = "";
789 try {
790 ok(state === "", "try: state = " + state);
791 state = "try";
792 }catch(ex) {
793 ok(false, "unexpected catch");
794 }
795 ok(state === "try", "state = " + state + " expected try");
796
797 state = "";
798 try {
799 ok(state === "", "try: state = " + state);
800 state = "try";
801 }finally {
802 ok(state === "try", "finally: state = " + state);
803 state = "finally";
804 }
805 ok(state === "finally", "state = " + state + " expected finally");
806
807 state = "";
808 try {
809 try {
810 throw 0;
811 }finally {
812 state = "finally";
813 }
814 }catch(e) {
815 ok(state === "finally", "state = " + state + " expected finally");
816 state = "catch";
817 }
818 ok(state === "catch", "state = " + state + " expected catch");
819
820 try {
821 try {
822 throw 0;
823 }finally {
824 throw 1;
825 }
826 }catch(e) {
827 ok(e === 1, "e = " + e);
828 }
829
830 state = "";
831 try {
832 ok(state === "", "try: state = " + state);
833 state = "try";
834 }catch(ex) {
835 ok(false, "unexpected catch");
836 }finally {
837 ok(state === "try", "finally: state = " + state);
838 state = "finally";
839 }
840 ok(state === "finally", "state = " + state + " expected finally");
841
842 var state = "";
843 try {
844 ok(state === "", "try: state = " + state);
845 state = "try";
846 throw "except";
847 }catch(ex) {
848 ok(state === "try", "catch: state = " + state);
849 ok(ex === "except", "ex is not \"except\"");
850 state = "catch";
851 }
852 ok(state === "catch", "state = " + state + " expected catch");
853
854 var state = "";
855 try {
856 ok(state === "", "try: state = " + state);
857 state = "try";
858 throw true;
859 }catch(ex) {
860 ok(state === "try", "catch: state = " + state);
861 ok(ex === true, "ex is not true");
862 state = "catch";
863 }finally {
864 ok(state === "catch", "finally: state = " + state);
865 state = "finally";
866 }
867 ok(state === "finally", "state = " + state + " expected finally");
868
869 var state = "";
870 try {
871 ok(state === "", "try: state = " + state);
872 state = "try";
873 try { throw true; } finally {}
874 }catch(ex) {
875 ok(state === "try", "catch: state = " + state);
876 ok(ex === true, "ex is not true");
877 state = "catch";
878 }finally {
879 ok(state === "catch", "finally: state = " + state);
880 state = "finally";
881 }
882 ok(state === "finally", "state = " + state + " expected finally");
883
884 var state = "";
885 try {
886 ok(state === "", "try: state = " + state);
887 state = "try";
888 try { throw "except"; } catch(ex) { throw true; }
889 }catch(ex) {
890 ok(state === "try", "catch: state = " + state);
891 ok(ex === true, "ex is not true");
892 state = "catch";
893 }finally {
894 ok(state === "catch", "finally: state = " + state);
895 state = "finally";
896 }
897 ok(state === "finally", "state = " + state + " expected finally");
898
899 function throwFunc(x) {
900 throw x;
901 }
902
903 var state = "";
904 try {
905 ok(state === "", "try: state = " + state);
906 state = "try";
907 throwFunc(true);
908 }catch(ex) {
909 ok(state === "try", "catch: state = " + state);
910 ok(ex === true, "ex is not true");
911 state = "catch";
912 }finally {
913 ok(state === "catch", "finally: state = " + state);
914 state = "finally";
915 }
916 ok(state === "finally", "state = " + state + " expected finally");
917
918 state = "";
919 switch(1) {
920 case "1":
921 ok(false, "unexpected case \"1\"");
922 case 1:
923 ok(state === "", "case 1: state = " + state);
924 state = "1";
925 default:
926 ok(state === "1", "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("") {
936 case "1":
937 case 1:
938 ok(false, "unexpected case 1");
939 default:
940 ok(state === "", "default: state = " + state);
941 state = "default";
942 case false:
943 ok(state === "default", "case false: state = " + state);
944 state = "false";
945 }
946 ok(state === "false", "state = " + state);
947
948 state = "";
949 switch(1) {
950 case "1":
951 ok(false, "unexpected case \"1\"");
952 case 1:
953 ok(state === "", "case 1: state = " + state);
954 state = "1";
955 default:
956 ok(state === "1", "default: state = " + state);
957 state = "default";
958 break;
959 case false:
960 ok(false, "unexpected case false");
961 }
962 ok(state === "default", "state = " + state);
963
964 switch(1) {
965 case 2:
966 ok(false, "unexpected case 2");
967 case 3:
968 ok(false, "unexpected case 3");
969 }
970
971 switch(1) {
972 case 2:
973 ok(false, "unexpected case 2");
974 break;
975 default:
976 /* empty default */
977 }
978
979 switch(2) {
980 default:
981 ok(false, "unexpected default");
982 break;
983 case 2:
984 /* empty case */
985 };
986
987 switch(2) {
988 default:
989 ok(false, "unexpected default");
990 break;
991 case 1:
992 case 2:
993 case 3:
994 /* empty case */
995 };
996
997 (function() {
998 var i=0;
999
1000 switch(1) {
1001 case 1:
1002 i++;
1003 }
1004 return i;
1005 })();
1006
1007 (function() {
1008 var ret, x;
1009
1010 function unreachable() {
1011 ok(false, "unreachable");
1012 }
1013
1014 function expect(value, expect_value) {
1015 ok(value === expect_value, "got " + value + " expected " + expect_value);
1016 }
1017
1018 ret = (function() {
1019 try {
1020 return "try";
1021 unreachable();
1022 }catch(e) {
1023 unreachable();
1024 }finally {
1025 return "finally";
1026 unreachable();
1027 }
1028 unreachable();
1029 })();
1030 expect(ret, "finally");
1031
1032 x = "";
1033 ret = (function() {
1034 try {
1035 x += "try,";
1036 return x;
1037 unreachable();
1038 }catch(e) {
1039 unreachable();
1040 }finally {
1041 x += "finally,";
1042 }
1043 unreachable();
1044 })();
1045 expect(ret, "try,");
1046 expect(x, "try,finally,");
1047
1048 x = "";
1049 ret = (function() {
1050 try {
1051 x += "try,"
1052 throw 1;
1053 unreachable();
1054 }catch(e) {
1055 x += "catch,";
1056 return "catch";
1057 unreachable();
1058 }finally {
1059 x += "finally,";
1060 return "finally";
1061 unreachable();
1062 }
1063 unreachable();
1064 })();
1065 expect(ret, "finally");
1066 expect(x, "try,catch,finally,");
1067
1068 x = "";
1069 ret = (function() {
1070 try {
1071 x += "try,"
1072 throw 1;
1073 unreachable();
1074 }catch(e) {
1075 x += "catch,";
1076 return "catch";
1077 unreachable();
1078 }finally {
1079 x += "finally,";
1080 }
1081 unreachable();
1082 })();
1083 expect(ret, "catch");
1084 expect(x, "try,catch,finally,");
1085
1086 x = "";
1087 ret = (function() {
1088 try {
1089 x += "try,"
1090 try {
1091 x += "try2,";
1092 return "try2";
1093 }catch(e) {
1094 unreachable();
1095 }finally {
1096 x += "finally2,";
1097 }
1098 unreachable();
1099 }catch(e) {
1100 unreachable();
1101 }finally {
1102 x += "finally,";
1103 }
1104 unreachable();
1105 })();
1106 expect(ret, "try2");
1107 expect(x, "try,try2,finally2,finally,");
1108
1109 x = "";
1110 ret = (function() {
1111 while(true) {
1112 try {
1113 x += "try,"
1114 try {
1115 x += "try2,";
1116 break;
1117 }catch(e) {
1118 unreachable();
1119 }finally {
1120 x += "finally2,";
1121 }
1122 unreachable();
1123 }catch(e) {
1124 unreachable();
1125 }finally {
1126 x += "finally,";
1127 }
1128 unreachable();
1129 }
1130 x += "ret";
1131 return "ret";
1132 })();
1133 expect(ret, "ret");
1134 expect(x, "try,try2,finally2,finally,ret");
1135
1136 x = "";
1137 ret = (function() {
1138 while(true) {
1139 try {
1140 x += "try,"
1141 try {
1142 x += "try2,";
1143 continue;
1144 }catch(e) {
1145 unreachable();
1146 }finally {
1147 x += "finally2,";
1148 }
1149 unreachable();
1150 }catch(e) {
1151 unreachable();
1152 }finally {
1153 x += "finally,";
1154 break;
1155 }
1156 unreachable();
1157 }
1158 x += "ret";
1159 return "ret";
1160 })();
1161 expect(ret, "ret");
1162 expect(x, "try,try2,finally2,finally,ret");
1163
1164 ret = (function() {
1165 try {
1166 return "try";
1167 unreachable();
1168 }catch(e) {
1169 unreachable();
1170 }finally {
1171 new Object();
1172 var tmp = (function() {
1173 var s = new String();
1174 try {
1175 s.length;
1176 }finally {
1177 return 1;
1178 }
1179 })();
1180 }
1181 unreachable();
1182 })();
1183 expect(ret, "try");
1184 })();
1185
1186 tmp = eval("1");
1187 ok(tmp === 1, "eval(\"1\") !== 1");
1188 eval("{ ok(tmp === 1, 'eval: tmp !== 1'); } tmp = 2;");
1189 ok(tmp === 2, "tmp !== 2");
1190
1191 ok(eval(false) === false, "eval(false) !== false");
1192 ok(eval() === undefined, "eval() !== undefined");
1193
1194 tmp = eval("1", "2");
1195 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
1196
1197 var state = "";
1198 try {
1199 ok(state === "", "try: state = " + state);
1200 state = "try";
1201 eval("throwFunc(true);");
1202 }catch(ex) {
1203 ok(state === "try", "catch: state = " + state);
1204 ok(ex === true, "ex is not true");
1205 state = "catch";
1206 }finally {
1207 ok(state === "catch", "finally: state = " + state);
1208 state = "finally";
1209 }
1210 ok(state === "finally", "state = " + state + " expected finally");
1211
1212 tmp = [,,1,2,,,true];
1213 ok(tmp.length === 7, "tmp.length !== 7");
1214 ok(tmp["0"] === undefined, "tmp[0] is not undefined");
1215 ok(tmp["3"] === 2, "tmp[3] !== 2");
1216 ok(tmp["6"] === true, "tmp[6] !== true");
1217 ok(tmp[2] === 1, "tmp[2] !== 1");
1218 ok(!("0" in tmp), "0 found in array");
1219 ok(!("1" in tmp), "1 found in array");
1220 ok("2" in tmp, "2 not found in array");
1221 ok(!("2" in [1,,,,]), "2 found in [1,,,,]");
1222
1223 ok([1,].length === 2, "[1,].length !== 2");
1224 ok([,,].length === 3, "[,,].length !== 3");
1225 ok([,].length === 2, "[].length != 2");
1226 ok([].length === 0, "[].length != 0");
1227
1228 tmp = 0;
1229 while(tmp < 4) {
1230 ok(tmp < 4, "tmp >= 4");
1231 tmp++;
1232 }
1233 ok(tmp === 4, "tmp !== 4");
1234
1235 tmp = 0;
1236 while(true) {
1237 ok(tmp < 4, "tmp >= 4");
1238 tmp++;
1239 if(tmp === 4) {
1240 break;
1241 ok(false, "break did not break");
1242 }
1243 }
1244 ok(tmp === 4, "tmp !== 4");
1245
1246 tmp = 0;
1247 do {
1248 ok(tmp < 4, "tmp >= 4");
1249 tmp++;
1250 } while(tmp < 4);
1251 ok(tmp === 4, "tmp !== 4");
1252
1253 tmp = 0;
1254 do {
1255 ok(tmp === 0, "tmp !=== 0");
1256 tmp++;
1257 } while(false);
1258 ok(tmp === 1, "tmp !== 1");
1259
1260 tmp = 0;
1261 do {
1262 ok(tmp < 4, "tmp >= 4");
1263 tmp++;
1264 } while(tmp < 4)
1265 ok(tmp === 4, "tmp !== 4")
1266
1267 tmp = 0;
1268 while(tmp < 4) {
1269 tmp++;
1270 if(tmp === 2) {
1271 continue;
1272 ok(false, "break did not break");
1273 }
1274 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
1275 }
1276 ok(tmp === 4, "tmp !== 4");
1277
1278 for(tmp=0; tmp < 4; tmp++)
1279 ok(tmp < 4, "tmp = " + tmp);
1280 ok(tmp === 4, "tmp !== 4");
1281
1282 for(tmp=0; tmp < 4; tmp++) {
1283 if(tmp === 2)
1284 break;
1285 ok(tmp < 2, "tmp = " + tmp);
1286 }
1287 ok(tmp === 2, "tmp !== 2");
1288
1289 for(tmp=0; tmp < 4; tmp++) {
1290 if(tmp === 2)
1291 continue;
1292 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
1293 }
1294 ok(tmp === 4, "tmp !== 4");
1295
1296 for(var fi=0; fi < 4; fi++)
1297 ok(fi < 4, "fi = " + fi);
1298 ok(fi === 4, "fi !== 4");
1299
1300 tmp = true;
1301 obj1 = new Object();
1302 for(obj1.nonexistent; tmp; tmp = false)
1303 ok(!("nonexistent" in obj1), "nonexistent added to obj1");
1304
1305 obj1 = new Object();
1306 for(tmp in obj1.nonexistent)
1307 ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
1308 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
1309
1310
1311 var i, j;
1312
1313 /* Previous versions have broken finally block implementation */
1314 if(ScriptEngineMinorVersion() >= 8) {
1315 tmp = "";
1316 i = 0;
1317 while(true) {
1318 tmp += "1";
1319 for(i = 1; i < 3; i++) {
1320 switch(i) {
1321 case 1:
1322 tmp += "2";
1323 continue;
1324 case 2:
1325 tmp += "3";
1326 try {
1327 throw null;
1328 }finally {
1329 tmp += "4";
1330 break;
1331 }
1332 default:
1333 ok(false, "unexpected state");
1334 }
1335 tmp += "5";
1336 }
1337 with({prop: "6"}) {
1338 tmp += prop;
1339 break;
1340 }
1341 }
1342 ok(tmp === "123456", "tmp = " + tmp);
1343 }
1344
1345 tmp = "";
1346 i = 0;
1347 for(j in [1,2,3]) {
1348 tmp += "1";
1349 for(;;) {
1350 with({prop: "2"}) {
1351 tmp += prop;
1352 try {
1353 throw "3";
1354 }catch(e) {
1355 tmp += e;
1356 with([0])
1357 break;
1358 }
1359 }
1360 ok(false, "unexpected state");
1361 }
1362 while(true) {
1363 tmp += "4";
1364 break;
1365 }
1366 break;
1367 }
1368 ok(tmp === "1234", "tmp = " + tmp);
1369
1370 tmp = 0;
1371 for(var iter in [1,2,3]) {
1372 tmp += +iter;
1373 continue;
1374 }
1375 ok(tmp === 3, "tmp = " + tmp);
1376
1377 tmp = false;
1378 for(var iter in [1,2,3]) {
1379 switch(+iter) {
1380 case 1:
1381 tmp = true;
1382 try {
1383 continue;
1384 }finally {}
1385 default:
1386 continue;
1387 }
1388 }
1389 ok(tmp, "tmp = " + tmp);
1390
1391 loop_label:
1392 while(true) {
1393 while(true)
1394 break loop_label;
1395 }
1396
1397 loop_label: {
1398 tmp = 0;
1399 while(true) {
1400 while(true)
1401 break loop_label;
1402 }
1403 ok(false, "unexpected evaluation 1");
1404 }
1405
1406 while(true) {
1407 some_label: break;
1408 ok(false, "unexpected evaluation 2");
1409 }
1410
1411 just_label: tmp = 1;
1412 ok(tmp === 1, "tmp != 1");
1413
1414 some_label: break some_label;
1415
1416 other_label: {
1417 break other_label;
1418 ok(false, "unexpected evaluation 3");
1419 }
1420
1421 loop_label:
1422 do {
1423 while(true)
1424 continue loop_label;
1425 }while(false);
1426
1427 loop_label:
1428 for(i = 0; i < 3; i++) {
1429 while(true)
1430 continue loop_label;
1431 }
1432
1433 loop_label:
1434 other_label:
1435 for(i = 0; i < 3; i++) {
1436 while(true)
1437 continue loop_label;
1438 }
1439
1440 loop_label:
1441 for(tmp in {prop: false}) {
1442 while(true)
1443 continue loop_label;
1444 }
1445
1446 ok((void 1) === undefined, "(void 1) !== undefined");
1447
1448 var inobj = new Object();
1449
1450 for(var iter in inobj)
1451 ok(false, "unexpected iter = " + iter);
1452
1453 inobj.test = true;
1454 tmp = 0;
1455 for(iter in inobj) {
1456 ok(iter == "test", "unexpected iter = " + iter);
1457 tmp++;
1458 }
1459 ok(tmp === 1, "for..in tmp = " + tmp);
1460
1461 function forinTestObj() {}
1462
1463 forinTestObj.prototype.test3 = true;
1464
1465 var arr = new Array();
1466 inobj = new forinTestObj();
1467 inobj.test1 = true;
1468 inobj.test2 = true;
1469
1470 tmp = 0;
1471 for(iter in inobj) {
1472 arr[iter] = true;
1473 tmp++;
1474 }
1475
1476 ok(tmp === 3, "for..in tmp = " + tmp);
1477 ok(arr["test1"] === true, "arr[test1] !== true");
1478 ok(arr["test2"] === true, "arr[test2] !== true");
1479 ok(arr["test3"] === true, "arr[test3] !== true");
1480
1481 tmp = new Object();
1482 tmp.test = false;
1483 ok((delete tmp.test) === true, "delete returned false");
1484 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1485 ok(!("test" in tmp), "test is still in tmp after delete?");
1486 for(iter in tmp)
1487 ok(false, "tmp has prop " + iter);
1488 ok((delete tmp.test) === true, "deleting test didn't return true");
1489 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1490 ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1491
1492 tmp = new Object();
1493 tmp.test = false;
1494 ok((delete tmp["test"]) === true, "delete returned false");
1495 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1496 ok(!("test" in tmp), "test is still in tmp after delete?");
1497
1498 tmp.testWith = true;
1499 with(tmp)
1500 ok(testWith === true, "testWith !== true");
1501
1502 if(false) {
1503 var varTest1 = true;
1504 }
1505
1506 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1507 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1508
1509 var varTest2;
1510
1511 function varTestFunc(varTest3) {
1512 var varTest3;
1513
1514 ok(varTest3 === 3, "varTest3 = " + varTest3);
1515 ok(varTest4 === undefined, "varTest4 = " + varTest4);
1516
1517 var varTest4;
1518 }
1519
1520 varTestFunc(3);
1521
1522 deleteTest = 1;
1523 delete deleteTest;
1524 try {
1525 tmp = deleteTest;
1526 ok(false, "deleteTest not throwed exception?");
1527 }catch(ex) {}
1528
1529 (function() {
1530 var to_delete = 2;
1531 var r = delete to_delete;
1532 ok(r === false, "delete 1 returned " + r);
1533 if(r)
1534 return;
1535 ok(to_delete === 2, "to_delete = " + to_delete);
1536
1537 to_delete = new Object();
1538 r = delete to_delete;
1539 ok(r === false, "delete 2 returned " + r);
1540 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1541 })();
1542
1543 (function(to_delete) {
1544 var r = delete to_delete;
1545 ok(r === false, "delete 3 returned " + r);
1546 ok(to_delete === 2, "to_delete = " + to_delete);
1547
1548 to_delete = new Object();
1549 r = delete to_delete;
1550 ok(r === false, "delete 4 returned " + r);
1551 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1552 })(2);
1553
1554 (function() {
1555 with({to_delete: new Object()}) {
1556 var r = delete to_delete;
1557 ok(r === true, "delete returned " + r);
1558 }
1559 })();
1560
1561 if (false)
1562 if (true)
1563 ok(false, "if evaluated");
1564 else
1565 ok(false, "else should be associated with nearest if statement");
1566
1567 if (true)
1568 if (false)
1569 ok(false, "if evaluated");
1570 else
1571 ok(true, "else should be associated with nearest if statement");
1572
1573 function instanceOfTest() {}
1574 tmp = new instanceOfTest();
1575
1576 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1577 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1578 ok((tmp instanceof String) === false, "tmp is instance of String");
1579
1580 instanceOfTest.prototype = new Object();
1581 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1582 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1583
1584 ok((1 instanceof Object) === false, "1 is instance of Object");
1585 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1586 ok(("" instanceof Object) === false, "'' is instance of Object");
1587
1588 (function () {
1589 ok((arguments instanceof Object) === true, "argument is not instance of Object");
1590 ok((arguments instanceof Array) === false, "argument is not instance of Array");
1591 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1592 })(1,2);
1593
1594 obj = new String();
1595 ok(("length" in obj) === true, "length is not in obj");
1596 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1597 ok(("abc" in obj) === false, "test is in obj");
1598 obj.abc = 1;
1599 ok(("abc" in obj) === true, "test is not in obj");
1600 ok(("1" in obj) === false, "1 is in obj");
1601
1602 obj = [1,2,3];
1603 ok((1 in obj) === true, "1 is not in obj");
1604
1605 obj = new Object();
1606 try {
1607 obj.prop["test"];
1608 ok(false, "expected exception");
1609 }catch(e) {}
1610 ok(!("prop" in obj), "prop in obj");
1611
1612 if(invokeVersion >= 2) {
1613 ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1614 ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1615
1616 tmp = "test";
1617 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1618 tmp[1] = "x";
1619 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1620 ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1621 ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1622 }else {
1623 ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1624 }
1625
1626 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1627 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1628 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1629 ok(isNaN() === true, "isNaN() !== true");
1630 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1631 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1632 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1633
1634 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1635 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1636 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1637 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1638 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1639 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1640 ok(isFinite() === false, "isFinite() !== false");
1641
1642 ok((1 < NaN) === false, "(1 < NaN) !== false");
1643 ok((1 > NaN) === false, "(1 > NaN) !== false");
1644 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1645 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1646 ok((NaN < 1) === false, "(NaN < 1) !== false");
1647 ok((NaN > 1) === false, "(NaN > 1) !== false");
1648 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1649 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1650 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1651 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1652 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1653
1654 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1655 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1656 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1657 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1658 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1659 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1660
1661 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1662 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1663 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1664 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1665 ok((0 === NaN) === false, "(0 === NaN) !== false");
1666
1667 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1668 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1669 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1670 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1671 ok((0 == NaN) === false, "(0 === NaN) != false");
1672
1673 // escape tests
1674 var escapeTests = [
1675 ["\'", "\\'", 39],
1676 ["\"", "\\\"", 34],
1677 ["\\", "\\\\", 92],
1678 ["\b", "\\b", 8],
1679 ["\t", "\\t", 9],
1680 ["\n", "\\n", 10],
1681 ["\v", "\\v", 118],
1682 ["\f", "\\f", 12],
1683 ["\r", "\\r", 13],
1684 ["\xf3", "\\xf3", 0xf3],
1685 ["\u1234", "\\u1234", 0x1234],
1686 ["\a", "\\a", 97],
1687 ["\?", "\\?", 63]
1688 ];
1689
1690 for(i=0; i<escapeTests.length; i++) {
1691 tmp = escapeTests[i][0].charCodeAt(0);
1692 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1693 }
1694
1695 tmp = !+"\v1";
1696 ok(tmp === true, '!+"\v1" = ' + tmp);
1697
1698 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1699 tmp = testFunc2(1);
1700 ok(tmp === 2, "testFunc2(1) = " + tmp);
1701 function testFunc2(x) { return x+1; }
1702
1703 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1704 tmp = testFunc3(1);
1705 ok(tmp === 3, "testFunc3(1) = " + tmp);
1706 tmp = function testFunc3(x) { return x+2; };
1707
1708 tmp = testFunc4(1);
1709 ok(tmp === 5, "testFunc4(1) = " + tmp);
1710 tmp = function testFunc4(x) { return x+3; };
1711 tmp = testFunc4(1);
1712 testFunc4 = 1;
1713 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1714 ok(tmp === 5, "testFunc4(1) = " + tmp);
1715 tmp = function testFunc4(x) { return x+4; };
1716 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1717
1718 function testEmbeddedFunctions() {
1719 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1720 tmp = testFunc5(1);
1721 ok(tmp === 3, "testFunc5(1) = " + tmp);
1722 tmp = function testFunc5(x) { return x+2; };
1723
1724 tmp = testFunc6(1);
1725 ok(tmp === 5, "testFunc6(1) = " + tmp);
1726 tmp = function testFunc6(x) { return x+3; };
1727 tmp = testFunc6(1);
1728 ok(tmp === 5, "testFunc6(1) = " + tmp);
1729 tmp = function testFunc6(x) { return x+4; };
1730 testFunc6 = 1;
1731 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1732 }
1733
1734 testEmbeddedFunctions();
1735
1736 date = new Date();
1737 date.toString = function() { return "toString"; }
1738 ok(""+date === "toString", "''+date = " + date);
1739 date.toString = function() { return this; }
1740 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1741
1742 str = new String("test");
1743 str.valueOf = function() { return "valueOf"; }
1744 ok(""+str === "valueOf", "''+str = " + str);
1745 str.valueOf = function() { return new Date(); }
1746 ok(""+str === "test", "''+str = " + str);
1747
1748 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1749
1750 var re = /=(\?|%3F)/g;
1751 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1752
1753 tmp = new Array();
1754 for(var i=0; i<2; i++)
1755 tmp[i] = /b/;
1756 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1757
1758 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1759 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1760 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1761
1762 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1763 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1764 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1765 ok(nullDisp !== re, "nullDisp === re");
1766 ok(nullDisp === null, "nullDisp === null");
1767 ok(nullDisp == null, "nullDisp == null");
1768 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1769 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1770 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1771 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1772 ok(nullDisp != new Object(), "nullDisp == new Object()");
1773 ok(new Object() != nullDisp, "new Object() == nullDisp");
1774 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1775 tmp = getVT(Object(nullDisp));
1776 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1777 tmp = Object(nullDisp).toString();
1778 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1779
1780 function do_test() {}
1781 function nosemicolon() {} nosemicolon();
1782 function () {} nosemicolon();
1783
1784 if(false) {
1785 function in_if_false() { return true; } ok(false, "!?");
1786 }
1787
1788 ok(in_if_false(), "in_if_false failed");
1789
1790 (function() { newValue = 1; })();
1791 ok(newValue === 1, "newValue = " + newValue);
1792
1793 obj = {undefined: 3};
1794
1795 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1796 name_override_func = 3;
1797 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1798 function name_override_func() {};
1799 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1800
1801 tmp = (function() {
1802 var ret = false;
1803 with({ret: true})
1804 return ret;
1805 })();
1806 ok(tmp, "tmp = " + tmp);
1807
1808 tmp = (function() {
1809 for(var iter in [1,2,3,4]) {
1810 var ret = false;
1811 with({ret: true})
1812 return ret;
1813 }
1814 })();
1815 ok(tmp, "tmp = " + tmp);
1816
1817 (function() {
1818 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
1819 with(new Object()) {
1820 var x = false && function func() {};
1821 }
1822 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
1823 })();
1824
1825 (function() {
1826 ok(x === undefined, "x = " + x); // x is declared, but never initialized
1827 with({x: 1}) {
1828 ok(x === 1, "x = " + x);
1829 var x = 2;
1830 ok(x === 2, "x = " + x);
1831 }
1832 ok(x === undefined, "x = " + x);
1833 })();
1834
1835 var get, set;
1836
1837 /* NoNewline rule parser tests */
1838 while(true) {
1839 if(true) break
1840 tmp = false
1841 }
1842
1843 while(true) {
1844 if(true) break /*
1845 * no semicolon, but comment present */
1846 tmp = false
1847 }
1848
1849 while(true) {
1850 if(true) break // no semicolon, but comment present
1851 tmp = false
1852 }
1853
1854 while(true) {
1855 break
1856 continue
1857 tmp = false
1858 }
1859
1860 function returnTest() {
1861 return
1862 true;
1863 }
1864
1865 ok(returnTest() === undefined, "returnTest = " + returnTest());
1866
1867 ActiveXObject = 1;
1868 ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);
1869
1870 Boolean = 1;
1871 ok(Boolean === 1, "Boolean = " + Boolean);
1872
1873 Object = 1;
1874 ok(Object === 1, "Object = " + Object);
1875
1876 Array = 1;
1877 ok(Array === 1, "Array = " + Array);
1878
1879 Date = 1;
1880 ok(Date === 1, "Date = " + Date);
1881
1882 Error = 1;
1883 ok(Error === 1, "Error = " + Error);
1884
1885 /* Keep this test in the end of file */
1886 undefined = 6;
1887 ok(undefined === 6, "undefined = " + undefined);
1888
1889 NaN = 6;
1890 ok(NaN === 6, "NaN !== 6");
1891
1892 Infinity = 6;
1893 ok(Infinity === 6, "Infinity !== 6");
1894
1895 Math = 6;
1896 ok(Math === 6, "NaN !== 6");
1897
1898 reportSuccess();