Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: src/extensions/statistics-extension.cc

Issue 10830160: Fix crash bug when calling getV8Statistics(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/extensions/statistics-extension.cc
diff --git a/src/extensions/statistics-extension.cc b/src/extensions/statistics-extension.cc
index cb347374b80a663834ec373297d1d5cddec3bb70..ac986f4991780e7d4c760df55bf5df1145a1d79b 100644
--- a/src/extensions/statistics-extension.cc
+++ b/src/extensions/statistics-extension.cc
@@ -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(
const v8::Arguments& args) {
Isolate* isolate = Isolate::Current();
Heap* heap = isolate->heap();
+
if (args.Length() > 0) { // GC if first argument evaluates to true.
if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
@@ -54,46 +65,31 @@ v8::Handle<v8::Value> StatisticsExtension::GetCounters(
Counters* counters = isolate->counters();
v8::Local<v8::Object> result = v8::Object::New();
- StatsCounter* counter = NULL;
-
#define ADD_COUNTER(name, caption) \
- counter = counters->name(); \
- if (counter->Enabled()) \
- result->Set(v8::String::New(#name), \
- v8::Number::New(*counter->GetInternalPointer()));
+ AddProperty(result, counters->name(), #name);
STATS_COUNTER_LIST_1(ADD_COUNTER)
STATS_COUNTER_LIST_2(ADD_COUNTER)
#undef ADD_COUNTER
#define ADD_COUNTER(name) \
- counter = counters->count_of_##name(); \
- if (counter->Enabled()) \
- 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()));
+ AddProperty(result, counters->count_of_##name(), "count_of_" #name); \
+ AddProperty(result, counters->size_of_##name(), "size_of_" #name);
INSTANCE_TYPE_LIST(ADD_COUNTER)
#undef ADD_COUNTER
#define ADD_COUNTER(name) \
- result->Set(v8::String::New("count_of_CODE_TYPE_" #name), \
- v8::Number::New( \
- *counters->count_of_CODE_TYPE_##name()->GetInternalPointer())); \
- result->Set(v8::String::New("size_of_CODE_TYPE_" #name), \
- v8::Number::New( \
- *counters->size_of_CODE_TYPE_##name()->GetInternalPointer()));
+ AddProperty(result, counters->count_of_CODE_TYPE_##name(), \
+ "count_of_CODE_TYPE_" #name); \
+ AddProperty(result, counters->size_of_CODE_TYPE_##name(), \
+ "size_of_CODE_TYPE_" #name);
CODE_KIND_LIST(ADD_COUNTER)
#undef ADD_COUNTER
#define ADD_COUNTER(name) \
- result->Set(v8::String::New("count_of_FIXED_ARRAY_" #name), \
- v8::Number::New( \
- *counters->count_of_FIXED_ARRAY_##name()->GetInternalPointer())); \
- result->Set(v8::String::New("size_of_FIXED_ARRAY_" #name), \
- v8::Number::New( \
- *counters->size_of_FIXED_ARRAY_##name()->GetInternalPointer()));
+ AddProperty(result, counters->count_of_FIXED_ARRAY_##name(), \
+ "count_of_FIXED_ARRAY_" #name); \
+ AddProperty(result, counters->size_of_FIXED_ARRAY_##name(), \
+ "size_of_FIXED_ARRAY_" #name);
FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADD_COUNTER)
#undef ADD_COUNTER
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698