Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach cxx to catch (Map)ParseException #102

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/wasm-opt-cxx-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ readme = "README.md"

[dependencies]
anyhow = "1.0.58"
cxx = "1.0.72"
cxx = "1.0.79"
wasm-opt-sys = { path = "../wasm-opt-sys", version = "0.110.1" }

[build-dependencies]
anyhow = "1.0.58"
cxx-build = { version = "1.0.72", features = ["parallel"] }
cxx-build = { version = "1.0.79", features = ["parallel"] }
51 changes: 17 additions & 34 deletions components/wasm-opt-cxx-sys/src/shims.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
#include <stdexcept> // runtime_error
#include <memory> // unique_ptr

namespace wasm_shims {
std::runtime_error parse_exception_to_runtime_error(const wasm::ParseException& e) {
namespace rust::behavior {
template <typename Try, typename Fail>
static void trycatch(Try&& func, Fail&& fail) noexcept try {
func();
} catch (const std::exception& e) {
fail(e.what());
} catch (const wasm::ParseException& e) {
Colors::setEnabled(false);

std::ostringstream buf;
e.dump(buf);

return std::runtime_error(buf.str());
}

std::runtime_error map_parse_exception_to_runtime_error(const wasm::MapParseException& e) {
fail(buf.str());
} catch (const wasm::MapParseException& e) {
Colors::setEnabled(false);

std::ostringstream buf;
e.dump(buf);

return std::runtime_error(buf.str());
fail(buf.str());
}
}

Expand Down Expand Up @@ -57,39 +56,23 @@ namespace wasm_shims {
}

void readText(const std::string& filename, Module& wasm) {
try {
inner.readText(std::string(filename), wasm);
} catch (const wasm::ParseException &e) {
throw parse_exception_to_runtime_error(e);
}
inner.readText(std::string(filename), wasm);
}

void readBinary(const std::string& filename,
Module& wasm,
const std::string& sourceMapFilename) {
try {
inner.readBinary(std::string(filename),
wasm,
std::string(sourceMapFilename));
} catch (const wasm::ParseException &e) {
throw parse_exception_to_runtime_error(e);
} catch (const wasm::MapParseException &e) {
throw map_parse_exception_to_runtime_error(e);
}
inner.readBinary(std::string(filename),
wasm,
std::string(sourceMapFilename));
}

void read(const std::string& filename,
Module& wasm,
const std::string& sourceMapFilename) {
try {
inner.read(std::string(filename),
wasm,
std::string(sourceMapFilename));
} catch (const wasm::ParseException &e) {
throw parse_exception_to_runtime_error(e);
} catch (const wasm::MapParseException &e) {
throw map_parse_exception_to_runtime_error(e);
}
inner.read(std::string(filename),
wasm,
std::string(sourceMapFilename));
}
};

Expand Down
4 changes: 2 additions & 2 deletions components/wasm-opt-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ links = "binaryen"
[build-dependencies]
anyhow = "1.0.58"
cc = { version = "1.0.73", features = ["parallel"] }
cxx-build = "1.0.72"
cxx-build = "1.0.79"
regex = "1.6.0"

[dependencies]
cxx = "1.0.72"
cxx = "1.0.79"