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