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

Unified Diff: src/scanner.cc

Issue 316173002: Handle "//# sourceURL" comments in the Parser instead of the JS. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: code review + less whitespaces allowed. Created 6 years, 6 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
« include/v8.h ('K') | « src/scanner.h ('k') | src/vector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner.cc
diff --git a/src/scanner.cc b/src/scanner.cc
index 0265a8fa7810a797361e202f05dfd5ff045d11d1..edf59d64b433d1365f99761eab69630a2bfa59c8 100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -18,6 +18,15 @@
namespace v8 {
namespace internal {
+
+Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const {
+ if (is_one_byte()) {
+ return isolate->factory()->InternalizeOneByteString(one_byte_literal());
+ }
+ return isolate->factory()->InternalizeTwoByteString(two_byte_literal());
+}
+
+
// ----------------------------------------------------------------------------
// Scanner
@@ -294,6 +303,52 @@ Token::Value Scanner::SkipSingleLineComment() {
}
+Token::Value Scanner::SkipMagicComment() {
+ TryToParseMagicComment();
+ while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
+ Advance();
+ }
+
+ return Token::WHITESPACE;
+}
+
+
+void Scanner::TryToParseMagicComment() {
+ // Magic comments are of the form: //[#@]\s<name>=\s*<value>\s*.* and this
+ // function will just return if it cannot parse a magic comment.
+ if (!unicode_cache_->IsWhiteSpace(c0_))
+ return;
+ Advance();
+ LiteralBuffer name;
+ while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_) &&
+ c0_ != '=') {
+ name.AddChar(c0_);
+ Advance();
+ }
+ if (!name.is_one_byte()) return;
+ Vector<const uint8_t> name_literal = name.one_byte_literal();
+ LiteralBuffer* value;
+ if (name_literal.IsEqualTo(STATIC_ASCII_VECTOR("sourceURL"))) {
+ value = &source_url_;
+ } else if (name_literal.IsEqualTo(STATIC_ASCII_VECTOR("sourceMappingURL"))) {
+ value = &source_mapping_url_;
+ } else {
+ return;
+ }
+ if (c0_ != '=')
+ return;
+ Advance();
+ value->Reset();
+ while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) {
+ Advance();
+ }
+ while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_)) {
yurys 2014/06/10 14:41:04 This will stop at first whitepace while ContentSea
yurys 2014/06/10 14:46:53 As Vsevolod pointed out sourceURLs that contain wh
+ value->AddChar(c0_);
+ Advance();
+ }
+}
+
+
Token::Value Scanner::SkipMultiLineComment() {
ASSERT(c0_ == '*');
Advance();
@@ -458,7 +513,14 @@ void Scanner::Scan() {
// / // /* /=
Advance();
if (c0_ == '/') {
- token = SkipSingleLineComment();
+ Advance();
+ if (c0_ == '@' || c0_ == '#') {
+ Advance();
+ token = SkipMagicComment();
+ } else {
+ PushBack(c0_);
+ token = SkipSingleLineComment();
+ }
} else if (c0_ == '*') {
token = SkipMultiLineComment();
} else if (c0_ == '=') {
@@ -1106,13 +1168,7 @@ Handle<String> Scanner::AllocateNextLiteralString(Isolate* isolate,
Handle<String> Scanner::AllocateInternalizedString(Isolate* isolate) {
- if (is_literal_one_byte()) {
- return isolate->factory()->InternalizeOneByteString(
- literal_one_byte_string());
- } else {
- return isolate->factory()->InternalizeTwoByteString(
- literal_two_byte_string());
- }
+ return current_.literal_chars->Internalize(isolate);
}
« include/v8.h ('K') | « src/scanner.h ('k') | src/vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698