michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: var gTestfile = 'propertyIsEnumerable.js'; michael@0: var BUGNUMBER = 619283; michael@0: var summary = "Object.prototype.propertyIsEnumerable"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: function expectThrowError(errorCtor, fun) michael@0: { michael@0: try michael@0: { michael@0: var r = fun(); michael@0: throw "didn't throw TypeError, returned " + r; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof errorCtor, true, michael@0: "didn't throw " + errorCtor.prototype.name + ", got: " + e); michael@0: } michael@0: } michael@0: michael@0: function expectThrowTypeError(fun) michael@0: { michael@0: expectThrowError(TypeError, fun); michael@0: } michael@0: michael@0: function withToString(fun) michael@0: { michael@0: return { toString: fun }; michael@0: } michael@0: michael@0: function withValueOf(fun) michael@0: { michael@0: return { toString: null, valueOf: fun }; michael@0: } michael@0: michael@0: var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; michael@0: michael@0: /* michael@0: * 1. Let P be ToString(V). michael@0: */ michael@0: expectThrowError(ReferenceError, function() michael@0: { michael@0: propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; })); michael@0: }); michael@0: expectThrowError(ReferenceError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; })); michael@0: }); michael@0: expectThrowError(ReferenceError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; })); michael@0: }); michael@0: michael@0: expectThrowError(ReferenceError, function() michael@0: { michael@0: propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; })); michael@0: }); michael@0: expectThrowError(ReferenceError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; })); michael@0: }); michael@0: expectThrowError(ReferenceError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; })); michael@0: }); michael@0: michael@0: expectThrowError(SyntaxError, function() michael@0: { michael@0: propertyIsEnumerable(withToString(function() { eval("}"); })); michael@0: }); michael@0: expectThrowError(SyntaxError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withToString(function() { eval("}"); })); michael@0: }); michael@0: expectThrowError(SyntaxError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); })); michael@0: }); michael@0: michael@0: expectThrowError(SyntaxError, function() michael@0: { michael@0: propertyIsEnumerable(withValueOf(function() { eval("}"); })); michael@0: }); michael@0: expectThrowError(SyntaxError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); })); michael@0: }); michael@0: expectThrowError(SyntaxError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); })); michael@0: }); michael@0: michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable(withToString(function() { [].length = -1; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withToString(function() { [].length = -1; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; })); michael@0: }); michael@0: michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable(withValueOf(function() { [].length = -1; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; })); michael@0: }); michael@0: michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable(withToString(function() { [].length = 0.7; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; })); michael@0: }); michael@0: michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable(withValueOf(function() { [].length = 0.7; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; })); michael@0: }); michael@0: expectThrowError(RangeError, function() michael@0: { michael@0: propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; })); michael@0: }); michael@0: michael@0: /* michael@0: * 2. Let O be the result of calling ToObject passing the this value as the michael@0: * argument. michael@0: */ michael@0: expectThrowTypeError(function() { propertyIsEnumerable("s"); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(null, "s"); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, "s"); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable(true); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(null, true); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, true); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable(NaN); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(null, NaN); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, NaN); }); michael@0: michael@0: expectThrowTypeError(function() { propertyIsEnumerable({}); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); }); michael@0: expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); }); michael@0: michael@0: /* michael@0: * 3. Let desc be the result of calling the [[GetOwnProperty]] internal method michael@0: * of O passing P as the argument. michael@0: * 4. If desc is undefined, return false. michael@0: */ michael@0: assertEq(propertyIsEnumerable.call({}, "valueOf"), false); michael@0: assertEq(propertyIsEnumerable.call({}, "toString"), false); michael@0: assertEq(propertyIsEnumerable.call("s", 1), false); michael@0: assertEq(propertyIsEnumerable.call({}, "dsfiodjfs"), false); michael@0: assertEq(propertyIsEnumerable.call(true, "toString"), false); michael@0: assertEq(propertyIsEnumerable.call({}, "__proto__"), false); michael@0: michael@0: assertEq(propertyIsEnumerable.call(Object, "getOwnPropertyDescriptor"), false); michael@0: assertEq(propertyIsEnumerable.call(this, "expectThrowTypeError"), true); michael@0: assertEq(propertyIsEnumerable.call("s", "length"), false); michael@0: assertEq(propertyIsEnumerable.call("s", 0), true); michael@0: assertEq(propertyIsEnumerable.call(Number, "MAX_VALUE"), false); michael@0: assertEq(propertyIsEnumerable.call({ x: 9 }, "x"), true); michael@0: assertEq(propertyIsEnumerable.call(function() { }, "prototype"), false); michael@0: assertEq(propertyIsEnumerable.call(function() { }, "length"), false); michael@0: assertEq(propertyIsEnumerable.call(function() { "use strict"; }, "caller"), false); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("All tests passed!");