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

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

Issue 2411793003: Preparse lazy function parameters (Closed)
Patch Set: rebased Created 4 years, 1 month 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
« no previous file with comments | « src/parsing/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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 i::FLAG_min_preparse_length = 0; 280 i::FLAG_min_preparse_length = 0;
281 281
282 v8::Isolate* isolate = CcTest::isolate(); 282 v8::Isolate* isolate = CcTest::isolate();
283 v8::HandleScope handles(isolate); 283 v8::HandleScope handles(isolate);
284 v8::Local<v8::Context> context = v8::Context::New(isolate); 284 v8::Local<v8::Context> context = v8::Context::New(isolate);
285 v8::Context::Scope context_scope(context); 285 v8::Context::Scope context_scope(context);
286 CcTest::i_isolate()->stack_guard()->SetStackLimit( 286 CcTest::i_isolate()->stack_guard()->SetStackLimit(
287 i::GetCurrentStackPosition() - 128 * 1024); 287 i::GetCurrentStackPosition() - 128 * 1024);
288 288
289 const char* good_code[] = { 289 const char* good_code[] = {
290 "function this_is_lazy() { var a; } function foo() { return 25; } foo();", 290 "function z() { var a; } function f() { return 25; } f();",
291 "var this_is_lazy = () => { var a; }; var foo = () => 25; foo();", 291 "var z = function () { var a; }; function f() { return 25; } f();",
292 "function *z() { var a; } function f() { return 25; } f();",
293 "var z = function *() { var a; }; function f() { return 25; } f();",
294 "function z(p1, p2) { var a; } function f() { return 25; } f();",
295 "var z = function (p1, p2) { var a; }; function f() { return 25; } f();",
296 "function *z(p1, p2) { var a; } function f() { return 25; } f();",
297 "var z = function *(p1, p2) { var a; }; function f() { return 25; } f();",
298 "var z = () => { var a; }; function f() { return 25; } f();",
299 "var z = (p1, p2) => { var a; }; function f() { return 25; } f();",
292 }; 300 };
293 301
294 // Insert a syntax error inside the lazy function. 302 // Insert a syntax error inside the lazy function.
295 const char* bad_code[] = { 303 const char* bad_code[] = {
296 "function this_is_lazy() { if ( } function foo() { return 25; } foo();", 304 "function z() { if ( } function f() { return 25; } f();",
297 "var this_is_lazy = () => { if ( }; var foo = () => 25; foo();", 305 "var z = function () { if ( }; function f() { return 25; } f();",
306 "function *z() { if ( } function f() { return 25; } f();",
307 "var z = function *() { if ( }; function f() { return 25; } f();",
308 "function z(p1, p2) { if ( } function f() { return 25; } f();",
309 "var z = function (p1, p2) { if ( }; function f() { return 25; } f();",
310 "function *z(p1, p2) { if ( } function f() { return 25; } f();",
311 "var z = function *(p1, p2) { if ( }; function f() { return 25; } f();",
312 "var z = () => { if ( }; function f() { return 25; } f();",
313 "var z = (p1, p2) => { if ( }; function f() { return 25; } f();",
298 }; 314 };
299 315
300 for (unsigned i = 0; i < arraysize(good_code); i++) { 316 for (unsigned i = 0; i < arraysize(good_code); i++) {
301 v8::ScriptCompiler::Source good_source(v8_str(good_code[i])); 317 v8::ScriptCompiler::Source good_source(v8_str(good_code[i]));
302 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &good_source, 318 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &good_source,
303 v8::ScriptCompiler::kProduceParserCache) 319 v8::ScriptCompiler::kProduceParserCache)
304 .ToLocalChecked(); 320 .ToLocalChecked();
305 321
306 const v8::ScriptCompiler::CachedData* cached_data = 322 const v8::ScriptCompiler::CachedData* cached_data =
307 good_source.GetCachedData(); 323 good_source.GetCachedData();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 .ToLocalChecked(); 497 .ToLocalChecked();
482 498
483 const v8::ScriptCompiler::CachedData* cached_data = 499 const v8::ScriptCompiler::CachedData* cached_data =
484 script_source.GetCachedData(); 500 script_source.GetCachedData();
485 i::ScriptData script_data(cached_data->data, cached_data->length); 501 i::ScriptData script_data(cached_data->data, cached_data->length);
486 std::unique_ptr<i::ParseData> pd(i::ParseData::FromCachedData(&script_data)); 502 std::unique_ptr<i::ParseData> pd(i::ParseData::FromCachedData(&script_data));
487 pd->Initialize(); 503 pd->Initialize();
488 504
489 int first_function = 505 int first_function =
490 static_cast<int>(strstr(program, "function") - program); 506 static_cast<int>(strstr(program, "function") - program);
491 int first_lbrace = first_function + i::StrLength("function () "); 507 int first_lparen = first_function + i::StrLength("function ");
492 CHECK_EQ('{', program[first_lbrace]); 508 CHECK_EQ('(', program[first_lparen]);
493 i::FunctionEntry entry1 = pd->GetFunctionEntry(first_lbrace); 509 i::FunctionEntry entry1 = pd->GetFunctionEntry(first_lparen);
494 CHECK(!entry1.is_valid()); 510 CHECK(!entry1.is_valid());
495 511
496 int second_function = 512 int second_function =
497 static_cast<int>(strstr(program + first_lbrace, "function") - program); 513 static_cast<int>(strstr(program + first_lparen, "function") - program);
498 int second_lbrace = 514 int second_lparen = second_function + i::StrLength("function ");
499 second_function + i::StrLength("function () "); 515 CHECK_EQ('(', program[second_lparen]);
500 CHECK_EQ('{', program[second_lbrace]); 516 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lparen);
501 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lbrace);
502 CHECK(entry2.is_valid()); 517 CHECK(entry2.is_valid());
503 CHECK_EQ('}', program[entry2.end_pos() - 1]); 518 CHECK_EQ('}', program[entry2.end_pos() - 1]);
504 } 519 }
505 520
506 521
507 TEST(PreParseOverflow) { 522 TEST(PreParseOverflow) {
508 v8::V8::Initialize(); 523 v8::V8::Initialize();
509 524
510 CcTest::i_isolate()->stack_guard()->SetStackLimit( 525 CcTest::i_isolate()->stack_guard()->SetStackLimit(
511 i::GetCurrentStackPosition() - 128 * 1024); 526 i::GetCurrentStackPosition() - 128 * 1024);
(...skipping 7813 matching lines...) Expand 10 before | Expand all | Expand 10 after
8325 const char* data[] = { 8340 const char* data[] = {
8326 "const arguments = 1", 8341 "const arguments = 1",
8327 "let arguments", 8342 "let arguments",
8328 "var arguments", 8343 "var arguments",
8329 NULL 8344 NULL
8330 }; 8345 };
8331 // clang-format on 8346 // clang-format on
8332 RunParserSyncTest(context_data, data, kSuccess); 8347 RunParserSyncTest(context_data, data, kSuccess);
8333 } 8348 }
8334 } 8349 }
OLDNEW
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698