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

Side by Side 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: . 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/char-predicates-inl.h" 10 #include "src/char-predicates-inl.h"
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 ParsingModeScope parsing_mode(this, mode); 884 ParsingModeScope parsing_mode(this, mode);
885 885
886 // Enters 'scope'. 886 // Enters 'scope'.
887 FunctionState function_state(&function_state_, &scope_, scope, zone()); 887 FunctionState function_state(&function_state_, &scope_, scope, zone());
888 888
889 scope_->SetStrictMode(info->strict_mode()); 889 scope_->SetStrictMode(info->strict_mode());
890 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 890 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
891 bool ok = true; 891 bool ok = true;
892 int beg_pos = scanner()->location().beg_pos; 892 int beg_pos = scanner()->location().beg_pos;
893 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 893 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
894
895 HandleMagicComments();
896
894 if (ok && strict_mode() == STRICT) { 897 if (ok && strict_mode() == STRICT) {
895 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 898 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
896 } 899 }
897 900
898 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 901 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
899 CheckConflictingVarDeclarations(scope_, &ok); 902 CheckConflictingVarDeclarations(scope_, &ok);
900 } 903 }
901 904
902 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 905 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
903 if (body->length() != 1 || 906 if (body->length() != 1 ||
(...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after
3828 // Register that a break target found at the given stop in the 3831 // Register that a break target found at the given stop in the
3829 // target stack has been used from the top of the target stack. Add 3832 // target stack has been used from the top of the target stack. Add
3830 // the break target to any TargetCollectors passed on the stack. 3833 // the break target to any TargetCollectors passed on the stack.
3831 for (Target* t = target_stack_; t != stop; t = t->previous()) { 3834 for (Target* t = target_stack_; t != stop; t = t->previous()) {
3832 TargetCollector* collector = t->node()->AsTargetCollector(); 3835 TargetCollector* collector = t->node()->AsTargetCollector();
3833 if (collector != NULL) collector->AddTarget(target, zone()); 3836 if (collector != NULL) collector->AddTarget(target, zone());
3834 } 3837 }
3835 } 3838 }
3836 3839
3837 3840
3841 void Parser::HandleMagicComments() {
3842 if (scanner_.source_url()->length() > 0) {
3843 info_->script()->set_source_url(
3844 *scanner_.source_url()->Internalize(isolate()));
3845 }
3846 if (scanner_.source_mapping_url()->length() > 0) {
3847 info_->script()->set_source_mapping_url(
3848 *scanner_.source_mapping_url()->Internalize(isolate()));
3849 }
3850 }
3851
3852
3838 void Parser::ThrowPendingError() { 3853 void Parser::ThrowPendingError() {
3839 if (has_pending_error_) { 3854 if (has_pending_error_) {
3840 MessageLocation location(script_, 3855 MessageLocation location(script_,
3841 pending_error_location_.beg_pos, 3856 pending_error_location_.beg_pos,
3842 pending_error_location_.end_pos); 3857 pending_error_location_.end_pos);
3843 Factory* factory = isolate()->factory(); 3858 Factory* factory = isolate()->factory();
3844 bool has_arg = 3859 bool has_arg =
3845 !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL; 3860 !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL;
3846 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); 3861 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
3847 if (!pending_error_arg_.is_null()) { 3862 if (!pending_error_arg_.is_null()) {
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
4781 ASSERT(info()->isolate()->has_pending_exception()); 4796 ASSERT(info()->isolate()->has_pending_exception());
4782 } else { 4797 } else {
4783 result = ParseProgram(); 4798 result = ParseProgram();
4784 } 4799 }
4785 } 4800 }
4786 info()->SetFunction(result); 4801 info()->SetFunction(result);
4787 return (result != NULL); 4802 return (result != NULL);
4788 } 4803 }
4789 4804
4790 } } // namespace v8::internal 4805 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698