2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
6 var gTestfile = 'propertyIsEnumerable.js';
7 var BUGNUMBER = 619283;
8 var summary = "Object.prototype.propertyIsEnumerable";
10 print(BUGNUMBER + ": " + summary);
16 function expectThrowError(errorCtor, fun)
21 throw "didn't throw TypeError, returned " + r;
25 assertEq(e instanceof errorCtor, true,
26 "didn't throw " + errorCtor.prototype.name + ", got: " + e);
30 function expectThrowTypeError(fun)
32 expectThrowError(TypeError, fun);
35 function withToString(fun)
37 return { toString: fun };
40 function withValueOf(fun)
42 return { toString: null, valueOf: fun };
45 var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
48 * 1. Let P be ToString(V).
50 expectThrowError(ReferenceError, function()
52 propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; }));
54 expectThrowError(ReferenceError, function()
56 propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; }));
58 expectThrowError(ReferenceError, function()
60 propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; }));
63 expectThrowError(ReferenceError, function()
65 propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; }));
67 expectThrowError(ReferenceError, function()
69 propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; }));
71 expectThrowError(ReferenceError, function()
73 propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; }));
76 expectThrowError(SyntaxError, function()
78 propertyIsEnumerable(withToString(function() { eval("}"); }));
80 expectThrowError(SyntaxError, function()
82 propertyIsEnumerable.call(null, withToString(function() { eval("}"); }));
84 expectThrowError(SyntaxError, function()
86 propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); }));
89 expectThrowError(SyntaxError, function()
91 propertyIsEnumerable(withValueOf(function() { eval("}"); }));
93 expectThrowError(SyntaxError, function()
95 propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); }));
97 expectThrowError(SyntaxError, function()
99 propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); }));
102 expectThrowError(RangeError, function()
104 propertyIsEnumerable(withToString(function() { [].length = -1; }));
106 expectThrowError(RangeError, function()
108 propertyIsEnumerable.call(null, withToString(function() { [].length = -1; }));
110 expectThrowError(RangeError, function()
112 propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; }));
115 expectThrowError(RangeError, function()
117 propertyIsEnumerable(withValueOf(function() { [].length = -1; }));
119 expectThrowError(RangeError, function()
121 propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; }));
123 expectThrowError(RangeError, function()
125 propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; }));
128 expectThrowError(RangeError, function()
130 propertyIsEnumerable(withToString(function() { [].length = 0.7; }));
132 expectThrowError(RangeError, function()
134 propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; }));
136 expectThrowError(RangeError, function()
138 propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; }));
141 expectThrowError(RangeError, function()
143 propertyIsEnumerable(withValueOf(function() { [].length = 0.7; }));
145 expectThrowError(RangeError, function()
147 propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; }));
149 expectThrowError(RangeError, function()
151 propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; }));
155 * 2. Let O be the result of calling ToObject passing the this value as the
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); });
168 expectThrowTypeError(function() { propertyIsEnumerable({}); });
169 expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); });
170 expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); });
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.
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);
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);
194 /******************************************************************************/
196 if (typeof reportCompare === "function")
197 reportCompare(true, true);
199 print("All tests passed!");