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

Unified Diff: sdk/lib/_internal/lib/mirrors_patch.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: 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/symbol.dart » ('j') | sdk/lib/internal/symbol.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/mirrors_patch.dart
diff --git a/sdk/lib/_internal/lib/mirrors_patch.dart b/sdk/lib/_internal/lib/mirrors_patch.dart
index 71c1e68c7b55a3538910eddf6f628846c16b738d..518277ad7a8689372749b7aab9635070cc2dba18 100644
--- a/sdk/lib/_internal/lib/mirrors_patch.dart
+++ b/sdk/lib/_internal/lib/mirrors_patch.dart
@@ -5,12 +5,37 @@
// Patch library for dart:mirrors.
import 'dart:_js_mirrors' as js;
+import 'dart:_internal' as internal show Symbol;
patch class MirrorSystem {
patch static String getName(Symbol symbol) => js.getName(symbol);
patch static Symbol getSymbol(String name, [LibraryMirror library]) {
ahe 2014/02/24 10:43:23 Could you move this code to a top-level in _js_mir
Lasse Reichstein Nielsen 2014/03/03 12:58:44 Done.
- throw new UnimplementedError("MirrorSystem.getSymbol not implemented");
+ if (_isPublicSymbol(name)) {
+ return new internal.Symbol.validated(name);
+ }
+ if (library == null) {
+ throw new ArgumentError(
+ "Library required for private symbol name: $name");
+ }
+ if (!internal.Symbol.validatePrivate(name)) {
+ throw new ArgumentError("Not a valid symbol name: $name");
+ }
+ throw new UnimplementedError(
+ "MirrorSystem.getSymbol not implemented for private names");
+ }
+
+ static 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/symbol.dart » ('j') | sdk/lib/internal/symbol.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698