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
|
function testBasic() {
var o1 = {x: 1};
var o2 = {a: 1, b: 2, c: 3, x: 4, y: 5, z: 6};
for (var i = 0; i < 4; i++) {
var to1 = Object.assign({}, o1);
assertEq(JSON.stringify(to1), '{"x":1}');
var to2 = Object.assign({}, o2);
assertEq(JSON.stringify(to2), '{"a":1,"b":2,"c":3,"x":4,"y":5,"z":6}');
}
}
testBasic();
// Target object's proto must not be changed by assign.
function testProto() {
var from = {};
from.a = 1;
from.b = 2;
from.c = 3;
for (var i = 0; i < 5; i++) {
var to = Object.assign(Object.create(null), from);
assertEq(JSON.stringify(to), '{"a":1,"b":2,"c":3}');
assertEq(Object.getPrototypeOf(to), null);
}
}
testProto();
// Target object's realm must not be changed by assign.
function testRealm() {
var global = newGlobal({sameCompartmentAs: this});
var from = global.evaluate("({})");
from.a = 1;
from.b = 2;
from.c = 3;
for (var i = 0; i < 5; i++) {
var to = Object.assign({}, from);
assertEq(JSON.stringify(to), '{"a":1,"b":2,"c":3}');
assertEq(objectGlobal(to), this);
assertEq(Object.getPrototypeOf(to), Object.prototype);
}
}
testRealm();
|