Skip to content

Commit 901d380

Browse files
bkonyiNoamDev
authored andcommitted
Remove usage of Dart_AllocateWithNativeFields from tonic (flutter#16588)
This API is being removed from the Dart SDK.
1 parent ed844fe commit 901d380

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/ui/painting.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,12 @@ class Path extends NativeFieldWrapperClass2 {
18901890
/// Create a new empty [Path] object.
18911891
@pragma('vm:entry-point')
18921892
Path() { _constructor(); }
1893+
1894+
// Workaround for tonic, which expects classes with native fields to have a
1895+
// private constructor.
1896+
@pragma('vm:entry-point')
1897+
Path._() { _constructor(); }
1898+
18931899
void _constructor() native 'Path_constructor';
18941900

18951901
/// Creates a copy of another [Path].

third_party/tonic/dart_wrappable.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) {
2222
Dart_PersistentHandle type = dart_state->class_library().GetClass(info);
2323
TONIC_DCHECK(!LogIfError(type));
2424

25-
intptr_t native_fields[kNumberOfNativeFields];
26-
native_fields[kPeerIndex] = reinterpret_cast<intptr_t>(this);
27-
native_fields[kWrapperInfoIndex] = reinterpret_cast<intptr_t>(&info);
28-
Dart_Handle wrapper =
29-
Dart_AllocateWithNativeFields(type, kNumberOfNativeFields, native_fields);
25+
Dart_Handle private_constructor_name = Dart_NewStringFromCString("_");
26+
Dart_Handle wrapper = Dart_New(type, private_constructor_name, 0, nullptr);
3027
TONIC_DCHECK(!LogIfError(wrapper));
3128

29+
Dart_Handle res = Dart_SetNativeInstanceField(
30+
wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this));
31+
TONIC_DCHECK(!LogIfError(res));
32+
res = Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex,
33+
reinterpret_cast<intptr_t>(&info));
34+
TONIC_DCHECK(!LogIfError(res));
35+
3236
this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
3337
dart_wrapper_ = Dart_NewWeakPersistentHandle(
3438
wrapper, this, GetAllocationSize(), &FinalizeDartWrapper);

0 commit comments

Comments
 (0)