OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/wasm/wasm-result.h" | 5 #include "src/wasm/wasm-result.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/heap/heap.h" | 8 #include "src/heap/heap.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 os << "Success"; | 21 os << "Success"; |
22 break; | 22 break; |
23 default: // TODO(titzer): render error codes | 23 default: // TODO(titzer): render error codes |
24 os << "Error"; | 24 os << "Error"; |
25 break; | 25 break; |
26 } | 26 } |
27 return os; | 27 return os; |
28 } | 28 } |
29 | 29 |
30 void ErrorThrower::Error(const char* format, ...) { | 30 void ErrorThrower::Error(const char* format, ...) { |
31 // only report the first error. | 31 // Only report the first error. |
32 if (error_ || isolate_->has_pending_exception()) return; | 32 if (error()) return; |
33 error_ = true; | 33 |
34 char buffer[256]; | 34 char buffer[256]; |
35 | |
36 va_list arguments; | 35 va_list arguments; |
37 va_start(arguments, format); | 36 va_start(arguments, format); |
38 base::OS::VSNPrintF(buffer, 255, format, arguments); | 37 base::OS::VSNPrintF(buffer, 255, format, arguments); |
39 va_end(arguments); | 38 va_end(arguments); |
40 | 39 |
41 std::ostringstream str; | 40 std::ostringstream str; |
42 if (context_ != nullptr) { | 41 if (context_ != nullptr) { |
43 str << context_ << ": "; | 42 str << context_ << ": "; |
44 } | 43 } |
45 str << buffer; | 44 str << buffer; |
46 | 45 |
47 isolate_->ScheduleThrow( | 46 message_ = isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()); |
48 *isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str())); | 47 } |
| 48 |
| 49 ErrorThrower::~ErrorThrower() { |
| 50 if (error() && !isolate_->has_pending_exception()) { |
| 51 isolate_->ScheduleThrow(*message_); |
| 52 } |
49 } | 53 } |
50 } // namespace wasm | 54 } // namespace wasm |
51 } // namespace internal | 55 } // namespace internal |
52 } // namespace v8 | 56 } // namespace v8 |
OLD | NEW |