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

Unified Diff: src/scanner.h

Issue 1302893002: Tighten & check the BookmarkScope API contract a bit. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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 | « src/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner.h
diff --git a/src/scanner.h b/src/scanner.h
index 92588905ad609b7ea64d8c5c7c2007d3e55d409b..2afa5b27c1a61315ddab75a5c64e35929c1d929b 100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -359,18 +359,35 @@ class Scanner {
// Scoped helper for a re-settable bookmark.
class BookmarkScope {
public:
- explicit BookmarkScope(Scanner* scanner) : scanner_(scanner) {
+ explicit BookmarkScope(Scanner* scanner)
+ : scanner_(scanner), my_bookmark_(false) {
DCHECK_NOT_NULL(scanner_);
}
- ~BookmarkScope() { scanner_->DropBookmark(); }
+ ~BookmarkScope() {
+ if (my_bookmark_) scanner_->DropBookmark();
rossberg 2015/08/20 15:45:12 Hm, this _does_ change the semantics, doesn't it?
vogelheim 2015/08/20 16:26:31 Yes, good observation. But I think the case where
+ }
- bool Set() { return scanner_->SetBookmark(); }
- void Reset() { scanner_->ResetToBookmark(); }
- bool HasBeenSet() { return scanner_->BookmarkHasBeenSet(); }
- bool HasBeenReset() { return scanner_->BookmarkHasBeenReset(); }
+ bool Set() {
+ DCHECK(!my_bookmark_);
+ my_bookmark_ = scanner_->SetBookmark();
+ return my_bookmark_;
+ }
+ void Reset() {
+ DCHECK(my_bookmark_);
+ scanner_->ResetToBookmark();
+ }
+ bool HasBeenSet() {
+ DCHECK(my_bookmark_);
+ return scanner_->BookmarkHasBeenSet();
+ }
+ bool HasBeenReset() {
+ DCHECK(my_bookmark_);
+ return scanner_->BookmarkHasBeenReset();
+ }
private:
Scanner* scanner_;
+ bool my_bookmark_; // Did this BookmarkScope set the current bookmark?
DISALLOW_COPY_AND_ASSIGN(BookmarkScope);
};
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698