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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/Object/propertyIsEnumerable.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,199 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +var gTestfile = 'propertyIsEnumerable.js';
    1.10 +var BUGNUMBER = 619283;
    1.11 +var summary = "Object.prototype.propertyIsEnumerable";
    1.12 +
    1.13 +print(BUGNUMBER + ": " + summary);
    1.14 +
    1.15 +/**************
    1.16 + * BEGIN TEST *
    1.17 + **************/
    1.18 +
    1.19 +function expectThrowError(errorCtor, fun)
    1.20 +{
    1.21 +  try
    1.22 +  {
    1.23 +    var r = fun();
    1.24 +    throw "didn't throw TypeError, returned " + r;
    1.25 +  }
    1.26 +  catch (e)
    1.27 +  {
    1.28 +    assertEq(e instanceof errorCtor, true,
    1.29 +             "didn't throw " + errorCtor.prototype.name + ", got: " + e);
    1.30 +  }
    1.31 +}
    1.32 +
    1.33 +function expectThrowTypeError(fun)
    1.34 +{
    1.35 +  expectThrowError(TypeError, fun);
    1.36 +}
    1.37 +
    1.38 +function withToString(fun)
    1.39 +{
    1.40 +  return { toString: fun };
    1.41 +}
    1.42 +
    1.43 +function withValueOf(fun)
    1.44 +{
    1.45 +  return { toString: null, valueOf: fun };
    1.46 +}
    1.47 +
    1.48 +var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
    1.49 +
    1.50 +/*
    1.51 + * 1. Let P be ToString(V).
    1.52 + */
    1.53 +expectThrowError(ReferenceError, function()
    1.54 +{
    1.55 +  propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; }));
    1.56 +});
    1.57 +expectThrowError(ReferenceError, function()
    1.58 +{
    1.59 +  propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; }));
    1.60 +});
    1.61 +expectThrowError(ReferenceError, function()
    1.62 +{
    1.63 +  propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; }));
    1.64 +});
    1.65 +
    1.66 +expectThrowError(ReferenceError, function()
    1.67 +{
    1.68 +  propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; }));
    1.69 +});
    1.70 +expectThrowError(ReferenceError, function()
    1.71 +{
    1.72 +  propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; }));
    1.73 +});
    1.74 +expectThrowError(ReferenceError, function()
    1.75 +{
    1.76 +  propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; }));
    1.77 +});
    1.78 +
    1.79 +expectThrowError(SyntaxError, function()
    1.80 +{
    1.81 +  propertyIsEnumerable(withToString(function() { eval("}"); }));
    1.82 +});
    1.83 +expectThrowError(SyntaxError, function()
    1.84 +{
    1.85 +  propertyIsEnumerable.call(null, withToString(function() { eval("}"); }));
    1.86 +});
    1.87 +expectThrowError(SyntaxError, function()
    1.88 +{
    1.89 +  propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); }));
    1.90 +});
    1.91 +
    1.92 +expectThrowError(SyntaxError, function()
    1.93 +{
    1.94 +  propertyIsEnumerable(withValueOf(function() { eval("}"); }));
    1.95 +});
    1.96 +expectThrowError(SyntaxError, function()
    1.97 +{
    1.98 +  propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); }));
    1.99 +});
   1.100 +expectThrowError(SyntaxError, function()
   1.101 +{
   1.102 +  propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); }));
   1.103 +});
   1.104 +
   1.105 +expectThrowError(RangeError, function()
   1.106 +{
   1.107 +  propertyIsEnumerable(withToString(function() { [].length = -1; }));
   1.108 +});
   1.109 +expectThrowError(RangeError, function()
   1.110 +{
   1.111 +  propertyIsEnumerable.call(null, withToString(function() { [].length = -1; }));
   1.112 +});
   1.113 +expectThrowError(RangeError, function()
   1.114 +{
   1.115 +  propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; }));
   1.116 +});
   1.117 +
   1.118 +expectThrowError(RangeError, function()
   1.119 +{
   1.120 +  propertyIsEnumerable(withValueOf(function() { [].length = -1; }));
   1.121 +});
   1.122 +expectThrowError(RangeError, function()
   1.123 +{
   1.124 +  propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; }));
   1.125 +});
   1.126 +expectThrowError(RangeError, function()
   1.127 +{
   1.128 +  propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; }));
   1.129 +});
   1.130 +
   1.131 +expectThrowError(RangeError, function()
   1.132 +{
   1.133 +  propertyIsEnumerable(withToString(function() { [].length = 0.7; }));
   1.134 +});
   1.135 +expectThrowError(RangeError, function()
   1.136 +{
   1.137 +  propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; }));
   1.138 +});
   1.139 +expectThrowError(RangeError, function()
   1.140 +{
   1.141 +  propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; }));
   1.142 +});
   1.143 +
   1.144 +expectThrowError(RangeError, function()
   1.145 +{
   1.146 +  propertyIsEnumerable(withValueOf(function() { [].length = 0.7; }));
   1.147 +});
   1.148 +expectThrowError(RangeError, function()
   1.149 +{
   1.150 +  propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; }));
   1.151 +});
   1.152 +expectThrowError(RangeError, function()
   1.153 +{
   1.154 +  propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; }));
   1.155 +});
   1.156 +
   1.157 +/*
   1.158 + * 2. Let O be the result of calling ToObject passing the this value as the
   1.159 + *    argument.
   1.160 + */
   1.161 +expectThrowTypeError(function() { propertyIsEnumerable("s"); });
   1.162 +expectThrowTypeError(function() { propertyIsEnumerable.call(null, "s"); });
   1.163 +expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, "s"); });
   1.164 +expectThrowTypeError(function() { propertyIsEnumerable(true); });
   1.165 +expectThrowTypeError(function() { propertyIsEnumerable.call(null, true); });
   1.166 +expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, true); });
   1.167 +expectThrowTypeError(function() { propertyIsEnumerable(NaN); });
   1.168 +expectThrowTypeError(function() { propertyIsEnumerable.call(null, NaN); });
   1.169 +expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, NaN); });
   1.170 +
   1.171 +expectThrowTypeError(function() { propertyIsEnumerable({}); });
   1.172 +expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); });
   1.173 +expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); });
   1.174 +
   1.175 +/*
   1.176 + * 3. Let desc be the result of calling the [[GetOwnProperty]] internal method
   1.177 + *    of O passing P as the argument.
   1.178 + * 4. If desc is undefined, return false.
   1.179 + */
   1.180 +assertEq(propertyIsEnumerable.call({}, "valueOf"), false);
   1.181 +assertEq(propertyIsEnumerable.call({}, "toString"), false);
   1.182 +assertEq(propertyIsEnumerable.call("s", 1), false);
   1.183 +assertEq(propertyIsEnumerable.call({}, "dsfiodjfs"), false);
   1.184 +assertEq(propertyIsEnumerable.call(true, "toString"), false);
   1.185 +assertEq(propertyIsEnumerable.call({}, "__proto__"), false);
   1.186 +
   1.187 +assertEq(propertyIsEnumerable.call(Object, "getOwnPropertyDescriptor"), false);
   1.188 +assertEq(propertyIsEnumerable.call(this, "expectThrowTypeError"), true);
   1.189 +assertEq(propertyIsEnumerable.call("s", "length"), false);
   1.190 +assertEq(propertyIsEnumerable.call("s", 0), true);
   1.191 +assertEq(propertyIsEnumerable.call(Number, "MAX_VALUE"), false);
   1.192 +assertEq(propertyIsEnumerable.call({ x: 9 }, "x"), true);
   1.193 +assertEq(propertyIsEnumerable.call(function() { }, "prototype"), false);
   1.194 +assertEq(propertyIsEnumerable.call(function() { }, "length"), false);
   1.195 +assertEq(propertyIsEnumerable.call(function() { "use strict"; }, "caller"), false);
   1.196 +
   1.197 +/******************************************************************************/
   1.198 +
   1.199 +if (typeof reportCompare === "function")
   1.200 +  reportCompare(true, true);
   1.201 +
   1.202 +print("All tests passed!");

mercurial