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 3 // found in the LICENSE file. 4 5 #include "src/wasm/wasm-result.h" 6 7 #include "src/factory.h" 8 #include "src/heap/heap.h" 9 #include "src/isolate-inl.h" 10 #include "src/objects.h" 11 12 #include "src/base/platform/platform.h" 13 14 namespace v8 { 15 namespace internal { 16 namespace wasm { 17 operator <<(std::ostream & os,const ErrorCode & error_code)18std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code) { 19 switch (error_code) { 20 case kSuccess: 21 os << "Success"; 22 break; 23 default: // TODO(titzer): render error codes 24 os << "Error"; 25 break; 26 } 27 return os; 28 } 29 Error(const char * format,...)30void ErrorThrower::Error(const char* format, ...) { 31 // Only report the first error. 32 if (error()) return; 33 34 char buffer[256]; 35 va_list arguments; 36 va_start(arguments, format); 37 base::OS::VSNPrintF(buffer, 255, format, arguments); 38 va_end(arguments); 39 40 std::ostringstream str; 41 if (context_ != nullptr) { 42 str << context_ << ": "; 43 } 44 str << buffer; 45 46 message_ = isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()); 47 } 48 ~ErrorThrower()49ErrorThrower::~ErrorThrower() { 50 if (error() && !isolate_->has_pending_exception()) { 51 isolate_->ScheduleThrow(*message_); 52 } 53 } 54 } // namespace wasm 55 } // namespace internal 56 } // namespace v8 57