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 <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/base/compiler-specific.h" | 10 #include "src/base/compiler-specific.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code); | 85 std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code); |
86 | 86 |
87 // A helper for generating error messages that bubble up to JS exceptions. | 87 // A helper for generating error messages that bubble up to JS exceptions. |
88 class V8_EXPORT_PRIVATE ErrorThrower { | 88 class V8_EXPORT_PRIVATE ErrorThrower { |
89 public: | 89 public: |
90 ErrorThrower(i::Isolate* isolate, const char* context) | 90 ErrorThrower(i::Isolate* isolate, const char* context) |
91 : isolate_(isolate), context_(context) {} | 91 : isolate_(isolate), context_(context) {} |
92 ~ErrorThrower(); | 92 ~ErrorThrower(); |
93 | 93 |
94 PRINTF_FORMAT(2, 3) void Error(const char* fmt, ...); | |
95 PRINTF_FORMAT(2, 3) void TypeError(const char* fmt, ...); | 94 PRINTF_FORMAT(2, 3) void TypeError(const char* fmt, ...); |
96 PRINTF_FORMAT(2, 3) void RangeError(const char* fmt, ...); | 95 PRINTF_FORMAT(2, 3) void RangeError(const char* fmt, ...); |
| 96 PRINTF_FORMAT(2, 3) void CompileError(const char* fmt, ...); |
| 97 PRINTF_FORMAT(2, 3) void RuntimeError(const char* fmt, ...); |
97 | 98 |
98 template <typename T> | 99 template <typename T> |
99 void Failed(const char* error, Result<T>& result) { | 100 void CompileFailed(const char* error, Result<T>& result) { |
100 std::ostringstream str; | 101 std::ostringstream str; |
101 str << error << result; | 102 str << error << result; |
102 Error("%s", str.str().c_str()); | 103 CompileError("%s", str.str().c_str()); |
103 } | 104 } |
104 | 105 |
105 i::Handle<i::Object> Reify() { | 106 i::Handle<i::Object> Reify() { |
106 i::Handle<i::Object> result = exception_; | 107 i::Handle<i::Object> result = exception_; |
107 exception_ = i::Handle<i::Object>::null(); | 108 exception_ = i::Handle<i::Object>::null(); |
108 return result; | 109 return result; |
109 } | 110 } |
110 | 111 |
111 bool error() const { return !exception_.is_null(); } | 112 bool error() const { return !exception_.is_null(); } |
112 | 113 |
113 private: | 114 private: |
114 void Format(i::Handle<i::JSFunction> constructor, const char* fmt, va_list); | 115 void Format(i::Handle<i::JSFunction> constructor, const char* fmt, va_list); |
115 | 116 |
116 i::Isolate* isolate_; | 117 i::Isolate* isolate_; |
117 const char* context_; | 118 const char* context_; |
118 i::Handle<i::Object> exception_; | 119 i::Handle<i::Object> exception_; |
119 }; | 120 }; |
120 } // namespace wasm | 121 } // namespace wasm |
121 } // namespace internal | 122 } // namespace internal |
122 } // namespace v8 | 123 } // namespace v8 |
123 | 124 |
124 #endif | 125 #endif |
OLD | NEW |