Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 HeapIterator iterator(CcTest::heap()); | 668 HeapIterator iterator(CcTest::heap()); |
| 669 DisallowHeapAllocation no_allocation; | 669 DisallowHeapAllocation no_allocation; |
| 670 int counter = 0; | 670 int counter = 0; |
| 671 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 671 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 672 if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++; | 672 if (obj->IsCode() && Code::cast(obj)->kind() == Code::BUILTIN) counter++; |
| 673 } | 673 } |
| 674 return counter; | 674 return counter; |
| 675 } | 675 } |
| 676 | 676 |
| 677 | 677 |
| 678 TEST(SerializeToplevel) { | 678 TEST(SerializeToplevelOnePlusOne) { |
| 679 FLAG_serialize_toplevel = true; | 679 FLAG_serialize_toplevel = true; |
| 680 LocalContext context; | |
| 680 v8::HandleScope scope(CcTest::isolate()); | 681 v8::HandleScope scope(CcTest::isolate()); |
| 681 v8::Local<v8::Context> context = CcTest::NewContext(PRINT_EXTENSION); | |
| 682 v8::Context::Scope context_scope(context); | |
| 683 | 682 |
| 684 const char* source1 = "1 + 1"; | 683 const char* source1 = "1 + 1"; |
| 685 const char* source2 = "1 + 2"; // Use alternate string to verify caching. | 684 const char* source2 = "1 + 2"; // Use alternate string to verify caching. |
| 686 | 685 |
| 687 Isolate* isolate = CcTest::i_isolate(); | 686 Isolate* isolate = CcTest::i_isolate(); |
| 688 Handle<String> source1_string = isolate->factory() | 687 Handle<String> source1_string = isolate->factory() |
| 689 ->NewStringFromUtf8(CStrVector(source1)) | 688 ->NewStringFromUtf8(CStrVector(source1)) |
| 690 .ToHandleChecked(); | 689 .ToHandleChecked(); |
| 691 | 690 |
| 692 Handle<String> source2_string = isolate->factory() | 691 Handle<String> source2_string = isolate->factory() |
| 693 ->NewStringFromUtf8(CStrVector(source2)) | 692 ->NewStringFromUtf8(CStrVector(source2)) |
| 694 .ToHandleChecked(); | 693 .ToHandleChecked(); |
| 695 | 694 |
| 696 ScriptData* cache = NULL; | 695 ScriptData* cache = NULL; |
| 697 | 696 |
| 698 Handle<SharedFunctionInfo> orig = | 697 Handle<SharedFunctionInfo> orig = |
| 699 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, | 698 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, |
| 700 Handle<Context>(isolate->native_context()), NULL, | 699 Handle<Context>(isolate->native_context()), NULL, |
| 701 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); | 700 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); |
| 702 | 701 |
| 703 int builtins_count = CountBuiltins(); | 702 int builtins_count = CountBuiltins(); |
| 704 | 703 |
| 705 Handle<SharedFunctionInfo> info = | 704 Handle<SharedFunctionInfo> copy = |
| 706 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, | 705 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, |
| 707 Handle<Context>(isolate->native_context()), NULL, | 706 Handle<Context>(isolate->native_context()), NULL, |
| 708 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); | 707 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); |
| 709 | 708 |
| 710 CHECK_NE(*orig, *info); | 709 CHECK_NE(*orig, *copy); |
| 711 Handle<JSFunction> fun = | 710 Handle<JSFunction> copy_fun = |
| 712 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 711 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 713 info, isolate->native_context()); | 712 copy, isolate->native_context()); |
| 714 Handle<JSObject> global(isolate->context()->global_object()); | 713 Handle<JSObject> global(isolate->context()->global_object()); |
| 715 Handle<Object> result = | 714 Handle<Object> copy_result = |
| 716 Execution::Call(isolate, fun, global, 0, NULL).ToHandleChecked(); | 715 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); |
| 717 CHECK_EQ(2, Handle<Smi>::cast(result)->value()); | 716 CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); |
| 718 | 717 |
| 719 CHECK_EQ(builtins_count, CountBuiltins()); | 718 CHECK_EQ(builtins_count, CountBuiltins()); |
| 720 | 719 |
| 721 delete cache; | 720 delete cache; |
| 722 } | 721 } |
| 722 | |
| 723 | |
| 724 TEST(SerializeToplevelInternalizedString) { | |
|
mvstanton
2014/07/14 13:31:03
Per our discussion, it might be nice in debug mode
| |
| 725 FLAG_serialize_toplevel = true; | |
| 726 LocalContext context; | |
| 727 v8::HandleScope scope(CcTest::isolate()); | |
| 728 | |
| 729 const char* source1 = "'string1'"; | |
| 730 const char* source2 = "'string2'"; // Use alternate string to verify caching. | |
| 731 | |
| 732 Isolate* isolate = CcTest::i_isolate(); | |
| 733 Handle<String> source1_string = isolate->factory() | |
| 734 ->NewStringFromUtf8(CStrVector(source1)) | |
| 735 .ToHandleChecked(); | |
| 736 | |
| 737 Handle<String> source2_string = isolate->factory() | |
| 738 ->NewStringFromUtf8(CStrVector(source2)) | |
| 739 .ToHandleChecked(); | |
| 740 Handle<JSObject> global(isolate->context()->global_object()); | |
| 741 ScriptData* cache = NULL; | |
| 742 | |
| 743 Handle<SharedFunctionInfo> orig = | |
| 744 Compiler::CompileScript(source1_string, Handle<String>(), 0, 0, false, | |
| 745 Handle<Context>(isolate->native_context()), NULL, | |
| 746 &cache, PRODUCE_CACHED_DATA, NOT_NATIVES_CODE); | |
| 747 Handle<JSFunction> orig_fun = | |
| 748 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 749 orig, isolate->native_context()); | |
| 750 Handle<Object> orig_result = | |
| 751 Execution::Call(isolate, orig_fun, global, 0, NULL).ToHandleChecked(); | |
| 752 CHECK(orig_result->IsInternalizedString()); | |
| 753 | |
| 754 int builtins_count = CountBuiltins(); | |
| 755 | |
| 756 Handle<SharedFunctionInfo> copy = | |
| 757 Compiler::CompileScript(source2_string, Handle<String>(), 0, 0, false, | |
| 758 Handle<Context>(isolate->native_context()), NULL, | |
| 759 &cache, CONSUME_CACHED_DATA, NOT_NATIVES_CODE); | |
| 760 CHECK_NE(*orig, *copy); | |
| 761 Handle<JSFunction> copy_fun = | |
| 762 isolate->factory()->NewFunctionFromSharedFunctionInfo( | |
| 763 copy, isolate->native_context()); | |
| 764 CHECK_NE(*orig_fun, *copy_fun); | |
| 765 Handle<Object> copy_result = | |
| 766 Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); | |
| 767 CHECK(orig_result.is_identical_to(copy_result)); | |
| 768 Handle<String> expected = | |
| 769 isolate->factory()->NewStringFromAsciiChecked("string1"); | |
| 770 | |
| 771 CHECK(Handle<String>::cast(copy_result)->Equals(*expected)); | |
| 772 CHECK_EQ(builtins_count, CountBuiltins()); | |
| 773 | |
| 774 delete cache; | |
| 775 } | |
| OLD | NEW |