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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart

Issue 11348133: Add JSNull, JSBool and JSFunction, and move toString into the new interceptor scheme. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/interceptors.dart (revision 15139)
+++ sdk/lib/_internal/compiler/implementation/lib/interceptors.dart (working copy)
@@ -28,6 +28,9 @@
if (isJsArray(object)) return const JSArray();
if (object is int) return const JSInt();
if (object is double) return const JSDouble();
+ if (object is bool) return const JSBool();
+ if (object == null) return const JSNull();
+ if (JS('String', 'typeof #', object) == 'function') return const JSFunction();
return const ObjectInterceptor();
}
@@ -58,25 +61,34 @@
return UNINTERCEPTED(receiver.iterator());
}
-toString(var value) {
- if (JS('bool', r'typeof # == "object" && # != null', value, value)) {
- if (isJsArray(value)) {
- return Collections.collectionToString(value);
- } else {
- return UNINTERCEPTED(value.toString());
- }
- }
- if (JS('bool', r'# === 0 && (1 / #) < 0', value, value)) {
- return '-0.0';
- }
- if (value == null) return 'null';
- if (JS('bool', r'typeof # == "function"', value)) {
- return 'Closure';
- }
- return JS('String', r'String(#)', value);
+/**
+ * The interceptor class for tear-off static methods. Unlike
+ * tear-off instance methods, tear-off static methods are just the JS
+ * function, and methods inherited from Object must therefore be
+ * intercepted.
+ */
+class JSFunction implements Function {
+ const JSFunction();
+ String toString() => 'Closure';
}
/**
+ * The interceptor class for [bool].
+ */
+class JSBool implements bool {
+ const JSBool();
+ String toString() => JS('String', r'String(#)', this);
+}
+
+/**
+ * The interceptor class for [Null].
+ */
+class JSNull implements Null {
+ const JSNull();
+ String toString() => 'null';
+}
+
+/**
* This is the [Jenkins hash function][1] but using masking to keep
* values in SMI range.
*
@@ -119,7 +131,3 @@
return UNINTERCEPTED(receiver.runtimeType);
}
}
-
-// TODO(lrn): These getters should be generated automatically for all
-// intercepted methods.
-get$toString(receiver) => () => toString(receiver);

Powered by Google App Engine
This is Rietveld 408576698