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

Side by Side Diff: runtime/vm/object.cc

Issue 9148048: Standardize error printing a bit by moving it to the Error object and (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
11 #include "vm/code_generator.h" 11 #include "vm/code_generator.h"
12 #include "vm/code_index_table.h" 12 #include "vm/code_index_table.h"
13 #include "vm/code_patcher.h" 13 #include "vm/code_patcher.h"
14 #include "vm/compiler.h" 14 #include "vm/compiler.h"
15 #include "vm/compiler_stats.h" 15 #include "vm/compiler_stats.h"
16 #include "vm/class_finalizer.h" 16 #include "vm/class_finalizer.h"
17 #include "vm/dart.h" 17 #include "vm/dart.h"
18 #include "vm/dart_entry.h"
18 #include "vm/debuginfo.h" 19 #include "vm/debuginfo.h"
19 #include "vm/exceptions.h" 20 #include "vm/exceptions.h"
20 #include "vm/growable_array.h" 21 #include "vm/growable_array.h"
21 #include "vm/heap.h" 22 #include "vm/heap.h"
22 #include "vm/ic_data.h" 23 #include "vm/ic_data.h"
23 #include "vm/object_store.h" 24 #include "vm/object_store.h"
24 #include "vm/parser.h" 25 #include "vm/parser.h"
25 #include "vm/runtime_entry.h" 26 #include "vm/runtime_entry.h"
26 #include "vm/scopes.h" 27 #include "vm/scopes.h"
27 #include "vm/timer.h" 28 #include "vm/timer.h"
(...skipping 5001 matching lines...) Expand 10 before | Expand all | Expand 10 after
5029 intptr_t context_level) const { 5030 intptr_t context_level) const {
5030 VariableDescAddr(scope_index)->context_level = Smi::New(context_level); 5031 VariableDescAddr(scope_index)->context_level = Smi::New(context_level);
5031 } 5032 }
5032 5033
5033 5034
5034 const char* ContextScope::ToCString() const { 5035 const char* ContextScope::ToCString() const {
5035 return "ContextScope"; 5036 return "ContextScope";
5036 } 5037 }
5037 5038
5038 5039
5040 const char* Error::ToErrorCString() const {
5041 UNREACHABLE();
5042 return "Internal Error";
5043 }
5044
5045
5039 const char* Error::ToCString() const { 5046 const char* Error::ToCString() const {
5040 // Error is an abstract class. We should never reach here. 5047 // Error is an abstract class. We should never reach here.
5041 UNREACHABLE(); 5048 UNREACHABLE();
5042 return "Error"; 5049 return "Error";
5043 } 5050 }
5044 5051
5045 5052
5046 RawApiError* ApiError::New(const String& message, Heap::Space space) { 5053 RawApiError* ApiError::New(const String& message, Heap::Space space) {
5047 const Class& cls = Class::Handle(Object::api_error_class()); 5054 const Class& cls = Class::Handle(Object::api_error_class());
5048 ApiError& result = ApiError::Handle(); 5055 ApiError& result = ApiError::Handle();
5049 { 5056 {
5050 RawObject* raw = Object::Allocate(cls, 5057 RawObject* raw = Object::Allocate(cls,
5051 ApiError::InstanceSize(), 5058 ApiError::InstanceSize(),
5052 space); 5059 space);
5053 NoGCScope no_gc; 5060 NoGCScope no_gc;
5054 result ^= raw; 5061 result ^= raw;
5055 } 5062 }
5056 result.set_message(message); 5063 result.set_message(message);
5057 return result.raw(); 5064 return result.raw();
5058 } 5065 }
5059 5066
5060 5067
5061 void ApiError::set_message(const String& message) const { 5068 void ApiError::set_message(const String& message) const {
5062 StorePointer(&raw_ptr()->message_, message.raw()); 5069 StorePointer(&raw_ptr()->message_, message.raw());
5063 } 5070 }
5064 5071
5065 5072
5073 const char* ApiError::ToErrorCString() const {
5074 const String& msg_str = String::Handle(message());
5075 return msg_str.ToCString();
5076 }
5077
5078
5066 const char* ApiError::ToCString() const { 5079 const char* ApiError::ToCString() const {
5067 return "ApiError"; 5080 return "ApiError";
5068 } 5081 }
5069 5082
5070 5083
5071 RawLanguageError* LanguageError::New(const String& message, Heap::Space space) { 5084 RawLanguageError* LanguageError::New(const String& message, Heap::Space space) {
5072 const Class& cls = Class::Handle(Object::language_error_class()); 5085 const Class& cls = Class::Handle(Object::language_error_class());
5073 LanguageError& result = LanguageError::Handle(); 5086 LanguageError& result = LanguageError::Handle();
5074 { 5087 {
5075 RawObject* raw = Object::Allocate(cls, 5088 RawObject* raw = Object::Allocate(cls,
5076 LanguageError::InstanceSize(), 5089 LanguageError::InstanceSize(),
5077 space); 5090 space);
5078 NoGCScope no_gc; 5091 NoGCScope no_gc;
5079 result ^= raw; 5092 result ^= raw;
5080 } 5093 }
5081 result.set_message(message); 5094 result.set_message(message);
5082 return result.raw(); 5095 return result.raw();
5083 } 5096 }
5084 5097
5085 5098
5086 void LanguageError::set_message(const String& message) const { 5099 void LanguageError::set_message(const String& message) const {
5087 StorePointer(&raw_ptr()->message_, message.raw()); 5100 StorePointer(&raw_ptr()->message_, message.raw());
5088 } 5101 }
5089 5102
5090 5103
5104 const char* LanguageError::ToErrorCString() const {
5105 const String& msg_str = String::Handle(message());
5106 return msg_str.ToCString();
5107 }
5108
5109
5091 const char* LanguageError::ToCString() const { 5110 const char* LanguageError::ToCString() const {
5092 return "LanguageError"; 5111 return "LanguageError";
5093 } 5112 }
5094 5113
5095 5114
5096 RawUnhandledException* UnhandledException::New(const Instance& exception, 5115 RawUnhandledException* UnhandledException::New(const Instance& exception,
5097 const Instance& stacktrace, 5116 const Instance& stacktrace,
5098 Heap::Space space) { 5117 Heap::Space space) {
5099 const Class& cls = Class::Handle(Object::unhandled_exception_class()); 5118 const Class& cls = Class::Handle(Object::unhandled_exception_class());
5100 UnhandledException& result = UnhandledException::Handle(); 5119 UnhandledException& result = UnhandledException::Handle();
(...skipping 13 matching lines...) Expand all
5114 void UnhandledException::set_exception(const Instance& exception) const { 5133 void UnhandledException::set_exception(const Instance& exception) const {
5115 StorePointer(&raw_ptr()->exception_, exception.raw()); 5134 StorePointer(&raw_ptr()->exception_, exception.raw());
5116 } 5135 }
5117 5136
5118 5137
5119 void UnhandledException::set_stacktrace(const Instance& stacktrace) const { 5138 void UnhandledException::set_stacktrace(const Instance& stacktrace) const {
5120 StorePointer(&raw_ptr()->stacktrace_, stacktrace.raw()); 5139 StorePointer(&raw_ptr()->stacktrace_, stacktrace.raw());
5121 } 5140 }
5122 5141
5123 5142
5143 const char* UnhandledException::ToErrorCString() const {
5144 Isolate* isolate = Isolate::Current();
5145 HANDLESCOPE(isolate);
5146 Object& strtmp = Object::Handle();
5147
5148 const Instance& exc = Instance::Handle(exception());
5149 strtmp = DartLibraryCalls::ToString(exc);
5150 const char* exc_str =
5151 "<Received error while converting exception to string>";
5152 if (!strtmp.IsError()) {
5153 exc_str = strtmp.ToCString();
5154 }
5155 const Instance& stack = Instance::Handle(stacktrace());
5156 strtmp = DartLibraryCalls::ToString(stack);
5157 const char* stack_str =
5158 "<Received error while converting stack trace to string>";
5159 if (!strtmp.IsError()) {
5160 stack_str = strtmp.ToCString();
5161 }
5162
5163 const char* format = "Unhandled exception:\n%s\n%s";
5164 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format)
5165 - 4 // Two '%s'
5166 + 1); // '\0'
5167 char* chars = reinterpret_cast<char*>(isolate->current_zone()->Allocate(len));
5168 OS::SNPrint(chars, len, format, exc_str, stack_str);
5169 return chars;
5170 }
5171
5172
5124 const char* UnhandledException::ToCString() const { 5173 const char* UnhandledException::ToCString() const {
5125 return "UnhandledException"; 5174 return "UnhandledException";
5126 } 5175 }
5127 5176
5128 5177
5129 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { 5178 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) {
5130 const Class& cls = Class::Handle(Object::unwind_error_class()); 5179 const Class& cls = Class::Handle(Object::unwind_error_class());
5131 UnwindError& result = UnwindError::Handle(); 5180 UnwindError& result = UnwindError::Handle();
5132 { 5181 {
5133 RawObject* raw = Object::Allocate(cls, 5182 RawObject* raw = Object::Allocate(cls,
5134 UnwindError::InstanceSize(), 5183 UnwindError::InstanceSize(),
5135 space); 5184 space);
5136 NoGCScope no_gc; 5185 NoGCScope no_gc;
5137 result ^= raw; 5186 result ^= raw;
5138 } 5187 }
5139 result.set_message(message); 5188 result.set_message(message);
5140 return result.raw(); 5189 return result.raw();
5141 } 5190 }
5142 5191
5143 5192
5144 void UnwindError::set_message(const String& message) const { 5193 void UnwindError::set_message(const String& message) const {
5145 StorePointer(&raw_ptr()->message_, message.raw()); 5194 StorePointer(&raw_ptr()->message_, message.raw());
5146 } 5195 }
5147 5196
5148 5197
5198 const char* UnwindError::ToErrorCString() const {
5199 UNIMPLEMENTED();
5200 return "UnwindError";
5201 }
5202
5203
5149 const char* UnwindError::ToCString() const { 5204 const char* UnwindError::ToCString() const {
5150 return "UnwindError"; 5205 return "UnwindError";
5151 } 5206 }
5152 5207
5153 5208
5154 bool Instance::Equals(const Instance& other) const { 5209 bool Instance::Equals(const Instance& other) const {
5155 if (this->raw() == other.raw()) { 5210 if (this->raw() == other.raw()) {
5156 return true; // "===". 5211 return true; // "===".
5157 } 5212 }
5158 5213
(...skipping 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after
7554 const String& str = String::Handle(pattern()); 7609 const String& str = String::Handle(pattern());
7555 const char* format = "JSRegExp: pattern=%s flags=%s"; 7610 const char* format = "JSRegExp: pattern=%s flags=%s";
7556 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7611 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
7557 char* chars = reinterpret_cast<char*>( 7612 char* chars = reinterpret_cast<char*>(
7558 Isolate::Current()->current_zone()->Allocate(len + 1)); 7613 Isolate::Current()->current_zone()->Allocate(len + 1));
7559 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7614 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
7560 return chars; 7615 return chars;
7561 } 7616 }
7562 7617
7563 } // namespace dart 7618 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698