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

Side by Side Diff: test/mjsunit/strong/load-property-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 readFromObjectSloppy(o) {
25 return o.foo;
26 }
27
28 function readFromObjectKeyedSloppy(o) {
29 return o["foo"];
30 }
31
32 function readFromObjectKeyedVarSloppy(o) {
33 var a = "foo";
34 return o[a];
35 }
36
37 function readFromObjectKeyedComputedSloppy(o) {
38 var a = "o";
39 return o["fo" + a];
40 }
41
42 function readFromObjectStrong(o) {
43 "use strong";
44 return o.foo;
45 }
46
47 function readFromObjectKeyedStrong(o) {
48 "use strong";
49 return o["foo"];
50 }
51
52 function readFromObjectKeyedLetStrong(o) {
53 "use strong";
54 let a = "foo";
55 return o[a];
56 }
57
58 function readFromObjectKeyedComputedStrong(o) {
59 "use strong";
60 let a = "o";
61 return o["fo" + a];
62 }
63
64 function getDescs(x) {
65 return [
66 {value: x},
67 {configurable: true, value: x},
68 {configurable: true, enumerable: true, writable: true, value: x},
69 {configurable: true, enumerable: true, get: (function() {return x}) },
70 ];
71 }
72
73 function assertStrongSemantics(func, object) {
74 %DeoptimizeFunction(func);
75 %ClearFunctionTypeFeedback(func);
76 assertThrows(function(){func(object)}, TypeError);
77 assertThrows(function(){func(object)}, TypeError);
78 assertThrows(function(){func(object)}, TypeError);
79 %OptimizeFunctionOnNextCall(func);
80 assertThrows(function(){func(object)}, TypeError);
81 %DeoptimizeFunction(func);
82 assertThrows(function(){func(object)}, TypeError);
83 }
84
85 function assertSloppySemantics(func, object) {
86 %DeoptimizeFunction(func);
87 %ClearFunctionTypeFeedback(func);
88 assertDoesNotThrow(function(){func(object)});
89 assertDoesNotThrow(function(){func(object)});
90 assertDoesNotThrow(function(){func(object)});
91 %OptimizeFunctionOnNextCall(func);
92 assertDoesNotThrow(function(){func(object)});
93 %DeoptimizeFunction(func);
94 assertDoesNotThrow(function(){func(object)});
95 }
96
97 (function () {
98 "use strict";
99
100 let goodKeys = [
101 "foo"
102 ]
103
104 let badKeys = [
105 "bar",
106 "1",
107 "100001",
108 "3000000001",
109 "5000000001"
110 ];
111
112 let values = [
113 "string",
114 1,
115 100001,
116 30000000001,
117 50000000001,
118 NaN,
119 {},
120 undefined
121 ];
122
123 let badAccessorDescs = [
124 { set: (function(){}) },
125 { configurable: true, set: (function(){}) },
126 { configurable: true, enumerable: true, set: (function(){}) }
127 ];
128
129 let readSloppy = [
130 readFromObjectSloppy,
131 readFromObjectKeyedSloppy,
132 readFromObjectKeyedVarSloppy,
133 readFromObjectKeyedComputedSloppy
134 ];
135
136 let readStrong = [
137 readFromObjectStrong,
138 readFromObjectKeyedStrong,
139 readFromObjectKeyedLetStrong,
140 readFromObjectKeyedComputedStrong
141 ];
142
143 let dummyProto = {};
144 for (let key of goodKeys) {
145 Object.defineProperty(dummyProto, key, { value: undefined });
146 }
147
148 // After altering the backing store, accessing a missing property should still
149 // throw.
150 for (let key of badKeys) {
151 for (let value of values) {
152 for (let desc of getDescs(value)) {
153 for (let object of getObjects()) {
154 print(object);
rossberg 2015/06/11 09:36:34 Stray debug output?
conradw 2015/06/11 13:48:32 Done.
155 Object.defineProperty(object, key, desc);
156 for (let func of readStrong) {
157 assertStrongSemantics(func, object);
158 }
159 for (let func of readSloppy) {
160 assertSloppySemantics(func, object);
161 }
162 // Accessing a property which is on the prototype chain of the object
163 // should not throw.
164 object.__proto__ = dummyProto;
165 for (let key of goodKeys) {
166 for (let func of readStrong.concat(readSloppy)) {
167 assertSloppySemantics(func, object);
168 }
169 }
170 }
171 }
172 }
173 }
174 })();
OLDNEW
« no previous file with comments | « test/mjsunit/strong/load-property.js ('k') | test/unittests/compiler/js-type-feedback-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698