2 * File Name: instanceof-001.js
6 * RelationalExpression instanceof Identifier
8 * Author: christine@netscape.com
9 * Date: 2 September 1998
11 var SECTION = "instanceof-001";
12 var VERSION = "ECMA_2";
13 var TITLE = "instanceof"
16 writeHeaderToLog( SECTION + " "+ TITLE);
19 var testcases = new Array();
21 function InstanceOf( object_1, object_2, expect ) {
22 result = object_1 instanceof object_2;
24 testcases[tc++] = new TestCase(
26 "(" + object_1 + ") instanceof " + object_2,
31 function Gen3(value) {
34 this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" );
37 Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\"");
39 function Gen2(value) {
44 Gen2.prototype = new Gen3();
46 function Gen1(value) {
51 Gen1.prototype = new Gen2();
53 function Gen0(value) {
58 Gen0.prototype = new Gen1();
61 function GenA(value) {
63 this.generation = "A";
64 this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
67 GenA.prototype = new Gen0();
70 function GenB(value) {
72 this.generation = "B";
73 this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
76 GenB.prototype = void 0;
78 // RelationalExpression is not an object.
80 InstanceOf( true, Boolean, false );
81 InstanceOf( new Boolean(false), Boolean, true );
83 // Identifier is not a function
85 // InstanceOf( true, true, false );
86 // InstanceOf( new Boolean(true), false, false );
88 // Identifier is a function, prototype of Identifier is not an object
90 // InstanceOf( new GenB(), GenB, false );
92 // __proto__ of RelationalExpression is null. should return false
94 genA.__proto__ = null;
96 InstanceOf( genA, GenA, false );
98 // RelationalExpression.__proto__ == (but not ===) Identifier.prototype
100 InstanceOf( new Gen2(), Gen0, false );
101 InstanceOf( new Gen2(), Gen1, false );
102 InstanceOf( new Gen2(), Gen2, true );
103 InstanceOf( new Gen2(), Gen3, true );
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 );
111 InstanceOf( new Gen0(), Object, true );
112 InstanceOf( new Gen0(), Function, false );
114 InstanceOf( Gen0, Function, true );
115 InstanceOf( Gen0, Object, true );