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 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 DECLARE_FLAG(bool, abort_on_assertion_errors); | 13 DECLARE_FLAG(bool, abort_on_assertion_errors); |
14 | 14 |
15 // Allocate and throw a new AssertionError. | 15 // Allocate and throw a new AssertionError. |
16 // Arg0: index of the first token of the failed assertion. | 16 // Arg0: index of the first token of the failed assertion. |
17 // Arg1: index of the first token after the failed assertion. | 17 // Arg1: index of the first token after the failed assertion. |
18 // Return value: none, throws an exception. | 18 // Return value: none, throws an exception. |
19 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { | 19 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { |
20 if (FLAG_abort_on_assertion_errors) { | 20 if (FLAG_abort_on_assertion_errors) { |
21 Exceptions::PrintStackTraceAndAbort("an assertion failure"); | 21 Exceptions::PrintStackTraceAndAbort("an assertion failure"); |
22 } | 22 } |
23 | 23 |
24 // No need to type check the arguments. This function can only be called | 24 // No need to type check the arguments. This function can only be called |
25 // internally from the VM. | 25 // internally from the VM. |
26 intptr_t assertion_start = | 26 const TokenPosition assertion_start = |
27 Smi::CheckedHandle(arguments->NativeArgAt(0)).Value(); | 27 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); |
28 intptr_t assertion_end = | 28 const TokenPosition assertion_end = |
29 Smi::CheckedHandle(arguments->NativeArgAt(1)).Value(); | 29 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); |
30 | 30 |
31 const Array& args = Array::Handle(Array::New(4)); | 31 const Array& args = Array::Handle(Array::New(4)); |
32 | 32 |
33 DartFrameIterator iterator; | 33 DartFrameIterator iterator; |
34 iterator.NextFrame(); // Skip native call. | 34 iterator.NextFrame(); // Skip native call. |
35 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 35 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
36 | 36 |
37 // Initialize argument 'failed_assertion' with source snippet. | 37 // Initialize argument 'failed_assertion' with source snippet. |
38 intptr_t from_line, from_column; | 38 intptr_t from_line, from_column; |
39 script.GetTokenLocation(assertion_start, &from_line, &from_column); | 39 script.GetTokenLocation(assertion_start, &from_line, &from_column); |
(...skipping 19 matching lines...) Expand all Loading... |
59 // Allocate and throw a new TypeError or CastError. | 59 // Allocate and throw a new TypeError or CastError. |
60 // Arg0: index of the token of the failed type check. | 60 // Arg0: index of the token of the failed type check. |
61 // Arg1: src value. | 61 // Arg1: src value. |
62 // Arg2: dst type name. | 62 // Arg2: dst type name. |
63 // Arg3: dst name. | 63 // Arg3: dst name. |
64 // Arg4: type error message. | 64 // Arg4: type error message. |
65 // Return value: none, throws an exception. | 65 // Return value: none, throws an exception. |
66 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { | 66 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { |
67 // 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 |
68 // internally from the VM. | 68 // internally from the VM. |
69 intptr_t location = Smi::CheckedHandle(arguments->NativeArgAt(0)).Value(); | 69 const TokenPosition location = |
| 70 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); |
70 const Instance& src_value = | 71 const Instance& src_value = |
71 Instance::CheckedHandle(arguments->NativeArgAt(1)); | 72 Instance::CheckedHandle(arguments->NativeArgAt(1)); |
72 const String& dst_type_name = | 73 const String& dst_type_name = |
73 String::CheckedHandle(arguments->NativeArgAt(2)); | 74 String::CheckedHandle(arguments->NativeArgAt(2)); |
74 const String& dst_name = String::CheckedHandle(arguments->NativeArgAt(3)); | 75 const String& dst_name = String::CheckedHandle(arguments->NativeArgAt(3)); |
75 const String& error_msg = String::CheckedHandle(arguments->NativeArgAt(4)); | 76 const String& error_msg = String::CheckedHandle(arguments->NativeArgAt(4)); |
76 const String& src_type_name = String::Handle( | 77 const String& src_type_name = String::Handle( |
77 AbstractType::Handle(src_value.GetType()).UserVisibleName()); | 78 AbstractType::Handle(src_value.GetType()).UserVisibleName()); |
78 Exceptions::CreateAndThrowTypeError(location, src_type_name, | 79 Exceptions::CreateAndThrowTypeError(location, src_type_name, |
79 dst_type_name, dst_name, error_msg); | 80 dst_type_name, dst_name, error_msg); |
80 UNREACHABLE(); | 81 UNREACHABLE(); |
81 return Object::null(); | 82 return Object::null(); |
82 } | 83 } |
83 | 84 |
84 | 85 |
85 // Allocate and throw a new FallThroughError. | 86 // Allocate and throw a new FallThroughError. |
86 // Arg0: index of the case clause token into which we fall through. | 87 // Arg0: index of the case clause token into which we fall through. |
87 // Return value: none, throws an exception. | 88 // Return value: none, throws an exception. |
88 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { | 89 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { |
89 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 90 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
90 intptr_t fallthrough_pos = smi_pos.Value(); | 91 TokenPosition fallthrough_pos = TokenPosition(smi_pos.Value()); |
91 | 92 |
92 const Array& args = Array::Handle(Array::New(2)); | 93 const Array& args = Array::Handle(Array::New(2)); |
93 | 94 |
94 // Initialize 'url' and 'line' arguments. | 95 // Initialize 'url' and 'line' arguments. |
95 DartFrameIterator iterator; | 96 DartFrameIterator iterator; |
96 iterator.NextFrame(); // Skip native call. | 97 iterator.NextFrame(); // Skip native call. |
97 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 98 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
98 args.SetAt(0, String::Handle(script.url())); | 99 args.SetAt(0, String::Handle(script.url())); |
99 intptr_t line; | 100 intptr_t line; |
100 script.GetTokenLocation(fallthrough_pos, &line, NULL); | 101 script.GetTokenLocation(fallthrough_pos, &line, NULL); |
101 args.SetAt(1, Smi::Handle(Smi::New(line))); | 102 args.SetAt(1, Smi::Handle(Smi::New(line))); |
102 | 103 |
103 Exceptions::ThrowByType(Exceptions::kFallThrough, args); | 104 Exceptions::ThrowByType(Exceptions::kFallThrough, args); |
104 UNREACHABLE(); | 105 UNREACHABLE(); |
105 return Object::null(); | 106 return Object::null(); |
106 } | 107 } |
107 | 108 |
108 | 109 |
109 // Allocate and throw a new AbstractClassInstantiationError. | 110 // Allocate and throw a new AbstractClassInstantiationError. |
110 // Arg0: Token position of allocation statement. | 111 // Arg0: Token position of allocation statement. |
111 // Arg1: class name of the abstract class that cannot be instantiated. | 112 // Arg1: class name of the abstract class that cannot be instantiated. |
112 // Return value: none, throws an exception. | 113 // Return value: none, throws an exception. |
113 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { | 114 DEFINE_NATIVE_ENTRY(AbstractClassInstantiationError_throwNew, 2) { |
114 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); | 115 GET_NON_NULL_NATIVE_ARGUMENT(Smi, smi_pos, arguments->NativeArgAt(0)); |
115 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); | 116 GET_NON_NULL_NATIVE_ARGUMENT(String, class_name, arguments->NativeArgAt(1)); |
116 intptr_t error_pos = smi_pos.Value(); | 117 TokenPosition error_pos = TokenPosition(smi_pos.Value()); |
117 | 118 |
118 const Array& args = Array::Handle(Array::New(3)); | 119 const Array& args = Array::Handle(Array::New(3)); |
119 | 120 |
120 // Initialize 'className', 'url' and 'line' arguments. | 121 // Initialize 'className', 'url' and 'line' arguments. |
121 DartFrameIterator iterator; | 122 DartFrameIterator iterator; |
122 iterator.NextFrame(); // Skip native call. | 123 iterator.NextFrame(); // Skip native call. |
123 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); | 124 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); |
124 args.SetAt(0, class_name); | 125 args.SetAt(0, class_name); |
125 args.SetAt(1, String::Handle(script.url())); | 126 args.SetAt(1, String::Handle(script.url())); |
126 intptr_t line; | 127 intptr_t line; |
127 script.GetTokenLocation(error_pos, &line, NULL); | 128 script.GetTokenLocation(error_pos, &line, NULL); |
128 args.SetAt(2, Smi::Handle(Smi::New(line))); | 129 args.SetAt(2, Smi::Handle(Smi::New(line))); |
129 | 130 |
130 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); | 131 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, args); |
131 UNREACHABLE(); | 132 UNREACHABLE(); |
132 return Object::null(); | 133 return Object::null(); |
133 } | 134 } |
134 | 135 |
135 // Rethrow an error with a stacktrace. | 136 // Rethrow an error with a stacktrace. |
136 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { | 137 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { |
137 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); | 138 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); |
138 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); | 139 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); |
139 Exceptions::ReThrow(thread, error, stacktrace); | 140 Exceptions::ReThrow(thread, error, stacktrace); |
140 return Object::null(); | 141 return Object::null(); |
141 } | 142 } |
142 | 143 |
143 } // namespace dart | 144 } // namespace dart |
OLD | NEW |