OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --strong-mode --allow-natives-syntax |
| 6 |
| 7 // TODO(conradw): Track implementation of strong bit for other objects, add |
| 8 // tests. |
| 9 |
| 10 function getObjects() { |
| 11 "use strict"; |
| 12 return [ |
| 13 {}, |
| 14 [], |
| 15 (function(){}), |
| 16 (class Foo {}) |
| 17 ]; |
| 18 } |
| 19 |
| 20 function readFromObjectElementSloppy(o) { |
| 21 return o[0]; |
| 22 } |
| 23 |
| 24 function readFromObjectElementSparseSloppy(o) { |
| 25 return o[100000]; |
| 26 } |
| 27 |
| 28 function readFromObjectElementNonSmiSloppy(o) { |
| 29 return o[3000000000]; |
| 30 } |
| 31 |
| 32 function readFromObjectNonIndexSloppy(o) { |
| 33 return o[5000000000]; |
| 34 } |
| 35 |
| 36 function readFromObjectElementVarSloppy(o) { |
| 37 var a = 0; |
| 38 return o[a]; |
| 39 } |
| 40 |
| 41 function readFromObjectElementSparseVarSloppy(o) { |
| 42 var a = 100000; |
| 43 return o[a]; |
| 44 } |
| 45 |
| 46 function readFromObjectElementNonSmiVarSloppy(o) { |
| 47 var a = 3000000000; |
| 48 return o[a]; |
| 49 } |
| 50 |
| 51 function readFromObjectNonIndexVarSloppy(o) { |
| 52 var a = 5000000000; |
| 53 return o[a]; |
| 54 } |
| 55 |
| 56 function readFromObjectElementStrong(o) { |
| 57 "use strong"; |
| 58 return o[0]; |
| 59 } |
| 60 |
| 61 function readFromObjectElementSparseStrong(o) { |
| 62 "use strong"; |
| 63 return o[100000]; |
| 64 } |
| 65 |
| 66 function readFromObjectElementNonSmiStrong(o) { |
| 67 "use strong"; |
| 68 return o[3000000000]; |
| 69 } |
| 70 |
| 71 function readFromObjectNonIndexStrong(o) { |
| 72 "use strong"; |
| 73 return o[5000000000]; |
| 74 } |
| 75 |
| 76 function readFromObjectElementLetStrong(o) { |
| 77 "use strong"; |
| 78 let a = 0; |
| 79 return o[a]; |
| 80 } |
| 81 |
| 82 function readFromObjectElementSparseLetStrong(o) { |
| 83 "use strong"; |
| 84 let a = 100000; |
| 85 return o[a]; |
| 86 } |
| 87 |
| 88 function readFromObjectElementNonSmiLetStrong(o) { |
| 89 "use strong"; |
| 90 let a = 3000000000; |
| 91 return o[a]; |
| 92 } |
| 93 |
| 94 function readFromObjectNonIndexLetStrong(o) { |
| 95 "use strong"; |
| 96 let a = 5000000000; |
| 97 return o[a]; |
| 98 } |
| 99 |
| 100 function getDescs(x) { |
| 101 return [ |
| 102 {value: x}, |
| 103 {configurable: true, value: x}, |
| 104 {configurable: true, enumerable: true, writable: true, value: x}, |
| 105 {configurable: true, enumerable: true, get: (function() {return x}) }, |
| 106 ]; |
| 107 } |
| 108 |
| 109 function assertStrongSemantics(func, object) { |
| 110 %DeoptimizeFunction(func); |
| 111 %ClearFunctionTypeFeedback(func); |
| 112 assertThrows(function(){func(object)}, TypeError); |
| 113 assertThrows(function(){func(object)}, TypeError); |
| 114 assertThrows(function(){func(object)}, TypeError); |
| 115 %OptimizeFunctionOnNextCall(func); |
| 116 assertThrows(function(){func(object)}, TypeError); |
| 117 %DeoptimizeFunction(func); |
| 118 assertThrows(function(){func(object)}, TypeError); |
| 119 } |
| 120 |
| 121 function assertSloppySemantics(func, object) { |
| 122 %DeoptimizeFunction(func); |
| 123 %ClearFunctionTypeFeedback(func); |
| 124 assertDoesNotThrow(function(){func(object)}); |
| 125 assertDoesNotThrow(function(){func(object)}); |
| 126 assertDoesNotThrow(function(){func(object)}); |
| 127 %OptimizeFunctionOnNextCall(func); |
| 128 assertDoesNotThrow(function(){func(object)}); |
| 129 %DeoptimizeFunction(func); |
| 130 assertDoesNotThrow(function(){func(object)}); |
| 131 } |
| 132 |
| 133 (function () { |
| 134 "use strict"; |
| 135 |
| 136 let goodKeys = [ |
| 137 "0", |
| 138 "100000", |
| 139 "3000000000", |
| 140 "5000000000" |
| 141 ] |
| 142 |
| 143 let badKeys = [ |
| 144 "bar", |
| 145 "1", |
| 146 "100001", |
| 147 "3000000001", |
| 148 "5000000001" |
| 149 ]; |
| 150 |
| 151 let values = [ |
| 152 "string", |
| 153 1, |
| 154 100001, |
| 155 30000000001, |
| 156 50000000001, |
| 157 NaN, |
| 158 {}, |
| 159 undefined |
| 160 ]; |
| 161 |
| 162 let badAccessorDescs = [ |
| 163 { set: (function(){}) }, |
| 164 { configurable: true, set: (function(){}) }, |
| 165 { configurable: true, enumerable: true, set: (function(){}) } |
| 166 ]; |
| 167 |
| 168 let readSloppy = [ |
| 169 readFromObjectElementSloppy, |
| 170 readFromObjectElementSparseSloppy, |
| 171 readFromObjectElementNonSmiSloppy, |
| 172 readFromObjectNonIndexSloppy, |
| 173 readFromObjectElementVarSloppy, |
| 174 readFromObjectElementSparseVarSloppy, |
| 175 readFromObjectElementNonSmiVarSloppy, |
| 176 readFromObjectNonIndexVarSloppy |
| 177 ]; |
| 178 |
| 179 let readStrong = [ |
| 180 readFromObjectElementStrong, |
| 181 readFromObjectElementSparseStrong, |
| 182 readFromObjectElementNonSmiStrong, |
| 183 readFromObjectNonIndexStrong, |
| 184 readFromObjectElementLetStrong, |
| 185 readFromObjectElementSparseLetStrong, |
| 186 readFromObjectElementNonSmiLetStrong, |
| 187 readFromObjectNonIndexLetStrong |
| 188 ]; |
| 189 |
| 190 let dummyProto = {}; |
| 191 for (let key of goodKeys) { |
| 192 Object.defineProperty(dummyProto, key, { value: undefined }); |
| 193 } |
| 194 |
| 195 // After altering the backing store, accessing a missing property should still |
| 196 // throw. |
| 197 for (let key of badKeys) { |
| 198 for (let value of values) { |
| 199 for (let desc of getDescs(value)) { |
| 200 for (let object of getObjects()) { |
| 201 Object.defineProperty(object, key, desc); |
| 202 for (let func of readStrong) { |
| 203 assertStrongSemantics(func, object); |
| 204 } |
| 205 for (let func of readSloppy) { |
| 206 assertSloppySemantics(func, object); |
| 207 } |
| 208 // Accessing a property which is on the prototype chain of the object |
| 209 // should not throw. |
| 210 object.__proto__ = dummyProto; |
| 211 for (let key of goodKeys) { |
| 212 for (let func of readStrong.concat(readSloppy)) { |
| 213 assertSloppySemantics(func, object); |
| 214 } |
| 215 } |
| 216 } |
| 217 } |
| 218 } |
| 219 } |
| 220 })(); |
OLD | NEW |