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

Unified 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: ready for review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index 80676b0d88498117b995158352e96bb5a852adb2..b1bd6a5be592f2299c8ea874c057ef368a29e348 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -4,6 +4,34 @@
part of html;
+class _ConsoleVariables {
+ Map<String, Object> _data = new Map<String, Object>();
+
+ /**
+ * Forward member accesses to the backing JavaScript object.
+ */
+ noSuchMethod(Invocation invocation) {
+ String member = MirrorSystem.getName(invocation.memberName);
+ if (invocation.isGetter) {
+ return _data[member];
+ } else if (invocation.isSetter) {
+ 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.
+ member = member.substring(0, member.length - 1);
+ }
+ _data[member] = invocation.positionalArguments[0];
+ } else {
+ return Function.apply(_data[member], invocation.positionalArguments, invocation.namedArguments);
+ }
+ }
+
+ void clear() => _data.clear();
+
+ /**
+ * List all variables currently defined.
+ */
+ List variables() => _data.keys.toList(growable: false);
+}
+
class _Utils {
static double dateTimeToDouble(DateTime dateTime) =>
dateTime.millisecondsSinceEpoch.toDouble();
@@ -102,6 +130,41 @@ class _Utils {
return map;
}
+ static _ConsoleVariables _consoleTempVariables = new _ConsoleVariables();
+ /**
+ * Takes an [expression] and a list of [local] variable and returns an
+ * expression for a closure with a body matching the original expression
+ * where locals are passed in as arguments. Returns a list containing the
+ * String expression for the closure and the list of arguments that should
+ * be passed to it.
+ *
+ * For example:
+ * <code>wrapExpressionAsClosure("foo + bar", ["bar", 40, "foo", 2])</code>
+ * will return:
+ * <code>["(final $var, final bar, final foo) => foo + bar", [40, 2]]</code>
+ */
+ static List wrapExpressionAsClosure(String expression, List locals) {
+ var args = {};
+ var sb = new StringBuffer("(");
+ addArg(arg, value) {
+ arg = stripMemberName(arg);
+ if (args.containsKey(arg)) return;
+ if (args.isNotEmpty) {
+ sb.write(", ");
+ }
+ sb.write("final $arg");
+ args[arg] = value;
+ }
+
+ addArg("\$var", _consoleTempVariables);
+
+ for (int i = 0; i < locals.length; i+= 2) {
+ addArg(locals[i], locals[i+1]);
+ }
+ sb..write(')=>\n$expression');
+ return [sb.toString(), args.values.toList(growable: false)];
+ }
+
/**
* Convenience helper to get the keys of a [Map] as a [List].
*/
« 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