@@ -7,7 +7,10 @@ namespace node {
7
7
using v8::ArrayBuffer;
8
8
using v8::Context;
9
9
using v8::Isolate;
10
+ using v8::Just;
10
11
using v8::Local;
12
+ using v8::Maybe;
13
+ using v8::Nothing;
11
14
using v8::Object;
12
15
using v8::String;
13
16
using v8::Value;
@@ -58,8 +61,7 @@ bool JSONParser::Parse(const std::string& content) {
58
61
return true ;
59
62
}
60
63
61
- std::optional<std::string> JSONParser::GetTopLevelStringField (
62
- std::string_view field) {
64
+ Maybe<std::string> JSONParser::GetTopLevelStringField (std::string_view field) {
63
65
Isolate* isolate = isolate_.get ();
64
66
Local<Context> context = context_.Get (isolate);
65
67
Local<Object> content_object = content_.Get (isolate);
@@ -69,17 +71,17 @@ std::optional<std::string> JSONParser::GetTopLevelStringField(
69
71
isolate, errors::PrinterTryCatch::kDontPrintSourceLine );
70
72
Local<Value> field_local;
71
73
if (!ToV8Value (context, field, isolate).ToLocal (&field_local)) {
72
- return {} ;
74
+ return Nothing<std::string>() ;
73
75
}
74
76
if (!content_object->Get (context, field_local).ToLocal (&value) ||
75
77
!value->IsString ()) {
76
- return {} ;
78
+ return Nothing<std::string>() ;
77
79
}
78
80
Utf8Value utf8_value (isolate, value);
79
- return utf8_value.ToString ();
81
+ return Just ( utf8_value.ToString () );
80
82
}
81
83
82
- std::optional <bool > JSONParser::GetTopLevelBoolField (std::string_view field) {
84
+ Maybe <bool > JSONParser::GetTopLevelBoolField (std::string_view field) {
83
85
Isolate* isolate = isolate_.get ();
84
86
Local<Context> context = context_.Get (isolate);
85
87
Local<Object> content_object = content_.Get (isolate);
@@ -90,19 +92,19 @@ std::optional<bool> JSONParser::GetTopLevelBoolField(std::string_view field) {
90
92
isolate, errors::PrinterTryCatch::kDontPrintSourceLine );
91
93
Local<Value> field_local;
92
94
if (!ToV8Value (context, field, isolate).ToLocal (&field_local)) {
93
- return {} ;
95
+ return Nothing< bool >() ;
94
96
}
95
97
if (!content_object->Has (context, field_local).To (&has_field)) {
96
- return {} ;
98
+ return Nothing< bool >() ;
97
99
}
98
100
if (!has_field) {
99
- return false ;
101
+ return Just ( false ) ;
100
102
}
101
103
if (!content_object->Get (context, field_local).ToLocal (&value) ||
102
104
!value->IsBoolean ()) {
103
- return {} ;
105
+ return Nothing< bool >() ;
104
106
}
105
- return value->BooleanValue (isolate);
107
+ return Just ( value->BooleanValue (isolate) );
106
108
}
107
109
108
110
} // namespace node
0 commit comments