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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/utils.dart

Issue 14673004: Guard more thoroughly against stack overflows in the backtracking version solver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review change. Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/solver/backtracking_solver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// Generic utility functions. Stuff that should possibly be in core. 5 /// Generic utility functions. Stuff that should possibly be in core.
6 library utils; 6 library utils;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:crypto'; 9 import 'dart:crypto';
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (uri.path.startsWith("/")) { 377 if (uri.path.startsWith("/")) {
378 // Drive-letter paths look like "file:///C:/path/to/file". The replaceFirst 378 // Drive-letter paths look like "file:///C:/path/to/file". The replaceFirst
379 // removes the extra initial slash. 379 // removes the extra initial slash.
380 return uri.path.replaceFirst("/", "").replaceAll("/", "\\"); 380 return uri.path.replaceFirst("/", "").replaceAll("/", "\\");
381 } else { 381 } else {
382 // Network paths look like "file://hostname/path/to/file". 382 // Network paths look like "file://hostname/path/to/file".
383 return "\\\\${uri.path.replaceAll("/", "\\")}"; 383 return "\\\\${uri.path.replaceAll("/", "\\")}";
384 } 384 }
385 } 385 }
386 386
387 /// Wraps [fn] to guard against several different kinds of stack overflow
388 /// exceptions:
389 ///
390 /// * A sufficiently long [Future] chain can cause a stack overflow if there are
391 /// no asynchronous operations in it (issue 9583).
392 /// * A recursive function that recurses too deeply without an asynchronous
393 /// operation can cause a stack overflow.
394 /// * Even if the former is guarded against by adding asynchronous operations,
395 /// returning a value through the [Future] chain can still cause a stack
396 /// overflow.
397 Future resetStack(fn()) {
398 // Using a [Completer] breaks the [Future] chain for the return value and
399 // avoids the third case described above.
400 var completer = new Completer();
401
402 // Using [new Future] adds an asynchronous operation that works around the
403 // first and second cases described above.
404 new Future(fn).then((val) {
405 runAsync(() => completer.complete(val));
406 }).catchError((err) {
407 runAsync(() => completer.completeError(err));
408 });
409 return completer.future;
410 }
411
387 /// An exception class for exceptions that are intended to be seen by the user. 412 /// An exception class for exceptions that are intended to be seen by the user.
388 /// These exceptions won't have any debugging information printed when they're 413 /// These exceptions won't have any debugging information printed when they're
389 /// thrown. 414 /// thrown.
390 class ApplicationException implements Exception { 415 class ApplicationException implements Exception {
391 final String message; 416 final String message;
392 417
393 ApplicationException(this.message); 418 ApplicationException(this.message);
394 } 419 }
395 420
396 /// Throw a [ApplicationException] with [message]. 421 /// Throw a [ApplicationException] with [message].
(...skipping 10 matching lines...) Expand all
407 error is FileIOException || 432 error is FileIOException ||
408 error is HttpException || 433 error is HttpException ||
409 error is HttpParserException || 434 error is HttpParserException ||
410 error is LinkIOException || 435 error is LinkIOException ||
411 error is MimeParserException || 436 error is MimeParserException ||
412 error is OSError || 437 error is OSError ||
413 error is ProcessException || 438 error is ProcessException ||
414 error is SocketIOException || 439 error is SocketIOException ||
415 error is WebSocketException; 440 error is WebSocketException;
416 } 441 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/solver/backtracking_solver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698