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

Unified Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 177483002: Add validation of private symbols to the dart2js mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/mirrors_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/js_mirrors.dart
diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart
index 4b46cb21c990321c060762188845559effa11e2e..e74a97306d3d93265bf37023c74368a5e37b6f3f 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -2797,3 +2797,31 @@ class UnmodifiableMapView<K, V> implements Map<K, V> {
void clear() => _throw();
}
+
+Symbol getSymbol(String name, LibararyMirror library) {
+ if (_isPublicSymbol(name)) {
+ return new _symbol_dev.Symbol.validated(name);
+ }
+ if (library == null) {
+ throw new ArgumentError(
+ "Library required for private symbol name: $name");
+ }
+ if (!_symbol_dev.Symbol.validatePrivate(name)) {
+ throw new ArgumentError("Not a valid symbol name: $name");
+ }
+ throw new UnimplementedError(
+ "MirrorSystem.getSymbol not implemented for private names");
+}
+
+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;
+}
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/mirrors_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698