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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 "Object.observe(obj2, observer2);" | 123 "Object.observe(obj2, observer2);" |
124 "Object.observe(obj2, observer1);" | 124 "Object.observe(obj2, observer1);" |
125 "obj2.foo = 'baz'"); | 125 "obj2.foo = 'baz'"); |
126 CHECK_EQ(3, CompileRun("ordering.length")->Int32Value()); | 126 CHECK_EQ(3, CompileRun("ordering.length")->Int32Value()); |
127 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); | 127 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); |
128 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 128 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); |
129 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); | 129 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); |
130 } | 130 } |
131 | 131 |
132 | 132 |
| 133 TEST(DeliveryCallbackThrows) { |
| 134 HandleScope scope(CcTest::isolate()); |
| 135 LocalContext context(CcTest::isolate()); |
| 136 CompileRun( |
| 137 "var obj = {};" |
| 138 "var ordering = [];" |
| 139 "function observer1() { ordering.push(1); };" |
| 140 "function observer2() { ordering.push(2); };" |
| 141 "function observer_throws() {" |
| 142 " ordering.push(0);" |
| 143 " throw new Error();" |
| 144 " ordering.push(-1);" |
| 145 "};" |
| 146 "Object.observe(obj, observer_throws.bind());" |
| 147 "Object.observe(obj, observer1);" |
| 148 "Object.observe(obj, observer_throws.bind());" |
| 149 "Object.observe(obj, observer2);" |
| 150 "Object.observe(obj, observer_throws.bind());" |
| 151 "obj.foo = 'bar';"); |
| 152 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value()); |
| 153 CHECK_EQ(0, CompileRun("ordering[0]")->Int32Value()); |
| 154 CHECK_EQ(1, CompileRun("ordering[1]")->Int32Value()); |
| 155 CHECK_EQ(0, CompileRun("ordering[2]")->Int32Value()); |
| 156 CHECK_EQ(2, CompileRun("ordering[3]")->Int32Value()); |
| 157 CHECK_EQ(0, CompileRun("ordering[4]")->Int32Value()); |
| 158 } |
| 159 |
| 160 |
| 161 TEST(DeliveryChangesMutationInCallback) { |
| 162 HandleScope scope(CcTest::isolate()); |
| 163 LocalContext context(CcTest::isolate()); |
| 164 CompileRun( |
| 165 "var obj = {};" |
| 166 "var ordering = [];" |
| 167 "function observer1(records) {" |
| 168 " ordering.push(100 + records.length);" |
| 169 " records.push(11);" |
| 170 " records.push(22);" |
| 171 "};" |
| 172 "function observer2(records) {" |
| 173 " ordering.push(200 + records.length);" |
| 174 " records.push(33);" |
| 175 " records.push(44);" |
| 176 "};" |
| 177 "Object.observe(obj, observer1);" |
| 178 "Object.observe(obj, observer2);" |
| 179 "obj.foo = 'bar';"); |
| 180 CHECK_EQ(2, CompileRun("ordering.length")->Int32Value()); |
| 181 CHECK_EQ(101, CompileRun("ordering[0]")->Int32Value()); |
| 182 CHECK_EQ(201, CompileRun("ordering[1]")->Int32Value()); |
| 183 } |
| 184 |
| 185 |
133 TEST(DeliveryOrderingReentrant) { | 186 TEST(DeliveryOrderingReentrant) { |
134 HandleScope scope(CcTest::isolate()); | 187 HandleScope scope(CcTest::isolate()); |
135 LocalContext context(CcTest::isolate()); | 188 LocalContext context(CcTest::isolate()); |
136 CompileRun( | 189 CompileRun( |
137 "var obj = {};" | 190 "var obj = {};" |
138 "var reentered = false;" | 191 "var reentered = false;" |
139 "var ordering = [];" | 192 "var ordering = [];" |
140 "function observer1() { ordering.push(1); };" | 193 "function observer1() { ordering.push(1); };" |
141 "function observer2() {" | 194 "function observer2() {" |
142 " if (!reentered) {" | 195 " if (!reentered) {" |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 notifier); | 755 notifier); |
703 CompileRun("var obj2 = {};" | 756 CompileRun("var obj2 = {};" |
704 "var notifier2 = Object.getNotifier(obj2);" | 757 "var notifier2 = Object.getNotifier(obj2);" |
705 "notifier2.performChange.call(" | 758 "notifier2.performChange.call(" |
706 "notifier, 'foo', function(){})"); | 759 "notifier, 'foo', function(){})"); |
707 } | 760 } |
708 | 761 |
709 CcTest::isolate()->ContextDisposedNotification(); | 762 CcTest::isolate()->ContextDisposedNotification(); |
710 CheckSurvivingGlobalObjectsCount(1); | 763 CheckSurvivingGlobalObjectsCount(1); |
711 } | 764 } |
OLD | NEW |