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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ## New
  2. NAN provides a `Nan::New()` helper for the creation of new JavaScript objects in a way that's compatible across the supported versions of V8.
  3. - <a href="#api_nan_new"><b><code>Nan::New()</code></b></a>
  4. - <a href="#api_nan_undefined"><b><code>Nan::Undefined()</code></b></a>
  5. - <a href="#api_nan_null"><b><code>Nan::Null()</code></b></a>
  6. - <a href="#api_nan_true"><b><code>Nan::True()</code></b></a>
  7. - <a href="#api_nan_false"><b><code>Nan::False()</code></b></a>
  8. - <a href="#api_nan_empty_string"><b><code>Nan::EmptyString()</code></b></a>
  9. <a name="api_nan_new"></a>
  10. ### Nan::New()
  11. `Nan::New()` should be used to instantiate new JavaScript objects.
  12. Refer to the specific V8 type in the [V8 documentation](https://v8docs.nodesource.com/node-8.11/d1/d83/classv8_1_1_data.html) for information on the types of arguments required for instantiation.
  13. Signatures:
  14. Return types are mostly omitted from the signatures for simplicity. In most cases the type will be contained within a `v8::Local<T>`. The following types will be contained within a `Nan::MaybeLocal<T>`: `v8::String`, `v8::Date`, `v8::RegExp`, `v8::Script`, `v8::UnboundScript`.
  15. Empty objects:
  16. ```c++
  17. Nan::New<T>();
  18. ```
  19. Generic single and multiple-argument:
  20. ```c++
  21. Nan::New<T>(A0 arg0);
  22. Nan::New<T>(A0 arg0, A1 arg1);
  23. Nan::New<T>(A0 arg0, A1 arg1, A2 arg2);
  24. Nan::New<T>(A0 arg0, A1 arg1, A2 arg2, A3 arg3);
  25. ```
  26. For creating `v8::FunctionTemplate` and `v8::Function` objects:
  27. _The definition of `Nan::FunctionCallback` can be found in the [Method declaration](./methods.md#api_nan_method) documentation._
  28. ```c++
  29. Nan::New<T>(Nan::FunctionCallback callback,
  30. v8::Local<v8::Value> data = v8::Local<v8::Value>());
  31. Nan::New<T>(Nan::FunctionCallback callback,
  32. v8::Local<v8::Value> data = v8::Local<v8::Value>(),
  33. A2 a2 = A2());
  34. ```
  35. Native number types:
  36. ```c++
  37. v8::Local<v8::Boolean> Nan::New<T>(bool value);
  38. v8::Local<v8::Int32> Nan::New<T>(int32_t value);
  39. v8::Local<v8::Uint32> Nan::New<T>(uint32_t value);
  40. v8::Local<v8::Number> Nan::New<T>(double value);
  41. ```
  42. String types:
  43. ```c++
  44. Nan::MaybeLocal<v8::String> Nan::New<T>(std::string const& value);
  45. Nan::MaybeLocal<v8::String> Nan::New<T>(const char * value, int length);
  46. Nan::MaybeLocal<v8::String> Nan::New<T>(const char * value);
  47. Nan::MaybeLocal<v8::String> Nan::New<T>(const uint16_t * value);
  48. Nan::MaybeLocal<v8::String> Nan::New<T>(const uint16_t * value, int length);
  49. ```
  50. Specialized types:
  51. ```c++
  52. v8::Local<v8::String> Nan::New<T>(v8::String::ExternalStringResource * value);
  53. v8::Local<v8::String> Nan::New<T>(Nan::ExternalOneByteStringResource * value);
  54. v8::Local<v8::RegExp> Nan::New<T>(v8::Local<v8::String> pattern, v8::RegExp::Flags flags);
  55. ```
  56. Note that `Nan::ExternalOneByteStringResource` maps to [`v8::String::ExternalOneByteStringResource`](https://v8docs.nodesource.com/node-8.11/d9/db3/classv8_1_1_string_1_1_external_one_byte_string_resource.html), and `v8::String::ExternalAsciiStringResource` in older versions of V8.
  57. <a name="api_nan_undefined"></a>
  58. ### Nan::Undefined()
  59. A helper method to reference the `v8::Undefined` object in a way that is compatible across all supported versions of V8.
  60. Signature:
  61. ```c++
  62. v8::Local<v8::Primitive> Nan::Undefined()
  63. ```
  64. <a name="api_nan_null"></a>
  65. ### Nan::Null()
  66. A helper method to reference the `v8::Null` object in a way that is compatible across all supported versions of V8.
  67. Signature:
  68. ```c++
  69. v8::Local<v8::Primitive> Nan::Null()
  70. ```
  71. <a name="api_nan_true"></a>
  72. ### Nan::True()
  73. A helper method to reference the `v8::Boolean` object representing the `true` value in a way that is compatible across all supported versions of V8.
  74. Signature:
  75. ```c++
  76. v8::Local<v8::Boolean> Nan::True()
  77. ```
  78. <a name="api_nan_false"></a>
  79. ### Nan::False()
  80. A helper method to reference the `v8::Boolean` object representing the `false` value in a way that is compatible across all supported versions of V8.
  81. Signature:
  82. ```c++
  83. v8::Local<v8::Boolean> Nan::False()
  84. ```
  85. <a name="api_nan_empty_string"></a>
  86. ### Nan::EmptyString()
  87. Call [`v8::String::Empty`](https://v8docs.nodesource.com/node-8.11/d2/db3/classv8_1_1_string.html#a7c1bc8886115d7ee46f1d571dd6ebc6d) to reference the empty string in a way that is compatible across all supported versions of V8.
  88. Signature:
  89. ```c++
  90. v8::Local<v8::String> Nan::EmptyString()
  91. ```
  92. <a name="api_nan_new_one_byte_string"></a>
  93. ### Nan::NewOneByteString()
  94. An implementation of [`v8::String::NewFromOneByte()`](https://v8docs.nodesource.com/node-8.11/d2/db3/classv8_1_1_string.html#a5264d50b96d2c896ce525a734dc10f09) provided for consistent availability and API across supported versions of V8. Allocates a new string from Latin-1 data.
  95. Signature:
  96. ```c++
  97. Nan::MaybeLocal<v8::String> Nan::NewOneByteString(const uint8_t * value,
  98. int length = -1)
  99. ```