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

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

Issue 15026006: Support for extending native classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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: sdk/lib/_internal/lib/interceptors.dart
diff --git a/sdk/lib/_internal/lib/interceptors.dart b/sdk/lib/_internal/lib/interceptors.dart
index 5e6e77e46a59fdb76722bf1640ad2e152c31b520..464b2db70110492beafc4b6cb139d966204858ed 100644
--- a/sdk/lib/_internal/lib/interceptors.dart
+++ b/sdk/lib/_internal/lib/interceptors.dart
@@ -25,7 +25,7 @@ import 'dart:_js_helper' show allMatchesInStringUnchecked,
lookupDispatchRecord,
StringMatch,
firstMatchAfter;
-import 'dart:_foreign_helper' show JS;
+import 'dart:_foreign_helper' show JS, JS_EFFECT;
part 'js_array.dart';
part 'js_number.dart';
@@ -246,6 +246,37 @@ void initializeDispatchPropertyCSP(
*/
var interceptedNames;
+
+/**
+ * Data structure used to map a [Type] to the [Interceptor] for that type. It
+ * is JavaScript array of 2N entries of adjacent slots containing a [Type]
+ * followed by an [Interceptor] class for the type.
ahe 2013/08/13 18:31:47 I'm not sure how critical this is for performance,
sra1 2013/08/14 04:36:47 It is not critical, at least for now. For the typ
+ *
+ * The value of this variable is set by the compiler and contains only types
+ * that are user extensions of native classes where the type occurs as a
+ * constant in the program.
+ */
+// TODO(sra): Mark this as initialized to a constant with unknown value.
+var mapTypeToInterceptor;
+
+findClassConstructorForType(Type type) {
+ JS_EFFECT((_){ mapTypeToInterceptor = _; });
+ if (mapTypeToInterceptor == null) return null;
+ List map = JS('JSFixedArray', '#', mapTypeToInterceptor);
+ for (int i = 0; i + 1 < map.length; i += 2) {
+ if (type == map[i]) {
+ return map[i + 1];
+ }
+ }
+ return null;
+}
+
+findInterceptorForType(Type type) {
+ var constructor = findClassConstructorForType(type);
+ if (constructor == null) return null;
+ return JS('', '#.prototype', constructor);
+}
+
/**
* The base interceptor class.
*

Powered by Google App Engine
This is Rietveld 408576698