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 "lib/error.h" | 5 #include "lib/error.h" |
6 | 6 |
7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 #include "vm/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
11 #include "vm/stack_frame.h" | 11 #include "vm/stack_frame.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks."); | 15 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks."); |
16 | 16 |
17 // Allocate and throw a new AssertionError. | 17 // Allocate and throw a new AssertionError. |
18 // Arg0: index of the first token of the failed assertion. | 18 // Arg0: index of the first token of the failed assertion. |
19 // Arg1: index of the first token after the failed assertion. | 19 // Arg1: index of the first token after the failed assertion. |
20 // Return value: none, throws an exception. | 20 // Return value: none, throws an exception. |
21 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { | 21 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { |
| 22 // No need to type check the arguments. This function can only be called |
| 23 // internally from the VM. |
22 intptr_t assertion_start = Smi::CheckedHandle(arguments->At(0)).Value(); | 24 intptr_t assertion_start = Smi::CheckedHandle(arguments->At(0)).Value(); |
23 intptr_t assertion_end = Smi::CheckedHandle(arguments->At(1)).Value(); | 25 intptr_t assertion_end = Smi::CheckedHandle(arguments->At(1)).Value(); |
24 | 26 |
25 // Allocate a new instance of type AssertionError. | 27 // Allocate a new instance of type AssertionError. |
26 const Instance& assertion_error = Instance::Handle( | 28 const Instance& assertion_error = Instance::Handle( |
27 Exceptions::NewInstance("AssertionError")); | 29 Exceptions::NewInstance("AssertionError")); |
28 | 30 |
29 // Initialize 'url', 'line', and 'column' fields. | 31 // Initialize 'url', 'line', and 'column' fields. |
30 DartFrameIterator iterator; | 32 DartFrameIterator iterator; |
31 iterator.NextFrame(); // Skip native call. | 33 iterator.NextFrame(); // Skip native call. |
(...skipping 16 matching lines...) Expand all Loading... |
48 | 50 |
49 | 51 |
50 // Allocate and throw a new TypeError. | 52 // Allocate and throw a new TypeError. |
51 // Arg0: index of the token of the failed type check. | 53 // Arg0: index of the token of the failed type check. |
52 // Arg1: src value. | 54 // Arg1: src value. |
53 // Arg2: dst type name. | 55 // Arg2: dst type name. |
54 // Arg3: dst name. | 56 // Arg3: dst name. |
55 // Arg4: malformed type error message. | 57 // Arg4: malformed type error message. |
56 // Return value: none, throws an exception. | 58 // Return value: none, throws an exception. |
57 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { | 59 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { |
| 60 // No need to type check the arguments. This function can only be called |
| 61 // internally from the VM. |
58 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value(); | 62 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value(); |
59 const Instance& src_value = Instance::CheckedHandle(arguments->At(1)); | 63 const Instance& src_value = Instance::CheckedHandle(arguments->At(1)); |
60 const String& dst_type_name = String::CheckedHandle(arguments->At(2)); | 64 const String& dst_type_name = String::CheckedHandle(arguments->At(2)); |
61 const String& dst_name = String::CheckedHandle(arguments->At(3)); | 65 const String& dst_name = String::CheckedHandle(arguments->At(3)); |
62 const String& malformed_error = String::CheckedHandle(arguments->At(4)); | 66 const String& malformed_error = String::CheckedHandle(arguments->At(4)); |
63 const String& src_type_name = | 67 const String& src_type_name = |
64 String::Handle(Type::Handle(src_value.GetType()).Name()); | 68 String::Handle(Type::Handle(src_value.GetType()).Name()); |
65 Exceptions::CreateAndThrowTypeError(location, src_type_name, | 69 Exceptions::CreateAndThrowTypeError(location, src_type_name, |
66 dst_type_name, dst_name, malformed_error); | 70 dst_type_name, dst_name, malformed_error); |
67 } | 71 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 intptr_t line, column; | 122 intptr_t line, column; |
119 script.GetTokenLocation(call_pos, &line, &column); | 123 script.GetTokenLocation(call_pos, &line, &column); |
120 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine", | 124 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine", |
121 String::Handle(script.GetLine(line))); | 125 String::Handle(script.GetLine(line))); |
122 | 126 |
123 Exceptions::Throw(resolution_exception); | 127 Exceptions::Throw(resolution_exception); |
124 UNREACHABLE(); | 128 UNREACHABLE(); |
125 } | 129 } |
126 | 130 |
127 } // namespace dart | 131 } // namespace dart |
OLD | NEW |