Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart._internal; | 5 part of dart._internal; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Implementation of [core.Symbol]. This class uses the same name as | 8 * Implementation of [core.Symbol]. This class uses the same name as |
| 9 * a core class so a user can't tell the difference. | 9 * a core class so a user can't tell the difference. |
| 10 * | 10 * |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 const Symbol.unvalidated(this._name); | 107 const Symbol.unvalidated(this._name); |
| 108 | 108 |
| 109 // This is called by dart2js. | 109 // This is called by dart2js. |
| 110 Symbol.validated(String name) | 110 Symbol.validated(String name) |
| 111 : this._name = validatePublicSymbol(name); | 111 : this._name = validatePublicSymbol(name); |
| 112 | 112 |
| 113 bool operator ==(other) => other is Symbol && _name == other._name; | 113 bool operator ==(other) => other is Symbol && _name == other._name; |
| 114 | 114 |
| 115 external int get hashCode; | 115 external int get hashCode; |
| 116 | 116 |
| 117 toString() => 'Symbol("$_name")'; | 117 external toString(); |
|
hausner
2016/12/14 23:35:40
Why is it necessary to patch toString()? Isn't the
Siggi Cherem (dart-lang)
2016/12/15 00:31:46
It seems like the vm was patching it with some ext
Lasse Reichstein Nielsen
2016/12/15 07:55:41
That's http://dartbug.com/13596 - the VM isn't val
| |
| 118 | 118 |
| 119 /// Platform-private accessor which cannot be called from user libraries. | 119 /// Platform-private accessor which cannot be called from user libraries. |
| 120 static String getName(Symbol symbol) => symbol._name; | 120 static String getName(Symbol symbol) => symbol._name; |
| 121 | 121 |
| 122 static String validatePublicSymbol(String name) { | 122 static String validatePublicSymbol(String name) { |
| 123 if (name.isEmpty || publicSymbolPattern.hasMatch(name)) return name; | 123 if (name.isEmpty || publicSymbolPattern.hasMatch(name)) return name; |
| 124 if (name.startsWith('_')) { | 124 if (name.startsWith('_')) { |
| 125 // There may be other private parts in a qualified name than the first | 125 // There may be other private parts in a qualified name than the first |
| 126 // one, but this is a common case that deserves a specific error | 126 // one, but this is a common case that deserves a specific error |
| 127 // message. | 127 // message. |
| 128 throw new ArgumentError('"$name" is a private identifier'); | 128 throw new ArgumentError('"$name" is a private identifier'); |
| 129 } | 129 } |
| 130 throw new ArgumentError( | 130 throw new ArgumentError( |
| 131 '"$name" is not a valid (qualified) symbol name'); | 131 '"$name" is not a valid (qualified) symbol name'); |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Checks whether name is a valid symbol name. | 135 * Checks whether name is a valid symbol name. |
| 136 * | 136 * |
| 137 * This test allows both private and non-private symbols. | 137 * This test allows both private and non-private symbols. |
| 138 */ | 138 */ |
| 139 static bool isValidSymbol(String name) { | 139 static bool isValidSymbol(String name) { |
| 140 return (name.isEmpty || symbolPattern.hasMatch(name)); | 140 return (name.isEmpty || symbolPattern.hasMatch(name)); |
| 141 } | 141 } |
| 142 } | 142 } |
| OLD | NEW |