The general pattern is that returned MaybeHandles (from any function, not
just JSON::Stringify) are empty when an exception has been thrown by the
operation. You can use a v8::TryCatch to catch this exception and inspect
it, it'll include a helpful error message.


On Tue, Feb 9, 2021 at 1:21 PM 'Vinayaka Kamath' via v8-users <
v8-users@googlegroups.com> wrote:

> Hello All,
>
> A call to JSON::Stringify is returning empty handle. I ensured that the
> parameters are valid. What are the other possible reasons? I tried
> retrieving the "JSON" object from the context using context->Global(), that
> fails and returns empty handle.
>
> bool toJSON(v8::Isolate *isolate, const v8::Local<v8::Value> &object,
> std::string &json) {
>
>    json.clear();
>
>     if (object.IsEmpty()) {    // Object is not empty
>         return true;
>     }
>
>      v8::HandleScope handle_scope(isolate);
>      auto context = isolate->GetCurrentContext();
>       std::cout << "Context: " << context.IsEmpty() << "\n";
>       std::cout << "converting to string \n";
>       v8::Local<v8::Value> result;
>       if (!v8::JSON::Stringify(context, object).ToLocal(&result))      //
> This call is failing
>            return false;
>        json = *v8::String::Utf8Value(isolate, result);
>        std::cout << "done converting to string \n" << json;
>        return true;
> }
>
> Any help would be very much appreciated, thanks!
>
> --
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAKSzg3SbdF-uZFc4uQ1gkA%3DkiAr5gWkeDFk9gahiwmeDc7VUaw%40mail.gmail.com.

Reply via email to