Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / Object / propertyIsEnumerable.js
1 /*
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/licenses/publicdomain/
4  */
5
6 var gTestfile = 'propertyIsEnumerable.js';
7 var BUGNUMBER = 619283;
8 var summary = "Object.prototype.propertyIsEnumerable";
9
10 print(BUGNUMBER + ": " + summary);
11
12 /**************
13  * BEGIN TEST *
14  **************/
15
16 function expectThrowError(errorCtor, fun)
17 {
18   try
19   {
20     var r = fun();
21     throw "didn't throw TypeError, returned " + r;
22   }
23   catch (e)
24   {
25     assertEq(e instanceof errorCtor, true,
26              "didn't throw " + errorCtor.prototype.name + ", got: " + e);
27   }
28 }
29
30 function expectThrowTypeError(fun)
31 {
32   expectThrowError(TypeError, fun);
33 }
34
35 function withToString(fun)
36 {
37   return { toString: fun };
38 }
39
40 function withValueOf(fun)
41 {
42   return { toString: null, valueOf: fun };
43 }
44
45 var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
46
47 /*
48  * 1. Let P be ToString(V).
49  */
50 expectThrowError(ReferenceError, function()
51 {
52   propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; }));
53 });
54 expectThrowError(ReferenceError, function()
55 {
56   propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; }));
57 });
58 expectThrowError(ReferenceError, function()
59 {
60   propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; }));
61 });
62
63 expectThrowError(ReferenceError, function()
64 {
65   propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; }));
66 });
67 expectThrowError(ReferenceError, function()
68 {
69   propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; }));
70 });
71 expectThrowError(ReferenceError, function()
72 {
73   propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; }));
74 });
75
76 expectThrowError(SyntaxError, function()
77 {
78   propertyIsEnumerable(withToString(function() { eval("}"); }));
79 });
80 expectThrowError(SyntaxError, function()
81 {
82   propertyIsEnumerable.call(null, withToString(function() { eval("}"); }));
83 });
84 expectThrowError(SyntaxError, function()
85 {
86   propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); }));
87 });
88
89 expectThrowError(SyntaxError, function()
90 {
91   propertyIsEnumerable(withValueOf(function() { eval("}"); }));
92 });
93 expectThrowError(SyntaxError, function()
94 {
95   propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); }));
96 });
97 expectThrowError(SyntaxError, function()
98 {
99   propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); }));
100 });
101
102 expectThrowError(RangeError, function()
103 {
104   propertyIsEnumerable(withToString(function() { [].length = -1; }));
105 });
106 expectThrowError(RangeError, function()
107 {
108   propertyIsEnumerable.call(null, withToString(function() { [].length = -1; }));
109 });
110 expectThrowError(RangeError, function()
111 {
112   propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; }));
113 });
114
115 expectThrowError(RangeError, function()
116 {
117   propertyIsEnumerable(withValueOf(function() { [].length = -1; }));
118 });
119 expectThrowError(RangeError, function()
120 {
121   propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; }));
122 });
123 expectThrowError(RangeError, function()
124 {
125   propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; }));
126 });
127
128 expectThrowError(RangeError, function()
129 {
130   propertyIsEnumerable(withToString(function() { [].length = 0.7; }));
131 });
132 expectThrowError(RangeError, function()
133 {
134   propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; }));
135 });
136 expectThrowError(RangeError, function()
137 {
138   propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; }));
139 });
140
141 expectThrowError(RangeError, function()
142 {
143   propertyIsEnumerable(withValueOf(function() { [].length = 0.7; }));
144 });
145 expectThrowError(RangeError, function()
146 {
147   propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; }));
148 });
149 expectThrowError(RangeError, function()
150 {
151   propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; }));
152 });
153
154 /*
155  * 2. Let O be the result of calling ToObject passing the this value as the
156  *    argument.
157  */
158 expectThrowTypeError(function() { propertyIsEnumerable("s"); });
159 expectThrowTypeError(function() { propertyIsEnumerable.call(null, "s"); });
160 expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, "s"); });
161 expectThrowTypeError(function() { propertyIsEnumerable(true); });
162 expectThrowTypeError(function() { propertyIsEnumerable.call(null, true); });
163 expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, true); });
164 expectThrowTypeError(function() { propertyIsEnumerable(NaN); });
165 expectThrowTypeError(function() { propertyIsEnumerable.call(null, NaN); });
166 expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, NaN); });
167
168 expectThrowTypeError(function() { propertyIsEnumerable({}); });
169 expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); });
170 expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); });
171
172 /*
173  * 3. Let desc be the result of calling the [[GetOwnProperty]] internal method
174  *    of O passing P as the argument.
175  * 4. If desc is undefined, return false.
176  */
177 assertEq(propertyIsEnumerable.call({}, "valueOf"), false);
178 assertEq(propertyIsEnumerable.call({}, "toString"), false);
179 assertEq(propertyIsEnumerable.call("s", 1), false);
180 assertEq(propertyIsEnumerable.call({}, "dsfiodjfs"), false);
181 assertEq(propertyIsEnumerable.call(true, "toString"), false);
182 assertEq(propertyIsEnumerable.call({}, "__proto__"), false);
183
184 assertEq(propertyIsEnumerable.call(Object, "getOwnPropertyDescriptor"), false);
185 assertEq(propertyIsEnumerable.call(this, "expectThrowTypeError"), true);
186 assertEq(propertyIsEnumerable.call("s", "length"), false);
187 assertEq(propertyIsEnumerable.call("s", 0), true);
188 assertEq(propertyIsEnumerable.call(Number, "MAX_VALUE"), false);
189 assertEq(propertyIsEnumerable.call({ x: 9 }, "x"), true);
190 assertEq(propertyIsEnumerable.call(function() { }, "prototype"), false);
191 assertEq(propertyIsEnumerable.call(function() { }, "length"), false);
192 assertEq(propertyIsEnumerable.call(function() { "use strict"; }, "caller"), false);
193
194 /******************************************************************************/
195
196 if (typeof reportCompare === "function")
197   reportCompare(true, true);
198
199 print("All tests passed!");