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

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

Issue 11049038: Change compile-time errors into dynamic errors in instance creation expression (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 | « no previous file | 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 UNREACHABLE(); 48 UNREACHABLE();
49 return Object::null(); 49 return Object::null();
50 } 50 }
51 51
52 52
53 // Allocate and throw a new TypeError. 53 // Allocate and throw a new TypeError.
54 // Arg0: index of the token of the failed type check. 54 // Arg0: index of the token of the failed type check.
55 // Arg1: src value. 55 // Arg1: src value.
56 // Arg2: dst type name. 56 // Arg2: dst type name.
57 // Arg3: dst name. 57 // Arg3: dst name.
58 // Arg4: malformed type error message. 58 // Arg4: type error message.
59 // Return value: none, throws an exception. 59 // Return value: none, throws an exception.
60 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { 60 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) {
61 // No need to type check the arguments. This function can only be called 61 // No need to type check the arguments. This function can only be called
62 // internally from the VM. 62 // internally from the VM.
63 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value(); 63 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value();
64 const Instance& src_value = Instance::CheckedHandle(arguments->At(1)); 64 const Instance& src_value = Instance::CheckedHandle(arguments->At(1));
65 const String& dst_type_name = String::CheckedHandle(arguments->At(2)); 65 const String& dst_type_name = String::CheckedHandle(arguments->At(2));
66 const String& dst_name = String::CheckedHandle(arguments->At(3)); 66 const String& dst_name = String::CheckedHandle(arguments->At(3));
67 const String& malformed_error = String::CheckedHandle(arguments->At(4)); 67 const String& type_error = String::CheckedHandle(arguments->At(4));
68 const String& src_type_name = 68 const String& src_type_name =
69 String::Handle(Type::Handle(src_value.GetType()).UserVisibleName()); 69 String::Handle(Type::Handle(src_value.GetType()).UserVisibleName());
70 Exceptions::CreateAndThrowTypeError(location, src_type_name, 70 Exceptions::CreateAndThrowTypeError(location, src_type_name,
71 dst_type_name, dst_name, malformed_error); 71 dst_type_name, dst_name, type_error);
72 UNREACHABLE(); 72 UNREACHABLE();
73 return Object::null(); 73 return Object::null();
74 } 74 }
75 75
76 76
77 // Allocate and throw a new FallThroughError. 77 // Allocate and throw a new FallThroughError.
78 // Arg0: index of the case clause token into which we fall through. 78 // Arg0: index of the case clause token into which we fall through.
79 // Return value: none, throws an exception. 79 // Return value: none, throws an exception.
80 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { 80 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) {
81 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 81 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 Exceptions::SetField(error, cls, "line", Smi::Handle(Smi::New(line))); 130 Exceptions::SetField(error, cls, "line", Smi::Handle(Smi::New(line)));
131 Exceptions::SetField(error, cls, "className", class_name); 131 Exceptions::SetField(error, cls, "className", class_name);
132 132
133 // Throw AbstractClassInstantiationError instance. 133 // Throw AbstractClassInstantiationError instance.
134 Exceptions::Throw(error); 134 Exceptions::Throw(error);
135 UNREACHABLE(); 135 UNREACHABLE();
136 return Object::null(); 136 return Object::null();
137 } 137 }
138 138
139 139
140 // Allocate and throw StaticResolutionException. 140 // Allocate and throw NoSuchMethodError.
141 // Arg0: index of the static call that was not resolved at compile time. 141 // Arg0: index of the call that was not resolved at compile time.
142 // Arg1: name of the method that was not resolved at compile time.
142 // Return value: none, throws an exception. 143 // Return value: none, throws an exception.
143 DEFINE_NATIVE_ENTRY(StaticResolutionException_throwNew, 1) { 144 DEFINE_NATIVE_ENTRY(NoSuchMethodError_throwNew, 2) {
144 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 145 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0));
146 GET_NATIVE_ARGUMENT(String, function_name, arguments->At(1));
145 intptr_t call_pos = smi_pos.Value(); 147 intptr_t call_pos = smi_pos.Value();
146 // Allocate a new instance of type StaticResolutionException. 148 // Allocate a new instance of type NoSuchMethodError.
147 const Instance& resolution_exception = 149 const Instance& error = Instance::Handle(
148 Instance::Handle(Exceptions::NewInstance("StaticResolutionException")); 150 Exceptions::NewInstance("NoSuchMethodErrorImplementation"));
149 ASSERT(!resolution_exception.IsNull()); 151 ASSERT(!error.IsNull());
150 152
151 // Initialize 'url', 'line', and 'column' fields. 153 // Initialize 'url', 'line', and 'column' fields.
152 DartFrameIterator iterator; 154 DartFrameIterator iterator;
153 iterator.NextFrame(); // Skip native call. 155 iterator.NextFrame(); // Skip native call.
154 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 156 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
155 const Class& cls = Class::Handle(resolution_exception.clazz()); 157 const Class& cls = Class::Handle(error.clazz());
156 Exceptions::SetLocationFields(resolution_exception, cls, script, call_pos); 158 Exceptions::SetLocationFields(error, cls, script, call_pos);
159 Exceptions::SetField(error, cls, "functionName", function_name);
157 160
158 intptr_t line, column; 161 intptr_t line, column;
159 script.GetTokenLocation(call_pos, &line, &column); 162 script.GetTokenLocation(call_pos, &line, &column);
160 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine", 163 Exceptions::SetField(error, cls, "failedResolutionLine",
161 String::Handle(script.GetLine(line))); 164 String::Handle(script.GetLine(line)));
162 165
163 Exceptions::Throw(resolution_exception); 166 Exceptions::Throw(error);
164 UNREACHABLE(); 167 UNREACHABLE();
165 return Object::null(); 168 return Object::null();
166 } 169 }
167 170
168 } // namespace dart 171 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698