| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library _interceptors; | 5 library _interceptors; |
| 6 | 6 |
| 7 import 'dart:_js_embedded_names' show | 7 import 'dart:_js_embedded_names' show |
| 8 DISPATCH_PROPERTY_NAME, | 8 DISPATCH_PROPERTY_NAME, |
| 9 MAP_TYPE_TO_INTERCEPTOR; | 9 MAP_TYPE_TO_INTERCEPTOR; |
| 10 | 10 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 /** | 178 /** |
| 179 * Data structure used to map a [Type] to the [Interceptor] and constructors for | 179 * Data structure used to map a [Type] to the [Interceptor] and constructors for |
| 180 * that type. It is JavaScript array of 3N entries of adjacent slots containing | 180 * that type. It is JavaScript array of 3N entries of adjacent slots containing |
| 181 * a [Type], followed by an [Interceptor] class for the type, followed by a | 181 * a [Type], followed by an [Interceptor] class for the type, followed by a |
| 182 * JavaScript object map for the constructors. | 182 * JavaScript object map for the constructors. |
| 183 * | 183 * |
| 184 * The value of this variable is set by the compiler and contains only types | 184 * The value of this variable is set by the compiler and contains only types |
| 185 * that are user extensions of native classes where the type occurs as a | 185 * that are user extensions of native classes where the type occurs as a |
| 186 * constant in the program. | 186 * constant in the program. |
| 187 * | 187 * |
| 188 * The compiler, in CustomElementsAnalysis, assumes that [mapTypeToInterceptor] | 188 * The compiler, in CustomElementsAnalysis, assumes that [typeToInterceptorMap] |
| 189 * is accessed only by code that also calls [findIndexForWebComponentType]. If | 189 * is accessed only by code that also calls [findIndexForWebComponentType]. If |
| 190 * this assumption is invalidated, the compiler will have to be updated. | 190 * this assumption is invalidated, the compiler will have to be updated. |
| 191 */ | 191 */ |
| 192 get mapTypeToInterceptor { | 192 get typeToInterceptorMap { |
| 193 return JS_EMBEDDED_GLOBAL('', MAP_TYPE_TO_INTERCEPTOR); | 193 return JS_EMBEDDED_GLOBAL('', TYPE_TO_INTERCEPTOR_MAP); |
| 194 } | 194 } |
| 195 | 195 |
| 196 int findIndexForNativeSubclassType(Type type) { | 196 int findIndexForNativeSubclassType(Type type) { |
| 197 if (JS('bool', '# == null', mapTypeToInterceptor)) return null; | 197 if (JS('bool', '# == null', typeToInterceptorMap)) return null; |
| 198 List map = JS('JSFixedArray', '#', mapTypeToInterceptor); | 198 List map = JS('JSFixedArray', '#', typeToInterceptorMap); |
| 199 for (int i = 0; i + 1 < map.length; i += 3) { | 199 for (int i = 0; i + 1 < map.length; i += 3) { |
| 200 if (type == map[i]) { | 200 if (type == map[i]) { |
| 201 return i; | 201 return i; |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 return null; | 204 return null; |
| 205 } | 205 } |
| 206 | 206 |
| 207 findInterceptorConstructorForType(Type type) { | 207 findInterceptorConstructorForType(Type type) { |
| 208 var index = findIndexForNativeSubclassType(type); | 208 var index = findIndexForNativeSubclassType(type); |
| 209 if (index == null) return null; | 209 if (index == null) return null; |
| 210 List map = JS('JSFixedArray', '#', mapTypeToInterceptor); | 210 List map = JS('JSFixedArray', '#', typeToInterceptorMap); |
| 211 return map[index + 1]; | 211 return map[index + 1]; |
| 212 } | 212 } |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * Returns a JavaScript function that runs the constructor on its argument, or | 215 * Returns a JavaScript function that runs the constructor on its argument, or |
| 216 * `null` if there is no such constructor. | 216 * `null` if there is no such constructor. |
| 217 * | 217 * |
| 218 * The returned function takes one argument, the web component object. | 218 * The returned function takes one argument, the web component object. |
| 219 */ | 219 */ |
| 220 findConstructorForNativeSubclassType(Type type, String name) { | 220 findConstructorForNativeSubclassType(Type type, String name) { |
| 221 var index = findIndexForNativeSubclassType(type); | 221 var index = findIndexForNativeSubclassType(type); |
| 222 if (index == null) return null; | 222 if (index == null) return null; |
| 223 List map = JS('JSFixedArray', '#', mapTypeToInterceptor); | 223 List map = JS('JSFixedArray', '#', typeToInterceptorMap); |
| 224 var constructorMap = map[index + 2]; | 224 var constructorMap = map[index + 2]; |
| 225 var constructorFn = JS('', '#[#]', constructorMap, name); | 225 var constructorFn = JS('', '#[#]', constructorMap, name); |
| 226 return constructorFn; | 226 return constructorFn; |
| 227 } | 227 } |
| 228 | 228 |
| 229 findInterceptorForType(Type type) { | 229 findInterceptorForType(Type type) { |
| 230 var constructor = findInterceptorConstructorForType(type); | 230 var constructor = findInterceptorConstructorForType(type); |
| 231 if (constructor == null) return null; | 231 if (constructor == null) return null; |
| 232 return JS('', '#.prototype', constructor); | 232 return JS('', '#.prototype', constructor); |
| 233 } | 233 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 * Interceptor for unclassified JavaScript objects, typically objects with a | 397 * Interceptor for unclassified JavaScript objects, typically objects with a |
| 398 * non-trivial prototype chain. | 398 * non-trivial prototype chain. |
| 399 * | 399 * |
| 400 * This class also serves as a fallback for unknown JavaScript exceptions. | 400 * This class also serves as a fallback for unknown JavaScript exceptions. |
| 401 */ | 401 */ |
| 402 class UnknownJavaScriptObject extends JavaScriptObject { | 402 class UnknownJavaScriptObject extends JavaScriptObject { |
| 403 const UnknownJavaScriptObject(); | 403 const UnknownJavaScriptObject(); |
| 404 | 404 |
| 405 String toString() => JS('String', 'String(#)', this); | 405 String toString() => JS('String', 'String(#)', this); |
| 406 } | 406 } |
| OLD | NEW |