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

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: trim linebreaks 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
« test/cctest/test-api.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
rossberg 2015/05/22 11:34:50 Instead of this, why not make the test below check
conradw 2015/05/22 13:37:57 It's kind of nasty because I interleave asserts th
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"];
rossberg 2015/05/22 11:34:50 Change this to an actual computation (e.g., Date()
conradw 2015/05/22 13:37:57 Done. Added as another case (want to keep both of
36 }
37
38 function deleteFromObjectKeyedVarSloppy(o) {
39 var a = "foo";
40 return delete o[a];
41 }
42
43 function deleteFromObjectWith(o) {
44 with(o){
45 return delete foo;
46 }
47 }
48
49 function deleteFromObjectStrict(o) {
50 "use strict";
51 return delete o.foo;
52 }
53
54 function deleteFromObjectKeyedStrict(o) {
55 "use strict";
56 return delete o["foo"];
57 }
58
59 function deleteFromObjectKeyedVarStrict(o) {
60 "use strict";
61 var a = "foo";
62 return delete o[a];
63 }
64
65 function testStrongObjectDelete() {
66 "use strict";
67 let sloppyObjects = getSloppyObjects();
68 let strictObjects = getStrictObjects();
69 let strongObjects = getStrongObjects();
70 let nonStrongObjects = sloppyObjects.concat(strictObjects);
71
72 let deleteFuncsSloppy = [deleteFromObjectSloppy, deleteFromObjectKeyedSloppy,
73 deleteFromObjectKeyedletSloppy, deleteFromObjectWith
74 ];
75 let deleteFuncsStrict = [deleteFromObjectStrict, deleteFromObjectKeyedStrict,
76 deleteFromObjectKeyedletStrict
77 ];
78
79 for (let deleteFunc of deleteFuncsSloppy) {
80 for (let o of nonStrongObjects) {
81 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
82 assertTrue(deleteFunc(o));
83 assertFalse(o.hasOwnProperty("foo"));
84 %OptimizeFunctionOnNextCall(deleteFunc);
85 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
86 assertTrue(deleteFunc(o));
87 assertFalse(o.hasOwnProperty("foo"));
88 %DeoptimizeFunction(deleteFunc);
89 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
90 assertTrue(deleteFunc(o));
91 assertFalse(o.hasOwnProperty("foo"));
92 }
93 for (let o of strongObjects) {
94 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
95 assertFalse(deleteFunc(o));
96 assertTrue(o.hasOwnProperty("foo"));
97 %OptimizeFunctionOnNextCall(deleteFunc);
98 assertFalse(deleteFunc(o));
99 assertTrue(o.hasOwnProperty("foo"));
100 %DeoptimizeFunction(deleteFunc);
101 assertFalse(deleteFunc(o));
102 assertTrue(o.hasOwnProperty("foo"));
103 assertTrue(delete o);
104 }
105 assertFalse(deleteFunc(strongFunction));
106 }
107 for (let deleteFunc of deleteFuncsStrict) {
108 for (let o of nonStrongObjects) {
109 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
110 assertTrue(deleteFunc(o));
111 assertFalse(o.hasOwnProperty("foo"));
112 %OptimizeFunctionOnNextCall(deleteFunc);
113 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
114 assertTrue(deleteFunc(o));
115 assertFalse(o.hasOwnProperty("foo"));
116 %DeoptimizeFunction(deleteFunc);
117 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
118 assertTrue(deleteFunc(o));
119 assertFalse(o.hasOwnProperty("foo"));
120 }
121 for (let o of strongObjects) {
122 Object.defineProperty(o, "foo", {configurable:true, value:"bar"});
123 assertThrows(deleteFunc(o), TypeError);
124 assertTrue(o.hasOwnProperty("foo"));
125 %OptimizeFunctionOnNextCall(deleteFunc);
126 assertThrows(deleteFunc(o), TypeError);
127 assertTrue(o.hasOwnProperty("foo"));
128 %DeoptimizeFunction(deleteFunc);
129 assertThrows(deleteFunc(o), TypeError);
130 assertTrue(o.hasOwnProperty("foo"));
131 assertTrue(delete o);
132 }
133 assertThrows(deleteFunc(strongFunction), TypeError);
134 }
135 }
136 testStrongObjectDelete();
OLDNEW
« test/cctest/test-api.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