2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
6 var gTestfile = 'isPrototypeOf.js';
7 var BUGNUMBER = 619283;
8 var summary = "Object.prototype.isPrototypeOf";
10 print(BUGNUMBER + ": " + summary);
16 function expectThrowTypeError(fun)
21 throw new Error("didn't throw TypeError, returned " + r);
25 assertEq(e instanceof TypeError, true,
26 "didn't throw TypeError, got: " + e);
30 var isPrototypeOf = Object.prototype.isPrototypeOf;
33 * 1. If V is not an Object, return false.
35 assertEq(isPrototypeOf(), false);
36 assertEq(isPrototypeOf(1), false);
37 assertEq(isPrototypeOf(Number.MAX_VALUE), false);
38 assertEq(isPrototypeOf(NaN), false);
39 assertEq(isPrototypeOf(""), false);
40 assertEq(isPrototypeOf("sesquicentennial"), false);
41 assertEq(isPrototypeOf(true), false);
42 assertEq(isPrototypeOf(false), false);
43 assertEq(isPrototypeOf(0.72), false);
44 assertEq(isPrototypeOf(undefined), false);
45 assertEq(isPrototypeOf(null), false);
49 * 2. Let O be the result of calling ToObject passing the this value as the
52 var protoGlobal = Object.create(this);
53 expectThrowTypeError(function() { isPrototypeOf.call(null, {}); });
54 expectThrowTypeError(function() { isPrototypeOf.call(undefined, {}); });
55 expectThrowTypeError(function() { isPrototypeOf({}); });
56 expectThrowTypeError(function() { isPrototypeOf.call(null, protoGlobal); });
57 expectThrowTypeError(function() { isPrototypeOf.call(undefined, protoGlobal); });
58 expectThrowTypeError(function() { isPrototypeOf(protoGlobal); });
66 * 3a. Let V be the value of the [[Prototype]] internal property of V.
67 * 3b. If V is null, return false.
69 assertEq(Object.prototype.isPrototypeOf(Object.prototype), false);
70 assertEq(String.prototype.isPrototypeOf({}), false);
71 assertEq(Object.prototype.isPrototypeOf(Object.create(null)), false);
73 /* 3c. If O and V refer to the same object, return true. */
74 assertEq(Object.prototype.isPrototypeOf({}), true);
75 assertEq(this.isPrototypeOf(protoGlobal), true);
76 assertEq(Object.prototype.isPrototypeOf({}), true);
77 assertEq(Object.prototype.isPrototypeOf(new Number(17)), true);
78 assertEq(Object.prototype.isPrototypeOf(function(){}), true);
81 /******************************************************************************/
83 if (typeof reportCompare === "function")
84 reportCompare(true, true);
86 print("All tests passed!");