| 10 | #include <string> |
| 11 | |
| 12 | NAN_METHOD(Stringify) { |
| 13 | if (info.Length() > 0) { |
| 14 | Nan::MaybeLocal<v8::Object> maybe_obj = Nan::To<v8::Object>(info[0]); |
| 15 | if (!maybe_obj.IsEmpty()) { |
| 16 | Nan::JSON NanJSON; |
| 17 | v8::Local<v8::Object> obj = maybe_obj.ToLocalChecked(); |
| 18 | |
| 19 | if (3 == info.Length()) { |
| 20 | if (info[2]->IsNumber()) { |
| 21 | int32_t len = Nan::To<int32_t>(info[2]).FromJust(); |
| 22 | len = (len > 10) ? 10 : len; |
| 23 | len = (len < 0) ? 0 : len; |
| 24 | Nan::MaybeLocal<v8::String> maybe_gap = |
| 25 | Nan::New<v8::String>(std::string(len, ' ')); |
| 26 | |
| 27 | if (!maybe_gap.IsEmpty()) { |
| 28 | v8::Local<v8::String> gap = maybe_gap.ToLocalChecked(); |
| 29 | |
| 30 | Nan::MaybeLocal<v8::String> result = |
| 31 | NanJSON.Stringify(obj, gap); |
| 32 | |
| 33 | if (!result.IsEmpty()) { |
| 34 | info.GetReturnValue().Set(result.ToLocalChecked()); |
| 35 | } |
| 36 | } |
| 37 | } else if (info[2]->IsString()) { |
| 38 | Nan::MaybeLocal<v8::String> result = NanJSON.Stringify( |
| 39 | obj, |
| 40 | Nan::To<v8::String>(info[2]).ToLocalChecked() |
| 41 | ); |
| 42 | |
| 43 | if (!result.IsEmpty()) { |
| 44 | info.GetReturnValue().Set(result.ToLocalChecked()); |
| 45 | } |
| 46 | } else { |
| 47 | Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj); |
| 48 | |
| 49 | if (!result.IsEmpty()) { |
| 50 | info.GetReturnValue().Set(result.ToLocalChecked()); |
| 51 | } |
| 52 | } |
| 53 | } else { |
| 54 | Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj); |
| 55 | |
| 56 | if (!result.IsEmpty()) { |
| 57 | info.GetReturnValue().Set(result.ToLocalChecked()); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | NAN_MODULE_INIT(Init) { |
| 65 | Nan::Set(target |
nothing calls this directly
no test coverage detected