Debian Codegraph @

js/src/jit-test/tests/watchtower/freeze-proto-1.js

raw
1 // |jit-test| --fast-warmup; --no-threads
2
3 // Freezing a prototype object must invalidate the megamorphic set-property cache.
4
5 var atoms = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
6
7 function addProps(obj) {
8 for (var i = 0; i < 10; i++) {
9 obj[atoms[i]] = i;
10 }
11 }
12
13 function f() {
14 var proto = Object.create(null);
15 proto.c = 0;
16 proto.g = 0;
17 proto.i = 0;
18
19 var obj1 = Object.create(proto);
20 var obj2 = Object.create(proto);
21
22 addProps(obj1);
23 Object.freeze(proto);
24 addProps(obj2);
25
26 assertEq(Object.keys(obj1).length, 10);
27 assertEq(Object.keys(obj2).length, 7);
28 }
29 for (var i = 0; i < 10; i++) {
30 f();
31 }