| Index: sdk/lib/_internal/js_runtime/lib/js_helper.dart
|
| diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
|
| index b4ab91c192b236631901ea56dfd63960692ea18a..309f255f7a75d48a2fe662fcede9a3bab75e4d9e 100644
|
| --- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart
|
| +++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
|
| @@ -3321,18 +3321,33 @@ class FallThroughErrorImplementation extends FallThroughError {
|
|
|
| /**
|
| * Helper function for implementing asserts. The compiler treats this specially.
|
| + *
|
| + * Returns the negation of the condition. That is: `true` if the assert should
|
| + * fail.
|
| + */
|
| +bool assertTest(condition) {
|
| + // Do bool success check first, it is common and faster than 'is Function'.
|
| + if (true == condition) return false;
|
| + if (condition is Function) condition = condition();
|
| + if (condition is bool) return !condition;
|
| + throw new TypeErrorImplementation(condition, 'bool');
|
| +}
|
| +
|
| +/**
|
| + * Helper function for implementing asserts with messages.
|
| + * The compiler treats this specially.
|
| */
|
| +void assertThrow(Object message) {
|
| + throw new _AssertionError(message);
|
| +}
|
| +
|
| +/**
|
| + * Helper function for implementing asserts without messages.
|
| + * The compiler treats this specially.
|
| + */
|
| +@NoInline()
|
| void assertHelper(condition) {
|
| - // Do a bool check first because it is common and faster than 'is Function'.
|
| - if (condition is !bool) {
|
| - if (condition is Function) condition = condition();
|
| - if (condition is !bool) {
|
| - throw new TypeErrorImplementation(condition, 'bool');
|
| - }
|
| - }
|
| - // Compare to true to avoid boolean conversion check in checked
|
| - // mode.
|
| - if (true != condition) throw new AssertionError();
|
| + if (assertTest(condition)) throw new AssertionError();
|
| }
|
|
|
| /**
|
| @@ -3995,3 +4010,10 @@ void badMain() {
|
| void mainHasTooManyParameters() {
|
| throw new MainError("'main' expects too many parameters.");
|
| }
|
| +
|
| +class _AssertionError extends AssertionError {
|
| + final _message;
|
| + _AssertionError(this._message);
|
| +
|
| + String toString() => "Assertion failed: " + Error.safeToString(_message);
|
| +}
|
|
|