Debian Codegraph @

rhino/testsrc/tests/ecma_2/extensions/instanceof-001.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'instanceof-001.js';
7
8 /**
9 * File Name: instanceof-001.js
10 * ECMA Section: 11.8.6
11 * Description:
12 *
13 * RelationalExpression instanceof Identifier
14 *
15 * Author: [email protected]
16 * Date: 2 September 1998
17 */
18 var SECTION = "instanceof-001";
19 var VERSION = "ECMA_2";
20 var TITLE = "instanceof"
21
22 startTest();
23 writeHeaderToLog( SECTION + " "+ TITLE);
24
25 function InstanceOf( object_1, object_2, expect ) {
26 result = object_1 instanceof object_2;
27
28 new TestCase(
29 SECTION,
30 "(" + object_1 + ") instanceof " + object_2,
31 expect,
32 result );
33 }
34
35 function Gen3(value) {
36 this.value = value;
37 this.generation = 3;
38 this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" );
39 }
40 Gen3.name = 3;
41 Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\"");
42
43 function Gen2(value) {
44 this.value = value;
45 this.generation = 2;
46 }
47 Gen2.name = 2;
48 Gen2.prototype = new Gen3();
49
50 function Gen1(value) {
51 this.value = value;
52 this.generation = 1;
53 }
54 Gen1.name = 1;
55 Gen1.prototype = new Gen2();
56
57 function Gen0(value) {
58 this.value = value;
59 this.generation = 0;
60 }
61 Gen0.name = 0;
62 Gen0.prototype = new Gen1();
63
64
65 function GenA(value) {
66 this.value = value;
67 this.generation = "A";
68 this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
69
70 }
71 GenA.prototype = new Gen0();
72 GenA.name = "A";
73
74 function GenB(value) {
75 this.value = value;
76 this.generation = "B";
77 this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" );
78 }
79 GenB.name = "B"
80 GenB.prototype = void 0;
81
82 // RelationalExpression is not an object.
83
84 InstanceOf( true, Boolean, false );
85 InstanceOf( new Boolean(false), Boolean, true );
86
87 // __proto__ of RelationalExpression is null. should return false
88 genA = new GenA();
89 genA.__proto__ = null;
90
91 InstanceOf( genA, GenA, false );
92
93 // RelationalExpression.__proto__ == (but not ===) Identifier.prototype
94
95 InstanceOf( new Gen2(), Gen0, false );
96 InstanceOf( new Gen2(), Gen1, false );
97 InstanceOf( new Gen2(), Gen2, true );
98 InstanceOf( new Gen2(), Gen3, true );
99
100 // RelationalExpression.__proto__.__proto__ === Identifier.prototype
101 InstanceOf( new Gen0(), Gen0, true );
102 InstanceOf( new Gen0(), Gen1, true );
103 InstanceOf( new Gen0(), Gen2, true );
104 InstanceOf( new Gen0(), Gen3, true );
105
106 InstanceOf( new Gen0(), Object, true );
107 InstanceOf( new Gen0(), Function, false );
108
109 InstanceOf( Gen0, Function, true );
110 InstanceOf( Gen0, Object, true );
111
112 test();