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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 reinterpret_cast<i::CpuProfile*>( | 907 reinterpret_cast<i::CpuProfile*>( |
908 const_cast<v8::CpuProfile*>(profile))->Print(); | 908 const_cast<v8::CpuProfile*>(profile))->Print(); |
909 | 909 |
910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
911 GetChild(root, "start"); | 911 GetChild(root, "start"); |
912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
913 GetChild(startNode, "fooMethod"); | 913 GetChild(startNode, "fooMethod"); |
914 | 914 |
915 cpu_profiler->DeleteAllCpuProfiles(); | 915 cpu_profiler->DeleteAllCpuProfiles(); |
916 } | 916 } |
| 917 |
| 918 |
| 919 static const char* bound_function_test_source = "function foo(iterations) {\n" |
| 920 " var r = 0;\n" |
| 921 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 922 " return r;\n" |
| 923 "}\n" |
| 924 "function start(duration) {\n" |
| 925 " var callback = foo.bind(this);\n" |
| 926 " var start = Date.now();\n" |
| 927 " while (Date.now() - start < duration) {\n" |
| 928 " callback(10 * 1000);\n" |
| 929 " }\n" |
| 930 "}"; |
| 931 |
| 932 |
| 933 TEST(BoundFunctionCall) { |
| 934 LocalContext env; |
| 935 v8::HandleScope scope(env->GetIsolate()); |
| 936 |
| 937 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run(); |
| 938 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 939 env->Global()->Get(v8::String::New("start"))); |
| 940 |
| 941 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 942 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 943 |
| 944 cpu_profiler->StartCpuProfiling(profile_name); |
| 945 int32_t duration_ms = 100; |
| 946 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 947 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 948 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 949 |
| 950 CHECK_NE(NULL, profile); |
| 951 // Dump collected profile to have a better diagnostic in case of failure. |
| 952 reinterpret_cast<i::CpuProfile*>( |
| 953 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 954 |
| 955 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 956 ScopedVector<v8::Handle<v8::String> > names(3); |
| 957 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 958 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 959 names[2] = v8::String::New("start"); |
| 960 // Don't allow |foo| node to be at the top level. |
| 961 CheckChildrenNames(root, names); |
| 962 |
| 963 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 964 GetChild(startNode, "foo"); |
| 965 |
| 966 cpu_profiler->DeleteAllCpuProfiles(); |
| 967 } |
OLD | NEW |