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

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

Issue 203353002: New compilation API, part 2. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased 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 | « test/cctest/test-debug.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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8::String::NewFromUtf8( 209 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8::String::NewFromUtf8(
210 isolate, source, v8::String::kNormalString, source_length)); 210 isolate, source, v8::String::kNormalString, source_length));
211 CHECK(!preparse->HasError()); 211 CHECK(!preparse->HasError());
212 bool lazy_flag = i::FLAG_lazy; 212 bool lazy_flag = i::FLAG_lazy;
213 { 213 {
214 i::FLAG_lazy = true; 214 i::FLAG_lazy = true;
215 ScriptResource* resource = new ScriptResource(source, source_length); 215 ScriptResource* resource = new ScriptResource(source, source_length);
216 v8::ScriptCompiler::Source script_source( 216 v8::ScriptCompiler::Source script_source(
217 v8::String::NewExternal(isolate, resource), 217 v8::String::NewExternal(isolate, resource),
218 v8::ScriptCompiler::CachedData( 218 new v8::ScriptCompiler::CachedData(
219 reinterpret_cast<const uint8_t*>(preparse->Data()), 219 reinterpret_cast<const uint8_t*>(preparse->Data()),
220 preparse->Length())); 220 preparse->Length()));
221 v8::ScriptCompiler::Compile(isolate, 221 v8::ScriptCompiler::Compile(isolate,
222 v8::ScriptCompiler::Source(script_source)); 222 &script_source);
223 } 223 }
224 224
225 { 225 {
226 i::FLAG_lazy = false; 226 i::FLAG_lazy = false;
227 227
228 ScriptResource* resource = new ScriptResource(source, source_length); 228 ScriptResource* resource = new ScriptResource(source, source_length);
229 v8::ScriptCompiler::Source script_source( 229 v8::ScriptCompiler::Source script_source(
230 v8::String::NewExternal(isolate, resource), 230 v8::String::NewExternal(isolate, resource),
231 v8::ScriptCompiler::CachedData( 231 new v8::ScriptCompiler::CachedData(
232 reinterpret_cast<const uint8_t*>(preparse->Data()), 232 reinterpret_cast<const uint8_t*>(preparse->Data()),
233 preparse->Length())); 233 preparse->Length()));
234 v8::ScriptCompiler::CompileUnbound(isolate, script_source); 234 v8::ScriptCompiler::CompileUnbound(isolate, &script_source);
235 } 235 }
236 delete preparse; 236 delete preparse;
237 i::FLAG_lazy = lazy_flag; 237 i::FLAG_lazy = lazy_flag;
238 238
239 // Syntax error. 239 // Syntax error.
240 v8::ScriptData* error_preparse = v8::ScriptData::PreCompile( 240 v8::ScriptData* error_preparse = v8::ScriptData::PreCompile(
241 v8::String::NewFromUtf8(isolate, 241 v8::String::NewFromUtf8(isolate,
242 error_source, 242 error_source,
243 v8::String::kNormalString, 243 v8::String::kNormalString,
244 error_source_length)); 244 error_source_length));
(...skipping 11 matching lines...) Expand all
256 CHECK_GT(strlen(message), 0); 256 CHECK_GT(strlen(message), 0);
257 args.Dispose(); 257 args.Dispose();
258 i::DeleteArray(message); 258 i::DeleteArray(message);
259 delete error_preparse; 259 delete error_preparse;
260 } 260 }
261 261
262 262
263 TEST(PreparseFunctionDataIsUsed) { 263 TEST(PreparseFunctionDataIsUsed) {
264 // This tests that we actually do use the function data generated by the 264 // This tests that we actually do use the function data generated by the
265 // preparser. 265 // preparser.
266
267 // Make preparsing work for short scripts.
268 i::FLAG_min_preparse_length = 0;
269
266 v8::Isolate* isolate = CcTest::isolate(); 270 v8::Isolate* isolate = CcTest::isolate();
267 v8::HandleScope handles(isolate); 271 v8::HandleScope handles(isolate);
268 v8::Local<v8::Context> context = v8::Context::New(isolate); 272 v8::Local<v8::Context> context = v8::Context::New(isolate);
269 v8::Context::Scope context_scope(context); 273 v8::Context::Scope context_scope(context);
270 int marker; 274 int marker;
271 CcTest::i_isolate()->stack_guard()->SetStackLimit( 275 CcTest::i_isolate()->stack_guard()->SetStackLimit(
272 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 276 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
273 277
274 const char* good_source = 278 const char* good_code =
275 "function this_is_lazy() { var a; } function foo() { return 25; } foo();"; 279 "function this_is_lazy() { var a; } function foo() { return 25; } foo();";
276 280
277 // Insert a syntax error inside the lazy function. 281 // Insert a syntax error inside the lazy function.
278 const char* bad_source = 282 const char* bad_code =
279 "function this_is_lazy() { if ( } function foo() { return 25; } foo();"; 283 "function this_is_lazy() { if ( } function foo() { return 25; } foo();";
280 284
281 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source)); 285 v8::ScriptCompiler::Source good_source(v8_str(good_code));
282 CHECK(!preparse->HasError()); 286 v8::ScriptCompiler::Compile(isolate, &good_source,
287 v8::ScriptCompiler::kProduceDataToCache);
288
289 const v8::ScriptCompiler::CachedData* cached_data =
290 good_source.GetCachedData();
291 CHECK(cached_data->data != NULL);
292 CHECK_GT(cached_data->length, 0);
283 293
284 // Now compile the erroneous code with the good preparse data. If the preparse 294 // Now compile the erroneous code with the good preparse data. If the preparse
285 // data is used, the lazy function is skipped and it should compile fine. 295 // data is used, the lazy function is skipped and it should compile fine.
286 v8::ScriptCompiler::Source source( 296 v8::ScriptCompiler::Source bad_source(
287 v8_str(bad_source), 297 v8_str(bad_code), new v8::ScriptCompiler::CachedData(
288 v8::ScriptCompiler::CachedData( 298 cached_data->data, cached_data->length));
289 reinterpret_cast<const uint8_t*>(preparse->Data()),
290 preparse->Length()));
291 v8::Local<v8::Value> result = 299 v8::Local<v8::Value> result =
292 v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run(); 300 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
293 CHECK(result->IsInt32()); 301 CHECK(result->IsInt32());
294 CHECK_EQ(25, result->Int32Value()); 302 CHECK_EQ(25, result->Int32Value());
295 delete preparse;
296 } 303 }
297 304
298 305
299 TEST(PreparseSymbolDataIsUsed) { 306 TEST(PreparseSymbolDataIsUsed) {
300 // This tests that we actually do use the symbol data generated by the 307 // This tests that we actually do use the symbol data generated by the
301 // preparser. 308 // preparser.
302 309
303 // Only do one compilation pass in this test (otherwise we will parse the 310 // Only do one compilation pass in this test (otherwise we will parse the
304 // source code again without preparse data and it will fail). 311 // source code again without preparse data and it will fail).
305 i::FLAG_crankshaft = false; 312 i::FLAG_crankshaft = false;
306 313
314 // Make preparsing work for short scripts.
315 i::FLAG_min_preparse_length = 0;
316
307 v8::Isolate* isolate = CcTest::isolate(); 317 v8::Isolate* isolate = CcTest::isolate();
308 v8::HandleScope handles(isolate); 318 v8::HandleScope handles(isolate);
309 v8::Local<v8::Context> context = v8::Context::New(isolate); 319 v8::Local<v8::Context> context = v8::Context::New(isolate);
310 v8::Context::Scope context_scope(context); 320 v8::Context::Scope context_scope(context);
311 int marker; 321 int marker;
312 CcTest::i_isolate()->stack_guard()->SetStackLimit( 322 CcTest::i_isolate()->stack_guard()->SetStackLimit(
313 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 323 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
314 324
315 // Note that the ( before function makes the function not lazily compiled. 325 // Note that the ( before function makes the function not lazily compiled.
316 const char* good_source = 326 const char* good_code =
317 "(function weird() { var foo = 26; return foo; })()"; 327 "(function weird() { var foo = 26; return foo; })()";
318 328
319 // Insert an undefined identifier. If the preparser data is used, the symbol 329 // Insert an undefined identifier. If the preparser data is used, the symbol
320 // stream is used instead, and this identifier resolves to "foo". 330 // stream is used instead, and this identifier resolves to "foo".
321 const char* bad_source = 331 const char* bad_code =
322 "(function weird() { var foo = 26; return wut; })()"; 332 "(function weird() { var foo = 26; return wut; })()";
323 333
324 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source)); 334 v8::ScriptCompiler::Source good_source(v8_str(good_code));
325 CHECK(!preparse->HasError()); 335 v8::ScriptCompiler::Compile(isolate, &good_source,
336 v8::ScriptCompiler::kProduceDataToCache);
337
338 const v8::ScriptCompiler::CachedData* cached_data =
339 good_source.GetCachedData();
340 CHECK(cached_data->data != NULL);
341 CHECK_GT(cached_data->length, 0);
326 342
327 // Now compile the erroneous code with the good preparse data. If the preparse 343 // Now compile the erroneous code with the good preparse data. If the preparse
328 // data is used, we will see a second occurrence of "foo" instead of the 344 // data is used, we will see a second occurrence of "foo" instead of the
329 // unknown "wut". 345 // unknown "wut".
330 v8::ScriptCompiler::Source source( 346 v8::ScriptCompiler::Source bad_source(
331 v8_str(bad_source), 347 v8_str(bad_code), new v8::ScriptCompiler::CachedData(
332 v8::ScriptCompiler::CachedData( 348 cached_data->data, cached_data->length));
333 reinterpret_cast<const uint8_t*>(preparse->Data()),
334 preparse->Length()));
335 v8::Local<v8::Value> result = 349 v8::Local<v8::Value> result =
336 v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run(); 350 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
337 CHECK(result->IsInt32()); 351 CHECK(result->IsInt32());
338 CHECK_EQ(26, result->Int32Value()); 352 CHECK_EQ(26, result->Int32Value());
339 delete preparse;
340 } 353 }
341 354
342 355
343 TEST(StandAlonePreParser) { 356 TEST(StandAlonePreParser) {
344 v8::V8::Initialize(); 357 v8::V8::Initialize();
345 358
346 int marker; 359 int marker;
347 CcTest::i_isolate()->stack_guard()->SetStackLimit( 360 CcTest::i_isolate()->stack_guard()->SetStackLimit(
348 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 361 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
349 362
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 2465
2453 const char* statement_data[] = { 2466 const char* statement_data[] = {
2454 statement, 2467 statement,
2455 NULL 2468 NULL
2456 }; 2469 };
2457 2470
2458 // The test is quite slow, so run it with a reduced set of flags. 2471 // The test is quite slow, so run it with a reduced set of flags.
2459 static const ParserFlag empty_flags[] = {kAllowLazy}; 2472 static const ParserFlag empty_flags[] = {kAllowLazy};
2460 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); 2473 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2461 } 2474 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698