| 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:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:_collection-dev' hide Symbol; | 8 import 'dart:_collection-dev' hide Symbol; |
| 9 import "dart:_collection-dev" as _symbol_dev show Symbol; | 9 import "dart:_collection-dev" as _symbol_dev show Symbol; |
| 10 import 'dart:_js_helper' show allMatchesInStringUnchecked, | 10 import 'dart:_js_helper' show allMatchesInStringUnchecked, |
| 11 Null, | 11 Null, |
| 12 JSSyntaxRegExp, | 12 JSSyntaxRegExp, |
| 13 Primitives, | 13 Primitives, |
| 14 checkNull, | 14 checkNull, |
| 15 checkNum, | 15 checkNum, |
| 16 checkString, | 16 checkString, |
| 17 defineProperty, | 17 defineProperty, |
| 18 getRuntimeType, | 18 getRuntimeType, |
| 19 regExpGetNative, | 19 regExpGetNative, |
| 20 stringContainsUnchecked, | 20 stringContainsUnchecked, |
| 21 stringLastIndexOfUnchecked, | 21 stringLastIndexOfUnchecked, |
| 22 stringReplaceAllFuncUnchecked, | 22 stringReplaceAllFuncUnchecked, |
| 23 stringReplaceAllUnchecked, | 23 stringReplaceAllUnchecked, |
| 24 stringReplaceFirstUnchecked, | 24 stringReplaceFirstUnchecked, |
| 25 lookupDispatchRecord, | 25 lookupDispatchRecord, |
| 26 StringMatch, | 26 StringMatch, |
| 27 firstMatchAfter; | 27 firstMatchAfter; |
| 28 import 'dart:_foreign_helper' show JS; | 28 import 'dart:_foreign_helper' show JS, JS_EFFECT; |
| 29 | 29 |
| 30 part 'js_array.dart'; | 30 part 'js_array.dart'; |
| 31 part 'js_number.dart'; | 31 part 'js_number.dart'; |
| 32 part 'js_string.dart'; | 32 part 'js_string.dart'; |
| 33 | 33 |
| 34 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 34 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
| 35 | 35 |
| 36 _symbolMapToStringMap(Map<Symbol, dynamic> map) { | 36 _symbolMapToStringMap(Map<Symbol, dynamic> map) { |
| 37 if (map == null) return null; | 37 if (map == null) return null; |
| 38 var result = new Map<String, dynamic>(); | 38 var result = new Map<String, dynamic>(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 /** | 242 /** |
| 243 * If [JSInvocationMirror._invokeOn] is being used, this variable | 243 * If [JSInvocationMirror._invokeOn] is being used, this variable |
| 244 * contains a JavaScript array with the names of methods that are | 244 * contains a JavaScript array with the names of methods that are |
| 245 * intercepted. | 245 * intercepted. |
| 246 */ | 246 */ |
| 247 var interceptedNames; | 247 var interceptedNames; |
| 248 | 248 |
| 249 |
| 250 /** |
| 251 * A JavaScript array of 2N entries of adjacent slots containing a [Type] |
| 252 * followed by an [Interceptor] class for the type. |
| 253 * |
| 254 * The value of this variable is set by the compiler and contains only types |
| 255 * that are user extensions of native classes where the type occurs as a |
| 256 * constant in the program. |
| 257 */ |
| 258 // TODO(sra): Mark this as initialized to a constant with unknown value. |
| 259 var mapTypeToInterceptor; |
| 260 |
| 261 findInterceptorConstructorForType(Type type) { |
| 262 JS_EFFECT((_){ mapTypeToInterceptor = _; }); |
| 263 if (mapTypeToInterceptor == null) return null; |
| 264 List map = JS('JSFixedArray', '#', mapTypeToInterceptor); |
| 265 for (int i = 0; i + 1 < map.length; i += 2) { |
| 266 if (type == map[i]) { |
| 267 return map[i + 1]; |
| 268 } |
| 269 } |
| 270 return null; |
| 271 } |
| 272 |
| 273 findInterceptorForType(Type type) { |
| 274 var constructor = findInterceptorConstructorForType(type); |
| 275 if (constructor == null) return null; |
| 276 return JS('', '#.prototype', constructor); |
| 277 } |
| 278 |
| 249 /** | 279 /** |
| 250 * The base interceptor class. | 280 * The base interceptor class. |
| 251 * | 281 * |
| 252 * The code `r.foo(a)` is compiled to `getInterceptor(r).foo$1(r, a)`. The | 282 * The code `r.foo(a)` is compiled to `getInterceptor(r).foo$1(r, a)`. The |
| 253 * value returned by [getInterceptor] holds the methods separately from the | 283 * value returned by [getInterceptor] holds the methods separately from the |
| 254 * state of the instance. The compiler converts the methods on an interceptor | 284 * state of the instance. The compiler converts the methods on an interceptor |
| 255 * to take the Dart `this` argument as an explicit `receiver` argument. The | 285 * to take the Dart `this` argument as an explicit `receiver` argument. The |
| 256 * JavaScript `this` parameter is bound to the interceptor. | 286 * JavaScript `this` parameter is bound to the interceptor. |
| 257 * | 287 * |
| 258 * In order to have uniform call sites, if a method is defined on an | 288 * In order to have uniform call sites, if a method is defined on an |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 432 } |
| 403 | 433 |
| 404 | 434 |
| 405 /** | 435 /** |
| 406 * Interceptor for unclassified JavaScript objects, typically objects with a | 436 * Interceptor for unclassified JavaScript objects, typically objects with a |
| 407 * non-trivial prototype chain. | 437 * non-trivial prototype chain. |
| 408 */ | 438 */ |
| 409 class UnknownJavaScriptObject extends JavaScriptObject { | 439 class UnknownJavaScriptObject extends JavaScriptObject { |
| 410 const UnknownJavaScriptObject(); | 440 const UnknownJavaScriptObject(); |
| 411 } | 441 } |
| OLD | NEW |