OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 bool is_warming_up_; | 709 bool is_warming_up_; |
710 }; | 710 }; |
711 | 711 |
712 | 712 |
713 // Test that native accessors are properly reported in the CPU profile. | 713 // Test that native accessors are properly reported in the CPU profile. |
714 // This test checks the case when the long-running accessors are called | 714 // This test checks the case when the long-running accessors are called |
715 // only once and the optimizer doesn't have chance to change the invocation | 715 // only once and the optimizer doesn't have chance to change the invocation |
716 // code. | 716 // code. |
717 TEST(NativeAccessorUninitializedIC) { | 717 TEST(NativeAccessorUninitializedIC) { |
718 LocalContext env; | 718 LocalContext env; |
719 v8::HandleScope scope(env->GetIsolate()); | 719 v8::Isolate* isolate = env->GetIsolate(); |
| 720 v8::HandleScope scope(isolate); |
720 | 721 |
721 | 722 v8::Local<v8::FunctionTemplate> func_template = |
722 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 723 v8::FunctionTemplate::New(isolate); |
723 v8::Local<v8::ObjectTemplate> instance_template = | 724 v8::Local<v8::ObjectTemplate> instance_template = |
724 func_template->InstanceTemplate(); | 725 func_template->InstanceTemplate(); |
725 | 726 |
726 TestApiCallbacks accessors(100); | 727 TestApiCallbacks accessors(100); |
727 v8::Local<v8::External> data = | 728 v8::Local<v8::External> data = |
728 v8::External::New(env->GetIsolate(), &accessors); | 729 v8::External::New(isolate, &accessors); |
729 instance_template->SetAccessor( | 730 instance_template->SetAccessor( |
730 v8::String::NewFromUtf8(env->GetIsolate(), "foo"), | 731 v8::String::NewFromUtf8(isolate, "foo"), |
731 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); | 732 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); |
732 v8::Local<v8::Function> func = func_template->GetFunction(); | 733 v8::Local<v8::Function> func = func_template->GetFunction(); |
733 v8::Local<v8::Object> instance = func->NewInstance(); | 734 v8::Local<v8::Object> instance = func->NewInstance(); |
734 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), | 735 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"), |
735 instance); | 736 instance); |
736 | 737 |
737 v8::Script::Compile( | 738 v8::Script::Compile( |
738 v8::String::NewFromUtf8(env->GetIsolate(), native_accessor_test_source)) | 739 v8::String::NewFromUtf8(isolate, native_accessor_test_source)) |
739 ->Run(); | 740 ->Run(); |
740 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 741 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
741 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 742 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); |
742 | 743 |
743 int32_t repeat_count = 1; | 744 int32_t repeat_count = 1; |
744 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 745 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
745 const v8::CpuProfile* profile = | 746 const v8::CpuProfile* profile = |
746 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); | 747 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); |
747 | 748 |
748 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 749 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
749 const v8::CpuProfileNode* startNode = | 750 const v8::CpuProfileNode* startNode = |
750 GetChild(env->GetIsolate(), root, "start"); | 751 GetChild(isolate, root, "start"); |
751 GetChild(env->GetIsolate(), startNode, "get foo"); | 752 GetChild(isolate, startNode, "get foo"); |
752 GetChild(env->GetIsolate(), startNode, "set foo"); | 753 GetChild(isolate, startNode, "set foo"); |
753 | 754 |
754 const_cast<v8::CpuProfile*>(profile)->Delete(); | 755 const_cast<v8::CpuProfile*>(profile)->Delete(); |
755 } | 756 } |
756 | 757 |
757 | 758 |
758 // Test that native accessors are properly reported in the CPU profile. | 759 // Test that native accessors are properly reported in the CPU profile. |
759 // This test makes sure that the accessors are called enough times to become | 760 // This test makes sure that the accessors are called enough times to become |
760 // hot and to trigger optimizations. | 761 // hot and to trigger optimizations. |
761 TEST(NativeAccessorMonomorphicIC) { | 762 TEST(NativeAccessorMonomorphicIC) { |
762 LocalContext env; | 763 LocalContext env; |
763 v8::HandleScope scope(env->GetIsolate()); | 764 v8::Isolate* isolate = env->GetIsolate(); |
| 765 v8::HandleScope scope(isolate); |
764 | 766 |
765 | 767 v8::Local<v8::FunctionTemplate> func_template = |
766 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 768 v8::FunctionTemplate::New(isolate); |
767 v8::Local<v8::ObjectTemplate> instance_template = | 769 v8::Local<v8::ObjectTemplate> instance_template = |
768 func_template->InstanceTemplate(); | 770 func_template->InstanceTemplate(); |
769 | 771 |
770 TestApiCallbacks accessors(1); | 772 TestApiCallbacks accessors(1); |
771 v8::Local<v8::External> data = | 773 v8::Local<v8::External> data = |
772 v8::External::New(env->GetIsolate(), &accessors); | 774 v8::External::New(isolate, &accessors); |
773 instance_template->SetAccessor( | 775 instance_template->SetAccessor( |
774 v8::String::NewFromUtf8(env->GetIsolate(), "foo"), | 776 v8::String::NewFromUtf8(isolate, "foo"), |
775 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); | 777 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); |
776 v8::Local<v8::Function> func = func_template->GetFunction(); | 778 v8::Local<v8::Function> func = func_template->GetFunction(); |
777 v8::Local<v8::Object> instance = func->NewInstance(); | 779 v8::Local<v8::Object> instance = func->NewInstance(); |
778 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), | 780 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"), |
779 instance); | 781 instance); |
780 | 782 |
781 v8::Script::Compile( | 783 v8::Script::Compile( |
782 v8::String::NewFromUtf8(env->GetIsolate(), native_accessor_test_source)) | 784 v8::String::NewFromUtf8(isolate, native_accessor_test_source)) |
783 ->Run(); | 785 ->Run(); |
784 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 786 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
785 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 787 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); |
786 | 788 |
787 { | 789 { |
788 // Make sure accessors ICs are in monomorphic state before starting | 790 // Make sure accessors ICs are in monomorphic state before starting |
789 // profiling. | 791 // profiling. |
790 accessors.set_warming_up(true); | 792 accessors.set_warming_up(true); |
791 int32_t warm_up_iterations = 3; | 793 int32_t warm_up_iterations = 3; |
792 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; | 794 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; |
793 function->Call(env->Global(), ARRAY_SIZE(args), args); | 795 function->Call(env->Global(), ARRAY_SIZE(args), args); |
794 accessors.set_warming_up(false); | 796 accessors.set_warming_up(false); |
795 } | 797 } |
796 | 798 |
797 int32_t repeat_count = 100; | 799 int32_t repeat_count = 100; |
798 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 800 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
799 const v8::CpuProfile* profile = | 801 const v8::CpuProfile* profile = |
800 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); | 802 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); |
801 | 803 |
802 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 804 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
803 const v8::CpuProfileNode* startNode = | 805 const v8::CpuProfileNode* startNode = |
804 GetChild(env->GetIsolate(), root, "start"); | 806 GetChild(isolate, root, "start"); |
805 GetChild(env->GetIsolate(), startNode, "get foo"); | 807 GetChild(isolate, startNode, "get foo"); |
806 GetChild(env->GetIsolate(), startNode, "set foo"); | 808 GetChild(isolate, startNode, "set foo"); |
807 | 809 |
808 const_cast<v8::CpuProfile*>(profile)->Delete(); | 810 const_cast<v8::CpuProfile*>(profile)->Delete(); |
809 } | 811 } |
810 | 812 |
811 | 813 |
812 static const char* native_method_test_source = "function start(count) {\n" | 814 static const char* native_method_test_source = "function start(count) {\n" |
813 " for (var i = 0; i < count; i++) {\n" | 815 " for (var i = 0; i < count; i++) {\n" |
814 " instance.fooMethod();\n" | 816 " instance.fooMethod();\n" |
815 " }\n" | 817 " }\n" |
816 "}\n"; | 818 "}\n"; |
817 | 819 |
818 | 820 |
819 TEST(NativeMethodUninitializedIC) { | 821 TEST(NativeMethodUninitializedIC) { |
820 LocalContext env; | 822 LocalContext env; |
821 v8::HandleScope scope(env->GetIsolate()); | 823 v8::Isolate* isolate = env->GetIsolate(); |
| 824 v8::HandleScope scope(isolate); |
822 | 825 |
823 TestApiCallbacks callbacks(100); | 826 TestApiCallbacks callbacks(100); |
824 v8::Local<v8::External> data = | 827 v8::Local<v8::External> data = |
825 v8::External::New(env->GetIsolate(), &callbacks); | 828 v8::External::New(isolate, &callbacks); |
826 | 829 |
827 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 830 v8::Local<v8::FunctionTemplate> func_template = |
| 831 v8::FunctionTemplate::New(isolate); |
828 func_template->SetClassName( | 832 func_template->SetClassName( |
829 v8::String::NewFromUtf8(env->GetIsolate(), "Test_InstanceCostructor")); | 833 v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor")); |
830 v8::Local<v8::ObjectTemplate> proto_template = | 834 v8::Local<v8::ObjectTemplate> proto_template = |
831 func_template->PrototypeTemplate(); | 835 func_template->PrototypeTemplate(); |
832 v8::Local<v8::Signature> signature = | 836 v8::Local<v8::Signature> signature = |
833 v8::Signature::New(env->GetIsolate(), func_template); | 837 v8::Signature::New(isolate, func_template); |
834 proto_template->Set(v8::String::NewFromUtf8(env->GetIsolate(), "fooMethod"), | 838 proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"), |
835 v8::FunctionTemplate::New(&TestApiCallbacks::Callback, | 839 v8::FunctionTemplate::New(isolate, |
| 840 &TestApiCallbacks::Callback, |
836 data, signature, 0)); | 841 data, signature, 0)); |
837 | 842 |
838 v8::Local<v8::Function> func = func_template->GetFunction(); | 843 v8::Local<v8::Function> func = func_template->GetFunction(); |
839 v8::Local<v8::Object> instance = func->NewInstance(); | 844 v8::Local<v8::Object> instance = func->NewInstance(); |
840 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), | 845 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"), |
841 instance); | 846 instance); |
842 | 847 |
843 v8::Script::Compile(v8::String::NewFromUtf8( | 848 v8::Script::Compile(v8::String::NewFromUtf8( |
844 env->GetIsolate(), native_method_test_source))->Run(); | 849 isolate, native_method_test_source))->Run(); |
845 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 850 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
846 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 851 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); |
847 | 852 |
848 int32_t repeat_count = 1; | 853 int32_t repeat_count = 1; |
849 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 854 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
850 const v8::CpuProfile* profile = | 855 const v8::CpuProfile* profile = |
851 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 856 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
852 | 857 |
853 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 858 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
854 const v8::CpuProfileNode* startNode = | 859 const v8::CpuProfileNode* startNode = |
855 GetChild(env->GetIsolate(), root, "start"); | 860 GetChild(isolate, root, "start"); |
856 GetChild(env->GetIsolate(), startNode, "fooMethod"); | 861 GetChild(isolate, startNode, "fooMethod"); |
857 | 862 |
858 const_cast<v8::CpuProfile*>(profile)->Delete(); | 863 const_cast<v8::CpuProfile*>(profile)->Delete(); |
859 } | 864 } |
860 | 865 |
861 | 866 |
862 TEST(NativeMethodMonomorphicIC) { | 867 TEST(NativeMethodMonomorphicIC) { |
863 LocalContext env; | 868 LocalContext env; |
864 v8::HandleScope scope(env->GetIsolate()); | 869 v8::Isolate* isolate = env->GetIsolate(); |
| 870 v8::HandleScope scope(isolate); |
865 | 871 |
866 TestApiCallbacks callbacks(1); | 872 TestApiCallbacks callbacks(1); |
867 v8::Local<v8::External> data = | 873 v8::Local<v8::External> data = |
868 v8::External::New(env->GetIsolate(), &callbacks); | 874 v8::External::New(isolate, &callbacks); |
869 | 875 |
870 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 876 v8::Local<v8::FunctionTemplate> func_template = |
| 877 v8::FunctionTemplate::New(isolate); |
871 func_template->SetClassName( | 878 func_template->SetClassName( |
872 v8::String::NewFromUtf8(env->GetIsolate(), "Test_InstanceCostructor")); | 879 v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor")); |
873 v8::Local<v8::ObjectTemplate> proto_template = | 880 v8::Local<v8::ObjectTemplate> proto_template = |
874 func_template->PrototypeTemplate(); | 881 func_template->PrototypeTemplate(); |
875 v8::Local<v8::Signature> signature = | 882 v8::Local<v8::Signature> signature = |
876 v8::Signature::New(env->GetIsolate(), func_template); | 883 v8::Signature::New(isolate, func_template); |
877 proto_template->Set(v8::String::NewFromUtf8(env->GetIsolate(), "fooMethod"), | 884 proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"), |
878 v8::FunctionTemplate::New(&TestApiCallbacks::Callback, | 885 v8::FunctionTemplate::New(isolate, |
| 886 &TestApiCallbacks::Callback, |
879 data, signature, 0)); | 887 data, signature, 0)); |
880 | 888 |
881 v8::Local<v8::Function> func = func_template->GetFunction(); | 889 v8::Local<v8::Function> func = func_template->GetFunction(); |
882 v8::Local<v8::Object> instance = func->NewInstance(); | 890 v8::Local<v8::Object> instance = func->NewInstance(); |
883 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), | 891 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"), |
884 instance); | 892 instance); |
885 | 893 |
886 v8::Script::Compile(v8::String::NewFromUtf8( | 894 v8::Script::Compile(v8::String::NewFromUtf8( |
887 env->GetIsolate(), native_method_test_source))->Run(); | 895 isolate, native_method_test_source))->Run(); |
888 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 896 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
889 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 897 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); |
890 { | 898 { |
891 // Make sure method ICs are in monomorphic state before starting | 899 // Make sure method ICs are in monomorphic state before starting |
892 // profiling. | 900 // profiling. |
893 callbacks.set_warming_up(true); | 901 callbacks.set_warming_up(true); |
894 int32_t warm_up_iterations = 3; | 902 int32_t warm_up_iterations = 3; |
895 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; | 903 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; |
896 function->Call(env->Global(), ARRAY_SIZE(args), args); | 904 function->Call(env->Global(), ARRAY_SIZE(args), args); |
897 callbacks.set_warming_up(false); | 905 callbacks.set_warming_up(false); |
898 } | 906 } |
899 | 907 |
900 int32_t repeat_count = 100; | 908 int32_t repeat_count = 100; |
901 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 909 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
902 const v8::CpuProfile* profile = | 910 const v8::CpuProfile* profile = |
903 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 911 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
904 | 912 |
905 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 913 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
906 GetChild(env->GetIsolate(), root, "start"); | 914 GetChild(isolate, root, "start"); |
907 const v8::CpuProfileNode* startNode = | 915 const v8::CpuProfileNode* startNode = |
908 GetChild(env->GetIsolate(), root, "start"); | 916 GetChild(isolate, root, "start"); |
909 GetChild(env->GetIsolate(), startNode, "fooMethod"); | 917 GetChild(isolate, startNode, "fooMethod"); |
910 | 918 |
911 const_cast<v8::CpuProfile*>(profile)->Delete(); | 919 const_cast<v8::CpuProfile*>(profile)->Delete(); |
912 } | 920 } |
913 | 921 |
914 | 922 |
915 static const char* bound_function_test_source = "function foo(iterations) {\n" | 923 static const char* bound_function_test_source = "function foo(iterations) {\n" |
916 " var r = 0;\n" | 924 " var r = 0;\n" |
917 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 925 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
918 " return r;\n" | 926 " return r;\n" |
919 "}\n" | 927 "}\n" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 // 55 0 CallJsFunction #0 4 | 1172 // 55 0 CallJsFunction #0 4 |
1165 // 55 1 bar #16 5 | 1173 // 55 1 bar #16 5 |
1166 // 54 54 foo #16 6 | 1174 // 54 54 foo #16 6 |
1167 TEST(JsNativeJsSample) { | 1175 TEST(JsNativeJsSample) { |
1168 const char* extensions[] = { "v8/profiler" }; | 1176 const char* extensions[] = { "v8/profiler" }; |
1169 v8::ExtensionConfiguration config(1, extensions); | 1177 v8::ExtensionConfiguration config(1, extensions); |
1170 LocalContext env(&config); | 1178 LocalContext env(&config); |
1171 v8::HandleScope scope(env->GetIsolate()); | 1179 v8::HandleScope scope(env->GetIsolate()); |
1172 | 1180 |
1173 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1181 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
1174 CallJsFunction); | 1182 env->GetIsolate(), CallJsFunction); |
1175 v8::Local<v8::Function> func = func_template->GetFunction(); | 1183 v8::Local<v8::Function> func = func_template->GetFunction(); |
1176 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); | 1184 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); |
1177 env->Global()->Set( | 1185 env->Global()->Set( |
1178 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); | 1186 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); |
1179 | 1187 |
1180 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1188 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1181 js_native_js_test_source))->Run(); | 1189 js_native_js_test_source))->Run(); |
1182 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1190 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1183 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1191 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1184 | 1192 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 // 54 3 bar #16 5 | 1255 // 54 3 bar #16 5 |
1248 // 51 51 foo #16 6 | 1256 // 51 51 foo #16 6 |
1249 // 2 2 (program) #0 2 | 1257 // 2 2 (program) #0 2 |
1250 TEST(JsNativeJsRuntimeJsSample) { | 1258 TEST(JsNativeJsRuntimeJsSample) { |
1251 const char* extensions[] = { "v8/profiler" }; | 1259 const char* extensions[] = { "v8/profiler" }; |
1252 v8::ExtensionConfiguration config(1, extensions); | 1260 v8::ExtensionConfiguration config(1, extensions); |
1253 LocalContext env(&config); | 1261 LocalContext env(&config); |
1254 v8::HandleScope scope(env->GetIsolate()); | 1262 v8::HandleScope scope(env->GetIsolate()); |
1255 | 1263 |
1256 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1264 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
1257 CallJsFunction); | 1265 env->GetIsolate(), CallJsFunction); |
1258 v8::Local<v8::Function> func = func_template->GetFunction(); | 1266 v8::Local<v8::Function> func = func_template->GetFunction(); |
1259 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); | 1267 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); |
1260 env->Global()->Set( | 1268 env->Global()->Set( |
1261 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); | 1269 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); |
1262 | 1270 |
1263 v8::Script::Compile( | 1271 v8::Script::Compile( |
1264 v8::String::NewFromUtf8(env->GetIsolate(), | 1272 v8::String::NewFromUtf8(env->GetIsolate(), |
1265 js_native_js_runtime_js_test_source))->Run(); | 1273 js_native_js_runtime_js_test_source))->Run(); |
1266 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1274 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1267 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1275 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 // 54 0 CallJsFunction2 #0 6 | 1342 // 54 0 CallJsFunction2 #0 6 |
1335 // 54 54 foo #16 7 | 1343 // 54 54 foo #16 7 |
1336 // 2 2 (program) #0 2 | 1344 // 2 2 (program) #0 2 |
1337 TEST(JsNative1JsNative2JsSample) { | 1345 TEST(JsNative1JsNative2JsSample) { |
1338 const char* extensions[] = { "v8/profiler" }; | 1346 const char* extensions[] = { "v8/profiler" }; |
1339 v8::ExtensionConfiguration config(1, extensions); | 1347 v8::ExtensionConfiguration config(1, extensions); |
1340 LocalContext env(&config); | 1348 LocalContext env(&config); |
1341 v8::HandleScope scope(env->GetIsolate()); | 1349 v8::HandleScope scope(env->GetIsolate()); |
1342 | 1350 |
1343 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1351 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
1344 CallJsFunction); | 1352 env->GetIsolate(), CallJsFunction); |
1345 v8::Local<v8::Function> func1 = func_template->GetFunction(); | 1353 v8::Local<v8::Function> func1 = func_template->GetFunction(); |
1346 func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1")); | 1354 func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1")); |
1347 env->Global()->Set( | 1355 env->Global()->Set( |
1348 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1); | 1356 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1); |
1349 | 1357 |
1350 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( | 1358 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( |
1351 CallJsFunction2)->GetFunction(); | 1359 env->GetIsolate(), CallJsFunction2)->GetFunction(); |
1352 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); | 1360 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); |
1353 env->Global()->Set( | 1361 env->Global()->Set( |
1354 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); | 1362 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); |
1355 | 1363 |
1356 v8::Script::Compile( | 1364 v8::Script::Compile( |
1357 v8::String::NewFromUtf8(env->GetIsolate(), | 1365 v8::String::NewFromUtf8(env->GetIsolate(), |
1358 js_native1_js_native2_js_test_source))->Run(); | 1366 js_native1_js_native2_js_test_source))->Run(); |
1359 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1367 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1360 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1368 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1361 | 1369 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 inner_profile = NULL; | 1548 inner_profile = NULL; |
1541 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1549 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1542 | 1550 |
1543 const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer); | 1551 const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer); |
1544 CHECK(outer_profile); | 1552 CHECK(outer_profile); |
1545 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1553 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1546 const_cast<v8::CpuProfile*>(outer_profile)->Delete(); | 1554 const_cast<v8::CpuProfile*>(outer_profile)->Delete(); |
1547 outer_profile = NULL; | 1555 outer_profile = NULL; |
1548 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1556 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1549 } | 1557 } |
OLD | NEW |