MCPcopy Create free account
hub / github.com/nodejs/nan / NAN_METHOD

Function NAN_METHOD

test/cpp/json-stringify.cpp:12–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <string>
11
12NAN_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
64NAN_MODULE_INIT(Init) {
65 Nan::Set(target

Callers

nothing calls this directly

Calls 6

ToLocalCheckedMethod · 0.80
FromJustMethod · 0.80
StringifyMethod · 0.80
IsEmptyMethod · 0.45
SetMethod · 0.45
GetReturnValueMethod · 0.45

Tested by

no test coverage detected