michael@0: // Copyright 2009 the Sputnik authors. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * Native ECMAScript objects have an internal property called [[Prototype]]. The value of this property is michael@0: * either null or an object and is used for implementing inheritance michael@0: * michael@0: * @path ch08/8.6/8.6.2/S8.6.2_A1.js michael@0: * @description Check [[Prototype]] property of object michael@0: */ michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#1 michael@0: var __obj={}; michael@0: if (!Object.prototype.isPrototypeOf(__obj)){ michael@0: $ERROR('#1: Native ECMAScript objects have an internal property called [[Prototype]]. '); michael@0: }; michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: //Establish proto (base) object michael@0: /*function ProtoObj(){ michael@0: michael@0: };*/ michael@0: var protoObj={}; michael@0: //Establish foo object michael@0: function FooObj(){}; michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#2 michael@0: // Invoke instance of foo object michael@0: var obj__= new FooObj; michael@0: michael@0: if (!Object.prototype.isPrototypeOf(obj__)){ michael@0: $ERROR('#2.1: protoObj={}; function FooObj(){}; var obj__= new FooObj; Object.prototype.isPrototypeOf(obj__) === true. Actual: ' + (Object.prototype.isPrototypeOf(obj__))); michael@0: }; michael@0: michael@0: if (!FooObj.prototype.isPrototypeOf(obj__)){ michael@0: $ERROR('#2.2: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype.isPrototypeOf(obj__) === true. Actual: ' + (FooObj.prototype.isPrototypeOf(obj__))); michael@0: }; michael@0: michael@0: if (protoObj.isPrototypeOf(obj__)){ michael@0: $ERROR('#2.3: protoObj={}; function FooObj(){}; var obj__= new FooObj; protoObj.isPrototypeOf(obj__) === false. Actual: ' + (protoObj.isPrototypeOf(obj__))); michael@0: }; michael@0: // Establish inheritance from proto object michael@0: FooObj.prototype=protoObj; michael@0: michael@0: if (protoObj.isPrototypeOf(obj__)){ michael@0: $ERROR('#2.4: protoObj={}; function FooObj(){}; var obj__= new FooObj; FooObj.prototype=protoObj; protoObj.isPrototypeOf(obj__) === false. Actual: ' + (protoObj.isPrototypeOf(obj__))); michael@0: }; michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //CHECK#3 michael@0: michael@0: // Invoke instance of foo object michael@0: var __foo=new FooObj; michael@0: michael@0: if (!Object.prototype.isPrototypeOf(__foo)){ michael@0: $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: }; michael@0: michael@0: if (!FooObj.prototype.isPrototypeOf(__foo)){ michael@0: $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: }; michael@0: michael@0: if (!protoObj.isPrototypeOf(__foo)){ michael@0: $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: }; michael@0: // michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: