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

Unified Diff: third_party/pkg/angular/lib/core/parser/utils.dart

Issue 148453003: Updating Angular version (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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
Index: third_party/pkg/angular/lib/core/parser/utils.dart
diff --git a/third_party/pkg/angular/lib/core/parser/utils.dart b/third_party/pkg/angular/lib/core/parser/utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5a31e052a6d39d53f32a3d483130c27ec00be093
--- /dev/null
+++ b/third_party/pkg/angular/lib/core/parser/utils.dart
@@ -0,0 +1,96 @@
+library angular.core.parser.utils;
+
+import 'package:angular/core/parser/syntax.dart' show Expression;
+export 'package:angular/utils.dart' show relaxFnApply, relaxFnArgs, toBool;
+
+/// Marker for an uninitialized value.
+const UNINITIALIZED = const _Uninitialized();
+class _Uninitialized { const _Uninitialized(); }
+
+class EvalError {
+ final String message;
+ EvalError(this.message);
+
+ String unwrap(String input, stack) {
+ String location = (stack == null) ? '' : '\n\nFROM:\n$stack';
+ return 'Eval Error: $message while evaling [$input]$location';
+ }
+}
+
+/// Evaluate the [list] in context of the [scope].
+List evalList(scope, List<Expression> list) {
+ int length = list.length;
+ for(int cacheLength = _evalListCache.length; cacheLength <= length; cacheLength++) {
+ _evalListCache.add(new List(cacheLength));
+ }
+ List result = _evalListCache[length];
+ for (int i = 0; i < length; i++) {
+ result[i] = list[i].eval(scope);
+ }
+ return result;
+}
+final List _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0]];
+
+/// Add the two arguments with automatic type conversion.
+autoConvertAdd(a, b) {
+ if (a != null && b != null) {
+ // TODO(deboer): Support others.
+ if (a is String && b is! String) {
+ return a + b.toString();
+ }
+ if (a is! String && b is String) {
+ return a.toString() + b;
+ }
+ return a + b;
+ }
+ if (a != null) return a;
+ if (b != null) return b;
+ return null;
+}
+
+/**
+ * Ensures that the given [function] is a function and return it. Throws
+ * an [EvalError] if it isn't.
+ */
+Function ensureFunction(function, String name) {
+ if (function is Function) return function;
+ if (function == null) {
+ throw new EvalError("Undefined function $name");
+ } else {
+ throw new EvalError("$name is not a function");
+ }
+}
+
+/**
+ * Ensures that the map entry with the given [name] is a function and
+ * return it. Throws an [EvalError] if it isn't.
+ */
+Function ensureFunctionFromMap(Map map, String name) {
+ return ensureFunction(map[name], name);
+}
+
+/// Get a keyed element from the given [object].
+getKeyed(object, key) {
+ if (object is List) {
+ return object[key.toInt()];
+ } else if (object is Map) {
+ return object["$key"]; // toString dangerous?
+ } else if (object == null) {
+ throw new EvalError('Accessing null object');
+ }
+ throw new EvalError("Attempted field access on a non-list, non-map");
+}
+
+/// Set a keyed element in the given [object].
+setKeyed(object, key, value) {
+ if (object is List) {
+ int index = key.toInt();
+ if (object.length <= index) object.length = index + 1;
+ object[index] = value;
+ } else if (object is Map) {
+ object["$key"] = value; // toString dangerous?
+ } else {
+ throw new EvalError("Attempting to set a field on a non-list, non-map");
+ }
+ return value;
+}
« no previous file with comments | « third_party/pkg/angular/lib/core/parser/unparser.dart ('k') | third_party/pkg/angular/lib/core/registry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698