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
|
// The cache lookup must happen after ensuring there are no dense elements.
function testNewDenseElement() {
var from = {x: 1, y: 2, z: 3};
for (var i = 0; i < 10; i++) {
if (i === 6) {
from[0] = 1;
}
var to = Object.assign({}, from);
if (i >= 6) {
assertEq(JSON.stringify(to), '{"0":1,"x":1,"y":2,"z":3}');
} else {
assertEq(JSON.stringify(to), '{"x":1,"y":2,"z":3}');
}
}
}
testNewDenseElement();
// The cache lookup must happen after ensuring there are non-writable
// properties on the proto chain.
function testProtoNonWritable() {
var proto = {x: 1};
var from = {x: 1, y: 2, z: 3};
for (var i = 0; i < 10; i++) {
if (i === 6) {
Object.freeze(proto);
}
var to = Object.create(proto);
var ex = null;
try {
Object.assign(to, from);
} catch (e) {
ex = e;
}
assertEq(ex instanceof TypeError, i > 5);
if (i <= 5) {
assertEq(JSON.stringify(to), '{"x":1,"y":2,"z":3}');
} else {
assertEq(JSON.stringify(to), '{}');
}
}
}
testProtoNonWritable();
function testDictionary1() {
var from = {a: 1, b: 2, c: 3};
delete from.a;
for (var i = 0; i < 10; i++) {
var to = Object.assign({}, from);
assertEq(JSON.stringify(to), '{"b":2,"c":3}');
}
}
testDictionary1();
function testDictionary2() {
var from = {a: 1, b: 2, c: 3};
delete from.a;
from.a = 4;
for (var i = 0; i < 10; i++) {
var to = Object.assign({}, from);
assertEq(JSON.stringify(to), '{"b":2,"c":3,"a":4}');
}
}
testDictionary2();
|