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

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

Issue 10916039: Throw AbstractClassInstantiationError if an abstract class is instantiated (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « lib/core/errors.dart ('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"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Exceptions::SetField(fallthrough_error, cls, "line", 98 Exceptions::SetField(fallthrough_error, cls, "line",
99 Smi::Handle(Smi::New(line))); 99 Smi::Handle(Smi::New(line)));
100 100
101 // Throw FallThroughError instance. 101 // Throw FallThroughError instance.
102 Exceptions::Throw(fallthrough_error); 102 Exceptions::Throw(fallthrough_error);
103 UNREACHABLE(); 103 UNREACHABLE();
104 return Object::null(); 104 return Object::null();
105 } 105 }
106 106
107 107
108 // Allocate and throw a new AbstractClassInstantiationError.
109 // Arg0: Token position of allocation statement.
110 // Arg1: class name of the abstract class that cannot be instantiated.
111 // Return value: none, throws an exception.
112 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) {
113 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0));
114 GET_NATIVE_ARGUMENT(String, class_name, arguments->At(1));
115 intptr_t error_pos = smi_pos.Value();
116
117 // Allocate a new instance of type AbstractClassInstantiationError.
118 const Instance& error = Instance::Handle(Exceptions::NewInstance(
119 "AbstractClassInstantiationErrorImplementation"));
120 ASSERT(!error.IsNull());
121
122 // Initialize 'url', 'line' and 'className' fields.
123 DartFrameIterator iterator;
124 iterator.NextFrame(); // Skip native call.
125 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
126 const Class& cls = Class::Handle(error.clazz());
127 Exceptions::SetField(error, cls, "url", String::Handle(script.url()));
128 intptr_t line, column;
129 script.GetTokenLocation(error_pos, &line, &column);
130 Exceptions::SetField(error, cls, "line", Smi::Handle(Smi::New(line)));
131 Exceptions::SetField(error, cls, "className", class_name);
132
133 // Throw AbstractClassInstantiationError instance.
134 Exceptions::Throw(error);
135 UNREACHABLE();
136 return Object::null();
137 }
138
139
108 // Allocate and throw StaticResolutionException. 140 // Allocate and throw StaticResolutionException.
109 // Arg0: index of the static call that was not resolved at compile time. 141 // Arg0: index of the static call that was not resolved at compile time.
110 // Return value: none, throws an exception. 142 // Return value: none, throws an exception.
111 DEFINE_NATIVE_ENTRY(StaticResolutionException_throwNew, 1) { 143 DEFINE_NATIVE_ENTRY(StaticResolutionException_throwNew, 1) {
112 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 144 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0));
113 intptr_t call_pos = smi_pos.Value(); 145 intptr_t call_pos = smi_pos.Value();
114 // Allocate a new instance of type StaticResolutionException. 146 // Allocate a new instance of type StaticResolutionException.
115 const Instance& resolution_exception = 147 const Instance& resolution_exception =
116 Instance::Handle(Exceptions::NewInstance("StaticResolutionException")); 148 Instance::Handle(Exceptions::NewInstance("StaticResolutionException"));
117 ASSERT(!resolution_exception.IsNull()); 149 ASSERT(!resolution_exception.IsNull());
118 150
119 // Initialize 'url', 'line', and 'column' fields. 151 // Initialize 'url', 'line', and 'column' fields.
120 DartFrameIterator iterator; 152 DartFrameIterator iterator;
121 iterator.NextFrame(); // Skip native call. 153 iterator.NextFrame(); // Skip native call.
122 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 154 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
123 const Class& cls = Class::Handle(resolution_exception.clazz()); 155 const Class& cls = Class::Handle(resolution_exception.clazz());
124 Exceptions::SetLocationFields(resolution_exception, cls, script, call_pos); 156 Exceptions::SetLocationFields(resolution_exception, cls, script, call_pos);
125 157
126 intptr_t line, column; 158 intptr_t line, column;
127 script.GetTokenLocation(call_pos, &line, &column); 159 script.GetTokenLocation(call_pos, &line, &column);
128 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine", 160 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine",
129 String::Handle(script.GetLine(line))); 161 String::Handle(script.GetLine(line)));
130 162
131 Exceptions::Throw(resolution_exception); 163 Exceptions::Throw(resolution_exception);
132 UNREACHABLE(); 164 UNREACHABLE();
133 return Object::null(); 165 return Object::null();
134 } 166 }
135 167
136 } // namespace dart 168 } // namespace dart
OLDNEW
« no previous file with comments | « lib/core/errors.dart ('k') | runtime/lib/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698