| 111 | } |
| 112 | |
| 113 | static std::expected<String, PreformattedMessage> validateModuleFile(const DiskPtr & user_scripts_disk, const String & path) |
| 114 | { |
| 115 | std::filesystem::path file_path(path); |
| 116 | |
| 117 | const auto & file_name = file_path.filename().string(); |
| 118 | |
| 119 | if (!endsWith(file_name, FILE_EXTENSION)) |
| 120 | return formatUnexpected("Unexpected file extension '{}', expected '{}'", file_path.extension().string(), FILE_EXTENSION); |
| 121 | |
| 122 | ReadSettings read_settings; |
| 123 | auto read_buf = user_scripts_disk->readFile(path, read_settings); |
| 124 | std::string file_header(16, '\0'); |
| 125 | size_t n = read_buf->read(file_header.data(), file_header.size()); |
| 126 | if (n != file_header.size()) |
| 127 | return formatUnexpected("File '{}' is too small to be a valid WebAssembly module", path); |
| 128 | |
| 129 | auto module_name = file_name.substr(0, file_name.size() - strlen(FILE_EXTENSION)); |
| 130 | if (auto res = checkValidWasmCode(module_name, file_header); !res) |
| 131 | return std::unexpected(std::move(res.error())); |
| 132 | return module_name; |
| 133 | } |
| 134 | |
| 135 | static std::unique_ptr<WebAssembly::IWasmEngine> createEngine(std::string_view engine_name) |
| 136 | { |
no test coverage detected