FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nan/test/cpp/json-stringify.cpp at main · nodejs/nan · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
nodejs
/
nan
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
529
Star
3.4k
Code
Issues
57
Pull requests
15
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
nan
/
test
/
cpp
/
json-stringify.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (61 loc) · 2.13 KB
Breadcrumbs
nan
/
test
/
cpp
/
json-stringify.cpp
Copy path
File metadata and controls
72 lines (61 loc) · 2.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2018 NAN contributors
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
*******************************************************************
*/
#
include
<
nan.h
>
#
include
<
string
>
NAN_METHOD
(Stringify) {
if
(info.
Length
() >
0
) {
Nan::MaybeLocal<v8::Object> maybe_obj = Nan::To<v8::Object>(info[
0
]);
if
(!maybe_obj.
IsEmpty
()) {
Nan::
JSON
NanJSON;
v8::Local<v8::Object> obj = maybe_obj.
ToLocalChecked
();
if
(
3
== info.
Length
()) {
if
(info[
2
]->
IsNumber
()) {
int32_t
len = Nan::To<
int32_t
>(info[
2
]).
FromJust
();
len = (len >
10
) ?
10
: len;
len = (len <
0
) ?
0
: len;
Nan::MaybeLocal<v8::String> maybe_gap =
Nan::New<v8::String>(
std::string
(len,
'
'
));
if
(!maybe_gap.
IsEmpty
()) {
v8::Local<v8::String> gap = maybe_gap.
ToLocalChecked
();
Nan::MaybeLocal<v8::String> result =
NanJSON.
Stringify
(obj, gap);
if
(!result.
IsEmpty
()) {
info.
GetReturnValue
().
Set
(result.
ToLocalChecked
());
}
}
}
else
if
(info[
2
]->
IsString
()) {
Nan::MaybeLocal<v8::String> result = NanJSON.
Stringify
(
obj,
Nan::To<v8::String>(info[
2
]).
ToLocalChecked
()
);
if
(!result.
IsEmpty
()) {
info.
GetReturnValue
().
Set
(result.
ToLocalChecked
());
}
}
else
{
Nan::MaybeLocal<v8::String> result = NanJSON.
Stringify
(obj);
if
(!result.
IsEmpty
()) {
info.
GetReturnValue
().
Set
(result.
ToLocalChecked
());
}
}
}
else
{
Nan::MaybeLocal<v8::String> result = NanJSON.
Stringify
(obj);
if
(!result.
IsEmpty
()) {
info.
GetReturnValue
().
Set
(result.
ToLocalChecked
());
}
}
}
}
}
NAN_MODULE_INIT
(Init) {
Nan::Set
(target
, Nan::New<v8::String>(
"
stringify
"
).
ToLocalChecked
()
,
Nan::GetFunction
(Nan::New<v8::FunctionTemplate>(Stringify))
.
ToLocalChecked
()
);
}
NODE_MODULE
(stringify, Init)
Back
|
FazBrowse Home
|
New Git URL