Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v8_internals.md 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ## V8 internals
  2. 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.
  3. - <a href="#api_nan_gc_callback"><b><code>NAN_GC_CALLBACK()</code></b></a>
  4. - <a href="#api_nan_add_gc_epilogue_callback"><b><code>Nan::AddGCEpilogueCallback()</code></b></a>
  5. - <a href="#api_nan_remove_gc_epilogue_callback"><b><code>Nan::RemoveGCEpilogueCallback()</code></b></a>
  6. - <a href="#api_nan_add_gc_prologue_callback"><b><code>Nan::AddGCPrologueCallback()</code></b></a>
  7. - <a href="#api_nan_remove_gc_prologue_callback"><b><code>Nan::RemoveGCPrologueCallback()</code></b></a>
  8. - <a href="#api_nan_get_heap_statistics"><b><code>Nan::GetHeapStatistics()</code></b></a>
  9. - <a href="#api_nan_set_counter_function"><b><code>Nan::SetCounterFunction()</code></b></a>
  10. - <a href="#api_nan_set_create_histogram_function"><b><code>Nan::SetCreateHistogramFunction()</code></b></a>
  11. - <a href="#api_nan_set_add_histogram_sample_function"><b><code>Nan::SetAddHistogramSampleFunction()</code></b></a>
  12. - <a href="#api_nan_idle_notification"><b><code>Nan::IdleNotification()</code></b></a>
  13. - <a href="#api_nan_low_memory_notification"><b><code>Nan::LowMemoryNotification()</code></b></a>
  14. - <a href="#api_nan_context_disposed_notification"><b><code>Nan::ContextDisposedNotification()</code></b></a>
  15. - <a href="#api_nan_get_internal_field_pointer"><b><code>Nan::GetInternalFieldPointer()</code></b></a>
  16. - <a href="#api_nan_set_internal_field_pointer"><b><code>Nan::SetInternalFieldPointer()</code></b></a>
  17. - <a href="#api_nan_adjust_external_memory"><b><code>Nan::AdjustExternalMemory()</code></b></a>
  18. <a name="api_nan_gc_callback"></a>
  19. ### NAN_GC_CALLBACK(callbackname)
  20. 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`.
  21. ```c++
  22. static Nan::Persistent<Function> callback;
  23. NAN_GC_CALLBACK(gcPrologueCallback) {
  24. v8::Local<Value> argv[] = { Nan::New("prologue").ToLocalChecked() };
  25. Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(callback), 1, argv);
  26. }
  27. NAN_METHOD(Hook) {
  28. callback.Reset(To<Function>(args[0]).ToLocalChecked());
  29. Nan::AddGCPrologueCallback(gcPrologueCallback);
  30. info.GetReturnValue().Set(info.Holder());
  31. }
  32. ```
  33. <a name="api_nan_add_gc_epilogue_callback"></a>
  34. ### Nan::AddGCEpilogueCallback()
  35. Signature:
  36. ```c++
  37. void Nan::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, v8::GCType gc_type_filter = v8::kGCTypeAll)
  38. ```
  39. Calls V8's [`AddGCEpilogueCallback()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a580f976e4290cead62c2fc4dd396be3e).
  40. <a name="api_nan_remove_gc_epilogue_callback"></a>
  41. ### Nan::RemoveGCEpilogueCallback()
  42. Signature:
  43. ```c++
  44. void Nan::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback)
  45. ```
  46. Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#adca9294555a3908e9f23c7bb0f0f284c).
  47. <a name="api_nan_add_gc_prologue_callback"></a>
  48. ### Nan::AddGCPrologueCallback()
  49. Signature:
  50. ```c++
  51. void Nan::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback, v8::GCType gc_type_filter callback)
  52. ```
  53. Calls V8's [`AddGCPrologueCallback()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a6dbef303603ebdb03da6998794ea05b8).
  54. <a name="api_nan_remove_gc_prologue_callback"></a>
  55. ### Nan::RemoveGCPrologueCallback()
  56. Signature:
  57. ```c++
  58. void Nan::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback)
  59. ```
  60. Calls V8's [`RemoveGCPrologueCallback()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a5f72c7cda21415ce062bbe5c58abe09e).
  61. <a name="api_nan_get_heap_statistics"></a>
  62. ### Nan::GetHeapStatistics()
  63. Signature:
  64. ```c++
  65. void Nan::GetHeapStatistics(v8::HeapStatistics *heap_statistics)
  66. ```
  67. Calls V8's [`GetHeapStatistics()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a5593ac74687b713095c38987e5950b34).
  68. <a name="api_nan_set_counter_function"></a>
  69. ### Nan::SetCounterFunction()
  70. Signature:
  71. ```c++
  72. void Nan::SetCounterFunction(v8::CounterLookupCallback cb)
  73. ```
  74. Calls V8's [`SetCounterFunction()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a045d7754e62fa0ec72ae6c259b29af94).
  75. <a name="api_nan_set_create_histogram_function"></a>
  76. ### Nan::SetCreateHistogramFunction()
  77. Signature:
  78. ```c++
  79. void Nan::SetCreateHistogramFunction(v8::CreateHistogramCallback cb)
  80. ```
  81. Calls V8's [`SetCreateHistogramFunction()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a542d67e85089cb3f92aadf032f99e732).
  82. <a name="api_nan_set_add_histogram_sample_function"></a>
  83. ### Nan::SetAddHistogramSampleFunction()
  84. Signature:
  85. ```c++
  86. void Nan::SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb)
  87. ```
  88. Calls V8's [`SetAddHistogramSampleFunction()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#aeb420b690bc2c216882d6fdd00ddd3ea).
  89. <a name="api_nan_idle_notification"></a>
  90. ### Nan::IdleNotification()
  91. Signature:
  92. ```c++
  93. bool Nan::IdleNotification(int idle_time_in_ms)
  94. ```
  95. Calls V8's [`IdleNotification()` or `IdleNotificationDeadline()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#ad6a2a02657f5425ad460060652a5a118) depending on V8 version.
  96. <a name="api_nan_low_memory_notification"></a>
  97. ### Nan::LowMemoryNotification()
  98. Signature:
  99. ```c++
  100. void Nan::LowMemoryNotification()
  101. ```
  102. Calls V8's [`LowMemoryNotification()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a24647f61d6b41f69668094bdcd6ea91f).
  103. <a name="api_nan_context_disposed_notification"></a>
  104. ### Nan::ContextDisposedNotification()
  105. Signature:
  106. ```c++
  107. void Nan::ContextDisposedNotification()
  108. ```
  109. Calls V8's [`ContextDisposedNotification()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b).
  110. <a name="api_nan_get_internal_field_pointer"></a>
  111. ### Nan::GetInternalFieldPointer()
  112. Gets a pointer to the internal field with at `index` from a V8 `Object` handle.
  113. Signature:
  114. ```c++
  115. void* Nan::GetInternalFieldPointer(v8::Local<v8::Object> object, int index)
  116. ```
  117. Calls the Object's [`GetAlignedPointerFromInternalField()` or `GetPointerFromInternalField()`](https://v8docs.nodesource.com/node-8.11/db/d85/classv8_1_1_object.html#a580ea84afb26c005d6762eeb9e3c308f) depending on the version of V8.
  118. <a name="api_nan_set_internal_field_pointer"></a>
  119. ### Nan::SetInternalFieldPointer()
  120. Sets the value of the internal field at `index` on a V8 `Object` handle.
  121. Signature:
  122. ```c++
  123. void Nan::SetInternalFieldPointer(v8::Local<v8::Object> object, int index, void* value)
  124. ```
  125. Calls the Object's [`SetAlignedPointerInInternalField()` or `SetPointerInInternalField()`](https://v8docs.nodesource.com/node-8.11/db/d85/classv8_1_1_object.html#ab3c57184263cf29963ef0017bec82281) depending on the version of V8.
  126. <a name="api_nan_adjust_external_memory"></a>
  127. ### Nan::AdjustExternalMemory()
  128. Signature:
  129. ```c++
  130. int Nan::AdjustExternalMemory(int bytesChange)
  131. ```
  132. Calls V8's [`AdjustAmountOfExternalAllocatedMemory()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#ae1a59cac60409d3922582c4af675473e).