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

Unified Diff: frog/value.dart

Issue 8534001: Adds typechecking of return values (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: better runtime checks Created 9 years, 1 month 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: frog/value.dart
diff --git a/frog/value.dart b/frog/value.dart
index e370fda36f36f7933c05f2bf12bfc5a9f896b3ea..0e9333fc7fa7ce14e64bfa648a955af874e68534 100644
--- a/frog/value.dart
+++ b/frog/value.dart
@@ -33,6 +33,12 @@ class Value {
/** Is this value a constant expression? */
bool get isConst() => false;
+ /**
+ * A canonicalized form of the code. Two const expressions that result in the
+ * same instance should have the same [canonicalCode].
+ */
+ String get canonicalCode() => null;
+
// TODO(jimhug): Fix these names once get/set are truly pseudo-keywords.
// See issue #379.
Value get_(MethodGenerator context, String name, Node node) {
@@ -327,7 +333,15 @@ class Value {
// We rely on the fact that calling an undefined method produces a JS
// TypeError. Alternatively we could define fallbacks on Object that throw.
String check;
- if (toType.library.isCore && toType.typeofName != null) {
+ if (toType.isVoid) {
+ check = '\$assert_void($code)';
+ if (toType.typeCheckCode == null) {
+ toType.typeCheckCode = '''
+function \$assert_void(x) {
+ return x == null ? x : x.is\$void(); // throws TypeError
+}''';
+ }
+ } else if (toType.library.isCore && toType.typeofName != null) {
check = '\$assert_${toType.name}($code)';
if (toType.typeCheckCode == null) {

Powered by Google App Engine
This is Rietveld 408576698