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

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

Issue 2453263002: Produce the correct assertion failure expression in the face of inlining (Closed)
Patch Set: Created 4 years, 1 month 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
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 11
11 namespace dart { 12 namespace dart {
12 13
14 static bool IsAssertionerrorFunction(const Function& function) {
15 const Class& assert_error_class = Class::Handle(
16 Library::LookupCoreClass(Symbols::AssertionError()));
17 return function.Owner() == assert_error_class.raw();
18 }
19
20
21 // Scan the stack until we hit the first function in the _AssertionError
22 // class. We then return the next frame's script taking inlining into account.
23 static RawScript* FindScript(DartFrameIterator* iterator) {
24 StackFrame* stack_frame = iterator->NextFrame();
25 Code& code = Code::Handle();
26 Function& func = Function::Handle();
27 bool hit_assertion_error = false;
siva 2016/10/27 10:46:48 why not add const Class& assert_error_class = ....
Cutch 2016/10/27 11:25:29 Done.
28 while (stack_frame != NULL) {
29 code ^= stack_frame->LookupDartCode();
30 if (code.is_optimized()) {
31 InlinedFunctionsIterator inlined_iterator(code, stack_frame->pc());
32 while (!inlined_iterator.Done()) {
33 func ^= inlined_iterator.function();
34 if (hit_assertion_error) {
35 return func.script();
36 }
37 ASSERT(!hit_assertion_error);
38 hit_assertion_error = IsAssertionerrorFunction(func);
39 inlined_iterator.Advance();
40 }
41 } else {
42 func ^= code.function();
43 ASSERT(!func.IsNull());
44 if (hit_assertion_error) {
45 return func.script();
46 }
47 ASSERT(!hit_assertion_error);
48 hit_assertion_error = IsAssertionerrorFunction(func);
49 }
50 stack_frame = iterator->NextFrame();
51 }
52 UNREACHABLE();
53 return Script::null();
54 }
55
56
13 // Allocate and throw a new AssertionError. 57 // Allocate and throw a new AssertionError.
14 // Arg0: index of the first token of the failed assertion. 58 // Arg0: index of the first token of the failed assertion.
15 // Arg1: index of the first token after the failed assertion. 59 // Arg1: index of the first token after the failed assertion.
16 // Return value: none, throws an exception. 60 // Return value: none, throws an exception.
17 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) { 61 DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) {
18 // No need to type check the arguments. This function can only be called 62 // No need to type check the arguments. This function can only be called
19 // internally from the VM. 63 // internally from the VM.
20 const TokenPosition assertion_start = 64 const TokenPosition assertion_start =
21 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value()); 65 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(0)).Value());
22 const TokenPosition assertion_end = 66 const TokenPosition assertion_end =
23 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value()); 67 TokenPosition(Smi::CheckedHandle(arguments->NativeArgAt(1)).Value());
24 68
25 const Array& args = Array::Handle(Array::New(4)); 69 const Array& args = Array::Handle(Array::New(4));
26 70
27 DartFrameIterator iterator; 71 DartFrameIterator iterator;
28 iterator.NextFrame(); // Skip native call. 72 iterator.NextFrame(); // Skip native call.
29 iterator.NextFrame(); // Skip _AssertionError._checkAssertion frame 73 const Script& script = Script::Handle(FindScript(&iterator));
30 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
31 74
32 // Initialize argument 'failed_assertion' with source snippet. 75 // Initialize argument 'failed_assertion' with source snippet.
33 intptr_t from_line, from_column; 76 intptr_t from_line, from_column;
34 script.GetTokenLocation(assertion_start, &from_line, &from_column); 77 script.GetTokenLocation(assertion_start, &from_line, &from_column);
35 intptr_t to_line, to_column; 78 intptr_t to_line, to_column;
36 script.GetTokenLocation(assertion_end, &to_line, &to_column); 79 script.GetTokenLocation(assertion_end, &to_line, &to_column);
37 // The snippet will extract the correct assertion code even if the source 80 // The snippet will extract the correct assertion code even if the source
38 // is generated. 81 // is generated.
39 args.SetAt(0, String::Handle( 82 args.SetAt(0, String::Handle(
40 script.GetSnippet(from_line, from_column, to_line, to_column))); 83 script.GetSnippet(from_line, from_column, to_line, to_column)));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 172
130 // Rethrow an error with a stacktrace. 173 // Rethrow an error with a stacktrace.
131 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) { 174 DEFINE_NATIVE_ENTRY(Async_rethrow, 2) {
132 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0)); 175 GET_NON_NULL_NATIVE_ARGUMENT(Instance, error, arguments->NativeArgAt(0));
133 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1)); 176 GET_NON_NULL_NATIVE_ARGUMENT(Instance, stacktrace, arguments->NativeArgAt(1));
134 Exceptions::ReThrow(thread, error, stacktrace); 177 Exceptions::ReThrow(thread, error, stacktrace);
135 return Object::null(); 178 return Object::null();
136 } 179 }
137 180
138 } // namespace dart 181 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/vm/regress_27671_other.dart » ('j') | tests/language/vm/regress_27671_other.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698