UNPKG

2.91 kBMarkdownView Raw
1## Miscellaneous V8 Helpers
2
3 - <a href="#api_nan_utf8_string"><b><code>Nan::Utf8String</code></b></a>
4 - <a href="#api_nan_get_current_context"><b><code>Nan::GetCurrentContext()</code></b></a>
5 - <a href="#api_nan_set_isolate_data"><b><code>Nan::SetIsolateData()</code></b></a>
6 - <a href="#api_nan_get_isolate_data"><b><code>Nan::GetIsolateData()</code></b></a>
7 - <a href="#api_nan_typedarray_contents"><b><code>Nan::TypedArrayContents</code></b></a>
8
9
10<a name="api_nan_utf8_string"></a>
11### Nan::Utf8String
12
13Converts 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.
14
15An implementation of [`v8::String::Utf8Value`](https://v8docs.nodesource.com/io.js-3.3/d4/d1b/classv8_1_1_string_1_1_utf8_value.html) that is consistent across all supported versions of V8.
16
17Definition:
18
19```c++
20class Nan::Utf8String {
21 public:
22 Nan::Utf8String(v8::Local<v8::Value> from);
23
24 int length() const;
25
26 char* operator*();
27 const char* operator*() const;
28};
29```
30
31<a name="api_nan_get_current_context"></a>
32### Nan::GetCurrentContext()
33
34A call to [`v8::Isolate::GetCurrent()->GetCurrentContext()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a81c7a1ed7001ae2a65e89107f75fd053) that works across all supported versions of V8.
35
36Signature:
37
38```c++
39v8::Local<v8::Context> Nan::GetCurrentContext()
40```
41
42<a name="api_nan_set_isolate_data"></a>
43### Nan::SetIsolateData()
44
45A helper to provide a consistent API to [`v8::Isolate#SetData()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a7acadfe7965997e9c386a05f098fbe36).
46
47Signature:
48
49```c++
50void Nan::SetIsolateData(v8::Isolate *isolate, T *data)
51```
52
53
54<a name="api_nan_get_isolate_data"></a>
55### Nan::GetIsolateData()
56
57A helper to provide a consistent API to [`v8::Isolate#GetData()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#aabd223436bc1100a787dadaa024c6257).
58
59Signature:
60
61```c++
62T *Nan::GetIsolateData(v8::Isolate *isolate)
63```
64
65<a name="api_nan_typedarray_contents"></a>
66### Nan::TypedArrayContents<T>
67
68A 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.
69
70Note that you must store a reference to the `array` object while you are accessing its contents.
71
72Definition:
73
74```c++
75template<typename T>
76class Nan::TypedArrayContents {
77 public:
78 TypedArrayContents(v8::Local<Value> array);
79
80 size_t length() const;
81
82 T* const operator*();
83 const T* const operator*() const;
84};
85```