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

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

Issue 389573006: Change ScriptCompiler::CompileOptions and add d8 --cache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 Handle<JSObject> global(isolate->context()->global_object()); 52 Handle<JSObject> global(isolate->context()->global_object());
53 Runtime::SetObjectProperty(isolate, global, internalized_name, object, 53 Runtime::SetObjectProperty(isolate, global, internalized_name, object,
54 SLOPPY).Check(); 54 SLOPPY).Check();
55 } 55 }
56 56
57 57
58 static Handle<JSFunction> Compile(const char* source) { 58 static Handle<JSFunction> Compile(const char* source) {
59 Isolate* isolate = CcTest::i_isolate(); 59 Isolate* isolate = CcTest::i_isolate();
60 Handle<String> source_code = isolate->factory()->NewStringFromUtf8( 60 Handle<String> source_code = isolate->factory()->NewStringFromUtf8(
61 CStrVector(source)).ToHandleChecked(); 61 CStrVector(source)).ToHandleChecked();
62 Handle<SharedFunctionInfo> shared_function = 62 Handle<SharedFunctionInfo> shared_function = Compiler::CompileScript(
63 Compiler::CompileScript(source_code, 63 source_code, Handle<String>(), 0, 0, false,
64 Handle<String>(), 64 Handle<Context>(isolate->native_context()), NULL, NULL,
65 0, 65 v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE);
66 0,
67 false,
68 Handle<Context>(isolate->native_context()),
69 NULL, NULL, NO_CACHED_DATA,
70 NOT_NATIVES_CODE);
71 return isolate->factory()->NewFunctionFromSharedFunctionInfo( 66 return isolate->factory()->NewFunctionFromSharedFunctionInfo(
72 shared_function, isolate->native_context()); 67 shared_function, isolate->native_context());
73 } 68 }
74 69
75 70
76 static double Inc(Isolate* isolate, int x) { 71 static double Inc(Isolate* isolate, int x) {
77 const char* source = "result = %d + 1;"; 72 const char* source = "result = %d + 1;";
78 EmbeddedVector<char, 512> buffer; 73 EmbeddedVector<char, 512> buffer;
79 SNPrintF(buffer, source, x); 74 SNPrintF(buffer, source, x);
80 75
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2")))); 387 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2"))));
393 CHECK(fun1->IsOptimized() 388 CHECK(fun1->IsOptimized()
394 || !CcTest::i_isolate()->use_crankshaft() || !fun1->IsOptimizable()); 389 || !CcTest::i_isolate()->use_crankshaft() || !fun1->IsOptimizable());
395 CHECK(fun2->IsOptimized() 390 CHECK(fun2->IsOptimized()
396 || !CcTest::i_isolate()->use_crankshaft() || !fun2->IsOptimizable()); 391 || !CcTest::i_isolate()->use_crankshaft() || !fun2->IsOptimizable());
397 CHECK_EQ(fun1->code(), fun2->code()); 392 CHECK_EQ(fun1->code(), fun2->code());
398 } 393 }
399 } 394 }
400 395
401 396
402 TEST(SerializeToplevel) { 397 TEST(SerializeToplevel) {
Yang 2014/07/14 11:22:49 Note that I updated and moved this entire test to
403 FLAG_serialize_toplevel = true; 398 FLAG_serialize_toplevel = true;
404 v8::HandleScope scope(CcTest::isolate()); 399 v8::HandleScope scope(CcTest::isolate());
405 v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION); 400 v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION);
406 v8::Context::Scope context_scope(context); 401 v8::Context::Scope context_scope(context);
407 402
408 const char* source1 = "1 + 1"; 403 const char* source1 = "1 + 1";
409 const char* source2 = "1 + 2"; // Use alternate string to verify caching. 404 const char* source2 = "1 + 2"; // Use alternate string to verify caching.
410 405
411 Isolate* isolate = CcTest::i_isolate(); 406 Isolate* isolate = CcTest::i_isolate();
412 Handle<String> source1_string = isolate->factory() 407 Handle<String> source1_string = isolate->factory()
413 ->NewStringFromUtf8(CStrVector(source1)) 408 ->NewStringFromUtf8(CStrVector(source1))
414 .ToHandleChecked(); 409 .ToHandleChecked();
415 Handle<String> source2_string = isolate->factory() 410 Handle<String> source2_string = isolate->factory()
416 ->NewStringFromUtf8(CStrVector(source2)) 411 ->NewStringFromUtf8(CStrVector(source2))
417 .ToHandleChecked(); 412 .ToHandleChecked();
418 413
419 ScriptData* cache = NULL; 414 ScriptData* cache = NULL;
420 415
421 Handle<SharedFunctionInfo> orig = 416 Handle<SharedFunctionInfo> orig = Compiler::CompileScript(
422 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, 417 source1_string, Handle<String>(), 0, 0, false,
423 Handle<Context>(isolate->native_context()), NULL, 418 Handle<Context>(isolate->native_context()), NULL, &cache,
424 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); 419 v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE);
425 420
426 Handle<SharedFunctionInfo> info = 421 Handle<SharedFunctionInfo> info = Compiler::CompileScript(
427 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, 422 source2_string, Handle<String>(), 0, 0, false,
428 Handle<Context>(isolate->native_context()), NULL, 423 Handle<Context>(isolate->native_context()), NULL, &cache,
429 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 424 v8::ScriptCompiler::kConsumeCodeCache, NOT_NATIVES_CODE);
430 425
431 CHECK_NE(*orig, *info); 426 CHECK_NE(*orig, *info);
432 Handle<JSFunction> fun = 427 Handle<JSFunction> fun =
433 isolate->factory()->NewFunctionFromSharedFunctionInfo( 428 isolate->factory()->NewFunctionFromSharedFunctionInfo(
434 info, isolate->native_context()); 429 info, isolate->native_context());
435 Handle<JSObject> global(isolate->context()->global_object()); 430 Handle<JSObject> global(isolate->context()->global_object());
436 Handle<Object> result = 431 Handle<Object> result =
437 Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked(); 432 Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked();
438 CHECK_EQ(2, Handle<Smi>::cast(result)->value()); 433 CHECK_EQ(2, Handle<Smi>::cast(result)->value());
439 434
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 CompileRun("function f() { a = 12345678 }; f();"); 481 CompileRun("function f() { a = 12345678 }; f();");
487 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 482 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
488 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 483 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
489 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 484 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
490 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 485 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
491 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 486 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
492 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 487 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
493 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 488 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
494 } 489 }
495 #endif 490 #endif
OLDNEW
« src/api.cc ('K') | « test/cctest/test-api.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698