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 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 | 34 |
34 namespace { | 35 namespace { |
35 // Need to create a new isolate when FLAG_harmony_observation is on. | 36 // Need to create a new isolate when FLAG_harmony_observation is on. |
36 class HarmonyIsolate { | 37 class HarmonyIsolate { |
37 public: | 38 public: |
38 HarmonyIsolate() { | 39 HarmonyIsolate() { |
39 i::FLAG_harmony_observation = true; | 40 i::FLAG_harmony_observation = true; |
40 isolate_ = Isolate::New(); | 41 isolate_ = Isolate::New(); |
41 isolate_->Enter(); | 42 isolate_->Enter(); |
42 } | 43 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 "Object.unobserve(obj, observer);" | 391 "Object.unobserve(obj, observer);" |
391 "obj.foo = 44;"); | 392 "obj.foo = 44;"); |
392 const RecordExpectation expected_records3[] = { | 393 const RecordExpectation expected_records3[] = { |
393 { proto, "new", "bar", Handle<Value>() } | 394 { proto, "new", "bar", Handle<Value>() } |
394 // TODO(adamk): The below record should be emitted since proto is observed | 395 // TODO(adamk): The below record should be emitted since proto is observed |
395 // and has been modified. Not clear if this happens in practice. | 396 // and has been modified. Not clear if this happens in practice. |
396 // { proto, "updated", "foo", Number::New(43) } | 397 // { proto, "updated", "foo", Number::New(43) } |
397 }; | 398 }; |
398 EXPECT_RECORDS(CompileRun("records"), expected_records3); | 399 EXPECT_RECORDS(CompileRun("records"), expected_records3); |
399 } | 400 } |
| 401 |
| 402 |
| 403 static int NumberOfElements(i::Handle<i::JSWeakMap> map) { |
| 404 return i::ObjectHashTable::cast(map->table())->NumberOfElements(); |
| 405 } |
| 406 |
| 407 |
| 408 TEST(ObservationWeakMap) { |
| 409 HarmonyIsolate isolate; |
| 410 HandleScope scope; |
| 411 LocalContext context; |
| 412 CompileRun( |
| 413 "var obj = {};" |
| 414 "Object.observe(obj, function(){});" |
| 415 "Object.getNotifier(obj);" |
| 416 "obj = null;"); |
| 417 i::Handle<i::JSObject> observation_state = FACTORY->observation_state(); |
| 418 i::Handle<i::JSWeakMap> observerInfoMap = |
| 419 i::Handle<i::JSWeakMap>::cast( |
| 420 i::GetProperty(observation_state, "observerInfoMap")); |
| 421 i::Handle<i::JSWeakMap> objectInfoMap = |
| 422 i::Handle<i::JSWeakMap>::cast( |
| 423 i::GetProperty(observation_state, "objectInfoMap")); |
| 424 i::Handle<i::JSWeakMap> notifierTargetMap = |
| 425 i::Handle<i::JSWeakMap>::cast( |
| 426 i::GetProperty(observation_state, "notifierTargetMap")); |
| 427 CHECK_EQ(1, NumberOfElements(observerInfoMap)); |
| 428 CHECK_EQ(1, NumberOfElements(objectInfoMap)); |
| 429 CHECK_EQ(1, NumberOfElements(notifierTargetMap)); |
| 430 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 431 CHECK_EQ(0, NumberOfElements(observerInfoMap)); |
| 432 CHECK_EQ(0, NumberOfElements(objectInfoMap)); |
| 433 CHECK_EQ(0, NumberOfElements(notifierTargetMap)); |
| 434 } |
OLD | NEW |