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 #ifndef V8_WASM_RESULT_H_ | 5 #ifndef V8_WASM_RESULT_H_ |
6 #define V8_WASM_RESULT_H_ | 6 #define V8_WASM_RESULT_H_ |
7 | 7 |
| 8 #include "src/base/compiler-specific.h" |
8 #include "src/base/smart-pointers.h" | 9 #include "src/base/smart-pointers.h" |
9 | 10 |
10 #include "src/globals.h" | 11 #include "src/globals.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 class Isolate; | 16 class Isolate; |
16 | 17 |
17 namespace wasm { | 18 namespace wasm { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 87 } |
87 | 88 |
88 std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code); | 89 std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code); |
89 | 90 |
90 // A helper for generating error messages that bubble up to JS exceptions. | 91 // A helper for generating error messages that bubble up to JS exceptions. |
91 class ErrorThrower { | 92 class ErrorThrower { |
92 public: | 93 public: |
93 ErrorThrower(Isolate* isolate, const char* context) | 94 ErrorThrower(Isolate* isolate, const char* context) |
94 : isolate_(isolate), context_(context), error_(false) {} | 95 : isolate_(isolate), context_(context), error_(false) {} |
95 | 96 |
96 void Error(const char* fmt, ...); | 97 PRINTF_FORMAT(2, 3) void Error(const char* fmt, ...); |
97 | 98 |
98 template <typename T> | 99 template <typename T> |
99 void Failed(const char* error, Result<T>& result) { | 100 void Failed(const char* error, Result<T>& result) { |
100 std::ostringstream str; | 101 std::ostringstream str; |
101 str << error << result; | 102 str << error << result; |
102 return Error(str.str().c_str()); | 103 return Error("%s", str.str().c_str()); |
103 } | 104 } |
104 | 105 |
105 bool error() const { return error_; } | 106 bool error() const { return error_; } |
106 | 107 |
107 private: | 108 private: |
108 Isolate* isolate_; | 109 Isolate* isolate_; |
109 const char* context_; | 110 const char* context_; |
110 bool error_; | 111 bool error_; |
111 }; | 112 }; |
112 } // namespace wasm | 113 } // namespace wasm |
113 } // namespace internal | 114 } // namespace internal |
114 } // namespace v8 | 115 } // namespace v8 |
115 | 116 |
116 #endif | 117 #endif |
OLD | NEW |