Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. // loop_addon.cc
  2. #include <node.h>
  3.  
  4. namespace loop_addon {
  5.  
  6. using v8::Exception;
  7. using v8::FunctionCallbackInfo;
  8. using v8::Isolate;
  9. using v8::Local;
  10. using v8::Number;
  11. using v8::Object;
  12. using v8::String;
  13. using v8::Value;
  14.  
  15. void loopPerformance(const FunctionCallbackInfo<Value> &args) {
  16. Isolate *isolate = args.GetIsolate();
  17. long int totalSum = 0;
  18. int rawNumber = args[0]->NumberValue(); // Get function call arguments.
  19.  
  20. while (rawNumber > 0) {
  21. totalSum += 1;
  22. rawNumber--;
  23. }
  24.  
  25. args.GetReturnValue().Set(Number::New(isolate, totalSum)); // Send response to JavaScript
  26. }
  27.  
  28. void init(Local<Object> exports) {
  29. NODE_SET_METHOD(exports, "sumNow", loopPerformance);
  30. }
  31.  
  32. NODE_MODULE(loop_addon, init)
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement