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_misc.md 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ## Miscellaneous V8 Helpers
  2. - <a href="#api_nan_utf8_string"><b><code>Nan::Utf8String</code></b></a>
  3. - <a href="#api_nan_get_current_context"><b><code>Nan::GetCurrentContext()</code></b></a>
  4. - <a href="#api_nan_set_isolate_data"><b><code>Nan::SetIsolateData()</code></b></a>
  5. - <a href="#api_nan_get_isolate_data"><b><code>Nan::GetIsolateData()</code></b></a>
  6. - <a href="#api_nan_typedarray_contents"><b><code>Nan::TypedArrayContents</code></b></a>
  7. <a name="api_nan_utf8_string"></a>
  8. ### Nan::Utf8String
  9. Converts an object to a UTF-8-encoded character array. If conversion to a string fails (e.g. due to an exception in the toString() method of the object) then the length() method returns 0 and the * operator returns NULL. The underlying memory used for this object is managed by the object.
  10. An implementation of [`v8::String::Utf8Value`](https://v8docs.nodesource.com/node-8.11/d4/d1b/classv8_1_1_string_1_1_utf8_value.html) that is consistent across all supported versions of V8.
  11. Definition:
  12. ```c++
  13. class Nan::Utf8String {
  14. public:
  15. Nan::Utf8String(v8::Local<v8::Value> from);
  16. int length() const;
  17. char* operator*();
  18. const char* operator*() const;
  19. };
  20. ```
  21. <a name="api_nan_get_current_context"></a>
  22. ### Nan::GetCurrentContext()
  23. A call to [`v8::Isolate::GetCurrent()->GetCurrentContext()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a81c7a1ed7001ae2a65e89107f75fd053) that works across all supported versions of V8.
  24. Signature:
  25. ```c++
  26. v8::Local<v8::Context> Nan::GetCurrentContext()
  27. ```
  28. <a name="api_nan_set_isolate_data"></a>
  29. ### Nan::SetIsolateData()
  30. A helper to provide a consistent API to [`v8::Isolate#SetData()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#a7acadfe7965997e9c386a05f098fbe36).
  31. Signature:
  32. ```c++
  33. void Nan::SetIsolateData(v8::Isolate *isolate, T *data)
  34. ```
  35. <a name="api_nan_get_isolate_data"></a>
  36. ### Nan::GetIsolateData()
  37. A helper to provide a consistent API to [`v8::Isolate#GetData()`](https://v8docs.nodesource.com/node-8.11/d5/dda/classv8_1_1_isolate.html#aabd223436bc1100a787dadaa024c6257).
  38. Signature:
  39. ```c++
  40. T *Nan::GetIsolateData(v8::Isolate *isolate)
  41. ```
  42. <a name="api_nan_typedarray_contents"></a>
  43. ### Nan::TypedArrayContents<T>
  44. A helper class for accessing the contents of an ArrayBufferView (aka a typedarray) from C++. If the input array is not a valid typedarray, then the data pointer of TypedArrayContents will default to `NULL` and the length will be 0. If the data pointer is not compatible with the alignment requirements of type, an assertion error will fail.
  45. Note that you must store a reference to the `array` object while you are accessing its contents.
  46. Definition:
  47. ```c++
  48. template<typename T>
  49. class Nan::TypedArrayContents {
  50. public:
  51. TypedArrayContents(v8::Local<Value> array);
  52. size_t length() const;
  53. T* const operator*();
  54. const T* const operator*() const;
  55. };
  56. ```