Index: src/wasm/wasm-result.cc |
diff --git a/src/wasm/wasm-result.cc b/src/wasm/wasm-result.cc |
index 0f5529fe385fc1a427930b6a562c1c73ede46ba4..30268ac8ad52d4ee03ee3b80e99393283e77d2f7 100644 |
--- a/src/wasm/wasm-result.cc |
+++ b/src/wasm/wasm-result.cc |
@@ -28,11 +28,10 @@ std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code) { |
} |
void ErrorThrower::Error(const char* format, ...) { |
- // only report the first error. |
- if (error_ || isolate_->has_pending_exception()) return; |
- error_ = true; |
- char buffer[256]; |
+ // Only report the first error. |
+ if (error()) return; |
+ char buffer[256]; |
va_list arguments; |
va_start(arguments, format); |
base::OS::VSNPrintF(buffer, 255, format, arguments); |
@@ -44,8 +43,13 @@ void ErrorThrower::Error(const char* format, ...) { |
} |
str << buffer; |
- isolate_->ScheduleThrow( |
- *isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str())); |
+ message_ = isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()); |
+} |
+ |
+ErrorThrower::~ErrorThrower() { |
+ if (error() && !isolate_->has_pending_exception()) { |
+ isolate_->ScheduleThrow(*message_); |
+ } |
} |
} // namespace wasm |
} // namespace internal |