Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_5 / Object / isPrototypeOf.js
1 /*
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/licenses/publicdomain/
4  */
5
6 var gTestfile = 'isPrototypeOf.js';
7 var BUGNUMBER = 619283;
8 var summary = "Object.prototype.isPrototypeOf";
9
10 print(BUGNUMBER + ": " + summary);
11
12 /**************
13  * BEGIN TEST *
14  **************/
15
16 function expectThrowTypeError(fun)
17 {
18   try
19   {
20     var r = fun();
21     throw new Error("didn't throw TypeError, returned " + r);
22   }
23   catch (e)
24   {
25     assertEq(e instanceof TypeError, true,
26              "didn't throw TypeError, got: " + e);
27   }
28 }
29
30 var isPrototypeOf = Object.prototype.isPrototypeOf;
31
32 /*
33  * 1. If V is not an Object, return false.
34  */
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);
46
47
48 /*
49  * 2. Let O be the result of calling ToObject passing the this value as the
50  *    argument.
51  */
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); });
59
60
61 /*
62  * 3. Repeat
63  */
64
65 /*
66  * 3a. Let V be the value of the [[Prototype]] internal property of V.
67  * 3b. If V is null, return false.
68  */
69 assertEq(Object.prototype.isPrototypeOf(Object.prototype), false);
70 assertEq(String.prototype.isPrototypeOf({}), false);
71 assertEq(Object.prototype.isPrototypeOf(Object.create(null)), false);
72
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);
79
80
81 /******************************************************************************/
82
83 if (typeof reportCompare === "function")
84   reportCompare(true, true);
85
86 print("All tests passed!");