OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/extensions/statistics-extension.h" | 5 #include "src/extensions/statistics-extension.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 | 9 |
10 const char* const StatisticsExtension::kSource = | 10 const char* const StatisticsExtension::kSource = |
11 "native function getV8Statistics();"; | 11 "native function getV8Statistics();"; |
12 | 12 |
13 | 13 |
14 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunctionTemplate( | 14 v8::Handle<v8::FunctionTemplate> StatisticsExtension::GetNativeFunctionTemplate( |
15 v8::Isolate* isolate, | 15 v8::Isolate* isolate, |
16 v8::Handle<v8::String> str) { | 16 v8::Handle<v8::String> str) { |
17 DCHECK(strcmp(*v8::String::Utf8Value(str), "getV8Statistics") == 0); | 17 DCHECK(strcmp(*v8::String::Utf8Value(str), "getV8Statistics") == 0); |
18 return v8::FunctionTemplate::New(isolate, StatisticsExtension::GetCounters); | 18 return v8::FunctionTemplate::New(isolate, StatisticsExtension::GetCounters); |
19 } | 19 } |
20 | 20 |
21 | 21 |
22 static void AddCounter(v8::Isolate* isolate, | 22 static void AddCounter(v8::Isolate* isolate, |
23 v8::Local<v8::Object> object, | 23 v8::Local<v8::Object> object, |
24 StatsCounter* counter, | 24 StatsCounter* counter, |
25 const char* name) { | 25 const char* name) { |
26 if (counter->Enabled()) { | 26 if (counter->Enabled()) { |
27 object->Set(v8::String::NewFromUtf8(isolate, name), | 27 object->Set(isolate->GetCurrentContext(), |
28 v8::Number::New(isolate, *counter->GetInternalPointer())); | 28 v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal) |
| 29 .ToLocalChecked(), |
| 30 v8::Number::New(isolate, *counter->GetInternalPointer())) |
| 31 .FromJust(); |
29 } | 32 } |
30 } | 33 } |
31 | 34 |
32 static void AddNumber(v8::Isolate* isolate, | 35 static void AddNumber(v8::Isolate* isolate, |
33 v8::Local<v8::Object> object, | 36 v8::Local<v8::Object> object, |
34 intptr_t value, | 37 intptr_t value, |
35 const char* name) { | 38 const char* name) { |
36 object->Set(v8::String::NewFromUtf8(isolate, name), | 39 object->Set(isolate->GetCurrentContext(), |
37 v8::Number::New(isolate, static_cast<double>(value))); | 40 v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal) |
| 41 .ToLocalChecked(), |
| 42 v8::Number::New(isolate, static_cast<double>(value))).FromJust(); |
38 } | 43 } |
39 | 44 |
40 | 45 |
41 static void AddNumber64(v8::Isolate* isolate, | 46 static void AddNumber64(v8::Isolate* isolate, |
42 v8::Local<v8::Object> object, | 47 v8::Local<v8::Object> object, |
43 int64_t value, | 48 int64_t value, |
44 const char* name) { | 49 const char* name) { |
45 object->Set(v8::String::NewFromUtf8(isolate, name), | 50 object->Set(isolate->GetCurrentContext(), |
46 v8::Number::New(isolate, static_cast<double>(value))); | 51 v8::String::NewFromUtf8(isolate, name, NewStringType::kNormal) |
| 52 .ToLocalChecked(), |
| 53 v8::Number::New(isolate, static_cast<double>(value))).FromJust(); |
47 } | 54 } |
48 | 55 |
49 | 56 |
50 void StatisticsExtension::GetCounters( | 57 void StatisticsExtension::GetCounters( |
51 const v8::FunctionCallbackInfo<v8::Value>& args) { | 58 const v8::FunctionCallbackInfo<v8::Value>& args) { |
52 Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate()); | 59 Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate()); |
53 Heap* heap = isolate->heap(); | 60 Heap* heap = isolate->heap(); |
54 | 61 |
55 if (args.Length() > 0) { // GC if first argument evaluates to true. | 62 if (args.Length() > 0) { // GC if first argument evaluates to true. |
56 if (args[0]->IsBoolean() && | 63 if (args[0]->IsBoolean() && |
57 args[0]->ToBoolean(args.GetIsolate())->Value()) { | 64 args[0] |
| 65 ->BooleanValue(args.GetIsolate()->GetCurrentContext()) |
| 66 .FromMaybe(false)) { |
58 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); | 67 heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension"); |
59 } | 68 } |
60 } | 69 } |
61 | 70 |
62 Counters* counters = isolate->counters(); | 71 Counters* counters = isolate->counters(); |
63 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); | 72 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); |
64 | 73 |
65 struct StatisticsCounter { | 74 struct StatisticsCounter { |
66 v8::internal::StatsCounter* counter; | 75 v8::internal::StatsCounter* counter; |
67 const char* name; | 76 const char* name; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 133 } |
125 | 134 |
126 AddNumber64(args.GetIsolate(), result, | 135 AddNumber64(args.GetIsolate(), result, |
127 heap->amount_of_external_allocated_memory(), | 136 heap->amount_of_external_allocated_memory(), |
128 "amount_of_external_allocated_memory"); | 137 "amount_of_external_allocated_memory"); |
129 args.GetReturnValue().Set(result); | 138 args.GetReturnValue().Set(result); |
130 } | 139 } |
131 | 140 |
132 } // namespace internal | 141 } // namespace internal |
133 } // namespace v8 | 142 } // namespace v8 |
OLD | NEW |