Chromium Code Reviews| Index: sdk/lib/_internal/lib/mirrors_patch.dart |
| diff --git a/sdk/lib/_internal/lib/mirrors_patch.dart b/sdk/lib/_internal/lib/mirrors_patch.dart |
| index 71c1e68c7b55a3538910eddf6f628846c16b738d..518277ad7a8689372749b7aab9635070cc2dba18 100644 |
| --- a/sdk/lib/_internal/lib/mirrors_patch.dart |
| +++ b/sdk/lib/_internal/lib/mirrors_patch.dart |
| @@ -5,12 +5,37 @@ |
| // Patch library for dart:mirrors. |
| import 'dart:_js_mirrors' as js; |
| +import 'dart:_internal' as internal show Symbol; |
| patch class MirrorSystem { |
| patch static String getName(Symbol symbol) => js.getName(symbol); |
| patch static Symbol getSymbol(String name, [LibraryMirror library]) { |
|
ahe
2014/02/24 10:43:23
Could you move this code to a top-level in _js_mir
Lasse Reichstein Nielsen
2014/03/03 12:58:44
Done.
|
| - throw new UnimplementedError("MirrorSystem.getSymbol not implemented"); |
| + if (_isPublicSymbol(name)) { |
| + return new internal.Symbol.validated(name); |
| + } |
| + if (library == null) { |
| + throw new ArgumentError( |
| + "Library required for private symbol name: $name"); |
| + } |
| + if (!internal.Symbol.validatePrivate(name)) { |
| + throw new ArgumentError("Not a valid symbol name: $name"); |
| + } |
| + throw new UnimplementedError( |
| + "MirrorSystem.getSymbol not implemented for private names"); |
| + } |
| + |
| + static bool _isPublicSymbol(String name) { |
| + // A symbol is public if it doesn't start with '_' and it doesn't |
| + // have a part (following a '.') that starts with '_'. |
| + const int UNDERSCORE = 0x5f; |
| + if (name.isEmpty) return true; |
| + int index = -1; |
| + do { |
| + if (name.codeUnitAt(index + 1) == UNDERSCORE) return false; |
| + index = name.indexOf('.', index + 1); |
| + } while (index >= 0 && index + 1 < name.length); |
| + return true; |
| } |
| } |