| 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 { | 7 class _ConsoleVariables { |
| 8 Map<String, Object> _data = new Map<String, Object>(); | 8 Map<String, Object> _data = new Map<String, Object>(); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Forward member accesses to the backing JavaScript object. | 11 * Forward member accesses to the backing JavaScript object. |
| 12 */ | 12 */ |
| 13 noSuchMethod(Invocation invocation) { | 13 noSuchMethod(Invocation invocation) { |
| 14 String member = MirrorSystem.getName(invocation.memberName); | 14 String member = MirrorSystem.getName(invocation.memberName); |
| 15 if (invocation.isGetter) { | 15 if (invocation.isGetter) { |
| 16 return _data[member]; | 16 return _data[member]; |
| 17 } else if (invocation.isSetter) { | 17 } else if (invocation.isSetter) { |
| 18 assert(member.endsWith('=')); |
| 19 member = member.substring(0, member.length - 1); |
| 18 _data[member] = invocation.positionalArguments[0]; | 20 _data[member] = invocation.positionalArguments[0]; |
| 19 } else { | 21 } else { |
| 20 return Function.apply(_data[member], invocation.positionalArguments, invoc
ation.namedArguments); | 22 return Function.apply(_data[member], invocation.positionalArguments, invoc
ation.namedArguments); |
| 21 } | 23 } |
| 22 } | 24 } |
| 23 | 25 |
| 24 void clear() => _data.clear(); | 26 void clear() => _data.clear(); |
| 25 | 27 |
| 26 /** | 28 /** |
| 27 * List all variables currently defined. | 29 * List all variables currently defined. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 128 } |
| 127 return map; | 129 return map; |
| 128 } | 130 } |
| 129 | 131 |
| 130 static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables(); | 132 static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables(); |
| 131 /** | 133 /** |
| 132 * Takes an [expression] and a list of [local] variable and returns an | 134 * Takes an [expression] and a list of [local] variable and returns an |
| 133 * expression for a closure with a body matching the original expression | 135 * expression for a closure with a body matching the original expression |
| 134 * where locals are passed in as arguments. Returns a list containing the | 136 * 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 | 137 * String expression for the closure and the list of arguments that should |
| 136 * be passed to it. | 138 * be passed to it. The expression should then be evaluated using |
| 139 * Dart_EvaluateExpr which will generate a closure that should be invoked |
| 140 * with the list of arguments passed to this method. |
| 137 * | 141 * |
| 138 * For example: | 142 * For example: |
| 139 * <code>wrapExpressionAsClosure("foo + bar", ["bar", 40, "foo", 2])</code> | 143 * <code>wrapExpressionAsClosure("foo + bar", ["bar", 40, "foo", 2])</code> |
| 140 * will return: | 144 * will return: |
| 141 * <code>["(final $var, final bar, final foo) => foo + bar", [40, 2]]</code> | 145 * <code>["(final $var, final bar, final foo) => foo + bar", [40, 2]]</code> |
| 142 */ | 146 */ |
| 143 static List wrapExpressionAsClosure(String expression, List locals) { | 147 static List wrapExpressionAsClosure(String expression, List locals) { |
| 144 var args = {}; | 148 var args = {}; |
| 145 var sb = new StringBuffer("("); | 149 var sb = new StringBuffer("("); |
| 146 addArg(arg, value) { | 150 addArg(arg, value) { |
| 147 arg = stripMemberName(arg); | 151 arg = stripMemberName(arg); |
| 148 if (args.containsKey(arg)) return; | 152 if (args.containsKey(arg)) return; |
| 153 // We ignore arguments with the name 'this' rather than throwing an |
| 154 // exception because Dart_GetLocalVariables includes 'this' and it |
| 155 // is more convenient to filter it out here than from C++ code. |
| 156 // 'this' needs to be handled by calling Dart_EvaluateExpr with |
| 157 // 'this' as the target rather than by passing it as an argument. |
| 158 if (arg == 'this') return; |
| 149 if (args.isNotEmpty) { | 159 if (args.isNotEmpty) { |
| 150 sb.write(", "); | 160 sb.write(", "); |
| 151 } | 161 } |
| 152 sb.write("final $arg"); | 162 sb.write("final $arg"); |
| 153 args[arg] = value; | 163 args[arg] = value; |
| 154 } | 164 } |
| 155 | 165 |
| 156 addArg("\$var", _consoleTempVariables); | 166 addArg("\$var", _consoleTempVariables); |
| 157 | 167 |
| 158 for (int i = 0; i < locals.length; i+= 2) { | 168 for (int i = 0; i < locals.length; i+= 2) { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 _send(msg) { | 500 _send(msg) { |
| 491 _sendToHelperIsolate(msg, _sendPort); | 501 _sendToHelperIsolate(msg, _sendPort); |
| 492 } | 502 } |
| 493 | 503 |
| 494 bool get isActive => _isActive; | 504 bool get isActive => _isActive; |
| 495 } | 505 } |
| 496 | 506 |
| 497 get _pureIsolateTimerFactoryClosure => | 507 get _pureIsolateTimerFactoryClosure => |
| 498 ((int milliSeconds, void callback(Timer time), bool repeating) => | 508 ((int milliSeconds, void callback(Timer time), bool repeating) => |
| 499 new _PureIsolateTimer(milliSeconds, callback, repeating)); | 509 new _PureIsolateTimer(milliSeconds, callback, repeating)); |
| OLD | NEW |