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 MANGLED_GLOBAL_NAMES, | 9 MANGLED_GLOBAL_NAMES, |
9 MANGLED_NAMES; | 10 MANGLED_NAMES; |
10 | 11 |
11 import 'dart:_foreign_helper' show | 12 import 'dart:_foreign_helper' show |
12 JS, | 13 JS, |
13 JS_EMBEDDED_GLOBAL, | 14 JS_EMBEDDED_GLOBAL, |
14 JS_GET_NAME; | 15 JS_GET_NAME; |
15 | 16 |
16 import 'dart:_js_helper' show | 17 import 'dart:_js_helper' show |
17 JsCache, | 18 JsCache, |
(...skipping 28 matching lines...) Expand all Loading... |
46 /// [mangledGlobalNames]). | 47 /// [mangledGlobalNames]). |
47 final Map<String, String> reflectiveGlobalNames = | 48 final Map<String, String> reflectiveGlobalNames = |
48 computeReflectiveNames(mangledGlobalNames); | 49 computeReflectiveNames(mangledGlobalNames); |
49 | 50 |
50 /// [jsMangledNames] is a JavaScript object literal. The keys are the mangled | 51 /// [jsMangledNames] is a JavaScript object literal. The keys are the mangled |
51 /// names, and the values are the "reflective" names. | 52 /// names, and the values are the "reflective" names. |
52 Map<String, String> computeMangledNames(jsMangledNames, bool isGlobal) { | 53 Map<String, String> computeMangledNames(jsMangledNames, bool isGlobal) { |
53 preserveNames(); | 54 preserveNames(); |
54 var keys = extractKeys(jsMangledNames); | 55 var keys = extractKeys(jsMangledNames); |
55 var result = <String, String>{}; | 56 var result = <String, String>{}; |
56 String getterPrefix = JS_GET_NAME('GETTER_PREFIX'); | 57 String getterPrefix = JS_GET_NAME(JsGetName.GETTER_PREFIX); |
57 int getterPrefixLength = getterPrefix.length; | 58 int getterPrefixLength = getterPrefix.length; |
58 String setterPrefix = JS_GET_NAME('SETTER_PREFIX'); | 59 String setterPrefix = JS_GET_NAME(JsGetName.SETTER_PREFIX); |
59 for (String key in keys) { | 60 for (String key in keys) { |
60 String value = JS('String', '#[#]', jsMangledNames, key); | 61 String value = JS('String', '#[#]', jsMangledNames, key); |
61 result[key] = value; | 62 result[key] = value; |
62 if (!isGlobal) { | 63 if (!isGlobal) { |
63 if (key.startsWith(getterPrefix)) { | 64 if (key.startsWith(getterPrefix)) { |
64 result['$setterPrefix${key.substring(getterPrefixLength)}'] = '$value='; | 65 result['$setterPrefix${key.substring(getterPrefixLength)}'] = '$value='; |
65 } | 66 } |
66 } | 67 } |
67 } | 68 } |
68 return result; | 69 return result; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return JsCache.fetch(names, name); | 107 return JsCache.fetch(names, name); |
107 } | 108 } |
108 | 109 |
109 String unmangleAllIdentifiersIfPreservedAnyways(String str) { | 110 String unmangleAllIdentifiersIfPreservedAnyways(String str) { |
110 return JS("String", | 111 return JS("String", |
111 r"(#).replace(/[^<,> ]+/g," | 112 r"(#).replace(/[^<,> ]+/g," |
112 r"function(m) { return #[m] || m; })", | 113 r"function(m) { return #[m] || m; })", |
113 str, | 114 str, |
114 JS_EMBEDDED_GLOBAL('', MANGLED_GLOBAL_NAMES)); | 115 JS_EMBEDDED_GLOBAL('', MANGLED_GLOBAL_NAMES)); |
115 } | 116 } |
OLD | NEW |