| OLD | NEW |
| 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 library dart._js_names; | 5 library dart._js_names; |
| 6 | 6 |
| 7 import 'dart:_js_embedded_names' show | 7 import 'dart:_js_embedded_names' show |
| 8 JsGetName, | 8 JsGetName, |
| 9 MANGLED_GLOBAL_NAMES, | 9 MANGLED_GLOBAL_NAMES, |
| 10 MANGLED_NAMES; | 10 MANGLED_NAMES; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 preserveNames(); | 73 preserveNames(); |
| 74 var result = <String, String>{}; | 74 var result = <String, String>{}; |
| 75 map.forEach((String mangledName, String reflectiveName) { | 75 map.forEach((String mangledName, String reflectiveName) { |
| 76 result[reflectiveName] = mangledName; | 76 result[reflectiveName] = mangledName; |
| 77 }); | 77 }); |
| 78 return result; | 78 return result; |
| 79 } | 79 } |
| 80 | 80 |
| 81 @NoInline() | 81 @NoInline() |
| 82 List extractKeys(victim) { | 82 List extractKeys(victim) { |
| 83 var result = JS('', ''' | 83 var result = JS('', '# ? Object.keys(#) : []', victim, victim); |
| 84 (function(victim, hasOwnProperty) { | |
| 85 var result = []; | |
| 86 for (var key in victim) { | |
| 87 if (hasOwnProperty.call(victim, key)) result.push(key); | |
| 88 } | |
| 89 return result; | |
| 90 })(#, Object.prototype.hasOwnProperty)''', victim); | |
| 91 return new JSArray.markFixed(result); | 84 return new JSArray.markFixed(result); |
| 92 } | 85 } |
| 93 | 86 |
| 94 /** | 87 /** |
| 95 * Returns the (global) unmangled version of [name]. | 88 * Returns the (global) unmangled version of [name]. |
| 96 * | 89 * |
| 97 * Normally, you should use [mangledGlobalNames] directly, but this method | 90 * Normally, you should use [mangledGlobalNames] directly, but this method |
| 98 * doesn't tell the compiler to preserve names. So this method only returns a | 91 * doesn't tell the compiler to preserve names. So this method only returns a |
| 99 * non-null value if some other component has made the compiler preserve names. | 92 * non-null value if some other component has made the compiler preserve names. |
| 100 * | 93 * |
| 101 * This is used, for example, to return unmangled names from TypeImpl.toString | 94 * This is used, for example, to return unmangled names from TypeImpl.toString |
| 102 * *if* names are being preserved for other reasons (use of dart:mirrors, for | 95 * *if* names are being preserved for other reasons (use of dart:mirrors, for |
| 103 * example). | 96 * example). |
| 104 */ | 97 */ |
| 105 String unmangleGlobalNameIfPreservedAnyways(String name) { | 98 String unmangleGlobalNameIfPreservedAnyways(String name) { |
| 106 var names = JS_EMBEDDED_GLOBAL('=Object', MANGLED_GLOBAL_NAMES); | 99 var names = JS_EMBEDDED_GLOBAL('=Object', MANGLED_GLOBAL_NAMES); |
| 107 return JsCache.fetch(names, name); | 100 return JsCache.fetch(names, name); |
| 108 } | 101 } |
| 109 | 102 |
| 110 String unmangleAllIdentifiersIfPreservedAnyways(String str) { | 103 String unmangleAllIdentifiersIfPreservedAnyways(String str) { |
| 111 return JS("String", | 104 return JS("String", |
| 112 r"(#).replace(/[^<,> ]+/g," | 105 r"(#).replace(/[^<,> ]+/g," |
| 113 r"function(m) { return #[m] || m; })", | 106 r"function(m) { return #[m] || m; })", |
| 114 str, | 107 str, |
| 115 JS_EMBEDDED_GLOBAL('', MANGLED_GLOBAL_NAMES)); | 108 JS_EMBEDDED_GLOBAL('', MANGLED_GLOBAL_NAMES)); |
| 116 } | 109 } |
| OLD | NEW |