Commit 0a0b4f4f authored by yangguo@chromium.org's avatar yangguo@chromium.org

Fix crash bug when calling getV8Statistics().

BUG=v8:2270

Review URL: https://chromiumcodereview.appspot.com/10830160

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12255 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 83fc4205
...@@ -41,10 +41,21 @@ v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction( ...@@ -41,10 +41,21 @@ v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunction(
} }
static void AddProperty(v8::Local<v8::Object> object,
StatsCounter* counter,
const char* name) {
if (counter->Enabled()) {
object->Set(v8::String::New(name),
v8::Number::New(*counter->GetInternalPointer()));
}
}
v8::Handle<v8::Value> StatisticsExtension::GetCounters( v8::Handle<v8::Value> StatisticsExtension::GetCounters(
const v8::Arguments& args) { const v8::Arguments& args) {
Isolate* isolate = Isolate::Current(); Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
if (args.Length() > 0) { // GC if first argument evaluates to true. if (args.Length() > 0) { // GC if first argument evaluates to true.
if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) { if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
...@@ -54,46 +65,31 @@ v8::Handle<v8::Value> StatisticsExtension::GetCounters( ...@@ -54,46 +65,31 @@ v8::Handle<v8::Value> StatisticsExtension::GetCounters(
Counters* counters = isolate->counters(); Counters* counters = isolate->counters();
v8::Local<v8::Object> result = v8::Object::New(); v8::Local<v8::Object> result = v8::Object::New();
StatsCounter* counter = NULL;
#define ADD_COUNTER(name, caption) \ #define ADD_COUNTER(name, caption) \
counter = counters->name(); \ AddProperty(result, counters->name(), #name);
if (counter->Enabled()) \
result->Set(v8::String::New(#name), \
v8::Number::New(*counter->GetInternalPointer()));
STATS_COUNTER_LIST_1(ADD_COUNTER) STATS_COUNTER_LIST_1(ADD_COUNTER)
STATS_COUNTER_LIST_2(ADD_COUNTER) STATS_COUNTER_LIST_2(ADD_COUNTER)
#undef ADD_COUNTER #undef ADD_COUNTER
#define ADD_COUNTER(name) \ #define ADD_COUNTER(name) \
counter = counters->count_of_##name(); \ AddProperty(result, counters->count_of_##name(), "count_of_" #name); \
if (counter->Enabled()) \ AddProperty(result, counters->size_of_##name(), "size_of_" #name);
result->Set(v8::String::New("count_of_" #name), \
v8::Number::New(*counter->GetInternalPointer())); \
counter = counters->size_of_##name(); \
if (counter->Enabled()) \
result->Set(v8::String::New("size_of_" #name), \
v8::Number::New(*counter->GetInternalPointer()));
INSTANCE_TYPE_LIST(ADD_COUNTER) INSTANCE_TYPE_LIST(ADD_COUNTER)
#undef ADD_COUNTER #undef ADD_COUNTER
#define ADD_COUNTER(name) \ #define ADD_COUNTER(name) \
result->Set(v8::String::New("count_of_CODE_TYPE_" #name), \ AddProperty(result, counters->count_of_CODE_TYPE_##name(), \
v8::Number::New( \ "count_of_CODE_TYPE_" #name); \
*counters->count_of_CODE_TYPE_##name()->GetInternalPointer())); \ AddProperty(result, counters->size_of_CODE_TYPE_##name(), \
result->Set(v8::String::New("size_of_CODE_TYPE_" #name), \ "size_of_CODE_TYPE_" #name);
v8::Number::New( \
*counters->size_of_CODE_TYPE_##name()->GetInternalPointer()));
CODE_KIND_LIST(ADD_COUNTER) CODE_KIND_LIST(ADD_COUNTER)
#undef ADD_COUNTER #undef ADD_COUNTER
#define ADD_COUNTER(name) \ #define ADD_COUNTER(name) \
result->Set(v8::String::New("count_of_FIXED_ARRAY_" #name), \ AddProperty(result, counters->count_of_FIXED_ARRAY_##name(), \
v8::Number::New( \ "count_of_FIXED_ARRAY_" #name); \
*counters->count_of_FIXED_ARRAY_##name()->GetInternalPointer())); \ AddProperty(result, counters->size_of_FIXED_ARRAY_##name(), \
result->Set(v8::String::New("size_of_FIXED_ARRAY_" #name), \ "size_of_FIXED_ARRAY_" #name);
v8::Number::New( \
*counters->size_of_FIXED_ARRAY_##name()->GetInternalPointer()));
FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER) FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER)
#undef ADD_COUNTER #undef ADD_COUNTER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment