1 ///////////////////////////////
4 function empty1() { ; }
5 shouldBe("empty1()", "undefined");
8 shouldBe("empty2()", "undefined");
11 var obj
= new Object();
13 obj
.func = function(a
) { return g
*l
*a
; };
17 shouldBe("obj.func(11)", "66");
19 ///////////////////////////////
23 this.dummy
= new Array(); // once broke the returned completion
27 shouldBe("c.x", "11");
29 ///////////////////////////////
30 // anonymous functions
31 ///////////////////////////////
38 shouldBe("f('bbbbb')", "'bbbbb'");
41 function f() {return 1;};
43 // just verify that this can be parsed
44 Math
.round(function anon() { });
46 ///////////////////////////////
48 ///////////////////////////////
52 for (i
= 0; i
< arguments
.length
; i
++)
53 result
+= arguments
[i
] + "|";
57 shouldBe("foo()", "'|'");
58 shouldBe("foo('bar')", "'|bar|'");
59 shouldBe("foo('bar', 'x')", "'|bar|x|'");
63 for(a
in arguments
) // should be enumerable
68 shouldBe("foo2(7)", "1");
70 // I have my doubts about the standard conformance of this
74 return foo3
.arguments
.length
;
76 return foo3
.arguments
;
82 shouldBe("foo3(0, 99)", "2");
83 shouldBe("foo3(1, 99).length", "2");
84 //shouldBe("foo3(2, 99)", "99"); // IE doesn't support this either
86 ///////////////////////////////
87 // nested function declarations
88 ///////////////////////////////
92 function nest1(c
) { return c
*c
; }
95 shouldBe("nest0(2,3)", "36");
97 ///////////////////////////////
99 ///////////////////////////////
101 shouldBe("(new Function('return 11;'))()", "11");
102 shouldBe("(new Function('', 'return 22;'))()", "22");
103 shouldBe("(new Function('a', 'b', 'return a*b;'))(11, 3)", "33");
104 shouldBe("(new Function(' a ', ' b ', 'return a*b;'))(11, 4)", "44");
105 shouldBe("(new Function(' a,b ', ' c ', 'return a*b;'))(11, 5)", "55");
106 shouldBe("(new Function(' a,b ', ' c3 ', 'return a*b;'))(11, 6)", "66");
109 ///////////////////////////////
111 function funcp3(a
, b
, c
) { }
112 shouldBe("funcp3.length", "3");
113 shouldBe("(function(a, b, c, d) { }).length", "4");
114 shouldBe("(new Function('a', 'b', '')).length", "2");
119 return i
== 1 ? 1 : i
*f4(i
-1);
122 shouldBe("f4(4)", "24");
129 return f5
.arguments
[0];
132 shouldBe("f5(11)", "11");
133 shouldBe("f5.arguments", "null");
135 ///////////////////////////////
136 // calling conventions
137 ///////////////////////////////
139 function manipulate(x
) {
140 x
[0] = 99; // should operate on reference
141 x
= "nothing"; // should detach
143 var arr
= new Array(1, 2, 3);
145 shouldBe("arr[0]", "99");
148 shouldBe("arr[0]", "99");
150 ///////////////////////////////
151 // toString() on functions
152 ///////////////////////////////
154 function orgFunc(s
) { return 'Hello ' + s
; }
155 eval("var orgFuncClone = " + orgFunc
);
156 shouldBe("typeof orgFuncClone", "'function'");
157 shouldBe("orgFuncClone('world')", "'Hello world'");
159 function groupFunc(a
, b
) { return (a
+b
)*3; } // check for () being preserved
160 eval("var groupClone = " + groupFunc
);
161 shouldBe("groupClone(1, 2)", "9");
163 var sinStr
= 'function sin() {\n [native code]\n}'
164 shouldBe("String(Math.sin)", "sinStr");
166 ///////////////////////////////
167 // shadowed functions
168 ///////////////////////////////
170 function shadow() { return 1; }
171 function shadow() { return 2; }
172 shouldBe("shadow()", "2");
174 ///////////////////////////////
177 var nest_property
= "global nest";
179 function nested_outer() {
181 var nest_property
= "inner nest";
183 function nested_inner() {
184 return nest_property
;
190 function not_nested() {
191 return nest_property
;
194 nested_outer
.nest_property
= "outer nest";
196 var nested
= nested_outer();
197 var nestedret
= nested();
198 shouldBe("nestedret","'inner nest'");
200 var not_nestedret
= not_nested();
201 shouldBe("not_nestedret","'global nest'");
203 ///////////////////////////////
205 ///////////////////////////////
206 function sample() { }
207 shouldBeUndefined("sample.prototype.prototype");
208 shouldBeTrue("sample.prototype.constructor == sample");
212 sample
.apply(1, 1); // invalid argument
216 shouldBeTrue("caught");
219 function functionWithVarOverride(a
) {
224 shouldBe("functionWithVarOverride(1)", "2");