lepu-test-platform-web/node_modules/nan/doc/v8_misc.md

2.8 KiB

Miscellaneous V8 Helpers

Nan::Utf8String

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.

An implementation of v8::String::Utf8Value that is consistent across all supported versions of V8.

Definition:

class Nan::Utf8String {
 public:
  Nan::Utf8String(v8::Local<v8::Value> from);

  int length() const;

  char* operator*();
  const char* operator*() const;
};

Nan::GetCurrentContext()

A call to v8::Isolate::GetCurrent()->GetCurrentContext() that works across all supported versions of V8.

Signature:

v8::Local<v8::Context> Nan::GetCurrentContext()

Nan::SetIsolateData()

A helper to provide a consistent API to v8::Isolate#SetData().

Signature:

void Nan::SetIsolateData(v8::Isolate *isolate, T *data)

Nan::GetIsolateData()

A helper to provide a consistent API to v8::Isolate#GetData().

Signature:

T *Nan::GetIsolateData(v8::Isolate *isolate)

Nan::TypedArrayContents

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.

Note that you must store a reference to the array object while you are accessing its contents.

Definition:

template<typename T>
class Nan::TypedArrayContents {
 public:
  TypedArrayContents(v8::Local<Value> array);

  size_t length() const;

  T* const operator*();
  const T* const operator*() const;
};