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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 "Object.notify(obj, {type: 'a'});"); | 158 "Object.notify(obj, {type: 'a'});"); |
159 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value()); | 159 CHECK_EQ(5, CompileRun("ordering.length")->Int32Value()); |
160 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); | 160 CHECK_EQ(1, CompileRun("ordering[0]")->Int32Value()); |
161 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 161 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); |
162 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); | 162 CHECK_EQ(3, CompileRun("ordering[2]")->Int32Value()); |
163 // Note that we re-deliver to observers 1 and 2, while observer3 | 163 // Note that we re-deliver to observers 1 and 2, while observer3 |
164 // already received the second record during the first round. | 164 // already received the second record during the first round. |
165 CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value()); | 165 CHECK_EQ(1, CompileRun("ordering[3]")->Int32Value()); |
166 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); | 166 CHECK_EQ(2, CompileRun("ordering[1]")->Int32Value()); |
167 } | 167 } |
| 168 |
| 169 TEST(ObjectHashTableGrowth) { |
| 170 HarmonyIsolate isolate; |
| 171 HandleScope scope; |
| 172 // Initializing this context sets up initial hash tables. |
| 173 LocalContext context; |
| 174 Handle<Value> obj = CompileRun("obj = {};"); |
| 175 Handle<Value> observer = CompileRun( |
| 176 "var ran = false;" |
| 177 "(function() { ran = true })"); |
| 178 { |
| 179 // As does initializing this context. |
| 180 LocalContext context2; |
| 181 context2->Global()->Set(String::New("obj"), obj); |
| 182 context2->Global()->Set(String::New("observer"), observer); |
| 183 CompileRun( |
| 184 "var objArr = [];" |
| 185 // 100 objects should be enough to make the hash table grow |
| 186 // (and thus relocate). |
| 187 "for (var i = 0; i < 100; ++i) {" |
| 188 " objArr.push({});" |
| 189 " Object.observe(objArr[objArr.length-1], function(){});" |
| 190 "}" |
| 191 "Object.observe(obj, observer);"); |
| 192 } |
| 193 // obj is now marked "is_observed", but our map has moved. |
| 194 CompileRun("obj.foo = 'bar'"); |
| 195 CHECK(CompileRun("ran")->BooleanValue()); |
| 196 } |
OLD | NEW |