Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests for heap profiler | 3 // Tests for heap profiler |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "cctest.h" | 7 #include "cctest.h" |
| 8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
| 9 #include "snapshot.h" | 9 #include "snapshot.h" |
| 10 #include "utils-inl.h" | 10 #include "utils-inl.h" |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 CHECK_NE(NULL, global); | 882 CHECK_NE(NULL, global); |
| 883 // Verify that we can find this object by iteration. | 883 // Verify that we can find this object by iteration. |
| 884 const int nodes_count = snapshot->GetNodesCount(); | 884 const int nodes_count = snapshot->GetNodesCount(); |
| 885 int count = 0; | 885 int count = 0; |
| 886 for (int i = 0; i < nodes_count; ++i) { | 886 for (int i = 0; i < nodes_count; ++i) { |
| 887 if (snapshot->GetNode(i) == global) | 887 if (snapshot->GetNode(i) == global) |
| 888 ++count; | 888 ++count; |
| 889 } | 889 } |
| 890 CHECK_EQ(1, count); | 890 CHECK_EQ(1, count); |
| 891 } | 891 } |
| 892 | |
| 893 | |
| 894 static int StringCmp(const char* ref, i::String* act) { | |
| 895 i::SmartPointer<char> s_act = act->ToCString(); | |
| 896 int result = strcmp(ref, *s_act); | |
| 897 if (result != 0) | |
| 898 fprintf(stderr, "Expected: \"%s\", Actual: \"%s\"\n", ref, *s_act); | |
| 899 return result; | |
| 900 } | |
| 901 | |
| 902 | |
| 903 TEST(GetConstructorName) { | |
| 904 v8::HandleScope scope; | |
| 905 LocalContext env; | |
| 906 | |
| 907 CompileRun( | |
| 908 "function Constructor1() {};\n" | |
| 909 "var obj1 = new Constructor1();\n" | |
| 910 "var Constructor2 = function() {};\n" | |
| 911 "var obj2 = new Constructor2();\n" | |
| 912 "var obj3 = {};\n" | |
| 913 "obj3.constructor = function Constructor3() {};\n" | |
| 914 "var obj4 = {};\n" | |
| 915 "// Slow properties\n" | |
| 916 "for (var i=0; i<2000; ++i) obj4[\"p\" + i] = i;\n" | |
| 917 "obj4.constructor = function Constructor4() {};\n" | |
| 918 "var obj5 = {};\n" | |
| 919 "var obj6 = {};\n" | |
|
Søren Thygesen Gjesse
2011/08/23 11:34:23
Why no test using obj6 below?
mnaganov (inactive)
2011/08/23 12:24:28
Thanks for spotting! Fixed.
| |
| 920 "obj6.constructor = 6;"); | |
| 921 v8::Local<v8::Object> js_global = | |
| 922 env->Global()->GetPrototype().As<v8::Object>(); | |
| 923 v8::Local<v8::Object> obj1 = js_global->Get(v8_str("obj1")).As<v8::Object>(); | |
| 924 i::Handle<i::JSObject> js_obj1 = v8::Utils::OpenHandle(*obj1); | |
| 925 CHECK_EQ(0, StringCmp( | |
| 926 "Constructor1", i::V8HeapExplorer::GetConstructorName(*js_obj1))); | |
| 927 v8::Local<v8::Object> obj2 = js_global->Get(v8_str("obj2")).As<v8::Object>(); | |
| 928 i::Handle<i::JSObject> js_obj2 = v8::Utils::OpenHandle(*obj2); | |
| 929 CHECK_EQ(0, StringCmp( | |
| 930 "Constructor2", i::V8HeapExplorer::GetConstructorName(*js_obj2))); | |
| 931 v8::Local<v8::Object> obj3 = js_global->Get(v8_str("obj3")).As<v8::Object>(); | |
| 932 i::Handle<i::JSObject> js_obj3 = v8::Utils::OpenHandle(*obj3); | |
| 933 CHECK_EQ(0, StringCmp( | |
| 934 "Constructor3", i::V8HeapExplorer::GetConstructorName(*js_obj3))); | |
| 935 v8::Local<v8::Object> obj4 = js_global->Get(v8_str("obj4")).As<v8::Object>(); | |
| 936 i::Handle<i::JSObject> js_obj4 = v8::Utils::OpenHandle(*obj4); | |
| 937 CHECK_EQ(0, StringCmp( | |
| 938 "Constructor4", i::V8HeapExplorer::GetConstructorName(*js_obj4))); | |
| 939 v8::Local<v8::Object> obj5 = js_global->Get(v8_str("obj5")).As<v8::Object>(); | |
| 940 i::Handle<i::JSObject> js_obj5 = v8::Utils::OpenHandle(*obj5); | |
| 941 CHECK_EQ(0, StringCmp( | |
| 942 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj5))); | |
| 943 } | |
| OLD | NEW |