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

Method JSON

nan_json.h:26–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24class JSON {
25 public:
26 JSON() {
27#if NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
28 Nan::HandleScope scope;
29
30 Nan::MaybeLocal<v8::Value> maybe_global_json = Nan::Get(
31 Nan::GetCurrentContext()->Global(),
32 Nan::New("JSON").ToLocalChecked()
33 );
34
35 assert(!maybe_global_json.IsEmpty() && "global JSON is empty");
36 v8::Local<v8::Value> val_global_json = maybe_global_json.ToLocalChecked();
37
38 assert(val_global_json->IsObject() && "global JSON is not an object");
39 Nan::MaybeLocal<v8::Object> maybe_obj_global_json =
40 Nan::To<v8::Object>(val_global_json);
41
42 assert(!maybe_obj_global_json.IsEmpty() && "global JSON object is empty");
43 v8::Local<v8::Object> global_json = maybe_obj_global_json.ToLocalChecked();
44
45#if NAN_JSON_H_NEED_PARSE
46 Nan::MaybeLocal<v8::Value> maybe_parse_method = Nan::Get(
47 global_json, Nan::New("parse").ToLocalChecked()
48 );
49
50 assert(!maybe_parse_method.IsEmpty() && "JSON.parse is empty");
51 v8::Local<v8::Value> parse_method = maybe_parse_method.ToLocalChecked();
52
53 assert(parse_method->IsFunction() && "JSON.parse is not a function");
54 parse_cb_.Reset(parse_method.As<v8::Function>());
55#endif // NAN_JSON_H_NEED_PARSE
56
57#if NAN_JSON_H_NEED_STRINGIFY
58 Nan::MaybeLocal<v8::Value> maybe_stringify_method = Nan::Get(
59 global_json, Nan::New("stringify").ToLocalChecked()
60 );
61
62 assert(!maybe_stringify_method.IsEmpty() && "JSON.stringify is empty");
63 v8::Local<v8::Value> stringify_method =
64 maybe_stringify_method.ToLocalChecked();
65
66 assert(
67 stringify_method->IsFunction() && "JSON.stringify is not a function"
68 );
69 stringify_cb_.Reset(stringify_method.As<v8::Function>());
70#endif // NAN_JSON_H_NEED_STRINGIFY
71#endif // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
72 }
73
74 inline
75 Nan::MaybeLocal<v8::Value> Parse(v8::Local<v8::String> json_string) {

Callers

nothing calls this directly

Calls 7

GetCurrentContextFunction · 0.85
ToLocalCheckedMethod · 0.80
GetFunction · 0.70
NewFunction · 0.70
GlobalMethod · 0.45
IsEmptyMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected