Skip to content

Refactor: stop implementing NativeWrapperClasses #123756

@dcharkes

Description

@dcharkes

Implementing subtypes of NativeWrapperClasses can lead to issues when passing such native wrapper to a native call, as it will try to unwrap a native field that doesn't exist (likely leading to a segfault).

The NativeWrapperClasses should be marked base so that none of their subtypes can be implemented:

Flutter has classes which extend NativeWrapperClasses and are mocked in tests, and Flutter has already opted in to 3.0, so adding the class modifiers to dart:nativewrappers is a breaking change for Flutter.

org-dartlang-sdk:///flutter/lib/ui/compositing.dart:13:7: Error: The type 'Scene' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:2537:7: Error: The type 'EngineLayer' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/compositing.dart:231:7: Error: The type 'SceneBuilder' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:1941:7: Error: The type '_Image' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:2071:7: Error: The type 'Codec' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:2580:7: Error: The type 'Path' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:3193:7: Error: The type '_PathMeasure' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:3535:7: Error: The type '_ColorFilter' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:3809:7: Error: The type '_ImageFilter' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:3891:7: Error: The type 'Shader' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:4322:7: Error: The type 'FragmentProgram' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:4573:7: Error: The type 'Vertices' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:4831:7: Error: The type 'Canvas' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:5991:7: Error: The type 'Picture' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:6111:7: Error: The type 'PictureRecorder' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:6359:7: Error: The type 'ImmutableBuffer' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/painting.dart:6461:7: Error: The type 'ImageDescriptor' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/semantics.dart:680:16: Error: The type 'StringAttribute' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/semantics.dart:771:7: Error: The type 'SemanticsUpdateBuilder' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/semantics.dart:1052:7: Error: The type 'SemanticsUpdate' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/text.dart:2681:7: Error: The type 'Paragraph' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.
org-dartlang-sdk:///flutter/lib/ui/text.dart:2958:7: Error: The type 'ParagraphBuilder' must be 'base', 'final' or 'sealed' because the supertype 'NativeFieldWrapperClass1' is 'base'.

log

A possible migration path would be to define APIs like Path as abstract classes that do not extend NativeFieldWrapperClass1. Apps would then call a factory to construct an instance of the engine's implementation that can be passed to native. cc @jason-simmons @dnfield

If possible, we should get these class modifiers into Dart 3.0. FYI @leafpetersen

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.r: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions