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

Assert with an error message instead of silently return empty object #26

Merged
merged 1 commit into from
Nov 10, 2021

Conversation

finalpatch
Copy link
Contributor

When passing JS interface objects but the interfaces lacks "+w", we currently pass an empty object into C++. This causes downstream code to fail silently and it confuses developers.

This change will trigger an assertion in this case with a clear error message about what happened. Also fix the case of passing C++ interface objects without "+c".

Copy link

@kburov-sc kburov-sc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@finalpatch finalpatch merged commit c481172 into master Nov 10, 2021
@finalpatch finalpatch deleted the lf/assert_on_missing_plus_w branch November 10, 2021 01:20
@@ -458,7 +458,10 @@ struct JsInterface {
// (interface +c)
template <typename, typename>
struct GetOrCreateCppProxy {
em::val operator() (const std::shared_ptr<I>& c) { return em::val::undefined(); }
em::val operator() (const std::shared_ptr<I>& c) {
assert(false && "Attempting to pass C++ object but interface lacks +c");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach of using assert for error handling in wasm code does have a benefit that emscripten bridges asserts back out to JS with reasonable messages and stack traces, rather than just crashing/aborting.

But this has a negative that we are now relying on something that is only defined when NDEBUG is not present. In the current bazel toolchain, if we build with -c opt, NDEBUG is defined, and all these asserts will disappear I believe.

The asserts in the emscripten STL come from here. They do the typical ifdef, where NDEBUG no-ops it. When it isn't defined, depending on your flags, I think it either uses the C++ impl here or bridges out to JS here.

I'm not sure if there's an emscripten equivalent of some of the tricks we usually do to turn on asserts with NDEBUG defined, like __attribute__((noinline)) extern "C" void __assert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants