This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Made sure not to delete handles of dart objects if the isolate has been deleted #25506
Merged
gaaclarke
merged 7 commits into
flutter:master
from
gaaclarke:dont-delete-handle-after-isolate-deleted
Apr 14, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbe2785
Made sure not to delete handles of dart objects if the isolate has be…
gaaclarke 0d2b963
added a tonic unit test
gaaclarke cdae48d
fixed tonic unit test
gaaclarke 3c66c97
added missing changes to dart_isolate_runner
gaaclarke b2e804e
added dart_isolate_test
gaaclarke 068bf41
updated TODO comment
gaaclarke 0d7d432
reworded comment
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
third_party/tonic/tests/dart_persistent_handle_unittest.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/testing/dart_isolate_runner.h" | ||
| #include "flutter/testing/fixture_test.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
|
|
||
| class DartPersistentHandleTest : public FixtureTest { | ||
| public: | ||
| DartPersistentHandleTest() | ||
| : settings_(CreateSettingsForFixture()), | ||
| vm_(DartVMRef::Create(settings_)), | ||
| thread_(CreateNewThread()), | ||
| task_runners_(GetCurrentTestName(), | ||
| thread_, | ||
| thread_, | ||
| thread_, | ||
| thread_) {} | ||
|
|
||
| ~DartPersistentHandleTest() = default; | ||
|
|
||
| [[nodiscard]] bool RunWithEntrypoint(const std::string& entrypoint) { | ||
| if (running_isolate_) { | ||
| return false; | ||
| } | ||
| auto isolate = RunDartCodeInIsolate(vm_, settings_, task_runners_, | ||
| entrypoint, {}, GetFixturesPath()); | ||
| if (!isolate || isolate->get()->GetPhase() != DartIsolate::Phase::Running) { | ||
| return false; | ||
| } | ||
|
|
||
| running_isolate_ = std::move(isolate); | ||
| return true; | ||
| } | ||
|
|
||
| protected: | ||
| Settings settings_; | ||
| DartVMRef vm_; | ||
| std::unique_ptr<AutoIsolateShutdown> running_isolate_; | ||
| fml::RefPtr<fml::TaskRunner> thread_; | ||
| TaskRunners task_runners_; | ||
| FML_DISALLOW_COPY_AND_ASSIGN(DartPersistentHandleTest); | ||
| }; | ||
|
|
||
| TEST_F(DartPersistentHandleTest, ClearAfterShutdown) { | ||
| auto persistent_value = tonic::DartPersistentValue(); | ||
|
|
||
| fml::AutoResetWaitableEvent event; | ||
| AddNativeCallback("GiveObjectToNative", | ||
| CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { | ||
| auto handle = Dart_GetNativeArgument(args, 0); | ||
|
|
||
| auto dart_state = tonic::DartState::Current(); | ||
| ASSERT_TRUE(dart_state); | ||
| ASSERT_TRUE(tonic::DartState::Current()); | ||
| persistent_value.Set(dart_state, handle); | ||
|
|
||
| event.Signal(); | ||
| })); | ||
|
|
||
| ASSERT_TRUE(RunWithEntrypoint("callGiveObjectToNative")); | ||
| event.Wait(); | ||
|
|
||
| running_isolate_->Shutdown(); | ||
|
|
||
| fml::AutoResetWaitableEvent clear; | ||
| task_runners_.GetUITaskRunner()->PostTask([&] { | ||
| persistent_value.Clear(); | ||
| clear.Signal(); | ||
| }); | ||
| clear.Wait(); | ||
| } | ||
| } // namespace testing | ||
| } // namespace flutter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches the logic in DartWeakPersistentValue.