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

Side by Side Diff: test/mjsunit/strong/load-element.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 literals = [0, NaN, true, ""];
167
168 let badAccessorDescs = [
169 { set: (function(){}) },
170 { configurable: true, set: (function(){}) },
171 { configurable: true, enumerable: true, set: (function(){}) }
172 ];
173
174 let readSloppy = [
175 readFromObjectElementSloppy,
176 readFromObjectElementSparseSloppy,
177 readFromObjectElementNonSmiSloppy,
178 readFromObjectNonIndexSloppy,
179 readFromObjectElementVarSloppy,
180 readFromObjectElementSparseVarSloppy,
181 readFromObjectElementNonSmiVarSloppy,
182 readFromObjectNonIndexVarSloppy
183 ];
184
185 let readStrong = [
186 readFromObjectElementStrong,
187 readFromObjectElementSparseStrong,
188 readFromObjectElementNonSmiStrong,
189 readFromObjectNonIndexStrong,
190 readFromObjectElementLetStrong,
191 readFromObjectElementSparseLetStrong,
192 readFromObjectElementNonSmiLetStrong,
193 readFromObjectNonIndexLetStrong
194 ];
195
196 let dummyProto = {};
197 for (let key of goodKeys) {
198 Object.defineProperty(dummyProto, key, { value: undefined });
199 }
200
201 let dummyAccessorProto = {};
202 for (let key of goodKeys) {
203 Object.defineProperty(dummyAccessorProto, key, { set: (function(){}) })
204 }
205
206 // String literals/objects should not throw on character index access
207 assertDoesNotThrow(function() {"use strong"; return "string"[0]; });
208 assertDoesNotThrow(function() {"use strong"; return Object("string")[0]; });
209
210 // Attempting to access a property on an object with no defined properties
211 // should throw.
212 for (let object of getObjects().concat(literals)) {
213 for (let func of readStrong) {
214 assertStrongSemantics(func, object);
215 }
216 for (let func of readSloppy) {
217 assertSloppySemantics(func, object);
218 }
219 }
220 for (let object of getObjects()) {
221 // Accessing a property which is on the prototype chain of the object should
222 // not throw.
223 object.__proto__ = dummyProto;
224 for (let key of goodKeys) {
225 for (let func of readStrong.concat(readSloppy)) {
226 assertSloppySemantics(func, object);
227 }
228 }
229 }
230 // Properties with accessor descriptors missing 'get' should throw on access.
231 for (let desc of badAccessorDescs) {
232 for (let key of goodKeys) {
233 for (let object of getObjects()) {
234 Object.defineProperty(object, key, desc);
235 for (let func of readStrong) {
236 assertStrongSemantics(func, object);
237 }
238 for (let func of readSloppy) {
239 assertSloppySemantics(func, object);
240 }
241 }
242 }
243 }
244 // The same behaviour should be expected for bad accessor properties on the
245 // prototype chain.
246 for (let object of getObjects()) {
247 object.__proto__ = dummyAccessorProto;
248 for (let func of readStrong) {
249 assertStrongSemantics(func, object);
250 }
251 for (let func of readSloppy) {
252 assertSloppySemantics(func, object);
253 }
254 }
255 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698