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

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

Issue 394793002: Verify that source string matches serialized code. (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
« no previous file with comments | « src/serialize.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 2007-2010 the V8 project authors. All rights reserved. 1 // Copyright 2007-2010 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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <signal.h> 28 #include <signal.h>
29 29
30 #include <sys/stat.h> 30 #include <sys/stat.h>
31 31
32 #include "src/v8.h" 32 #include "src/v8.h"
33 33
34 #include "src/bootstrapper.h" 34 #include "src/bootstrapper.h"
35 #include "src/compilation-cache.h"
35 #include "src/debug.h" 36 #include "src/debug.h"
36 #include "src/ic-inl.h" 37 #include "src/ic-inl.h"
37 #include "src/natives.h" 38 #include "src/natives.h"
38 #include "src/objects.h" 39 #include "src/objects.h"
39 #include "src/runtime.h" 40 #include "src/runtime.h"
40 #include "src/scopeinfo.h" 41 #include "src/scopeinfo.h"
41 #include "src/serialize.h" 42 #include "src/serialize.h"
42 #include "src/snapshot.h" 43 #include "src/snapshot.h"
43 #include "src/spaces.h" 44 #include "src/spaces.h"
44 #include "test/cctest/cctest.h" 45 #include "test/cctest/cctest.h"
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 672 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
672 if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++; 673 if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++;
673 } 674 }
674 return counter; 675 return counter;
675 } 676 }
676 677
677 678
678 TEST(SerializeToplevelOnePlusOne) { 679 TEST(SerializeToplevelOnePlusOne) {
679 FLAG_serialize_toplevel = true; 680 FLAG_serialize_toplevel = true;
680 LocalContext context; 681 LocalContext context;
682 Isolate* isolate = CcTest::i_isolate();
683 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
684
681 v8::HandleScope scope(CcTest::isolate()); 685 v8::HandleScope scope(CcTest::isolate());
682 686
683 const char* source1 = "1 + 1"; 687 const char* source = "1 + 1";
684 const char* source2 = "1 + 2"; // Use alternate string to verify caching.
685 688
686 Isolate* isolate = CcTest::i_isolate(); 689 Handle<String> orig_source = isolate->factory()
687 Handle<String> source1_string = isolate->factory() 690 ->NewStringFromUtf8(CStrVector(source))
688 ->NewStringFromUtf8(CStrVector(source1)) 691 .ToHandleChecked();
689 .ToHandleChecked(); 692 Handle<String> copy_source = isolate->factory()
690 693 ->NewStringFromUtf8(CStrVector(source))
691 Handle<String> source2_string = isolate->factory() 694 .ToHandleChecked();
692 ->NewStringFromUtf8(CStrVector(source2)) 695 CHECK(!orig_source.is_identical_to(copy_source));
693 .ToHandleChecked(); 696 CHECK(orig_source->Equals(*copy_source));
694 697
695 ScriptData* cache = NULL; 698 ScriptData* cache = NULL;
696 699
697 Handle<SharedFunctionInfo> orig = 700 Handle<SharedFunctionInfo> orig =
698 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, 701 Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
699 Handle<Context>(isolate->native_context()), NULL, 702 Handle<Context>(isolate->native_context()), NULL,
700 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); 703 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
701 704
702 int builtins_count = CountBuiltins(); 705 int builtins_count = CountBuiltins();
703 706
704 Handle<SharedFunctionInfo> copy = 707 Handle<SharedFunctionInfo> copy;
705 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, 708 {
706 Handle<Context>(isolate->native_context()), NULL, 709 DisallowCompilation no_compile_expected(isolate);
mvstanton 2014/07/15 14:54:31 Elegant!
707 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 710 copy = Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
708 711 Handle<Context>(isolate->native_context()),
712 NULL, &cache, CONSUME_CACHED_DATA,
713 NOT_NATIVES_CODE);
714 }
709 CHECK_NE(*orig, *copy); 715 CHECK_NE(*orig, *copy);
710 CHECK(Script::cast(copy->script())->source() == *source2_string); 716 CHECK(Script::cast(copy->script())->source() == *copy_source);
711 717
712 Handle<JSFunction> copy_fun = 718 Handle<JSFunction> copy_fun =
713 isolate->factory()->NewFunctionFromSharedFunctionInfo( 719 isolate->factory()->NewFunctionFromSharedFunctionInfo(
714 copy, isolate->native_context()); 720 copy, isolate->native_context());
715 Handle<JSObject> global(isolate->context()->global_object()); 721 Handle<JSObject> global(isolate->context()->global_object());
716 Handle<Object> copy_result = 722 Handle<Object> copy_result =
717 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 723 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
718 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); 724 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value());
719 725
720 CHECK_EQ(builtins_count, CountBuiltins()); 726 CHECK_EQ(builtins_count, CountBuiltins());
721 727
722 delete cache; 728 delete cache;
723 } 729 }
724 730
725 731
726 TEST(SerializeToplevelInternalizedString) { 732 TEST(SerializeToplevelInternalizedString) {
727 FLAG_serialize_toplevel = true; 733 FLAG_serialize_toplevel = true;
728 LocalContext context; 734 LocalContext context;
735 Isolate* isolate = CcTest::i_isolate();
736 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache.
737
729 v8::HandleScope scope(CcTest::isolate()); 738 v8::HandleScope scope(CcTest::isolate());
730 739
731 const char* source1 = "'string1'"; 740 const char* source = "'string1'";
732 const char* source2 = "'string2'"; // Use alternate string to verify caching.
733 741
734 Isolate* isolate = CcTest::i_isolate(); 742 Handle<String> orig_source = isolate->factory()
735 Handle<String> source1_string = isolate->factory() 743 ->NewStringFromUtf8(CStrVector(source))
736 ->NewStringFromUtf8(CStrVector(source1)) 744 .ToHandleChecked();
737 .ToHandleChecked(); 745 Handle<String> copy_source = isolate->factory()
746 ->NewStringFromUtf8(CStrVector(source))
747 .ToHandleChecked();
748 CHECK(!orig_source.is_identical_to(copy_source));
749 CHECK(orig_source->Equals(*copy_source));
738 750
739 Handle<String> source2_string = isolate->factory()
740 ->NewStringFromUtf8(CStrVector(source2))
741 .ToHandleChecked();
742 Handle<JSObject> global(isolate->context()->global_object()); 751 Handle<JSObject> global(isolate->context()->global_object());
743 ScriptData* cache = NULL; 752 ScriptData* cache = NULL;
744 753
745 Handle<SharedFunctionInfo> orig = 754 Handle<SharedFunctionInfo> orig =
746 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, 755 Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
747 Handle<Context>(isolate->native_context()), NULL, 756 Handle<Context>(isolate->native_context()), NULL,
748 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); 757 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
749 Handle<JSFunction> orig_fun = 758 Handle<JSFunction> orig_fun =
750 isolate->factory()->NewFunctionFromSharedFunctionInfo( 759 isolate->factory()->NewFunctionFromSharedFunctionInfo(
751 orig, isolate->native_context()); 760 orig, isolate->native_context());
752 Handle<Object> orig_result = 761 Handle<Object> orig_result =
753 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked(); 762 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked();
754 CHECK(orig_result->IsInternalizedString()); 763 CHECK(orig_result->IsInternalizedString());
755 764
756 int builtins_count = CountBuiltins(); 765 int builtins_count = CountBuiltins();
757 766
758 Handle<SharedFunctionInfo> copy = 767 Handle<SharedFunctionInfo> copy;
759 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, 768 {
760 Handle<Context>(isolate->native_context()), NULL, 769 DisallowCompilation no_compile_expected(isolate);
761 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 770 copy = Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
771 Handle<Context>(isolate->native_context()),
772 NULL, &cache, CONSUME_CACHED_DATA,
773 NOT_NATIVES_CODE);
774 }
762 CHECK_NE(*orig, *copy); 775 CHECK_NE(*orig, *copy);
763 CHECK(Script::cast(copy->script())->source() == *source2_string); 776 CHECK(Script::cast(copy->script())->source() == *copy_source);
764 777
765 Handle<JSFunction> copy_fun = 778 Handle<JSFunction> copy_fun =
766 isolate->factory()->NewFunctionFromSharedFunctionInfo( 779 isolate->factory()->NewFunctionFromSharedFunctionInfo(
767 copy, isolate->native_context()); 780 copy, isolate->native_context());
768 CHECK_NE(*orig_fun, *copy_fun); 781 CHECK_NE(*orig_fun, *copy_fun);
769 Handle<Object> copy_result = 782 Handle<Object> copy_result =
770 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 783 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
771 CHECK(orig_result.is_identical_to(copy_result)); 784 CHECK(orig_result.is_identical_to(copy_result));
772 Handle<String> expected = 785 Handle<String> expected =
773 isolate->factory()->NewStringFromAsciiChecked("string1"); 786 isolate->factory()->NewStringFromAsciiChecked("string1");
774 787
775 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); 788 CHECK(Handle<String>::cast(copy_result)->Equals(*expected));
776 CHECK_EQ(builtins_count, CountBuiltins()); 789 CHECK_EQ(builtins_count, CountBuiltins());
777 790
778 delete cache; 791 delete cache;
779 } 792 }
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698