Skip to content

Commit e18aba3

Browse files
authored
Refactor of ClaimDartHandle -> AssociateWithDartWrapper (flutter#16720)
1 parent 4aaafe0 commit e18aba3

File tree

6 files changed

+18
-31
lines changed

6 files changed

+18
-31
lines changed

lib/ui/compositing/scene.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void Scene::create(Dart_Handle scene_handle,
3434
auto scene = fml::MakeRefCounted<Scene>(
3535
std::move(rootLayer), rasterizerTracingThreshold,
3636
checkerboardRasterCacheImages, checkerboardOffscreenLayers);
37-
scene->ClaimDartHandle(scene_handle);
37+
scene->AssociateWithDartWrapper(scene_handle);
3838
}
3939

4040
Scene::Scene(std::shared_ptr<flutter::Layer> rootLayer,

lib/ui/painting/engine_layer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class EngineLayer : public RefCountedDartWrappable<EngineLayer> {
3333
static void MakeRetained(Dart_Handle dart_handle,
3434
std::shared_ptr<flutter::ContainerLayer> layer) {
3535
auto engine_layer = fml::MakeRefCounted<EngineLayer>(layer);
36-
engine_layer->ClaimDartHandle(dart_handle);
36+
engine_layer->AssociateWithDartWrapper(dart_handle);
3737
}
3838

3939
static void RegisterNatives(tonic::DartLibraryNatives* natives);

lib/ui/painting/picture.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fml::RefPtr<Picture> Picture::Create(
3131
flutter::SkiaGPUObject<SkPicture> picture) {
3232
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture));
3333

34-
canvas_picture->ClaimDartHandle(dart_handle);
34+
canvas_picture->AssociateWithDartWrapper(dart_handle);
3535
return canvas_picture;
3636
}
3737

third_party/tonic/dart_args.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,17 @@ void DartCallConstructor(Sig func, Dart_NativeArguments args) {
226226
return;
227227
wrappable = decoder.DispatchCtor(func);
228228
}
229-
wrappable->AssociateWithDartWrapper(args);
229+
230+
Dart_Handle wrapper = Dart_GetNativeArgument(args, 0);
231+
TONIC_CHECK(!LogIfError(wrapper));
232+
233+
intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
234+
TONIC_CHECK(!LogIfError(Dart_GetNativeFieldsOfArgument(
235+
args, 0, DartWrappable::kNumberOfNativeFields, native_fields)));
236+
TONIC_CHECK(!native_fields[DartWrappable::kPeerIndex]);
237+
TONIC_CHECK(!native_fields[DartWrappable::kWrapperInfoIndex]);
238+
239+
wrappable->AssociateWithDartWrapper(wrapper);
230240
}
231241

232242
} // namespace tonic

third_party/tonic/dart_wrappable.cc

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) {
4242
return wrapper;
4343
}
4444

45-
void DartWrappable::ClaimDartHandle(Dart_Handle wrapper) {
45+
void DartWrappable::AssociateWithDartWrapper(Dart_Handle wrapper) {
4646
TONIC_DCHECK(!dart_wrapper_);
4747
TONIC_CHECK(!LogIfError(wrapper));
4848

@@ -58,29 +58,6 @@ void DartWrappable::ClaimDartHandle(Dart_Handle wrapper) {
5858
wrapper, this, GetAllocationSize(), &FinalizeDartWrapper);
5959
}
6060

61-
void DartWrappable::AssociateWithDartWrapper(Dart_NativeArguments args) {
62-
TONIC_DCHECK(!dart_wrapper_);
63-
64-
Dart_Handle wrapper = Dart_GetNativeArgument(args, 0);
65-
TONIC_CHECK(!LogIfError(wrapper));
66-
67-
intptr_t native_fields[kNumberOfNativeFields];
68-
TONIC_CHECK(!LogIfError(Dart_GetNativeFieldsOfArgument(
69-
args, 0, kNumberOfNativeFields, native_fields)));
70-
TONIC_CHECK(!native_fields[kPeerIndex]);
71-
TONIC_CHECK(!native_fields[kWrapperInfoIndex]);
72-
73-
const DartWrapperInfo& info = GetDartWrapperInfo();
74-
TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(
75-
wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this))));
76-
TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(
77-
wrapper, kWrapperInfoIndex, reinterpret_cast<intptr_t>(&info))));
78-
79-
this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
80-
dart_wrapper_ = Dart_NewWeakPersistentHandle(
81-
wrapper, this, GetAllocationSize(), &FinalizeDartWrapper);
82-
}
83-
8461
void DartWrappable::ClearDartWrapper() {
8562
TONIC_DCHECK(dart_wrapper_);
8663
Dart_Handle wrapper = Dart_HandleFromWeakPersistent(dart_wrapper_);

third_party/tonic/dart_wrappable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class DartWrappable {
4444
virtual void ReleaseDartWrappableReference() const = 0;
4545

4646
// Use this method sparingly. It follows a slower path using Dart_New.
47-
// Prefer constructing the object in Dart code and using ClaimDartHandle.
47+
// Prefer constructing the object in Dart code and using
48+
// AssociateWithDartWrapper.
4849
Dart_Handle CreateDartWrapper(DartState* dart_state);
49-
void ClaimDartHandle(Dart_Handle wrappable);
50-
void AssociateWithDartWrapper(Dart_NativeArguments args);
50+
void AssociateWithDartWrapper(Dart_Handle wrappable);
5151
void ClearDartWrapper(); // Warning: Might delete this.
5252
Dart_WeakPersistentHandle dart_wrapper() const { return dart_wrapper_; }
5353

0 commit comments

Comments
 (0)