Add ArgumentError.checkNotNull utility

In the places where other utilities like `RangeError.checkNotNegative`
are used it reads nicer to call through a similar signature than to
follow a conditional with the utility.

Change-Id: Idd89b2934020fb55e57a22c39773fd7879d1c28f
Reviewed-on: https://dart-review.googlesource.com/c/81287
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b310f71..eba4543 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -151,6 +151,7 @@
 ### Core library changes
 
 *   Add `HashMap.fromEntries` and `LinkedHashmap.fromEntries` constructors.
+*   Add `ArgumentError.checkNotNull` utility method.
 
 ### Dart VM
 
diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart
index 5f60976..015c414 100644
--- a/sdk/lib/core/errors.dart
+++ b/sdk/lib/core/errors.dart
@@ -173,6 +173,13 @@
         message = "Must not be null",
         invalidValue = null;
 
+  /**
+   * Throws if [argument] is `null`.
+   */
+  static void checkNotNull(Object argument, [String name]) {
+    if (argument == null) throw ArgumentError.notNull(name);
+  }
+
   // Helper functions for toString overridden in subclasses.
   String get _errorName => "Invalid argument${!_hasValue ? "(s)" : ""}";
   String get _errorExplanation => "";