]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /** |
2 | * File Name: instanceof-001.js | |
3 | * ECMA Section: 11.8.6 | |
4 | * Description: | |
5 | * | |
6 | * RelationalExpression instanceof Identifier | |
7 | * | |
8 | * Author: christine@netscape.com | |
9 | * Date: 2 September 1998 | |
10 | */ | |
11 | var SECTION = "instanceof-001"; | |
12 | var VERSION = "ECMA_2"; | |
13 | var TITLE = "instanceof" | |
14 | ||
15 | startTest(); | |
16 | writeHeaderToLog( SECTION + " "+ TITLE); | |
17 | ||
18 | var tc = 0; | |
19 | var testcases = new Array(); | |
20 | ||
21 | function InstanceOf( object_1, object_2, expect ) { | |
22 | result = object_1 instanceof object_2; | |
23 | ||
24 | testcases[tc++] = new TestCase( | |
25 | SECTION, | |
26 | "(" + object_1 + ") instanceof " + object_2, | |
27 | expect, | |
28 | result ); | |
29 | } | |
30 | ||
31 | function Gen3(value) { | |
32 | this.value = value; | |
33 | this.generation = 3; | |
34 | this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); | |
35 | } | |
36 | Gen3.name = 3; | |
37 | Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); | |
38 | ||
39 | function Gen2(value) { | |
40 | this.value = value; | |
41 | this.generation = 2; | |
42 | } | |
43 | Gen2.name = 2; | |
44 | Gen2.prototype = new Gen3(); | |
45 | ||
46 | function Gen1(value) { | |
47 | this.value = value; | |
48 | this.generation = 1; | |
49 | } | |
50 | Gen1.name = 1; | |
51 | Gen1.prototype = new Gen2(); | |
52 | ||
53 | function Gen0(value) { | |
54 | this.value = value; | |
55 | this.generation = 0; | |
56 | } | |
57 | Gen0.name = 0; | |
58 | Gen0.prototype = new Gen1(); | |
59 | ||
60 | ||
61 | function GenA(value) { | |
62 | this.value = value; | |
63 | this.generation = "A"; | |
64 | this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); | |
65 | ||
66 | } | |
67 | GenA.prototype = new Gen0(); | |
68 | GenA.name = "A"; | |
69 | ||
70 | function GenB(value) { | |
71 | this.value = value; | |
72 | this.generation = "B"; | |
73 | this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); | |
74 | } | |
75 | GenB.name = "B" | |
76 | GenB.prototype = void 0; | |
77 | ||
78 | // RelationalExpression is not an object. | |
79 | ||
80 | InstanceOf( true, Boolean, false ); | |
81 | InstanceOf( new Boolean(false), Boolean, true ); | |
82 | ||
83 | // Identifier is not a function | |
84 | ||
85 | // InstanceOf( true, true, false ); | |
86 | // InstanceOf( new Boolean(true), false, false ); | |
87 | ||
88 | // Identifier is a function, prototype of Identifier is not an object | |
89 | ||
90 | // InstanceOf( new GenB(), GenB, false ); | |
91 | ||
92 | // __proto__ of RelationalExpression is null. should return false | |
93 | genA = new GenA(); | |
94 | genA.__proto__ = null; | |
95 | ||
96 | InstanceOf( genA, GenA, false ); | |
97 | ||
98 | // RelationalExpression.__proto__ == (but not ===) Identifier.prototype | |
99 | ||
100 | InstanceOf( new Gen2(), Gen0, false ); | |
101 | InstanceOf( new Gen2(), Gen1, false ); | |
102 | InstanceOf( new Gen2(), Gen2, true ); | |
103 | InstanceOf( new Gen2(), Gen3, true ); | |
104 | ||
105 | // RelationalExpression.__proto__.__proto__ === Identifier.prototype | |
106 | InstanceOf( new Gen0(), Gen0, true ); | |
107 | InstanceOf( new Gen0(), Gen1, true ); | |
108 | InstanceOf( new Gen0(), Gen2, true ); | |
109 | InstanceOf( new Gen0(), Gen3, true ); | |
110 | ||
111 | InstanceOf( new Gen0(), Object, true ); | |
112 | InstanceOf( new Gen0(), Function, false ); | |
113 | ||
114 | InstanceOf( Gen0, Function, true ); | |
115 | InstanceOf( Gen0, Object, true ); | |
116 | ||
117 | test(); |