未验证 提交 1340970b 编写于 作者: C Chris Bracken 提交者: GitHub

Assert in place of ArgumentError for null checks (#5612)

For consistency with the rest of dart:ui, check required parameters with
assert(param != null) rather than throwing ArgumentError. ArgumentError
is typically reserved for checking the validity of non-null args -- e.g.
that a list has the required number of elements.
上级 2c158b63
......@@ -7,31 +7,29 @@ part of dart.ui;
abstract class IsolateNameServer {
// Looks up the [SendPort] associated with a given name. Returns null
// if the name does not exist.
//
// `name` must not be null.
static SendPort lookupPortByName(String name) {
if (name == null) {
throw new ArgumentError("'name' cannot be null.");
}
assert(name != null, "'name' cannot be null.");
return _lookupPortByName(name);
}
// Registers a SendPort with a given name. Returns true if registration is
// successful, false if the name entry already exists.
//
// `port` and `name` must not be null.
static bool registerPortWithName(SendPort port, String name) {
if (name == null) {
throw new ArgumentError("'name' cannot be null.");
}
if (port == null) {
throw new ArgumentError("'port' cannot be null.");
}
assert(port != null, "'port' cannot be null.");
assert(name != null, "'name' cannot be null.");
return _registerPortWithName(port, name);
}
// Removes a name to SendPort mapping given a name. Returns true if the
// mapping was successfully removed, false if the mapping does not exist.
//
// `name` must not be null.
static bool removePortNameMapping(String name) {
if (name == null) {
throw new ArgumentError("'name' cannot be null.");
}
assert(name != null, "'name' cannot be null.");
return _removePortNameMapping(name);
}
......
......@@ -81,20 +81,6 @@ void main() {
receivePort2.close();
});
test('isolate name server null args', () {
// None of our IsolateNameServer methods should accept null.
expect(() => IsolateNameServer.lookupPortByName(null), throwsArgumentError);
expect(() => IsolateNameServer.registerPortWithName(null, 'abc'),
throwsArgumentError);
final receivePort = new ReceivePort();
final sendPort = receivePort.sendPort;
expect(() => IsolateNameServer.registerPortWithName(sendPort, null),
throwsArgumentError);
expect(() => IsolateNameServer.removePortNameMapping(null),
throwsArgumentError);
receivePort.close();
});
test('isolate name server multi-isolate', () async {
// Register our send port with the name server.
final receivePort = new ReceivePort();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册