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

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

Issue 11293290: Fix native argument handling (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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/lib/double.cc ('k') | runtime/lib/growable_array.cc » ('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 = Smi::CheckedHandle(arguments->At(0)).Value(); 24 intptr_t assertion_start =
25 intptr_t assertion_end = Smi::CheckedHandle(arguments->At(1)).Value(); 25 Smi::CheckedHandle(arguments->NativeArgAt(0)).Value();
26 intptr_t assertion_end =
27 Smi::CheckedHandle(arguments->NativeArgAt(1)).Value();
26 28
27 // Allocate a new instance of type AssertionError. 29 // Allocate a new instance of type AssertionError.
28 const Instance& assertion_error = Instance::Handle( 30 const Instance& assertion_error = Instance::Handle(
29 Exceptions::NewInstance("AssertionErrorImplementation")); 31 Exceptions::NewInstance("AssertionErrorImplementation"));
30 32
31 // Initialize 'url', 'line', and 'column' fields. 33 // Initialize 'url', 'line', and 'column' fields.
32 DartFrameIterator iterator; 34 DartFrameIterator iterator;
33 iterator.NextFrame(); // Skip native call. 35 iterator.NextFrame(); // Skip native call.
34 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 36 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
35 const Class& cls = Class::Handle(assertion_error.clazz()); 37 const Class& cls = Class::Handle(assertion_error.clazz());
(...skipping 17 matching lines...) Expand all
53 // Allocate and throw a new TypeError. 55 // Allocate and throw a new TypeError.
54 // Arg0: index of the token of the failed type check. 56 // Arg0: index of the token of the failed type check.
55 // Arg1: src value. 57 // Arg1: src value.
56 // Arg2: dst type name. 58 // Arg2: dst type name.
57 // Arg3: dst name. 59 // Arg3: dst name.
58 // Arg4: type error message. 60 // Arg4: type error message.
59 // Return value: none, throws an exception. 61 // Return value: none, throws an exception.
60 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { 62 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) {
61 // No need to type check the arguments. This function can only be called 63 // No need to type check the arguments. This function can only be called
62 // internally from the VM. 64 // internally from the VM.
63 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value(); 65 intptr_t location = Smi::CheckedHandle(arguments->NativeArgAt(0)).Value();
64 const Instance& src_value = Instance::CheckedHandle(arguments->At(1)); 66 const Instance& src_value =
65 const String& dst_type_name = String::CheckedHandle(arguments->At(2)); 67 Instance::CheckedHandle(arguments->NativeArgAt(1));
66 const String& dst_name = String::CheckedHandle(arguments->At(3)); 68 const String& dst_type_name =
67 const String& type_error = String::CheckedHandle(arguments->At(4)); 69 String::CheckedHandle(arguments->NativeArgAt(2));
70 const String& dst_name = String::CheckedHandle(arguments->NativeArgAt(3));
71 const String& type_error = String::CheckedHandle(arguments->NativeArgAt(4));
68 const String& src_type_name = 72 const String& src_type_name =
69 String::Handle(Type::Handle(src_value.GetType()).UserVisibleName()); 73 String::Handle(Type::Handle(src_value.GetType()).UserVisibleName());
70 Exceptions::CreateAndThrowTypeError(location, src_type_name, 74 Exceptions::CreateAndThrowTypeError(location, src_type_name,
71 dst_type_name, dst_name, type_error); 75 dst_type_name, dst_name, type_error);
72 UNREACHABLE(); 76 UNREACHABLE();
73 return Object::null(); 77 return Object::null();
74 } 78 }
75 79
76 80
77 // Allocate and throw a new FallThroughError. 81 // Allocate and throw a new FallThroughError.
78 // 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.
79 // Return value: none, throws an exception. 83 // Return value: none, throws an exception.
80 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { 84 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) {
81 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 85 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0));
82 intptr_t fallthrough_pos = smi_pos.Value(); 86 intptr_t fallthrough_pos = smi_pos.Value();
83 87
84 // Allocate a new instance of type FallThroughError. 88 // Allocate a new instance of type FallThroughError.
85 const Instance& fallthrough_error = Instance::Handle(Exceptions::NewInstance( 89 const Instance& fallthrough_error = Instance::Handle(Exceptions::NewInstance(
86 "FallThroughErrorImplementation")); 90 "FallThroughErrorImplementation"));
87 ASSERT(!fallthrough_error.IsNull()); 91 ASSERT(!fallthrough_error.IsNull());
88 92
89 // Initialize 'url' and 'line' fields. 93 // Initialize 'url' and 'line' fields.
90 DartFrameIterator iterator; 94 DartFrameIterator iterator;
91 iterator.NextFrame(); // Skip native call. 95 iterator.NextFrame(); // Skip native call.
(...skipping 11 matching lines...) Expand all
103 UNREACHABLE(); 107 UNREACHABLE();
104 return Object::null(); 108 return Object::null();
105 } 109 }
106 110
107 111
108 // Allocate and throw a new AbstractClassInstantiationError. 112 // Allocate and throw a new AbstractClassInstantiationError.
109 // Arg0: Token position of allocation statement. 113 // Arg0: Token position of allocation statement.
110 // Arg1: class name of the abstract class that cannot be instantiated. 114 // Arg1: class name of the abstract class that cannot be instantiated.
111 // Return value: none, throws an exception. 115 // Return value: none, throws an exception.
112 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { 116 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) {
113 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 117 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0));
114 GET_NATIVE_ARGUMENT(String, class_name, arguments->At(1)); 118 GET_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1));
115 intptr_t error_pos = smi_pos.Value(); 119 intptr_t error_pos = smi_pos.Value();
116 120
117 // Allocate a new instance of type AbstractClassInstantiationError. 121 // Allocate a new instance of type AbstractClassInstantiationError.
118 const Instance& error = Instance::Handle(Exceptions::NewInstance( 122 const Instance& error = Instance::Handle(Exceptions::NewInstance(
119 "AbstractClassInstantiationErrorImplementation")); 123 "AbstractClassInstantiationErrorImplementation"));
120 ASSERT(!error.IsNull()); 124 ASSERT(!error.IsNull());
121 125
122 // Initialize 'url', 'line' and 'className' fields. 126 // Initialize 'url', 'line' and 'className' fields.
123 DartFrameIterator iterator; 127 DartFrameIterator iterator;
124 iterator.NextFrame(); // Skip native call. 128 iterator.NextFrame(); // Skip native call.
(...skipping 10 matching lines...) Expand all
135 UNREACHABLE(); 139 UNREACHABLE();
136 return Object::null(); 140 return Object::null();
137 } 141 }
138 142
139 143
140 // Allocate and throw NoSuchMethodError. 144 // Allocate and throw NoSuchMethodError.
141 // Arg0: index of the call that was not resolved at compile time. 145 // 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. 146 // Arg1: name of the method that was not resolved at compile time.
143 // Return value: none, throws an exception. 147 // Return value: none, throws an exception.
144 DEFINE_NATIVE_ENTRY(NoSuchMethodError_throwNew, 2) { 148 DEFINE_NATIVE_ENTRY(NoSuchMethodError_throwNew, 2) {
145 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 149 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0));
146 GET_NATIVE_ARGUMENT(String, function_name, arguments->At(1)); 150 GET_NATIVE_ARGUMENT(String, function_name, arguments->NativeArgAt(1));
147 intptr_t call_pos = smi_pos.Value(); 151 intptr_t call_pos = smi_pos.Value();
148 // Allocate a new instance of type NoSuchMethodError. 152 // Allocate a new instance of type NoSuchMethodError.
149 const Instance& error = Instance::Handle( 153 const Instance& error = Instance::Handle(
150 Exceptions::NewInstance("NoSuchMethodErrorImplementation")); 154 Exceptions::NewInstance("NoSuchMethodErrorImplementation"));
151 ASSERT(!error.IsNull()); 155 ASSERT(!error.IsNull());
152 156
153 // Initialize 'url', 'line', and 'column' fields. 157 // Initialize 'url', 'line', and 'column' fields.
154 DartFrameIterator iterator; 158 DartFrameIterator iterator;
155 iterator.NextFrame(); // Skip native call. 159 iterator.NextFrame(); // Skip native call.
156 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 160 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
157 const Class& cls = Class::Handle(error.clazz()); 161 const Class& cls = Class::Handle(error.clazz());
158 Exceptions::SetLocationFields(error, cls, script, call_pos); 162 Exceptions::SetLocationFields(error, cls, script, call_pos);
159 Exceptions::SetField(error, cls, "functionName", function_name); 163 Exceptions::SetField(error, cls, "functionName", function_name);
160 164
161 intptr_t line, column; 165 intptr_t line, column;
162 script.GetTokenLocation(call_pos, &line, &column); 166 script.GetTokenLocation(call_pos, &line, &column);
163 Exceptions::SetField(error, cls, "failedResolutionLine", 167 Exceptions::SetField(error, cls, "failedResolutionLine",
164 String::Handle(script.GetLine(line))); 168 String::Handle(script.GetLine(line)));
165 169
166 Exceptions::Throw(error); 170 Exceptions::Throw(error);
167 UNREACHABLE(); 171 UNREACHABLE();
168 return Object::null(); 172 return Object::null();
169 } 173 }
170 174
171 } // namespace dart 175 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/double.cc ('k') | runtime/lib/growable_array.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698