diff --git a/src/json_parser.cc b/src/json_parser.cc index f7710e3fd8e11c..a9973c099087e5 100644 --- a/src/json_parser.cc +++ b/src/json_parser.cc @@ -7,10 +7,7 @@ namespace node { using v8::ArrayBuffer; using v8::Context; using v8::Isolate; -using v8::Just; using v8::Local; -using v8::Maybe; -using v8::Nothing; using v8::Object; using v8::String; using v8::Value; @@ -61,7 +58,8 @@ bool JSONParser::Parse(const std::string& content) { return true; } -Maybe JSONParser::GetTopLevelStringField(std::string_view field) { +std::optional JSONParser::GetTopLevelStringField( + std::string_view field) { Isolate* isolate = isolate_.get(); Local context = context_.Get(isolate); Local content_object = content_.Get(isolate); @@ -71,17 +69,17 @@ Maybe JSONParser::GetTopLevelStringField(std::string_view field) { isolate, errors::PrinterTryCatch::kDontPrintSourceLine); Local field_local; if (!ToV8Value(context, field, isolate).ToLocal(&field_local)) { - return Nothing(); + return {}; } if (!content_object->Get(context, field_local).ToLocal(&value) || !value->IsString()) { - return Nothing(); + return {}; } Utf8Value utf8_value(isolate, value); - return Just(utf8_value.ToString()); + return utf8_value.ToString(); } -Maybe JSONParser::GetTopLevelBoolField(std::string_view field) { +std::optional JSONParser::GetTopLevelBoolField(std::string_view field) { Isolate* isolate = isolate_.get(); Local context = context_.Get(isolate); Local content_object = content_.Get(isolate); @@ -92,19 +90,19 @@ Maybe JSONParser::GetTopLevelBoolField(std::string_view field) { isolate, errors::PrinterTryCatch::kDontPrintSourceLine); Local field_local; if (!ToV8Value(context, field, isolate).ToLocal(&field_local)) { - return Nothing(); + return {}; } if (!content_object->Has(context, field_local).To(&has_field)) { - return Nothing(); + return {}; } if (!has_field) { - return Just(false); + return false; } if (!content_object->Get(context, field_local).ToLocal(&value) || !value->IsBoolean()) { - return Nothing(); + return {}; } - return Just(value->BooleanValue(isolate)); + return value->BooleanValue(isolate); } } // namespace node diff --git a/src/json_parser.h b/src/json_parser.h index 37bd9b4327da12..555f539acf3076 100644 --- a/src/json_parser.h +++ b/src/json_parser.h @@ -4,6 +4,7 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include +#include #include #include "util.h" #include "v8.h" @@ -17,8 +18,8 @@ class JSONParser { JSONParser(); ~JSONParser() {} bool Parse(const std::string& content); - v8::Maybe GetTopLevelStringField(std::string_view field); - v8::Maybe GetTopLevelBoolField(std::string_view field); + std::optional GetTopLevelStringField(std::string_view field); + std::optional GetTopLevelBoolField(std::string_view field); private: // We might want a lighter-weight JSON parser for this use case. But for now diff --git a/src/node_sea.cc b/src/node_sea.cc index ef6b2dd28b006d..c92490508a3d28 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -161,7 +161,7 @@ std::optional ParseSingleExecutableConfig( } result.main_path = - parser.GetTopLevelStringField("main").FromMaybe(std::string()); + parser.GetTopLevelStringField("main").value_or(std::string()); if (result.main_path.empty()) { FPrintF(stderr, "\"main\" field of %s is not a non-empty string\n", @@ -170,7 +170,7 @@ std::optional ParseSingleExecutableConfig( } result.output_path = - parser.GetTopLevelStringField("output").FromMaybe(std::string()); + parser.GetTopLevelStringField("output").value_or(std::string()); if (result.output_path.empty()) { FPrintF(stderr, "\"output\" field of %s is not a non-empty string\n", @@ -178,15 +178,15 @@ std::optional ParseSingleExecutableConfig( return std::nullopt; } - bool disable_experimental_sea_warning; - if (!parser.GetTopLevelBoolField("disableExperimentalSEAWarning") - .To(&disable_experimental_sea_warning)) { + std::optional disable_experimental_sea_warning = + parser.GetTopLevelBoolField("disableExperimentalSEAWarning"); + if (!disable_experimental_sea_warning.has_value()) { FPrintF(stderr, "\"disableExperimentalSEAWarning\" field of %s is not a Boolean\n", config_path); return std::nullopt; } - if (disable_experimental_sea_warning) { + if (disable_experimental_sea_warning.value()) { result.flags |= SeaFlags::kDisableExperimentalSeaWarning; }