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

Unified Diff: runtime/vm/code_generator.cc

Issue 778063002: Implement correct semantics of Boolean Conversion (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/code_generator.cc
===================================================================
--- runtime/vm/code_generator.cc (revision 42124)
+++ runtime/vm/code_generator.cc (working copy)
@@ -55,6 +55,7 @@
DECLARE_FLAG(int, deoptimization_counter_threshold);
DECLARE_FLAG(bool, enable_type_checks);
+DECLARE_FLAG(bool, enable_asserts);
srdjan 2014/12/05 00:49:28 Please order alphabetically.
hausner 2014/12/05 20:36:10 Done.
DECLARE_FLAG(bool, warn_on_javascript_compatibility);
DEFINE_FLAG(bool, use_osr, true, "Use on-stack replacement.");
@@ -559,12 +560,29 @@
// Report that the type of the given object is not bool in conditional context.
+// Throw assertion error if the object is null. (cf. Boolean Conversion
+// in language Spec.)
// Arg0: bad object.
-// Return value: none, throws a TypeError.
+// Return value: none, throws TypeError or AssertionError.
DEFINE_RUNTIME_ENTRY(NonBoolTypeError, 1) {
const intptr_t location = GetCallerLocation();
const Instance& src_instance = Instance::CheckedHandle(arguments.ArgAt(0));
- ASSERT(src_instance.IsNull() || !src_instance.IsBool());
+
+ if (src_instance.IsNull()) {
+ const Array& args = Array::Handle(Array::New(4));
+ args.SetAt(0, String::Handle(
+ String::New("Failed assertion: boolean expression must not be null")));
srdjan 2014/12/05 00:49:28 s/boolean/Boolean/
hausner 2014/12/05 20:36:10 We always start error messages with lower case.
+
+ // No source code for this assertion, set url to null.
+ args.SetAt(1, String::Handle(String::null()));
+ args.SetAt(2, Smi::Handle(Smi::New(0)));
+ args.SetAt(3, Smi::Handle(Smi::New(0)));
+
+ Exceptions::ThrowByType(Exceptions::kAssertion, args);
+ UNREACHABLE();
+ }
+
+ ASSERT(!src_instance.IsBool());
const Type& bool_interface = Type::Handle(Type::BoolType());
const AbstractType& src_type = AbstractType::Handle(src_instance.GetType());
const String& src_type_name = String::Handle(src_type.UserVisibleName());

Powered by Google App Engine
This is Rietveld 408576698