[ADVAPI32_WINETEST] Revert service.c changes from 3c1b7834e1 to avoid testbot hangs...
[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 ok(!("0" in tmp), "0 found in array");
1175 ok(!("1" in tmp), "1 found in array");
1176 ok("2" in tmp, "2 not found in array");
1177 ok(!("2" in [1,,,,]), "2 found in [1,,,,]");
1178
1179 ok([1,].length === 2, "[1,].length !== 2");
1180 ok([,,].length === 3, "[,,].length !== 3");
1181 ok([,].length === 2, "[].length != 2");
1182 ok([].length === 0, "[].length != 0");
1183
1184 tmp = 0;
1185 while(tmp < 4) {
1186 ok(tmp < 4, "tmp >= 4");
1187 tmp++;
1188 }
1189 ok(tmp === 4, "tmp !== 4");
1190
1191 tmp = 0;
1192 while(true) {
1193 ok(tmp < 4, "tmp >= 4");
1194 tmp++;
1195 if(tmp === 4) {
1196 break;
1197 ok(false, "break did not break");
1198 }
1199 }
1200 ok(tmp === 4, "tmp !== 4");
1201
1202 tmp = 0;
1203 do {
1204 ok(tmp < 4, "tmp >= 4");
1205 tmp++;
1206 } while(tmp < 4);
1207 ok(tmp === 4, "tmp !== 4");
1208
1209 tmp = 0;
1210 do {
1211 ok(tmp === 0, "tmp !=== 0");
1212 tmp++;
1213 } while(false);
1214 ok(tmp === 1, "tmp !== 1");
1215
1216 tmp = 0;
1217 do {
1218 ok(tmp < 4, "tmp >= 4");
1219 tmp++;
1220 } while(tmp < 4)
1221 ok(tmp === 4, "tmp !== 4")
1222
1223 tmp = 0;
1224 while(tmp < 4) {
1225 tmp++;
1226 if(tmp === 2) {
1227 continue;
1228 ok(false, "break did not break");
1229 }
1230 ok(tmp <= 4 && tmp != 2, "tmp = " + tmp);
1231 }
1232 ok(tmp === 4, "tmp !== 4");
1233
1234 for(tmp=0; tmp < 4; tmp++)
1235 ok(tmp < 4, "tmp = " + tmp);
1236 ok(tmp === 4, "tmp !== 4");
1237
1238 for(tmp=0; tmp < 4; tmp++) {
1239 if(tmp === 2)
1240 break;
1241 ok(tmp < 2, "tmp = " + tmp);
1242 }
1243 ok(tmp === 2, "tmp !== 2");
1244
1245 for(tmp=0; tmp < 4; tmp++) {
1246 if(tmp === 2)
1247 continue;
1248 ok(tmp < 4 && tmp != 2, "tmp = " + tmp);
1249 }
1250 ok(tmp === 4, "tmp !== 4");
1251
1252 for(var fi=0; fi < 4; fi++)
1253 ok(fi < 4, "fi = " + fi);
1254 ok(fi === 4, "fi !== 4");
1255
1256 tmp = true;
1257 obj1 = new Object();
1258 for(obj1.nonexistent; tmp; tmp = false)
1259 ok(!("nonexistent" in obj1), "nonexistent added to obj1");
1260
1261 obj1 = new Object();
1262 for(tmp in obj1.nonexistent)
1263 ok(false, "for(tmp in obj1.nonexistent) called with tmp = " + tmp);
1264 ok(!("nonexistent" in obj1), "nonexistent added to obj1 by for..in loop");
1265
1266
1267 var i, j;
1268
1269 /* Previous versions have broken finally block implementation */
1270 if(ScriptEngineMinorVersion() >= 8) {
1271 tmp = "";
1272 i = 0;
1273 while(true) {
1274 tmp += "1";
1275 for(i = 1; i < 3; i++) {
1276 switch(i) {
1277 case 1:
1278 tmp += "2";
1279 continue;
1280 case 2:
1281 tmp += "3";
1282 try {
1283 throw null;
1284 }finally {
1285 tmp += "4";
1286 break;
1287 }
1288 default:
1289 ok(false, "unexpected state");
1290 }
1291 tmp += "5";
1292 }
1293 with({prop: "6"}) {
1294 tmp += prop;
1295 break;
1296 }
1297 }
1298 ok(tmp === "123456", "tmp = " + tmp);
1299 }
1300
1301 tmp = "";
1302 i = 0;
1303 for(j in [1,2,3]) {
1304 tmp += "1";
1305 for(;;) {
1306 with({prop: "2"}) {
1307 tmp += prop;
1308 try {
1309 throw "3";
1310 }catch(e) {
1311 tmp += e;
1312 with([0])
1313 break;
1314 }
1315 }
1316 ok(false, "unexpected state");
1317 }
1318 while(true) {
1319 tmp += "4";
1320 break;
1321 }
1322 break;
1323 }
1324 ok(tmp === "1234", "tmp = " + tmp);
1325
1326 tmp = 0;
1327 for(var iter in [1,2,3]) {
1328 tmp += +iter;
1329 continue;
1330 }
1331 ok(tmp === 3, "tmp = " + tmp);
1332
1333 tmp = false;
1334 for(var iter in [1,2,3]) {
1335 switch(+iter) {
1336 case 1:
1337 tmp = true;
1338 try {
1339 continue;
1340 }finally {}
1341 default:
1342 continue;
1343 }
1344 }
1345 ok(tmp, "tmp = " + tmp);
1346
1347 loop_label:
1348 while(true) {
1349 while(true)
1350 break loop_label;
1351 }
1352
1353 loop_label: {
1354 tmp = 0;
1355 while(true) {
1356 while(true)
1357 break loop_label;
1358 }
1359 ok(false, "unexpected evaluation 1");
1360 }
1361
1362 while(true) {
1363 some_label: break;
1364 ok(false, "unexpected evaluation 2");
1365 }
1366
1367 just_label: tmp = 1;
1368 ok(tmp === 1, "tmp != 1");
1369
1370 some_label: break some_label;
1371
1372 other_label: {
1373 break other_label;
1374 ok(false, "unexpected evaluation 3");
1375 }
1376
1377 loop_label:
1378 do {
1379 while(true)
1380 continue loop_label;
1381 }while(false);
1382
1383 loop_label:
1384 for(i = 0; i < 3; i++) {
1385 while(true)
1386 continue loop_label;
1387 }
1388
1389 loop_label:
1390 other_label:
1391 for(i = 0; i < 3; i++) {
1392 while(true)
1393 continue loop_label;
1394 }
1395
1396 loop_label:
1397 for(tmp in {prop: false}) {
1398 while(true)
1399 continue loop_label;
1400 }
1401
1402 ok((void 1) === undefined, "(void 1) !== undefined");
1403
1404 var inobj = new Object();
1405
1406 for(var iter in inobj)
1407 ok(false, "unexpected iter = " + iter);
1408
1409 inobj.test = true;
1410 tmp = 0;
1411 for(iter in inobj) {
1412 ok(iter == "test", "unexpected iter = " + iter);
1413 tmp++;
1414 }
1415 ok(tmp === 1, "for..in tmp = " + tmp);
1416
1417 function forinTestObj() {}
1418
1419 forinTestObj.prototype.test3 = true;
1420
1421 var arr = new Array();
1422 inobj = new forinTestObj();
1423 inobj.test1 = true;
1424 inobj.test2 = true;
1425
1426 tmp = 0;
1427 for(iter in inobj) {
1428 arr[iter] = true;
1429 tmp++;
1430 }
1431
1432 ok(tmp === 3, "for..in tmp = " + tmp);
1433 ok(arr["test1"] === true, "arr[test1] !== true");
1434 ok(arr["test2"] === true, "arr[test2] !== true");
1435 ok(arr["test3"] === true, "arr[test3] !== true");
1436
1437 tmp = new Object();
1438 tmp.test = false;
1439 ok((delete tmp.test) === true, "delete returned false");
1440 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1441 ok(!("test" in tmp), "test is still in tmp after delete?");
1442 for(iter in tmp)
1443 ok(false, "tmp has prop " + iter);
1444 ok((delete tmp.test) === true, "deleting test didn't return true");
1445 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't return true");
1446 ok((delete nonexistent) === true, "deleting nonexistent didn't return true");
1447
1448 tmp = new Object();
1449 tmp.test = false;
1450 ok((delete tmp["test"]) === true, "delete returned false");
1451 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1452 ok(!("test" in tmp), "test is still in tmp after delete?");
1453
1454 tmp.testWith = true;
1455 with(tmp)
1456 ok(testWith === true, "testWith !== true");
1457
1458 if(false) {
1459 var varTest1 = true;
1460 }
1461
1462 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1463 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1464
1465 var varTest2;
1466
1467 function varTestFunc(varTest3) {
1468 var varTest3;
1469
1470 ok(varTest3 === 3, "varTest3 = " + varTest3);
1471 ok(varTest4 === undefined, "varTest4 = " + varTest4);
1472
1473 var varTest4;
1474 }
1475
1476 varTestFunc(3);
1477
1478 deleteTest = 1;
1479 delete deleteTest;
1480 try {
1481 tmp = deleteTest;
1482 ok(false, "deleteTest not throwed exception?");
1483 }catch(ex) {}
1484
1485 (function() {
1486 var to_delete = 2;
1487 var r = delete to_delete;
1488 ok(r === false, "delete 1 returned " + r);
1489 if(r)
1490 return;
1491 ok(to_delete === 2, "to_delete = " + to_delete);
1492
1493 to_delete = new Object();
1494 r = delete to_delete;
1495 ok(r === false, "delete 2 returned " + r);
1496 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1497 })();
1498
1499 (function(to_delete) {
1500 var r = delete to_delete;
1501 ok(r === false, "delete 3 returned " + r);
1502 ok(to_delete === 2, "to_delete = " + to_delete);
1503
1504 to_delete = new Object();
1505 r = delete to_delete;
1506 ok(r === false, "delete 4 returned " + r);
1507 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1508 })(2);
1509
1510 (function() {
1511 with({to_delete: new Object()}) {
1512 var r = delete to_delete;
1513 ok(r === true, "delete returned " + r);
1514 }
1515 })();
1516
1517 if (false)
1518 if (true)
1519 ok(false, "if evaluated");
1520 else
1521 ok(false, "else should be associated with nearest if statement");
1522
1523 if (true)
1524 if (false)
1525 ok(false, "if evaluated");
1526 else
1527 ok(true, "else should be associated with nearest if statement");
1528
1529 function instanceOfTest() {}
1530 tmp = new instanceOfTest();
1531
1532 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1533 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1534 ok((tmp instanceof String) === false, "tmp is instance of String");
1535
1536 instanceOfTest.prototype = new Object();
1537 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1538 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1539
1540 ok((1 instanceof Object) === false, "1 is instance of Object");
1541 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1542 ok(("" instanceof Object) === false, "'' is instance of Object");
1543
1544 (function () {
1545 ok((arguments instanceof Object) === true, "argument is not instance of Object");
1546 ok((arguments instanceof Array) === false, "argument is not instance of Array");
1547 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1548 })(1,2);
1549
1550 obj = new String();
1551 ok(("length" in obj) === true, "length is not in obj");
1552 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1553 ok(("abc" in obj) === false, "test is in obj");
1554 obj.abc = 1;
1555 ok(("abc" in obj) === true, "test is not in obj");
1556 ok(("1" in obj) === false, "1 is in obj");
1557
1558 obj = [1,2,3];
1559 ok((1 in obj) === true, "1 is not in obj");
1560
1561 obj = new Object();
1562 try {
1563 obj.prop["test"];
1564 ok(false, "expected exception");
1565 }catch(e) {}
1566 ok(!("prop" in obj), "prop in obj");
1567
1568 if(invokeVersion >= 2) {
1569 ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1570 ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1571
1572 tmp = "test";
1573 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1574 tmp[1] = "x";
1575 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1576 ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1577 ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1578 }else {
1579 ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1580 }
1581
1582 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1583 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1584 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1585 ok(isNaN() === true, "isNaN() !== true");
1586 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1587 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1588 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1589
1590 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1591 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1592 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1593 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1594 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1595 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1596 ok(isFinite() === false, "isFinite() !== false");
1597
1598 ok((1 < NaN) === false, "(1 < NaN) !== false");
1599 ok((1 > NaN) === false, "(1 > NaN) !== false");
1600 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1601 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1602 ok((NaN < 1) === false, "(NaN < 1) !== false");
1603 ok((NaN > 1) === false, "(NaN > 1) !== false");
1604 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1605 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1606 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1607 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1608 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1609
1610 ok(isNaN(+"test") === true, "isNaN(+'test') !== true");
1611 ok(isNaN(+"123t") === true, "isNaN(+'123t') !== true");
1612 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x') !== true");
1613 ok(+"Infinity" === Infinity, "+'Infinity' !== Infinity");
1614 ok(+" Infinity " === Infinity, "+' Infinity ' !== Infinity");
1615 ok(+"-Infinity" === -Infinity, "+'-Infinity' !== -Infinity");
1616
1617 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1618 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1619 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1620 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1621 ok((0 === NaN) === false, "(0 === NaN) !== false");
1622
1623 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1624 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1625 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1626 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1627 ok((0 == NaN) === false, "(0 === NaN) != false");
1628
1629 // escape tests
1630 var escapeTests = [
1631 ["\'", "\\'", 39],
1632 ["\"", "\\\"", 34],
1633 ["\\", "\\\\", 92],
1634 ["\b", "\\b", 8],
1635 ["\t", "\\t", 9],
1636 ["\n", "\\n", 10],
1637 ["\v", "\\v", 118],
1638 ["\f", "\\f", 12],
1639 ["\r", "\\r", 13],
1640 ["\xf3", "\\xf3", 0xf3],
1641 ["\u1234", "\\u1234", 0x1234],
1642 ["\a", "\\a", 97],
1643 ["\?", "\\?", 63]
1644 ];
1645
1646 for(i=0; i<escapeTests.length; i++) {
1647 tmp = escapeTests[i][0].charCodeAt(0);
1648 ok(tmp === escapeTests[i][2], "escaped '" + escapeTests[i][1] + "' = " + tmp + " expected " + escapeTests[i][2]);
1649 }
1650
1651 tmp = !+"\v1";
1652 ok(tmp === true, '!+"\v1" = ' + tmp);
1653
1654 ok(typeof(testFunc2) === "function", "typeof(testFunc2) = " + typeof(testFunc2));
1655 tmp = testFunc2(1);
1656 ok(tmp === 2, "testFunc2(1) = " + tmp);
1657 function testFunc2(x) { return x+1; }
1658
1659 ok(typeof(testFunc3) === "function", "typeof(testFunc3) = " + typeof(testFunc3));
1660 tmp = testFunc3(1);
1661 ok(tmp === 3, "testFunc3(1) = " + tmp);
1662 tmp = function testFunc3(x) { return x+2; };
1663
1664 tmp = testFunc4(1);
1665 ok(tmp === 5, "testFunc4(1) = " + tmp);
1666 tmp = function testFunc4(x) { return x+3; };
1667 tmp = testFunc4(1);
1668 testFunc4 = 1;
1669 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1670 ok(tmp === 5, "testFunc4(1) = " + tmp);
1671 tmp = function testFunc4(x) { return x+4; };
1672 ok(testFunc4 === 1, "testFunc4 = " + testFunc4);
1673
1674 function testEmbeddedFunctions() {
1675 ok(typeof(testFunc5) === "function", "typeof(testFunc5) = " + typeof(testFunc5));
1676 tmp = testFunc5(1);
1677 ok(tmp === 3, "testFunc5(1) = " + tmp);
1678 tmp = function testFunc5(x) { return x+2; };
1679
1680 tmp = testFunc6(1);
1681 ok(tmp === 5, "testFunc6(1) = " + tmp);
1682 tmp = function testFunc6(x) { return x+3; };
1683 tmp = testFunc6(1);
1684 ok(tmp === 5, "testFunc6(1) = " + tmp);
1685 tmp = function testFunc6(x) { return x+4; };
1686 testFunc6 = 1;
1687 ok(testFunc6 === 1, "testFunc4 = " + testFunc6);
1688 }
1689
1690 testEmbeddedFunctions();
1691
1692 date = new Date();
1693 date.toString = function() { return "toString"; }
1694 ok(""+date === "toString", "''+date = " + date);
1695 date.toString = function() { return this; }
1696 ok(""+date === ""+date.valueOf(), "''+date = " + date);
1697
1698 str = new String("test");
1699 str.valueOf = function() { return "valueOf"; }
1700 ok(""+str === "valueOf", "''+str = " + str);
1701 str.valueOf = function() { return new Date(); }
1702 ok(""+str === "test", "''+str = " + str);
1703
1704 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1705
1706 var re = /=(\?|%3F)/g;
1707 ok(re.source === "=(\\?|%3F)", "re.source = " + re.source);
1708
1709 tmp = new Array();
1710 for(var i=0; i<2; i++)
1711 tmp[i] = /b/;
1712 ok(tmp[0] != tmp[1], "tmp[0] == tmp [1]");
1713
1714 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed\n");
1715 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1716 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1717
1718 ok(getVT(nullDisp) === "VT_DISPATCH", "getVT(nullDisp) = " + getVT(nullDisp));
1719 ok(typeof(nullDisp) === "object", "typeof(nullDisp) = " + typeof(nullDisp));
1720 ok(nullDisp === nullDisp, "nullDisp !== nullDisp");
1721 ok(nullDisp !== re, "nullDisp === re");
1722 ok(nullDisp === null, "nullDisp === null");
1723 ok(nullDisp == null, "nullDisp == null");
1724 ok(getVT(true && nullDisp) === "VT_DISPATCH",
1725 "getVT(0 && nullDisp) = " + getVT(true && nullDisp));
1726 ok(!nullDisp === true, "!nullDisp = " + !nullDisp);
1727 ok(String(nullDisp) === "null", "String(nullDisp) = " + String(nullDisp));
1728 ok(nullDisp != new Object(), "nullDisp == new Object()");
1729 ok(new Object() != nullDisp, "new Object() == nullDisp");
1730 ok((typeof Object(nullDisp)) === "object", "typeof Object(nullDisp) !== 'object'");
1731 tmp = getVT(Object(nullDisp));
1732 ok(tmp === "VT_DISPATCH", "getVT(Object(nullDisp) = " + tmp);
1733 tmp = Object(nullDisp).toString();
1734 ok(tmp === "[object Object]", "Object(nullDisp).toString() = " + tmp);
1735
1736 function do_test() {}
1737 function nosemicolon() {} nosemicolon();
1738 function () {} nosemicolon();
1739
1740 if(false) {
1741 function in_if_false() { return true; } ok(false, "!?");
1742 }
1743
1744 ok(in_if_false(), "in_if_false failed");
1745
1746 (function() { newValue = 1; })();
1747 ok(newValue === 1, "newValue = " + newValue);
1748
1749 obj = {undefined: 3};
1750
1751 ok(typeof(name_override_func) === "function", "typeof(name_override_func) = " + typeof(name_override_func));
1752 name_override_func = 3;
1753 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1754 function name_override_func() {};
1755 ok(name_override_func === 3, "name_override_func = " + name_override_func);
1756
1757 tmp = (function() {
1758 var ret = false;
1759 with({ret: true})
1760 return ret;
1761 })();
1762 ok(tmp, "tmp = " + tmp);
1763
1764 tmp = (function() {
1765 for(var iter in [1,2,3,4]) {
1766 var ret = false;
1767 with({ret: true})
1768 return ret;
1769 }
1770 })();
1771 ok(tmp, "tmp = " + tmp);
1772
1773 (function() {
1774 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
1775 with(new Object()) {
1776 var x = false && function func() {};
1777 }
1778 ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
1779 })();
1780
1781 (function() {
1782 ok(x === undefined, "x = " + x); // x is declared, but never initialized
1783 with({x: 1}) {
1784 ok(x === 1, "x = " + x);
1785 var x = 2;
1786 ok(x === 2, "x = " + x);
1787 }
1788 ok(x === undefined, "x = " + x);
1789 })();
1790
1791 /* NoNewline rule parser tests */
1792 while(true) {
1793 if(true) break
1794 tmp = false
1795 }
1796
1797 while(true) {
1798 if(true) break /*
1799 * no semicolon, but comment present */
1800 tmp = false
1801 }
1802
1803 while(true) {
1804 if(true) break // no semicolon, but comment present
1805 tmp = false
1806 }
1807
1808 while(true) {
1809 break
1810 continue
1811 tmp = false
1812 }
1813
1814 function returnTest() {
1815 return
1816 true;
1817 }
1818
1819 ok(returnTest() === undefined, "returnTest = " + returnTest());
1820
1821 ActiveXObject = 1;
1822 ok(ActiveXObject === 1, "ActiveXObject = " + ActiveXObject);
1823
1824 Boolean = 1;
1825 ok(Boolean === 1, "Boolean = " + Boolean);
1826
1827 Object = 1;
1828 ok(Object === 1, "Object = " + Object);
1829
1830 Array = 1;
1831 ok(Array === 1, "Array = " + Array);
1832
1833 Date = 1;
1834 ok(Date === 1, "Date = " + Date);
1835
1836 Error = 1;
1837 ok(Error === 1, "Error = " + Error);
1838
1839 /* Keep this test in the end of file */
1840 undefined = 6;
1841 ok(undefined === 6, "undefined = " + undefined);
1842
1843 NaN = 6;
1844 ok(NaN === 6, "NaN !== 6");
1845
1846 Infinity = 6;
1847 ok(Infinity === 6, "Infinity !== 6");
1848
1849 Math = 6;
1850 ok(Math === 6, "NaN !== 6");
1851
1852 reportSuccess();