Commit 37091088 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Infer proper type for calls to Date.now.

Recognize Date.now() calls in the Typer and assign the proper integer
type to them.

See Node issue https://github.com/nodejs/node/issues/9729 for more
information.

R=yangguo@chromium.org
BUG=v8:5267

Review-Url: https://codereview.chromium.org/2528853003
Cr-Commit-Position: refs/heads/master@{#41242}
parent 9da894ed
...@@ -97,6 +97,11 @@ class TypeCache final { ...@@ -97,6 +97,11 @@ class TypeCache final {
// [0, String::kMaxLength]. // [0, String::kMaxLength].
Type* const kStringLengthType = CreateRange(0.0, String::kMaxLength); Type* const kStringLengthType = CreateRange(0.0, String::kMaxLength);
// A time value always contains a tagged number in the range
// [-kMaxTimeInMs, kMaxTimeInMs].
Type* const kTimeValueType =
CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs);
// The JSDate::day property always contains a tagged number in the range // The JSDate::day property always contains a tagged number in the range
// [1, 31] or NaN. // [1, 31] or NaN.
Type* const kJSDateDayType = Type* const kJSDateDayType =
...@@ -123,9 +128,8 @@ class TypeCache final { ...@@ -123,9 +128,8 @@ class TypeCache final {
// The JSDate::value property always contains a tagged number in the range // The JSDate::value property always contains a tagged number in the range
// [-kMaxTimeInMs, kMaxTimeInMs] or NaN. // [-kMaxTimeInMs, kMaxTimeInMs] or NaN.
Type* const kJSDateValueType = Type::Union( Type* const kJSDateValueType =
CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs), Type::Union(kTimeValueType, Type::NaN(), zone());
Type::NaN(), zone());
// The JSDate::weekday property always contains a tagged number in the range // The JSDate::weekday property always contains a tagged number in the range
// [0, 6] or NaN. // [0, 6] or NaN.
......
...@@ -1348,6 +1348,8 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) { ...@@ -1348,6 +1348,8 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
case kMathClz32: case kMathClz32:
return t->cache_.kZeroToThirtyTwo; return t->cache_.kZeroToThirtyTwo;
// Date functions. // Date functions.
case kDateNow:
return t->cache_.kTimeValueType;
case kDateGetDate: case kDateGetDate:
return t->cache_.kJSDateDayType; return t->cache_.kJSDateDayType;
case kDateGetDay: case kDateGetDay:
......
...@@ -7237,6 +7237,7 @@ class Script: public Struct { ...@@ -7237,6 +7237,7 @@ class Script: public Struct {
V(Array.prototype, push, ArrayPush) \ V(Array.prototype, push, ArrayPush) \
V(Array.prototype, pop, ArrayPop) \ V(Array.prototype, pop, ArrayPop) \
V(Array.prototype, shift, ArrayShift) \ V(Array.prototype, shift, ArrayShift) \
V(Date, now, DateNow) \
V(Date.prototype, getDate, DateGetDate) \ V(Date.prototype, getDate, DateGetDate) \
V(Date.prototype, getDay, DateGetDay) \ V(Date.prototype, getDay, DateGetDay) \
V(Date.prototype, getFullYear, DateGetFullYear) \ V(Date.prototype, getFullYear, DateGetFullYear) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment