Return Boolean value in node c++ addon

560 Views Asked by At

In Node C++ Addon, I can return a String like this:

void Method(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();  
  args.GetReturnValue().Set(
    String::NewFromUtf8(isolate, "hello")
      .ToLocalChecked()
  );
}

How can I achieve the same but setting a boolean value instead of a string?

1

There are 1 best solutions below

0
On

Thanks to @UnholySheep for providing links to the V8 docs.

args.GetReturnValue().Set() has an overload the accepts a bool, so you can just pass it directly.

void Method(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();  
  args.GetReturnValue().Set(true);
}