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.

converters.md 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ## Converters
  2. 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.
  3. - <a href="#api_nan_to"><b><code>Nan::To()</code></b></a>
  4. <a name="api_nan_to"></a>
  5. ### Nan::To()
  6. Converts a `v8::Local<v8::Value>` to a different subtype of `v8::Value` or to a native data type. Returns a `Nan::MaybeLocal<>` or a `Nan::Maybe<>` accordingly.
  7. See [maybe_types.md](./maybe_types.md) for more information on `Nan::Maybe` types.
  8. Signatures:
  9. ```c++
  10. // V8 types
  11. Nan::MaybeLocal<v8::Boolean> Nan::To<v8::Boolean>(v8::Local<v8::Value> val);
  12. Nan::MaybeLocal<v8::Int32> Nan::To<v8::Int32>(v8::Local<v8::Value> val);
  13. Nan::MaybeLocal<v8::Integer> Nan::To<v8::Integer>(v8::Local<v8::Value> val);
  14. Nan::MaybeLocal<v8::Object> Nan::To<v8::Object>(v8::Local<v8::Value> val);
  15. Nan::MaybeLocal<v8::Number> Nan::To<v8::Number>(v8::Local<v8::Value> val);
  16. Nan::MaybeLocal<v8::String> Nan::To<v8::String>(v8::Local<v8::Value> val);
  17. Nan::MaybeLocal<v8::Uint32> Nan::To<v8::Uint32>(v8::Local<v8::Value> val);
  18. // Native types
  19. Nan::Maybe<bool> Nan::To<bool>(v8::Local<v8::Value> val);
  20. Nan::Maybe<double> Nan::To<double>(v8::Local<v8::Value> val);
  21. Nan::Maybe<int32_t> Nan::To<int32_t>(v8::Local<v8::Value> val);
  22. Nan::Maybe<int64_t> Nan::To<int64_t>(v8::Local<v8::Value> val);
  23. Nan::Maybe<uint32_t> Nan::To<uint32_t>(v8::Local<v8::Value> val);
  24. ```
  25. ### Example
  26. ```c++
  27. v8::Local<v8::Value> val;
  28. Nan::MaybeLocal<v8::String> str = Nan::To<v8::String>(val);
  29. Nan::Maybe<double> d = Nan::To<double>(val);
  30. ```