1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/extensions/instanceof-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + * File Name: instanceof-001.js 1.12 + * ECMA Section: 11.8.6 1.13 + * Description: 1.14 + * 1.15 + * RelationalExpression instanceof Identifier 1.16 + * 1.17 + * Author: christine@netscape.com 1.18 + * Date: 2 September 1998 1.19 + */ 1.20 +var SECTION = "instanceof-001"; 1.21 +var VERSION = "ECMA_2"; 1.22 +var TITLE = "instanceof" 1.23 + 1.24 + startTest(); 1.25 +writeHeaderToLog( SECTION + " "+ TITLE); 1.26 + 1.27 +function InstanceOf( object_1, object_2, expect ) { 1.28 + result = object_1 instanceof object_2; 1.29 + 1.30 + new TestCase( 1.31 + SECTION, 1.32 + "(" + object_1 + ") instanceof " + object_2, 1.33 + expect, 1.34 + result ); 1.35 +} 1.36 + 1.37 +function Gen3(value) { 1.38 + this.value = value; 1.39 + this.generation = 3; 1.40 + this.toString = new Function ( "return \"(Gen\"+this.generation+\" instance)\"" ); 1.41 +} 1.42 +Gen3.name = 3; 1.43 +Gen3.__proto__.toString = new Function( "return \"(\"+this.name+\" object)\""); 1.44 + 1.45 +function Gen2(value) { 1.46 + this.value = value; 1.47 + this.generation = 2; 1.48 +} 1.49 +Gen2.name = 2; 1.50 +Gen2.prototype = new Gen3(); 1.51 + 1.52 +function Gen1(value) { 1.53 + this.value = value; 1.54 + this.generation = 1; 1.55 +} 1.56 +Gen1.name = 1; 1.57 +Gen1.prototype = new Gen2(); 1.58 + 1.59 +function Gen0(value) { 1.60 + this.value = value; 1.61 + this.generation = 0; 1.62 +} 1.63 +Gen0.name = 0; 1.64 +Gen0.prototype = new Gen1(); 1.65 + 1.66 + 1.67 +function GenA(value) { 1.68 + this.value = value; 1.69 + this.generation = "A"; 1.70 + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); 1.71 + 1.72 +} 1.73 +GenA.prototype = new Gen0(); 1.74 +GenA.name = "A"; 1.75 + 1.76 +function GenB(value) { 1.77 + this.value = value; 1.78 + this.generation = "B"; 1.79 + this.toString = new Function ( "return \"(instance of Gen\"+this.generation+\")\"" ); 1.80 +} 1.81 +GenB.name = "B" 1.82 + GenB.prototype = void 0; 1.83 + 1.84 +// RelationalExpression is not an object. 1.85 + 1.86 +InstanceOf( true, Boolean, false ); 1.87 +InstanceOf( new Boolean(false), Boolean, true ); 1.88 + 1.89 +// __proto__ of RelationalExpression is null. should return false 1.90 +genA = new GenA(); 1.91 +genA.__proto__ = null; 1.92 + 1.93 +InstanceOf( genA, GenA, false ); 1.94 + 1.95 +// RelationalExpression.__proto__ == (but not ===) Identifier.prototype 1.96 + 1.97 +InstanceOf( new Gen2(), Gen0, false ); 1.98 +InstanceOf( new Gen2(), Gen1, false ); 1.99 +InstanceOf( new Gen2(), Gen2, true ); 1.100 +InstanceOf( new Gen2(), Gen3, true ); 1.101 + 1.102 +// RelationalExpression.__proto__.__proto__ === Identifier.prototype 1.103 +InstanceOf( new Gen0(), Gen0, true ); 1.104 +InstanceOf( new Gen0(), Gen1, true ); 1.105 +InstanceOf( new Gen0(), Gen2, true ); 1.106 +InstanceOf( new Gen0(), Gen3, true ); 1.107 + 1.108 +InstanceOf( new Gen0(), Object, true ); 1.109 +InstanceOf( new Gen0(), Function, false ); 1.110 + 1.111 +InstanceOf( Gen0, Function, true ); 1.112 +InstanceOf( Gen0, Object, true ); 1.113 + 1.114 +test();