File tree 3 files changed +21
-6
lines changed 3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -3569,9 +3569,12 @@ extension JsConstructorExtension on JsConstructor {
3569
3569
@JS ('window.FinalizationRegistry' )
3570
3570
@staticInterop
3571
3571
class SkObjectFinalizationRegistry {
3572
- // TODO(hterkelsen): Add a type for the `cleanup` function when
3573
- // native constructors support type parameters.
3574
- external factory SkObjectFinalizationRegistry (JSFunction cleanup);
3572
+ factory SkObjectFinalizationRegistry (JSFunction cleanup) {
3573
+ return js_util.callConstructor (
3574
+ _finalizationRegistryConstructor! .toObjectShallow,
3575
+ < Object > [cleanup],
3576
+ );
3577
+ }
3575
3578
}
3576
3579
3577
3580
extension SkObjectFinalizationRegistryExtension on SkObjectFinalizationRegistry {
Original file line number Diff line number Diff line change @@ -11,9 +11,11 @@ import 'canvaskit_api.dart';
11
11
12
12
/// Collects native objects that weren't explicitly disposed of using
13
13
/// [UniqueRef.dispose] or [CountedRef.unref] .
14
- SkObjectFinalizationRegistry _finalizationRegistry = SkObjectFinalizationRegistry ((UniqueRef <Object > uniq) {
15
- uniq.collect ();
16
- }.toJS);
14
+ SkObjectFinalizationRegistry _finalizationRegistry = SkObjectFinalizationRegistry (
15
+ (UniqueRef <Object > uniq) {
16
+ uniq.collect ();
17
+ }.toJS
18
+ );
17
19
18
20
NativeMemoryFinalizationRegistry nativeMemoryFinalizationRegistry = NativeMemoryFinalizationRegistry ();
19
21
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'dart:js_interop' ;
5
6
import 'dart:math' ;
6
7
import 'dart:typed_data' ;
7
8
@@ -1891,6 +1892,15 @@ void _paragraphTests() {
1891
1892
'http://localhost:1234/foo/canvaskit.wasm' ,
1892
1893
);
1893
1894
});
1895
+
1896
+ test ('SkObjectFinalizationRegistry' , () {
1897
+ // There's no reliable way to test the actual functionality of
1898
+ // FinalizationRegistry because it depends on GC, which cannot be controlled,
1899
+ // So the test simply tests that a FinalizationRegistry can be constructed
1900
+ // and its `register` method can be called.
1901
+ final SkObjectFinalizationRegistry registry = SkObjectFinalizationRegistry ((String arg) {}.toJS);
1902
+ registry.register ('foo' , 'bar' );
1903
+ });
1894
1904
}
1895
1905
1896
1906
You can’t perform that action at this time.
0 commit comments