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

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

Issue 25675002: Generative constructor factories for native objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 9dff6fbd4f70356211521212c6a648243889d62c..78b591d69b353ea1acddc60cff48dc522cd3553e 100644
--- a/sdk/lib/_internal/lib/interceptors.dart
+++ b/sdk/lib/_internal/lib/interceptors.dart
@@ -151,9 +151,10 @@ 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.
+ * Data structure used to map a [Type] to the [Interceptor] and constructors for
+ * that type. It is JavaScript array of 3N entries of adjacent slots containing
+ * a [Type], followed by an [Interceptor] class for the type, followed by a
+ * JavaScript object map for the constructors.
*
* 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
@@ -162,18 +163,40 @@ var interceptedNames;
// TODO(sra): Mark this as initialized to a constant with unknown value.
var mapTypeToInterceptor;
-findInterceptorConstructorForType(Type type) {
+int findIndexForWebComponentType(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) {
+ for (int i = 0; i + 1 < map.length; i += 3) {
if (type == map[i]) {
- return map[i + 1];
+ return i;
}
}
return null;
}
+findInterceptorConstructorForType(Type type) {
+ var index = findIndexForWebComponentType(type);
+ if (index == null) return null;
+ List map = JS('JSFixedArray', '#', mapTypeToInterceptor);
+ return mapTypeToInterceptor[index + 1];
+}
+
+/**
+ * Returns a JavaScript function that runs the constructor on its argument, or
+ * `null` if there is no such constructor.
+ *
+ * The returned function takes one argument, the web component object.
+ */
+findConstructorForWebComponentType(Type type, String name) {
+ var index = findIndexForWebComponentType(type);
+ if (index == null) return null;
+ List map = JS('JSFixedArray', '#', mapTypeToInterceptor);
+ var constructorMap = mapTypeToInterceptor[index + 2];
+ var constructorFn = JS('', '#[#]', constructorMap, name);
+ return constructorFn;
+}
+
findInterceptorForType(Type type) {
var constructor = findInterceptorConstructorForType(type);
if (constructor == null) return null;

Powered by Google App Engine
This is Rietveld 408576698