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