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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 198903002: Only call to LogSymbol when needed. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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/preparser.cc ('k') | no next file » | 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 v8::Local<v8::Value> result = PreCompileCompileRun(source); 357 v8::Local<v8::Value> result = PreCompileCompileRun(source);
358 CHECK(result->IsString()); 358 CHECK(result->IsString());
359 v8::String::Utf8Value utf8(result); 359 v8::String::Utf8Value utf8(result);
360 CHECK_EQ("foo", *utf8); 360 CHECK_EQ("foo", *utf8);
361 } 361 }
362 } 362 }
363 363
364 namespace v8 { 364 namespace v8 {
365 namespace internal { 365 namespace internal {
366 366
367 void FakeWritingSymbolIdInPreParseData(i::CompleteParserRecorder* log, 367 struct CompleteParserRecorderFriend {
368 int number) { 368 static void FakeWritingSymbolIdInPreParseData(CompleteParserRecorder* log,
369 log->WriteNumber(number); 369 int number) {
370 if (log->symbol_id_ < number + 1) { 370 log->WriteNumber(number);
371 log->symbol_id_ = number + 1; 371 if (log->symbol_id_ < number + 1) {
372 log->symbol_id_ = number + 1;
373 }
372 } 374 }
373 } 375 static int symbol_position(CompleteParserRecorder* log) {
376 return log->symbol_store_.size();
377 }
378 static int symbol_ids(CompleteParserRecorder* log) {
379 return log->symbol_id_;
380 }
381 static int function_position(CompleteParserRecorder* log) {
382 return log->function_store_.size();
383 }
384 };
374 385
375 } 386 }
376 } 387 }
377 388
378 389
379 TEST(StoringNumbersInPreParseData) { 390 TEST(StoringNumbersInPreParseData) {
380 // Symbol IDs are split into chunks of 7 bits for storing. This is a 391 // Symbol IDs are split into chunks of 7 bits for storing. This is a
381 // regression test for a bug where a symbol id was incorrectly stored if some 392 // regression test for a bug where a symbol id was incorrectly stored if some
382 // of the chunks in the middle were all zeros. 393 // of the chunks in the middle were all zeros.
394 typedef i::CompleteParserRecorderFriend F;
383 i::CompleteParserRecorder log; 395 i::CompleteParserRecorder log;
384 for (int i = 0; i < 18; ++i) { 396 for (int i = 0; i < 18; ++i) {
385 FakeWritingSymbolIdInPreParseData(&log, 1 << i); 397 F::FakeWritingSymbolIdInPreParseData(&log, 1 << i);
386 } 398 }
387 for (int i = 1; i < 18; ++i) { 399 for (int i = 1; i < 18; ++i) {
388 FakeWritingSymbolIdInPreParseData(&log, (1 << i) + 1); 400 F::FakeWritingSymbolIdInPreParseData(&log, (1 << i) + 1);
389 } 401 }
390 for (int i = 6; i < 18; ++i) { 402 for (int i = 6; i < 18; ++i) {
391 FakeWritingSymbolIdInPreParseData(&log, (3 << i) + (5 << (i - 6))); 403 F::FakeWritingSymbolIdInPreParseData(&log, (3 << i) + (5 << (i - 6)));
392 } 404 }
393 i::Vector<unsigned> store = log.ExtractData(); 405 i::Vector<unsigned> store = log.ExtractData();
394 i::ScriptDataImpl script_data(store); 406 i::ScriptDataImpl script_data(store);
395 script_data.Initialize(); 407 script_data.Initialize();
396 // Check that we get the same symbols back. 408 // Check that we get the same symbols back.
397 for (int i = 0; i < 18; ++i) { 409 for (int i = 0; i < 18; ++i) {
398 CHECK_EQ(1 << i, script_data.GetSymbolIdentifier()); 410 CHECK_EQ(1 << i, script_data.GetSymbolIdentifier());
399 } 411 }
400 for (int i = 1; i < 18; ++i) { 412 for (int i = 1; i < 18; ++i) {
401 CHECK_EQ((1 << i) + 1, script_data.GetSymbolIdentifier()); 413 CHECK_EQ((1 << i) + 1, script_data.GetSymbolIdentifier());
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 // Labels, variables and functions insize lazy functions are not recorded. 2013 // Labels, variables and functions insize lazy functions are not recorded.
2002 {"function lazy() { var a, b, c; }", 1, 1}, 2014 {"function lazy() { var a, b, c; }", 1, 1},
2003 {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1}, 2015 {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1},
2004 {"function lazy() { function a() {} function b() {} function c() {} }", 1, 2016 {"function lazy() { function a() {} function b() {} function c() {} }", 1,
2005 1}, 2017 1},
2006 {NULL, 0, 0} 2018 {NULL, 0, 0}
2007 }; 2019 };
2008 // Each function adds 5 elements to the preparse function data. 2020 // Each function adds 5 elements to the preparse function data.
2009 const int kDataPerFunction = 5; 2021 const int kDataPerFunction = 5;
2010 2022
2023 typedef i::CompleteParserRecorderFriend F;
2011 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 2024 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
2012 for (int i = 0; test_cases[i].program; i++) { 2025 for (int i = 0; test_cases[i].program; i++) {
2013 const char* program = test_cases[i].program; 2026 const char* program = test_cases[i].program;
2014 i::Utf8ToUtf16CharacterStream stream( 2027 i::Utf8ToUtf16CharacterStream stream(
2015 reinterpret_cast<const i::byte*>(program), 2028 reinterpret_cast<const i::byte*>(program),
2016 static_cast<unsigned>(strlen(program))); 2029 static_cast<unsigned>(strlen(program)));
2017 i::CompleteParserRecorder log; 2030 i::CompleteParserRecorder log;
2018 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 2031 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
2019 scanner.Initialize(&stream); 2032 scanner.Initialize(&stream);
2020 2033
2021 i::PreParser preparser(&scanner, &log, stack_limit); 2034 i::PreParser preparser(&scanner, &log, stack_limit);
2022 preparser.set_allow_lazy(true); 2035 preparser.set_allow_lazy(true);
2023 preparser.set_allow_natives_syntax(true); 2036 preparser.set_allow_natives_syntax(true);
2024 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 2037 i::PreParser::PreParseResult result = preparser.PreParseProgram();
2025 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 2038 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
2026 if (log.symbol_ids() != test_cases[i].symbols) { 2039 if (F::symbol_ids(&log) != test_cases[i].symbols) {
2027 i::OS::Print( 2040 i::OS::Print(
2028 "Expected preparse data for program:\n" 2041 "Expected preparse data for program:\n"
2029 "\t%s\n" 2042 "\t%s\n"
2030 "to contain %d symbols, however, received %d symbols.\n", 2043 "to contain %d symbols, however, received %d symbols.\n",
2031 program, test_cases[i].symbols, log.symbol_ids()); 2044 program, test_cases[i].symbols, F::symbol_ids(&log));
2032 CHECK(false); 2045 CHECK(false);
2033 } 2046 }
2034 if (log.function_position() != test_cases[i].functions * kDataPerFunction) { 2047 if (F::function_position(&log) !=
2048 test_cases[i].functions * kDataPerFunction) {
2035 i::OS::Print( 2049 i::OS::Print(
2036 "Expected preparse data for program:\n" 2050 "Expected preparse data for program:\n"
2037 "\t%s\n" 2051 "\t%s\n"
2038 "to contain %d functions, however, received %d functions.\n", 2052 "to contain %d functions, however, received %d functions.\n",
2039 program, test_cases[i].functions, 2053 program, test_cases[i].functions,
2040 log.function_position() / kDataPerFunction); 2054 F::function_position(&log) / kDataPerFunction);
2041 CHECK(false); 2055 CHECK(false);
2042 } 2056 }
2043 i::ScriptDataImpl data(log.ExtractData()); 2057 i::ScriptDataImpl data(log.ExtractData());
2044 CHECK(!data.has_error()); 2058 CHECK(!data.has_error());
2045 } 2059 }
2046 } 2060 }
2047 2061
2048 2062
2049 TEST(FunctionDeclaresItselfStrict) { 2063 TEST(FunctionDeclaresItselfStrict) {
2050 // Tests that we produce the right kinds of errors when a function declares 2064 // Tests that we produce the right kinds of errors when a function declares
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 2363
2350 const char* statement_data[] = { 2364 const char* statement_data[] = {
2351 statement, 2365 statement,
2352 NULL 2366 NULL
2353 }; 2367 };
2354 2368
2355 // The test is quite slow, so run it with a reduced set of flags. 2369 // The test is quite slow, so run it with a reduced set of flags.
2356 static const ParserFlag empty_flags[] = {kAllowLazy}; 2370 static const ParserFlag empty_flags[] = {kAllowLazy};
2357 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); 2371 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2358 } 2372 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698