@@ -474,7 +474,9 @@ asInt(obj) {
474
474
475
475
asNullableInt (obj) => obj == null ? null : asInt (obj);
476
476
477
- /// Checks that `x` is not null or undefined.
477
+ /// Checks for null or undefined and returns [x] .
478
+ ///
479
+ /// Throws [NoSuchMethodError] when it is null or undefined.
478
480
//
479
481
// TODO(jmesserly): inline this, either by generating it as a function into
480
482
// the module, or via some other pattern such as:
@@ -487,12 +489,13 @@ _notNull(x) {
487
489
return x;
488
490
}
489
491
490
- /// Checks that `x` is not null or undefined.
492
+ /// Checks for null or undefined and returns [x] .
493
+ ///
494
+ /// Throws a [TypeError] when [x] is null or undefined (under sound null safety
495
+ /// mode) or emits a runtime warning (otherwise).
491
496
///
492
- /// Unlike `_notNull` , this throws a `CastError` (under strict checking)
493
- /// or emits a runtime warning (otherwise). This is only used by the
494
- /// compiler when casting from nullable to non-nullable variants of the
495
- /// same type.
497
+ /// This is only used by the compiler when casting from nullable to non-nullable
498
+ /// variants of the same type.
496
499
nullCast (x, type) {
497
500
if (x == null ) {
498
501
if (! strictNullSafety) {
@@ -504,6 +507,16 @@ nullCast(x, type) {
504
507
return x;
505
508
}
506
509
510
+ /// Checks for null or undefined and returns [x] .
511
+ ///
512
+ /// Throws a [TypeError] when [x] is null or undefined.
513
+ ///
514
+ /// This is only used by the compiler for the runtime null check operator `!` .
515
+ nullCheck (x) {
516
+ if (x == null ) throw TypeErrorImpl ("Unexpected null value." );
517
+ return x;
518
+ }
519
+
507
520
/// The global constant map table.
508
521
final constantMaps = JS <Object >('!' , 'new Map()' );
509
522
0 commit comments