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

Side by Side Diff: src/parser.cc

Issue 220233006: PreParser fix: propagate reference erros properly. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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
« no previous file with comments | « src/parser.h ('k') | src/preparse-data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 char* result = NewArray<char>(length + 1); 297 char* result = NewArray<char>(length + 1);
298 for (int i = 0; i < length; i++) { 298 for (int i = 0; i < length; i++) {
299 result[i] = start[i + 1]; 299 result[i] = start[i + 1];
300 } 300 }
301 result[length] = '\0'; 301 result[length] = '\0';
302 if (chars != NULL) *chars = length; 302 if (chars != NULL) *chars = length;
303 return result; 303 return result;
304 } 304 }
305 305
306 306
307 Scanner::Location ScriptDataImpl::MessageLocation() { 307 Scanner::Location ScriptDataImpl::MessageLocation() const {
308 int beg_pos = Read(PreparseDataConstants::kMessageStartPos); 308 int beg_pos = Read(PreparseDataConstants::kMessageStartPos);
309 int end_pos = Read(PreparseDataConstants::kMessageEndPos); 309 int end_pos = Read(PreparseDataConstants::kMessageEndPos);
310 return Scanner::Location(beg_pos, end_pos); 310 return Scanner::Location(beg_pos, end_pos);
311 } 311 }
312 312
313 313
314 const char* ScriptDataImpl::BuildMessage() { 314 bool ScriptDataImpl::IsReferenceError() const {
315 return Read(PreparseDataConstants::kIsReferenceErrorPos);
316 }
317
318
319 const char* ScriptDataImpl::BuildMessage() const {
315 unsigned* start = ReadAddress(PreparseDataConstants::kMessageTextPos); 320 unsigned* start = ReadAddress(PreparseDataConstants::kMessageTextPos);
316 return ReadString(start, NULL); 321 return ReadString(start, NULL);
317 } 322 }
318 323
319 324
320 Vector<const char*> ScriptDataImpl::BuildArgs() { 325 Vector<const char*> ScriptDataImpl::BuildArgs() const {
321 int arg_count = Read(PreparseDataConstants::kMessageArgCountPos); 326 int arg_count = Read(PreparseDataConstants::kMessageArgCountPos);
322 const char** array = NewArray<const char*>(arg_count); 327 const char** array = NewArray<const char*>(arg_count);
323 // Position after text found by skipping past length field and 328 // Position after text found by skipping past length field and
324 // length field content words. 329 // length field content words.
325 int pos = PreparseDataConstants::kMessageTextPos + 1 330 int pos = PreparseDataConstants::kMessageTextPos + 1
326 + Read(PreparseDataConstants::kMessageTextPos); 331 + Read(PreparseDataConstants::kMessageTextPos);
327 for (int i = 0; i < arg_count; i++) { 332 for (int i = 0; i < arg_count; i++) {
328 int count = 0; 333 int count = 0;
329 array[i] = ReadString(ReadAddress(pos), &count); 334 array[i] = ReadString(ReadAddress(pos), &count);
330 pos += count + 1; 335 pos += count + 1;
331 } 336 }
332 return Vector<const char*>(array, arg_count); 337 return Vector<const char*>(array, arg_count);
333 } 338 }
334 339
335 340
336 unsigned ScriptDataImpl::Read(int position) { 341 unsigned ScriptDataImpl::Read(int position) const {
337 return store_[PreparseDataConstants::kHeaderSize + position]; 342 return store_[PreparseDataConstants::kHeaderSize + position];
338 } 343 }
339 344
340 345
341 unsigned* ScriptDataImpl::ReadAddress(int position) { 346 unsigned* ScriptDataImpl::ReadAddress(int position) const {
342 return &store_[PreparseDataConstants::kHeaderSize + position]; 347 return &store_[PreparseDataConstants::kHeaderSize + position];
343 } 348 }
344 349
345 350
346 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 351 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
347 Scope* result = new(zone()) Scope(parent, scope_type, zone()); 352 Scope* result = new(zone()) Scope(parent, scope_type, zone());
348 result->Initialize(); 353 result->Initialize();
349 return result; 354 return result;
350 } 355 }
351 356
(...skipping 3026 matching lines...) Expand 10 before | Expand all | Expand 10 after
3378 return NULL; 3383 return NULL;
3379 } 3384 }
3380 if (logger.has_error()) { 3385 if (logger.has_error()) {
3381 const char* arg = logger.argument_opt(); 3386 const char* arg = logger.argument_opt();
3382 Vector<const char*> args; 3387 Vector<const char*> args;
3383 if (arg != NULL) { 3388 if (arg != NULL) {
3384 args = Vector<const char*>(&arg, 1); 3389 args = Vector<const char*>(&arg, 1);
3385 } 3390 }
3386 ParserTraits::ReportMessageAt( 3391 ParserTraits::ReportMessageAt(
3387 Scanner::Location(logger.start(), logger.end()), 3392 Scanner::Location(logger.start(), logger.end()),
3388 logger.message(), 3393 logger.message(), args, logger.is_reference_error());
3389 args);
3390 *ok = false; 3394 *ok = false;
3391 return NULL; 3395 return NULL;
3392 } 3396 }
3393 scope->set_end_position(logger.end()); 3397 scope->set_end_position(logger.end());
3394 Expect(Token::RBRACE, CHECK_OK); 3398 Expect(Token::RBRACE, CHECK_OK);
3395 isolate()->counters()->total_preparse_skipped()->Increment( 3399 isolate()->counters()->total_preparse_skipped()->Increment(
3396 scope->end_position() - function_block_pos); 3400 scope->end_position() - function_block_pos);
3397 materialized_literal_count = logger.literals(); 3401 materialized_literal_count = logger.literals();
3398 expected_property_count = logger.properties(); 3402 expected_property_count = logger.properties();
3399 scope_->SetStrictMode(logger.strict_mode()); 3403 scope_->SetStrictMode(logger.strict_mode());
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
4681 result = ParseProgram(); 4685 result = ParseProgram();
4682 } 4686 }
4683 } else { 4687 } else {
4684 SetCachedData(info()->cached_data(), info()->cached_data_mode()); 4688 SetCachedData(info()->cached_data(), info()->cached_data_mode());
4685 if (info()->cached_data_mode() == CONSUME_CACHED_DATA && 4689 if (info()->cached_data_mode() == CONSUME_CACHED_DATA &&
4686 (*info()->cached_data())->has_error()) { 4690 (*info()->cached_data())->has_error()) {
4687 ScriptDataImpl* cached_data = *(info()->cached_data()); 4691 ScriptDataImpl* cached_data = *(info()->cached_data());
4688 Scanner::Location loc = cached_data->MessageLocation(); 4692 Scanner::Location loc = cached_data->MessageLocation();
4689 const char* message = cached_data->BuildMessage(); 4693 const char* message = cached_data->BuildMessage();
4690 Vector<const char*> args = cached_data->BuildArgs(); 4694 Vector<const char*> args = cached_data->BuildArgs();
4691 ParserTraits::ReportMessageAt(loc, message, args); 4695 ParserTraits::ReportMessageAt(loc, message, args,
4696 cached_data->IsReferenceError());
4692 DeleteArray(message); 4697 DeleteArray(message);
4693 for (int i = 0; i < args.length(); i++) { 4698 for (int i = 0; i < args.length(); i++) {
4694 DeleteArray(args[i]); 4699 DeleteArray(args[i]);
4695 } 4700 }
4696 DeleteArray(args.start()); 4701 DeleteArray(args.start());
4697 ASSERT(info()->isolate()->has_pending_exception()); 4702 ASSERT(info()->isolate()->has_pending_exception());
4698 } else { 4703 } else {
4699 result = ParseProgram(); 4704 result = ParseProgram();
4700 } 4705 }
4701 } 4706 }
4702 info()->SetFunction(result); 4707 info()->SetFunction(result);
4703 return (result != NULL); 4708 return (result != NULL);
4704 } 4709 }
4705 4710
4706 } } // namespace v8::internal 4711 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparse-data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698