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

Side by Side Diff: test/cctest/test-object-observe.cc

Issue 190853007: Revert "Enable Object.observe by default" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-microtask-delivery.cc ('k') | test/mjsunit/debug-script.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "cctest.h" 30 #include "cctest.h"
31 31
32 using namespace v8; 32 using namespace v8;
33 namespace i = v8::internal; 33 namespace i = v8::internal;
34 34
35 namespace {
36 // Need to create a new isolate when FLAG_harmony_observation is on.
37 class HarmonyIsolate {
38 public:
39 HarmonyIsolate() {
40 i::FLAG_harmony_observation = true;
41 isolate_ = Isolate::New();
42 isolate_->Enter();
43 }
44
45 ~HarmonyIsolate() {
46 isolate_->Exit();
47 isolate_->Dispose();
48 }
49
50 Isolate* GetIsolate() const { return isolate_; }
51
52 private:
53 Isolate* isolate_;
54 };
55 }
56
35 57
36 TEST(PerIsolateState) { 58 TEST(PerIsolateState) {
37 HandleScope scope(CcTest::isolate()); 59 HarmonyIsolate isolate;
38 LocalContext context1(CcTest::isolate()); 60 HandleScope scope(isolate.GetIsolate());
61 LocalContext context1(isolate.GetIsolate());
39 CompileRun( 62 CompileRun(
40 "var count = 0;" 63 "var count = 0;"
41 "var calls = 0;" 64 "var calls = 0;"
42 "var observer = function(records) { count = records.length; calls++ };" 65 "var observer = function(records) { count = records.length; calls++ };"
43 "var obj = {};" 66 "var obj = {};"
44 "Object.observe(obj, observer);"); 67 "Object.observe(obj, observer);");
45 Handle<Value> observer = CompileRun("observer"); 68 Handle<Value> observer = CompileRun("observer");
46 Handle<Value> obj = CompileRun("obj"); 69 Handle<Value> obj = CompileRun("obj");
47 Handle<Value> notify_fun1 = CompileRun( 70 Handle<Value> notify_fun1 = CompileRun(
48 "(function() { obj.foo = 'bar'; })"); 71 "(function() { obj.foo = 'bar'; })");
49 Handle<Value> notify_fun2; 72 Handle<Value> notify_fun2;
50 { 73 {
51 LocalContext context2(CcTest::isolate()); 74 LocalContext context2(isolate.GetIsolate());
52 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 75 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
53 obj); 76 obj);
54 notify_fun2 = CompileRun( 77 notify_fun2 = CompileRun(
55 "(function() { obj.foo = 'baz'; })"); 78 "(function() { obj.foo = 'baz'; })");
56 } 79 }
57 Handle<Value> notify_fun3; 80 Handle<Value> notify_fun3;
58 { 81 {
59 LocalContext context3(CcTest::isolate()); 82 LocalContext context3(isolate.GetIsolate());
60 context3->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 83 context3->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
61 obj); 84 obj);
62 notify_fun3 = CompileRun( 85 notify_fun3 = CompileRun(
63 "(function() { obj.foo = 'bat'; })"); 86 "(function() { obj.foo = 'bat'; })");
64 } 87 }
65 { 88 {
66 LocalContext context4(CcTest::isolate()); 89 LocalContext context4(isolate.GetIsolate());
67 context4->Global()->Set( 90 context4->Global()->Set(
68 String::NewFromUtf8(CcTest::isolate(), "observer"), observer); 91 String::NewFromUtf8(isolate.GetIsolate(), "observer"), observer);
69 context4->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "fun1"), 92 context4->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "fun1"),
70 notify_fun1); 93 notify_fun1);
71 context4->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "fun2"), 94 context4->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "fun2"),
72 notify_fun2); 95 notify_fun2);
73 context4->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "fun3"), 96 context4->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "fun3"),
74 notify_fun3); 97 notify_fun3);
75 CompileRun("fun1(); fun2(); fun3(); Object.deliverChangeRecords(observer)"); 98 CompileRun("fun1(); fun2(); fun3(); Object.deliverChangeRecords(observer)");
76 } 99 }
77 CHECK_EQ(1, CompileRun("calls")->Int32Value()); 100 CHECK_EQ(1, CompileRun("calls")->Int32Value());
78 CHECK_EQ(3, CompileRun("count")->Int32Value()); 101 CHECK_EQ(3, CompileRun("count")->Int32Value());
79 } 102 }
80 103
81 104
82 TEST(EndOfMicrotaskDelivery) { 105 TEST(EndOfMicrotaskDelivery) {
83 HandleScope scope(CcTest::isolate()); 106 HarmonyIsolate isolate;
84 LocalContext context(CcTest::isolate()); 107 HandleScope scope(isolate.GetIsolate());
108 LocalContext context(isolate.GetIsolate());
85 CompileRun( 109 CompileRun(
86 "var obj = {};" 110 "var obj = {};"
87 "var count = 0;" 111 "var count = 0;"
88 "var observer = function(records) { count = records.length };" 112 "var observer = function(records) { count = records.length };"
89 "Object.observe(obj, observer);" 113 "Object.observe(obj, observer);"
90 "obj.foo = 'bar';"); 114 "obj.foo = 'bar';");
91 CHECK_EQ(1, CompileRun("count")->Int32Value()); 115 CHECK_EQ(1, CompileRun("count")->Int32Value());
92 } 116 }
93 117
94 118
95 TEST(DeliveryOrdering) { 119 TEST(DeliveryOrdering) {
96 HandleScope scope(CcTest::isolate()); 120 HarmonyIsolate isolate;
97 LocalContext context(CcTest::isolate()); 121 HandleScope scope(isolate.GetIsolate());
122 LocalContext context(isolate.GetIsolate());
98 CompileRun( 123 CompileRun(
99 "var obj1 = {};" 124 "var obj1 = {};"
100 "var obj2 = {};" 125 "var obj2 = {};"
101 "var ordering = [];" 126 "var ordering = [];"
102 "function observer2() { ordering.push(2); };" 127 "function observer2() { ordering.push(2); };"
103 "function observer1() { ordering.push(1); };" 128 "function observer1() { ordering.push(1); };"
104 "function observer3() { ordering.push(3); };" 129 "function observer3() { ordering.push(3); };"
105 "Object.observe(obj1, observer1);" 130 "Object.observe(obj1, observer1);"
106 "Object.observe(obj1, observer2);" 131 "Object.observe(obj1, observer2);"
107 "Object.observe(obj1, observer3);" 132 "Object.observe(obj1, observer3);"
108 "obj1.foo = 'bar';"); 133 "obj1.foo = 'bar';");
109 CHECK_EQ(3, CompileRun("ordering.length")->Int32Value()); 134 CHECK_EQ(3, CompileRun("ordering.length")->Int32Value());
110 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); 135 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value());
111 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); 136 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
112 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); 137 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value());
113 CompileRun( 138 CompileRun(
114 "ordering = [];" 139 "ordering = [];"
115 "Object.observe(obj2, observer3);" 140 "Object.observe(obj2, observer3);"
116 "Object.observe(obj2, observer2);" 141 "Object.observe(obj2, observer2);"
117 "Object.observe(obj2, observer1);" 142 "Object.observe(obj2, observer1);"
118 "obj2.foo = 'baz'"); 143 "obj2.foo = 'baz'");
119 CHECK_EQ(3, CompileRun("ordering.length")->Int32Value()); 144 CHECK_EQ(3, CompileRun("ordering.length")->Int32Value());
120 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); 145 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value());
121 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); 146 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
122 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); 147 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value());
123 } 148 }
124 149
125 150
126 TEST(DeliveryOrderingReentrant) { 151 TEST(DeliveryOrderingReentrant) {
127 HandleScope scope(CcTest::isolate()); 152 HarmonyIsolate isolate;
128 LocalContext context(CcTest::isolate()); 153 HandleScope scope(isolate.GetIsolate());
154 LocalContext context(isolate.GetIsolate());
129 CompileRun( 155 CompileRun(
130 "var obj = {};" 156 "var obj = {};"
131 "var reentered = false;" 157 "var reentered = false;"
132 "var ordering = [];" 158 "var ordering = [];"
133 "function observer1() { ordering.push(1); };" 159 "function observer1() { ordering.push(1); };"
134 "function observer2() {" 160 "function observer2() {"
135 " if (!reentered) {" 161 " if (!reentered) {"
136 " obj.foo = 'baz';" 162 " obj.foo = 'baz';"
137 " reentered = true;" 163 " reentered = true;"
138 " }" 164 " }"
139 " ordering.push(2);" 165 " ordering.push(2);"
140 "};" 166 "};"
141 "function observer3() { ordering.push(3); };" 167 "function observer3() { ordering.push(3); };"
142 "Object.observe(obj, observer1);" 168 "Object.observe(obj, observer1);"
143 "Object.observe(obj, observer2);" 169 "Object.observe(obj, observer2);"
144 "Object.observe(obj, observer3);" 170 "Object.observe(obj, observer3);"
145 "obj.foo = 'bar';"); 171 "obj.foo = 'bar';");
146 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value()); 172 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value());
147 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); 173 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value());
148 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); 174 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
149 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); 175 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value());
150 // Note that we re-deliver to observers 1 and 2, while observer3 176 // Note that we re-deliver to observers 1 and 2, while observer3
151 // already received the second record during the first round. 177 // already received the second record during the first round.
152 CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value()); 178 CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value());
153 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); 179 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value());
154 } 180 }
155 181
156 182
157 TEST(DeliveryOrderingDeliverChangeRecords) { 183 TEST(DeliveryOrderingDeliverChangeRecords) {
158 HandleScope scope(CcTest::isolate()); 184 HarmonyIsolate isolate;
159 LocalContext context(CcTest::isolate()); 185 HandleScope scope(isolate.GetIsolate());
186 LocalContext context(isolate.GetIsolate());
160 CompileRun( 187 CompileRun(
161 "var obj = {};" 188 "var obj = {};"
162 "var ordering = [];" 189 "var ordering = [];"
163 "function observer1() { ordering.push(1); if (!obj.b) obj.b = true };" 190 "function observer1() { ordering.push(1); if (!obj.b) obj.b = true };"
164 "function observer2() { ordering.push(2); };" 191 "function observer2() { ordering.push(2); };"
165 "Object.observe(obj, observer1);" 192 "Object.observe(obj, observer1);"
166 "Object.observe(obj, observer2);" 193 "Object.observe(obj, observer2);"
167 "obj.a = 1;" 194 "obj.a = 1;"
168 "Object.deliverChangeRecords(observer2);"); 195 "Object.deliverChangeRecords(observer2);");
169 CHECK_EQ(4, CompileRun("ordering.length")->Int32Value()); 196 CHECK_EQ(4, CompileRun("ordering.length")->Int32Value());
170 // First, observer2 is called due to deliverChangeRecords 197 // First, observer2 is called due to deliverChangeRecords
171 CHECK_EQ(2, CompileRun("ordering[0]")->Int32Value()); 198 CHECK_EQ(2, CompileRun("ordering[0]")->Int32Value());
172 // Then, observer1 is called when the stack unwinds 199 // Then, observer1 is called when the stack unwinds
173 CHECK_EQ(1, CompileRun("ordering[1]")->Int32Value()); 200 CHECK_EQ(1, CompileRun("ordering[1]")->Int32Value());
174 // observer1's mutation causes both 1 and 2 to be reactivated, 201 // observer1's mutation causes both 1 and 2 to be reactivated,
175 // with 1 having priority. 202 // with 1 having priority.
176 CHECK_EQ(1, CompileRun("ordering[2]")->Int32Value()); 203 CHECK_EQ(1, CompileRun("ordering[2]")->Int32Value());
177 CHECK_EQ(2, CompileRun("ordering[3]")->Int32Value()); 204 CHECK_EQ(2, CompileRun("ordering[3]")->Int32Value());
178 } 205 }
179 206
180 207
181 TEST(ObjectHashTableGrowth) { 208 TEST(ObjectHashTableGrowth) {
182 HandleScope scope(CcTest::isolate()); 209 HarmonyIsolate isolate;
210 HandleScope scope(isolate.GetIsolate());
183 // Initializing this context sets up initial hash tables. 211 // Initializing this context sets up initial hash tables.
184 LocalContext context(CcTest::isolate()); 212 LocalContext context(isolate.GetIsolate());
185 Handle<Value> obj = CompileRun("obj = {};"); 213 Handle<Value> obj = CompileRun("obj = {};");
186 Handle<Value> observer = CompileRun( 214 Handle<Value> observer = CompileRun(
187 "var ran = false;" 215 "var ran = false;"
188 "(function() { ran = true })"); 216 "(function() { ran = true })");
189 { 217 {
190 // As does initializing this context. 218 // As does initializing this context.
191 LocalContext context2(CcTest::isolate()); 219 LocalContext context2(isolate.GetIsolate());
192 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 220 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
193 obj); 221 obj);
194 context2->Global()->Set( 222 context2->Global()->Set(
195 String::NewFromUtf8(CcTest::isolate(), "observer"), observer); 223 String::NewFromUtf8(isolate.GetIsolate(), "observer"), observer);
196 CompileRun( 224 CompileRun(
197 "var objArr = [];" 225 "var objArr = [];"
198 // 100 objects should be enough to make the hash table grow 226 // 100 objects should be enough to make the hash table grow
199 // (and thus relocate). 227 // (and thus relocate).
200 "for (var i = 0; i < 100; ++i) {" 228 "for (var i = 0; i < 100; ++i) {"
201 " objArr.push({});" 229 " objArr.push({});"
202 " Object.observe(objArr[objArr.length-1], function(){});" 230 " Object.observe(objArr[objArr.length-1], function(){});"
203 "}" 231 "}"
204 "Object.observe(obj, observer);"); 232 "Object.observe(obj, observer);");
205 } 233 }
206 // obj is now marked "is_observed", but our map has moved. 234 // obj is now marked "is_observed", but our map has moved.
207 CompileRun("obj.foo = 'bar'"); 235 CompileRun("obj.foo = 'bar'");
208 CHECK(CompileRun("ran")->BooleanValue()); 236 CHECK(CompileRun("ran")->BooleanValue());
209 } 237 }
210 238
211 239
212 TEST(GlobalObjectObservation) { 240 TEST(GlobalObjectObservation) {
213 LocalContext context(CcTest::isolate()); 241 HarmonyIsolate isolate;
214 HandleScope scope(CcTest::isolate()); 242 LocalContext context(isolate.GetIsolate());
243 HandleScope scope(isolate.GetIsolate());
215 Handle<Object> global_proxy = context->Global(); 244 Handle<Object> global_proxy = context->Global();
216 CompileRun( 245 CompileRun(
217 "var records = [];" 246 "var records = [];"
218 "var global = this;" 247 "var global = this;"
219 "Object.observe(global, function(r) { [].push.apply(records, r) });" 248 "Object.observe(global, function(r) { [].push.apply(records, r) });"
220 "global.foo = 'hello';"); 249 "global.foo = 'hello';");
221 CHECK_EQ(1, CompileRun("records.length")->Int32Value()); 250 CHECK_EQ(1, CompileRun("records.length")->Int32Value());
222 CHECK(global_proxy->StrictEquals(CompileRun("records[0].object"))); 251 CHECK(global_proxy->StrictEquals(CompileRun("records[0].object")));
223 252
224 // Detached, mutating the proxy has no effect. 253 // Detached, mutating the proxy has no effect.
225 context->DetachGlobal(); 254 context->DetachGlobal();
226 CompileRun("global.bar = 'goodbye';"); 255 CompileRun("global.bar = 'goodbye';");
227 CHECK_EQ(1, CompileRun("records.length")->Int32Value()); 256 CHECK_EQ(1, CompileRun("records.length")->Int32Value());
228 CompileRun("this.baz = 'goodbye';"); 257 CompileRun("this.baz = 'goodbye';");
229 CHECK_EQ(1, CompileRun("records.length")->Int32Value()); 258 CHECK_EQ(1, CompileRun("records.length")->Int32Value());
230 259
231 // Attached to a different context, should not leak mutations 260 // Attached to a different context, should not leak mutations
232 // to the old context. 261 // to the old context.
233 context->DetachGlobal(); 262 context->DetachGlobal();
234 { 263 {
235 LocalContext context2(CcTest::isolate()); 264 LocalContext context2(isolate.GetIsolate());
236 CompileRun( 265 CompileRun(
237 "var records2 = [];" 266 "var records2 = [];"
238 "var global = this;" 267 "var global = this;"
239 "Object.observe(this, function(r) { [].push.apply(records2, r) });" 268 "Object.observe(this, function(r) { [].push.apply(records2, r) });"
240 "this.v1 = 'context2';"); 269 "this.v1 = 'context2';");
241 context2->DetachGlobal(); 270 context2->DetachGlobal();
242 CompileRun( 271 CompileRun(
243 "global.v2 = 'context2';" 272 "global.v2 = 'context2';"
244 "this.v3 = 'context2';"); 273 "this.v3 = 'context2';");
245 CHECK_EQ(1, CompileRun("records2.length")->Int32Value()); 274 CHECK_EQ(1, CompileRun("records2.length")->Int32Value());
246 } 275 }
247 CHECK_EQ(1, CompileRun("records.length")->Int32Value()); 276 CHECK_EQ(1, CompileRun("records.length")->Int32Value());
248 277
249 // Attaching by passing to Context::New 278 // Attaching by passing to Context::New
250 { 279 {
251 // Delegates to Context::New 280 // Delegates to Context::New
252 LocalContext context3( 281 LocalContext context3(
253 CcTest::isolate(), NULL, Handle<ObjectTemplate>(), global_proxy); 282 isolate.GetIsolate(), NULL, Handle<ObjectTemplate>(), global_proxy);
254 CompileRun( 283 CompileRun(
255 "var records3 = [];" 284 "var records3 = [];"
256 "Object.observe(this, function(r) { [].push.apply(records3, r) });" 285 "Object.observe(this, function(r) { [].push.apply(records3, r) });"
257 "this.qux = 'context3';"); 286 "this.qux = 'context3';");
258 CHECK_EQ(1, CompileRun("records3.length")->Int32Value()); 287 CHECK_EQ(1, CompileRun("records3.length")->Int32Value());
259 CHECK(global_proxy->StrictEquals(CompileRun("records3[0].object"))); 288 CHECK(global_proxy->StrictEquals(CompileRun("records3[0].object")));
260 } 289 }
261 CHECK_EQ(1, CompileRun("records.length")->Int32Value()); 290 CHECK_EQ(1, CompileRun("records.length")->Int32Value());
262 } 291 }
263 292
(...skipping 27 matching lines...) Expand all
291 recordObj->Get(String::NewFromUtf8(isolate, "name")))); 320 recordObj->Get(String::NewFromUtf8(isolate, "name"))));
292 if (!expectations[i].old_value.IsEmpty()) { 321 if (!expectations[i].old_value.IsEmpty()) {
293 CHECK(expectations[i].old_value->Equals( 322 CHECK(expectations[i].old_value->Equals(
294 recordObj->Get(String::NewFromUtf8(isolate, "oldValue")))); 323 recordObj->Get(String::NewFromUtf8(isolate, "oldValue"))));
295 } 324 }
296 } 325 }
297 } 326 }
298 } 327 }
299 328
300 #define EXPECT_RECORDS(records, expectations) \ 329 #define EXPECT_RECORDS(records, expectations) \
301 ExpectRecords(CcTest::isolate(), records, expectations, \ 330 ExpectRecords(isolate.GetIsolate(), records, expectations, \
302 ARRAY_SIZE(expectations)) 331 ARRAY_SIZE(expectations))
303 332
304 TEST(APITestBasicMutation) { 333 TEST(APITestBasicMutation) {
305 v8::Isolate* v8_isolate = CcTest::isolate(); 334 HarmonyIsolate isolate;
335 v8::Isolate* v8_isolate = isolate.GetIsolate();
306 HandleScope scope(v8_isolate); 336 HandleScope scope(v8_isolate);
307 LocalContext context(v8_isolate); 337 LocalContext context(v8_isolate);
308 Handle<Object> obj = Handle<Object>::Cast(CompileRun( 338 Handle<Object> obj = Handle<Object>::Cast(CompileRun(
309 "var records = [];" 339 "var records = [];"
310 "var obj = {};" 340 "var obj = {};"
311 "function observer(r) { [].push.apply(records, r); };" 341 "function observer(r) { [].push.apply(records, r); };"
312 "Object.observe(obj, observer);" 342 "Object.observe(obj, observer);"
313 "obj")); 343 "obj"));
314 obj->Set(String::NewFromUtf8(v8_isolate, "foo"), 344 obj->Set(String::NewFromUtf8(v8_isolate, "foo"),
315 Number::New(v8_isolate, 7)); 345 Number::New(v8_isolate, 7));
(...skipping 26 matching lines...) Expand all
342 { obj, "add", "1.1", Handle<Value>() }, 372 { obj, "add", "1.1", Handle<Value>() },
343 { obj, "delete", "foo", Number::New(v8_isolate, 3) }, 373 { obj, "delete", "foo", Number::New(v8_isolate, 3) },
344 { obj, "delete", "1", Number::New(v8_isolate, 5) }, 374 { obj, "delete", "1", Number::New(v8_isolate, 5) },
345 { obj, "delete", "1.1", Number::New(v8_isolate, 6) } 375 { obj, "delete", "1.1", Number::New(v8_isolate, 6) }
346 }; 376 };
347 EXPECT_RECORDS(CompileRun("records"), expected_records); 377 EXPECT_RECORDS(CompileRun("records"), expected_records);
348 } 378 }
349 379
350 380
351 TEST(HiddenPrototypeObservation) { 381 TEST(HiddenPrototypeObservation) {
352 v8::Isolate* v8_isolate = CcTest::isolate(); 382 HarmonyIsolate isolate;
383 v8::Isolate* v8_isolate = isolate.GetIsolate();
353 HandleScope scope(v8_isolate); 384 HandleScope scope(v8_isolate);
354 LocalContext context(v8_isolate); 385 LocalContext context(v8_isolate);
355 Handle<FunctionTemplate> tmpl = FunctionTemplate::New(v8_isolate); 386 Handle<FunctionTemplate> tmpl = FunctionTemplate::New(v8_isolate);
356 tmpl->SetHiddenPrototype(true); 387 tmpl->SetHiddenPrototype(true);
357 tmpl->InstanceTemplate()->Set( 388 tmpl->InstanceTemplate()->Set(
358 String::NewFromUtf8(v8_isolate, "foo"), Number::New(v8_isolate, 75)); 389 String::NewFromUtf8(v8_isolate, "foo"), Number::New(v8_isolate, 75));
359 Handle<Object> proto = tmpl->GetFunction()->NewInstance(); 390 Handle<Object> proto = tmpl->GetFunction()->NewInstance();
360 Handle<Object> obj = Object::New(v8_isolate); 391 Handle<Object> obj = Object::New(v8_isolate);
361 obj->SetPrototype(proto); 392 obj->SetPrototype(proto);
362 context->Global()->Set(String::NewFromUtf8(v8_isolate, "obj"), obj); 393 context->Global()->Set(String::NewFromUtf8(v8_isolate, "obj"), obj);
(...skipping 30 matching lines...) Expand all
393 EXPECT_RECORDS(CompileRun("records"), expected_records3); 424 EXPECT_RECORDS(CompileRun("records"), expected_records3);
394 } 425 }
395 426
396 427
397 static int NumberOfElements(i::Handle<i::JSWeakMap> map) { 428 static int NumberOfElements(i::Handle<i::JSWeakMap> map) {
398 return i::ObjectHashTable::cast(map->table())->NumberOfElements(); 429 return i::ObjectHashTable::cast(map->table())->NumberOfElements();
399 } 430 }
400 431
401 432
402 TEST(ObservationWeakMap) { 433 TEST(ObservationWeakMap) {
403 HandleScope scope(CcTest::isolate()); 434 HarmonyIsolate isolate;
404 LocalContext context(CcTest::isolate()); 435 HandleScope scope(isolate.GetIsolate());
436 LocalContext context(isolate.GetIsolate());
405 CompileRun( 437 CompileRun(
406 "var obj = {};" 438 "var obj = {};"
407 "Object.observe(obj, function(){});" 439 "Object.observe(obj, function(){});"
408 "Object.getNotifier(obj);" 440 "Object.getNotifier(obj);"
409 "obj = null;"); 441 "obj = null;");
410 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(CcTest::isolate()); 442 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate.GetIsolate());
411 i::Handle<i::JSObject> observation_state = 443 i::Handle<i::JSObject> observation_state =
412 i_isolate->factory()->observation_state(); 444 i_isolate->factory()->observation_state();
413 i::Handle<i::JSWeakMap> callbackInfoMap = 445 i::Handle<i::JSWeakMap> callbackInfoMap =
414 i::Handle<i::JSWeakMap>::cast( 446 i::Handle<i::JSWeakMap>::cast(
415 i::GetProperty(observation_state, "callbackInfoMap")); 447 i::GetProperty(observation_state, "callbackInfoMap"));
416 i::Handle<i::JSWeakMap> objectInfoMap = 448 i::Handle<i::JSWeakMap> objectInfoMap =
417 i::Handle<i::JSWeakMap>::cast( 449 i::Handle<i::JSWeakMap>::cast(
418 i::GetProperty(observation_state, "objectInfoMap")); 450 i::GetProperty(observation_state, "objectInfoMap"));
419 i::Handle<i::JSWeakMap> notifierObjectInfoMap = 451 i::Handle<i::JSWeakMap> notifierObjectInfoMap =
420 i::Handle<i::JSWeakMap>::cast( 452 i::Handle<i::JSWeakMap>::cast(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 tmpl->SetAccessCheckCallbacks(namedCallback, indexedCallback, data); 521 tmpl->SetAccessCheckCallbacks(namedCallback, indexedCallback, data);
490 Handle<Object> instance = tmpl->NewInstance(); 522 Handle<Object> instance = tmpl->NewInstance();
491 Handle<Object> global = instance->CreationContext()->Global(); 523 Handle<Object> global = instance->CreationContext()->Global();
492 global->Set(String::NewFromUtf8(isolate, "obj"), instance); 524 global->Set(String::NewFromUtf8(isolate, "obj"), instance);
493 global->Set(kBlockedContextIndex, v8::True(isolate)); 525 global->Set(kBlockedContextIndex, v8::True(isolate));
494 return instance; 526 return instance;
495 } 527 }
496 528
497 529
498 TEST(NamedAccessCheck) { 530 TEST(NamedAccessCheck) {
531 HarmonyIsolate isolate;
499 const AccessType types[] = { ACCESS_GET, ACCESS_HAS }; 532 const AccessType types[] = { ACCESS_GET, ACCESS_HAS };
500 for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { 533 for (size_t i = 0; i < ARRAY_SIZE(types); ++i) {
501 HandleScope scope(CcTest::isolate()); 534 HandleScope scope(isolate.GetIsolate());
502 LocalContext context(CcTest::isolate()); 535 LocalContext context(isolate.GetIsolate());
503 g_access_block_type = types[i]; 536 g_access_block_type = types[i];
504 Handle<Object> instance = CreateAccessCheckedObject( 537 Handle<Object> instance = CreateAccessCheckedObject(
505 CcTest::isolate(), 538 isolate.GetIsolate(),
506 NamedAccessAllowUnlessBlocked, 539 NamedAccessAllowUnlessBlocked,
507 IndexedAccessAlwaysAllowed, 540 IndexedAccessAlwaysAllowed,
508 String::NewFromUtf8(CcTest::isolate(), "foo")); 541 String::NewFromUtf8(isolate.GetIsolate(), "foo"));
509 CompileRun("var records = null;" 542 CompileRun("var records = null;"
510 "var objNoCheck = {};" 543 "var objNoCheck = {};"
511 "var observer = function(r) { records = r };" 544 "var observer = function(r) { records = r };"
512 "Object.observe(obj, observer);" 545 "Object.observe(obj, observer);"
513 "Object.observe(objNoCheck, observer);"); 546 "Object.observe(objNoCheck, observer);");
514 Handle<Value> obj_no_check = CompileRun("objNoCheck"); 547 Handle<Value> obj_no_check = CompileRun("objNoCheck");
515 { 548 {
516 LocalContext context2(CcTest::isolate()); 549 LocalContext context2(isolate.GetIsolate());
517 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 550 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
518 instance); 551 instance);
519 context2->Global()->Set( 552 context2->Global()->Set(
520 String::NewFromUtf8(CcTest::isolate(), "objNoCheck"), 553 String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"),
521 obj_no_check); 554 obj_no_check);
522 CompileRun("var records2 = null;" 555 CompileRun("var records2 = null;"
523 "var observer2 = function(r) { records2 = r };" 556 "var observer2 = function(r) { records2 = r };"
524 "Object.observe(obj, observer2);" 557 "Object.observe(obj, observer2);"
525 "Object.observe(objNoCheck, observer2);" 558 "Object.observe(objNoCheck, observer2);"
526 "obj.foo = 'bar';" 559 "obj.foo = 'bar';"
527 "Object.defineProperty(obj, 'foo', {value: 5});" 560 "Object.defineProperty(obj, 'foo', {value: 5});"
528 "Object.defineProperty(obj, 'foo', {get: function(){}});" 561 "Object.defineProperty(obj, 'foo', {get: function(){}});"
529 "obj.bar = 'baz';" 562 "obj.bar = 'baz';"
530 "objNoCheck.baz = 'quux'"); 563 "objNoCheck.baz = 'quux'");
531 const RecordExpectation expected_records2[] = { 564 const RecordExpectation expected_records2[] = {
532 { instance, "add", "foo", Handle<Value>() }, 565 { instance, "add", "foo", Handle<Value>() },
533 { instance, "update", "foo", 566 { instance, "update", "foo",
534 String::NewFromUtf8(CcTest::isolate(), "bar") }, 567 String::NewFromUtf8(isolate.GetIsolate(), "bar") },
535 { instance, "reconfigure", "foo", 568 { instance, "reconfigure", "foo",
536 Number::New(CcTest::isolate(), 5) }, 569 Number::New(isolate.GetIsolate(), 5) },
537 { instance, "add", "bar", Handle<Value>() }, 570 { instance, "add", "bar", Handle<Value>() },
538 { obj_no_check, "add", "baz", Handle<Value>() }, 571 { obj_no_check, "add", "baz", Handle<Value>() },
539 }; 572 };
540 EXPECT_RECORDS(CompileRun("records2"), expected_records2); 573 EXPECT_RECORDS(CompileRun("records2"), expected_records2);
541 } 574 }
542 const RecordExpectation expected_records[] = { 575 const RecordExpectation expected_records[] = {
543 { instance, "add", "bar", Handle<Value>() }, 576 { instance, "add", "bar", Handle<Value>() },
544 { obj_no_check, "add", "baz", Handle<Value>() } 577 { obj_no_check, "add", "baz", Handle<Value>() }
545 }; 578 };
546 EXPECT_RECORDS(CompileRun("records"), expected_records); 579 EXPECT_RECORDS(CompileRun("records"), expected_records);
547 } 580 }
548 } 581 }
549 582
550 583
551 TEST(IndexedAccessCheck) { 584 TEST(IndexedAccessCheck) {
585 HarmonyIsolate isolate;
552 const AccessType types[] = { ACCESS_GET, ACCESS_HAS }; 586 const AccessType types[] = { ACCESS_GET, ACCESS_HAS };
553 for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { 587 for (size_t i = 0; i < ARRAY_SIZE(types); ++i) {
554 HandleScope scope(CcTest::isolate()); 588 HandleScope scope(isolate.GetIsolate());
555 LocalContext context(CcTest::isolate()); 589 LocalContext context(isolate.GetIsolate());
556 g_access_block_type = types[i]; 590 g_access_block_type = types[i];
557 Handle<Object> instance = CreateAccessCheckedObject( 591 Handle<Object> instance = CreateAccessCheckedObject(
558 CcTest::isolate(), NamedAccessAlwaysAllowed, 592 isolate.GetIsolate(), NamedAccessAlwaysAllowed,
559 IndexedAccessAllowUnlessBlocked, Number::New(CcTest::isolate(), 7)); 593 IndexedAccessAllowUnlessBlocked, Number::New(isolate.GetIsolate(), 7));
560 CompileRun("var records = null;" 594 CompileRun("var records = null;"
561 "var objNoCheck = {};" 595 "var objNoCheck = {};"
562 "var observer = function(r) { records = r };" 596 "var observer = function(r) { records = r };"
563 "Object.observe(obj, observer);" 597 "Object.observe(obj, observer);"
564 "Object.observe(objNoCheck, observer);"); 598 "Object.observe(objNoCheck, observer);");
565 Handle<Value> obj_no_check = CompileRun("objNoCheck"); 599 Handle<Value> obj_no_check = CompileRun("objNoCheck");
566 { 600 {
567 LocalContext context2(CcTest::isolate()); 601 LocalContext context2(isolate.GetIsolate());
568 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 602 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
569 instance); 603 instance);
570 context2->Global()->Set( 604 context2->Global()->Set(
571 String::NewFromUtf8(CcTest::isolate(), "objNoCheck"), 605 String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"),
572 obj_no_check); 606 obj_no_check);
573 CompileRun("var records2 = null;" 607 CompileRun("var records2 = null;"
574 "var observer2 = function(r) { records2 = r };" 608 "var observer2 = function(r) { records2 = r };"
575 "Object.observe(obj, observer2);" 609 "Object.observe(obj, observer2);"
576 "Object.observe(objNoCheck, observer2);" 610 "Object.observe(objNoCheck, observer2);"
577 "obj[7] = 'foo';" 611 "obj[7] = 'foo';"
578 "Object.defineProperty(obj, '7', {value: 5});" 612 "Object.defineProperty(obj, '7', {value: 5});"
579 "Object.defineProperty(obj, '7', {get: function(){}});" 613 "Object.defineProperty(obj, '7', {get: function(){}});"
580 "obj[8] = 'bar';" 614 "obj[8] = 'bar';"
581 "objNoCheck[42] = 'quux'"); 615 "objNoCheck[42] = 'quux'");
582 const RecordExpectation expected_records2[] = { 616 const RecordExpectation expected_records2[] = {
583 { instance, "add", "7", Handle<Value>() }, 617 { instance, "add", "7", Handle<Value>() },
584 { instance, "update", "7", 618 { instance, "update", "7",
585 String::NewFromUtf8(CcTest::isolate(), "foo") }, 619 String::NewFromUtf8(isolate.GetIsolate(), "foo") },
586 { instance, "reconfigure", "7", Number::New(CcTest::isolate(), 5) }, 620 { instance, "reconfigure", "7", Number::New(isolate.GetIsolate(), 5) },
587 { instance, "add", "8", Handle<Value>() }, 621 { instance, "add", "8", Handle<Value>() },
588 { obj_no_check, "add", "42", Handle<Value>() } 622 { obj_no_check, "add", "42", Handle<Value>() }
589 }; 623 };
590 EXPECT_RECORDS(CompileRun("records2"), expected_records2); 624 EXPECT_RECORDS(CompileRun("records2"), expected_records2);
591 } 625 }
592 const RecordExpectation expected_records[] = { 626 const RecordExpectation expected_records[] = {
593 { instance, "add", "8", Handle<Value>() }, 627 { instance, "add", "8", Handle<Value>() },
594 { obj_no_check, "add", "42", Handle<Value>() } 628 { obj_no_check, "add", "42", Handle<Value>() }
595 }; 629 };
596 EXPECT_RECORDS(CompileRun("records"), expected_records); 630 EXPECT_RECORDS(CompileRun("records"), expected_records);
597 } 631 }
598 } 632 }
599 633
600 634
601 TEST(SpliceAccessCheck) { 635 TEST(SpliceAccessCheck) {
602 HandleScope scope(CcTest::isolate()); 636 HarmonyIsolate isolate;
603 LocalContext context(CcTest::isolate()); 637 HandleScope scope(isolate.GetIsolate());
638 LocalContext context(isolate.GetIsolate());
604 g_access_block_type = ACCESS_GET; 639 g_access_block_type = ACCESS_GET;
605 Handle<Object> instance = CreateAccessCheckedObject( 640 Handle<Object> instance = CreateAccessCheckedObject(
606 CcTest::isolate(), NamedAccessAlwaysAllowed, 641 isolate.GetIsolate(), NamedAccessAlwaysAllowed,
607 IndexedAccessAllowUnlessBlocked, Number::New(CcTest::isolate(), 1)); 642 IndexedAccessAllowUnlessBlocked, Number::New(isolate.GetIsolate(), 1));
608 CompileRun("var records = null;" 643 CompileRun("var records = null;"
609 "obj[1] = 'foo';" 644 "obj[1] = 'foo';"
610 "obj.length = 2;" 645 "obj.length = 2;"
611 "var objNoCheck = {1: 'bar', length: 2};" 646 "var objNoCheck = {1: 'bar', length: 2};"
612 "observer = function(r) { records = r };" 647 "observer = function(r) { records = r };"
613 "Array.observe(obj, observer);" 648 "Array.observe(obj, observer);"
614 "Array.observe(objNoCheck, observer);"); 649 "Array.observe(objNoCheck, observer);");
615 Handle<Value> obj_no_check = CompileRun("objNoCheck"); 650 Handle<Value> obj_no_check = CompileRun("objNoCheck");
616 { 651 {
617 LocalContext context2(CcTest::isolate()); 652 LocalContext context2(isolate.GetIsolate());
618 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 653 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
619 instance); 654 instance);
620 context2->Global()->Set( 655 context2->Global()->Set(
621 String::NewFromUtf8(CcTest::isolate(), "objNoCheck"), obj_no_check); 656 String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"), obj_no_check);
622 CompileRun("var records2 = null;" 657 CompileRun("var records2 = null;"
623 "var observer2 = function(r) { records2 = r };" 658 "var observer2 = function(r) { records2 = r };"
624 "Array.observe(obj, observer2);" 659 "Array.observe(obj, observer2);"
625 "Array.observe(objNoCheck, observer2);" 660 "Array.observe(objNoCheck, observer2);"
626 // No one should hear about this: no splice records are emitted 661 // No one should hear about this: no splice records are emitted
627 // for access-checked objects 662 // for access-checked objects
628 "[].push.call(obj, 5);" 663 "[].push.call(obj, 5);"
629 "[].splice.call(obj, 1, 1);" 664 "[].splice.call(obj, 1, 1);"
630 "[].pop.call(obj);" 665 "[].pop.call(obj);"
631 "[].pop.call(objNoCheck);"); 666 "[].pop.call(objNoCheck);");
632 // TODO(adamk): Extend EXPECT_RECORDS to be able to assert more things 667 // TODO(adamk): Extend EXPECT_RECORDS to be able to assert more things
633 // about splice records. For this test it's not so important since 668 // about splice records. For this test it's not so important since
634 // we just want to guarantee the machinery is in operation at all. 669 // we just want to guarantee the machinery is in operation at all.
635 const RecordExpectation expected_records2[] = { 670 const RecordExpectation expected_records2[] = {
636 { obj_no_check, "splice", "", Handle<Value>() } 671 { obj_no_check, "splice", "", Handle<Value>() }
637 }; 672 };
638 EXPECT_RECORDS(CompileRun("records2"), expected_records2); 673 EXPECT_RECORDS(CompileRun("records2"), expected_records2);
639 } 674 }
640 const RecordExpectation expected_records[] = { 675 const RecordExpectation expected_records[] = {
641 { obj_no_check, "splice", "", Handle<Value>() } 676 { obj_no_check, "splice", "", Handle<Value>() }
642 }; 677 };
643 EXPECT_RECORDS(CompileRun("records"), expected_records); 678 EXPECT_RECORDS(CompileRun("records"), expected_records);
644 } 679 }
645 680
646 681
647 TEST(DisallowAllForAccessKeys) { 682 TEST(DisallowAllForAccessKeys) {
648 HandleScope scope(CcTest::isolate()); 683 HarmonyIsolate isolate;
649 LocalContext context(CcTest::isolate()); 684 HandleScope scope(isolate.GetIsolate());
685 LocalContext context(isolate.GetIsolate());
650 Handle<Object> instance = CreateAccessCheckedObject( 686 Handle<Object> instance = CreateAccessCheckedObject(
651 CcTest::isolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed); 687 isolate.GetIsolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed);
652 CompileRun("var records = null;" 688 CompileRun("var records = null;"
653 "var objNoCheck = {};" 689 "var objNoCheck = {};"
654 "var observer = function(r) { records = r };" 690 "var observer = function(r) { records = r };"
655 "Object.observe(obj, observer);" 691 "Object.observe(obj, observer);"
656 "Object.observe(objNoCheck, observer);"); 692 "Object.observe(objNoCheck, observer);");
657 Handle<Value> obj_no_check = CompileRun("objNoCheck"); 693 Handle<Value> obj_no_check = CompileRun("objNoCheck");
658 { 694 {
659 LocalContext context2(CcTest::isolate()); 695 LocalContext context2(isolate.GetIsolate());
660 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 696 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
661 instance); 697 instance);
662 context2->Global()->Set( 698 context2->Global()->Set(
663 String::NewFromUtf8(CcTest::isolate(), "objNoCheck"), obj_no_check); 699 String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"), obj_no_check);
664 CompileRun("var records2 = null;" 700 CompileRun("var records2 = null;"
665 "var observer2 = function(r) { records2 = r };" 701 "var observer2 = function(r) { records2 = r };"
666 "Object.observe(obj, observer2);" 702 "Object.observe(obj, observer2);"
667 "Object.observe(objNoCheck, observer2);" 703 "Object.observe(objNoCheck, observer2);"
668 "obj.foo = 'bar';" 704 "obj.foo = 'bar';"
669 "obj[5] = 'baz';" 705 "obj[5] = 'baz';"
670 "objNoCheck.baz = 'quux'"); 706 "objNoCheck.baz = 'quux'");
671 const RecordExpectation expected_records2[] = { 707 const RecordExpectation expected_records2[] = {
672 { instance, "add", "foo", Handle<Value>() }, 708 { instance, "add", "foo", Handle<Value>() },
673 { instance, "add", "5", Handle<Value>() }, 709 { instance, "add", "5", Handle<Value>() },
674 { obj_no_check, "add", "baz", Handle<Value>() }, 710 { obj_no_check, "add", "baz", Handle<Value>() },
675 }; 711 };
676 EXPECT_RECORDS(CompileRun("records2"), expected_records2); 712 EXPECT_RECORDS(CompileRun("records2"), expected_records2);
677 } 713 }
678 const RecordExpectation expected_records[] = { 714 const RecordExpectation expected_records[] = {
679 { obj_no_check, "add", "baz", Handle<Value>() } 715 { obj_no_check, "add", "baz", Handle<Value>() }
680 }; 716 };
681 EXPECT_RECORDS(CompileRun("records"), expected_records); 717 EXPECT_RECORDS(CompileRun("records"), expected_records);
682 } 718 }
683 719
684 720
685 TEST(AccessCheckDisallowApiModifications) { 721 TEST(AccessCheckDisallowApiModifications) {
686 HandleScope scope(CcTest::isolate()); 722 HarmonyIsolate isolate;
687 LocalContext context(CcTest::isolate()); 723 HandleScope scope(isolate.GetIsolate());
724 LocalContext context(isolate.GetIsolate());
688 Handle<Object> instance = CreateAccessCheckedObject( 725 Handle<Object> instance = CreateAccessCheckedObject(
689 CcTest::isolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed); 726 isolate.GetIsolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed);
690 CompileRun("var records = null;" 727 CompileRun("var records = null;"
691 "var observer = function(r) { records = r };" 728 "var observer = function(r) { records = r };"
692 "Object.observe(obj, observer);"); 729 "Object.observe(obj, observer);");
693 { 730 {
694 LocalContext context2(CcTest::isolate()); 731 LocalContext context2(isolate.GetIsolate());
695 context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"), 732 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
696 instance); 733 instance);
697 CompileRun("var records2 = null;" 734 CompileRun("var records2 = null;"
698 "var observer2 = function(r) { records2 = r };" 735 "var observer2 = function(r) { records2 = r };"
699 "Object.observe(obj, observer2);"); 736 "Object.observe(obj, observer2);");
700 instance->Set(5, String::NewFromUtf8(CcTest::isolate(), "bar")); 737 instance->Set(5, String::NewFromUtf8(isolate.GetIsolate(), "bar"));
701 instance->Set(String::NewFromUtf8(CcTest::isolate(), "foo"), 738 instance->Set(String::NewFromUtf8(isolate.GetIsolate(), "foo"),
702 String::NewFromUtf8(CcTest::isolate(), "bar")); 739 String::NewFromUtf8(isolate.GetIsolate(), "bar"));
703 CompileRun(""); // trigger delivery 740 CompileRun(""); // trigger delivery
704 const RecordExpectation expected_records2[] = { 741 const RecordExpectation expected_records2[] = {
705 { instance, "add", "5", Handle<Value>() }, 742 { instance, "add", "5", Handle<Value>() },
706 { instance, "add", "foo", Handle<Value>() } 743 { instance, "add", "foo", Handle<Value>() }
707 }; 744 };
708 EXPECT_RECORDS(CompileRun("records2"), expected_records2); 745 EXPECT_RECORDS(CompileRun("records2"), expected_records2);
709 } 746 }
710 CHECK(CompileRun("records")->IsNull()); 747 CHECK(CompileRun("records")->IsNull());
711 } 748 }
712 749
713 750
714 TEST(HiddenPropertiesLeakage) { 751 TEST(HiddenPropertiesLeakage) {
715 HandleScope scope(CcTest::isolate()); 752 HarmonyIsolate isolate;
716 LocalContext context(CcTest::isolate()); 753 HandleScope scope(isolate.GetIsolate());
754 LocalContext context(isolate.GetIsolate());
717 CompileRun("var obj = {};" 755 CompileRun("var obj = {};"
718 "var records = null;" 756 "var records = null;"
719 "var observer = function(r) { records = r };" 757 "var observer = function(r) { records = r };"
720 "Object.observe(obj, observer);"); 758 "Object.observe(obj, observer);");
721 Handle<Value> obj = 759 Handle<Value> obj =
722 context->Global()->Get(String::NewFromUtf8(CcTest::isolate(), "obj")); 760 context->Global()->Get(String::NewFromUtf8(isolate.GetIsolate(), "obj"));
723 Handle<Object>::Cast(obj) 761 Handle<Object>::Cast(obj)
724 ->SetHiddenValue(String::NewFromUtf8(CcTest::isolate(), "foo"), 762 ->SetHiddenValue(String::NewFromUtf8(isolate.GetIsolate(), "foo"),
725 Null(CcTest::isolate())); 763 Null(isolate.GetIsolate()));
726 CompileRun(""); // trigger delivery 764 CompileRun(""); // trigger delivery
727 CHECK(CompileRun("records")->IsNull()); 765 CHECK(CompileRun("records")->IsNull());
728 } 766 }
OLDNEW
« no previous file with comments | « test/cctest/test-microtask-delivery.cc ('k') | test/mjsunit/debug-script.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698