Commit f2bd9c6c authored by Tobias Nießen's avatar Tobias Nießen Committed by Commit Bot

[wasm] Fix silent failure with --dump-wasm-module

The previous behavior failed silently if the file could not be opened
in the first place, and only wrote to stderr if writing failed after
opening the file successfully.

Change-Id: I1d1058134efd9298b60b65191ed6334de24d3f52
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1972886Reviewed-by: 's avatarBill Budge <bbudge@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65875}
parent e3602c11
......@@ -291,14 +291,15 @@ class ModuleDecoderImpl : public Decoder {
size_t hash = base::hash_range(module_bytes.begin(), module_bytes.end());
EmbeddedVector<char, 32> buf;
SNPrintF(buf, "%016zx.%s.wasm", hash, ok() ? "ok" : "failed");
std::string name(buf.begin());
if (FILE* wasm_file = base::OS::FOpen((path + name).c_str(), "wb")) {
if (fwrite(module_bytes.begin(), module_bytes.length(), 1, wasm_file) !=
1) {
OFStream os(stderr);
os << "Error while dumping wasm file" << std::endl;
}
fclose(wasm_file);
path += buf.begin();
size_t rv = 0;
if (FILE* file = base::OS::FOpen(path.c_str(), "wb")) {
rv = fwrite(module_bytes.begin(), module_bytes.length(), 1, file);
fclose(file);
}
if (rv != 1) {
OFStream os(stderr);
os << "Error while dumping wasm file to " << path << std::endl;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment