From eb715e1c1ee49465442a7384ef92f3064f791e8e Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Thu, 13 Feb 2020 08:54:59 -0800 Subject: [PATCH 1/5] Remove usage of Dart_AllocateWithNativeFields from tonic This API is being removed from the Dart SDK. --- third_party/tonic/dart_wrappable.cc | 12 +++++++----- third_party/tonic/dart_wrappable.h | 6 ------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/third_party/tonic/dart_wrappable.cc b/third_party/tonic/dart_wrappable.cc index 96b5e44ed80fd..e749dfdf414a5 100644 --- a/third_party/tonic/dart_wrappable.cc +++ b/third_party/tonic/dart_wrappable.cc @@ -22,13 +22,15 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) { Dart_PersistentHandle type = dart_state->class_library().GetClass(info); TONIC_DCHECK(!LogIfError(type)); - intptr_t native_fields[kNumberOfNativeFields]; - native_fields[kPeerIndex] = reinterpret_cast(this); - native_fields[kWrapperInfoIndex] = reinterpret_cast(&info); - Dart_Handle wrapper = - Dart_AllocateWithNativeFields(type, kNumberOfNativeFields, native_fields); + Dart_Handle wrapper = Dart_New(type, Dart_Null(), 0, nullptr); TONIC_DCHECK(!LogIfError(wrapper)); + // Must set peer first to work with Dart_GetNativeReceiver. + Dart_Handle res = Dart_SetNativeInstanceField(wrapper, 0, reinterpret_cast(this)); + TONIC_DCHECK(!LogIfError(res)); + res = Dart_SetNativeInstanceField(wrapper, 1, reinterpret_cast(&info)); + TONIC_DCHECK(!LogIfError(res)); + this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper. dart_wrapper_ = Dart_NewWeakPersistentHandle( wrapper, this, GetAllocationSize(), &FinalizeDartWrapper); diff --git a/third_party/tonic/dart_wrappable.h b/third_party/tonic/dart_wrappable.h index d6823c1ef92bc..dda11f904e648 100644 --- a/third_party/tonic/dart_wrappable.h +++ b/third_party/tonic/dart_wrappable.h @@ -20,12 +20,6 @@ namespace tonic { // exposed to Dart code as an interface. class DartWrappable { public: - enum DartNativeFields { - kPeerIndex, // Must be first to work with Dart_GetNativeReceiver. - kWrapperInfoIndex, - kNumberOfNativeFields, - }; - DartWrappable() : dart_wrapper_(nullptr) {} // Subclasses that wish to expose a new interface must override this function From 1ae66cf9b937eac45b2dd41b4e7e019036e4ea75 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Thu, 13 Feb 2020 09:10:25 -0800 Subject: [PATCH 2/5] Fix compile error --- third_party/tonic/dart_wrappable.cc | 5 ++--- third_party/tonic/dart_wrappable.h | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/third_party/tonic/dart_wrappable.cc b/third_party/tonic/dart_wrappable.cc index e749dfdf414a5..f7c987e160eda 100644 --- a/third_party/tonic/dart_wrappable.cc +++ b/third_party/tonic/dart_wrappable.cc @@ -25,10 +25,9 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) { Dart_Handle wrapper = Dart_New(type, Dart_Null(), 0, nullptr); TONIC_DCHECK(!LogIfError(wrapper)); - // Must set peer first to work with Dart_GetNativeReceiver. - Dart_Handle res = Dart_SetNativeInstanceField(wrapper, 0, reinterpret_cast(this)); + Dart_Handle res = Dart_SetNativeInstanceField(wrapper, kPeerIndex, reinterpret_cast(this)); TONIC_DCHECK(!LogIfError(res)); - res = Dart_SetNativeInstanceField(wrapper, 1, reinterpret_cast(&info)); + res = Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex, reinterpret_cast(&info)); TONIC_DCHECK(!LogIfError(res)); this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper. diff --git a/third_party/tonic/dart_wrappable.h b/third_party/tonic/dart_wrappable.h index dda11f904e648..d6823c1ef92bc 100644 --- a/third_party/tonic/dart_wrappable.h +++ b/third_party/tonic/dart_wrappable.h @@ -20,6 +20,12 @@ namespace tonic { // exposed to Dart code as an interface. class DartWrappable { public: + enum DartNativeFields { + kPeerIndex, // Must be first to work with Dart_GetNativeReceiver. + kWrapperInfoIndex, + kNumberOfNativeFields, + }; + DartWrappable() : dart_wrapper_(nullptr) {} // Subclasses that wish to expose a new interface must override this function From f55b0ab7f48a12895c1981713176faff887c3cd5 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Thu, 13 Feb 2020 09:17:55 -0800 Subject: [PATCH 3/5] Formatting --- third_party/tonic/dart_wrappable.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/third_party/tonic/dart_wrappable.cc b/third_party/tonic/dart_wrappable.cc index f7c987e160eda..d99c8af324f87 100644 --- a/third_party/tonic/dart_wrappable.cc +++ b/third_party/tonic/dart_wrappable.cc @@ -25,9 +25,11 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) { Dart_Handle wrapper = Dart_New(type, Dart_Null(), 0, nullptr); TONIC_DCHECK(!LogIfError(wrapper)); - Dart_Handle res = Dart_SetNativeInstanceField(wrapper, kPeerIndex, reinterpret_cast(this)); + Dart_Handle res = Dart_SetNativeInstanceField( + wrapper, kPeerIndex, reinterpret_cast(this)); TONIC_DCHECK(!LogIfError(res)); - res = Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex, reinterpret_cast(&info)); + res = Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex, + reinterpret_cast(&info)); TONIC_DCHECK(!LogIfError(res)); this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper. From 743efd6181e1b24eb9fc240f32d5682f421d274a Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 14 Feb 2020 11:44:51 -0800 Subject: [PATCH 4/5] Invoke private constructor --- third_party/tonic/dart_wrappable.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/tonic/dart_wrappable.cc b/third_party/tonic/dart_wrappable.cc index d99c8af324f87..b5edf4f8f55a9 100644 --- a/third_party/tonic/dart_wrappable.cc +++ b/third_party/tonic/dart_wrappable.cc @@ -22,7 +22,8 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) { Dart_PersistentHandle type = dart_state->class_library().GetClass(info); TONIC_DCHECK(!LogIfError(type)); - Dart_Handle wrapper = Dart_New(type, Dart_Null(), 0, nullptr); + Dart_Handle private_constructor_name = Dart_NewStringFromCString("_"); + Dart_Handle wrapper = Dart_New(type, private_constructor_name, 0, nullptr); TONIC_DCHECK(!LogIfError(wrapper)); Dart_Handle res = Dart_SetNativeInstanceField( From 6c50bc5594afa84de3166df1adde10f6a9287667 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 14 Feb 2020 12:47:38 -0800 Subject: [PATCH 5/5] Added private constructor to Path --- lib/ui/painting.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index e44287a96a573..8e7e8ea697e5b 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -1890,6 +1890,12 @@ class Path extends NativeFieldWrapperClass2 { /// Create a new empty [Path] object. @pragma('vm:entry-point') Path() { _constructor(); } + + // Workaround for tonic, which expects classes with native fields to have a + // private constructor. + @pragma('vm:entry-point') + Path._() { _constructor(); } + void _constructor() native 'Path_constructor'; /// Creates a copy of another [Path].