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