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 /** |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables(); | 160 static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables(); |
161 | 161 |
162 /** | 162 /** |
163 * Header passed in from the Dartium Developer Tools when an expression is | 163 * Header passed in from the Dartium Developer Tools when an expression is |
164 * evaluated in the console as opposed to the watch window or another context | 164 * evaluated in the console as opposed to the watch window or another context |
165 * that does not expect REPL support. | 165 * that does not expect REPL support. |
166 */ | 166 */ |
167 static const _CONSOLE_API_SUPPORT_HEADER = | 167 static const _CONSOLE_API_SUPPORT_HEADER = |
168 'with ((this && this.console && this.console._commandLineAPI) || {}) {\n'; | 168 'with ((this && this.console && this.console._commandLineAPI) || {}) {\n'; |
169 | 169 |
| 170 static bool expectsConsoleApi(String expression) { |
| 171 return expression.indexOf(_CONSOLE_API_SUPPORT_HEADER) == 0;; |
| 172 } |
| 173 |
170 /** | 174 /** |
171 * Takes an [expression] and a list of [local] variable and returns an | 175 * Takes an [expression] and a list of [local] variable and returns an |
172 * expression for a closure with a body matching the original expression | 176 * expression for a closure with a body matching the original expression |
173 * where locals are passed in as arguments. Returns a list containing the | 177 * where locals are passed in as arguments. Returns a list containing the |
174 * String expression for the closure and the list of arguments that should | 178 * String expression for the closure and the list of arguments that should |
175 * be passed to it. The expression should then be evaluated using | 179 * be passed to it. The expression should then be evaluated using |
176 * Dart_EvaluateExpr which will generate a closure that should be invoked | 180 * Dart_EvaluateExpr which will generate a closure that should be invoked |
177 * with the list of arguments passed to this method. | 181 * with the list of arguments passed to this method. |
178 * | 182 * |
179 * For example: | 183 * For example: |
(...skipping 24 matching lines...) Expand all Loading... |
204 // 'this' needs to be handled by calling Dart_EvaluateExpr with | 208 // 'this' needs to be handled by calling Dart_EvaluateExpr with |
205 // 'this' as the target rather than by passing it as an argument. | 209 // 'this' as the target rather than by passing it as an argument. |
206 if (arg == 'this') return; | 210 if (arg == 'this') return; |
207 if (args.isNotEmpty) { | 211 if (args.isNotEmpty) { |
208 sb.write(", "); | 212 sb.write(", "); |
209 } | 213 } |
210 sb.write("final $arg"); | 214 sb.write("final $arg"); |
211 args[arg] = value; | 215 args[arg] = value; |
212 } | 216 } |
213 | 217 |
214 if (expression.indexOf(_CONSOLE_API_SUPPORT_HEADER) == 0) { | 218 if (expectsConsoleApi(expression)) { |
215 expression = expression.substring(expression.indexOf('\n') + 1); | 219 expression = expression.substring(expression.indexOf('\n') + 1); |
216 expression = expression.substring(0, expression.lastIndexOf('\n')); | 220 expression = expression.substring(0, expression.lastIndexOf('\n')); |
217 | 221 |
218 addArg("\$consoleVariables", _consoleTempVariables); | 222 addArg("\$consoleVariables", _consoleTempVariables); |
219 | 223 |
220 // FIXME: use a real Dart tokenizer. The following regular expressions | 224 // FIXME: use a real Dart tokenizer. The following regular expressions |
221 // only allow setting variables at the immediate start of the expression | 225 // only allow setting variables at the immediate start of the expression |
222 // to limit the number of edge cases we have to handle. | 226 // to limit the number of edge cases we have to handle. |
223 | 227 |
224 // Match expressions that start with "var x" | 228 // Match expressions that start with "var x" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 _scheduleImmediateHelper._schedule(callback); | 585 _scheduleImmediateHelper._schedule(callback); |
582 }; | 586 }; |
583 | 587 |
584 get _pureIsolateScheduleImmediateClosure => ((void callback()) => | 588 get _pureIsolateScheduleImmediateClosure => ((void callback()) => |
585 throw new UnimplementedError("scheduleMicrotask in background isolates " | 589 throw new UnimplementedError("scheduleMicrotask in background isolates " |
586 "are not supported in the browser")); | 590 "are not supported in the browser")); |
587 | 591 |
588 void _initializeCustomElement(Element e) { | 592 void _initializeCustomElement(Element e) { |
589 _Utils.initializeCustomElement(e); | 593 _Utils.initializeCustomElement(e); |
590 } | 594 } |
OLD | NEW |