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