All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.doc.converters.md Maven / Gradle / Ivy

Go to download

Native Abstractions for Node.js: C++ header for Node 0.8 -> 18 compatibility

There is a newer version: 2.19.0
Show newest version
## Converters

NAN contains functions that convert `v8::Value`s to other `v8::Value` types and native types. Since type conversion is not guaranteed to succeed, they return `Nan::Maybe` types. These converters can be used in place of `value->ToX()` and `value->XValue()` (where `X` is one of the types, e.g. `Boolean`) in a way that provides a consistent interface across V8 versions. Newer versions of V8 use the new `v8::Maybe` and `v8::MaybeLocal` types for these conversions, older versions don't have this functionality so it is provided by NAN.

 - Nan::To()


### Nan::To()

Converts a `v8::Local` to a different subtype of `v8::Value` or to a native data type. Returns a `Nan::MaybeLocal<>` or a `Nan::Maybe<>` accordingly.

See [maybe_types.md](./maybe_types.md) for more information on `Nan::Maybe` types.

Signatures:

```c++
// V8 types
Nan::MaybeLocal Nan::To(v8::Local val);
Nan::MaybeLocal Nan::To(v8::Local val);
Nan::MaybeLocal Nan::To(v8::Local val);
Nan::MaybeLocal Nan::To(v8::Local val);
Nan::MaybeLocal Nan::To(v8::Local val);
Nan::MaybeLocal Nan::To(v8::Local val);
Nan::MaybeLocal Nan::To(v8::Local val);

// Native types
Nan::Maybe Nan::To(v8::Local val);
Nan::Maybe Nan::To(v8::Local val);
Nan::Maybe Nan::To(v8::Local val);
Nan::Maybe Nan::To(v8::Local val);
Nan::Maybe Nan::To(v8::Local val);
```

### Example

```c++
v8::Local val;
Nan::MaybeLocal str = Nan::To(val);
Nan::Maybe d = Nan::To(val);
```





© 2015 - 2024 Weber Informatics LLC | Privacy Policy