Skip to content

[wasm] Exception filter clause evaluated at wrong time #52394

@radekdoulik

Description

@radekdoulik

Repro: radekdoulik@0a454d2

The modified sample above tests the ordering of exception filter clause evaluation. When built with AOT, the clause is evaluated at wrong time.

Looks like we are unwinding the stack (and thus running finnaly block) before evaluating the filter clause. That leads to unhandled exception in this test, as the finally block modifies the state (answer variable) and the clause is evaluated as false.

Test output built with AOT:

going to throw
finally: answer = 1
check: 1 == 42 => False
test_exit: 1
dotnet.js:6509 Unhandled exception in _finalize_startup Error: System.Exception: Throw
   at :64251/Sample.Test.TestExcFilter()
    at Object._convert_exception_for_method_call (dotnet.js:8196)
    at Object._handle_exception_for_call (dotnet.js:8258)
    at Object._handle_exception_and_produce_result_for_call (dotnet.js:8267)
    at Object._call_method_with_converted_args (dotnet.js:8295)
    at Object.call_method (dotnet.js:8254)
    at Object.call_static_method (dotnet.js:8483)
    at Object.init (localhost/:39)
    at Object.config.loaded_cb (runtime.js:8)
    at Object._finalize_startup (dotnet.js:6470)
    at onPendingRequestComplete (dotnet.js:6507)
onPendingRequestComplete @ dotnet.js:6509
dotnet.js:8196 Uncaught (in promise) Error: System.Exception: Throw
   at :64251/Sample.Test.TestExcFilter()
    at Object._convert_exception_for_method_call (dotnet.js:8196)
    at Object._handle_exception_for_call (dotnet.js:8258)
    at Object._handle_exception_and_produce_result_for_call (dotnet.js:8267)
    at Object._call_method_with_converted_args (dotnet.js:8295)
    at Object.call_method (dotnet.js:8254)
    at Object.call_static_method (dotnet.js:8483)
    at Object.init (localhost/:39)
    at Object.config.loaded_cb (runtime.js:8)
    at Object._finalize_startup (dotnet.js:6470)
    at onPendingRequestComplete (dotnet.js:6507)

When built without AOT, it works as expected and we don't get unhandled exception. Output with interpreter only:

going to throw
check: 42 == 42 => True
finally: answer = 1
catch in TestExcFilter, answer: 1

Assigning to @BrzVlad as the filtering happens in interpreter. The origin of the issue might be in AOT though, as the handling of the exception starts in AOT code.

/cc @vargaz

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions