Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1258)

Side by Side Diff: dart/runtime/lib/symbol_patch.dart

Issue 14173005: Update dart:mirrors to use Symbol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add question about LibraryMirror.url Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 patch class Symbol { 5 patch class Symbol {
6 final String _name; 6 final String _name;
7 /* patch */ const Symbol(String name) 7 /* patch */ const Symbol(String name)
8 : this._name = _validate(name); 8 : this._name = _validate(name);
9 9
10 10
11 static final RegExp _validationPattern = 11 static final RegExp _validationPattern =
12 new RegExp(r'^[a-zA-Z$][a-zA-Z$0-9_]*=?'); 12 new RegExp(r'^(?:[a-zA-Z$][a-zA-Z$0-9_]*=?|'
13 r'-|'
14 r'\[\]=|'
15 r'~|'
16 r'==|'
17 r'\[\]|'
18 r'\*|'
19 r'/|'
20 r'%|'
21 r'~/|'
22 r'\+|'
23 r'<<|'
24 r'>>|'
25 r'>=|'
26 r'>|'
27 r'<=|'
28 r'<|'
29 r'&|'
30 r'\^|'
31 r'\|'
32 r')');
13 33
14 static _validate(String name) { 34 static _validate(String name) {
15 if (name is! String) throw new ArgumentError('name must be a String'); 35 if (name is! String) throw new ArgumentError('name must be a String');
16 if (name.isEmpty) return; 36 if (name.isEmpty) return name;
ahe 2013/04/11 20:12:27 Note to self: I need to update the symbol_test.dar
ahe 2013/04/15 12:34:02 Done.
17 if (name.startsWith('_')) { 37 if (name.startsWith('_')) {
18 throw new ArgumentError('"$name" is a private identifier'); 38 throw new ArgumentError('"$name" is a private identifier');
19 } 39 }
20 if (!_validationPattern.hasMatch(name)) { 40 if (!_validationPattern.hasMatch(name)) {
21 throw new ArgumentError( 41 throw new ArgumentError(
22 » '"$name" is not an identifier or an empty String'); 42 '"$name" is not an identifier or an empty String');
23 } 43 }
24 return name; 44 return name;
25 } 45 }
26 46
27 /* patch */ bool operator ==(other) { 47 /* patch */ bool operator ==(other) {
28 return other is Symbol && _name == other._name; 48 return other is Symbol &&
49 Symbol == other.runtimeType &&
50 _name == other._name;
29 } 51 }
30 52
31 /* patch */ int get hashCode { 53 /* patch */ int get hashCode {
32 const arbitraryPrime = 664597; 54 const arbitraryPrime = 664597;
33 return 0x1fffffff & (arbitraryPrime * _name.hashCode); 55 return 0x1fffffff & (arbitraryPrime * _name.hashCode);
34 } 56 }
57
58 /* patch */ static String getName(Symbol symbol) => symbol._name;
ahe 2013/04/11 20:12:27 I should not submit this change.
Ivan Posva 2013/04/12 04:16:18 Why not?
ahe 2013/04/15 12:34:02 Because this method needs to be in the mirror API,
35 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698