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

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
« no previous file with comments | « sdk/lib/_internal/lib/foreign_helper.dart ('k') | sdk/lib/_internal/lib/native_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/interceptors.dart
diff --git a/sdk/lib/_internal/lib/interceptors.dart b/sdk/lib/_internal/lib/interceptors.dart
index 27c2edf91e61ad966fbe3dd16e1ce3ce42f83c5d..aa2d5a0c2b310865048ddc08405fdf74912a7c2f 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';
@@ -247,6 +247,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.
+ *
+ * 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.
*
« no previous file with comments | « sdk/lib/_internal/lib/foreign_helper.dart ('k') | sdk/lib/_internal/lib/native_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698