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

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

Issue 389573006: Change ScriptCompiler::CompileOptions and add d8 --cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: even more rebase Created 6 years, 5 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 | « test/cctest/test-debug.cc ('k') | test/cctest/test-serialize.cc » ('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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 "var w = /RegExp Literal\\u0020With Escape/gin;" 212 "var w = /RegExp Literal\\u0020With Escape/gin;"
213 "var y = { get getter() { return 42; }, " 213 "var y = { get getter() { return 42; }, "
214 " set setter(v) { this.value = v; }};"; 214 " set setter(v) { this.value = v; }};";
215 int source_length = i::StrLength(source); 215 int source_length = i::StrLength(source);
216 216
217 // ScriptResource will be deleted when the corresponding String is GCd. 217 // ScriptResource will be deleted when the corresponding String is GCd.
218 v8::ScriptCompiler::Source script_source(v8::String::NewExternal( 218 v8::ScriptCompiler::Source script_source(v8::String::NewExternal(
219 isolate, new ScriptResource(source, source_length))); 219 isolate, new ScriptResource(source, source_length)));
220 i::FLAG_min_preparse_length = 0; 220 i::FLAG_min_preparse_length = 0;
221 v8::ScriptCompiler::Compile(isolate, &script_source, 221 v8::ScriptCompiler::Compile(isolate, &script_source,
222 v8::ScriptCompiler::kProduceDataToCache); 222 v8::ScriptCompiler::kProduceParserCache);
223 CHECK(script_source.GetCachedData()); 223 CHECK(script_source.GetCachedData());
224 224
225 // Compile the script again, using the cached data. 225 // Compile the script again, using the cached data.
226 bool lazy_flag = i::FLAG_lazy; 226 bool lazy_flag = i::FLAG_lazy;
227 i::FLAG_lazy = true; 227 i::FLAG_lazy = true;
228 v8::ScriptCompiler::Compile(isolate, &script_source); 228 v8::ScriptCompiler::Compile(isolate, &script_source,
229 v8::ScriptCompiler::kConsumeParserCache);
229 i::FLAG_lazy = false; 230 i::FLAG_lazy = false;
230 v8::ScriptCompiler::CompileUnbound(isolate, &script_source); 231 v8::ScriptCompiler::CompileUnbound(isolate, &script_source,
232 v8::ScriptCompiler::kConsumeParserCache);
231 i::FLAG_lazy = lazy_flag; 233 i::FLAG_lazy = lazy_flag;
232 } 234 }
233 235
234 236
235 TEST(PreparseFunctionDataIsUsed) { 237 TEST(PreparseFunctionDataIsUsed) {
236 // This tests that we actually do use the function data generated by the 238 // This tests that we actually do use the function data generated by the
237 // preparser. 239 // preparser.
238 240
239 // Make preparsing work for short scripts. 241 // Make preparsing work for short scripts.
240 i::FLAG_min_preparse_length = 0; 242 i::FLAG_min_preparse_length = 0;
241 243
242 v8::Isolate* isolate = CcTest::isolate(); 244 v8::Isolate* isolate = CcTest::isolate();
243 v8::HandleScope handles(isolate); 245 v8::HandleScope handles(isolate);
244 v8::Local<v8::Context> context = v8::Context::New(isolate); 246 v8::Local<v8::Context> context = v8::Context::New(isolate);
245 v8::Context::Scope context_scope(context); 247 v8::Context::Scope context_scope(context);
246 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 248 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
247 128 * 1024); 249 128 * 1024);
248 250
249 const char* good_code = 251 const char* good_code =
250 "function this_is_lazy() { var a; } function foo() { return 25; } foo();"; 252 "function this_is_lazy() { var a; } function foo() { return 25; } foo();";
251 253
252 // Insert a syntax error inside the lazy function. 254 // Insert a syntax error inside the lazy function.
253 const char* bad_code = 255 const char* bad_code =
254 "function this_is_lazy() { if ( } function foo() { return 25; } foo();"; 256 "function this_is_lazy() { if ( } function foo() { return 25; } foo();";
255 257
256 v8::ScriptCompiler::Source good_source(v8_str(good_code)); 258 v8::ScriptCompiler::Source good_source(v8_str(good_code));
257 v8::ScriptCompiler::Compile(isolate, &good_source, 259 v8::ScriptCompiler::Compile(isolate, &good_source,
258 v8::ScriptCompiler::kProduceDataToCache); 260 v8::ScriptCompiler::kProduceParserCache);
259 261
260 const v8::ScriptCompiler::CachedData* cached_data = 262 const v8::ScriptCompiler::CachedData* cached_data =
261 good_source.GetCachedData(); 263 good_source.GetCachedData();
262 CHECK(cached_data->data != NULL); 264 CHECK(cached_data->data != NULL);
263 CHECK_GT(cached_data->length, 0); 265 CHECK_GT(cached_data->length, 0);
264 266
265 // Now compile the erroneous code with the good preparse data. If the preparse 267 // Now compile the erroneous code with the good preparse data. If the preparse
266 // data is used, the lazy function is skipped and it should compile fine. 268 // data is used, the lazy function is skipped and it should compile fine.
267 v8::ScriptCompiler::Source bad_source( 269 v8::ScriptCompiler::Source bad_source(
268 v8_str(bad_code), new v8::ScriptCompiler::CachedData( 270 v8_str(bad_code), new v8::ScriptCompiler::CachedData(
269 cached_data->data, cached_data->length)); 271 cached_data->data, cached_data->length));
270 v8::Local<v8::Value> result = 272 v8::Local<v8::Value> result =
271 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run(); 273 v8::ScriptCompiler::Compile(
274 isolate, &bad_source, v8::ScriptCompiler::kConsumeParserCache)->Run();
272 CHECK(result->IsInt32()); 275 CHECK(result->IsInt32());
273 CHECK_EQ(25, result->Int32Value()); 276 CHECK_EQ(25, result->Int32Value());
274 } 277 }
275 278
276 279
277 TEST(StandAlonePreParser) { 280 TEST(StandAlonePreParser) {
278 v8::V8::Initialize(); 281 v8::V8::Initialize();
279 282
280 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 283 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
281 128 * 1024); 284 128 * 1024);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // didn't match what Parser wanted to consume. 351 // didn't match what Parser wanted to consume.
349 v8::Isolate* isolate = CcTest::isolate(); 352 v8::Isolate* isolate = CcTest::isolate();
350 v8::HandleScope handles(isolate); 353 v8::HandleScope handles(isolate);
351 v8::Local<v8::Context> context = v8::Context::New(isolate); 354 v8::Local<v8::Context> context = v8::Context::New(isolate);
352 v8::Context::Scope context_scope(context); 355 v8::Context::Scope context_scope(context);
353 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - 356 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() -
354 128 * 1024); 357 128 * 1024);
355 358
356 { 359 {
357 const char* source = "var myo = {if: \"foo\"}; myo.if;"; 360 const char* source = "var myo = {if: \"foo\"}; myo.if;";
358 v8::Local<v8::Value> result = PreCompileCompileRun(source); 361 v8::Local<v8::Value> result = ParserCacheCompileRun(source);
359 CHECK(result->IsString()); 362 CHECK(result->IsString());
360 v8::String::Utf8Value utf8(result); 363 v8::String::Utf8Value utf8(result);
361 CHECK_EQ("foo", *utf8); 364 CHECK_EQ("foo", *utf8);
362 } 365 }
363 366
364 { 367 {
365 const char* source = "var myo = {\"bar\": \"foo\"}; myo[\"bar\"];"; 368 const char* source = "var myo = {\"bar\": \"foo\"}; myo[\"bar\"];";
366 v8::Local<v8::Value> result = PreCompileCompileRun(source); 369 v8::Local<v8::Value> result = ParserCacheCompileRun(source);
367 CHECK(result->IsString()); 370 CHECK(result->IsString());
368 v8::String::Utf8Value utf8(result); 371 v8::String::Utf8Value utf8(result);
369 CHECK_EQ("foo", *utf8); 372 CHECK_EQ("foo", *utf8);
370 } 373 }
371 374
372 { 375 {
373 const char* source = "var myo = {1: \"foo\"}; myo[1];"; 376 const char* source = "var myo = {1: \"foo\"}; myo[1];";
374 v8::Local<v8::Value> result = PreCompileCompileRun(source); 377 v8::Local<v8::Value> result = ParserCacheCompileRun(source);
375 CHECK(result->IsString()); 378 CHECK(result->IsString());
376 v8::String::Utf8Value utf8(result); 379 v8::String::Utf8Value utf8(result);
377 CHECK_EQ("foo", *utf8); 380 CHECK_EQ("foo", *utf8);
378 } 381 }
379 } 382 }
380 383
381 384
382 TEST(RegressChromium62639) { 385 TEST(RegressChromium62639) {
383 v8::V8::Initialize(); 386 v8::V8::Initialize();
384 i::Isolate* isolate = CcTest::i_isolate(); 387 i::Isolate* isolate = CcTest::i_isolate();
(...skipping 1859 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 }; 2247 };
2245 2248
2246 for (int i = 0; test_cases[i].program; i++) { 2249 for (int i = 0; test_cases[i].program; i++) {
2247 const char* program = test_cases[i].program; 2250 const char* program = test_cases[i].program;
2248 i::Factory* factory = CcTest::i_isolate()->factory(); 2251 i::Factory* factory = CcTest::i_isolate()->factory();
2249 i::Handle<i::String> source = 2252 i::Handle<i::String> source =
2250 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); 2253 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
2251 i::Handle<i::Script> script = factory->NewScript(source); 2254 i::Handle<i::Script> script = factory->NewScript(source);
2252 i::CompilationInfoWithZone info(script); 2255 i::CompilationInfoWithZone info(script);
2253 i::ScriptData* sd = NULL; 2256 i::ScriptData* sd = NULL;
2254 info.SetCachedData(&sd, i::PRODUCE_CACHED_DATA); 2257 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache);
2255 i::Parser::Parse(&info, true); 2258 i::Parser::Parse(&info, true);
2256 i::ParseData pd(sd); 2259 i::ParseData pd(sd);
2257 2260
2258 if (pd.FunctionCount() != test_cases[i].functions) { 2261 if (pd.FunctionCount() != test_cases[i].functions) {
2259 v8::base::OS::Print( 2262 v8::base::OS::Print(
2260 "Expected preparse data for program:\n" 2263 "Expected preparse data for program:\n"
2261 "\t%s\n" 2264 "\t%s\n"
2262 "to contain %d functions, however, received %d functions.\n", 2265 "to contain %d functions, however, received %d functions.\n",
2263 program, test_cases[i].functions, pd.FunctionCount()); 2266 program, test_cases[i].functions, pd.FunctionCount());
2264 CHECK(false); 2267 CHECK(false);
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 3144
3142 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {}) 3145 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
3143 "foo ? bar : baz => {}", 3146 "foo ? bar : baz => {}",
3144 NULL 3147 NULL
3145 }; 3148 };
3146 3149
3147 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; 3150 static const ParserFlag always_flags[] = {kAllowArrowFunctions};
3148 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 3151 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
3149 always_flags, ARRAY_SIZE(always_flags)); 3152 always_flags, ARRAY_SIZE(always_flags));
3150 } 3153 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698