Skip to content

interval.range should protect against infinite loops. #25

@BrunoRB

Description

@BrunoRB
d3.timeWeek.range(new Date(2017, 6, 10), new Date(2017, 9, 10));

The code above works fine on chrome, but creates an infinite loop on firefox (-v 52.2.0, tested on two different linux machines).
Doing some debugging I ended up here, the do-while never halts. Placing some console.log calls in the code I got the following:

do {
	range.push(new Date(+start));
	if (_dbgstop++ >= 100) {
		throw 'stop';
	}
	console.log(start.toISOString());
	offseti(start, step);
	console.log(start.toISOString());
	floori(start);
	console.log(start.toISOString());
	console.log(stop, start < stop);
} while (start < stop);

firefox:

 d3.timeWeek.range(
    new Date(2017, 6, 10),
    new Date(2017, 9, 10)
);
2017-07-16T03:00:00.000Z  d3-time.js:45:3
2017-07-23T03:00:00.000Z  d3-time.js:47:3
2017-07-23T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-07-23T03:00:00.000Z  d3-time.js:45:3
2017-07-30T03:00:00.000Z  d3-time.js:47:3
2017-07-30T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-07-30T03:00:00.000Z  d3-time.js:45:3
2017-08-06T03:00:00.000Z  d3-time.js:47:3
2017-08-06T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-08-06T03:00:00.000Z  d3-time.js:45:3
2017-08-13T03:00:00.000Z  d3-time.js:47:3
2017-08-13T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-08-13T03:00:00.000Z  d3-time.js:45:3
2017-08-20T03:00:00.000Z  d3-time.js:47:3
2017-08-20T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-08-20T03:00:00.000Z  d3-time.js:45:3
2017-08-27T03:00:00.000Z  d3-time.js:47:3
2017-08-27T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-08-27T03:00:00.000Z  d3-time.js:45:3
2017-09-03T03:00:00.000Z  d3-time.js:47:3
2017-09-03T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-09-03T03:00:00.000Z  d3-time.js:45:3
2017-09-10T03:00:00.000Z  d3-time.js:47:3
2017-09-10T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-09-10T03:00:00.000Z  d3-time.js:45:3
2017-09-17T03:00:00.000Z  d3-time.js:47:3
2017-09-17T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-09-17T03:00:00.000Z  d3-time.js:45:3
2017-09-24T03:00:00.000Z  d3-time.js:47:3
2017-09-24T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-09-24T03:00:00.000Z  d3-time.js:45:3
2017-10-01T03:00:00.000Z  d3-time.js:47:3
2017-10-01T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-10-01T03:00:00.000Z  d3-time.js:45:3
2017-10-08T03:00:00.000Z  d3-time.js:47:3
2017-10-08T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-10-08T03:00:00.000Z  d3-time.js:45:3
2017-10-15T02:00:00.000Z  d3-time.js:47:3
2017-10-08T03:00:00.000Z  d3-time.js:49:3
Date 2017-10-10T03:00:00.000Z true  d3-time.js:50:3
2017-10-08T03:00:00.000Z  d3-time.js:45:3
2017-10-15T02:00:00.000Z  d3-time.js:47:3
2017-10-08T03:00:00.000Z
.... (more of the same)
Error: stop

so offseti increases 2017-10-08T03:00:00.000Z to 2017-10-15T02:00:00.000Z and then floori decreases it back to 2017-10-08T03:00:00.000Z and this keeps going on forever.

for chrome we have:

(sameas ff)...
2017-09-24T03:00:00.000Z
d3-time.js:47 2017-10-01T03:00:00.000Z
d3-time.js:49 2017-10-01T03:00:00.000Z
d3-time.js:50 Tue Oct 10 2017 00:00:00 GMT-0300 (-03) true
d3-time.js:45 2017-10-01T03:00:00.000Z
d3-time.js:47 2017-10-08T03:00:00.000Z
d3-time.js:49 2017-10-08T03:00:00.000Z
d3-time.js:50 Tue Oct 10 2017 00:00:00 GMT-0300 (-03) true
d3-time.js:45 2017-10-08T03:00:00.000Z
d3-time.js:47 2017-10-15T03:00:00.000Z
d3-time.js:49 2017-10-15T03:00:00.000Z
d3-time.js:50 Tue Oct 10 2017 00:00:00 GMT-0300 (-03) false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions