| 14 |
liveuser |
1 |
## V8 internals
|
|
|
2 |
|
|
|
3 |
The hooks to access V8 internals—including GC and statistics—are different across the supported versions of V8, therefore NAN provides its own hooks that call the appropriate V8 methods.
|
|
|
4 |
|
|
|
5 |
- <a href="#api_nan_gc_callback"><b><code>NAN_GC_CALLBACK()</code></b></a>
|
|
|
6 |
- <a href="#api_nan_add_gc_epilogue_callback"><b><code>Nan::AddGCEpilogueCallback()</code></b></a>
|
|
|
7 |
- <a href="#api_nan_remove_gc_epilogue_callback"><b><code>Nan::RemoveGCEpilogueCallback()</code></b></a>
|
|
|
8 |
- <a href="#api_nan_add_gc_prologue_callback"><b><code>Nan::AddGCPrologueCallback()</code></b></a>
|
|
|
9 |
- <a href="#api_nan_remove_gc_prologue_callback"><b><code>Nan::RemoveGCPrologueCallback()</code></b></a>
|
|
|
10 |
- <a href="#api_nan_get_heap_statistics"><b><code>Nan::GetHeapStatistics()</code></b></a>
|
|
|
11 |
- <a href="#api_nan_set_counter_function"><b><code>Nan::SetCounterFunction()</code></b></a>
|
|
|
12 |
- <a href="#api_nan_set_create_histogram_function"><b><code>Nan::SetCreateHistogramFunction()</code></b></a>
|
|
|
13 |
- <a href="#api_nan_set_add_histogram_sample_function"><b><code>Nan::SetAddHistogramSampleFunction()</code></b></a>
|
|
|
14 |
- <a href="#api_nan_idle_notification"><b><code>Nan::IdleNotification()</code></b></a>
|
|
|
15 |
- <a href="#api_nan_low_memory_notification"><b><code>Nan::LowMemoryNotification()</code></b></a>
|
|
|
16 |
- <a href="#api_nan_context_disposed_notification"><b><code>Nan::ContextDisposedNotification()</code></b></a>
|
|
|
17 |
- <a href="#api_nan_get_internal_field_pointer"><b><code>Nan::GetInternalFieldPointer()</code></b></a>
|
|
|
18 |
- <a href="#api_nan_set_internal_field_pointer"><b><code>Nan::SetInternalFieldPointer()</code></b></a>
|
|
|
19 |
- <a href="#api_nan_adjust_external_memory"><b><code>Nan::AdjustExternalMemory()</code></b></a>
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
<a name="api_nan_gc_callback"></a>
|
|
|
23 |
### NAN_GC_CALLBACK(callbackname)
|
|
|
24 |
|
|
|
25 |
Use `NAN_GC_CALLBACK` to declare your callbacks for `Nan::AddGCPrologueCallback()` and `Nan::AddGCEpilogueCallback()`. Your new method receives the arguments `v8::GCType type` and `v8::GCCallbackFlags flags`.
|
|
|
26 |
|
|
|
27 |
```c++
|
|
|
28 |
static Nan::Persistent<Function> callback;
|
|
|
29 |
|
|
|
30 |
NAN_GC_CALLBACK(gcPrologueCallback) {
|
|
|
31 |
v8::Local<Value> argv[] = { Nan::New("prologue").ToLocalChecked() };
|
|
|
32 |
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(callback), 1, argv);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
NAN_METHOD(Hook) {
|
|
|
36 |
callback.Reset(args[0].As<Function>());
|
|
|
37 |
Nan::AddGCPrologueCallback(gcPrologueCallback);
|
|
|
38 |
info.GetReturnValue().Set(info.Holder());
|
|
|
39 |
}
|
|
|
40 |
```
|
|
|
41 |
|
|
|
42 |
<a name="api_nan_add_gc_epilogue_callback"></a>
|
|
|
43 |
### Nan::AddGCEpilogueCallback()
|
|
|
44 |
|
|
|
45 |
Signature:
|
|
|
46 |
|
|
|
47 |
```c++
|
|
|
48 |
void Nan::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, v8::GCType gc_type_filter = v8::kGCTypeAll)
|
|
|
49 |
```
|
|
|
50 |
|
|
|
51 |
Calls V8's [`AddGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a90d1860babc76059c62514b422f56960).
|
|
|
52 |
|
|
|
53 |
<a name="api_nan_remove_gc_epilogue_callback"></a>
|
|
|
54 |
### Nan::RemoveGCEpilogueCallback()
|
|
|
55 |
|
|
|
56 |
Signature:
|
|
|
57 |
|
|
|
58 |
```c++
|
|
|
59 |
void Nan::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback)
|
|
|
60 |
```
|
|
|
61 |
|
|
|
62 |
Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a05c60859fd4b8e96bfcd451281ed6c7c).
|
|
|
63 |
|
|
|
64 |
<a name="api_nan_add_gc_prologue_callback"></a>
|
|
|
65 |
### Nan::AddGCPrologueCallback()
|
|
|
66 |
|
|
|
67 |
Signature:
|
|
|
68 |
|
|
|
69 |
```c++
|
|
|
70 |
void Nan::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback, v8::GCType gc_type_filter callback)
|
|
|
71 |
```
|
|
|
72 |
|
|
|
73 |
Calls V8's [`AddGCPrologueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ab4b87b8f9f8e5bf95eba4009357e001f).
|
|
|
74 |
|
|
|
75 |
<a name="api_nan_remove_gc_prologue_callback"></a>
|
|
|
76 |
### Nan::RemoveGCPrologueCallback()
|
|
|
77 |
|
|
|
78 |
Signature:
|
|
|
79 |
|
|
|
80 |
```c++
|
|
|
81 |
void Nan::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback)
|
|
|
82 |
```
|
|
|
83 |
|
|
|
84 |
Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a9f6c51932811593f81ff30b949124186).
|
|
|
85 |
|
|
|
86 |
<a name="api_nan_get_heap_statistics"></a>
|
|
|
87 |
### Nan::GetHeapStatistics()
|
|
|
88 |
|
|
|
89 |
Signature:
|
|
|
90 |
|
|
|
91 |
```c++
|
|
|
92 |
void Nan::GetHeapStatistics(v8::HeapStatistics *heap_statistics)
|
|
|
93 |
```
|
|
|
94 |
|
|
|
95 |
Calls V8's [`GetHeapStatistics()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a5593ac74687b713095c38987e5950b34).
|
|
|
96 |
|
|
|
97 |
<a name="api_nan_set_counter_function"></a>
|
|
|
98 |
### Nan::SetCounterFunction()
|
|
|
99 |
|
|
|
100 |
Signature:
|
|
|
101 |
|
|
|
102 |
```c++
|
|
|
103 |
void Nan::SetCounterFunction(v8::CounterLookupCallback cb)
|
|
|
104 |
```
|
|
|
105 |
|
|
|
106 |
Calls V8's [`SetCounterFunction()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a045d7754e62fa0ec72ae6c259b29af94).
|
|
|
107 |
|
|
|
108 |
<a name="api_nan_set_create_histogram_function"></a>
|
|
|
109 |
### Nan::SetCreateHistogramFunction()
|
|
|
110 |
|
|
|
111 |
Signature:
|
|
|
112 |
|
|
|
113 |
```c++
|
|
|
114 |
void Nan::SetCreateHistogramFunction(v8::CreateHistogramCallback cb)
|
|
|
115 |
```
|
|
|
116 |
|
|
|
117 |
Calls V8's [`SetCreateHistogramFunction()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a542d67e85089cb3f92aadf032f99e732).
|
|
|
118 |
|
|
|
119 |
<a name="api_nan_set_add_histogram_sample_function"></a>
|
|
|
120 |
### Nan::SetAddHistogramSampleFunction()
|
|
|
121 |
|
|
|
122 |
Signature:
|
|
|
123 |
|
|
|
124 |
```c++
|
|
|
125 |
void Nan::SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb)
|
|
|
126 |
```
|
|
|
127 |
|
|
|
128 |
Calls V8's [`SetAddHistogramSampleFunction()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#aeb420b690bc2c216882d6fdd00ddd3ea).
|
|
|
129 |
|
|
|
130 |
<a name="api_nan_idle_notification"></a>
|
|
|
131 |
### Nan::IdleNotification()
|
|
|
132 |
|
|
|
133 |
Signature:
|
|
|
134 |
|
|
|
135 |
```c++
|
|
|
136 |
void Nan::IdleNotification(v8::HeapStatistics *heap_statistics)
|
|
|
137 |
```
|
|
|
138 |
|
|
|
139 |
Calls V8's [`IdleNotification()` or `IdleNotificationDeadline()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ad6a2a02657f5425ad460060652a5a118) depending on V8 version.
|
|
|
140 |
|
|
|
141 |
<a name="api_nan_low_memory_notification"></a>
|
|
|
142 |
### Nan::LowMemoryNotification()
|
|
|
143 |
|
|
|
144 |
Signature:
|
|
|
145 |
|
|
|
146 |
```c++
|
|
|
147 |
void Nan::LowMemoryNotification()
|
|
|
148 |
```
|
|
|
149 |
|
|
|
150 |
Calls V8's [`IdleNotification()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#a24647f61d6b41f69668094bdcd6ea91f).
|
|
|
151 |
|
|
|
152 |
<a name="api_nan_context_disposed_notification"></a>
|
|
|
153 |
### Nan::ContextDisposedNotification()
|
|
|
154 |
|
|
|
155 |
Signature:
|
|
|
156 |
|
|
|
157 |
```c++
|
|
|
158 |
void Nan::ContextDisposedNotification()
|
|
|
159 |
```
|
|
|
160 |
|
|
|
161 |
Calls V8's [`ContextDisposedNotification()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b).
|
|
|
162 |
|
|
|
163 |
<a name="api_nan_get_internal_field_pointer"></a>
|
|
|
164 |
### Nan::GetInternalFieldPointer()
|
|
|
165 |
|
|
|
166 |
Gets a pointer to the internal field with at `index` from a V8 `Object` handle.
|
|
|
167 |
|
|
|
168 |
Signature:
|
|
|
169 |
|
|
|
170 |
```c++
|
|
|
171 |
void* Nan::GetInternalFieldPointer(v8::Local<v8::Object> object, int index)
|
|
|
172 |
```
|
|
|
173 |
|
|
|
174 |
Calls the Object's [`GetAlignedPointerFromInternalField()` or `GetPointerFromInternalField()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#ab3c57184263cf29963ef0017bec82281) depending on the version of V8.
|
|
|
175 |
|
|
|
176 |
<a name="api_nan_set_internal_field_pointer"></a>
|
|
|
177 |
### Nan::SetInternalFieldPointer()
|
|
|
178 |
|
|
|
179 |
Sets the value of the internal field at `index` on a V8 `Object` handle.
|
|
|
180 |
|
|
|
181 |
Signature:
|
|
|
182 |
|
|
|
183 |
```c++
|
|
|
184 |
void Nan::SetInternalFieldPointer(v8::Local<v8::Object> object, int index, void* value)
|
|
|
185 |
```
|
|
|
186 |
|
|
|
187 |
Calls the Object's [`SetAlignedPointerInInternalField()` or `SetPointerInInternalField()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b) depending on the version of V8.
|
|
|
188 |
|
|
|
189 |
<a name="api_nan_adjust_external_memory"></a>
|
|
|
190 |
### Nan::AdjustExternalMemory()
|
|
|
191 |
|
|
|
192 |
Signature:
|
|
|
193 |
|
|
|
194 |
```c++
|
|
|
195 |
int Nan::AdjustExternalMemory(int bytesChange)
|
|
|
196 |
```
|
|
|
197 |
|
|
|
198 |
Calls V8's [`AdjustAmountOfExternalAllocatedMemory()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ae1a59cac60409d3922582c4af675473e).
|
|
|
199 |
|