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.

callback.md 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ## Nan::Callback
  2. `Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution.
  3. - <a href="#api_nan_callback"><b><code>Nan::Callback</code></b></a>
  4. <a name="api_nan_callback"></a>
  5. ### Nan::Callback
  6. ```c++
  7. class Callback {
  8. public:
  9. Callback();
  10. explicit Callback(const v8::Local<v8::Function> &fn);
  11. ~Callback();
  12. bool operator==(const Callback &other) const;
  13. bool operator!=(const Callback &other) const;
  14. v8::Local<v8::Function> operator*() const;
  15. MaybeLocal<v8::Value> operator()(AsyncResource* async_resource,
  16. v8::Local<v8::Object> target,
  17. int argc = 0,
  18. v8::Local<v8::Value> argv[] = 0) const;
  19. MaybeLocal<v8::Value> operator()(AsyncResource* async_resource,
  20. int argc = 0,
  21. v8::Local<v8::Value> argv[] = 0) const;
  22. void SetFunction(const v8::Local<v8::Function> &fn);
  23. v8::Local<v8::Function> GetFunction() const;
  24. bool IsEmpty() const;
  25. void Reset(const v8::Local<v8::Function> &fn);
  26. void Reset();
  27. MaybeLocal<v8::Value> Call(v8::Local<v8::Object> target,
  28. int argc,
  29. v8::Local<v8::Value> argv[],
  30. AsyncResource* async_resource) const;
  31. MaybeLocal<v8::Value> Call(int argc,
  32. v8::Local<v8::Value> argv[],
  33. AsyncResource* async_resource) const;
  34. // Deprecated versions. Use the versions that accept an async_resource instead
  35. // as they run the callback in the correct async context as specified by the
  36. // resource. If you want to call a synchronous JS function (i.e. on a
  37. // non-empty JS stack), you can use Nan::Call instead.
  38. v8::Local<v8::Value> operator()(v8::Local<v8::Object> target,
  39. int argc = 0,
  40. v8::Local<v8::Value> argv[] = 0) const;
  41. v8::Local<v8::Value> operator()(int argc = 0,
  42. v8::Local<v8::Value> argv[] = 0) const;
  43. v8::Local<v8::Value> Call(v8::Local<v8::Object> target,
  44. int argc,
  45. v8::Local<v8::Value> argv[]) const;
  46. v8::Local<v8::Value> Call(int argc, v8::Local<v8::Value> argv[]) const;
  47. };
  48. ```
  49. Example usage:
  50. ```c++
  51. v8::Local<v8::Function> function;
  52. Nan::Callback callback(function);
  53. callback.Call(0, 0);
  54. ```