Reviewers: Hannes Payer,

Message:
PTAL

Reference documentation (current ES6 draft) for ToBoolean:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toboolean

Description:
[turbofan] Improve typing of ToBoolean.

According to ES6 draft, revision 29 (2014-12-06), section 7.1.2,
ToBoolean yields true for true, detectable receivers (the ES6 Object
type), symbols and numbers except -0, +0 and NaN.

Please review this at https://codereview.chromium.org/807663006/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+6, -2 lines):
  M src/compiler/typer.h
  M src/compiler/typer.cc


Index: src/compiler/typer.cc
diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc
index 58e6c37ab51a2e5229c8d3f4e669fab78dd3cefc..b33ee0c863d26da882553dd5e7ace770d658c249 100644
--- a/src/compiler/typer.cc
+++ b/src/compiler/typer.cc
@@ -187,6 +187,9 @@ Typer::Typer(Graph* graph, MaybeHandle<Context> context)
Type::Union(Type::Union(singleton_false, zeroish, zone),
                                     undefined_or_null, zone),
                         zone);
+  truish = Type::Union(
+      singleton_true,
+      Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone);
   integer = Type::Range(minusinfinity, infinity, zone);
   weakint = Type::Union(integer, nan_or_minuszero, zone);

@@ -513,8 +516,8 @@ Type* Typer::Visitor::ToPrimitive(Type* type, Typer* t) {
 Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) {
   if (type->Is(Type::Boolean())) return type;
   if (type->Is(t->falsish)) return t->singleton_false;
-  if (type->Is(Type::DetectableReceiver())) return t->singleton_true;
- if (type->Is(Type::OrderedNumber()) && (type->Max() < 0 || 0 < type->Min())) {
+  if (type->Is(t->truish)) return t->singleton_true;
+ if (type->Is(Type::PlainNumber()) && (type->Max() < 0 || 0 < type->Min())) {
     return t->singleton_true;  // Ruled out nan, -0 and +0.
   }
   return Type::Boolean();
Index: src/compiler/typer.h
diff --git a/src/compiler/typer.h b/src/compiler/typer.h
index 45d3a32b79fca160909bf93f9d9378fbf21380f3..b65a9a5aff09edb1c5a13f4cc1df494b70d4e574 100644
--- a/src/compiler/typer.h
+++ b/src/compiler/typer.h
@@ -54,6 +54,7 @@ class Typer {
   Type* signed32ish;
   Type* unsigned32ish;
   Type* falsish;
+  Type* truish;
   Type* integer;
   Type* weakint;
   Type* number_fun0_;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to