[3.0 alpha] Remove deprecated NoSuchMessageError API

Contributes to https://github.com/dart-lang/sdk/issues/49529

Change-Id: I2cef41b991c59869f606235929347449e17022cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271082
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Michael Thomsen 2022-12-12 09:48:05 +00:00
parent d6b40b0926
commit 4028b9b0fe
8 changed files with 25 additions and 43 deletions

View file

@ -2,6 +2,16 @@
### Libraries
#### `dart:core`
- **Breaking change** [#49529][]:
- Removed the deprecated [`NoSuchMethodError`][] default constructor.
Use the [`NoSuchMethodError.withInvocation`][] named constructor instead.
[#49529]: https://github.com/dart-lang/sdk/issues/49529
[`NoSuchMethodError`]: https://api.dart.dev/stable/2.18.4/dart-core/NoSuchMethodError/NoSuchMethodError.html
[`NoSuchMethodError.withInvocation`]: https://api.dart.dev/stable/2.18.4/dart-core/NoSuchMethodError/NoSuchMethodError.withInvocation.html
#### `dart:html`
- **Breaking change**: As previously announced, the deprecated `registerElement`

View file

@ -139,7 +139,8 @@ class JsObject {
if (args != null) args = List.from(args.map(_convertToJS));
var fn = JS('', '#[#]', _jsObject, method);
if (JS<bool>('!', 'typeof(#) !== "function"', fn)) {
throw NoSuchMethodError(_jsObject, Symbol('$method'), args, {});
final invocation = Invocation.method(Symbol('$method'), args, {});
throw NoSuchMethodError.withInvocation(_jsObject, invocation);
}
return _convertToDart(JS('', '#.apply(#, #)', fn, _jsObject, args));
}

View file

@ -90,7 +90,10 @@ throwNullValueError() {
// TODO(vsm): Per spec, we should throw an NSM here. Technically, we ought
// to thread through method info, but that uglifies the code and can't
// actually be queried ... it only affects how the error is printed.
throw NoSuchMethodError(null, Symbol('<Unexpected Null Value>'), null, null);
throw NoSuchMethodError.withInvocation(
null,
Invocation.method(Symbol('<Unexpected Null Value>'), null, null),
);
}
castError(obj, expectedType) {

View file

@ -334,8 +334,7 @@ abstract class Interceptor {
// calls to use interceptor calling convention). If we did allow it, the
// interceptor context would select the correct `this`.
dynamic noSuchMethod(Invocation invocation) {
throw new NoSuchMethodError(this, invocation.memberName,
invocation.positionalArguments, invocation.namedArguments);
throw new NoSuchMethodError.withInvocation(this, invocation);
}
Type get runtimeType => getRuntimeType(this);

View file

@ -208,18 +208,6 @@ class NoSuchMethodError {
typeArgumentsLength, typeArguments, arguments, argumentNames);
}
// Deprecated constructor.
@patch
NoSuchMethodError(this._receiver, Symbol memberName,
List? positionalArguments, Map<Symbol, dynamic>? namedArguments,
[List? existingArgumentNames = null]) // existingArgumentNames ignored.
: this._invocation = new _InvocationMirror._withType(
memberName,
_InvocationMirror._UNINITIALIZED,
null, // Type arguments not supported in deprecated constructor.
positionalArguments,
namedArguments);
// Helper to build a map of named arguments.
static Map<Symbol, dynamic> _NamedArgumentsMap(
List arguments, List argumentNames) {

View file

@ -551,31 +551,6 @@ class NoSuchMethodError extends Error {
external factory NoSuchMethodError.withInvocation(
Object? receiver, Invocation invocation);
/// Create a [NoSuchMethodError] corresponding to a failed method call.
///
/// The [receiver] is the receiver of the method call.
/// That is, the object on which the method was attempted called.
/// If the receiver is `null`, it is interpreted as a call to a top-level
/// function of a library.
///
/// The [memberName] is a [Symbol] representing the name of the called method
/// or accessor.
///
/// The [positionalArguments] is a list of the positional arguments that the
/// method was called with. If `null`, it is considered equivalent to the
/// empty list.
///
/// The [namedArguments] is a map from [Symbol]s to the values of named
/// arguments that the method was called with. If `null`, it is considered
/// equivalent to the empty map.
///
/// This constructor does not handle type arguments.
/// To include type variables, create an [Invocation] and use
/// [NoSuchMethodError.withInvocation].
@Deprecated("Use NoSuchMethod.withInvocation instead")
external NoSuchMethodError(Object? receiver, Symbol memberName,
List? positionalArguments, Map<Symbol, dynamic>? namedArguments);
external String toString();
}

View file

@ -56,7 +56,10 @@ class CarolCaretaker implements Carol {
CarolCaretaker(this._carol, this._gate);
foo() {
if (!_gate()) throw new NoSuchMethodError(this, #foo, [], {});
if (!_gate()) throw new NoSuchMethodError.withInvocation(
this,
Invocation.method(#foo, [], {}),
);
return _carol.foo();
}

View file

@ -58,7 +58,10 @@ class CarolCaretaker implements Carol {
CarolCaretaker(this._carol, this._gate);
foo() {
if (!_gate()) throw new NoSuchMethodError(this, #foo, [], {});
if (!_gate()) throw new NoSuchMethodError.withInvocation(
this,
Invocation.method(#foo, [], {}),
);
return _carol.foo();
}