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

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

Issue 16851002: Implement minified MirrorSystem.getName. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
Index: dart/sdk/lib/_internal/lib/js_names.dart
diff --git a/dart/sdk/lib/_internal/lib/js_names.dart b/dart/sdk/lib/_internal/lib/js_names.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4aa1bd56883f416787b596abc2724e7fbf066992
--- /dev/null
+++ b/dart/sdk/lib/_internal/lib/js_names.dart
@@ -0,0 +1,46 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+library dart._js_names;
+
+import 'dart:_foreign_helper' show JS;
+
+/// No-op method that is called to inform the compiler that unmangled
+/// named must be preserved.
+preserveNames() {}
+
+final Map<String, String> mangledNames = computeMangledNames();
+
+final Map<String, String> reflectiveNames = computeReflectiveNames();
+
+Map<String, String> computeMangledNames() {
+ preserveNames();
+ var mangledNames = JS('', 'init.mangledNames');
+ var keys = extractKeys(mangledNames);
+ var result = <String, String>{};
+ for (String key in keys) {
+ result[key] = JS('String', '#[#]', mangledNames, key);
+ }
+ return result;
+}
+
+Map<String, String> computeReflectiveNames() {
+ preserveNames();
+ var result = <String, String>{};
+ mangledNames.forEach((String mangledName, String reflectiveName) {
+ result[reflectiveName] = mangledName;
kasperl 2013/06/19 09:19:50 Weird indentation.
ahe 2013/06/19 12:20:59 Done.
+ });
+ return result;
+}
+
+List extractKeys(victim) {
+ return JS('List', '''
+(function(victim, hasOwnProperty) {
+ var result = [];
+ for (var key in victim) {
+ if (hasOwnProperty.call(victim, key)) result.push(key);
+ }
+ return result;
+})(#, Object.prototype.hasOwnProperty)''', victim);
+}

Powered by Google App Engine
This is Rietveld 408576698