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;
@@ -44,7 +45,6 @@ using v8::Uint32;
44
45
using v8::V8;
45
46
using v8::Value;
46
47
47
-
48
48
#define HEAP_STATISTICS_PROPERTIES (V ) \
49
49
V (0 , total_heap_size, kTotalHeapSizeIndex ) \
50
50
V (1 , total_heap_size_executable, kTotalHeapSizeExecutableIndex ) \
@@ -63,7 +63,6 @@ static constexpr size_t kHeapStatisticsPropertiesCount =
63
63
HEAP_STATISTICS_PROPERTIES (V);
64
64
#undef V
65
65
66
-
67
66
#define HEAP_SPACE_STATISTICS_PROPERTIES (V ) \
68
67
V (0 , space_size, kSpaceSizeIndex ) \
69
68
V (1 , space_used_size, kSpaceUsedSizeIndex ) \
@@ -85,32 +84,34 @@ static const size_t kHeapCodeStatisticsPropertiesCount =
85
84
HEAP_CODE_STATISTICS_PROPERTIES (V);
86
85
#undef V
87
86
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
- };
87
+ BindingData::BindingData (Environment* env, Local<Object> obj)
88
+ : BaseObject(env, obj),
89
+ heap_statistics_buffer (env->isolate (), kHeapStatisticsPropertiesCount),
90
+ heap_space_statistics_buffer(env->isolate (),
91
+ kHeapSpaceStatisticsPropertiesCount),
92
+ heap_code_statistics_buffer(env->isolate (),
93
+ kHeapCodeStatisticsPropertiesCount) {
94
+ obj->Set (env->context (),
95
+ FIXED_ONE_BYTE_STRING (env->isolate (), " heapStatisticsBuffer" ),
96
+ heap_statistics_buffer.GetJSArray ())
97
+ .Check ();
98
+ obj->Set (env->context (),
99
+ FIXED_ONE_BYTE_STRING (env->isolate (), " heapCodeStatisticsBuffer" ),
100
+ heap_code_statistics_buffer.GetJSArray ())
101
+ .Check ();
102
+ obj->Set (env->context (),
103
+ FIXED_ONE_BYTE_STRING (env->isolate (), " heapSpaceStatisticsBuffer" ),
104
+ heap_space_statistics_buffer.GetJSArray ())
105
+ .Check ();
106
+ }
107
+
108
+ void BindingData::MemoryInfo (MemoryTracker* tracker) const {
109
+ tracker->TrackField (" heap_statistics_buffer" , heap_statistics_buffer);
110
+ tracker->TrackField (" heap_space_statistics_buffer" ,
111
+ heap_space_statistics_buffer);
112
+ tracker->TrackField (" heap_code_statistics_buffer" ,
113
+ heap_code_statistics_buffer);
114
+ }
114
115
115
116
// TODO(addaleax): Remove once we're on C++17.
116
117
constexpr FastStringKey BindingData::type_name;
@@ -179,36 +180,12 @@ void Initialize(Local<Object> target,
179
180
180
181
env->SetMethodNoSideEffect (target, " cachedDataVersionTag" ,
181
182
CachedDataVersionTag);
182
-
183
- // Export symbols used by v8.getHeapStatistics()
184
183
env->SetMethod (
185
184
target, " updateHeapStatisticsBuffer" , UpdateHeapStatisticsBuffer);
186
185
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
186
env->SetMethod (
202
187
target, " updateHeapCodeStatisticsBuffer" , UpdateHeapCodeStatisticsBuffer);
203
188
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
189
size_t number_of_heap_spaces = env->isolate ()->NumberOfHeapSpaces ();
213
190
214
191
// Heap space names are extracted once and exposed to JavaScript to
@@ -230,20 +207,23 @@ void Initialize(Local<Object> target,
230
207
" updateHeapSpaceStatisticsBuffer" ,
231
208
UpdateHeapSpaceStatisticsBuffer);
232
209
233
- target
234
- -> Set (env-> context (),
235
- FIXED_ONE_BYTE_STRING (env->isolate (),
236
- " heapSpaceStatisticsBuffer " ),
237
- binding_data-> heap_space_statistics_buffer . GetJSArray ())
210
+ # define V ( i, _, name ) \
211
+ target \
212
+ -> Set (env->context (), \
213
+ FIXED_ONE_BYTE_STRING (env-> isolate (), #name), \
214
+ Uint32::NewFromUnsigned (env-> isolate (), i)) \
238
215
.Check ();
239
216
217
+ HEAP_STATISTICS_PROPERTIES (V)
218
+ HEAP_CODE_STATISTICS_PROPERTIES (V)
240
219
HEAP_SPACE_STATISTICS_PROPERTIES (V)
241
220
#undef V
242
221
243
222
// Export symbols used by v8.setFlagsFromString()
244
223
env->SetMethod (target, " setFlagsFromString" , SetFlagsFromString);
245
224
}
246
225
226
+ } // namespace v8_utils
247
227
} // namespace node
248
228
249
- NODE_MODULE_CONTEXT_AWARE_INTERNAL (v8, node::Initialize)
229
+ NODE_MODULE_CONTEXT_AWARE_INTERNAL (v8, node::v8_utils:: Initialize)
0 commit comments