From 36499224b6af4c4b4e773b310ba20714457d1da4 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Fri, 31 Mar 2023 18:06:00 -0700 Subject: [PATCH] Revert "[web] use callConstructor for FinalizationRegistry due to bug in dart2js (#40798)" This reverts commit d5a0b29132197a851dfeb594fe63ba9cffa045d0. --- lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart | 9 +++------ lib/web_ui/lib/src/engine/canvaskit/native_memory.dart | 8 +++----- lib/web_ui/test/canvaskit/canvaskit_api_test.dart | 10 ---------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart index de79aa6a9a147..6d70ee28b3f80 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart @@ -3569,12 +3569,9 @@ extension JsConstructorExtension on JsConstructor { @JS('window.FinalizationRegistry') @staticInterop class SkObjectFinalizationRegistry { - factory SkObjectFinalizationRegistry(JSFunction cleanup) { - return js_util.callConstructor( - _finalizationRegistryConstructor!.toObjectShallow, - [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 { diff --git a/lib/web_ui/lib/src/engine/canvaskit/native_memory.dart b/lib/web_ui/lib/src/engine/canvaskit/native_memory.dart index 45b051c5058e1..77d80f8f5e39d 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/native_memory.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/native_memory.dart @@ -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 uniq) { - uniq.collect(); - }.toJS -); +SkObjectFinalizationRegistry _finalizationRegistry = SkObjectFinalizationRegistry((UniqueRef uniq) { + uniq.collect(); +}.toJS); NativeMemoryFinalizationRegistry nativeMemoryFinalizationRegistry = NativeMemoryFinalizationRegistry(); diff --git a/lib/web_ui/test/canvaskit/canvaskit_api_test.dart b/lib/web_ui/test/canvaskit/canvaskit_api_test.dart index b9e292c11ac08..a92dcdc755e5e 100644 --- a/lib/web_ui/test/canvaskit/canvaskit_api_test.dart +++ b/lib/web_ui/test/canvaskit/canvaskit_api_test.dart @@ -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'; @@ -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'); - }); }