Index: src/wasm/wasm-result.cc |
diff --git a/src/wasm/wasm-result.cc b/src/wasm/wasm-result.cc |
index 30268ac8ad52d4ee03ee3b80e99393283e77d2f7..7d251f03dfc884f19df22ca731bf800b15718a22 100644 |
--- a/src/wasm/wasm-result.cc |
+++ b/src/wasm/wasm-result.cc |
@@ -27,15 +27,13 @@ std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code) { |
return os; |
} |
-void ErrorThrower::Error(const char* format, ...) { |
+void ErrorThrower::Format(i::Handle<i::JSFunction> constructor, |
+ const char* format, va_list args) { |
// 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); |
- va_end(arguments); |
+ base::OS::VSNPrintF(buffer, 255, format, args); |
std::ostringstream str; |
if (context_ != nullptr) { |
@@ -43,12 +41,39 @@ void ErrorThrower::Error(const char* format, ...) { |
} |
str << buffer; |
- message_ = isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()); |
+ i::Handle<i::String> message = |
+ isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()); |
+ exception_ = isolate_->factory()->NewError(constructor, message); |
+} |
+ |
+void ErrorThrower::Error(const char* format, ...) { |
+ if (error()) return; |
+ va_list arguments; |
+ va_start(arguments, format); |
+ Format(isolate_->error_function(), format, arguments); |
+ va_end(arguments); |
+} |
+ |
+void ErrorThrower::TypeError(const char* format, ...) { |
+ if (error()) return; |
+ va_list arguments; |
+ va_start(arguments, format); |
+ Format(isolate_->type_error_function(), format, arguments); |
+ va_end(arguments); |
+} |
+ |
+void ErrorThrower::RangeError(const char* format, ...) { |
+ if (error()) return; |
+ va_list arguments; |
+ va_start(arguments, format); |
+ CHECK(*isolate_->range_error_function() != *isolate_->type_error_function()); |
+ Format(isolate_->range_error_function(), format, arguments); |
+ va_end(arguments); |
} |
ErrorThrower::~ErrorThrower() { |
if (error() && !isolate_->has_pending_exception()) { |
- isolate_->ScheduleThrow(*message_); |
+ isolate_->ScheduleThrow(*exception_); |
} |
} |
} // namespace wasm |