| 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 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // Scan the stack until we hit the first function in the _AssertionError | 14 // Scan the stack until we hit the first function in the _AssertionError |
| 15 // class. We then return the next frame's script taking inlining into account. | 15 // class. We then return the next frame's script taking inlining into account. |
| 16 static RawScript* FindScript(DartFrameIterator* iterator) { | 16 static RawScript* FindScript(DartFrameIterator* iterator) { |
| 17 if (FLAG_precompiled_runtime) { | 17 #if defined(DART_PRECOMPILED_RUNTIME) |
| 18 // The precompiled runtime faces two issues in recovering the correct | 18 // The precompiled runtime faces two issues in recovering the correct |
| 19 // assertion text. First, the precompiled runtime does not include | 19 // assertion text. First, the precompiled runtime does not include |
| 20 // the inlining meta-data so we cannot walk the inline-aware stack trace. | 20 // the inlining meta-data so we cannot walk the inline-aware stack trace. |
| 21 // Second, the script text itself is missing so whatever script is returned | 21 // Second, the script text itself is missing so whatever script is returned |
| 22 // from here will be missing the assertion expression text. | 22 // from here will be missing the assertion expression text. |
| 23 iterator->NextFrame(); // Skip _AssertionError._evaluateAssertion frame | 23 iterator->NextFrame(); // Skip _AssertionError._evaluateAssertion frame |
| 24 return Exceptions::GetCallerScript(iterator); | 24 return Exceptions::GetCallerScript(iterator); |
| 25 } | 25 #else |
| 26 StackFrame* stack_frame = iterator->NextFrame(); | 26 StackFrame* stack_frame = iterator->NextFrame(); |
| 27 Code& code = Code::Handle(); | 27 Code& code = Code::Handle(); |
| 28 Function& func = Function::Handle(); | 28 Function& func = Function::Handle(); |
| 29 const Class& assert_error_class = | 29 const Class& assert_error_class = |
| 30 Class::Handle(Library::LookupCoreClass(Symbols::AssertionError())); | 30 Class::Handle(Library::LookupCoreClass(Symbols::AssertionError())); |
| 31 ASSERT(!assert_error_class.IsNull()); | 31 ASSERT(!assert_error_class.IsNull()); |
| 32 bool hit_assertion_error = false; | 32 bool hit_assertion_error = false; |
| 33 while (stack_frame != NULL) { | 33 while (stack_frame != NULL) { |
| 34 code ^= stack_frame->LookupDartCode(); | 34 code ^= stack_frame->LookupDartCode(); |
| 35 if (code.is_optimized()) { | 35 if (code.is_optimized()) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 49 if (hit_assertion_error) { | 49 if (hit_assertion_error) { |
| 50 return func.script(); | 50 return func.script(); |
| 51 } | 51 } |
| 52 ASSERT(!hit_assertion_error); | 52 ASSERT(!hit_assertion_error); |
| 53 hit_assertion_error = (func.Owner() == assert_error_class.raw()); | 53 hit_assertion_error = (func.Owner() == assert_error_class.raw()); |
| 54 } | 54 } |
| 55 stack_frame = iterator->NextFrame(); | 55 stack_frame = iterator->NextFrame(); |
| 56 } | 56 } |
| 57 UNREACHABLE(); | 57 UNREACHABLE(); |
| 58 return Script::null(); | 58 return Script::null(); |
| 59 #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 59 } | 60 } |
| 60 | 61 |
| 61 | 62 |
| 62 // Allocate and throw a new AssertionError. | 63 // Allocate and throw a new AssertionError. |
| 63 // Arg0: index of the first token of the failed assertion. | 64 // Arg0: index of the first token of the failed assertion. |
| 64 // Arg1: index of the first token after the failed assertion. | 65 // Arg1: index of the first token after the failed assertion. |
| 65 // Arg2: Message object or null. | 66 // Arg2: Message object or null. |
| 66 // Return value: none, throws an exception. | 67 // Return value: none, throws an exception. |
| 67 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 3) { | 68 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 3) { |
| 68 // No need to type check the arguments. This function can only be called | 69 // No need to type check the arguments. This function can only be called |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 // Rethrow an error with a stacktrace. | 186 // Rethrow an error with a stacktrace. |
| 186 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { | 187 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { |
| 187 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); | 188 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); |
| 188 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); | 189 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); |
| 189 Exceptions::ReThrow(thread, error, stacktrace); | 190 Exceptions::ReThrow(thread, error, stacktrace); |
| 190 return Object::null(); | 191 return Object::null(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace dart | 194 } // namespace dart |
| OLD | NEW |