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

Review exception handling #459

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public static TestModule of(Module module) {
+ "import after table "
+ "import after memory "
+ "i32 constant out of range "
+ "unknown label";
+ "unknown label "
+ "alignment "
+ "multiple start sections";

public static TestModule of(File file, ModuleType moduleType) {
if (moduleType == ModuleType.TEXT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static TestModule of(Module module) {
+ "import after table "
+ "import after memory "
+ "i32 constant out of range "
+ "unknown label";
+ "unknown label "
+ "alignment "
+ "multiple start sections";

public static TestModule of(File file, ModuleType moduleType) {
if (moduleType == ModuleType.TEXT) {
Expand Down
29 changes: 9 additions & 20 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static com.dylibso.chicory.runtime.ConstantEvaluators.computeConstantValue;
import static com.dylibso.chicory.wasm.types.Value.REF_NULL_VALUE;

import com.dylibso.chicory.runtime.exceptions.WASMMachineException;
import com.dylibso.chicory.wasm.Module;
import com.dylibso.chicory.wasm.exceptions.ChicoryException;
import com.dylibso.chicory.wasm.exceptions.InvalidException;
Expand Down Expand Up @@ -280,7 +279,11 @@ public Instance initialize(boolean start) {
}

if (startFunction != null && start) {
export(START_FUNCTION_NAME).apply();
try {
export(START_FUNCTION_NAME).apply();
} catch (TrapException e) {
throw new UninstantiableException(e.getMessage(), e);
}
}

return this;
Expand All @@ -297,27 +300,13 @@ public ExportFunction export(String name) {
switch (export.exportType()) {
case FUNCTION:
{
var funcId = export.index();
return (args) -> {
try {
return machine.call(funcId, args);
} catch (InvalidException e) {
throw e;
} catch (TrapException e) {
throw new UninstantiableException("unreachable", e);
} catch (Exception e) {
throw new WASMMachineException(machine.getStackTrace(), e);
}
};
return (args) -> machine.call(export.index(), args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: no need for parens around singular lambda argument

}
case GLOBAL:
{
return new ExportFunction() {
@Override
public Value[] apply(Value... args) throws ChicoryException {
assert (args.length == 0);
return new Value[] {readGlobal(export.index())};
}
return args -> {
assert (args.length == 0);
return new Value[] {readGlobal(export.index())};
};
}
default:
Expand Down
Loading