OLD | NEW |
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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 #include "vm/exceptions.h" | 6 #include "vm/exceptions.h" |
7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
8 #include "vm/runtime_entry.h" | 8 #include "vm/runtime_entry.h" |
9 #include "vm/stack_frame.h" | 9 #include "vm/stack_frame.h" |
10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 ASSERT(!hit_assertion_error); | 52 ASSERT(!hit_assertion_error); |
53 hit_assertion_error = (func.Owner() == assert_error_class.raw()); | 53 hit_assertion_error = (func.Owner() == assert_error_class.raw()); |
54 } | 54 } |
55 stack_frame = iterator->NextFrame(); | 55 stack_frame = iterator->NextFrame(); |
56 } | 56 } |
57 UNREACHABLE(); | 57 UNREACHABLE(); |
58 return Script::null(); | 58 return Script::null(); |
59 } | 59 } |
60 | 60 |
61 | |
62 // Allocate and throw a new AssertionError. | 61 // Allocate and throw a new AssertionError. |
63 // Arg0: index of the first token of the failed assertion. | 62 // Arg0: index of the first token of the failed assertion. |
64 // Arg1: index of the first token after the failed assertion. | 63 // Arg1: index of the first token after the failed assertion. |
65 // Arg2: Message object or null. | 64 // Arg2: Message object or null. |
66 // Return value: none, throws an exception. | 65 // Return value: none, throws an exception. |
67 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 3) { | 66 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 3) { |
68 // No need to type check the arguments. This function can only be called | 67 // No need to type check the arguments. This function can only be called |
69 // internally from the VM. | 68 // internally from the VM. |
70 const TokenPosition assertion_start = | 69 const TokenPosition assertion_start = |
71 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); | 70 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); |
(...skipping 23 matching lines...) Expand all Loading... |
95 args.SetAt(1, String::Handle(script.url())); | 94 args.SetAt(1, String::Handle(script.url())); |
96 args.SetAt(2, Smi::Handle(Smi::New(from_line))); | 95 args.SetAt(2, Smi::Handle(Smi::New(from_line))); |
97 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1))); | 96 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1))); |
98 args.SetAt(4, message); | 97 args.SetAt(4, message); |
99 | 98 |
100 Exceptions::ThrowByType(Exceptions::kAssertion, args); | 99 Exceptions::ThrowByType(Exceptions::kAssertion, args); |
101 UNREACHABLE(); | 100 UNREACHABLE(); |
102 return Object::null(); | 101 return Object::null(); |
103 } | 102 } |
104 | 103 |
105 | |
106 // Allocate and throw a new TypeError or CastError. | 104 // Allocate and throw a new TypeError or CastError. |
107 // Arg0: index of the token of the failed type check. | 105 // Arg0: index of the token of the failed type check. |
108 // Arg1: src value. | 106 // Arg1: src value. |
109 // Arg2: dst type. | 107 // Arg2: dst type. |
110 // Arg3: dst name. | 108 // Arg3: dst name. |
111 // Arg4: type error message. | 109 // Arg4: type error message. |
112 // Return value: none, throws an exception. | 110 // Return value: none, throws an exception. |
113 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { | 111 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { |
114 // No need to type check the arguments. This function can only be called | 112 // No need to type check the arguments. This function can only be called |
115 // internally from the VM. | 113 // internally from the VM. |
116 const TokenPosition location = | 114 const TokenPosition location = |
117 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); | 115 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); |
118 const Instance& src_value = | 116 const Instance& src_value = |
119 Instance::CheckedHandle(arguments->NativeArgAt(1)); | 117 Instance::CheckedHandle(arguments->NativeArgAt(1)); |
120 const AbstractType& dst_type = | 118 const AbstractType& dst_type = |
121 AbstractType::CheckedHandle(arguments->NativeArgAt(2)); | 119 AbstractType::CheckedHandle(arguments->NativeArgAt(2)); |
122 const String& dst_name = String::CheckedHandle(arguments->NativeArgAt(3)); | 120 const String& dst_name = String::CheckedHandle(arguments->NativeArgAt(3)); |
123 const String& error_msg = String::CheckedHandle(arguments->NativeArgAt(4)); | 121 const String& error_msg = String::CheckedHandle(arguments->NativeArgAt(4)); |
124 const AbstractType& src_type = | 122 const AbstractType& src_type = |
125 AbstractType::Handle(src_value.GetType(Heap::kNew)); | 123 AbstractType::Handle(src_value.GetType(Heap::kNew)); |
126 Exceptions::CreateAndThrowTypeError(location, src_type, dst_type, dst_name, | 124 Exceptions::CreateAndThrowTypeError(location, src_type, dst_type, dst_name, |
127 error_msg); | 125 error_msg); |
128 UNREACHABLE(); | 126 UNREACHABLE(); |
129 return Object::null(); | 127 return Object::null(); |
130 } | 128 } |
131 | 129 |
132 | |
133 // Allocate and throw a new FallThroughError. | 130 // Allocate and throw a new FallThroughError. |
134 // Arg0: index of the case clause token into which we fall through. | 131 // Arg0: index of the case clause token into which we fall through. |
135 // Return value: none, throws an exception. | 132 // Return value: none, throws an exception. |
136 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { | 133 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { |
137 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 134 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
138 TokenPosition fallthrough_pos = TokenPosition(smi_pos.Value()); | 135 TokenPosition fallthrough_pos = TokenPosition(smi_pos.Value()); |
139 | 136 |
140 const Array& args = Array::Handle(Array::New(2)); | 137 const Array& args = Array::Handle(Array::New(2)); |
141 | 138 |
142 // Initialize 'url' and 'line' arguments. | 139 // Initialize 'url' and 'line' arguments. |
143 DartFrameIterator iterator(thread, | 140 DartFrameIterator iterator(thread, |
144 StackFrameIterator::kNoCrossThreadIteration); | 141 StackFrameIterator::kNoCrossThreadIteration); |
145 iterator.NextFrame(); // Skip native call. | 142 iterator.NextFrame(); // Skip native call. |
146 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 143 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
147 args.SetAt(0, String::Handle(script.url())); | 144 args.SetAt(0, String::Handle(script.url())); |
148 intptr_t line; | 145 intptr_t line; |
149 script.GetTokenLocation(fallthrough_pos, &line, NULL); | 146 script.GetTokenLocation(fallthrough_pos, &line, NULL); |
150 args.SetAt(1, Smi::Handle(Smi::New(line))); | 147 args.SetAt(1, Smi::Handle(Smi::New(line))); |
151 | 148 |
152 Exceptions::ThrowByType(Exceptions::kFallThrough, args); | 149 Exceptions::ThrowByType(Exceptions::kFallThrough, args); |
153 UNREACHABLE(); | 150 UNREACHABLE(); |
154 return Object::null(); | 151 return Object::null(); |
155 } | 152 } |
156 | 153 |
157 | |
158 // Allocate and throw a new AbstractClassInstantiationError. | 154 // Allocate and throw a new AbstractClassInstantiationError. |
159 // Arg0: Token position of allocation statement. | 155 // Arg0: Token position of allocation statement. |
160 // Arg1: class name of the abstract class that cannot be instantiated. | 156 // Arg1: class name of the abstract class that cannot be instantiated. |
161 // Return value: none, throws an exception. | 157 // Return value: none, throws an exception. |
162 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { | 158 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { |
163 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 159 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
164 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); | 160 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); |
165 TokenPosition error_pos = TokenPosition(smi_pos.Value()); | 161 TokenPosition error_pos = TokenPosition(smi_pos.Value()); |
166 | 162 |
167 const Array& args = Array::Handle(Array::New(3)); | 163 const Array& args = Array::Handle(Array::New(3)); |
(...skipping 16 matching lines...) Expand all Loading... |
184 | 180 |
185 // Rethrow an error with a stacktrace. | 181 // Rethrow an error with a stacktrace. |
186 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { | 182 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { |
187 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); | 183 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); |
188 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); | 184 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); |
189 Exceptions::ReThrow(thread, error, stacktrace); | 185 Exceptions::ReThrow(thread, error, stacktrace); |
190 return Object::null(); | 186 return Object::null(); |
191 } | 187 } |
192 | 188 |
193 } // namespace dart | 189 } // namespace dart |
OLD | NEW |