Numeric identifiers of events are not guaranteed to be unique
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 21:49:20 +0000 (21:49 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 21:49:20 +0000 (21:49 +0000)
commit1a616166db0323b9c830c03f013f4062a951fd05
treeb19654d841d9c2f412ff4030b1c24cff7033a58e
parente22ac5237344915e15bcd403f6bd8beb0cd65187
Numeric identifiers of events are not guaranteed to be unique
https://bugs.webkit.org/show_bug.cgi?id=103259

Patch by Cosmin Truta <ctruta@rim.com> on 2013-02-14
Reviewed by Alexey Proskuryakov.

The results of setTimeout, setInterval and navigator.geolocation.watchPosition
are positive integer values extracted from a simple circular sequential number
generator, whose uniqueness can be guaranteed for no more than 2^31 calls to
any of these functions. In order to provide this guarantee beyond this limit,
we repeatedly ask for the next sequential id until we get one that's not used
already.

This solution works instantly under normal circumstances, when there are few
live timeout ids or geolocation ids at any given moment. Handling millions of
live ids will require another solution.

No new tests. Brief tests of uniqueness already exist.
Moreover, reproducing this particular issue would require 2^31 set/clear
function calls, which is prohibitively expensive.

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::Watchers::add): Rename from Watchers::set; return false if watch id already exists.
(WebCore::Geolocation::watchPosition): Repeat until the new watch id is unique.
* Modules/geolocation/Geolocation.h:
(Watchers): Rename Watchers::set to Watchers::add.
* Modules/geolocation/Geolocation.idl: Rename the argument of Geolocation::clearWatch to WatchID.
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::ScriptExecutionContext): Update initialization.
(WebCore::ScriptExecutionContext::circularSequentialID): Rename from newUniqueID; remove FIXME note.
* dom/ScriptExecutionContext.h:
(ScriptExecutionContext): Rename ScriptExecutionContext::newUniqueID to ScriptExecutionContext::circularSequentialID.
(WebCore::ScriptExecutionContext::addTimeout): Return false (do not assert) if timeout id already exists.
* page/DOMTimer.cpp:
(WebCore::DOMTimer::DOMTimer): Repeat until the new timeout id is unique.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142909 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/Modules/geolocation/Geolocation.cpp
Source/WebCore/Modules/geolocation/Geolocation.h
Source/WebCore/Modules/geolocation/Geolocation.idl
Source/WebCore/dom/ScriptExecutionContext.cpp
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/page/DOMTimer.cpp