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
93
94
|
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if ("values" in Object) {
assertEq(Object.values.length, 1);
var o, values;
o = { a: 3, b: 2 };
values = Object.values(o);
assertDeepEq(values, [3, 2]);
o = { get a() { return 17; }, b: 2 };
values = Object.values(o),
assertDeepEq(values, [17, 2]);
o = { __iterator__: function() { return Iterator({a: 2, b: 3}); } };
values = Object.values(o);
assertDeepEq(values, [o.__iterator__]);
o = { a: 1, b: 2 };
delete o.a;
o.a = 3;
values = Object.values(o);
assertDeepEq(values, [2, 3]);
o = [0, 1, 2];
values = Object.values(o);
assertDeepEq(values, [0, 1, 2]);
o = /./.exec("abc");
values = Object.values(o);
assertDeepEq(values, ["a", 0, "abc"]);
o = { a: 1, b: 2, c: 3 };
delete o.b;
o.b = 5;
values = Object.values(o);
assertDeepEq(values, [1, 3, 5]);
function f() { }
f.prototype.p = 1;
o = new f();
o.g = 1;
values = Object.values(o);
assertDeepEq(values, [1]);
var o = {get a() {delete this.b; return 1}, b: 2, c: 3};
values = Object.values(o);
assertDeepEq(values, [1, 3]);
assertThrowsInstanceOf(() => Object.values(), TypeError);
assertThrowsInstanceOf(() => Object.values(undefined), TypeError);
assertThrowsInstanceOf(() => Object.values(null), TypeError);
assertDeepEq(Object.values(1), []);
assertDeepEq(Object.values(true), []);
if (typeof Symbol === "function")
assertDeepEq(Object.values(Symbol("foo")), []);
assertDeepEq(Object.values("foo"), ["f", "o", "o"]);
values = Object.values({
get a(){
Object.defineProperty(this, "b", {enumerable: false});
return "A";
},
b: "B"
});
assertDeepEq(values, ["A"]);
let ownKeysCallCount = 0;
let getOwnPropertyDescriptorCalls = [];
let target = { a: 1, b: 2, c: 3 };
o = new Proxy(target, {
ownKeys() {
ownKeysCallCount++;
return ["c", "a"];
},
getOwnPropertyDescriptor(target, key) {
getOwnPropertyDescriptorCalls.push(key);
return Object.getOwnPropertyDescriptor(target, key);
}
});
values = Object.values(o);
assertEq(ownKeysCallCount, 1);
assertDeepEq(values, [3, 1]);
assertDeepEq(getOwnPropertyDescriptorCalls, ["c", "a"]);
}
if (typeof reportCompare === "function")
reportCompare(true, true);
|