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 5866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5877 static bool utils_has_been_collected = false; | 5877 static bool utils_has_been_collected = false; |
5878 | 5878 |
5879 static void UtilsHasBeenCollected( | 5879 static void UtilsHasBeenCollected( |
5880 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { | 5880 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { |
5881 utils_has_been_collected = true; | 5881 utils_has_been_collected = true; |
5882 data.GetParameter()->Reset(); | 5882 data.GetParameter()->Reset(); |
5883 } | 5883 } |
5884 | 5884 |
5885 | 5885 |
5886 TEST(BootstrappingExports) { | 5886 TEST(BootstrappingExports) { |
5887 FLAG_expose_natives_as = "natives"; | 5887 // Expose utils object and delete it to observe that it is indeed |
| 5888 // being garbage-collected. |
| 5889 FLAG_expose_natives_as = "utils"; |
5888 CcTest::InitializeVM(); | 5890 CcTest::InitializeVM(); |
5889 v8::Isolate* isolate = CcTest::isolate(); | 5891 v8::Isolate* isolate = CcTest::isolate(); |
5890 | 5892 |
5891 if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return; | 5893 if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return; |
5892 | 5894 |
5893 utils_has_been_collected = false; | 5895 utils_has_been_collected = false; |
5894 | 5896 |
5895 v8::Persistent<v8::Object> utils; | 5897 v8::Persistent<v8::Object> utils; |
5896 | 5898 |
5897 { | 5899 { |
5898 v8::HandleScope scope(isolate); | 5900 v8::HandleScope scope(isolate); |
5899 v8::Handle<v8::Object> natives = | 5901 v8::Local<v8::String> name = v8_str("utils"); |
5900 CcTest::global()->Get(v8_str("natives"))->ToObject(isolate); | 5902 utils.Reset(isolate, CcTest::global()->Get(name)->ToObject(isolate)); |
5901 utils.Reset(isolate, natives->Get(v8_str("utils"))->ToObject(isolate)); | 5903 CcTest::global()->Delete(name); |
5902 natives->Delete(v8_str("utils")); | |
5903 } | 5904 } |
5904 | 5905 |
5905 utils.SetWeak(&utils, UtilsHasBeenCollected, | 5906 utils.SetWeak(&utils, UtilsHasBeenCollected, |
5906 v8::WeakCallbackType::kParameter); | 5907 v8::WeakCallbackType::kParameter); |
5907 | 5908 |
5908 CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks"); | 5909 CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks"); |
5909 | 5910 |
5910 CHECK(utils_has_been_collected); | 5911 CHECK(utils_has_been_collected); |
5911 } | 5912 } |
5912 | 5913 |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6315 // The CollectGarbage call above starts sweeper threads. | 6316 // The CollectGarbage call above starts sweeper threads. |
6316 // The crash will happen if the following two functions | 6317 // The crash will happen if the following two functions |
6317 // are called before sweeping finishes. | 6318 // are called before sweeping finishes. |
6318 heap->StartIncrementalMarking(); | 6319 heap->StartIncrementalMarking(); |
6319 heap->FinalizeIncrementalMarkingIfComplete("test"); | 6320 heap->FinalizeIncrementalMarkingIfComplete("test"); |
6320 } | 6321 } |
6321 | 6322 |
6322 | 6323 |
6323 } // namespace internal | 6324 } // namespace internal |
6324 } // namespace v8 | 6325 } // namespace v8 |
OLD | NEW |