blob: 3de5812e9f47638753246775a6ce60cca637c672 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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.h"
10#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
11#include "src/objects.h"
12
13#include "src/base/platform/platform.h"
14
15namespace v8 {
16namespace internal {
17namespace wasm {
18
19std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code) {
20 switch (error_code) {
21 case kSuccess:
22 os << "Success";
23 break;
24 default: // TODO(titzer): render error codes
25 os << "Error";
26 break;
27 }
28 return os;
29}
30
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000031void ErrorThrower::Error(const char* format, ...) {
32 if (error_) return; // only report the first error.
33 error_ = true;
34 char buffer[256];
35
36 va_list arguments;
37 va_start(arguments, format);
38 base::OS::VSNPrintF(buffer, 255, format, arguments);
39 va_end(arguments);
40
41 std::ostringstream str;
42 if (context_ != nullptr) {
43 str << context_ << ": ";
44 }
45 str << buffer;
46
47 isolate_->ScheduleThrow(
48 *isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()));
49}
50} // namespace wasm
51} // namespace internal
52} // namespace v8