shape-teleporting-1.js (2774B)
1 // Receiver shadows 2 (function() { 3 function check(p) { return p.x; } 4 5 let a = { x: "a" }; 6 let b = { __proto__: a }; 7 let c = { __proto__: b }; 8 let d = { __proto__: c }; 9 10 assertEq(check(d), "a"); 11 assertEq(check(d), "a"); 12 d.x = "d"; 13 assertEq(check(d), "d"); 14 })(); 15 16 // Intermediate proto shadows 17 (function() { 18 function check(p) { return p.x; } 19 20 let a = { x: "a" }; 21 let b = { __proto__: a }; 22 let c = { __proto__: b }; 23 let d = { __proto__: c }; 24 25 assertEq(check(d), "a"); 26 assertEq(check(d), "a"); 27 c.x = "c"; 28 assertEq(check(d), "c"); 29 })(); 30 31 // Receiver proto changes 32 (function() { 33 function check(p) { return p.x; } 34 35 let a = { x: "a" }; 36 let b = { __proto__: a }; 37 let c = { __proto__: b }; 38 let d = { __proto__: c }; 39 40 assertEq(check(d), "a"); 41 assertEq(check(d), "a"); 42 d.__proto__ = { x: "?" }; 43 assertEq(check(d), "?"); 44 })(); 45 46 // Intermediate proto changes 47 (function() { 48 function check(p) { return p.x; } 49 50 let a = { x: "a" }; 51 let b = { __proto__: a }; 52 let c = { __proto__: b }; 53 let d = { __proto__: c }; 54 55 assertEq(check(d), "a"); 56 assertEq(check(d), "a"); 57 c.__proto__ = { x: "?" }; 58 assertEq(check(d), "?"); 59 })(); 60 61 // Uncacheable holder proto 62 (function() { 63 function check(p) { return p.x; } 64 65 function Base() { this.x = "a"; } 66 let a = new Base; 67 a.__proto__ = new Object; 68 let b = { __proto__: a }; 69 let c = { __proto__: b }; 70 let d = { __proto__: c }; 71 72 assertEq(check(d), "a"); 73 assertEq(check(d), "a"); 74 b.__proto__ = { x: "?" }; 75 assertEq(check(d), "?"); 76 })(); 77 78 // Uncacheable intermediate proto 79 (function() { 80 function check(p) { return p.x; } 81 82 function Base() { this.x = "a"; } 83 function Node() { } 84 85 let a = new Base; 86 let b = new Node; b.__proto__ = a; 87 let c = { __proto__: b }; 88 let d = { __proto__: c }; 89 90 assertEq(check(d), "a"); 91 assertEq(check(d), "a"); 92 b.__proto__ = { x: "?" }; 93 assertEq(check(d), "?"); 94 })(); 95 96 // Uncacheable receiver proto 97 (function() { 98 function check(p) { return p.x; } 99 100 function Base() { this.x = "a"; } 101 function Node() { } 102 103 let a = new Base; 104 let b = { __proto__: a }; 105 let c = { __proto__: b }; 106 let d = new Node; d.__proto__ = c; 107 108 assertEq(check(d), "a"); 109 assertEq(check(d), "a"); 110 d.__proto__ = { x: "?" }; 111 assertEq(check(d), "?"); 112 })(); 113 114 // Uncacheable receiver proto (only receiver / holder) 115 (function() { 116 function check(p) { return p.x; } 117 118 function Base() { this.x = "a"; } 119 function Node() { } 120 121 let a = new Base; 122 let b = new Node; b.__proto__ = a; 123 124 assertEq(check(b), "a"); 125 assertEq(check(b), "a"); 126 b.__proto__ = { x: "?" }; 127 assertEq(check(b), "?"); 128 })();