Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: test/mjsunit/strong/load-element-mutate-backing-store.js

Issue 1168093002: [strong] Implement strong mode restrictions on property access (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback 3 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 function getSloppyArguments() {
8 return arguments;
9 }
10
11 function getObjects() {
12 "use strict";
13 return [
14 {},
15 [],
16 (function(){}),
17 (class Foo {}),
18 getSloppyArguments(),
19 arguments,
20 new Date()
21 ];
22 }
23
24 function readFromObjectElementSloppy(o) {
25 return o[0];
26 }
27
28 function readFromObjectElementSparseSloppy(o) {
29 return o[100000];
30 }
31
32 function readFromObjectElementNonSmiSloppy(o) {
33 return o[3000000000];
34 }
35
36 function readFromObjectNonIndexSloppy(o) {
37 return o[5000000000];
38 }
39
40 function readFromObjectElementVarSloppy(o) {
41 var a = 0;
42 return o[a];
43 }
44
45 function readFromObjectElementSparseVarSloppy(o) {
46 var a = 100000;
47 return o[a];
48 }
49
50 function readFromObjectElementNonSmiVarSloppy(o) {
51 var a = 3000000000;
52 return o[a];
53 }
54
55 function readFromObjectNonIndexVarSloppy(o) {
56 var a = 5000000000;
57 return o[a];
58 }
59
60 function readFromObjectElementStrong(o) {
61 "use strong";
62 return o[0];
63 }
64
65 function readFromObjectElementSparseStrong(o) {
66 "use strong";
67 return o[100000];
68 }
69
70 function readFromObjectElementNonSmiStrong(o) {
71 "use strong";
72 return o[3000000000];
73 }
74
75 function readFromObjectNonIndexStrong(o) {
76 "use strong";
77 return o[5000000000];
78 }
79
80 function readFromObjectElementLetStrong(o) {
81 "use strong";
82 let a = 0;
83 return o[a];
84 }
85
86 function readFromObjectElementSparseLetStrong(o) {
87 "use strong";
88 let a = 100000;
89 return o[a];
90 }
91
92 function readFromObjectElementNonSmiLetStrong(o) {
93 "use strong";
94 let a = 3000000000;
95 return o[a];
96 }
97
98 function readFromObjectNonIndexLetStrong(o) {
99 "use strong";
100 let a = 5000000000;
101 return o[a];
102 }
103
104 function getDescs(x) {
105 return [
106 {value: x},
107 {configurable: true, value: x},
108 {configurable: true, enumerable: true, writable: true, value: x},
109 {configurable: true, enumerable: true, get: (function() {return x}) },
110 ];
111 }
112
113 function assertStrongSemantics(func, object) {
114 %DeoptimizeFunction(func);
115 %ClearFunctionTypeFeedback(func);
116 assertThrows(function(){func(object)}, TypeError);
117 assertThrows(function(){func(object)}, TypeError);
118 assertThrows(function(){func(object)}, TypeError);
119 %OptimizeFunctionOnNextCall(func);
120 assertThrows(function(){func(object)}, TypeError);
121 %DeoptimizeFunction(func);
122 assertThrows(function(){func(object)}, TypeError);
123 }
124
125 function assertSloppySemantics(func, object) {
126 %DeoptimizeFunction(func);
127 %ClearFunctionTypeFeedback(func);
128 assertDoesNotThrow(function(){func(object)});
129 assertDoesNotThrow(function(){func(object)});
130 assertDoesNotThrow(function(){func(object)});
131 %OptimizeFunctionOnNextCall(func);
132 assertDoesNotThrow(function(){func(object)});
133 %DeoptimizeFunction(func);
134 assertDoesNotThrow(function(){func(object)});
135 }
136
137 (function () {
138 "use strict";
139
140 let goodKeys = [
141 "0",
142 "100000",
143 "3000000000",
144 "5000000000"
145 ]
146
147 let badKeys = [
148 "bar",
149 "1",
150 "100001",
151 "3000000001",
152 "5000000001"
153 ];
154
155 let values = [
156 "string",
157 1,
158 100001,
159 30000000001,
160 50000000001,
161 NaN,
162 {},
163 undefined
164 ];
165
166 let badAccessorDescs = [
167 { set: (function(){}) },
168 { configurable: true, set: (function(){}) },
169 { configurable: true, enumerable: true, set: (function(){}) }
170 ];
171
172 let readSloppy = [
173 readFromObjectElementSloppy,
174 readFromObjectElementSparseSloppy,
175 readFromObjectElementNonSmiSloppy,
176 readFromObjectNonIndexSloppy,
177 readFromObjectElementVarSloppy,
178 readFromObjectElementSparseVarSloppy,
179 readFromObjectElementNonSmiVarSloppy,
180 readFromObjectNonIndexVarSloppy
181 ];
182
183 let readStrong = [
184 readFromObjectElementStrong,
185 readFromObjectElementSparseStrong,
186 readFromObjectElementNonSmiStrong,
187 readFromObjectNonIndexStrong,
188 readFromObjectElementLetStrong,
189 readFromObjectElementSparseLetStrong,
190 readFromObjectElementNonSmiLetStrong,
191 readFromObjectNonIndexLetStrong
192 ];
193
194 let dummyProto = {};
195 for (let key of goodKeys) {
196 Object.defineProperty(dummyProto, key, { value: undefined });
197 }
198
199 // After altering the backing store, accessing a missing property should still
200 // throw.
201 for (let key of badKeys) {
202 for (let value of values) {
203 for (let desc of getDescs(value)) {
204 for (let object of getObjects()) {
205 Object.defineProperty(object, key, desc);
206 for (let func of readStrong) {
207 assertStrongSemantics(func, object);
208 }
209 for (let func of readSloppy) {
210 assertSloppySemantics(func, object);
211 }
212 // Accessing a property which is on the prototype chain of the object
213 // should not throw.
214 object.__proto__ = dummyProto;
215 for (let key of goodKeys) {
216 for (let func of readStrong.concat(readSloppy)) {
217 assertSloppySemantics(func, object);
218 }
219 }
220 }
221 }
222 }
223 }
224 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698