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

Side by Side Diff: test/mjsunit/strong/object-delete.js

Issue 1156573002: [strong] Implement per-object restrictions behaviour of delete operator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback Created 5 years, 7 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
« src/elements.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(conradw): Track implementation of strong bit for other objects, add
8 // tests.
9
10 function getSloppyObjects() {
11 return [(function(){}), ({})];
12 }
13
14 function getStrictObjects() {
15 "use strict";
16 return [(function(){}), ({})];
17 }
18
19 function getStrongObjects() {
20 "use strong";
21 // Strong functions can't have properties added to them, and will be tested as a
22 // special case.
23 return [({})];
24 }
25
26 function strongFunction() {
27 "use strong";
28 }
29
30 function deleteFromObjectSloppy(o) {
31 return delete o.foo;
32 }
33
34 function deleteFromObjectKeyedSloppy(o) {
35 return delete o["foo"];
36 }
37
38 function deleteFromObjectKeyedVarSloppy(o) {
39 var a = "foo";
40 return delete o[a];
41 }
42
43 function deleteFromObjectKeyedComputedSloppy(o) {
44 return delete o[Date()+""];
45 }
46
47 function deleteFromObjectWith(o) {
48 with(o) {
49 return delete foo;
50 }
51 }
52
53 function deleteFromObjectStrict(o) {
54 "use strict";
55 return delete o.foo;
56 }
57
58 function deleteFromObjectKeyedStrict(o) {
59 "use strict";
60 return delete o["foo"];
61 }
62
63 function deleteFromObjectKeyedVarStrict(o) {
64 "use strict";
65 var a = "foo";
66 return delete o[a];
67 }
68
69 function deleteFromObjectKeyedComputedStrict(o) {
70 "use strict";
71 return delete o[Date()+""];
72 }
73
74 function testStrongObjectDelete() {
75 "use strict";
76 let sloppyObjects = getSloppyObjects();
77 let strictObjects = getStrictObjects();
78 let strongObjects = getStrongObjects();
79 let nonStrongObjects = sloppyObjects.concat(strictObjects);
80
81 let deleteFuncsSloppy = [deleteFromObjectSloppy, deleteFromObjectKeyedSloppy,
82 deleteFromObjectKeyedVarSloppy,
83 deleteFromObjectKeyedComputedSloppy,
84 deleteFromObjectWith
85 ];
86 let deleteFuncsStrict = [deleteFromObjectStrict, deleteFromObjectKeyedStrict,
87 deleteFromObjectKeyedVarStrict,
88 deleteFromObjectKeyedComputedStrict
89 ];
90
91 for (let deleteFunc of deleteFuncsSloppy) {
92 for (let o of nonStrongObjects) {
93 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
94 assertTrue(deleteFunc(o));
95 assertFalse(o.hasOwnProperty("foo"));
96 %OptimizeFunctionOnNextCall(deleteFunc);
97 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
98 assertTrue(deleteFunc(o));
99 assertFalse(o.hasOwnProperty("foo"));
100 %DeoptimizeFunction(deleteFunc);
101 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
102 assertTrue(deleteFunc(o));
103 assertFalse(o.hasOwnProperty("foo"));
104 }
105 for (let o of strongObjects) {
106 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
107 assertFalse(deleteFunc(o));
108 assertTrue(o.hasOwnProperty("foo"));
109 %OptimizeFunctionOnNextCall(deleteFunc);
110 assertFalse(deleteFunc(o));
111 assertTrue(o.hasOwnProperty("foo"));
112 %DeoptimizeFunction(deleteFunc);
113 assertFalse(deleteFunc(o));
114 assertTrue(o.hasOwnProperty("foo"));
115 assertTrue(delete o);
rossberg 2015/05/22 14:01:26 I'm confused, shouldn't this be a SyntaxError in s
conradw 2015/05/27 18:09:32 Yes, mistake here. I can't actually run the strong
116 }
117 assertFalse(deleteFunc(strongFunction));
118 }
119 for (let deleteFunc of deleteFuncsStrict) {
120 for (let o of nonStrongObjects) {
121 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
122 assertTrue(deleteFunc(o));
123 assertFalse(o.hasOwnProperty("foo"));
124 %OptimizeFunctionOnNextCall(deleteFunc);
125 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
126 assertTrue(deleteFunc(o));
127 assertFalse(o.hasOwnProperty("foo"));
128 %DeoptimizeFunction(deleteFunc);
129 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
130 assertTrue(deleteFunc(o));
131 assertFalse(o.hasOwnProperty("foo"));
132 }
133 for (let o of strongObjects) {
134 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
135 assertThrows(deleteFunc(o), TypeError);
136 assertTrue(o.hasOwnProperty("foo"));
137 %OptimizeFunctionOnNextCall(deleteFunc);
138 assertThrows(deleteFunc(o), TypeError);
139 assertTrue(o.hasOwnProperty("foo"));
140 %DeoptimizeFunction(deleteFunc);
141 assertThrows(deleteFunc(o), TypeError);
142 assertTrue(o.hasOwnProperty("foo"));
143 assertTrue(delete o);
144 }
145 assertThrows(deleteFunc(strongFunction), TypeError);
146 }
147 }
148 testStrongObjectDelete();
rossberg 2015/05/22 14:01:26 It seems we don't have tests for redundant deletes
conradw 2015/05/27 18:09:33 Done, I thought they should fail (and should have
OLDNEW
« src/elements.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698