• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.getOwnPropertyNames(arr);
18// props should contain: 0,1,2,length and the order is not defined!
19assert (props.indexOf("0") !== -1);
20assert (props.indexOf("1") !== -1);
21assert (props.indexOf("2") !== -1);
22assert (props.indexOf("length") !== -1);
23assert (props.length === 4);
24
25// Test object
26var obj = {key1: 'a', key3: 'b', key2: 'c', key4: 'c', key5: ''};
27props = Object.getOwnPropertyNames(obj);
28// props should contain: key1,key2,key3,key4,key5 and the order is not defined!
29assert (props.indexOf("key1") !== -1);
30assert (props.indexOf("key2") !== -1);
31assert (props.indexOf("key3") !== -1);
32assert (props.indexOf("key4") !== -1);
33assert (props.indexOf("key5") !== -1);
34assert (props.length === 5);
35
36var obj2 = {};
37Object.defineProperties(obj2, {
38    key_one: {enumerable: true, value: 'one'},
39    key_two: {enumerable: false, value: 'two'},
40});
41
42props = Object.getOwnPropertyNames(obj2);
43// props should contain: key_one,key_two and the order is not defined!
44assert (props.indexOf("key_one") !== -1);
45assert (props.indexOf("key_two") !== -1);
46assert (props.length === 2);
47
48// Test prototype chain
49function Parent() {}
50Parent.prototype.inheritedMethod = function() {};
51
52function Child() {
53  this.prop = 5;
54  this.method = function() {};
55}
56Child.prototype = new Parent;
57Child.prototype.prototypeMethod = function() {};
58
59props = Object.getOwnPropertyNames (new Child());
60// props should contain: prop,method and the order is not defined!
61assert (props.indexOf("prop") !== -1);
62assert (props.indexOf("method") !== -1);
63
64assert (props.length === 2);
65