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

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: yet another trivial rebase 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
« no previous file with comments | « 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 df19ee8faf3314176542f89a5c47588371350811..3c682014fe81ddffb401f50be5f23beb98ec034c 100644
--- a/src/scanner.cc
+++ b/src/scanner.cc
@@ -19,6 +19,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
@@ -295,6 +304,68 @@ Token::Value Scanner::SkipSingleLineComment() {
}
+Token::Value Scanner::SkipSourceURLComment() {
+ TryToParseSourceURLComment();
+ while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
+ Advance();
+ }
+
+ return Token::WHITESPACE;
+}
+
+
+void Scanner::TryToParseSourceURLComment() {
+ // 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 == STATIC_ASCII_VECTOR("sourceURL")) {
+ value = &source_url_;
+ } else if (name_literal == 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_->IsLineTerminator(c0_)) {
+ // Disallowed characters.
+ if (c0_ == '"' || c0_ == '\'') {
+ value->Reset();
+ return;
+ }
+ if (unicode_cache_->IsWhiteSpace(c0_)) {
+ break;
+ }
+ value->AddChar(c0_);
+ Advance();
+ }
+ // Allow whitespace at the end.
+ while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) {
+ if (!unicode_cache_->IsWhiteSpace(c0_)) {
+ value->Reset();
+ break;
+ }
+ Advance();
+ }
+}
+
+
Token::Value Scanner::SkipMultiLineComment() {
ASSERT(c0_ == '*');
Advance();
@@ -459,7 +530,14 @@ void Scanner::Scan() {
// / // /* /=
Advance();
if (c0_ == '/') {
- token = SkipSingleLineComment();
+ Advance();
+ if (c0_ == '@' || c0_ == '#') {
+ Advance();
+ token = SkipSourceURLComment();
+ } else {
+ PushBack(c0_);
+ token = SkipSingleLineComment();
+ }
} else if (c0_ == '*') {
token = SkipMultiLineComment();
} else if (c0_ == '=') {
« no previous file with comments | « src/scanner.h ('k') | src/vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698