summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/object/15.2.3.14-01.js
blob: 6cb8965a6c9ee48fc933f87c28260386de7ccb7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

//-----------------------------------------------------------------------------
var BUGNUMBER = 307791;
var summary = 'ES5 Object.keys(O)';
var actual = '';
var expect = '';

printBugNumber(BUGNUMBER);
printStatus(summary);

function arraysEqual(a1, a2)
{
  return a1.length === a2.length &&
         a1.every(function(v, i) { return v === a2[i]; });
}

/**************
 * BEGIN TEST *
 **************/

assertEq(Object.keys.length, 1);

var o, keys;

o = { a: 3, b: 2 };
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["a", "b"]), true,
         "" + keys);

o = { get a() { return 17; }, b: 2 };
keys = Object.keys(o),
assertEq(arraysEqual(keys, ["a", "b"]), true,
         "" + keys);

o = { __iterator__: function() { throw new Error("non-standard __iterator__ called?"); } };
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["__iterator__"]), true,
         "" + keys);

o = { a: 1, b: 2 };
delete o.a;
o.a = 3;
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["b", "a"]), true,
         "" + keys);

o = [0, 1, 2];
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["0", "1", "2"]), true,
         "" + keys);

o = /./.exec("abc");
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["0", "index", "input", "groups"]), true,
         "" + keys);

o = { a: 1, b: 2, c: 3 };
delete o.b;
o.b = 5;
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["a", "c", "b"]), true,
         "" + keys);

function f() { }
f.prototype.p = 1;
o = new f();
o.g = 1;
keys = Object.keys(o);
assertEq(arraysEqual(keys, ["g"]), true,
         "" + keys);

if (typeof Namespace !== "undefined" && typeof QName !== "undefined")
{
  var o2 = {};
  var qn = new QName(new Namespace("foo"), "v");
  o2.f = 1;
  o2[qn] = 3;
  o2.baz = 4;
  var keys2 = Object.keys(o2);
  assertEq(arraysEqual(keys2, ["f", "foo::v", "baz"]), true,
           "" + keys2);
}

/******************************************************************************/

reportCompare(expect, actual, "Object.keys");

printStatus("All tests passed!");