OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /** | 5 /** |
6 * Convert top-level or static functions to objects that can be sent to | 6 * Convert top-level or static functions to objects that can be sent to |
7 * other isolates. | 7 * other isolates. |
8 * | 8 * |
9 * This package is only needed until such functions can be sent directly | 9 * This package is only needed until such functions can be sent directly |
10 * through send-ports. | 10 * through send-ports. |
(...skipping 14 matching lines...) Expand all Loading... | |
25 if (owner is ClassMirror) { | 25 if (owner is ClassMirror) { |
26 className = owner.simpleName; | 26 className = owner.simpleName; |
27 owner = owner.owner; | 27 owner = owner.owner; |
28 } | 28 } |
29 if (owner is LibraryMirror) { | 29 if (owner is LibraryMirror) { |
30 LibraryMirror ownerLibrary = owner; | 30 LibraryMirror ownerLibrary = owner; |
31 Uri libraryUri = ownerLibrary.uri; | 31 Uri libraryUri = ownerLibrary.uri; |
32 return new _FunctionRef(libraryUri, className, functionName); | 32 return new _FunctionRef(libraryUri, className, functionName); |
33 } | 33 } |
34 } | 34 } |
35 throw new ArgumentError.value(function, "function", | 35 throw new ArgumentError.value( |
36 "Not a static or top-level function"); | 36 function, "function", "Not a static or top-level function"); |
37 } | 37 } |
38 // It's a Function but not a closure, so it's a callable object. | 38 // It's a Function but not a closure, so it's a callable object. |
39 return new _CallableObjectRef(function); | 39 return new _CallableObjectRef(function); |
40 } | 40 } |
41 | 41 |
42 Function get function; | 42 Function get function; |
43 } | 43 } |
44 | 44 |
45 class _FunctionRef implements FunctionRef { | 45 class _FunctionRef implements FunctionRef { |
46 final Uri libraryUri; | 46 final Uri libraryUri; |
(...skipping 11 matching lines...) Expand all Loading... | |
58 owner = cm; | 58 owner = cm; |
59 } | 59 } |
60 if (owner != null) { | 60 if (owner != null) { |
61 ClosureMirror function = owner.getField(this.functionName); | 61 ClosureMirror function = owner.getField(this.functionName); |
62 if (function != null) return function.reflectee; | 62 if (function != null) return function.reflectee; |
63 } | 63 } |
64 } | 64 } |
65 String functionName = MirrorSystem.getName(this.functionName); | 65 String functionName = MirrorSystem.getName(this.functionName); |
66 String classQualifier = ""; | 66 String classQualifier = ""; |
67 if (this.className != null) { | 67 if (this.className != null) { |
68 classQualifier = " in class ${MirrorSystem.getName(this.className)}"; | 68 classQualifier = " in class ${MirrorSystem.getName(this.className)}"; |
69 } | 69 } |
70 throw new UnsupportedError( | 70 throw new UnsupportedError( |
71 "Function $functionName${classQualifier} not found in library $libraryUri" | 71 "Function $functionName${classQualifier} not found in library $libraryUr i"); |
Lasse Reichstein Nielsen
2015/02/26 10:59:15
Long line. The original was badly indented, but I'
| |
72 ); | |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 class _CallableObjectRef implements FunctionRef { | 75 class _CallableObjectRef implements FunctionRef { |
77 final Function object; | 76 final Function object; |
78 _CallableObjectRef(this.object); | 77 _CallableObjectRef(this.object); |
79 Function get function => object; | 78 Function get function => object; |
80 } | 79 } |
OLD | NEW |