From c632a629ffa47182dc74a024a12928bb3fc23ac0 Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Thu, 16 Jul 2020 00:12:22 +0000 Subject: [PATCH] [web] remove mirrors patch for web compilers. This makes both compilers report a compile-time error when importing dart:mirrors. Change-Id: I23360b87ee31fba36fe7c111cee1987aa2d50638 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154622 Reviewed-by: Nicholas Shahan Commit-Queue: Sigmund Cherem --- CHANGELOG.md | 12 ++++++ .../js_runtime/lib/mirrors_patch_cfe.dart | 38 ------------------- sdk/lib/libraries.json | 15 -------- sdk/lib/libraries.yaml | 15 -------- tests/lib/web/mirrors_support_test.dart | 13 ++----- tests/lib_2/web/mirrors_support_test.dart | 13 ++----- 6 files changed, 18 insertions(+), 88 deletions(-) delete mode 100644 sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebc4799933..725055ba56c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,18 @@ [#41653]: https://github.com/dart-lang/sdk/issues/41653 +#### `dart:mirrors` + +* **Breaking Change** [#42714][]: web compilers (dart2js and DDC) now produce + a compile-time error if `dart:mirrors` is imported. + + Most projects should not be affected. Since 2.0.0 this library was + unsupported and produced runtime errors on all its APIs. Since then several + tools already reject code that use `dart:mirrors` including webdev and + flutter tools, we expect few projects to run into this problem. + +[#42714]: https://github.com/dart-lang/sdk/issues/42714 + ### Tools #### dartfmt diff --git a/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart b/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart deleted file mode 100644 index c429ecbf8e1..00000000000 --- a/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -// Patch library for dart:mirrors. - -import 'dart:_js_helper' show patch; -import 'dart:mirrors'; - -const String _message = 'dart:mirrors is no longer supported for web apps'; - -@patch -MirrorSystem currentMirrorSystem() => throw new UnsupportedError(_message); - -@patch -InstanceMirror reflect(dynamic reflectee) => - throw new UnsupportedError(_message); - -@patch -ClassMirror reflectClass(Type key) => throw new UnsupportedError(_message); - -@patch -TypeMirror reflectType(Type key, [List? typeArguments]) => - throw new UnsupportedError(_message); - -@patch -abstract class MirrorSystem { - @patch - LibraryMirror findLibrary(Symbol libraryName) => - throw new UnsupportedError(_message); - - @patch - static String getName(Symbol symbol) => throw new UnsupportedError(_message); - - @patch - static Symbol getSymbol(String name, [LibraryMirror? library]) => - throw new UnsupportedError(_message); -} diff --git a/sdk/lib/libraries.json b/sdk/lib/libraries.json index 02892382785..15b4cd31f09 100644 --- a/sdk/lib/libraries.json +++ b/sdk/lib/libraries.json @@ -221,11 +221,6 @@ "uri": "math/math.dart", "patches": "_internal/js_runtime/lib/math_patch.dart" }, - "mirrors": { - "uri": "mirrors/mirrors.dart", - "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", - "supported": false - }, "typed_data": { "uri": "typed_data/typed_data.dart", "patches": "_internal/js_runtime/lib/typed_data_patch.dart" @@ -334,11 +329,6 @@ "uri": "math/math.dart", "patches": "_internal/js_runtime/lib/math_patch.dart" }, - "mirrors": { - "uri": "mirrors/mirrors.dart", - "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", - "supported": false - }, "typed_data": { "uri": "typed_data/typed_data.dart", "patches": "_internal/js_runtime/lib/typed_data_patch.dart" @@ -448,11 +438,6 @@ "patches": "_internal/js_dev_runtime/patch/isolate_patch.dart", "supported": false }, - "mirrors": { - "uri": "mirrors/mirrors.dart", - "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", - "supported": false - }, "math": { "uri": "math/math.dart", "patches": "_internal/js_dev_runtime/patch/math_patch.dart" diff --git a/sdk/lib/libraries.yaml b/sdk/lib/libraries.yaml index a80284d02e6..50e350e892f 100644 --- a/sdk/lib/libraries.yaml +++ b/sdk/lib/libraries.yaml @@ -218,11 +218,6 @@ dart2js: uri: "math/math.dart" patches: "_internal/js_runtime/lib/math_patch.dart" - mirrors: - uri: "mirrors/mirrors.dart" - patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" - supported: false - typed_data: uri: "typed_data/typed_data.dart" patches: "_internal/js_runtime/lib/typed_data_patch.dart" @@ -329,11 +324,6 @@ dart2js_server: uri: "math/math.dart" patches: "_internal/js_runtime/lib/math_patch.dart" - mirrors: - uri: "mirrors/mirrors.dart" - patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" - supported: false - typed_data: uri: "typed_data/typed_data.dart" patches: "_internal/js_runtime/lib/typed_data_patch.dart" @@ -441,11 +431,6 @@ dartdevc: patches: "_internal/js_dev_runtime/patch/isolate_patch.dart" supported: false - mirrors: - uri: "mirrors/mirrors.dart" - patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" - supported: false - math: uri: "math/math.dart" patches: "_internal/js_dev_runtime/patch/math_patch.dart" diff --git a/tests/lib/web/mirrors_support_test.dart b/tests/lib/web/mirrors_support_test.dart index 03dc2d5bae9..78f3648a625 100644 --- a/tests/lib/web/mirrors_support_test.dart +++ b/tests/lib/web/mirrors_support_test.dart @@ -2,16 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// 'dart:mirrors' provides no functionality in dart-web, but can be imported and -// all APIs throw. -import 'dart:mirrors'; -import 'package:expect/expect.dart'; +// 'dart:mirrors' can no longer be imported, doing so produces a static error. +import 'dart:mirrors'; //# 01: compile-time error main() { - Expect.throws(() => currentMirrorSystem()); - Expect.throws(() => reflect(main)); - Expect.throws(() => reflectClass(Object)); - Expect.throws(() => reflectType(Object)); - Expect.throws(() => MirrorSystem.getName(#core)); - Expect.throws(() => MirrorSystem.getSymbol("core")); + reflect(main); //# 01: continued } diff --git a/tests/lib_2/web/mirrors_support_test.dart b/tests/lib_2/web/mirrors_support_test.dart index 03dc2d5bae9..78f3648a625 100644 --- a/tests/lib_2/web/mirrors_support_test.dart +++ b/tests/lib_2/web/mirrors_support_test.dart @@ -2,16 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// 'dart:mirrors' provides no functionality in dart-web, but can be imported and -// all APIs throw. -import 'dart:mirrors'; -import 'package:expect/expect.dart'; +// 'dart:mirrors' can no longer be imported, doing so produces a static error. +import 'dart:mirrors'; //# 01: compile-time error main() { - Expect.throws(() => currentMirrorSystem()); - Expect.throws(() => reflect(main)); - Expect.throws(() => reflectClass(Object)); - Expect.throws(() => reflectType(Object)); - Expect.throws(() => MirrorSystem.getName(#core)); - Expect.throws(() => MirrorSystem.getSymbol("core")); + reflect(main); //# 01: continued }