CacheFactory icon indicating copy to clipboard operation
CacheFactory copied to clipboard

Accept more than number as maxAge (and others)

Open jrencz opened this issue 9 years ago • 0 comments

http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#timers

When the above methods are to get the timeout, they must run the following steps:

  1. Let timeout be the second argument to the method, or zero if the argument was omitted.
  2. Apply the ToString() abstract operation to timeout, and let timeout be the result. [ECMA262] 3. Apply the ToNumber() abstract operation to timeout, and let timeout be the result. [ECMA262]
  3. If timeout is an Infinity value, a Not-a-Number (NaN) value, or negative, let timeout be zero.
  4. Round timeout down to the nearest integer, and let timeout be the result.
  5. Return timeout.

So:

http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tonumber calls http://www.ecma-international.org/ecma-262/6.0/index.html#sec-toprimitive which calls valueOf

Effectively: each data structure, primitive or object that abstract operation ToNumber can cast to a number should be a valid value of all options that now require number

Real life example: http://momentjs.com/docs/#/durations/ Duration implements valueOf and it returns duration length as milliseconds. CacheFactory triggers an error where it shouldn't when duration is passed - browser can handle that.

jrencz avatar May 11 '16 11:05 jrencz