Skip to content

Accept more than number as maxAge (and others) #14

Open
@jrencz

Description

@jrencz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions