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

Unified Diff: runtime/lib/errors.cc

Issue 2453263002: Produce the correct assertion failure expression in the face of inlining (Closed)
Patch Set: asiva review Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/vm/regress_27671_other.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/errors.cc
diff --git a/runtime/lib/errors.cc b/runtime/lib/errors.cc
index 28d4ef49c41d6c823a2c98caf59ec782b93222d0..b039efa97257f8575b727c52ababeb0fc6c4af13 100644
--- a/runtime/lib/errors.cc
+++ b/runtime/lib/errors.cc
@@ -7,9 +7,49 @@
#include "vm/object_store.h"
#include "vm/runtime_entry.h"
#include "vm/stack_frame.h"
+#include "vm/symbols.h"
namespace dart {
+// Scan the stack until we hit the first function in the _AssertionError
+// class. We then return the next frame's script taking inlining into account.
+static RawScript* FindScript(DartFrameIterator* iterator) {
+ StackFrame* stack_frame = iterator->NextFrame();
+ Code& code = Code::Handle();
+ Function& func = Function::Handle();
+ const Class& assert_error_class = Class::Handle(
+ Library::LookupCoreClass(Symbols::AssertionError()));
+ ASSERT(!assert_error_class.IsNull());
+ bool hit_assertion_error = false;
+ while (stack_frame != NULL) {
+ code ^= stack_frame->LookupDartCode();
+ if (code.is_optimized()) {
+ InlinedFunctionsIterator inlined_iterator(code, stack_frame->pc());
+ while (!inlined_iterator.Done()) {
+ func ^= inlined_iterator.function();
+ if (hit_assertion_error) {
+ return func.script();
+ }
+ ASSERT(!hit_assertion_error);
+ hit_assertion_error = (func.Owner() == assert_error_class.raw());
+ inlined_iterator.Advance();
+ }
+ } else {
+ func ^= code.function();
+ ASSERT(!func.IsNull());
+ if (hit_assertion_error) {
+ return func.script();
+ }
+ ASSERT(!hit_assertion_error);
+ hit_assertion_error = (func.Owner() == assert_error_class.raw());
+ }
+ stack_frame = iterator->NextFrame();
+ }
+ UNREACHABLE();
+ return Script::null();
+}
+
+
// Allocate and throw a new AssertionError.
// Arg0: index of the first token of the failed assertion.
// Arg1: index of the first token after the failed assertion.
@@ -26,8 +66,7 @@ DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) {
DartFrameIterator iterator;
iterator.NextFrame(); // Skip native call.
- iterator.NextFrame(); // Skip _AssertionError._checkAssertion frame
- const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
+ const Script& script = Script::Handle(FindScript(&iterator));
// Initialize argument 'failed_assertion' with source snippet.
intptr_t from_line, from_column;
« no previous file with comments | « no previous file | tests/language/vm/regress_27671_other.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698