Chromium Code Reviews| 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 | 8 |
| 9 part 'js_array.dart'; | 9 part 'js_array.dart'; |
| 10 part 'js_number.dart'; | 10 part 'js_number.dart'; |
| 11 part 'js_string.dart'; | 11 part 'js_string.dart'; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * The interceptor class for all non-primitive objects. All its | 14 * The interceptor class for all non-primitive objects. All its |
| 15 * members are synthethized by the compiler's emitter. | 15 * members are synthethized by the compiler's emitter. |
| 16 */ | 16 */ |
| 17 class ObjectInterceptor { | 17 class ObjectInterceptor { |
| 18 const ObjectInterceptor(); | 18 const ObjectInterceptor(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Get the interceptor for [object]. Called by the compiler when it needs | 22 * Get the interceptor for [object]. Called by the compiler when it needs |
| 23 * to emit a call to an intercepted method, that is a method that is | 23 * to emit a call to an intercepted method, that is a method that is |
| 24 * defined in an interceptor class. | 24 * defined in an interceptor class. |
| 25 */ | 25 */ |
| 26 getInterceptor(object) { | 26 Function getInterceptor; |
|
ahe
2012/11/27 14:29:45
I suggest using this pattern instead:
getIntercep
ngeoffray
2012/11/27 15:50:54
Done.
| |
| 27 if (object is String) return stringInterceptor; | |
| 28 if (isJsArray(object)) return arrayInterceptor; | |
| 29 if (object is int) return intInterceptor; | |
| 30 if (object is double) return doubleInterceptor; | |
| 31 if (object is bool) return boolInterceptor; | |
| 32 if (object == null) return nullInterceptor; | |
| 33 if (JS('String', 'typeof #', object) == 'function') { | |
| 34 return functionInterceptor; | |
| 35 } | |
| 36 return objectInterceptor; | |
| 37 } | |
| 38 | |
| 39 final arrayInterceptor = const JSArray(); | |
| 40 final boolInterceptor = const JSBool(); | |
| 41 final doubleInterceptor = const JSDouble(); | |
| 42 final intInterceptor = const JSInt(); | |
| 43 final functionInterceptor = const JSFunction(); | |
| 44 final nullInterceptor = const JSNull(); | |
| 45 final numberInterceptor = const JSNumber(); | |
| 46 final stringInterceptor = const JSString(); | |
| 47 final objectInterceptor = const ObjectInterceptor(); | |
| 48 | 27 |
| 49 /** | 28 /** |
| 50 * The interceptor class for tear-off static methods. Unlike | 29 * The interceptor class for tear-off static methods. Unlike |
| 51 * tear-off instance methods, tear-off static methods are just the JS | 30 * tear-off instance methods, tear-off static methods are just the JS |
| 52 * function, and methods inherited from Object must therefore be | 31 * function, and methods inherited from Object must therefore be |
| 53 * intercepted. | 32 * intercepted. |
| 54 */ | 33 */ |
| 55 class JSFunction implements Function { | 34 class JSFunction implements Function { |
| 56 const JSFunction(); | 35 const JSFunction(); |
| 57 String toString() => 'Closure'; | 36 String toString() => 'Closure'; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 73 | 52 |
| 74 /** | 53 /** |
| 75 * The interceptor class for [Null]. | 54 * The interceptor class for [Null]. |
| 76 */ | 55 */ |
| 77 class JSNull implements Null { | 56 class JSNull implements Null { |
| 78 const JSNull(); | 57 const JSNull(); |
| 79 String toString() => 'null'; | 58 String toString() => 'null'; |
| 80 int get hashCode => 0; | 59 int get hashCode => 0; |
| 81 Type get runtimeType => createRuntimeType('Null'); | 60 Type get runtimeType => createRuntimeType('Null'); |
| 82 } | 61 } |
| OLD | NEW |