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

Unified Diff: src/parser.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: oops 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
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 369a451f350c543e3c193a5a332eb8c9e8fef0f0..c65766df77fb88a2afa9d626142697299dcff9a8 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -891,6 +891,9 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
bool ok = true;
int beg_pos = scanner()->location().beg_pos;
ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
+
+ if (scanner()->HasSourceMapComment()) ParseSourceMapComment();
+
if (ok && strict_mode() == STRICT) {
CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
}
@@ -3835,6 +3838,51 @@ void Parser::RegisterTargetUse(Label* target, Target* stop) {
}
+void Parser::ParseSourceMapComment() {
+ Handle<String> source_map_comment =
+ scanner()->AllocateInternalizedSourceMapComment(isolate());
+ int value_start = 0, value_end = 0;
+ {
+ DisallowHeapAllocation no_gc; // flat_data needs to stay alive.
+ String::FlatContent flat_data = source_map_comment->GetFlatContent();
+ if (!flat_data.IsAscii())
+ return;
+ Vector<const uint8_t> data = flat_data.ToOneByteVector();
+ // Parse the following: \s*name\s*=\s*value\s*.*
+ int name_start = 0;
+ while (name_start < data.length() && data[name_start] == ' ') {
yurys 2014/06/05 13:55:21 This won't work for \tname=. Also the original pat
+ ++name_start;
+ }
+ int name_end = name_start;
+ while (name_end < data.length() && data[name_end] != ' ' &&
+ data[name_end] != '=') {
+ ++name_end;
+ }
+ value_start = name_end;
+ while (value_start < data.length() && data[value_start] == ' ') {
yurys 2014/06/05 13:55:21 Same here, the original pattern was [\040\t]source
+ ++value_start;
+ }
+ if (value_start >= data.length() || data[value_start] != '=') {
+ return;
+ }
+ ++value_start; // Skip '='
+ while (value_start < data.length() && data[value_start] == ' ') {
+ ++value_start;
+ }
+ value_end = value_start;
+ while (value_end < data.length() && data[value_end] != ' ') {
+ ++value_end;
+ }
+ Vector<const uint8_t> name = data.SubVector(name_start, name_end);
+ if (!name.IsEqualTo(STATIC_ASCII_VECTOR("sourceURL"))) {
+ return;
+ }
+ }
+ info_->script()->set_source_url(*(isolate()->factory()->NewSubString(
+ source_map_comment, value_start, value_end)));
+}
+
+
void Parser::ThrowPendingError() {
if (has_pending_error_) {
MessageLocation location(script_,

Powered by Google App Engine
This is Rietveld 408576698