Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: tools/dom/src/native_DOMImplementation.dart

Issue 23647013: Dart helper methods to support the Dart REPL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 _data[member] = invocation.positionalArguments[0];
19 } else {
20 return Function.apply(_data[member], invocation.positionalArguments, invoc ation.namedArguments);
21 }
22 }
23
24 void clear() => _data.clear();
25
26 /**
27 * List all variables currently defined.
28 */
29 List variables() => _data.keys.toList(growable: false);
30 }
31
7 class _Utils { 32 class _Utils {
8 static double dateTimeToDouble(DateTime dateTime) => 33 static double dateTimeToDouble(DateTime dateTime) =>
9 dateTime.millisecondsSinceEpoch.toDouble(); 34 dateTime.millisecondsSinceEpoch.toDouble();
10 static DateTime doubleToDateTime(double dateTime) { 35 static DateTime doubleToDateTime(double dateTime) {
11 try { 36 try {
12 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); 37 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt());
13 } catch(_) { 38 } catch(_) {
14 // TODO(antonnm): treat exceptions properly in bindings and 39 // TODO(antonnm): treat exceptions properly in bindings and
15 // find out how to treat NaNs. 40 // find out how to treat NaNs.
16 return null; 41 return null;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 * can be queried to lookup names and values. 120 * can be queried to lookup names and values.
96 */ 121 */
97 static Map<String, dynamic> createLocalVariablesMap(List localVariables) { 122 static Map<String, dynamic> createLocalVariablesMap(List localVariables) {
98 var map = {}; 123 var map = {};
99 for (int i = 0; i < localVariables.length; i+=2) { 124 for (int i = 0; i < localVariables.length; i+=2) {
100 map[stripMemberName(localVariables[i])] = localVariables[i+1]; 125 map[stripMemberName(localVariables[i])] = localVariables[i+1];
101 } 126 }
102 return map; 127 return map;
103 } 128 }
104 129
130 static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables();
131 /**
132 * Takes an [expression] and a list of [local] variable and returns an
133 * expression for a closure with a body matching the original expression
134 * where locals are passed in as arguments. Returns a list containing the
135 * String expression for the closure and the list of arguments that should
136 * be passed to it.
137 *
138 * For example:
139 * <code>wrapExpressionAsClosure("foo + bar", ["bar", 40, "foo", 2])</code>
140 * will return:
141 * <code>["(final $var, final bar, final foo) => foo + bar", [40, 2]]</code>
142 */
143 static List wrapExpressionAsClosure(String expression, List locals) {
144 var args = {};
145 var sb = new StringBuffer("(");
146 addArg(arg, value) {
147 arg = stripMemberName(arg);
148 if (args.containsKey(arg)) return;
149 if (args.isNotEmpty) {
150 sb.write(", ");
151 }
152 sb.write("final $arg");
153 args[arg] = value;
154 }
155
156 addArg("\$var", _consoleTempVariables);
157
158 for (int i = 0; i < locals.length; i+= 2) {
159 addArg(locals[i], locals[i+1]);
160 }
161 sb..write(')=>\n$expression');
162 return [sb.toString(), args.values.toList(growable: false)];
163 }
164
105 /** 165 /**
106 * Convenience helper to get the keys of a [Map] as a [List]. 166 * Convenience helper to get the keys of a [Map] as a [List].
107 */ 167 */
108 static List getMapKeyList(Map map) => map.keys.toList(); 168 static List getMapKeyList(Map map) => map.keys.toList();
109 169
110 /** 170 /**
111 * Returns the keys of an arbitrary Dart Map encoded as unique Strings. 171 * 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 172 * Keys that are strings are left unchanged except that the prefix ":" is
113 * added to disambiguate keys from other Dart members. 173 * 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 174 * 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
430 _send(msg) { 490 _send(msg) {
431 _sendToHelperIsolate(msg, _sendPort); 491 _sendToHelperIsolate(msg, _sendPort);
432 } 492 }
433 493
434 bool get isActive => _isActive; 494 bool get isActive => _isActive;
435 } 495 }
436 496
437 get _pureIsolateTimerFactoryClosure => 497 get _pureIsolateTimerFactoryClosure =>
438 ((int milliSeconds, void callback(Timer time), bool repeating) => 498 ((int milliSeconds, void callback(Timer time), bool repeating) =>
439 new _PureIsolateTimer(milliSeconds, callback, repeating)); 499 new _PureIsolateTimer(milliSeconds, callback, repeating));
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698