| 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..5e0fc8954ea6d47222363f01c9f7a8d7ac2210b8
|
| --- /dev/null
|
| +++ b/dart/sdk/lib/_internal/lib/js_names.dart
|
| @@ -0,0 +1,64 @@
|
| +// 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() {}
|
| +
|
| +/// A map from mangled names to "reflective" names, that is, unmangled names
|
| +/// with some additional information, such as, number of required arguments.
|
| +/// This map is for mangled names used as instance members.
|
| +final Map<String, String> mangledNames =
|
| + computeMangledNames(JS('', 'init.mangledNames'));
|
| +
|
| +/// A map from "reflective" names to mangled names (the reverse of
|
| +/// [mangledNames]).
|
| +final Map<String, String> reflectiveNames =
|
| + computeReflectiveNames(mangledNames);
|
| +
|
| +/// A map from mangled names to "reflective" names (see [mangledNames]). This
|
| +/// map is for globals, that is, static and top-level members.
|
| +final Map<String, String> mangledGlobalNames =
|
| + computeMangledNames(JS('', 'init.mangledGlobalNames'));
|
| +
|
| +/// A map from "reflective" names to mangled names (the reverse of
|
| +/// [mangledGlobalNames]).
|
| +final Map<String, String> reflectiveGlobalNames =
|
| + computeReflectiveNames(mangledGlobalNames);
|
| +
|
| +/// [jsMangledNames] is a JavaScript object literal. The keys are the mangled
|
| +/// names, and the values are the "reflective" names.
|
| +Map<String, String> computeMangledNames(jsMangledNames) {
|
| + preserveNames();
|
| + var keys = extractKeys(jsMangledNames);
|
| + var result = <String, String>{};
|
| + for (String key in keys) {
|
| + result[key] = JS('String', '#[#]', jsMangledNames, key);
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +Map<String, String> computeReflectiveNames(Map<String, String> map) {
|
| + preserveNames();
|
| + var result = <String, String>{};
|
| + map.forEach((String mangledName, String reflectiveName) {
|
| + result[reflectiveName] = mangledName;
|
| + });
|
| + 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);
|
| +}
|
|
|