Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | // Copyright 2009 the Sputnik authors. All rights reserved. |
michael@0 | 2 | // This code is governed by the BSD license found in the LICENSE file. |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Native ECMAScript objects have an internal property called [[Prototype]]. The value of this property is |
michael@0 | 6 | * either null or an object and is used for implementing inheritance |
michael@0 | 7 | * |
michael@0 | 8 | * @path ch08/8.6/8.6.2/S8.6.2_A1.js |
michael@0 | 9 | * @description Check [[Prototype]] property of object |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 13 | //CHECK#1 |
michael@0 | 14 | var __obj={}; |
michael@0 | 15 | if (!Object.prototype.isPrototypeOf(__obj)){ |
michael@0 | 16 | $ERROR('#1: Native ECMAScript objects have an internal property called [[Prototype]]. '); |
michael@0 | 17 | }; |
michael@0 | 18 | // |
michael@0 | 19 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 20 | |
michael@0 | 21 | //Establish proto (base) object |
michael@0 | 22 | /*function ProtoObj(){ |
michael@0 | 23 | |
michael@0 | 24 | };*/ |
michael@0 | 25 | var protoObj={}; |
michael@0 | 26 | //Establish foo object |
michael@0 | 27 | function FooObj(){}; |
michael@0 | 28 | |
michael@0 | 29 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 30 | //CHECK#2 |
michael@0 | 31 | // Invoke instance of foo object |
michael@0 | 32 | var obj__= new FooObj; |
michael@0 | 33 | |
michael@0 | 34 | if (!Object.prototype.isPrototypeOf(obj__)){ |
michael@0 | 35 | $ERROR('#2.1: protoObj={}; function FooObj(){}; var obj__= new FooObj; Object.prototype.isPrototypeOf(obj__) === true. Actual: ' + (Object.prototype.isPrototypeOf(obj__))); |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | if (!FooObj.prototype.isPrototypeOf(obj__)){ |
michael@0 | 39 | $ERROR('#2.2: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype.isPrototypeOf(obj__) === true. Actual: ' + (FooObj.prototype.isPrototypeOf(obj__))); |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | if (protoObj.isPrototypeOf(obj__)){ |
michael@0 | 43 | $ERROR('#2.3: protoObj={}; function FooObj(){}; var obj__= new FooObj; protoObj.isPrototypeOf(obj__) === false. Actual: ' + (protoObj.isPrototypeOf(obj__))); |
michael@0 | 44 | }; |
michael@0 | 45 | // Establish inheritance from proto object |
michael@0 | 46 | FooObj.prototype=protoObj; |
michael@0 | 47 | |
michael@0 | 48 | if (protoObj.isPrototypeOf(obj__)){ |
michael@0 | 49 | $ERROR('#2.4: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype=protoObj; protoObj.isPrototypeOf(obj__) === false. Actual: ' + (protoObj.isPrototypeOf(obj__))); |
michael@0 | 50 | }; |
michael@0 | 51 | // |
michael@0 | 52 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 53 | |
michael@0 | 54 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 55 | //CHECK#3 |
michael@0 | 56 | |
michael@0 | 57 | // Invoke instance of foo object |
michael@0 | 58 | var __foo=new FooObj; |
michael@0 | 59 | |
michael@0 | 60 | if (!Object.prototype.isPrototypeOf(__foo)){ |
michael@0 | 61 | $ERROR('#3.1: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype=protoObj; var __foo=new FooObj; Object.prototype.isPrototypeOf(__foo) === true. Actual: ' + (Object.prototype.isPrototypeOf(__foo))); |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | if (!FooObj.prototype.isPrototypeOf(__foo)){ |
michael@0 | 65 | $ERROR('#3.2: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype=protoObj; var __foo=new FooObj; FooObj.prototype.isPrototypeOf(__foo) === true. Actual: ' + (FooObj.prototype.isPrototypeOf(__foo))); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | if (!protoObj.isPrototypeOf(__foo)){ |
michael@0 | 69 | $ERROR('#3.3: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype=protoObj; var __foo=new FooObj; protoObj.isPrototypeOf(__foo) === true. Actual: ' + (protoObj.isPrototypeOf(__foo))); |
michael@0 | 70 | }; |
michael@0 | 71 | // |
michael@0 | 72 | ////////////////////////////////////////////////////////////////////////////// |
michael@0 | 73 |