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

Unified Diff: mojo/public/dart/third_party/shelf/lib/src/util.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
Index: mojo/public/dart/third_party/shelf/lib/src/util.dart
diff --git a/mojo/public/dart/third_party/shelf/lib/src/util.dart b/mojo/public/dart/third_party/shelf/lib/src/util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6d9f2c1b44c791cfbd8b30d76fb79214f3b618e9
--- /dev/null
+++ b/mojo/public/dart/third_party/shelf/lib/src/util.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library shelf.util;
+
+import 'dart:async';
+
+/// Like [new Future], but avoids around issue 11911 by using [new Future.value]
+/// under the covers.
+Future newFuture(callback()) => new Future.value().then((_) => callback());
+
+/// Run [callback] and capture any errors that would otherwise be top-leveled.
+///
+/// If [this] is called in a non-root error zone, it will just run [callback]
+/// and return the result. Otherwise, it will capture any errors using
+/// [runZoned] and pass them to [onError].
+catchTopLevelErrors(callback(), void onError(error, StackTrace stackTrace)) {
+ if (Zone.current.inSameErrorZone(Zone.ROOT)) {
+ return runZoned(callback, onError: onError);
+ } else {
+ return callback();
+ }
+}
+
+/// Returns a [Map] with the values from [original] and the values from
+/// [updates].
+///
+/// For keys that are the same between [original] and [updates], the value in
+/// [updates] is used.
+///
+/// If [updates] is `null` or empty, [original] is returned unchanged.
+Map updateMap(Map original, Map updates) {
+ if (updates == null || updates.isEmpty) return original;
+
+ return new Map.from(original)..addAll(updates);
+}
+
+/// Adds a header with [name] and [value] to [headers], which may be null.
+///
+/// Returns a new map without modifying [headers].
+Map<String, String> addHeader(
+ Map<String, String> headers, String name, String value) {
+ headers = headers == null ? {} : new Map.from(headers);
+ headers[name] = value;
+ return headers;
+}

Powered by Google App Engine
This is Rietveld 408576698