| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // No need to type check the arguments. This function can only be called | 68 // No need to type check the arguments. This function can only be called |
| 69 // internally from the VM. | 69 // internally from the VM. |
| 70 const TokenPosition assertion_start = | 70 const TokenPosition assertion_start = |
| 71 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); | 71 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); |
| 72 const TokenPosition assertion_end = | 72 const TokenPosition assertion_end = |
| 73 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); | 73 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); |
| 74 | 74 |
| 75 const Instance& message = Instance::CheckedHandle(arguments->NativeArgAt(2)); | 75 const Instance& message = Instance::CheckedHandle(arguments->NativeArgAt(2)); |
| 76 const Array& args = Array::Handle(Array::New(5)); | 76 const Array& args = Array::Handle(Array::New(5)); |
| 77 | 77 |
| 78 DartFrameIterator iterator; | 78 DartFrameIterator iterator(thread, |
| 79 StackFrameIterator::kNoCrossThreadIteration); |
| 79 iterator.NextFrame(); // Skip native call. | 80 iterator.NextFrame(); // Skip native call. |
| 80 const Script& script = Script::Handle(FindScript(&iterator)); | 81 const Script& script = Script::Handle(FindScript(&iterator)); |
| 81 | 82 |
| 82 // Initialize argument 'failed_assertion' with source snippet. | 83 // Initialize argument 'failed_assertion' with source snippet. |
| 83 intptr_t from_line, from_column; | 84 intptr_t from_line, from_column; |
| 84 script.GetTokenLocation(assertion_start, &from_line, &from_column); | 85 script.GetTokenLocation(assertion_start, &from_line, &from_column); |
| 85 intptr_t to_line, to_column; | 86 intptr_t to_line, to_column; |
| 86 script.GetTokenLocation(assertion_end, &to_line, &to_column); | 87 script.GetTokenLocation(assertion_end, &to_line, &to_column); |
| 87 // The snippet will extract the correct assertion code even if the source | 88 // The snippet will extract the correct assertion code even if the source |
| 88 // is generated. | 89 // is generated. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // Allocate and throw a new FallThroughError. | 133 // Allocate and throw a new FallThroughError. |
| 133 // Arg0: index of the case clause token into which we fall through. | 134 // Arg0: index of the case clause token into which we fall through. |
| 134 // Return value: none, throws an exception. | 135 // Return value: none, throws an exception. |
| 135 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { | 136 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { |
| 136 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 137 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
| 137 TokenPosition fallthrough_pos = TokenPosition(smi_pos.Value()); | 138 TokenPosition fallthrough_pos = TokenPosition(smi_pos.Value()); |
| 138 | 139 |
| 139 const Array& args = Array::Handle(Array::New(2)); | 140 const Array& args = Array::Handle(Array::New(2)); |
| 140 | 141 |
| 141 // Initialize 'url' and 'line' arguments. | 142 // Initialize 'url' and 'line' arguments. |
| 142 DartFrameIterator iterator; | 143 DartFrameIterator iterator(thread, |
| 144 StackFrameIterator::kNoCrossThreadIteration); |
| 143 iterator.NextFrame(); // Skip native call. | 145 iterator.NextFrame(); // Skip native call. |
| 144 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 146 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
| 145 args.SetAt(0, String::Handle(script.url())); | 147 args.SetAt(0, String::Handle(script.url())); |
| 146 intptr_t line; | 148 intptr_t line; |
| 147 script.GetTokenLocation(fallthrough_pos, &line, NULL); | 149 script.GetTokenLocation(fallthrough_pos, &line, NULL); |
| 148 args.SetAt(1, Smi::Handle(Smi::New(line))); | 150 args.SetAt(1, Smi::Handle(Smi::New(line))); |
| 149 | 151 |
| 150 Exceptions::ThrowByType(Exceptions::kFallThrough, args); | 152 Exceptions::ThrowByType(Exceptions::kFallThrough, args); |
| 151 UNREACHABLE(); | 153 UNREACHABLE(); |
| 152 return Object::null(); | 154 return Object::null(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 | 157 |
| 156 // Allocate and throw a new AbstractClassInstantiationError. | 158 // Allocate and throw a new AbstractClassInstantiationError. |
| 157 // Arg0: Token position of allocation statement. | 159 // Arg0: Token position of allocation statement. |
| 158 // Arg1: class name of the abstract class that cannot be instantiated. | 160 // Arg1: class name of the abstract class that cannot be instantiated. |
| 159 // Return value: none, throws an exception. | 161 // Return value: none, throws an exception. |
| 160 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { | 162 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { |
| 161 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 163 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
| 162 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); | 164 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); |
| 163 TokenPosition error_pos = TokenPosition(smi_pos.Value()); | 165 TokenPosition error_pos = TokenPosition(smi_pos.Value()); |
| 164 | 166 |
| 165 const Array& args = Array::Handle(Array::New(3)); | 167 const Array& args = Array::Handle(Array::New(3)); |
| 166 | 168 |
| 167 // Initialize 'className', 'url' and 'line' arguments. | 169 // Initialize 'className', 'url' and 'line' arguments. |
| 168 DartFrameIterator iterator; | 170 DartFrameIterator iterator(thread, |
| 171 StackFrameIterator::kNoCrossThreadIteration); |
| 169 iterator.NextFrame(); // Skip native call. | 172 iterator.NextFrame(); // Skip native call. |
| 170 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 173 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
| 171 args.SetAt(0, class_name); | 174 args.SetAt(0, class_name); |
| 172 args.SetAt(1, String::Handle(script.url())); | 175 args.SetAt(1, String::Handle(script.url())); |
| 173 intptr_t line; | 176 intptr_t line; |
| 174 script.GetTokenLocation(error_pos, &line, NULL); | 177 script.GetTokenLocation(error_pos, &line, NULL); |
| 175 args.SetAt(2, Smi::Handle(Smi::New(line))); | 178 args.SetAt(2, Smi::Handle(Smi::New(line))); |
| 176 | 179 |
| 177 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); | 180 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); |
| 178 UNREACHABLE(); | 181 UNREACHABLE(); |
| 179 return Object::null(); | 182 return Object::null(); |
| 180 } | 183 } |
| 181 | 184 |
| 182 // Rethrow an error with a stacktrace. | 185 // Rethrow an error with a stacktrace. |
| 183 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { | 186 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { |
| 184 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); | 187 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); |
| 185 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); | 188 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); |
| 186 Exceptions::ReThrow(thread, error, stacktrace); | 189 Exceptions::ReThrow(thread, error, stacktrace); |
| 187 return Object::null(); | 190 return Object::null(); |
| 188 } | 191 } |
| 189 | 192 |
| 190 } // namespace dart | 193 } // namespace dart |
| OLD | NEW |