Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart

Issue 2971243003: fix #30094, assert should work with a function (Closed)
Patch Set: fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
index 835ead6f55a006461877ef6cb31680a4c128fc5c..d8014d99ed6feb7339dd88c153a6a3d89553b003 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart
@@ -701,11 +701,20 @@ map(values, [K, V]) => JS(
})()''');
@JSExportName('assert')
-assert_(condition, [message]) => JS(
- '',
- '''(() => {
- if (!$condition) $throwAssertionError(message);
-})()''');
+assert_(condition, message()) {
+ if (JS('bool', '# !== true', condition)) {
+ if (condition == null) _throwBooleanConversionError();
Jennifer Messerly 2017/07/07 23:43:17 Now has correct handling for null
+ throwAssertionError(message);
+ }
+}
+
+dassert(value, message()) {
+ if (JS('bool', '# != null && #[#] instanceof #', value, value, _runtimeType,
+ AbstractFunctionType)) {
+ value = JS('', '#(#)', dcall, value);
+ }
+ return assert_(dtest(value), message);
Jennifer Messerly 2017/07/07 23:43:17 now correctly handles all cases where a non-boolea
+}
/// Store a JS error for an exception. For non-primitives, we store as an
/// expando. For primitive, we use a side cache. To limit memory leakage, we

Powered by Google App Engine
This is Rietveld 408576698