Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: src/wasm/wasm-result.cc

Issue 2342623002: [wasm] Set up Table and Memory constructors
Patch Set: Eps Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 11
12 #include "src/base/platform/platform.h" 12 #include "src/base/platform/platform.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 namespace wasm { 16 namespace wasm {
17 17
18 std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code) { 18 std::ostream& operator<<(std::ostream& os, const ErrorCode& error_code) {
19 switch (error_code) { 19 switch (error_code) {
20 case kSuccess: 20 case kSuccess:
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::Format(
31 i::Handle<i::JSFunction> constructor, const char* format, va_list args) {
31 // Only report the first error. 32 // Only report the first error.
32 if (error()) return; 33 if (error()) return;
33 34
34 char buffer[256]; 35 char buffer[256];
35 va_list arguments; 36 base::OS::VSNPrintF(buffer, 255, format, args);
36 va_start(arguments, format);
37 base::OS::VSNPrintF(buffer, 255, format, arguments);
38 va_end(arguments);
39 37
40 std::ostringstream str; 38 std::ostringstream str;
41 if (context_ != nullptr) { 39 if (context_ != nullptr) {
42 str << context_ << ": "; 40 str << context_ << ": ";
43 } 41 }
44 str << buffer; 42 str << buffer;
45 43
46 message_ = isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str()); 44 i::Handle<i::String> message =
45 isolate_->factory()->NewStringFromAsciiChecked(str.str().c_str());
46 exception_ = isolate_->factory()->NewError(constructor, message);
47 }
48
49 void ErrorThrower::Error(const char* format, ...) {
50 if (error()) return;
51 va_list arguments;
52 va_start(arguments, format);
53 Format(isolate_->error_function(), format, arguments);
54 va_end(arguments);
55 }
56
57 void ErrorThrower::TypeError(const char* format, ...) {
58 if (error()) return;
59 va_list arguments;
60 va_start(arguments, format);
61 Format(isolate_->type_error_function(), format, arguments);
62 va_end(arguments);
63 }
64
65 void ErrorThrower::RangeError(const char* format, ...) {
66 if (error()) return;
67 va_list arguments;
68 va_start(arguments, format);
69 CHECK(*isolate_->range_error_function() != *isolate_->type_error_function());
70 Format(isolate_->range_error_function(), format, arguments);
71 va_end(arguments);
47 } 72 }
48 73
49 ErrorThrower::~ErrorThrower() { 74 ErrorThrower::~ErrorThrower() {
50 if (error() && !isolate_->has_pending_exception()) { 75 if (error() && !isolate_->has_pending_exception()) {
51 isolate_->ScheduleThrow(*message_); 76 isolate_->ScheduleThrow(*exception_);
52 } 77 }
53 } 78 }
54 } // namespace wasm 79 } // namespace wasm
55 } // namespace internal 80 } // namespace internal
56 } // namespace v8 81 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698