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

Unified Diff: runtime/vm/code_generator.cc

Issue 779253003: 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
« no previous file with comments | « runtime/lib/errors_patch.dart ('k') | runtime/vm/flow_graph_builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_generator.cc
===================================================================
--- runtime/vm/code_generator.cc (revision 42168)
+++ runtime/vm/code_generator.cc (working copy)
@@ -54,6 +54,7 @@
DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks.");
DECLARE_FLAG(int, deoptimization_counter_threshold);
+DECLARE_FLAG(bool, enable_asserts);
DECLARE_FLAG(bool, enable_type_checks);
DECLARE_FLAG(bool, warn_on_javascript_compatibility);
@@ -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")));
+
+ // 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());
« no previous file with comments | « runtime/lib/errors_patch.dart ('k') | runtime/vm/flow_graph_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698