| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 53 | 53 | 
| 54 TEST(PerIsolateState) { | 54 TEST(PerIsolateState) { | 
| 55   HarmonyIsolate isolate; | 55   HarmonyIsolate isolate; | 
| 56   HandleScope scope; | 56   HandleScope scope; | 
| 57   LocalContext context1; | 57   LocalContext context1; | 
| 58   CompileRun( | 58   CompileRun( | 
| 59       "var count = 0;" | 59       "var count = 0;" | 
| 60       "var calls = 0;" | 60       "var calls = 0;" | 
| 61       "var observer = function(records) { count = records.length; calls++ };" | 61       "var observer = function(records) { count = records.length; calls++ };" | 
| 62       "var obj = {};" | 62       "var obj = {};" | 
| 63       "Object.observe(obj, observer);" | 63       "Object.observe(obj, observer);"); | 
| 64       "Object.notify(obj, {type: 'a'});"); |  | 
| 65   Handle<Value> observer = CompileRun("observer"); | 64   Handle<Value> observer = CompileRun("observer"); | 
| 66   Handle<Value> obj = CompileRun("obj"); | 65   Handle<Value> obj = CompileRun("obj"); | 
|  | 66   Handle<Value> notify_fun1 = CompileRun( | 
|  | 67       "(function() { Object.notify(obj, {type: 'a'}); })"); | 
|  | 68   Handle<Value> notify_fun2; | 
| 67   { | 69   { | 
| 68     LocalContext context2; | 70     LocalContext context2; | 
| 69     context2->Global()->Set(String::New("obj"), obj); | 71     context2->Global()->Set(String::New("obj"), obj); | 
| 70     CompileRun("Object.notify(obj, {type: 'b'});"); | 72     notify_fun2 = CompileRun( | 
|  | 73         "(function() { Object.notify(obj, {type: 'b'}); })"); | 
| 71   } | 74   } | 
|  | 75   Handle<Value> notify_fun3; | 
| 72   { | 76   { | 
| 73     LocalContext context3; | 77     LocalContext context3; | 
| 74     context3->Global()->Set(String::New("obj"), obj); | 78     context3->Global()->Set(String::New("obj"), obj); | 
| 75     CompileRun("Object.notify(obj, {type: 'c'});"); | 79     notify_fun3 = CompileRun( | 
|  | 80         "(function() { Object.notify(obj, {type: 'c'}); })"); | 
| 76   } | 81   } | 
| 77   { | 82   { | 
| 78     LocalContext context4; | 83     LocalContext context4; | 
| 79     context4->Global()->Set(String::New("observer"), observer); | 84     context4->Global()->Set(String::New("observer"), observer); | 
| 80     CompileRun("Object.deliverChangeRecords(observer)"); | 85     context4->Global()->Set(String::New("fun1"), notify_fun1); | 
|  | 86     context4->Global()->Set(String::New("fun2"), notify_fun2); | 
|  | 87     context4->Global()->Set(String::New("fun3"), notify_fun3); | 
|  | 88     CompileRun("fun1(); fun2(); fun3(); Object.deliverChangeRecords(observer)"); | 
| 81   } | 89   } | 
| 82   CHECK_EQ(1, CompileRun("calls")->Int32Value()); | 90   CHECK_EQ(1, CompileRun("calls")->Int32Value()); | 
| 83   CHECK_EQ(3, CompileRun("count")->Int32Value()); | 91   CHECK_EQ(3, CompileRun("count")->Int32Value()); | 
| 84 } | 92 } | 
|  | 93 | 
|  | 94 TEST(EndOfMicrotaskDelivery) { | 
|  | 95   HarmonyIsolate isolate; | 
|  | 96   HandleScope scope; | 
|  | 97   LocalContext context; | 
|  | 98   CompileRun( | 
|  | 99       "var obj = {};" | 
|  | 100       "var count = 0;" | 
|  | 101       "var observer = function(records) { count = records.length };" | 
|  | 102       "Object.observe(obj, observer);" | 
|  | 103       "Object.notify(obj, {type: 'a'});"); | 
|  | 104   CHECK_EQ(1, CompileRun("count")->Int32Value()); | 
|  | 105 } | 
|  | 106 | 
|  | 107 TEST(DeliveryOrdering) { | 
|  | 108   HarmonyIsolate isolate; | 
|  | 109   HandleScope scope; | 
|  | 110   LocalContext context; | 
|  | 111   CompileRun( | 
|  | 112       "var obj1 = {};" | 
|  | 113       "var obj2 = {};" | 
|  | 114       "var ordering = [];" | 
|  | 115       "function observer2() { ordering.push(2); };" | 
|  | 116       "function observer1() { ordering.push(1); };" | 
|  | 117       "function observer3() { ordering.push(3); };" | 
|  | 118       "Object.observe(obj1, observer1);" | 
|  | 119       "Object.observe(obj1, observer2);" | 
|  | 120       "Object.observe(obj1, observer3);" | 
|  | 121       "Object.notify(obj1, {type: 'a'});"); | 
|  | 122   CHECK_EQ(3, CompileRun("ordering.length")->Int32Value()); | 
|  | 123   CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); | 
|  | 124   CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 
|  | 125   CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); | 
|  | 126   CompileRun( | 
|  | 127       "ordering = [];" | 
|  | 128       "Object.observe(obj2, observer3);" | 
|  | 129       "Object.observe(obj2, observer2);" | 
|  | 130       "Object.observe(obj2, observer1);" | 
|  | 131       "Object.notify(obj2, {type: 'b'});"); | 
|  | 132   CHECK_EQ(3, CompileRun("ordering.length")->Int32Value()); | 
|  | 133   CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); | 
|  | 134   CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 
|  | 135   CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); | 
|  | 136 } | 
|  | 137 | 
|  | 138 TEST(DeliveryOrderingReentrant) { | 
|  | 139   HarmonyIsolate isolate; | 
|  | 140   HandleScope scope; | 
|  | 141   LocalContext context; | 
|  | 142   CompileRun( | 
|  | 143       "var obj = {};" | 
|  | 144       "var reentered = false;" | 
|  | 145       "var ordering = [];" | 
|  | 146       "function observer1() { ordering.push(1); };" | 
|  | 147       "function observer2() {" | 
|  | 148       "  if (!reentered) {" | 
|  | 149       "    Object.notify(obj, {type: 'b'});" | 
|  | 150       "    reentered = true;" | 
|  | 151       "  }" | 
|  | 152       "  ordering.push(2);" | 
|  | 153       "};" | 
|  | 154       "function observer3() { ordering.push(3); };" | 
|  | 155       "Object.observe(obj, observer1);" | 
|  | 156       "Object.observe(obj, observer2);" | 
|  | 157       "Object.observe(obj, observer3);" | 
|  | 158       "Object.notify(obj, {type: 'a'});"); | 
|  | 159   CHECK_EQ(5, CompileRun("ordering.length")->Int32Value()); | 
|  | 160   CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); | 
|  | 161   CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 
|  | 162   CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); | 
|  | 163   // Note that we re-deliver to observers 1 and 2, while observer3 | 
|  | 164   // already received the second record during the first round. | 
|  | 165   CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value()); | 
|  | 166   CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 
|  | 167 } | 
| OLD | NEW | 
|---|