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
|
load("test-common.js");
try {
assert(Reflect.set.length === 3);
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
assertThrowsError(() => {
Reflect.set(value);
}, {
error: TypeError,
message: "First argument of Reflect.set() must be an object"
});
});
assert(Reflect.set({}) === true);
assert(Reflect.set({}, "foo") === true);
assert(Reflect.set({}, "foo", "bar") === true);
var o = {};
assert(o.foo === undefined);
assert(Reflect.set(o, "foo", 1) === true);
assert(o.foo === 1);
assert(Reflect.set(o, "foo", 2) === true);
assert(o.foo === 2);
Object.defineProperty(o, "bar", { value: 2, configurable: true, writable: false });
assert(Reflect.set(o, "bar") === false);
assert(o.bar === 2);
Object.defineProperty(o, "baz", { value: 3, configurable: false, writable: true });
assert(Reflect.set(o, "baz") === true);
assert(o.baz === undefined);
var a = [];
assert(a.length === 0);
assert(Reflect.set(a, "0") === true);
assert(a.length === 1);
assert(a[0] === undefined);
assert(Reflect.set(a, 1, "foo") === true);
assert(a.length === 2);
assert(a[0] === undefined);
assert(a[1] === "foo");
assert(Reflect.set(a, 4, "bar") === true);
assert(a.length === 5);
assert(a[0] === undefined);
assert(a[1] === "foo");
assert(a[2] === undefined);
assert(a[3] === undefined);
assert(a[4] === "bar");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
|