Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: runtime/lib/errors.cc

Issue 2574003003: Add optional message argument to assert statements in the VM. (Closed)
Patch Set: Update dart2js status file Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/errors_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 (FLAG_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._checkAssertion frame 23 iterator->NextFrame(); // Skip _AssertionError._evaluateAssertion frame
24 return Exceptions::GetCallerScript(iterator); 24 return Exceptions::GetCallerScript(iterator);
25 } 25 }
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) {
(...skipping 21 matching lines...) Expand all
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 } 59 }
60 60
61 61
62 // Allocate and throw a new AssertionError. 62 // Allocate and throw a new AssertionError.
63 // Arg0: index of the first token of the failed assertion. 63 // Arg0: index of the first token of the failed assertion.
64 // Arg1: index of the first token after the failed assertion. 64 // Arg1: index of the first token after the failed assertion.
65 // Arg2: Message object or null.
65 // Return value: none, throws an exception. 66 // Return value: none, throws an exception.
66 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { 67 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 3) {
67 // No need to type check the arguments. This function can only be called 68 // No need to type check the arguments. This function can only be called
68 // internally from the VM. 69 // internally from the VM.
69 const TokenPosition assertion_start = 70 const TokenPosition assertion_start =
70 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); 71 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value());
71 const TokenPosition assertion_end = 72 const TokenPosition assertion_end =
72 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); 73 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value());
73 74
74 const Array& args = Array::Handle(Array::New(4)); 75 const Instance& message = Instance::CheckedHandle(arguments->NativeArgAt(2));
76 const Array& args = Array::Handle(Array::New(5));
75 77
76 DartFrameIterator iterator; 78 DartFrameIterator iterator;
77 iterator.NextFrame(); // Skip native call. 79 iterator.NextFrame(); // Skip native call.
78 const Script& script = Script::Handle(FindScript(&iterator)); 80 const Script& script = Script::Handle(FindScript(&iterator));
79 81
80 // Initialize argument 'failed_assertion' with source snippet. 82 // Initialize argument 'failed_assertion' with source snippet.
81 intptr_t from_line, from_column; 83 intptr_t from_line, from_column;
82 script.GetTokenLocation(assertion_start, &from_line, &from_column); 84 script.GetTokenLocation(assertion_start, &from_line, &from_column);
83 intptr_t to_line, to_column; 85 intptr_t to_line, to_column;
84 script.GetTokenLocation(assertion_end, &to_line, &to_column); 86 script.GetTokenLocation(assertion_end, &to_line, &to_column);
85 // The snippet will extract the correct assertion code even if the source 87 // The snippet will extract the correct assertion code even if the source
86 // is generated. 88 // is generated.
87 args.SetAt(0, String::Handle(script.GetSnippet(from_line, from_column, 89 args.SetAt(0, String::Handle(script.GetSnippet(from_line, from_column,
88 to_line, to_column))); 90 to_line, to_column)));
89 91
90 // Initialize location arguments starting at position 1. 92 // Initialize location arguments starting at position 1.
91 // Do not set a column if the source has been generated as it will be wrong. 93 // Do not set a column if the source has been generated as it will be wrong.
92 args.SetAt(1, String::Handle(script.url())); 94 args.SetAt(1, String::Handle(script.url()));
93 args.SetAt(2, Smi::Handle(Smi::New(from_line))); 95 args.SetAt(2, Smi::Handle(Smi::New(from_line)));
94 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1))); 96 args.SetAt(3, Smi::Handle(Smi::New(script.HasSource() ? from_column : -1)));
97 args.SetAt(4, message);
95 98
96 Exceptions::ThrowByType(Exceptions::kAssertion, args); 99 Exceptions::ThrowByType(Exceptions::kAssertion, args);
97 UNREACHABLE(); 100 UNREACHABLE();
98 return Object::null(); 101 return Object::null();
99 } 102 }
100 103
101 104
102 // Allocate and throw a new TypeError or CastError. 105 // Allocate and throw a new TypeError or CastError.
103 // Arg0: index of the token of the failed type check. 106 // Arg0: index of the token of the failed type check.
104 // Arg1: src value. 107 // Arg1: src value.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 181
179 // Rethrow an error with a stacktrace. 182 // Rethrow an error with a stacktrace.
180 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { 183 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) {
181 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); 184 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0));
182 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); 185 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1));
183 Exceptions::ReThrow(thread, error, stacktrace); 186 Exceptions::ReThrow(thread, error, stacktrace);
184 return Object::null(); 187 return Object::null();
185 } 188 }
186 189
187 } // namespace dart 190 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/errors_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698