19
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
22
- #include " node .h"
22
+ #include " node_v8 .h"
23
23
#include " base_object-inl.h"
24
24
#include " env-inl.h"
25
25
#include " memory_tracker-inl.h"
26
+ #include " node.h"
26
27
#include " util-inl.h"
27
28
#include " v8.h"
28
29
29
30
namespace node {
30
-
31
+ namespace v8_utils {
31
32
using v8::Array;
32
33
using v8::Context;
33
34
using v8::FunctionCallbackInfo;
35
+ using v8::HandleScope;
34
36
using v8::HeapCodeStatistics;
35
37
using v8::HeapSpaceStatistics;
36
38
using v8::HeapStatistics;
@@ -44,7 +46,6 @@ using v8::Uint32;
44
46
using v8::V8;
45
47
using v8::Value;
46
48
47
-
48
49
#define HEAP_STATISTICS_PROPERTIES (V ) \
49
50
V (0 , total_heap_size, kTotalHeapSizeIndex ) \
50
51
V (1 , total_heap_size_executable, kTotalHeapSizeExecutableIndex ) \
@@ -63,7 +64,6 @@ static constexpr size_t kHeapStatisticsPropertiesCount =
63
64
HEAP_STATISTICS_PROPERTIES (V);
64
65
#undef V
65
66
66
-
67
67
#define HEAP_SPACE_STATISTICS_PROPERTIES (V ) \
68
68
V (0 , space_size, kSpaceSizeIndex ) \
69
69
V (1 , space_used_size, kSpaceUsedSizeIndex ) \
@@ -85,32 +85,34 @@ static const size_t kHeapCodeStatisticsPropertiesCount =
85
85
HEAP_CODE_STATISTICS_PROPERTIES (V);
86
86
#undef V
87
87
88
- class BindingData : public BaseObject {
89
- public:
90
- BindingData (Environment* env, Local<Object> obj)
91
- : BaseObject(env, obj),
92
- heap_statistics_buffer (env->isolate (), kHeapStatisticsPropertiesCount),
93
- heap_space_statistics_buffer(env->isolate (),
94
- kHeapSpaceStatisticsPropertiesCount),
95
- heap_code_statistics_buffer(env->isolate (),
96
- kHeapCodeStatisticsPropertiesCount) {}
97
-
98
- static constexpr FastStringKey type_name { " v8" };
99
-
100
- AliasedFloat64Array heap_statistics_buffer;
101
- AliasedFloat64Array heap_space_statistics_buffer;
102
- AliasedFloat64Array heap_code_statistics_buffer;
103
-
104
- void MemoryInfo (MemoryTracker* tracker) const override {
105
- tracker->TrackField (" heap_statistics_buffer" , heap_statistics_buffer);
106
- tracker->TrackField (" heap_space_statistics_buffer" ,
107
- heap_space_statistics_buffer);
108
- tracker->TrackField (" heap_code_statistics_buffer" ,
109
- heap_code_statistics_buffer);
110
- }
111
- SET_SELF_SIZE (BindingData)
112
- SET_MEMORY_INFO_NAME(BindingData)
113
- };
88
+ BindingData::BindingData (Environment* env, Local<Object> obj)
89
+ : BaseObject(env, obj),
90
+ heap_statistics_buffer (env->isolate (), kHeapStatisticsPropertiesCount),
91
+ heap_space_statistics_buffer(env->isolate (),
92
+ kHeapSpaceStatisticsPropertiesCount),
93
+ heap_code_statistics_buffer(env->isolate (),
94
+ kHeapCodeStatisticsPropertiesCount) {
95
+ obj->Set (env->context (),
96
+ FIXED_ONE_BYTE_STRING (env->isolate (), " heapStatisticsBuffer" ),
97
+ heap_statistics_buffer.GetJSArray ())
98
+ .Check ();
99
+ obj->Set (env->context (),
100
+ FIXED_ONE_BYTE_STRING (env->isolate (), " heapCodeStatisticsBuffer" ),
101
+ heap_code_statistics_buffer.GetJSArray ())
102
+ .Check ();
103
+ obj->Set (env->context (),
104
+ FIXED_ONE_BYTE_STRING (env->isolate (), " heapSpaceStatisticsBuffer" ),
105
+ heap_space_statistics_buffer.GetJSArray ())
106
+ .Check ();
107
+ }
108
+
109
+ void BindingData::MemoryInfo (MemoryTracker* tracker) const {
110
+ tracker->TrackField (" heap_statistics_buffer" , heap_statistics_buffer);
111
+ tracker->TrackField (" heap_space_statistics_buffer" ,
112
+ heap_space_statistics_buffer);
113
+ tracker->TrackField (" heap_code_statistics_buffer" ,
114
+ heap_code_statistics_buffer);
115
+ }
114
116
115
117
// TODO(addaleax): Remove once we're on C++17.
116
118
constexpr FastStringKey BindingData::type_name;
@@ -179,36 +181,12 @@ void Initialize(Local<Object> target,
179
181
180
182
env->SetMethodNoSideEffect (target, " cachedDataVersionTag" ,
181
183
CachedDataVersionTag);
182
-
183
- // Export symbols used by v8.getHeapStatistics()
184
184
env->SetMethod (
185
185
target, " updateHeapStatisticsBuffer" , UpdateHeapStatisticsBuffer);
186
186
187
- target
188
- ->Set (env->context (),
189
- FIXED_ONE_BYTE_STRING (env->isolate (), " heapStatisticsBuffer" ),
190
- binding_data->heap_statistics_buffer .GetJSArray ())
191
- .Check ();
192
-
193
- #define V (i, _, name ) \
194
- target->Set (env->context (), \
195
- FIXED_ONE_BYTE_STRING (env->isolate (), #name), \
196
- Uint32::NewFromUnsigned (env->isolate (), i)).Check ();
197
-
198
- HEAP_STATISTICS_PROPERTIES (V)
199
-
200
- // Export symbols used by v8.getHeapCodeStatistics()
201
187
env->SetMethod (
202
188
target, " updateHeapCodeStatisticsBuffer" , UpdateHeapCodeStatisticsBuffer);
203
189
204
- target
205
- ->Set (env->context (),
206
- FIXED_ONE_BYTE_STRING (env->isolate (), " heapCodeStatisticsBuffer" ),
207
- binding_data->heap_code_statistics_buffer .GetJSArray ())
208
- .Check ();
209
-
210
- HEAP_CODE_STATISTICS_PROPERTIES (V)
211
-
212
190
size_t number_of_heap_spaces = env->isolate ()->NumberOfHeapSpaces ();
213
191
214
192
// Heap space names are extracted once and exposed to JavaScript to
@@ -230,20 +208,23 @@ void Initialize(Local<Object> target,
230
208
" updateHeapSpaceStatisticsBuffer" ,
231
209
UpdateHeapSpaceStatisticsBuffer);
232
210
233
- target
234
- -> Set (env-> context (),
235
- FIXED_ONE_BYTE_STRING (env->isolate (),
236
- " heapSpaceStatisticsBuffer " ),
237
- binding_data-> heap_space_statistics_buffer . GetJSArray ())
211
+ # define V ( i, _, name ) \
212
+ target \
213
+ -> Set (env->context (), \
214
+ FIXED_ONE_BYTE_STRING (env-> isolate (), #name), \
215
+ Uint32::NewFromUnsigned (env-> isolate (), i)) \
238
216
.Check ();
239
217
218
+ HEAP_STATISTICS_PROPERTIES (V)
219
+ HEAP_CODE_STATISTICS_PROPERTIES (V)
240
220
HEAP_SPACE_STATISTICS_PROPERTIES (V)
241
221
#undef V
242
222
243
223
// Export symbols used by v8.setFlagsFromString()
244
224
env->SetMethod (target, " setFlagsFromString" , SetFlagsFromString);
245
225
}
246
226
227
+ } // namespace v8_utils
247
228
} // namespace node
248
229
249
- NODE_MODULE_CONTEXT_AWARE_INTERNAL (v8, node::Initialize)
230
+ NODE_MODULE_CONTEXT_AWARE_INTERNAL (v8, node::v8_utils:: Initialize)
0 commit comments