Skip to content

Commit

Permalink
[turbofan] Infer proper type for calls to Date.now.
Browse files Browse the repository at this point in the history
Recognize Date.now() calls in the Typer and assign the proper integer
type to them.

See Node issue nodejs/node#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}
  • Loading branch information
bmeurer authored and Commit bot committed Nov 24, 2016
1 parent 9da894e commit 3709108
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/compiler/type-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class TypeCache final {
// [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
// [1, 31] or NaN.
Type* const kJSDateDayType =
Expand All @@ -123,9 +128,8 @@ class TypeCache final {

// The JSDate::value property always contains a tagged number in the range
// [-kMaxTimeInMs, kMaxTimeInMs] or NaN.
Type* const kJSDateValueType = Type::Union(
CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs),
Type::NaN(), zone());
Type* const kJSDateValueType =
Type::Union(kTimeValueType, Type::NaN(), zone());

// The JSDate::weekday property always contains a tagged number in the range
// [0, 6] or NaN.
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/typer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,8 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
case kMathClz32:
return t->cache_.kZeroToThirtyTwo;
// Date functions.
case kDateNow:
return t->cache_.kTimeValueType;
case kDateGetDate:
return t->cache_.kJSDateDayType;
case kDateGetDay:
Expand Down
1 change: 1 addition & 0 deletions src/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -7237,6 +7237,7 @@ class Script: public Struct {
V(Array.prototype, push, ArrayPush) \
V(Array.prototype, pop, ArrayPop) \
V(Array.prototype, shift, ArrayShift) \
V(Date, now, DateNow) \
V(Date.prototype, getDate, DateGetDate) \
V(Date.prototype, getDay, DateGetDay) \
V(Date.prototype, getFullYear, DateGetFullYear) \
Expand Down

0 comments on commit 3709108

Please sign in to comment.