Chromium Code Reviews| Index: dart/runtime/lib/symbol_patch.dart |
| diff --git a/dart/runtime/lib/symbol_patch.dart b/dart/runtime/lib/symbol_patch.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0a658845f8718d6b1847c91112648ef9d02234b7 |
| --- /dev/null |
| +++ b/dart/runtime/lib/symbol_patch.dart |
| @@ -0,0 +1,21 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
kasperl
2013/04/11 10:48:58
2013
ahe
2013/04/11 11:26:06
Done.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +patch class Symbol { |
| + final String _name; |
| + /* patch */ const Symbol(String name) |
| + : this._name = _validate(name); |
| + |
| + static _validate(String name) { |
| + if (name is! String) throw new ArgumentError('name must be a String'); |
| + if (name.isEmpty) return; |
| + if (name.startsWith('_')) { |
| + throw new ArgumentError('"$name" is a private identifier'); |
| + } |
| + if (!new RegExp(r'^[a-zA-Z$][a-zA-Z$0-9]*=?').hasMatch(name)) { |
|
kasperl
2013/04/11 10:48:58
Throw the RegExp into a lazily initialized static
ahe
2013/04/11 11:26:06
Done * 2
|
| + throw new ArgumentError( |
| + '"$name" is not an identifier or the empty String'); |
|
kasperl
2013/04/11 10:48:58
I'd change 'the empty String' to 'an empty string'
ahe
2013/04/11 11:26:06
Done.
|
| + } |
| + } |
| +} |