| Index: dart/sdk/lib/_collection_dev/symbol.dart
|
| diff --git a/dart/sdk/lib/_collection_dev/symbol.dart b/dart/sdk/lib/_collection_dev/symbol.dart
|
| index 1a81f4767fd1c08d18f34cc543d27bb04ea114f1..7fd79d3d0e570ebf793bb230a46df41923f1f7bb 100644
|
| --- a/dart/sdk/lib/_collection_dev/symbol.dart
|
| +++ b/dart/sdk/lib/_collection_dev/symbol.dart
|
| @@ -15,6 +15,30 @@ part of dart._collection.dev;
|
| class Symbol implements core.Symbol {
|
| final String _name;
|
|
|
| + static final RegExp validationPattern =
|
| + new RegExp(r'^(?:[a-zA-Z$][a-zA-Z$0-9_]*\.)*(?:[a-zA-Z$][a-zA-Z$0-9_]*=?|'
|
| + r'-|'
|
| + r'unary-|'
|
| + r'\[\]=|'
|
| + r'~|'
|
| + r'==|'
|
| + r'\[\]|'
|
| + r'\*|'
|
| + r'/|'
|
| + r'%|'
|
| + r'~/|'
|
| + r'\+|'
|
| + r'<<|'
|
| + r'>>|'
|
| + r'>=|'
|
| + r'>|'
|
| + r'<=|'
|
| + r'<|'
|
| + r'&|'
|
| + r'\^|'
|
| + r'\|'
|
| + r')$');
|
| +
|
| external const Symbol(String name);
|
|
|
| /**
|
| @@ -23,6 +47,10 @@ class Symbol implements core.Symbol {
|
| */
|
| const Symbol.unvalidated(this._name);
|
|
|
| + // This is called by dart2js.
|
| + Symbol.validated(String name)
|
| + : this._name = validate(name);
|
| +
|
| bool operator ==(other) => other is Symbol && _name == other._name;
|
|
|
| int get hashCode {
|
| @@ -32,4 +60,16 @@ class Symbol implements core.Symbol {
|
|
|
| /// Platform-private accessor which cannot be called from user libraries.
|
| static String getName(Symbol symbol) => symbol._name;
|
| +
|
| + static String validate(String name) {
|
| + if (name.isEmpty) return name;
|
| + if (name.startsWith('_')) {
|
| + throw new ArgumentError('"$name" is a private identifier');
|
| + }
|
| + if (!validationPattern.hasMatch(name)) {
|
| + throw new ArgumentError(
|
| + '"$name" is not an identifier or an empty String');
|
| + }
|
| + return name;
|
| + }
|
| }
|
|
|