 Chromium Code Reviews
 Chromium Code Reviews Issue 1168093002:
  [strong] Implement strong mode restrictions on property access  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1168093002:
  [strong] Implement strong mode restrictions on property access  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| 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 | |
| 
rossberg
2015/06/10 08:28:08
See above
 
conradw
2015/06/10 12:03:23
Done.
 | |
| 8 // tests. | |
| 9 | |
| 10 function getObjects() { | |
| 
rossberg
2015/06/10 08:28:08
See above
 
conradw
2015/06/10 12:03:23
Done.
 | |
| 11 "use strict"; | |
| 12 return [ | |
| 13 {}, | |
| 14 [], | |
| 15 (function(){}), | |
| 16 (class Foo {}) | |
| 17 ]; | |
| 18 } | |
| 19 | |
| 20 function readFromObjectSloppy(o) { | |
| 21 return o.foo; | |
| 22 } | |
| 23 | |
| 24 function readFromObjectKeyedSloppy(o) { | |
| 25 return o["foo"]; | |
| 26 } | |
| 27 | |
| 28 function readFromObjectKeyedVarSloppy(o) { | |
| 29 var a = "foo"; | |
| 30 return o[a]; | |
| 31 } | |
| 32 | |
| 33 function readFromObjectKeyedComputedSloppy(o) { | |
| 34 var a = "o"; | |
| 35 return o["fo" + a]; | |
| 36 } | |
| 37 | |
| 38 function readFromObjectStrong(o) { | |
| 39 "use strong"; | |
| 40 return o.foo; | |
| 41 } | |
| 42 | |
| 43 function readFromObjectKeyedStrong(o) { | |
| 44 "use strong"; | |
| 45 return o["foo"]; | |
| 46 } | |
| 47 | |
| 48 function readFromObjectKeyedLetStrong(o) { | |
| 49 "use strong"; | |
| 50 let a = "foo"; | |
| 51 return o[a]; | |
| 52 } | |
| 53 | |
| 54 function readFromObjectKeyedComputedStrong(o) { | |
| 55 "use strong"; | |
| 56 let a = "o"; | |
| 57 return o["fo" + a]; | |
| 58 } | |
| 59 | |
| 60 function getDescs(x) { | |
| 61 return [ | |
| 62 {value: x}, | |
| 63 {configurable: true, value: x}, | |
| 64 {configurable: true, enumerable: true, writable: true, value: x}, | |
| 65 {configurable: true, enumerable: true, get: (function() {return x}) }, | |
| 66 ]; | |
| 67 } | |
| 68 | |
| 69 function assertStrongSemantics(func, object) { | |
| 70 %DeoptimizeFunction(func); | |
| 71 %ClearFunctionTypeFeedback(func); | |
| 72 assertThrows(function(){func(object)}, TypeError); | |
| 73 assertThrows(function(){func(object)}, TypeError); | |
| 74 assertThrows(function(){func(object)}, TypeError); | |
| 75 %OptimizeFunctionOnNextCall(func); | |
| 76 assertThrows(function(){func(object)}, TypeError); | |
| 77 %DeoptimizeFunction(func); | |
| 78 assertThrows(function(){func(object)}, TypeError); | |
| 79 } | |
| 80 | |
| 81 function assertSloppySemantics(func, object) { | |
| 82 %DeoptimizeFunction(func); | |
| 83 %ClearFunctionTypeFeedback(func); | |
| 84 assertDoesNotThrow(function(){func(object)}); | |
| 85 assertDoesNotThrow(function(){func(object)}); | |
| 86 assertDoesNotThrow(function(){func(object)}); | |
| 87 %OptimizeFunctionOnNextCall(func); | |
| 88 assertDoesNotThrow(function(){func(object)}); | |
| 89 %DeoptimizeFunction(func); | |
| 90 assertDoesNotThrow(function(){func(object)}); | |
| 91 } | |
| 92 | |
| 93 (function () { | |
| 94 "use strict"; | |
| 95 | |
| 96 let goodKeys = [ | |
| 97 "foo" | |
| 98 ] | |
| 99 | |
| 100 let badKeys = [ | |
| 101 "bar", | |
| 102 "1", | |
| 103 "100001", | |
| 104 "3000000001", | |
| 105 "5000000001" | |
| 106 ]; | |
| 107 | |
| 108 let values = [ | |
| 109 "string", | |
| 110 1, | |
| 111 100001, | |
| 112 30000000001, | |
| 113 50000000001, | |
| 114 NaN, | |
| 115 {}, | |
| 116 undefined | |
| 117 ]; | |
| 118 | |
| 119 let badAccessorDescs = [ | |
| 120 { set: (function(){}) }, | |
| 121 { configurable: true, set: (function(){}) }, | |
| 122 { configurable: true, enumerable: true, set: (function(){}) } | |
| 123 ]; | |
| 124 | |
| 125 let readSloppy = [ | |
| 126 readFromObjectSloppy, | |
| 127 readFromObjectKeyedSloppy, | |
| 128 readFromObjectKeyedVarSloppy, | |
| 129 readFromObjectKeyedComputedSloppy | |
| 130 ]; | |
| 131 | |
| 132 let readStrong = [ | |
| 133 readFromObjectStrong, | |
| 134 readFromObjectKeyedStrong, | |
| 135 readFromObjectKeyedLetStrong, | |
| 136 readFromObjectKeyedComputedStrong | |
| 137 ]; | |
| 138 | |
| 139 let dummyProto = {}; | |
| 140 for (let key of goodKeys) { | |
| 141 Object.defineProperty(dummyProto, key, { value: undefined }); | |
| 142 } | |
| 143 | |
| 144 // After altering the backing store, accessing a missing property should still | |
| 145 // throw. | |
| 146 for (let key of badKeys) { | |
| 147 for (let value of values) { | |
| 148 for (let desc of getDescs(value)) { | |
| 149 for (let object of getObjects()) { | |
| 150 Object.defineProperty(object, key, desc); | |
| 151 for (let func of readStrong) { | |
| 152 assertStrongSemantics(func, object); | |
| 153 } | |
| 154 for (let func of readSloppy) { | |
| 155 assertSloppySemantics(func, object); | |
| 156 } | |
| 157 // Accessing a property which is on the prototype chain of the object | |
| 158 // should not throw. | |
| 159 object.__proto__ = dummyProto; | |
| 160 for (let key of goodKeys) { | |
| 161 for (let func of readStrong.concat(readSloppy)) { | |
| 162 assertSloppySemantics(func, object); | |
| 163 } | |
| 164 } | |
| 165 } | |
| 166 } | |
| 167 } | |
| 168 } | |
| 169 })(); | |
| OLD | NEW |