| 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, 3) { |
| 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 intptr_t assertion_start = |
| 21 Smi::CheckedHandle(arguments->NativeArgAt(0)).Value(); | 21 Smi::CheckedHandle(arguments->NativeArgAt(0)).Value(); |
| 22 intptr_t assertion_end = | 22 intptr_t assertion_end = |
| 23 Smi::CheckedHandle(arguments->NativeArgAt(1)).Value(); | 23 Smi::CheckedHandle(arguments->NativeArgAt(1)).Value(); |
| 24 | 24 const Instance& message = Instance::CheckedHandle(arguments->NativeArgAt(2)); |
| 25 const Array& args = Array::Handle(Array::New(4)); | 25 const Array& args = Array::Handle(Array::New(5)); |
| 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); |
| 34 intptr_t to_line, to_column; | 34 intptr_t to_line, to_column; |
| 35 script.GetTokenLocation(assertion_end, &to_line, &to_column); | 35 script.GetTokenLocation(assertion_end, &to_line, &to_column); |
| 36 // The snippet will extract the correct assertion code even if the source | 36 // The snippet will extract the correct assertion code even if the source |
| 37 // is generated. | 37 // is generated. |
| 38 args.SetAt(0, String::Handle( | 38 args.SetAt(0, String::Handle( |
| 39 script.GetSnippet(from_line, from_column, to_line, to_column))); | 39 script.GetSnippet(from_line, from_column, to_line, to_column))); |
| 40 | 40 |
| 41 // Initialize location arguments starting at position 1. | 41 // Initialize location arguments starting at position 1. |
| 42 // Do not set a column if the source has been generated as it will be wrong. | 42 // Do not set a column if the source has been generated as it will be wrong. |
| 43 args.SetAt(1, String::Handle(script.url())); | 43 args.SetAt(1, String::Handle(script.url())); |
| 44 args.SetAt(2, Smi::Handle(Smi::New(from_line))); | 44 args.SetAt(2, Smi::Handle(Smi::New(from_line))); |
| 45 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1))); | 45 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1))); |
| 46 args.SetAt(4, message); |
| 46 | 47 |
| 47 Exceptions::ThrowByType(Exceptions::kAssertion, args); | 48 Exceptions::ThrowByType(Exceptions::kAssertion, args); |
| 48 UNREACHABLE(); | 49 UNREACHABLE(); |
| 49 return Object::null(); | 50 return Object::null(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 | 53 |
| 53 // Allocate and throw a new TypeError or CastError. | 54 // Allocate and throw a new TypeError or CastError. |
| 54 // Arg0: index of the token of the failed type check. | 55 // Arg0: index of the token of the failed type check. |
| 55 // Arg1: src value. | 56 // Arg1: src value. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } // namespace dart | 130 } // namespace dart |
| OLD | NEW |