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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // didn't match what Parser wanted to consume. | 349 // didn't match what Parser wanted to consume. |
347 v8::Isolate* isolate = CcTest::isolate(); | 350 v8::Isolate* isolate = CcTest::isolate(); |
348 v8::HandleScope handles(isolate); | 351 v8::HandleScope handles(isolate); |
349 v8::Local<v8::Context> context = v8::Context::New(isolate); | 352 v8::Local<v8::Context> context = v8::Context::New(isolate); |
350 v8::Context::Scope context_scope(context); | 353 v8::Context::Scope context_scope(context); |
351 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - | 354 CcTest::i_isolate()->stack_guard()->SetStackLimit(GetCurrentStackPosition() - |
352 128 * 1024); | 355 128 * 1024); |
353 | 356 |
354 { | 357 { |
355 const char* source = "var myo = {if: \"foo\"}; myo.if;"; | 358 const char* source = "var myo = {if: \"foo\"}; myo.if;"; |
356 v8::Local<v8::Value> result = PreCompileCompileRun(source); | 359 v8::Local<v8::Value> result = ParserCacheCompileRun(source); |
357 CHECK(result->IsString()); | 360 CHECK(result->IsString()); |
358 v8::String::Utf8Value utf8(result); | 361 v8::String::Utf8Value utf8(result); |
359 CHECK_EQ("foo", *utf8); | 362 CHECK_EQ("foo", *utf8); |
360 } | 363 } |
361 | 364 |
362 { | 365 { |
363 const char* source = "var myo = {\"bar\": \"foo\"}; myo[\"bar\"];"; | 366 const char* source = "var myo = {\"bar\": \"foo\"}; myo[\"bar\"];"; |
364 v8::Local<v8::Value> result = PreCompileCompileRun(source); | 367 v8::Local<v8::Value> result = ParserCacheCompileRun(source); |
365 CHECK(result->IsString()); | 368 CHECK(result->IsString()); |
366 v8::String::Utf8Value utf8(result); | 369 v8::String::Utf8Value utf8(result); |
367 CHECK_EQ("foo", *utf8); | 370 CHECK_EQ("foo", *utf8); |
368 } | 371 } |
369 | 372 |
370 { | 373 { |
371 const char* source = "var myo = {1: \"foo\"}; myo[1];"; | 374 const char* source = "var myo = {1: \"foo\"}; myo[1];"; |
372 v8::Local<v8::Value> result = PreCompileCompileRun(source); | 375 v8::Local<v8::Value> result = ParserCacheCompileRun(source); |
373 CHECK(result->IsString()); | 376 CHECK(result->IsString()); |
374 v8::String::Utf8Value utf8(result); | 377 v8::String::Utf8Value utf8(result); |
375 CHECK_EQ("foo", *utf8); | 378 CHECK_EQ("foo", *utf8); |
376 } | 379 } |
377 } | 380 } |
378 | 381 |
379 | 382 |
380 TEST(RegressChromium62639) { | 383 TEST(RegressChromium62639) { |
381 v8::V8::Initialize(); | 384 v8::V8::Initialize(); |
382 i::Isolate* isolate = CcTest::i_isolate(); | 385 i::Isolate* isolate = CcTest::i_isolate(); |
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 }; | 2182 }; |
2180 | 2183 |
2181 for (int i = 0; test_cases[i].program; i++) { | 2184 for (int i = 0; test_cases[i].program; i++) { |
2182 const char* program = test_cases[i].program; | 2185 const char* program = test_cases[i].program; |
2183 i::Factory* factory = CcTest::i_isolate()->factory(); | 2186 i::Factory* factory = CcTest::i_isolate()->factory(); |
2184 i::Handle<i::String> source = | 2187 i::Handle<i::String> source = |
2185 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2188 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
2186 i::Handle<i::Script> script = factory->NewScript(source); | 2189 i::Handle<i::Script> script = factory->NewScript(source); |
2187 i::CompilationInfoWithZone info(script); | 2190 i::CompilationInfoWithZone info(script); |
2188 i::ScriptData* sd = NULL; | 2191 i::ScriptData* sd = NULL; |
2189 info.SetCachedData(&sd, i::PRODUCE_CACHED_DATA); | 2192 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); |
2190 i::Parser::Parse(&info, true); | 2193 i::Parser::Parse(&info, true); |
2191 i::ParseData pd(sd); | 2194 i::ParseData pd(sd); |
2192 | 2195 |
2193 if (pd.FunctionCount() != test_cases[i].functions) { | 2196 if (pd.FunctionCount() != test_cases[i].functions) { |
2194 v8::base::OS::Print( | 2197 v8::base::OS::Print( |
2195 "Expected preparse data for program:\n" | 2198 "Expected preparse data for program:\n" |
2196 "\t%s\n" | 2199 "\t%s\n" |
2197 "to contain %d functions, however, received %d functions.\n", | 2200 "to contain %d functions, however, received %d functions.\n", |
2198 program, test_cases[i].functions, pd.FunctionCount()); | 2201 program, test_cases[i].functions, pd.FunctionCount()); |
2199 CHECK(false); | 2202 CHECK(false); |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2913 LocalContext env; | 2916 LocalContext env; |
2914 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; | 2917 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; |
2915 global_use_counts = use_counts; | 2918 global_use_counts = use_counts; |
2916 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); | 2919 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); |
2917 CompileRun("\"use asm\";\n" | 2920 CompileRun("\"use asm\";\n" |
2918 "var foo = 1;\n" | 2921 "var foo = 1;\n" |
2919 "\"use asm\";\n" // Only the first one counts. | 2922 "\"use asm\";\n" // Only the first one counts. |
2920 "function bar() { \"use asm\"; var baz = 1; }"); | 2923 "function bar() { \"use asm\"; var baz = 1; }"); |
2921 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); | 2924 CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]); |
2922 } | 2925 } |
OLD | NEW |