Skip to content

Commit 0045d8f

Browse files
Use string_view for trap
1 parent 986e7cb commit 0045d8f

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/shell-interface.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,15 @@ struct ShellExternalInterface : ModuleRunner::ExternalInterface {
325325
return true;
326326
}
327327

328-
void trap(const char* why) override {
328+
void trap(std::string_view why) override {
329329
std::cout << "[trap " << why << "]\n";
330330
throw TrapException();
331331
}
332332

333-
void hostLimit(const char* why) override {
333+
void hostLimit(std::string_view why) override {
334334
std::cout << "[host limit " << why << "]\n";
335335
throw HostLimitException();
336336
}
337-
338337
void throwException(const WasmException& exn) override { throw exn; }
339338
};
340339

src/tools/wasm-ctor-eval.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,12 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface {
451451
throw FailToEvalException("grow table");
452452
}
453453

454-
void trap(const char* why) override {
455-
throw FailToEvalException(std::string("trap: ") + why);
454+
void trap(std::string_view why) override {
455+
throw FailToEvalException(std::string("trap: ") + std::string(why));
456456
}
457457

458-
void hostLimit(const char* why) override {
459-
throw FailToEvalException(std::string("trap: ") + why);
458+
void hostLimit(std::string_view why) override {
459+
throw FailToEvalException(std::string("trap: ") + std::string(why));
460460
}
461461

462462
void throwException(const WasmException& exn) override {

src/wasm-interpreter.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Flow {
8686
}
8787

8888
Literals values;
89-
Name breakTo; // if non-null, a break is going on
89+
Name breakTo; // if non-null, a break is going on
9090
Tag* suspendTag = nullptr; // if non-null, breakTo must be SUSPEND_FLOW, and
9191
// this is the tag being suspended
9292

@@ -2689,9 +2689,9 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
26892689
return makeGCData(std::move(contents), curr->type);
26902690
}
26912691

2692-
virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); }
2692+
virtual void trap(std::string_view why) { WASM_UNREACHABLE("unimp"); }
26932693

2694-
virtual void hostLimit(const char* why) { WASM_UNREACHABLE("unimp"); }
2694+
virtual void hostLimit(std::string_view why) { WASM_UNREACHABLE("unimp"); }
26952695

26962696
virtual void throwException(const WasmException& exn) {
26972697
WASM_UNREACHABLE("unimp");
@@ -2924,9 +2924,11 @@ class ConstantExpressionRunner : public ExpressionRunner<SubType> {
29242924
Flow visitResumeThrow(ResumeThrow* curr) { return Flow(NONCONSTANT_FLOW); }
29252925
Flow visitStackSwitch(StackSwitch* curr) { return Flow(NONCONSTANT_FLOW); }
29262926

2927-
void trap(const char* why) override { throw NonconstantException(); }
2927+
void trap(std::string_view why) override { throw NonconstantException(); }
29282928

2929-
void hostLimit(const char* why) override { throw NonconstantException(); }
2929+
void hostLimit(std::string_view why) override {
2930+
throw NonconstantException();
2931+
}
29302932

29312933
virtual void throwException(const WasmException& exn) override {
29322934
throw NonconstantException();
@@ -2969,8 +2971,8 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
29692971
const Literal& value,
29702972
Index oldSize,
29712973
Index newSize) = 0;
2972-
virtual void trap(const char* why) = 0;
2973-
virtual void hostLimit(const char* why) = 0;
2974+
virtual void trap(std::string_view why) = 0;
2975+
virtual void hostLimit(std::string_view why) = 0;
29742976
virtual void throwException(const WasmException& exn) = 0;
29752977
// Get the Tag instance for a tag implemented in the host, that is, not
29762978
// among the linked ModuleRunner instances, but imported from the host.
@@ -4715,13 +4717,11 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
47154717
}
47164718
Flow visitStackSwitch(StackSwitch* curr) { return Flow(NONCONSTANT_FLOW); }
47174719

4718-
void trap(const char* why) override {
4719-
// Traps break all current continuations - they will never be resumable.
4720+
void trap(std::string_view why) {
47204721
self()->clearContinuationStore();
47214722
externalInterface->trap(why);
47224723
}
4723-
4724-
void hostLimit(const char* why) override {
4724+
void hostLimit(std::string_view why) {
47254725
self()->clearContinuationStore();
47264726
externalInterface->hostLimit(why);
47274727
}

0 commit comments

Comments
 (0)