| Index: src/compiler/typer.cc
|
| diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc
|
| index 96f7b65be2cfbbd51a6b5f6b754695affe952a89..e011a0a2ebb690e4f626bdc17f3fcbd3157ed02c 100644
|
| --- a/src/compiler/typer.cc
|
| +++ b/src/compiler/typer.cc
|
| @@ -231,7 +231,11 @@ class Typer::Visitor : public Reducer {
|
|
|
| static Type* ToPrimitive(Type*, Typer*);
|
| static Type* ToBoolean(Type*, Typer*);
|
| + static Type* ToInteger(Type*, Typer*);
|
| + static Type* ToLength(Type*, Typer*);
|
| + static Type* ToName(Type*, Typer*);
|
| static Type* ToNumber(Type*, Typer*);
|
| + static Type* ToObject(Type*, Typer*);
|
| static Type* ToString(Type*, Typer*);
|
| static Type* NumberToInt32(Type*, Typer*);
|
| static Type* NumberToUint32(Type*, Typer*);
|
| @@ -402,6 +406,39 @@ Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) {
|
| }
|
|
|
|
|
| +// static
|
| +Type* Typer::Visitor::ToInteger(Type* type, Typer* t) {
|
| + // ES6 section 7.1.4 ToInteger ( argument )
|
| + type = ToNumber(type, t);
|
| + if (type->Is(t->cache_.kIntegerish)) return type;
|
| + return t->cache_.kIntegerish;
|
| +}
|
| +
|
| +
|
| +// static
|
| +Type* Typer::Visitor::ToLength(Type* type, Typer* t) {
|
| + // ES6 section 7.1.15 ToLength ( argument )
|
| + type = ToInteger(type, t);
|
| + double min = type->Min();
|
| + double max = type->Max();
|
| + if (min <= 0.0) min = 0.0;
|
| + if (max > kMaxSafeInteger) max = kMaxSafeInteger;
|
| + if (max <= min) max = min;
|
| + return Type::Range(min, max, t->zone());
|
| +}
|
| +
|
| +
|
| +// static
|
| +Type* Typer::Visitor::ToName(Type* type, Typer* t) {
|
| + // ES6 section 7.1.14 ToPropertyKey ( argument )
|
| + type = ToPrimitive(type, t);
|
| + if (type->Is(Type::Name())) return type;
|
| + if (type->Maybe(Type::Symbol())) return Type::Name();
|
| + return ToString(type, t);
|
| +}
|
| +
|
| +
|
| +// static
|
| Type* Typer::Visitor::ToNumber(Type* type, Typer* t) {
|
| if (type->Is(Type::Number())) return type;
|
| if (type->Is(Type::NullOrUndefined())) {
|
| @@ -424,7 +461,20 @@ Type* Typer::Visitor::ToNumber(Type* type, Typer* t) {
|
| }
|
|
|
|
|
| +// static
|
| +Type* Typer::Visitor::ToObject(Type* type, Typer* t) {
|
| + // ES6 section 7.1.13 ToObject ( argument )
|
| + if (type->Is(Type::Receiver())) return type;
|
| + if (type->Is(Type::Primitive())) return Type::OtherObject();
|
| + if (!type->Maybe(Type::Undetectable())) return Type::DetectableReceiver();
|
| + return Type::Receiver();
|
| +}
|
| +
|
| +
|
| +// static
|
| Type* Typer::Visitor::ToString(Type* type, Typer* t) {
|
| + // ES6 section 7.1.12 ToString ( argument )
|
| + type = ToPrimitive(type, t);
|
| if (type->Is(Type::String())) return type;
|
| return Type::String();
|
| }
|
| @@ -1142,10 +1192,14 @@ Type* Typer::Visitor::TypeJSToString(Node* node) {
|
| }
|
|
|
|
|
| -Type* Typer::Visitor::TypeJSToName(Node* node) { return Type::Name(); }
|
| +Type* Typer::Visitor::TypeJSToName(Node* node) {
|
| + return TypeUnaryOp(node, ToName);
|
| +}
|
|
|
|
|
| -Type* Typer::Visitor::TypeJSToObject(Node* node) { return Type::Receiver(); }
|
| +Type* Typer::Visitor::TypeJSToObject(Node* node) {
|
| + return TypeUnaryOp(node, ToObject);
|
| +}
|
|
|
|
|
| // JS object operators.
|
| @@ -1468,8 +1522,22 @@ Type* Typer::Visitor::TypeJSCallRuntime(Node* node) {
|
| return Type::Range(0, 32, zone());
|
| case Runtime::kInlineStringGetLength:
|
| return Type::Range(0, String::kMaxLength, zone());
|
| + case Runtime::kInlineToInteger:
|
| + return TypeUnaryOp(node, ToInteger);
|
| + case Runtime::kInlineToLength:
|
| + return TypeUnaryOp(node, ToLength);
|
| + case Runtime::kInlineToName:
|
| + return TypeUnaryOp(node, ToName);
|
| + case Runtime::kInlineToNumber:
|
| + return TypeUnaryOp(node, ToNumber);
|
| case Runtime::kInlineToObject:
|
| - return Type::Receiver();
|
| + return TypeUnaryOp(node, ToObject);
|
| + case Runtime::kInlineToPrimitive:
|
| + case Runtime::kInlineToPrimitive_Number:
|
| + case Runtime::kInlineToPrimitive_String:
|
| + return TypeUnaryOp(node, ToPrimitive);
|
| + case Runtime::kInlineToString:
|
| + return TypeUnaryOp(node, ToString);
|
| default:
|
| break;
|
| }
|
|
|