| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 61 |
| 62 // Allocate and throw a new AssertionError. | 62 // Allocate and throw a new AssertionError. |
| 63 // Arg0: index of the first token of the failed assertion. | 63 // Arg0: index of the first token of the failed assertion. |
| 64 // Arg1: index of the first token after the failed assertion. | 64 // Arg1: index of the first token after the failed assertion. |
| 65 // Arg2: Message object or null. |
| 65 // Return value: none, throws an exception. | 66 // Return value: none, throws an exception. |
| 66 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { | 67 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 3) { |
| 67 // 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 |
| 68 // internally from the VM. | 69 // internally from the VM. |
| 69 const TokenPosition assertion_start = | 70 const TokenPosition assertion_start = |
| 70 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); | 71 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); |
| 71 const TokenPosition assertion_end = | 72 const TokenPosition assertion_end = |
| 72 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); | 73 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); |
| 73 | 74 |
| 74 const Array& args = Array::Handle(Array::New(4)); | 75 const Instance& message = Instance::CheckedHandle(arguments->NativeArgAt(2)); |
| 76 const Array& args = Array::Handle(Array::New(5)); |
| 75 | 77 |
| 76 DartFrameIterator iterator; | 78 DartFrameIterator iterator; |
| 77 iterator.NextFrame(); // Skip native call. | 79 iterator.NextFrame(); // Skip native call. |
| 78 const Script& script = Script::Handle(FindScript(&iterator)); | 80 const Script& script = Script::Handle(FindScript(&iterator)); |
| 79 | 81 |
| 80 // Initialize argument 'failed_assertion' with source snippet. | 82 // Initialize argument 'failed_assertion' with source snippet. |
| 81 intptr_t from_line, from_column; | 83 intptr_t from_line, from_column; |
| 82 script.GetTokenLocation(assertion_start, &from_line, &from_column); | 84 script.GetTokenLocation(assertion_start, &from_line, &from_column); |
| 83 intptr_t to_line, to_column; | 85 intptr_t to_line, to_column; |
| 84 script.GetTokenLocation(assertion_end, &to_line, &to_column); | 86 script.GetTokenLocation(assertion_end, &to_line, &to_column); |
| 85 // The snippet will extract the correct assertion code even if the source | 87 // The snippet will extract the correct assertion code even if the source |
| 86 // is generated. | 88 // is generated. |
| 87 args.SetAt(0, String::Handle(script.GetSnippet(from_line, from_column, | 89 args.SetAt(0, String::Handle(script.GetSnippet(from_line, from_column, |
| 88 to_line, to_column))); | 90 to_line, to_column))); |
| 89 | 91 |
| 90 // Initialize location arguments starting at position 1. | 92 // Initialize location arguments starting at position 1. |
| 91 // Do not set a column if the source has been generated as it will be wrong. | 93 // Do not set a column if the source has been generated as it will be wrong. |
| 92 args.SetAt(1, String::Handle(script.url())); | 94 args.SetAt(1, String::Handle(script.url())); |
| 93 args.SetAt(2, Smi::Handle(Smi::New(from_line))); | 95 args.SetAt(2, Smi::Handle(Smi::New(from_line))); |
| 94 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))); |
| 97 args.SetAt(4, message); |
| 95 | 98 |
| 96 Exceptions::ThrowByType(Exceptions::kAssertion, args); | 99 Exceptions::ThrowByType(Exceptions::kAssertion, args); |
| 97 UNREACHABLE(); | 100 UNREACHABLE(); |
| 98 return Object::null(); | 101 return Object::null(); |
| 99 } | 102 } |
| 100 | 103 |
| 101 | 104 |
| 102 // Allocate and throw a new TypeError or CastError. | 105 // Allocate and throw a new TypeError or CastError. |
| 103 // Arg0: index of the token of the failed type check. | 106 // Arg0: index of the token of the failed type check. |
| 104 // Arg1: src value. | 107 // Arg1: src value. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 181 |
| 179 // Rethrow an error with a stacktrace. | 182 // Rethrow an error with a stacktrace. |
| 180 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { | 183 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { |
| 181 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); | 184 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); |
| 182 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); | 185 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); |
| 183 Exceptions::ReThrow(thread, error, stacktrace); | 186 Exceptions::ReThrow(thread, error, stacktrace); |
| 184 return Object::null(); | 187 return Object::null(); |
| 185 } | 188 } |
| 186 | 189 |
| 187 } // namespace dart | 190 } // namespace dart |
| OLD | NEW |