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

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
« src/objects.h ('K') | « 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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
681 v8::HandleScope scope(CcTest::isolate()); 682 v8::HandleScope scope(CcTest::isolate());
682 683
683 const char* source1 = "1 + 1"; 684 const char* source = "1 + 1";
684 const char* source2 = "1 + 2"; // Use alternate string to verify caching.
685 685
686 Isolate* isolate = CcTest::i_isolate(); 686 Isolate* isolate = CcTest::i_isolate();
687 Handle<String> source1_string = isolate->factory() 687 isolate->compilation_cache()->Disable();
688 ->NewStringFromUtf8(CStrVector(source1))
689 .ToHandleChecked();
690 688
691 Handle<String> source2_string = isolate->factory() 689 Handle<String> orig_source = isolate->factory()
692 ->NewStringFromUtf8(CStrVector(source2)) 690 ->NewStringFromUtf8(CStrVector(source))
693 .ToHandleChecked(); 691 .ToHandleChecked();
692 Handle<String> copy_source = isolate->factory()
693 ->NewStringFromUtf8(CStrVector(source))
694 .ToHandleChecked();
695 CHECK(!orig_source.is_identical_to(copy_source));
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 Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
706 Handle<Context>(isolate->native_context()), NULL, 709 Handle<Context>(isolate->native_context()), NULL,
707 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 710 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
708 711
vogelheim 2014/07/15 13:42:31 Just for my understanding: Previously, this would
Yang 2014/07/15 13:47:31 You are right. Currently, if CompileScript was to
709 CHECK_NE(*orig, *copy); 712 CHECK_NE(*orig, *copy);
710 CHECK(Script::cast(copy->script())->source() == *source2_string); 713 CHECK(Script::cast(copy->script())->source() == *copy_source);
711 714
712 Handle<JSFunction> copy_fun = 715 Handle<JSFunction> copy_fun =
713 isolate->factory()->NewFunctionFromSharedFunctionInfo( 716 isolate->factory()->NewFunctionFromSharedFunctionInfo(
714 copy, isolate->native_context()); 717 copy, isolate->native_context());
715 Handle<JSObject> global(isolate->context()->global_object()); 718 Handle<JSObject> global(isolate->context()->global_object());
716 Handle<Object> copy_result = 719 Handle<Object> copy_result =
717 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 720 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
718 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); 721 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value());
719 722
720 CHECK_EQ(builtins_count, CountBuiltins()); 723 CHECK_EQ(builtins_count, CountBuiltins());
721 724
722 delete cache; 725 delete cache;
723 } 726 }
724 727
725 728
726 TEST(SerializeToplevelInternalizedString) { 729 TEST(SerializeToplevelInternalizedString) {
727 FLAG_serialize_toplevel = true; 730 FLAG_serialize_toplevel = true;
728 LocalContext context; 731 LocalContext context;
729 v8::HandleScope scope(CcTest::isolate()); 732 v8::HandleScope scope(CcTest::isolate());
730 733
731 const char* source1 = "'string1'"; 734 const char* source = "'string1'";
732 const char* source2 = "'string2'"; // Use alternate string to verify caching.
733 735
734 Isolate* isolate = CcTest::i_isolate(); 736 Isolate* isolate = CcTest::i_isolate();
735 Handle<String> source1_string = isolate->factory() 737 isolate->compilation_cache()->Disable();
736 ->NewStringFromUtf8(CStrVector(source1))
737 .ToHandleChecked();
738 738
739 Handle<String> source2_string = isolate->factory() 739 Handle<String> orig_source = isolate->factory()
740 ->NewStringFromUtf8(CStrVector(source2)) 740 ->NewStringFromUtf8(CStrVector(source))
741 .ToHandleChecked(); 741 .ToHandleChecked();
742 Handle<String> copy_source = isolate->factory()
743 ->NewStringFromUtf8(CStrVector(source))
744 .ToHandleChecked();
745 CHECK(!orig_source.is_identical_to(copy_source));
746 CHECK(orig_source->Equals(*copy_source));
747
742 Handle<JSObject> global(isolate->context()->global_object()); 748 Handle<JSObject> global(isolate->context()->global_object());
743 ScriptData* cache = NULL; 749 ScriptData* cache = NULL;
744 750
745 Handle<SharedFunctionInfo> orig = 751 Handle<SharedFunctionInfo> orig =
746 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, 752 Compiler::CompileScript(orig_source, Handle<String>(), 0, 0, false,
747 Handle<Context>(isolate->native_context()), NULL, 753 Handle<Context>(isolate->native_context()), NULL,
748 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); 754 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE);
749 Handle<JSFunction> orig_fun = 755 Handle<JSFunction> orig_fun =
750 isolate->factory()->NewFunctionFromSharedFunctionInfo( 756 isolate->factory()->NewFunctionFromSharedFunctionInfo(
751 orig, isolate->native_context()); 757 orig, isolate->native_context());
752 Handle<Object> orig_result = 758 Handle<Object> orig_result =
753 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked(); 759 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked();
754 CHECK(orig_result->IsInternalizedString()); 760 CHECK(orig_result->IsInternalizedString());
755 761
756 int builtins_count = CountBuiltins(); 762 int builtins_count = CountBuiltins();
757 763
758 Handle<SharedFunctionInfo> copy = 764 Handle<SharedFunctionInfo> copy =
759 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, 765 Compiler::CompileScript(copy_source, Handle<String>(), 0, 0, false,
760 Handle<Context>(isolate->native_context()), NULL, 766 Handle<Context>(isolate->native_context()), NULL,
761 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); 767 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE);
762 CHECK_NE(*orig, *copy); 768 CHECK_NE(*orig, *copy);
763 CHECK(Script::cast(copy->script())->source() == *source2_string); 769 CHECK(Script::cast(copy->script())->source() == *copy_source);
764 770
765 Handle<JSFunction> copy_fun = 771 Handle<JSFunction> copy_fun =
766 isolate->factory()->NewFunctionFromSharedFunctionInfo( 772 isolate->factory()->NewFunctionFromSharedFunctionInfo(
767 copy, isolate->native_context()); 773 copy, isolate->native_context());
768 CHECK_NE(*orig_fun, *copy_fun); 774 CHECK_NE(*orig_fun, *copy_fun);
769 Handle<Object> copy_result = 775 Handle<Object> copy_result =
770 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); 776 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked();
771 CHECK(orig_result.is_identical_to(copy_result)); 777 CHECK(orig_result.is_identical_to(copy_result));
772 Handle<String> expected = 778 Handle<String> expected =
773 isolate->factory()->NewStringFromAsciiChecked("string1"); 779 isolate->factory()->NewStringFromAsciiChecked("string1");
774 780
775 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); 781 CHECK(Handle<String>::cast(copy_result)->Equals(*expected));
776 CHECK_EQ(builtins_count, CountBuiltins()); 782 CHECK_EQ(builtins_count, CountBuiltins());
777 783
778 delete cache; 784 delete cache;
779 } 785 }
OLDNEW
« src/objects.h ('K') | « src/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698