2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 ok(true, "true is not true?");
22 ok(!false, "!false is not true");
23 ok(!undefined, "!undefined is not true");
24 ok(!null, "!null is not true");
25 ok(!0, "!0 is not true");
26 ok(!0.0, "!0.0 is not true");
28 ok(1 === 1, "1 === 1 is false");
29 ok(!(1 === 2), "!(1 === 2) is false");
30 ok(1.0 === 1, "1.0 === 1 is false");
31 ok("abc" === "abc", "\"abc\" === \"abc\" is false");
32 ok(true === true, "true === true is false");
33 ok(null === null, "null === null is false");
34 ok(undefined === undefined, "undefined === undefined is false");
35 ok(!(undefined === null), "!(undefined === null) is false");
36 ok(1E0
=== 1, "1E0 === 1 is false");
37 ok(1000000*1000000 === 1000000000000, "1000000*1000000 === 1000000000000 is false");
38 ok(8.64e15
=== 8640000000000000, "8.64e15 !== 8640000000000000");
39 ok(1e2147483648
=== Infinity
, "1e2147483648 !== Infinity");
41 ok(00 === 0, "00 != 0");
42 ok(010 === 8, "010 != 8");
43 ok(077 === 63, "077 != 63");
44 ok(080 === 80, "080 != 80");
45 ok(090 === 90, "090 != 90");
46 ok(018 === 18, "018 != 18");
47 tmp
= 07777777777777777777777;
48 ok(typeof(tmp
) === "number" && tmp
> 0xffffffff, "tmp = " + tmp
);
49 tmp
= 07777777779777777777777;
50 ok(typeof(tmp
) === "number" && tmp
> 0xffffffff, "tmp = " + tmp
);
51 ok(0xffffffff === 4294967295, "0xffffffff = " + 0xffffffff);
52 tmp
= 0x10000000000000000000000000000000000000000000000000000000000000000;
53 ok(tmp
=== Math
.pow(2, 256), "0x1000...00 != 2^256");
55 ok(1 !== 2, "1 !== 2 is false");
56 ok(null !== undefined, "null !== undefined is false");
58 ok(1 == 1, "1 == 1 is false");
59 ok(!(1 == 2), "!(1 == 2) is false");
60 ok(1.0 == 1, "1.0 == 1 is false");
61 ok("abc" == "abc", "\"abc\" == \"abc\" is false");
62 ok(true == true, "true == true is false");
63 ok(null == null, "null == null is false");
64 ok(undefined == undefined, "undefined == undefined is false");
65 ok(undefined == null, "undefined == null is false");
66 ok(true == 1, "true == 1 is false");
67 ok(!(true == 2), "true == 2");
68 ok(0 == false, "0 == false is false");
70 ok(1 != 2, "1 != 2 is false");
71 ok(false != 1, "false != 1 is false");
73 ok(this === test
, "this !== test");
74 eval('ok(this === test, "this !== test");');
77 ok(trueVar
, "trueVar is not true");
79 ok(ScriptEngine
.length
=== 0, "ScriptEngine.length is not 0");
81 function testFunc1(x
, y
) {
82 ok(this !== undefined, "this is undefined");
83 ok(x
=== true, "x is not true");
84 ok(y
=== "test", "y is not \"test\"");
85 ok(arguments
.length
=== 2, "arguments.length is not 2");
86 ok(arguments
["0"] === true, "arguments[0] is not true");
87 ok(arguments
["1"] === "test", "arguments[1] is not \"test\"");
88 ok(arguments
.callee
=== testFunc1
, "arguments.calee !== testFunc1");
89 ok(testFunc1
.arguments
=== arguments
, "testFunc1.arguments = " + testFunc1
.arguments
);
92 ok(arguments
[0] === false, "arguments[0] is not false");
94 ok(y
=== "x", "y = " + y
);
95 ok(arguments
[1] === "x", "arguments[1] = " + arguments
[1]);
97 ok(arguments
["0x0"] === undefined, "arguments['0x0'] = " + arguments
["0x0"]);
98 ok(arguments
["x"] === undefined, "arguments['x'] = " + arguments
["x"]);
100 ok(this === test
, "this !== test");
101 eval('ok(this === test, "this !== test");');
103 tmp
= delete arguments
;
104 ok(tmp
=== false, "arguments deleted");
105 ok(typeof(arguments
) === "object", "typeof(arguments) = " + typeof(arguments
));
108 ok(x
=== 2, "x = " + x
);
109 ok(arguments
[0] === 2, "arguments[0] = " + arguments
[0]);
114 ok(testFunc1
.length
=== 2, "testFunc1.length is not 2");
115 ok(testFunc1
.arguments
=== null, "testFunc1.arguments = " + testFunc1
.arguments
);
117 ok(Object
.prototype !== undefined, "Object.prototype is undefined");
118 ok(Object
.prototype.prototype === undefined, "Object.prototype is not undefined");
119 ok(String
.prototype !== undefined, "String.prototype is undefined");
120 ok(Array
.prototype !== undefined, "Array.prototype is undefined");
121 ok(Boolean
.prototype !== undefined, "Boolean.prototype is undefined");
122 ok(Number
.prototype !== undefined, "Number.prototype is undefined");
123 ok(RegExp
.prototype !== undefined, "RegExp.prototype is undefined");
124 ok(Math
!== undefined, "Math is undefined");
125 ok(Math
.prototype === undefined, "Math.prototype is not undefined");
126 ok(Function
.prototype !== undefined, "Function.prototype is undefined");
127 ok(Function
.prototype.prototype === undefined, "Function.prototype.prototype is not undefined");
128 ok(Date
.prototype !== undefined, "Date.prototype is undefined");
129 ok(Date
.prototype.prototype === undefined, "Date.prototype is not undefined");
131 function testConstructor(constr
, name
, inst
) {
132 ok(constr
.prototype.constructor === constr
, name
+ ".prototype.constructor !== " + name
);
133 ok(constr
.prototype.hasOwnProperty("constructor"), name
+ ".prototype.hasOwnProperty('constructor')");
138 ok(inst
.constructor === constr
, "(new " + name
+ "()).constructor !== " + name
);
139 ok(!inst
.hasOwnProperty("constructor"), "(new " + name
+ "()).hasOwnProperty('constructor')");
142 testConstructor(Object
, "Object");
143 testConstructor(String
, "String");
144 testConstructor(Array
, "Array");
145 testConstructor(Boolean
, "Boolean");
146 testConstructor(Number
, "Number");
147 testConstructor(RegExp
, "RegExp", /x
/);
148 testConstructor(Function
, "Function");
149 testConstructor(Date
, "Date");
150 testConstructor(VBArray
, "VBArray", new VBArray(createArray()));
151 testConstructor(Error
, "Error");
152 testConstructor(EvalError
, "EvalError");
153 testConstructor(RangeError
, "RangeError");
154 testConstructor(ReferenceError
, "ReferenceError");
155 testConstructor(RegExpError
, "RegExpError");
156 testConstructor(SyntaxError
, "SyntaxError");
157 testConstructor(TypeError
, "TypeError");
158 testConstructor(URIError
, "URIError");
160 Function
.prototype.test
= true;
161 ok(testFunc1
.test
=== true, "testFunc1.test !== true");
162 ok(Function
.test
=== true, "Function.test !== true");
164 ok(typeof(0) === "number", "typeof(0) is not number");
165 ok(typeof(1.5) === "number", "typeof(1.5) is not number");
166 ok(typeof("abc") === "string", "typeof(\"abc\") is not string");
167 ok(typeof("") === "string", "typeof(\"\") is not string");
168 ok(typeof(true) === "boolean", "typeof(true) is not boolean");
169 ok(typeof(null) === "object", "typeof(null) is not object");
170 ok(typeof(undefined) === "undefined", "typeof(undefined) is not undefined");
171 ok(typeof(Math
) === "object", "typeof(Math) is not object");
172 ok(typeof(String
.prototype) === "object", "typeof(String.prototype) is not object");
173 ok(typeof(testFunc1
) === "function", "typeof(testFunc1) is not function");
174 ok(typeof(String
) === "function", "typeof(String) is not function");
175 ok(typeof(ScriptEngine
) === "function", "typeof(ScriptEngine) is not function");
176 ok(typeof(this) === "object", "typeof(this) is not object");
177 ok(typeof(doesnotexist
) === "undefined", "typeof(doesnotexist) = " + typeof(doesnotexist
));
178 tmp
= typeof((new Object()).doesnotexist
);
179 ok(tmp
=== "undefined", "typeof((new Object).doesnotexist = " + tmp
);
180 tmp
= typeof(testObj
.onlyDispID
);
181 ok(tmp
=== "unknown", "typeof(testObj.onlyDispID) = " + tmp
);
183 ok("\0\0x\0\0".length
=== 5, "\"\\0\\0x\\0\\0\".length = " + "\0\0x\0\0".length
);
184 ok("\0\0x\0\0" === String
.fromCharCode(0) + "\0x\0" + String
.fromCharCode(0), "\"\\0\\0x\\0\\0\" unexpected");
186 ok(testFunc1(true, "test") === true, "testFunc1 not returned true");
188 ok(testFunc1
.arguments
=== null, "testFunc1.arguments = " + testFunc1
.arguments
);
191 ok(tmp
=== 3, "tmp = " + tmp
);
193 function testRecFunc(x
) {
194 ok(testRecFunc
.arguments
=== arguments
, "testRecFunc.arguments = " + testRecFunc
.arguments
);
197 ok(testRecFunc
.arguments
=== arguments
, "testRecFunc.arguments = " + testRecFunc
.arguments
);
198 ok(testRecFunc
.arguments
[0] === true, "testRecFunc.arguments.x = " + testRecFunc
.arguments
[0]);
202 testRecFunc
.arguments
= 5;
203 ok(testRecFunc
.arguments
=== null, "testRecFunc.arguments = " + testRecFunc
.arguments
);
205 ok(testRecFunc
.arguments
=== null, "testRecFunc.arguments = " + testRecFunc
.arguments
);
207 function argumentsTest() {
208 var save
= arguments
;
209 with({arguments
: 1}) {
210 ok(arguments
=== 1, "arguments = " + arguments
);
212 ok(argumentsTest
.arguments
=== save
, "unexpected argumentsTest.arguments");
215 eval('ok(arguments === save, "unexpected arguments");');
216 [1,2].sort(function() {
217 ok(argumentsTest
.arguments
=== save
, "unexpected argumentsTest.arguments");
224 // arguments object detached from its execution context
226 var args
, get_x
, set_x
;
228 function test_args(detached
) {
229 ok(args
[0] === 1, "args[0] = " + args
[0]);
231 ok(args
[0] === (detached
? 1 : 2), "args[0] = " + args
[0] + " expected " + (detached
? 1 : 2));
233 ok(get_x() === (detached
? 2 : 3), "get_x() = " + get_x());
234 ok(args
[0] === 3, "args[0] = " + args
[0]);
239 get_x = function() { return x
; };
240 set_x = function(v
) { x
= v
; };
249 // arguments is a regular variable, it may be overwritten
251 ok(typeof(arguments
) === "object", "typeof(arguments) = " + typeof(arguments
));
253 ok(arguments
=== 1, "arguments = " + arguments
);
256 (function callAsExprTest() {
257 ok(callAsExprTest
.arguments
=== null, "callAsExprTest.arguments = " + callAsExprTest
.arguments
);
260 tmp
= (function() {1;})();
261 ok(tmp
=== undefined, "tmp = " + tmp
);
263 ok(tmp
=== 1, "tmp = " + tmp
);
265 ok(tmp
=== 2, "tmp = " + tmp
);
266 tmp
= eval("testNoRes(),2;");
267 ok(tmp
=== 2, "tmp = " + tmp
);
268 tmp
= eval("if(true) {3}");
269 ok(tmp
=== 3, "tmp = " + tmp
);
270 eval("testRes(); testRes()");
271 tmp
= eval("3; if(false) {4;} else {};;;")
272 ok(tmp
=== 3, "tmp = " + tmp
);
273 tmp
= eval("try { 1; } finally { 2; }")
274 ok(tmp
=== 2, "tmp = " + tmp
);
277 testRes() && testRes();
278 testNoRes(), testNoRes();
282 ok(x
=== 1, "x = " + x
);
288 ok(r
=== 1, "r = " + r
);
289 (function(x
, a
) { x(a
); })(eval
, "2");
294 ok(r
=== 1, "r = " + r
);
295 (function(x
, a
) { x(a
); })(eval
, "2");
298 tmp
= (function(){ return testNoRes(), testRes();})();
302 ok(funcexpr() == 2, "funcexpr() = " + funcexpr());
304 f1
= function funcexpr() { return 1; }
305 ok(f1
!= funcexpr
, "f1 == funcexpr");
306 ok(f1() === 1, "f1() = " + f1());
308 f2
= function funcexpr() { return 2; }
309 ok(f2
!= funcexpr
, "f2 != funcexpr");
310 ok(f2() === 2, "f2() = " + f2());
313 for(i
= 0; i
< 3; i
++) {
314 f2
= function funcexpr2() {};
315 ok(f1
!= f2
, "f1 == f2");
320 for(i
= 0; i
< 3; i
++) {
322 ok(f1
!= f2
, "f1 == f2");
327 ok(infuncexpr() == 2, "infuncexpr() = " + infuncexpr());
329 f1
= function infuncexpr() { return 1; }
330 ok(f1
!= funcexpr
, "f1 == funcexpr");
331 ok(f1() === 1, "f1() = " + f1());
333 f2
= function infuncexpr() { return 2; }
334 ok(f2
!= funcexpr
, "f2 != funcexpr");
335 ok(f2() === 2, "f2() = " + f2());
338 for(i
= 0; i
< 3; i
++) {
339 f2
= function infuncexpr2() {};
340 ok(f1
!= f2
, "f1 == f2");
345 for(i
= 0; i
< 3; i
++) {
347 ok(f1
!= f2
, "f1 == f2");
352 var obj1
= new Object();
353 ok(typeof(obj1
) === "object", "typeof(obj1) is not object");
354 ok(obj1
.constructor === Object
, "unexpected obj1.constructor");
356 obj1
.func = function () {
357 ok(this === obj1
, "this is not obj1");
358 ok(this.test
=== true, "this.test is not true");
359 ok(arguments
.length
=== 1, "arguments.length is not 1");
360 ok(arguments
["0"] === true, "arguments[0] is not true");
361 ok(typeof(arguments
.callee
) === "function", "typeof(arguments.calee) = " + typeof(arguments
.calee
));
366 ok(obj1
.func(true) === "test", "obj1.func(true) is not \"test\"");
368 function testConstr1() {
371 ok(this !== undefined, "this is undefined");
372 ok(arguments
.length
=== 1, "arguments.length is not 1");
373 ok(arguments
["0"] === true, "arguments[0] is not 1");
374 ok(arguments
.callee
=== testConstr1
, "arguments.calee !== testConstr1");
379 testConstr1
.prototype.pvar
= 1;
380 ok(testConstr1
.prototype.constructor === testConstr1
, "testConstr1.prototype.constructor !== testConstr1");
382 var obj2
= new testConstr1(true);
383 ok(typeof(obj2
) === "object", "typeof(obj2) is not object");
384 ok(obj2
.constructor === testConstr1
, "unexpected obj2.constructor");
385 ok(obj2
.pvar
=== 1, "obj2.pvar is not 1");
386 ok(!obj2
.hasOwnProperty('constructor'), "obj2.hasOwnProperty('constructor')");
388 testConstr1
.prototype.pvar
= 2;
389 ok(obj2
.pvar
=== 2, "obj2.pvar is not 2");
392 testConstr1
.prototype.pvar
= 1;
393 ok(obj2
.pvar
=== 3, "obj2.pvar is not 3");
396 function testConstr3() {
400 obj2
= new testConstr3();
401 ok(obj1
=== obj2
, "obj1 != obj2");
403 function testConstr4() {
407 obj2
= new testConstr3();
408 ok(typeof(obj2
) === "object", "typeof(obj2) = " + typeof(obj2
));
410 var obj3
= new Object
;
411 ok(typeof(obj3
) === "object", "typeof(obj3) is not object");
414 ok(typeof(func
) === "function", "typeof(func) = " + typeof(func
));
416 ok(typeof(func
) === "function", "typeof(func) = " + typeof(func
));
418 ok(typeof(func
) === "number", "typeof(func) = " + typeof(func
));
422 ok(typeof(f
) === "function", "typeof(f) = " + typeof(f
));
424 ok(typeof(f
) === "function", "typeof(f) = " + typeof(f
));
427 for(var iter
in "test")
428 ok(false, "unexpected forin call, test = " + iter
);
430 for(var iter
in null)
431 ok(false, "unexpected forin call, test = " + iter
);
433 for(var iter
in false)
434 ok(false, "unexpected forin call, test = " + iter
);
436 for(var iter
in pureDisp
)
437 ok(false, "unexpected forin call in pureDisp object");
440 ok(!tmp
.nonexistent
, "!tmp.nonexistent = " + !tmp
.nonexistent
);
441 ok(!("nonexistent" in tmp
), "nonexistent is in tmp after '!' expression")
444 ok((~tmp
.nonexistent
) === -1, "!tmp.nonexistent = " + ~tmp
.nonexistent
);
445 ok(!("nonexistent" in tmp
), "nonexistent is in tmp after '~' expression")
448 ok(isNaN(+tmp
.nonexistent
), "!tmp.nonexistent = " + (+tmp
.nonexistent
));
449 ok(!("nonexistent" in tmp
), "nonexistent is in tmp after '+' expression")
452 tmp
[tmp
.nonexistent
];
453 ok(!("nonexistent" in tmp
), "nonexistent is in tmp after array expression")
459 ok(false, "else evaluated");
460 ok(tmp
=== 1, "tmp !== 1, if not evaluated?");
464 ok(false, "if evaluated");
467 ok(tmp
=== 1, "tmp !== 1, if not evaluated?");
470 ok(false, "if(false) evaluated");
475 ok(tmp
=== 1, "tmp !== 1, if(true) not evaluated?");
481 var obj3
= { prop1
: 1, prop2
: typeof(false) };
482 ok(obj3
.prop1
=== 1, "obj3.prop1 is not 1");
483 ok(obj3
.prop2
=== "boolean", "obj3.prop2 is not \"boolean\"");
484 ok(obj3
.constructor === Object
, "unexpected obj3.constructor");
486 if(invokeVersion
>= 2) {
487 eval("tmp = {prop: 'value',}");
488 ok(tmp
.prop
=== "value", "tmp.prop = " + tmp
.prop
);
489 eval("tmp = {prop: 'value',second:2,}");
490 ok(tmp
.prop
=== "value", "tmp.prop = " + tmp
.prop
);
493 eval("tmp = {prop: 'value',}");
497 ok(tmp
=== true, "exception not fired");
504 ok(blockVar
=== 2, "blockVar !== 2");
506 ok((true ? 1 : 2) === 1, "conditional expression true is not 1");
507 ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2");
509 ok(getVT(undefined) === "VT_EMPTY", "getVT(undefined) is not VT_EMPTY");
510 ok(getVT(null) === "VT_NULL", "getVT(null) is not VT_NULL");
511 ok(getVT(0) === "VT_I4", "getVT(0) is not VT_I4");
512 ok(getVT(0.5) === "VT_R8", "getVT(0.5) is not VT_R8");
513 ok(getVT("test") === "VT_BSTR", "getVT(\"test\") is not VT_BSTR");
514 ok(getVT(Math
) === "VT_DISPATCH", "getVT(Math) is not VT_DISPATCH");
515 ok(getVT(false) === "VT_BOOL", "getVT(false) is not VT_BOOL");
518 ok(tmp
=== 4, "2+2 !== 4");
519 ok(getVT(tmp
) === "VT_I4", "getVT(2+2) !== VT_I4");
522 ok(tmp
=== 4.5, "2+2.5 !== 4.5");
523 ok(getVT(tmp
) === "VT_R8", "getVT(2+2.5) !== VT_R8");
526 ok(tmp
=== 4, "1.4+2.5 !== 4");
527 ok(getVT(tmp
) === "VT_I4", "getVT(1.5+2.5) !== VT_I4");
530 ok(tmp
=== 2, "4-2 !== 2");
531 ok(getVT(tmp
) === "VT_I4", "getVT(4-2) !== VT_I4");
534 ok(tmp
=== 2.5, "4.5-2 !== 2.5");
535 ok(getVT(tmp
) === "VT_R8", "getVT(4.5-2) !== VT_R8");
538 ok(tmp
=== 0-2, "-2 !== 0-2");
539 ok(getVT(tmp
) === "VT_I4", "getVT(-2) !== VT_I4");
542 ok(tmp
=== 6, "2*3 !== 6");
543 ok(getVT(tmp
) === "VT_I4", "getVT(2*3) !== VT_I4");
546 ok(tmp
=== 7, "2*3.5 !== 7");
547 ok(getVT(tmp
) === "VT_I4", "getVT(2*3.5) !== VT_I4");
550 /* FIXME: the parser loses precision */
551 /* ok(tmp === 8.75, "2.5*3.5 !== 8.75"); */
552 ok(tmp
> 8.749999 && tmp
< 8.750001, "2.5*3.5 !== 8.75");
553 ok(getVT(tmp
) === "VT_R8", "getVT(2.5*3.5) !== VT_R8");
556 ok(tmp
=== 1, "2*.5 !== 1");
557 ok(getVT(tmp
) == "VT_I4", "getVT(2*.5) !== VT_I4");
560 ok(tmp
=== 2, "4/2 !== 2");
561 ok(getVT(tmp
) === "VT_I4", "getVT(4/2) !== VT_I4");
564 ok(tmp
=== 3, "4.5/1.5 !== 3");
565 ok(getVT(tmp
) === "VT_I4", "getVT(4.5/1.5) !== VT_I4");
568 ok(tmp
=== 1.5, "3/2 !== 1.5");
569 ok(getVT(tmp
) === "VT_R8", "getVT(3/2) !== VT_R8");
572 ok(tmp
=== 1, "3%2 = " + tmp
);
575 ok(tmp
===0, "4%2 = " + tmp
);
578 ok(tmp
=== 0.5, "3.5%1.5 = " + tmp
);
581 ok(tmp
=== 0, "3%true = " + tmp
);
584 ok(tmp
=== "abcd", "\"ab\" + \"cd\" !== \"abcd\"");
587 ok((tmp
+= 1) === 2, "tmp += 1 !== 2");
588 ok(tmp
=== 2, "tmp !== 2");
591 ok((tmp
-= 1) === 1, "tmp -= 1 !== 1");
592 ok(tmp
=== 1, "tmp !=== 1");
595 ok((tmp
*= 1.5) === 3, "tmp *= 1.5 !== 3");
596 ok(tmp
=== 3, "tmp !=== 3");
599 ok((tmp
/= 2) === 2.5, "tmp /= 2 !== 2.5");
600 ok(tmp === 2.5, "tmp
!=== 2.5");
603 ok((tmp %= 2) === 1, "tmp
%= 2 !== 1");
604 ok(tmp === 1, "tmp
!== 1");
607 ok((tmp <<= 1) === 16, "tmp
<<= 1 !== 16");
610 ok((tmp >>= 1) === 4, "tmp
>>= 1 !== 4");
613 ok((tmp >>>= 1) === 4, "tmp
>>>= 1 !== 4");
615 tmp = 3 || ok(false, "second or expression called
");
616 ok(tmp === 3, "3 || (...) is not
3");
619 ok(tmp === 2, "false || 2 is not
2");
621 tmp = 0 && ok(false, "second and expression called
");
622 ok(tmp === 0, "0 && (...) is not
0");
624 tmp = true && "test
";
625 ok(tmp === "test
", "true && \"test
\" is not
\"test
\"");
628 ok(tmp === 0, "true && 0 is not
0");
631 ok(tmp === 7, "3 | 4 !== 7");
632 ok(getVT(tmp) === "VT_I4
", "getVT(3|4) = " + getVT(tmp));
635 ok(tmp === 3, "3.5 | 0 !== 3");
636 ok(getVT(tmp) === "VT_I4
", "getVT(3.5|0) = " + getVT(tmp));
639 ok(tmp === -3, "-3.5 | 0 !== -3");
640 ok(getVT(tmp) === "VT_I4
", "getVT(3.5|0) = " + getVT(tmp));
643 ok(tmp === 0, "0 | NaN
= " + tmp);
646 ok(tmp === 0, "0 | NaN
= " + tmp);
648 tmp = 0 | (-Infinity);
649 ok(tmp === 0, "0 | NaN
= " + tmp);
652 ok((tmp |= 0x10) === 26, "tmp(10) |= 0x10 !== 26");
653 ok(getVT(tmp) === "VT_I4
", "getVT(tmp
|= 10) = " + getVT(tmp));
655 tmp = (123 * Math.pow(2,32) + 2) | 0;
656 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
658 tmp = (-123 * Math.pow(2,32) + 2) | 0;
659 ok(tmp === 2, "123*2^32+2 | 0 = " + tmp);
662 ok(tmp === 1, "3 & 5 !== 1");
663 ok(getVT(tmp) === "VT_I4
", "getVT(3|5) = " + getVT(tmp));
666 ok(tmp === 3, "3.5 & 0xffff !== 3 ");
667 ok(getVT(tmp) === "VT_I4
", "getVT(3.5&0xffff) = " + getVT(tmp));
669 tmp = (-3.5) & 0xffffffff;
670 ok(tmp === -3, "-3.5 & 0xffff !== -3");
671 ok(getVT(tmp) === "VT_I4
", "getVT(3.5&0xffff) = " + getVT(tmp));
674 ok(tmp === 16, "2 << 3 = " + tmp);
677 ok(tmp === 16, "2 << 35 = " + tmp);
680 ok(tmp === 2, "8 >> 2 = " + tmp);
683 ok(tmp === -4, "-64 >> 4 = " + tmp);
686 ok(tmp === 2, "8 >> 2 = " + tmp);
689 ok(tmp === 0x0ffffffc, "-64 >>> 4 = " + tmp);
692 ok(tmp === 4, "4 >>> NaN
= " + tmp);
695 ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8");
696 ok(getVT(tmp) === "VT_I4
", "getVT(tmp
&= 8) = " + getVT(tmp));
699 ok(tmp === 0x0ff0, "0xf0f0^0xff00 !== 0x0ff0");
700 ok(getVT(tmp) === "VT_I4
", "getVT(0xf0f0^0xff00) = " + getVT(tmp));
703 ok((tmp ^= 3) === 6, "tmp(5) ^= 3 !== 6");
704 ok(getVT(tmp) === "VT_I4
", "getVT(tmp
^= 3) = " + getVT(tmp));
707 ok(tmp === -2, "~1 !== -2");
708 ok(getVT(tmp) === "VT_I4
", "getVT(~1) = " + getVT(tmp));
710 ok((3,4) === 4, "(3,4) !== 4");
712 ok(+3 === 3, "+3 !== 3");
713 ok(+true === 1, "+true !== 1");
714 ok(+false === 0, "+false !== 0");
715 ok(+null === 0, "+null !== 0");
716 ok(+"0" === 0, "+'0' !== 0");
717 ok(+"3" === 3, "+'3' !== 3");
718 ok(+"-3" === -3, "+'-3' !== -3");
719 ok(+"0xff" === 255, "+'0xff' !== 255");
720 ok(+"3e3
" === 3000, "+'3e3' !== 3000");
723 ok(+tmp === 1, "+(new Number(1)) = " + (+tmp));
724 ok(tmp.constructor === Number, "unexpected tmp
.constructor");
725 tmp = new String("1");
726 ok(+tmp === 1, "+(new String('1')) = " + (+tmp));
727 ok(tmp.constructor === String, "unexpected tmp
.constructor");
729 ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
730 ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
731 ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
732 ok("" + null === "null", "\"\" + null !== \"null\"");
733 ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
734 ok("" + true === "true", "\"\" + true !== \"true\"");
735 ok("" + false === "false", "\"\" + false !== \"false\"");
736 ok("" + 0.5 === "0.5", "'' + 0.5 = " + 0.5);
737 ok("" + (-0.5432) === "-0.5432", "'' + (-0.5432) = " + (-0.5432));
739 ok(1 < 3.4, "1 < 3.4 failed
");
740 ok(!(3.4 < 1), "3.4 < 1");
741 ok("abc
" < "abcd
", "abc
< abcd failed
");
742 ok("abcd
" < "abce
", "abce
< abce failed
");
743 ok("" < "x
", "\"\" < \"x
\" failed
");
744 ok(!(0 < 0), "0 < 0");
746 ok(1 <= 3.4, "1 <= 3.4 failed
");
747 ok(!(3.4 <= 1), "3.4 <= 1");
748 ok("abc
" <= "abcd
", "abc
<= abcd failed
");
749 ok("abcd
" <= "abce
", "abce
<= abce failed
");
750 ok("" <= "x
", "\"\" <= \"x
\" failed
");
751 ok(0 <= 0, "0 <= 0 failed
");
753 ok(3.4 > 1, "3.4 > 1 failed
");
754 ok(!(1 > 3.4), "1 > 3.4");
755 ok("abcd
" > "abc
", "abc
> abcd failed
");
756 ok("abce
" > "abcd
", "abce
> abce failed
");
757 ok("x
" > "", "\"x
\" > \"\" failed
");
758 ok(!(0 > 0), "0 > 0");
760 ok(3.4 >= 1, "3.4 >= 1 failed
");
761 ok(!(1 >= 3.4), "1 >= 3.4");
762 ok("abcd
" >= "abc
", "abc
>= abcd failed
");
763 ok("abce
" >= "abcd
", "abce
>= abce failed
");
764 ok("x
" >= "", "\"x
\" >= \"\" failed
");
765 ok(0 >= 0, "0 >= 0");
768 ok(++tmp === 2, "++tmp (1) is not
2");
769 ok(tmp === 2, "incremented tmp is not
2");
770 ok(--tmp === 1, "--tmp (2) is not
1");
771 ok(tmp === 1, "decremented tmp is not
1");
772 ok(tmp++ === 1, "tmp
++ (1) is not
1");
773 ok(tmp === 2, "incremented
tmp(1) is not
2");
774 ok(tmp-- === 2, "tmp
-- (2) is not
2");
775 ok(tmp === 1, "decremented tmp is not
1");
779 ok(isNaN(tmp.iii), "tmp
.iii
= " + tmp.iii);
781 String.prototype.test = true;
782 ok("".test === true, "\"\".test is not
true");
784 Boolean.prototype.test = true;
785 ok(true.test === true, "true.test is not
true");
787 Number.prototype.test = true;
788 ok((0).test === true, "(0).test is not
true");
789 ok((0.5).test === true, "(0.5).test is not
true");
793 ok(state === "", "try: state
= " + state);
796 ok(false, "unexpected
catch");
798 ok(state === "try", "state
= " + state + " expected
try");
802 ok(state === "", "try: state
= " + state);
805 ok(state === "try", "finally: state
= " + state);
808 ok(state === "finally", "state
= " + state + " expected
finally");
818 ok(state === "finally", "state
= " + state + " expected
finally");
821 ok(state === "catch", "state
= " + state + " expected
catch");
830 ok(e === 1, "e
= " + e);
835 ok(state === "", "try: state
= " + state);
838 ok(false, "unexpected
catch");
840 ok(state === "try", "finally: state
= " + state);
843 ok(state === "finally", "state
= " + state + " expected
finally");
847 ok(state === "", "try: state
= " + state);
851 ok(state === "try", "catch: state
= " + state);
852 ok(ex === "except
", "ex is not
\"except
\"");
855 ok(state === "catch", "state
= " + state + " expected
catch");
859 ok(state === "", "try: state
= " + state);
863 ok(state === "try", "catch: state
= " + state);
864 ok(ex === true, "ex is not
true");
867 ok(state === "catch", "finally: state
= " + state);
870 ok(state === "finally", "state
= " + state + " expected
finally");
874 ok(state === "", "try: state
= " + state);
876 try { throw true; } finally {}
878 ok(state === "try", "catch: state
= " + state);
879 ok(ex === true, "ex is not
true");
882 ok(state === "catch", "finally: state
= " + state);
885 ok(state === "finally", "state
= " + state + " expected
finally");
889 ok(state === "", "try: state
= " + state);
891 try { throw "except
"; } catch(ex) { throw true; }
893 ok(state === "try", "catch: state
= " + state);
894 ok(ex === true, "ex is not
true");
897 ok(state === "catch", "finally: state
= " + state);
900 ok(state === "finally", "state
= " + state + " expected
finally");
902 function throwFunc(x) {
908 ok(state === "", "try: state
= " + state);
912 ok(state === "try", "catch: state
= " + state);
913 ok(ex === true, "ex is not
true");
916 ok(state === "catch", "finally: state
= " + state);
919 ok(state === "finally", "state
= " + state + " expected
finally");
924 ok(false, "unexpected
case \"1\"");
926 ok(state === "", "case 1: state
= " + state);
929 ok(state === "1", "default: state
= " + state);
932 ok(state === "default", "case false: state
= " + state);
935 ok(state === "false", "state
= " + state);
941 ok(false, "unexpected
case 1");
943 ok(state === "", "default: state
= " + state);
946 ok(state === "default", "case false: state
= " + state);
949 ok(state === "false", "state
= " + state);
954 ok(false, "unexpected
case \"1\"");
956 ok(state === "", "case 1: state
= " + state);
959 ok(state === "1", "default: state
= " + state);
963 ok(false, "unexpected
case false");
965 ok(state === "default", "state
= " + state);
969 ok(false, "unexpected
case 2");
971 ok(false, "unexpected
case 3");
976 ok(false, "unexpected
case 2");
984 ok(false, "unexpected
default");
992 ok(false, "unexpected
default");
1013 function unreachable() {
1014 ok(false, "unreachable
");
1017 function expect(value, expect_value) {
1018 ok(value === expect_value, "got
" + value + " expected
" + expect_value);
1033 expect(ret, "finally");
1048 expect(ret, "try,");
1049 expect(x, "try,finally,");
1068 expect(ret, "finally");
1069 expect(x, "try,catch,finally,");
1086 expect(ret, "catch");
1087 expect(x, "try,catch,finally,");
1109 expect(ret, "try2
");
1110 expect(x, "try,try2
,finally2
,finally,");
1137 expect(x, "try,try2
,finally2
,finally,ret
");
1165 expect(x, "try,try2
,finally2
,finally,ret
");
1175 var tmp = (function() {
1176 var s = new String();
1190 ok(tmp === 1, "eval(\"1\") !== 1");
1191 eval("{ ok(tmp
=== 1, 'eval: tmp !== 1'); } tmp
= 2;");
1192 ok(tmp === 2, "tmp
!== 2");
1194 ok(eval(false) === false, "eval(false) !== false");
1195 ok(eval() === undefined, "eval() !== undefined");
1197 tmp = eval("1", "2");
1198 ok(tmp === 1, "eval(\"1\", \"2\") !== 1");
1202 ok(state === "", "try: state
= " + state);
1204 eval("throwFunc(true);");
1206 ok(state === "try", "catch: state
= " + state);
1207 ok(ex === true, "ex is not
true");
1210 ok(state === "catch", "finally: state
= " + state);
1213 ok(state === "finally", "state
= " + state + " expected
finally");
1215 tmp = [,,1,2,,,true];
1216 ok(tmp.length === 7, "tmp
.length
!== 7");
1217 ok(tmp["0"] === undefined, "tmp
[0] is not
undefined");
1218 ok(tmp["3"] === 2, "tmp
[3] !== 2");
1219 ok(tmp["6"] === true, "tmp
[6] !== true");
1220 ok(tmp[2] === 1, "tmp
[2] !== 1");
1221 ok(!("0" in tmp), "0 found
in array
");
1222 ok(!("1" in tmp), "1 found
in array
");
1223 ok("2" in tmp, "2 not found
in array
");
1224 ok(!("2" in [1,,,,]), "2 found
in [1,,,,]");
1226 ok([1,].length === 2, "[1,].length
!== 2");
1227 ok([,,].length === 3, "[,,].length
!== 3");
1228 ok([,].length === 2, "[].length
!= 2");
1229 ok([].length === 0, "[].length
!= 0");
1233 ok(tmp < 4, "tmp
>= 4");
1236 ok(tmp === 4, "tmp
!== 4");
1240 ok(tmp < 4, "tmp
>= 4");
1244 ok(false, "break did not
break");
1247 ok(tmp === 4, "tmp
!== 4");
1251 ok(tmp < 4, "tmp
>= 4");
1254 ok(tmp === 4, "tmp
!== 4");
1258 ok(tmp === 0, "tmp
!=== 0");
1261 ok(tmp === 1, "tmp
!== 1");
1265 ok(tmp < 4, "tmp
>= 4");
1268 ok(tmp === 4, "tmp
!== 4")
1275 ok(false, "break did not
break");
1277 ok(tmp <= 4 && tmp != 2, "tmp
= " + tmp);
1279 ok(tmp === 4, "tmp
!== 4");
1281 for(tmp=0; tmp < 4; tmp++)
1282 ok(tmp < 4, "tmp
= " + tmp);
1283 ok(tmp === 4, "tmp
!== 4");
1285 for(tmp=0; tmp < 4; tmp++) {
1288 ok(tmp < 2, "tmp
= " + tmp);
1290 ok(tmp === 2, "tmp
!== 2");
1292 for(tmp=0; tmp < 4; tmp++) {
1295 ok(tmp < 4 && tmp != 2, "tmp
= " + tmp);
1297 ok(tmp === 4, "tmp
!== 4");
1299 for(var fi=0; fi < 4; fi++)
1300 ok(fi < 4, "fi
= " + fi);
1301 ok(fi === 4, "fi
!== 4");
1304 obj1 = new Object();
1305 for(obj1.nonexistent; tmp; tmp = false)
1306 ok(!("nonexistent
" in obj1), "nonexistent added to obj1
");
1308 obj1 = new Object();
1309 for(tmp in obj1.nonexistent)
1310 ok(false, "for(tmp
in obj1
.nonexistent
) called
with tmp
= " + tmp);
1311 ok(!("nonexistent
" in obj1), "nonexistent added to obj1 by
for..in loop
");
1316 /* Previous versions have broken finally block implementation */
1317 if(ScriptEngineMinorVersion() >= 8) {
1322 for(i = 1; i < 3; i++) {
1336 ok(false, "unexpected state
");
1345 ok(tmp === "123456", "tmp
= " + tmp);
1363 ok(false, "unexpected state
");
1371 ok(tmp === "1234", "tmp
= " + tmp);
1374 for(var iter in [1,2,3]) {
1378 ok(tmp === 3, "tmp
= " + tmp);
1381 for(var iter in [1,2,3]) {
1392 ok(tmp, "tmp
= " + tmp);
1406 ok(false, "unexpected evaluation
1");
1411 ok(false, "unexpected evaluation
2");
1414 just_label: tmp = 1;
1415 ok(tmp === 1, "tmp
!= 1");
1417 some_label: break some_label;
1421 ok(false, "unexpected evaluation
3");
1427 continue loop_label;
1431 for(i = 0; i < 3; i++) {
1433 continue loop_label;
1438 for(i = 0; i < 3; i++) {
1440 continue loop_label;
1444 for(tmp in {prop: false}) {
1446 continue loop_label;
1449 ok((void 1) === undefined, "(void 1) !== undefined");
1451 var inobj = new Object();
1453 for(var iter in inobj)
1454 ok(false, "unexpected iter
= " + iter);
1458 for(iter in inobj) {
1459 ok(iter == "test
", "unexpected iter
= " + iter);
1462 ok(tmp === 1, "for..in tmp
= " + tmp);
1464 function forinTestObj() {}
1466 forinTestObj.prototype.test3 = true;
1468 var arr = new Array();
1469 inobj = new forinTestObj();
1474 for(iter in inobj) {
1479 ok(tmp === 3, "for..in tmp
= " + tmp);
1480 ok(arr["test1
"] === true, "arr
[test1
] !== true");
1481 ok(arr["test2
"] === true, "arr
[test2
] !== true");
1482 ok(arr["test3
"] === true, "arr
[test3
] !== true");
1486 ok((delete tmp.test) === true, "delete returned
false");
1487 ok(typeof(tmp.test) === "undefined", "tmp
.test type
= " + typeof(tmp.test));
1488 ok(!("test
" in tmp), "test is still
in tmp after
delete?");
1490 ok(false, "tmp has prop
" + iter);
1491 ok((delete tmp.test) === true, "deleting test didn
't return true");
1492 ok((delete tmp.nonexistent) === true, "deleting nonexistent didn't
return true");
1493 ok((delete nonexistent) === true, "deleting nonexistent didn
't return true");
1497 ok((delete tmp["test"]) === true, "delete returned false");
1498 ok(typeof(tmp.test) === "undefined", "tmp.test type = " + typeof(tmp.test));
1499 ok(!("test" in tmp), "test is still in tmp after delete?");
1501 tmp.testWith = true;
1503 ok(testWith === true, "testWith !== true");
1506 var varTest1 = true;
1509 ok(varTest1 === undefined, "varTest1 = " + varTest1);
1510 ok(varTest2 === undefined, "varTest2 = " + varTest1);
1514 function varTestFunc(varTest3) {
1517 ok(varTest3 === 3, "varTest3 = " + varTest3);
1518 ok(varTest4 === undefined, "varTest4 = " + varTest4);
1529 ok(false, "deleteTest did not throw an exception?");
1534 var r = delete to_delete;
1535 ok(r === false, "delete 1 returned " + r);
1538 ok(to_delete === 2, "to_delete = " + to_delete);
1540 to_delete = new Object();
1541 r = delete to_delete;
1542 ok(r === false, "delete 2 returned " + r);
1543 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1546 (function(to_delete) {
1547 var r = delete to_delete;
1548 ok(r === false, "delete 3 returned " + r);
1549 ok(to_delete === 2, "to_delete = " + to_delete);
1551 to_delete = new Object();
1552 r = delete to_delete;
1553 ok(r === false, "delete 4 returned " + r);
1554 ok(typeof(to_delete) === "object", "typeof(to_delete) = " + typeof(to_delete));
1558 with({to_delete: new Object()}) {
1559 var r = delete to_delete;
1560 ok(r === true, "delete returned " + r);
1566 ok(false, "if evaluated");
1568 ok(false, "else should be associated with nearest if statement");
1572 ok(false, "if evaluated");
1574 ok(true, "else should be associated with nearest if statement");
1576 function instanceOfTest() {}
1577 tmp = new instanceOfTest();
1579 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
1580 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1581 ok((tmp instanceof String) === false, "tmp is instance of String");
1583 instanceOfTest.prototype = new Object();
1584 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
1585 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
1587 ok((1 instanceof Object) === false, "1 is instance of Object");
1588 ok((false instanceof Boolean) === false, "false is instance of Boolean");
1589 ok(("" instanceof Object) === false, "'' is instance of Object");
1592 ok((arguments instanceof Object) === true, "argument is not instance of Object");
1593 ok((arguments instanceof Array) === false, "argument is not instance of Array");
1594 ok(arguments.toString() === "[object Object]", "arguments.toString() = " + arguments.toString());
1598 ok(("length" in obj) === true, "length is not in obj");
1599 ok(("isPrototypeOf" in obj) === true, "isPrototypeOf is not in obj");
1600 ok(("abc" in obj) === false, "test is in obj");
1602 ok(("abc" in obj) === true, "test is not in obj");
1603 ok(("1" in obj) === false, "1 is in obj");
1606 ok((1 in obj) === true, "1 is not in obj");
1611 ok(false, "expected exception");
1613 ok(!("prop" in obj), "prop in obj");
1615 if(invokeVersion >= 2) {
1616 ok("test"[0] === "t", '"test"[0] = ' + test[0]);
1617 ok("test"[5] === undefined, '"test"[0] = ' + test[0]);
1620 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1622 ok(tmp[1] === "e", "tmp[1] = " + tmp[1]);
1623 ok(tmp["1"] === "e", "tmp['1'] = " + tmp["1"]);
1624 ok(tmp["0x1"] === undefined, "tmp['0x1'] = " + tmp["0x1"]);
1626 ok("test"[0] === undefined, '"test"[0] = ' + test[0]);
1629 ok(isNaN(NaN) === true, "isNaN(NaN) !== true");
1630 ok(isNaN(0.5) === false, "isNaN(0.5) !== false");
1631 ok(isNaN(Infinity) === false, "isNaN(Infinity) !== false");
1632 ok(isNaN() === true, "isNaN() !== true");
1633 ok(isNaN(NaN, 0) === true, "isNaN(NaN, 0) !== true");
1634 ok(isNaN(0.5, NaN) === false, "isNaN(0.5, NaN) !== false");
1635 ok(isNaN(+undefined) === true, "isNaN(+undefined) !== true");
1637 ok(isFinite(0.5) === true, "isFinite(0.5) !== true");
1638 ok(isFinite(Infinity) === false, "isFinite(Infinity) !== false");
1639 ok(isFinite(-Infinity) === false, "isFinite(Infinity) !== false");
1640 ok(isFinite(NaN) === false, "isFinite(NaN) !== false");
1641 ok(isFinite(0.5, NaN) === true, "isFinite(0.5, NaN) !== true");
1642 ok(isFinite(NaN, 0.5) === false, "isFinite(NaN, 0.5) !== false");
1643 ok(isFinite() === false, "isFinite() !== false");
1645 ok((1 < NaN) === false, "(1 < NaN) !== false");
1646 ok((1 > NaN) === false, "(1 > NaN) !== false");
1647 ok((1 <= NaN) === false, "(1 <= NaN) !== false");
1648 ok((1 >= NaN) === false, "(1 >= NaN) !== false");
1649 ok((NaN < 1) === false, "(NaN < 1) !== false");
1650 ok((NaN > 1) === false, "(NaN > 1) !== false");
1651 ok((NaN <= 1) === false, "(NaN <= 1) !== false");
1652 ok((NaN >= 1) === false, "(NaN >= 1) !== false");
1653 ok((Infinity < 2) === false, "(Infinity < 2) !== false");
1654 ok((Infinity > 2) === true, "(Infinity > 2) !== true");
1655 ok((-Infinity < 2) === true, "(-Infinity < 2) !== true");
1657 ok(isNaN(+"test") === true, "isNaN(+'test
') !== true");
1658 ok(isNaN(+"123t") === true, "isNaN(+'123t
') !== true");
1659 ok(isNaN(+"Infinity x") === true, "isNaN(+'Infinity x
') !== true");
1660 ok(+"Infinity" === Infinity, "+'Infinity
' !== Infinity");
1661 ok(+" Infinity " === Infinity, "+' Infinity
' !== Infinity");
1662 ok(+"-Infinity" === -Infinity, "+'-Infinity
' !== -Infinity");
1664 ok((NaN !== NaN) === true, "(NaN !== NaN) !== true");
1665 ok((NaN === NaN) === false, "(NaN === NaN) !== false");
1666 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1667 ok((Infinity !== NaN) === true, "(Infinity !== NaN) !== true");
1668 ok((0 === NaN) === false, "(0 === NaN) !== false");
1670 ok((NaN != NaN) === true, "(NaN !== NaN) != true");
1671 ok((NaN == NaN) === false, "(NaN === NaN) != false");
1672 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1673 ok((Infinity != NaN) === true, "(Infinity != NaN) !== true");
1674 ok((0 == NaN) === false, "(0 === NaN) != false");
1687 ["\xf3", "\\xf3
", 0xf3],
1688 ["\u1234", "\\u1234
", 0x1234],
1693 for(i=0; i<escapeTests.length; i++) {
1694 tmp = escapeTests[i][0].charCodeAt(0);
1695 ok(tmp === escapeTests[i][2], "escaped
'" + escapeTests[i][1] + "' = " + tmp + " expected
" + escapeTests[i][2]);
1699 ok(tmp === true, '!+"\v1" = ' + tmp);
1701 ok(typeof(testFunc2) === "function", "typeof(testFunc2
) = " + typeof(testFunc2));
1703 ok(tmp === 2, "testFunc2(1) = " + tmp);
1704 function testFunc2(x) { return x+1; }
1706 ok(typeof(testFunc3) === "function", "typeof(testFunc3
) = " + typeof(testFunc3));
1708 ok(tmp === 3, "testFunc3(1) = " + tmp);
1709 tmp = function testFunc3(x) { return x+2; };
1712 ok(tmp === 5, "testFunc4(1) = " + tmp);
1713 tmp = function testFunc4(x) { return x+3; };
1716 ok(testFunc4 === 1, "testFunc4
= " + testFunc4);
1717 ok(tmp === 5, "testFunc4(1) = " + tmp);
1718 tmp = function testFunc4(x) { return x+4; };
1719 ok(testFunc4 === 1, "testFunc4
= " + testFunc4);
1721 function testEmbeddedFunctions() {
1722 ok(typeof(testFunc5) === "function", "typeof(testFunc5
) = " + typeof(testFunc5));
1724 ok(tmp === 3, "testFunc5(1) = " + tmp);
1725 tmp = function testFunc5(x) { return x+2; };
1728 ok(tmp === 5, "testFunc6(1) = " + tmp);
1729 tmp = function testFunc6(x) { return x+3; };
1731 ok(tmp === 5, "testFunc6(1) = " + tmp);
1732 tmp = function testFunc6(x) { return x+4; };
1734 ok(testFunc6 === 1, "testFunc4
= " + testFunc6);
1737 testEmbeddedFunctions();
1740 date.toString = function() { return "toString
"; }
1741 ok(""+date === "toString
", "''+date
= " + date);
1742 date.toString = function() { return this; }
1743 ok(""+date === ""+date.valueOf(), "''+date
= " + date);
1745 str = new String("test
");
1746 str.valueOf = function() { return "valueOf
"; }
1747 ok(""+str === "valueOf
", "''+str
= " + str);
1748 str.valueOf = function() { return new Date(); }
1749 ok(""+str === "test
", "''+str
= " + str);
1751 ok((function (){return 1;})() === 1, "(function (){return 1;})() = " + (function (){return 1;})());
1753 var re = /=(\?|%3F)/g;
1754 ok(re.source === "=(\\?|%3F
)", "re
.source
= " + re.source);
1757 for(var i=0; i<2; i++)
1759 ok(tmp[0] != tmp[1], "tmp
[0] == tmp
[1]");
1761 ok(isNullBSTR(getNullBSTR()), "isNullBSTR(getNullBSTR()) failed
\n");
1762 ok(getNullBSTR() === '', "getNullBSTR() !== ''");
1763 ok(+getNullBSTR() === 0 , "+getNullBTR() !=== 0");
1765 ok(getVT(nullDisp) === "VT_DISPATCH
", "getVT(nullDisp
) = " + getVT(nullDisp));
1766 ok(typeof(nullDisp) === "object
", "typeof(nullDisp
) = " + typeof(nullDisp));
1767 ok(nullDisp === nullDisp, "nullDisp
!== nullDisp
");
1768 ok(nullDisp !== re, "nullDisp
=== re
");
1769 ok(nullDisp === null, "nullDisp
=== null");
1770 ok(nullDisp == null, "nullDisp
== null");
1771 ok(getVT(true && nullDisp) === "VT_DISPATCH
",
1772 "getVT(0 && nullDisp
) = " + getVT(true && nullDisp));
1773 ok(!nullDisp === true, "!nullDisp
= " + !nullDisp);
1774 ok(String(nullDisp) === "null", "String(nullDisp
) = " + String(nullDisp));
1775 ok(nullDisp != new Object(), "nullDisp
== new Object()");
1776 ok(new Object() != nullDisp, "new Object() == nullDisp
");
1777 ok((typeof Object(nullDisp)) === "object
", "typeof Object(nullDisp
) !== 'object'");
1778 tmp = getVT(Object(nullDisp));
1779 ok(tmp === "VT_DISPATCH
", "getVT(Object(nullDisp
) = " + tmp);
1780 tmp = Object(nullDisp).toString();
1781 ok(tmp === "[object Object
]", "Object(nullDisp
).toString() = " + tmp);
1783 function do_test() {}
1784 function nosemicolon() {} nosemicolon();
1785 function () {} nosemicolon();
1788 function in_if_false() { return true; } ok(false, "!?");
1791 ok(in_if_false(), "in_if_false failed
");
1793 (function() { newValue = 1; })();
1794 ok(newValue === 1, "newValue
= " + newValue);
1796 obj = {undefined: 3};
1798 ok(typeof(name_override_func) === "function", "typeof(name_override_func
) = " + typeof(name_override_func));
1799 name_override_func = 3;
1800 ok(name_override_func === 3, "name_override_func
= " + name_override_func);
1801 function name_override_func() {};
1802 ok(name_override_func === 3, "name_override_func
= " + name_override_func);
1809 ok(tmp, "tmp
= " + tmp);
1812 for(var iter in [1,2,3,4]) {
1818 ok(tmp, "tmp
= " + tmp);
1821 ok(typeof(func) === "function", "typeof(func
) = " + typeof(func));
1822 with(new Object()) {
1823 var x = false && function func() {};
1825 ok(typeof(func) === "function", "typeof(func
) = " + typeof(func));
1829 ok(x === undefined, "x
= " + x); // x is declared, but never initialized
1831 ok(x === 1, "x
= " + x);
1833 ok(x === 2, "x
= " + x);
1835 ok(x === undefined, "x
= " + x);
1840 /* NoNewline rule parser tests */
1848 * no semicolon, but comment present */
1853 if(true) break // no semicolon, but comment present
1863 function returnTest() {
1868 ok(returnTest() === undefined, "returnTest
= " + returnTest());
1871 ok(ActiveXObject === 1, "ActiveXObject
= " + ActiveXObject);
1874 ok(Boolean === 1, "Boolean
= " + Boolean);
1877 ok(Object === 1, "Object
= " + Object);
1880 ok(Array === 1, "Array
= " + Array);
1883 ok(Date === 1, "Date
= " + Date);
1886 ok(Error === 1, "Error
= " + Error);
1888 /* Keep this test in the end of file */
1890 ok(undefined === 6, "undefined = " + undefined);
1893 ok(NaN === 6, "NaN
!== 6");
1896 ok(Infinity === 6, "Infinity
!== 6");
1899 ok(Math === 6, "NaN
!== 6");