OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of html; | 5 part of html; |
6 | 6 |
7 class _Utils { | 7 class _Utils { |
8 static double dateTimeToDouble(DateTime dateTime) => | 8 static double dateTimeToDouble(DateTime dateTime) => |
9 dateTime.millisecondsSinceEpoch.toDouble(); | 9 dateTime.millisecondsSinceEpoch.toDouble(); |
10 static DateTime doubleToDateTime(double dateTime) { | 10 static DateTime doubleToDateTime(double dateTime) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 64 |
65 static makeUnimplementedError(String fileName, int lineNo) { | 65 static makeUnimplementedError(String fileName, int lineNo) { |
66 return new UnsupportedError('[info: $fileName:$lineNo]'); | 66 return new UnsupportedError('[info: $fileName:$lineNo]'); |
67 } | 67 } |
68 | 68 |
69 static window() native "Utils_window"; | 69 static window() native "Utils_window"; |
70 static forwardingPrint(String message) native "Utils_forwardingPrint"; | 70 static forwardingPrint(String message) native "Utils_forwardingPrint"; |
71 static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFu nction"; | 71 static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFu nction"; |
72 static void spawnDomUri(String uri, int replyTo) native "Utils_spawnDomUri"; | 72 static void spawnDomUri(String uri, int replyTo) native "Utils_spawnDomUri"; |
73 static int _getNewIsolateId() native "Utils_getNewIsolateId"; | 73 static int _getNewIsolateId() native "Utils_getNewIsolateId"; |
74 | |
75 // The following methods were added for debugger integration to make working | |
76 // with the Dart C mirrors API simpler. | |
blois
2013/07/12 21:30:38
Does seem like an internal library would be a bett
Jacob
2013/07/12 22:01:54
do you care if I move it to an internal library no
| |
77 // TODO(jacobr): consider moving them to a separate library. | |
78 // If Dart supported dynamic code injection, we would only inject this code | |
79 // when the debugger is invoked. | |
80 | |
81 /** | |
82 * Strips the private secret prefix from member names of the form | |
83 * someName@hash. | |
84 */ | |
85 static String stripMemberName(String name) { | |
86 int endIndex = name.indexOf('@'); | |
blois
2013/07/12 21:30:38
lastIndexOf?
Jacob
2013/07/12 22:01:54
valid dart member names cannot contain @ so I thin
| |
87 return endIndex > 0 ? name.substring(0, endIndex) : name; | |
88 } | |
89 | |
90 /** | |
91 * Takes a list containing variable names and corresponding values and | |
92 * returns a map from normalized names to values. Variable names are assumed | |
93 * to have list offsets 2*n values at offset 2*n+1. This method is required | |
94 * because Dart_GetLocalVariables returns a list instead of an object that | |
95 * can be queried to lookup names and values. | |
96 */ | |
97 static Map<String, dynamic> createLocalVariablesMap(List localVariables) { | |
98 var map = {}; | |
99 for (int i = 0; i < localVariables.length; i+=2) { | |
100 map[stripMemberName(localVariables[i])] = localVariables[i+1]; | |
101 } | |
102 return map; | |
103 } | |
104 | |
105 /** | |
106 * Convenience helper to get the keys of a [Map] as a [List]. | |
107 */ | |
108 static List getMapKeyList(Map map) => map.keys.toList(); | |
109 | |
110 /** | |
111 * Returns the keys of an arbitrary Dart Map encoded as unique Strings. | |
112 * Keys that are strings are left unchanged except that the prefix ":" is | |
113 * added to disambiguate keys from other Dart members. | |
114 * Keys that are not strings have # followed by the index of the key in the ma p | |
115 * prepended to disambuguate. This scheme is simplistic but easy to encode and | |
116 * decode. The use case for this method is displaying all map keys in a human | |
117 * readable way in debugging tools. | |
118 */ | |
119 static List<String> getEncodedMapKeyList(dynamic obj) { | |
120 if (obj is! Map) return null; | |
121 | |
122 var ret = new List<String>(); | |
123 int i = 0; | |
124 return obj.keys.map((key) { | |
125 var encodedKey; | |
126 if (key is String) { | |
127 encodedKey = ':$key'; | |
128 } else { | |
129 // If the key isn't a string, return a guaranteed unique for this map | |
130 // string representation of the key that is still somewhat human | |
131 // readable. | |
132 encodedKey = '#${i}:$key'; | |
133 } | |
134 i++; | |
135 return encodedKey; | |
136 }).toList(growable: false); | |
137 } | |
138 | |
139 static final RegExp _NON_STRING_KEY_REGEXP = new RegExp("^#(\\d+):(.+)\$"); | |
140 | |
141 static _decodeKey(Map map, String key) { | |
142 // The key is a regular old String. | |
143 if (key.startsWith(':')) return key.substring(1); | |
144 | |
145 var match = _NON_STRING_KEY_REGEXP.firstMatch(key); | |
146 if (match != null) { | |
147 int index = int.parse(match.group(1)); | |
148 var iter = map.keys.skip(index); | |
149 if (iter.isNotEmpty) { | |
150 var ret = iter.first; | |
151 // Validate that the toString representation of the key matches what we | |
152 // expect. FIXME: throw an error if it does not. | |
153 assert(match.group(2) == '$ret'); | |
154 return ret; | |
155 } | |
156 } | |
157 return null; | |
158 } | |
159 | |
160 /** | |
161 * Converts keys encoded with [getEncodedMapKeyList] to their actual keys. | |
162 */ | |
163 static lookupValueForEncodedMapKey(Map obj, String key) => obj[_decodeKey(obj, key)]; | |
164 | |
165 /** | |
166 * Builds a constructor name with the form expected by the C Dart mirrors API. | |
167 */ | |
168 static String buildConstructorName(String className, String constructorName) = > '$className.$constructorName'; | |
169 | |
170 /** | |
171 * Strips the class name from an expression of the form "className.someName". | |
172 */ | |
173 static String stripClassName(String str, String className) { | |
174 if (str.length > className.length + 1 && | |
175 str.startsWith(className) && str[className.length] == '.') { | |
176 return str.substring(className.length + 1); | |
177 } else { | |
178 return str; | |
179 } | |
180 } | |
181 | |
182 /** | |
183 * Removes the trailing dot from an expression ending in a dot. | |
184 * This method is used as Library prefixes include a trailing dot when using | |
185 * the C Dart debugger API. | |
186 */ | |
187 static String stripTrailingDot(String str) => | |
188 (str != null && str[str.length - 1] == '.') ? str.substring(0, str.length - 1) : str; | |
189 | |
190 static String addTrailingDot(String str) => '${str}.'; | |
191 | |
192 // TODO(jacobr): we need a failsafe way to determine that a Node is really a | |
193 // DOM node rather than just a class that extends Node. | |
194 static bool isNode(obj) => obj is Node; | |
74 } | 195 } |
75 | 196 |
76 class _NPObject extends NativeFieldWrapperClass1 { | 197 class _NPObject extends NativeFieldWrapperClass1 { |
77 _NPObject.internal(); | 198 _NPObject.internal(); |
78 static _NPObject retrieve(String key) native "NPObject_retrieve"; | 199 static _NPObject retrieve(String key) native "NPObject_retrieve"; |
79 property(String propertyName) native "NPObject_property"; | 200 property(String propertyName) native "NPObject_property"; |
80 invoke(String methodName, [List args = null]) native "NPObject_invoke"; | 201 invoke(String methodName, [List args = null]) native "NPObject_invoke"; |
81 } | 202 } |
82 | 203 |
83 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements | 204 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 _send(msg) { | 386 _send(msg) { |
266 _sendToHelperIsolate(msg, _sendPort); | 387 _sendToHelperIsolate(msg, _sendPort); |
267 } | 388 } |
268 | 389 |
269 bool get isActive => _isActive; | 390 bool get isActive => _isActive; |
270 } | 391 } |
271 | 392 |
272 get _pureIsolateTimerFactoryClosure => | 393 get _pureIsolateTimerFactoryClosure => |
273 ((int milliSeconds, void callback(Timer time), bool repeating) => | 394 ((int milliSeconds, void callback(Timer time), bool repeating) => |
274 new _PureIsolateTimer(milliSeconds, callback, repeating)); | 395 new _PureIsolateTimer(milliSeconds, callback, repeating)); |
OLD | NEW |