Skip to content

Commit

Permalink
Revert "[web] use callConstructor for FinalizationRegistry due to bug… (
Browse files Browse the repository at this point in the history
#40841)

… in dart2js (#40798)"

This reverts commit d5a0b29.

The original PR resulted in a silent failure.
  • Loading branch information
yjbanov authored Apr 1, 2023
1 parent c3c951c commit b6756c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
9 changes: 3 additions & 6 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3569,12 +3569,9 @@ extension JsConstructorExtension on JsConstructor {
@JS('window.FinalizationRegistry')
@staticInterop
class SkObjectFinalizationRegistry {
factory SkObjectFinalizationRegistry(JSFunction cleanup) {
return js_util.callConstructor(
_finalizationRegistryConstructor!.toObjectShallow,
<Object>[cleanup],
);
}
// TODO(hterkelsen): Add a type for the `cleanup` function when
// native constructors support type parameters.
external factory SkObjectFinalizationRegistry(JSFunction cleanup);
}

extension SkObjectFinalizationRegistryExtension on SkObjectFinalizationRegistry {
Expand Down
8 changes: 3 additions & 5 deletions lib/web_ui/lib/src/engine/canvaskit/native_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import 'canvaskit_api.dart';

/// Collects native objects that weren't explicitly disposed of using
/// [UniqueRef.dispose] or [CountedRef.unref].
SkObjectFinalizationRegistry _finalizationRegistry = SkObjectFinalizationRegistry(
(UniqueRef<Object> uniq) {
uniq.collect();
}.toJS
);
SkObjectFinalizationRegistry _finalizationRegistry = SkObjectFinalizationRegistry((UniqueRef<Object> uniq) {
uniq.collect();
}.toJS);

NativeMemoryFinalizationRegistry nativeMemoryFinalizationRegistry = NativeMemoryFinalizationRegistry();

Expand Down
10 changes: 0 additions & 10 deletions lib/web_ui/test/canvaskit/canvaskit_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:js_interop';
import 'dart:math';
import 'dart:typed_data';

Expand Down Expand Up @@ -1894,15 +1893,6 @@ void _paragraphTests() {
'http://localhost:1234/foo/canvaskit.wasm',
);
});

test('SkObjectFinalizationRegistry', () {
// There's no reliable way to test the actual functionality of
// FinalizationRegistry because it depends on GC, which cannot be controlled,
// So the test simply tests that a FinalizationRegistry can be constructed
// and its `register` method can be called.
final SkObjectFinalizationRegistry registry = SkObjectFinalizationRegistry((String arg) {}.toJS);
registry.register('foo', 'bar');
});
}


Expand Down

0 comments on commit b6756c5

Please sign in to comment.