Chromium Code Reviews| 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 _ConsoleVariables { | |
| 8 Map<String, Object> _data = new Map<String, Object>(); | |
| 9 | |
| 10 /** | |
| 11 * Forward member accesses to the backing JavaScript object. | |
| 12 */ | |
| 13 noSuchMethod(Invocation invocation) { | |
| 14 String member = MirrorSystem.getName(invocation.memberName); | |
| 15 if (invocation.isGetter) { | |
| 16 return _data[member]; | |
| 17 } else if (invocation.isSetter) { | |
| 18 if (member.endsWith('=')) { | |
|
vsm
2013/09/12 01:01:21
I don't think this is needed anymore. (The js-int
Jacob
2013/09/12 17:02:37
Done.
| |
| 19 member = member.substring(0, member.length - 1); | |
| 20 } | |
| 21 _data[member] = invocation.positionalArguments[0]; | |
| 22 } else { | |
| 23 return Function.apply(_data[member], invocation.positionalArguments, invoc ation.namedArguments); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 void clear() => _data.clear(); | |
| 28 | |
| 29 /** | |
| 30 * List all variables currently defined. | |
| 31 */ | |
| 32 List variables() => _data.keys.toList(growable: false); | |
| 33 } | |
| 34 | |
| 7 class _Utils { | 35 class _Utils { |
| 8 static double dateTimeToDouble(DateTime dateTime) => | 36 static double dateTimeToDouble(DateTime dateTime) => |
| 9 dateTime.millisecondsSinceEpoch.toDouble(); | 37 dateTime.millisecondsSinceEpoch.toDouble(); |
| 10 static DateTime doubleToDateTime(double dateTime) { | 38 static DateTime doubleToDateTime(double dateTime) { |
| 11 try { | 39 try { |
| 12 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); | 40 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); |
| 13 } catch(_) { | 41 } catch(_) { |
| 14 // TODO(antonnm): treat exceptions properly in bindings and | 42 // TODO(antonnm): treat exceptions properly in bindings and |
| 15 // find out how to treat NaNs. | 43 // find out how to treat NaNs. |
| 16 return null; | 44 return null; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 * can be queried to lookup names and values. | 123 * can be queried to lookup names and values. |
| 96 */ | 124 */ |
| 97 static Map<String, dynamic> createLocalVariablesMap(List localVariables) { | 125 static Map<String, dynamic> createLocalVariablesMap(List localVariables) { |
| 98 var map = {}; | 126 var map = {}; |
| 99 for (int i = 0; i < localVariables.length; i+=2) { | 127 for (int i = 0; i < localVariables.length; i+=2) { |
| 100 map[stripMemberName(localVariables[i])] = localVariables[i+1]; | 128 map[stripMemberName(localVariables[i])] = localVariables[i+1]; |
| 101 } | 129 } |
| 102 return map; | 130 return map; |
| 103 } | 131 } |
| 104 | 132 |
| 133 static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables(); | |
| 134 /** | |
| 135 * Takes an [expression] and a list of [local] variable and returns an | |
| 136 * expression for a closure with a body matching the original expression | |
| 137 * where locals are passed in as arguments. Returns a list containing the | |
| 138 * String expression for the closure and the list of arguments that should | |
| 139 * be passed to it. | |
| 140 * | |
| 141 * For example: | |
| 142 * <code>wrapExpressionAsClosure("foo + bar", ["bar", 40, "foo", 2])</code> | |
| 143 * will return: | |
| 144 * <code>["(final $var, final bar, final foo) => foo + bar", [40, 2]]</code> | |
| 145 */ | |
| 146 static List wrapExpressionAsClosure(String expression, List locals) { | |
| 147 var args = {}; | |
| 148 var sb = new StringBuffer("("); | |
| 149 addArg(arg, value) { | |
| 150 arg = stripMemberName(arg); | |
| 151 if (args.containsKey(arg)) return; | |
| 152 if (args.isNotEmpty) { | |
| 153 sb.write(", "); | |
| 154 } | |
| 155 sb.write("final $arg"); | |
| 156 args[arg] = value; | |
| 157 } | |
| 158 | |
| 159 addArg("\$var", _consoleTempVariables); | |
| 160 | |
| 161 for (int i = 0; i < locals.length; i+= 2) { | |
| 162 addArg(locals[i], locals[i+1]); | |
| 163 } | |
| 164 sb..write(')=>\n$expression'); | |
| 165 return [sb.toString(), args.values.toList(growable: false)]; | |
| 166 } | |
| 167 | |
| 105 /** | 168 /** |
| 106 * Convenience helper to get the keys of a [Map] as a [List]. | 169 * Convenience helper to get the keys of a [Map] as a [List]. |
| 107 */ | 170 */ |
| 108 static List getMapKeyList(Map map) => map.keys.toList(); | 171 static List getMapKeyList(Map map) => map.keys.toList(); |
| 109 | 172 |
| 110 /** | 173 /** |
| 111 * Returns the keys of an arbitrary Dart Map encoded as unique Strings. | 174 * 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 | 175 * Keys that are strings are left unchanged except that the prefix ":" is |
| 113 * added to disambiguate keys from other Dart members. | 176 * 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 | 177 * Keys that are not strings have # followed by the index of the key in the ma p |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 _send(msg) { | 493 _send(msg) { |
| 431 _sendToHelperIsolate(msg, _sendPort); | 494 _sendToHelperIsolate(msg, _sendPort); |
| 432 } | 495 } |
| 433 | 496 |
| 434 bool get isActive => _isActive; | 497 bool get isActive => _isActive; |
| 435 } | 498 } |
| 436 | 499 |
| 437 get _pureIsolateTimerFactoryClosure => | 500 get _pureIsolateTimerFactoryClosure => |
| 438 ((int milliSeconds, void callback(Timer time), bool repeating) => | 501 ((int milliSeconds, void callback(Timer time), bool repeating) => |
| 439 new _PureIsolateTimer(milliSeconds, callback, repeating)); | 502 new _PureIsolateTimer(milliSeconds, callback, repeating)); |
| OLD | NEW |