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