OLD | NEW |
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // Should not crash. | 253 // Should not crash. |
254 const char* message = pre_impl->BuildMessage(); | 254 const char* message = pre_impl->BuildMessage(); |
255 i::Vector<const char*> args = pre_impl->BuildArgs(); | 255 i::Vector<const char*> args = pre_impl->BuildArgs(); |
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) { |
| 264 // This tests that we actually do use the function data generated by the |
| 265 // preparser. |
| 266 v8::Isolate* isolate = CcTest::isolate(); |
| 267 v8::HandleScope handles(isolate); |
| 268 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 269 v8::Context::Scope context_scope(context); |
| 270 int marker; |
| 271 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 272 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 273 |
| 274 const char* good_source = |
| 275 "function this_is_lazy() { var a; } function foo() { return 25; } foo();"; |
| 276 |
| 277 // Insert a syntax error inside the lazy function. |
| 278 const char* bad_source = |
| 279 "function this_is_lazy() { if ( } function foo() { return 25; } foo();"; |
| 280 |
| 281 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source)); |
| 282 CHECK(!preparse->HasError()); |
| 283 |
| 284 // 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. |
| 286 v8::ScriptCompiler::Source source( |
| 287 v8_str(bad_source), |
| 288 v8::ScriptCompiler::CachedData( |
| 289 reinterpret_cast<const uint8_t*>(preparse->Data()), |
| 290 preparse->Length())); |
| 291 v8::Local<v8::Value> result = |
| 292 v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run(); |
| 293 CHECK(result->IsInt32()); |
| 294 CHECK_EQ(25, result->Int32Value()); |
| 295 delete preparse; |
| 296 } |
| 297 |
| 298 |
| 299 TEST(PreparseSymbolDataIsUsed) { |
| 300 // This tests that we actually do use the symbol data generated by the |
| 301 // preparser. |
| 302 |
| 303 // Only do one compilation pass in this test (otherwise we will parse the |
| 304 // source code again without preparse data and it will fail). |
| 305 i::FLAG_crankshaft = false; |
| 306 |
| 307 v8::Isolate* isolate = CcTest::isolate(); |
| 308 v8::HandleScope handles(isolate); |
| 309 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 310 v8::Context::Scope context_scope(context); |
| 311 int marker; |
| 312 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 313 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 314 |
| 315 // Note that the ( before function makes the |
| 316 const char* good_source = |
| 317 "(function weird() { var foo = 26; return foo; })()"; |
| 318 |
| 319 // Insert an undefined identifier. If the preparser data is used, the symbol |
| 320 // stream is used instead, and this identifier resolves correctly to"foo". |
| 321 const char* bad_source = |
| 322 "(function weird() { var foo = 26; return wut; })()"; |
| 323 |
| 324 v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source)); |
| 325 CHECK(!preparse->HasError()); |
| 326 |
| 327 // 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 |
| 329 // unknown "wut". |
| 330 v8::ScriptCompiler::Source source( |
| 331 v8_str(bad_source), |
| 332 v8::ScriptCompiler::CachedData( |
| 333 reinterpret_cast<const uint8_t*>(preparse->Data()), |
| 334 preparse->Length())); |
| 335 v8::Local<v8::Value> result = |
| 336 v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run(); |
| 337 CHECK(result->IsInt32()); |
| 338 CHECK_EQ(26, result->Int32Value()); |
| 339 delete preparse; |
| 340 } |
| 341 |
| 342 |
263 TEST(StandAlonePreParser) { | 343 TEST(StandAlonePreParser) { |
264 v8::V8::Initialize(); | 344 v8::V8::Initialize(); |
265 | 345 |
266 int marker; | 346 int marker; |
267 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 347 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
268 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 348 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
269 | 349 |
270 const char* programs[] = { | 350 const char* programs[] = { |
271 "{label: 42}", | 351 "{label: 42}", |
272 "var x = 42;", | 352 "var x = 42;", |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 | 2452 |
2373 const char* statement_data[] = { | 2453 const char* statement_data[] = { |
2374 statement, | 2454 statement, |
2375 NULL | 2455 NULL |
2376 }; | 2456 }; |
2377 | 2457 |
2378 // The test is quite slow, so run it with a reduced set of flags. | 2458 // The test is quite slow, so run it with a reduced set of flags. |
2379 static const ParserFlag empty_flags[] = {kAllowLazy}; | 2459 static const ParserFlag empty_flags[] = {kAllowLazy}; |
2380 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); | 2460 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); |
2381 } | 2461 } |
OLD | NEW |