js/src/tests/ecma_5/Object/propertyIsEnumerable.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial