1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Test array 16var arr = ['a', 'b', 'c']; 17var props = Object.keys(arr); 18// props should contain: 0,1,2 and the order is not defined! 19assert (props.indexOf("0") !== -1); 20assert (props.indexOf("1") !== -1); 21assert (props.indexOf("2") !== -1); 22assert (props.length === 3); 23 24// Test object 25var obj = {key1: 'a', key3: 'b', key2: 'c', key4: 'c', key5: ''}; 26props = Object.keys(obj); 27// props should contain: key1,key2,key3,key4,key5 and the order is not defined! 28assert (props.indexOf("key1") !== -1); 29assert (props.indexOf("key2") !== -1); 30assert (props.indexOf("key3") !== -1); 31assert (props.indexOf("key4") !== -1); 32assert (props.indexOf("key5") !== -1); 33assert (props.length === 5); 34 35var obj2 = {}; 36Object.defineProperties(obj2, { 37 key_one: {enumerable: true, value: 'one'}, 38 key_two: {enumerable: false, value: 'two'}, 39}); 40 41props = Object.keys(obj2); 42// props should contain: key_one 43assert (props.indexOf("key_one") !== -1); 44assert (props.indexOf("key_two") === -1); 45assert (props.length === 1); 46 47// Test prototype chain 48function Parent() {} 49Parent.prototype.inheritedMethod = function() {}; 50 51function Child() { 52 this.prop = 5; 53 this.method = function() {}; 54} 55Child.prototype = new Parent; 56Child.prototype.prototypeMethod = function() {}; 57 58props = Object.keys (new Child()); 59// props should contain: prop,method and the order is not defined! 60assert (props.indexOf("prop") !== -1); 61assert (props.indexOf("method") !== -1); 62assert (props.length === 2); 63 64var o = {}; 65 66Object.defineProperty(o, 'a', { 67 value: "OK", 68 writable: true, 69 enumerable: true, 70 configurable: true 71}); 72 73Object.defineProperty(o, 'b', { 74 value: "NOT_OK", 75 writable: true, 76 enumerable: false, 77 configurable: true 78}); 79 80Object.defineProperty(o, 'c', { 81 value: "OK", 82 writable: true, 83 enumerable: true, 84 configurable: true 85}); 86 87props = Object.keys(o); 88assert(props.length === 2); 89assert(o[props[0]] === "OK"); 90assert(o[props[1]] === "OK"); 91