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 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 DartFrameIterator iterator; | 29 DartFrameIterator iterator; |
30 iterator.NextFrame(); // Skip native call. | 30 iterator.NextFrame(); // Skip native call. |
31 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 31 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
32 | 32 |
33 // Initialize argument 'failed_assertion' with source snippet. | 33 // Initialize argument 'failed_assertion' with source snippet. |
34 intptr_t from_line, from_column; | 34 intptr_t from_line, from_column; |
35 script.GetTokenLocation(assertion_start, &from_line, &from_column); | 35 script.GetTokenLocation(assertion_start, &from_line, &from_column); |
36 intptr_t to_line, to_column; | 36 intptr_t to_line, to_column; |
37 script.GetTokenLocation(assertion_end, &to_line, &to_column); | 37 script.GetTokenLocation(assertion_end, &to_line, &to_column); |
| 38 // The snippet will extract the correct assertion code even if the source |
| 39 // is generated. |
38 args.SetAt(0, String::Handle( | 40 args.SetAt(0, String::Handle( |
39 script.GetSnippet(from_line, from_column, to_line, to_column))); | 41 script.GetSnippet(from_line, from_column, to_line, to_column))); |
40 | 42 |
41 // Initialize location arguments starting at position 1. | 43 // Initialize location arguments starting at position 1. |
| 44 // Do not set a column if the source has been generated as it will be wrong. |
42 args.SetAt(1, String::Handle(script.url())); | 45 args.SetAt(1, String::Handle(script.url())); |
43 args.SetAt(2, Smi::Handle(Smi::New(from_line))); | 46 args.SetAt(2, Smi::Handle(Smi::New(from_line))); |
44 args.SetAt(3, Smi::Handle(Smi::New(from_column))); | 47 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1))); |
45 | 48 |
46 Exceptions::ThrowByType(Exceptions::kAssertion, args); | 49 Exceptions::ThrowByType(Exceptions::kAssertion, args); |
47 UNREACHABLE(); | 50 UNREACHABLE(); |
48 return Object::null(); | 51 return Object::null(); |
49 } | 52 } |
50 | 53 |
51 | 54 |
52 // Allocate and throw a new TypeError or CastError. | 55 // Allocate and throw a new TypeError or CastError. |
53 // Arg0: index of the token of the failed type check. | 56 // Arg0: index of the token of the failed type check. |
54 // Arg1: src value. | 57 // Arg1: src value. |
(...skipping 27 matching lines...) Expand all Loading... |
82 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 85 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
83 intptr_t fallthrough_pos = smi_pos.Value(); | 86 intptr_t fallthrough_pos = smi_pos.Value(); |
84 | 87 |
85 const Array& args = Array::Handle(Array::New(2)); | 88 const Array& args = Array::Handle(Array::New(2)); |
86 | 89 |
87 // Initialize 'url' and 'line' arguments. | 90 // Initialize 'url' and 'line' arguments. |
88 DartFrameIterator iterator; | 91 DartFrameIterator iterator; |
89 iterator.NextFrame(); // Skip native call. | 92 iterator.NextFrame(); // Skip native call. |
90 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 93 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
91 args.SetAt(0, String::Handle(script.url())); | 94 args.SetAt(0, String::Handle(script.url())); |
92 intptr_t line, column; | 95 intptr_t line; |
93 script.GetTokenLocation(fallthrough_pos, &line, &column); | 96 script.GetTokenLocation(fallthrough_pos, &line, NULL); |
94 args.SetAt(1, Smi::Handle(Smi::New(line))); | 97 args.SetAt(1, Smi::Handle(Smi::New(line))); |
95 | 98 |
96 Exceptions::ThrowByType(Exceptions::kFallThrough, args); | 99 Exceptions::ThrowByType(Exceptions::kFallThrough, 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 AbstractClassInstantiationError. | 105 // Allocate and throw a new AbstractClassInstantiationError. |
103 // Arg0: Token position of allocation statement. | 106 // Arg0: Token position of allocation statement. |
104 // Arg1: class name of the abstract class that cannot be instantiated. | 107 // Arg1: class name of the abstract class that cannot be instantiated. |
105 // Return value: none, throws an exception. | 108 // Return value: none, throws an exception. |
106 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { | 109 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { |
107 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 110 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
108 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); | 111 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); |
109 intptr_t error_pos = smi_pos.Value(); | 112 intptr_t error_pos = smi_pos.Value(); |
110 | 113 |
111 const Array& args = Array::Handle(Array::New(3)); | 114 const Array& args = Array::Handle(Array::New(3)); |
112 | 115 |
113 // Initialize 'className', 'url' and 'line' arguments. | 116 // Initialize 'className', 'url' and 'line' arguments. |
114 DartFrameIterator iterator; | 117 DartFrameIterator iterator; |
115 iterator.NextFrame(); // Skip native call. | 118 iterator.NextFrame(); // Skip native call. |
116 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 119 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
117 args.SetAt(0, class_name); | 120 args.SetAt(0, class_name); |
118 args.SetAt(1, String::Handle(script.url())); | 121 args.SetAt(1, String::Handle(script.url())); |
119 intptr_t line, column; | 122 intptr_t line; |
120 script.GetTokenLocation(error_pos, &line, &column); | 123 script.GetTokenLocation(error_pos, &line, NULL); |
121 args.SetAt(2, Smi::Handle(Smi::New(line))); | 124 args.SetAt(2, Smi::Handle(Smi::New(line))); |
122 | 125 |
123 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); | 126 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); |
124 UNREACHABLE(); | 127 UNREACHABLE(); |
125 return Object::null(); | 128 return Object::null(); |
126 } | 129 } |
127 | 130 |
128 } // namespace dart | 131 } // namespace dart |
OLD | NEW |