|
11 | 11 | #include "embedded_data.h" |
12 | 12 | #include "encoding_binding.h" |
13 | 13 | #include "env-inl.h" |
14 | | -#include "json_parser.h" |
15 | 14 | #include "node_blob.h" |
16 | 15 | #include "node_builtins.h" |
17 | 16 | #include "node_contextify.h" |
|
27 | 26 | #include "node_url.h" |
28 | 27 | #include "node_v8.h" |
29 | 28 | #include "node_v8_platform-inl.h" |
| 29 | +#include "simdjson.h" |
30 | 30 | #include "timers.h" |
31 | 31 |
|
32 | 32 | #if HAVE_INSPECTOR |
@@ -909,32 +909,61 @@ std::optional<SnapshotConfig> ReadSnapshotConfig(const char* config_path) { |
909 | 909 | return std::nullopt; |
910 | 910 | } |
911 | 911 |
|
912 | | - JSONParser parser; |
913 | | - if (!parser.Parse(config_content)) { |
914 | | - FPrintF(stderr, "Cannot parse JSON from %s\n", config_path); |
915 | | - return std::nullopt; |
916 | | - } |
917 | | - |
918 | 912 | SnapshotConfig result; |
919 | | - result.builder_script_path = parser.GetTopLevelStringField("builder"); |
920 | | - if (!result.builder_script_path.has_value()) { |
| 913 | + |
| 914 | + simdjson::ondemand::parser parser; |
| 915 | + simdjson::ondemand::document document; |
| 916 | + simdjson::ondemand::object main_object; |
| 917 | + simdjson::error_code error = |
| 918 | + parser.iterate(simdjson::pad(config_content)).get(document); |
| 919 | + |
| 920 | + if (!error) { |
| 921 | + error = document.get_object().get(main_object); |
| 922 | + } |
| 923 | + if (error) { |
921 | 924 | FPrintF(stderr, |
922 | | - "\"builder\" field of %s is not a non-empty string\n", |
923 | | - config_path); |
| 925 | + "Cannot parse JSON from %s: %s\n", |
| 926 | + config_path, |
| 927 | + simdjson::error_message(error)); |
924 | 928 | return std::nullopt; |
925 | 929 | } |
926 | 930 |
|
927 | | - std::optional<bool> WithoutCodeCache = |
928 | | - parser.GetTopLevelBoolField("withoutCodeCache"); |
929 | | - if (!WithoutCodeCache.has_value()) { |
| 931 | + for (auto field : main_object) { |
| 932 | + std::string_view key; |
| 933 | + if (field.unescaped_key().get(key)) { |
| 934 | + FPrintF(stderr, "Cannot read key from %s\n", config_path); |
| 935 | + return std::nullopt; |
| 936 | + } |
| 937 | + if (key == "builder") { |
| 938 | + std::string builder_path; |
| 939 | + if (field.value().get_string().get(builder_path) || |
| 940 | + builder_path.empty()) { |
| 941 | + FPrintF(stderr, |
| 942 | + "\"builder\" field of %s is not a non-empty string\n", |
| 943 | + config_path); |
| 944 | + return std::nullopt; |
| 945 | + } |
| 946 | + result.builder_script_path = builder_path; |
| 947 | + } else if (key == "withoutCodeCache") { |
| 948 | + bool without_code_cache_value = false; |
| 949 | + if (field.value().get_bool().get(without_code_cache_value)) { |
| 950 | + FPrintF(stderr, |
| 951 | + "\"withoutCodeCache\" field of %s is not a boolean\n", |
| 952 | + config_path); |
| 953 | + return std::nullopt; |
| 954 | + } |
| 955 | + if (without_code_cache_value) { |
| 956 | + result.flags |= SnapshotFlags::kWithoutCodeCache; |
| 957 | + } |
| 958 | + } |
| 959 | + } |
| 960 | + |
| 961 | + if (!result.builder_script_path.has_value()) { |
930 | 962 | FPrintF(stderr, |
931 | | - "\"withoutCodeCache\" field of %s is not a boolean\n", |
| 963 | + "\"builder\" field of %s is not a non-empty string\n", |
932 | 964 | config_path); |
933 | 965 | return std::nullopt; |
934 | 966 | } |
935 | | - if (WithoutCodeCache.value()) { |
936 | | - result.flags |= SnapshotFlags::kWithoutCodeCache; |
937 | | - } |
938 | 967 |
|
939 | 968 | return result; |
940 | 969 | } |
|
0 commit comments