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

Side by Side Diff: runtime/lib/error.cc

Issue 19172002: Revert "Cleanup VM error handling." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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/bin/dartutils.cc ('k') | runtime/lib/error.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "lib/error.h" 5 #include "lib/error.h"
6 6
7 #include "vm/bootstrap_natives.h" 7 #include "vm/bootstrap_natives.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/runtime_entry.h" 10 #include "vm/runtime_entry.h"
11 #include "vm/stack_frame.h" 11 #include "vm/stack_frame.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks."); 15 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks.");
16 16
17 // Allocate and throw a new AssertionError. 17 // Allocate and throw a new AssertionError.
18 // Arg0: index of the first token of the failed assertion. 18 // Arg0: index of the first token of the failed assertion.
19 // Arg1: index of the first token after the failed assertion. 19 // Arg1: index of the first token after the failed assertion.
20 // Return value: none, throws an exception. 20 // Return value: none, throws an exception.
21 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { 21 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) {
22 // No need to type check the arguments. This function can only be called 22 // No need to type check the arguments. This function can only be called
23 // internally from the VM. 23 // internally from the VM.
24 intptr_t assertion_start = 24 intptr_t assertion_start =
25 Smi::CheckedHandle(arguments->NativeArgAt(0)).Value(); 25 Smi::CheckedHandle(arguments->NativeArgAt(0)).Value();
26 intptr_t assertion_end = 26 intptr_t assertion_end =
27 Smi::CheckedHandle(arguments->NativeArgAt(1)).Value(); 27 Smi::CheckedHandle(arguments->NativeArgAt(1)).Value();
28 28
29 const Array& args = Array::Handle(Array::New(4)); 29 // Allocate a new instance of type AssertionError.
30 const Instance& assertion_error = Instance::Handle(
31 Exceptions::NewInstance("AssertionErrorImplementation"));
30 32
33 // Initialize 'url', 'line', and 'column' fields.
31 DartFrameIterator iterator; 34 DartFrameIterator iterator;
32 iterator.NextFrame(); // Skip native call. 35 iterator.NextFrame(); // Skip native call.
33 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 36 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
37 const Class& cls = Class::Handle(assertion_error.clazz());
38 Exceptions::SetLocationFields(assertion_error, cls, script, assertion_start);
34 39
35 // Initialize argument 'failed_assertion' with source snippet. 40 // Initialize field 'failed_assertion' with source snippet.
36 intptr_t from_line, from_column; 41 intptr_t from_line, from_column;
37 script.GetTokenLocation(assertion_start, &from_line, &from_column); 42 script.GetTokenLocation(assertion_start, &from_line, &from_column);
38 intptr_t to_line, to_column; 43 intptr_t to_line, to_column;
39 script.GetTokenLocation(assertion_end, &to_line, &to_column); 44 script.GetTokenLocation(assertion_end, &to_line, &to_column);
40 args.SetAt(0, String::Handle( 45 Exceptions::SetField(assertion_error, cls, "failedAssertion", String::Handle(
41 script.GetSnippet(from_line, from_column, to_line, to_column))); 46 script.GetSnippet(from_line, from_column, to_line, to_column)));
42 47
43 // Initialize location arguments starting at position 1. 48 // Throw AssertionError instance.
44 args.SetAt(1, String::Handle(script.url())); 49 Exceptions::Throw(assertion_error);
45 args.SetAt(2, Smi::Handle(Smi::New(from_line)));
46 args.SetAt(3, Smi::Handle(Smi::New(from_column)));
47
48 Exceptions::ThrowByType(Exceptions::kAssertion, args);
49 UNREACHABLE(); 50 UNREACHABLE();
50 return Object::null(); 51 return Object::null();
51 } 52 }
52 53
53 54
54 // Allocate and throw a new TypeError. 55 // Allocate and throw a new TypeError.
55 // Arg0: index of the token of the failed type check. 56 // Arg0: index of the token of the failed type check.
56 // Arg1: src value. 57 // Arg1: src value.
57 // Arg2: dst type name. 58 // Arg2: dst type name.
58 // Arg3: dst name. 59 // Arg3: dst name.
(...skipping 18 matching lines...) Expand all
77 } 78 }
78 79
79 80
80 // Allocate and throw a new FallThroughError. 81 // Allocate and throw a new FallThroughError.
81 // Arg0: index of the case clause token into which we fall through. 82 // Arg0: index of the case clause token into which we fall through.
82 // Return value: none, throws an exception. 83 // Return value: none, throws an exception.
83 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { 84 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) {
84 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); 85 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0));
85 intptr_t fallthrough_pos = smi_pos.Value(); 86 intptr_t fallthrough_pos = smi_pos.Value();
86 87
87 const Array& args = Array::Handle(Array::New(2)); 88 // Allocate a new instance of type FallThroughError.
89 const Instance& fallthrough_error = Instance::Handle(Exceptions::NewInstance(
90 "FallThroughErrorImplementation"));
91 ASSERT(!fallthrough_error.IsNull());
88 92
89 // Initialize 'url' and 'line' arguments. 93 // Initialize 'url' and 'line' fields.
90 DartFrameIterator iterator; 94 DartFrameIterator iterator;
91 iterator.NextFrame(); // Skip native call. 95 iterator.NextFrame(); // Skip native call.
92 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 96 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
93 args.SetAt(0, String::Handle(script.url())); 97 const Class& cls = Class::Handle(fallthrough_error.clazz());
98 Exceptions::SetField(fallthrough_error, cls, "url",
99 String::Handle(script.url()));
94 intptr_t line, column; 100 intptr_t line, column;
95 script.GetTokenLocation(fallthrough_pos, &line, &column); 101 script.GetTokenLocation(fallthrough_pos, &line, &column);
96 args.SetAt(1, Smi::Handle(Smi::New(line))); 102 Exceptions::SetField(fallthrough_error, cls, "line",
103 Smi::Handle(Smi::New(line)));
97 104
98 Exceptions::ThrowByType(Exceptions::kFallThrough, args); 105 // Throw FallThroughError instance.
106 Exceptions::Throw(fallthrough_error);
99 UNREACHABLE(); 107 UNREACHABLE();
100 return Object::null(); 108 return Object::null();
101 } 109 }
102 110
103 111
104 // Allocate and throw a new AbstractClassInstantiationError. 112 // Allocate and throw a new AbstractClassInstantiationError.
105 // Arg0: Token position of allocation statement. 113 // Arg0: Token position of allocation statement.
106 // Arg1: class name of the abstract class that cannot be instantiated. 114 // Arg1: class name of the abstract class that cannot be instantiated.
107 // Return value: none, throws an exception. 115 // Return value: none, throws an exception.
108 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { 116 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) {
109 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); 117 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0));
110 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); 118 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1));
111 intptr_t error_pos = smi_pos.Value(); 119 intptr_t error_pos = smi_pos.Value();
112 120
113 const Array& args = Array::Handle(Array::New(3)); 121 // Allocate a new instance of type AbstractClassInstantiationError.
122 const Instance& error = Instance::Handle(Exceptions::NewInstance(
123 "AbstractClassInstantiationErrorImplementation"));
124 ASSERT(!error.IsNull());
114 125
115 // Initialize 'className', 'url' and 'line' arguments. 126 // Initialize 'url', 'line' and 'className' fields.
116 DartFrameIterator iterator; 127 DartFrameIterator iterator;
117 iterator.NextFrame(); // Skip native call. 128 iterator.NextFrame(); // Skip native call.
118 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 129 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
119 args.SetAt(0, class_name); 130 const Class& cls = Class::Handle(error.clazz());
120 args.SetAt(1, String::Handle(script.url())); 131 Exceptions::SetField(error, cls, "url", String::Handle(script.url()));
121 intptr_t line, column; 132 intptr_t line, column;
122 script.GetTokenLocation(error_pos, &line, &column); 133 script.GetTokenLocation(error_pos, &line, &column);
123 args.SetAt(2, Smi::Handle(Smi::New(line))); 134 Exceptions::SetField(error, cls, "line", Smi::Handle(Smi::New(line)));
135 Exceptions::SetField(error, cls, "className", class_name);
124 136
125 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); 137 // Throw AbstractClassInstantiationError instance.
138 Exceptions::Throw(error);
126 UNREACHABLE(); 139 UNREACHABLE();
127 return Object::null(); 140 return Object::null();
128 } 141 }
129 142
130 } // namespace dart 143 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/lib/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698