1// Copyright 2013 the V8 project authors. All rights reserved. 2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24description("KDE JS Test"); 25// Object.prototype.hasOwnProperty 26 27function MyClass() 28{ 29 this.y = 2; 30} 31 32MyClass.prototype = { x : 1 }; 33 34var sub = new MyClass(); 35shouldBe("sub.x","1"); 36shouldBe("sub.y","2"); 37shouldBe("sub.hasOwnProperty('x')","false"); 38shouldBe("sub.hasOwnProperty('y')","true"); 39sub.x = 6; 40shouldBe("sub.x","6"); 41shouldBe("sub.hasOwnProperty('x')","true"); 42delete sub.y; 43shouldBe("sub.y","undefined"); 44shouldBe("sub.hasOwnProperty('y')","false"); 45 46 47 48// Object.prototype.isPrototypeOf 49 50function Class1() {} 51function Class2() {} 52function Class3() {} 53 54Class1.prototype = new Object(); 55Class1.prototype.hasClass1 = true; 56Class2.prototype = new Class1(); 57Class2.prototype.hasClass2 = true; 58Class3.prototype = new Class2(); 59Class3.prototype.hasClass3 = true; 60 61var obj = new Class3(); 62shouldBe("obj.hasClass1","true"); 63shouldBe("obj.hasClass2","true"); 64shouldBe("obj.hasClass3","true"); 65 66shouldBe("Class1.prototype.isPrototypeOf(obj)","true"); 67shouldBe("Class2.prototype.isPrototypeOf(obj)","true"); 68shouldBe("Class3.prototype.isPrototypeOf(obj)","true"); 69shouldBe("obj.isPrototypeOf(Class1.prototype)","false"); 70shouldBe("obj.isPrototypeOf(Class2.prototype)","false"); 71shouldBe("obj.isPrototypeOf(Class3.prototype)","false"); 72 73shouldBe("Class1.prototype.isPrototypeOf(Class2.prototype)","true"); 74shouldBe("Class2.prototype.isPrototypeOf(Class1.prototype)","false"); 75shouldBe("Class1.prototype.isPrototypeOf(Class3.prototype)","true"); 76shouldBe("Class3.prototype.isPrototypeOf(Class1.prototype)","false"); 77shouldBe("Class2.prototype.isPrototypeOf(Class3.prototype)","true"); 78shouldBe("Class3.prototype.isPrototypeOf(Class2.prototype)","false"); 79 80shouldBeUndefined("Class1.prototype.prototype"); 81 82function checkEnumerable(obj,property) 83{ 84 for (var propname in obj) { 85 if (propname == property) 86 return true; 87 } 88 return false; 89} 90 91function myfunc(a,b,c) 92{ 93} 94myfunc.someproperty = 4; 95 96shouldBe("myfunc.length","3"); 97shouldBe("myfunc.someproperty","4"); 98shouldBe("myfunc.propertyIsEnumerable('length')","false"); 99shouldBe("myfunc.propertyIsEnumerable('someproperty')","true"); 100shouldBe("checkEnumerable(myfunc,'length')","false"); 101shouldBe("checkEnumerable(myfunc,'someproperty')","true"); 102