diff --git a/lib/src/component_declaration/component_base.dart b/lib/src/component_declaration/component_base.dart index 640763e38..69355f618 100644 --- a/lib/src/component_declaration/component_base.dart +++ b/lib/src/component_declaration/component_base.dart @@ -21,7 +21,6 @@ import 'package:meta/meta.dart'; import 'package:over_react/over_react.dart'; import 'package:over_react/src/component_declaration/component_type_checking.dart'; -import 'package:over_react/src/util/ddc_emulated_function_name_bug.dart' as ddc_emulated_function_name_bug; import 'package:over_react/src/util/test_mode.dart'; import 'package:react/react.dart' as react; import 'package:react/react_client.dart'; @@ -483,14 +482,6 @@ abstract class UiProps extends MapBase $CssClassPropsMixin implements Map { - - UiProps() { - // Work around https://github.com/dart-lang/sdk/issues/27647 for all UiProps instances - if (ddc_emulated_function_name_bug.isBugPresent) { - ddc_emulated_function_name_bug.patchName(this); - } - } - /// Adds an arbitrary [propKey]/[value] pair if [shouldAdd] is `true`. /// /// Is a noop if [shouldAdd] is `false`. diff --git a/lib/src/util/ddc_emulated_function_name_bug.dart b/lib/src/util/ddc_emulated_function_name_bug.dart deleted file mode 100644 index 3fcadae89..000000000 --- a/lib/src/util/ddc_emulated_function_name_bug.dart +++ /dev/null @@ -1,85 +0,0 @@ -/// Provides detection and patching of the bug described in , -/// in which getters/setters with the identifier `name` don't work for emulated function classes, like [UiProps]. -@JS() -library over_react.src.util.ddc_emulated_function_name_bug; - -import 'package:js/js.dart'; -import 'package:over_react/over_react.dart'; - -/// Create a reduced test case of the issue, using an emulated function pattern that is similar to [UiProps]. -/// -/// We can't use [UiProps] itself, since it uses [isBugPresent], and that would cause a cyclic initialization error. -class _NsmEmulatedFunctionWithNameProperty implements Function { - void call(); - - @override - noSuchMethod(i) {} - - String _name; - - // ignore: unnecessary_getters_setters - String get name => _name; - // ignore: unnecessary_getters_setters - set name(String value) => _name = value; -} - -/// Whether this bug, , is present in the current runtime. -/// -/// This performs functional detection of the bug, and will be `true` -/// only in the DDC and only in versions of the DDC where this bug is present. -final bool isBugPresent = (() { - const testValue = 'test value'; - - var testObject = new _NsmEmulatedFunctionWithNameProperty(); - - try { - // In the DDC, this throws: - // TypeError: Cannot assign to read only property 'name' of function 'function call(...args) { - // return call.call.apply(call, args); - // }' - testObject.name = testValue; - } catch(_) { - return true; - } - - try { - // We don't expect accessing this to throw, but just in case... - return testObject.name != testValue; - } catch(_) { - return true; - } -})(); - - -@JS() -@anonymous -class _PropertyDescriptor {} - -@JS('Object.getPrototypeOf') -external dynamic _getPrototypeOf(dynamic object); - -@JS('Object.getOwnPropertyDescriptor') -external _PropertyDescriptor _getOwnPropertyDescriptor(dynamic object, String propertyName); - -@JS('Object.defineProperty') -external void _defineProperty(dynamic object, String propertyName, _PropertyDescriptor descriptor); - -/// Patches the `name` property on the given [object] to have the expected behavior -/// by copying the property descriptor for `name` from the appropriate prototype. -/// -/// This is a noop if `name` is not a property on the given object. -/// -/// __This functionality is unstable, and should not be used when [isBugPresent] is `false`.__ -/// -/// This method also had undefined behavior on non-[UiProps] instances. -void patchName(dynamic object) { - var current = object; - while ((current = _getPrototypeOf(current)) != null) { - var nameDescriptor = _getOwnPropertyDescriptor(current, 'name'); - - if (nameDescriptor != null) { - _defineProperty(object, 'name', nameDescriptor); - return; - } - } -} diff --git a/test/over_react/util/ddc_emulated_function_name_bug_test.dart b/test/over_react/util/ddc_emulated_function_name_bug_test.dart deleted file mode 100644 index 8af4ddbdb..000000000 --- a/test/over_react/util/ddc_emulated_function_name_bug_test.dart +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2016 Workiva Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import 'package:test/test.dart'; - -import 'package:over_react/src/util/ddc_emulated_function_name_bug.dart'; - -main() { - group('ddc_emulated_function_name_bug library:', () { - group('isBugPresent correctly detects whether the bug is present', () { - test('in dart2js', () { - expect(isBugPresent, isFalse); - }, testOn: 'js'); - - test('in content_shell/Dartium', () { - expect(isBugPresent, isFalse); - }, testOn: 'dart-vm'); - - // This bug is fixed in Dart 2. - // TODO: Remove the whole lib this file is testing: -// test('in the DDC', () { -// expect(isBugPresent, isTrue, -// reason: 'if this test fails, then it\'s possible that the bug was fixed in' -// ' a newer version of the Dart SDK, and this library can be eliminated!' -// ); -// }, tags: 'ddc', -// // Tests run in `ddev coverage` don't respect tags and show up as the 'vm' platform -// // so we can use this to disable certain browser tests during coverage. -// // Workaround for https://github.com/Workiva/dart_dev/issues/200 -// testOn: '!vm'); - }); - - // This bug is fixed in Dart 2. - // TODO: Remove the whole lib this file is testing: -// test('patchName fixes instances of a class with the issue in the DDC', () { -// const testValue = 'test value'; -// -// var testObject = new ProblematicClass(); -// -// try { -// testObject.name = testValue; -// } catch(_) {} -// expect(testObject.name, isNot(testValue), reason: 'sanity check that the bug is present'); -// -// patchName(testObject); -// -// expect(() => testObject.name = testValue, returnsNormally); -// expect(testObject.name, testValue); -// }, tags: 'ddc', -// // Tests run in `ddev coverage` don't respect tags and show up as the 'vm' platform -// // so we can use this to disable certain browser tests during coverage. -// // Workaround for https://github.com/Workiva/dart_dev/issues/200 -// testOn: '!vm'); - }); -} - -class ProblematicClass implements Function { - void call(); - - @override - noSuchMethod(i) {} - - String _name; - - // ignore: unnecessary_getters_setters - String get name => _name; - // ignore: unnecessary_getters_setters - set name(String value) => _name = value; -} diff --git a/test/over_react_util_test.dart b/test/over_react_util_test.dart index c5ff0768f..9715e86c7 100644 --- a/test/over_react_util_test.dart +++ b/test/over_react_util_test.dart @@ -26,7 +26,6 @@ import 'package:test/test.dart'; import 'over_react/util/class_names_test.dart' as class_names_test; import 'over_react/util/constants_base_test.dart' as constants_base_test; import 'over_react/util/css_value_util_test.dart' as css_value_util_test; -import 'over_react/util/ddc_emulated_function_name_bug_test.dart' as ddc_emulated_function_name_bug_test; import 'over_react/util/dom_util_test.dart' as dom_util_test; import 'over_react/util/event_helpers_test.dart' as event_helpers_test; import 'over_react/util/guid_util_test.dart' as guid_util_test; @@ -48,7 +47,6 @@ void main() { class_names_test.main(); constants_base_test.main(); css_value_util_test.main(); - ddc_emulated_function_name_bug_test.main(); dom_util_test.main(); event_helpers_test.main(); guid_util_test.main();