W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2013

Re: Feature-detectable API extensions?

From: Joshua Bell <jsbell@google.com>
Date: Tue, 27 Aug 2013 14:23:58 -0700
Message-ID: <CAD649j5oStp6KSJ1hEtbxwF_dcFe0d6D7KYmL97EM6R0KOpczg@mail.gmail.com>
To: Brendan Eich <brendan@secure.meer.net>
Cc: public-script-coord <public-script-coord@w3.org>
On Tue, Aug 27, 2013 at 1:46 PM, Brendan Eich <brendan@secure.meer.net>wrote:

> Joshua Bell wrote:
>
>> We're considering extending an existing method on a browser object with a
>> second, optional parameter. The API under consideration is the "continue"
>> method on the IDBCursor in the Indexed DB API, but I'm interested in
>> general thoughts.
>>
>> Existing code, or that didn't need the new capabilities would use:
>>
>> myCursor.continue("my key");
>>
>> New code that needed the extra capabilities could use:
>>
>> myCursor.continue("my key", {primaryKey: "my primary key"});
>>
>> Now the problem: the new call would fail silently on older
>> implementations; it would yield a value that would be incorrect, but not in
>> a way that's trivial to detect.
>>
>
> That says this is a backward-incompatible extension.
>
>
>  How should the API be designed to allow feature detection, without
>> "designing for the past" ?
>>
>> Various solutions:
>>
>> * Use a new method, e.g. continueWithPrimaryKey(), and detect with
>> ('continueWithPrimaryKey' in IDBCursor)
>>
>
> This works best. Is a polyfill possible?
>
>
That points out an issue with extensibility of the Indexed DB API here. The
the result of a continue() call is delivered asynchronously to a previously
created "request" object handed to script when the cursor was created; the
request is known internally by the cursor but there's no path from cursor
to request from script. A polyfill would need to wrap several other methods
such as openCursor(), and would rely on unhooking existing event handlers
from the request while it's doing manual iteration.


>  * Rely on a library like Modernizr to implement a test - in this case, by
>> creating a scratch database, populating it with data, and probing the
>> behavior; doable, but with a minimum of 3 turns of the event loop (open
>> database, populate+open cursor, call continue, check result)
>>
>
> Lost me after "Rely on" ;-).
>
>
>  * Change the method signature in such a way that it would throw an
>> exception in older implementations, e.g. continue({key: ..., primaryKey:
>> ...}).
>>
>> Note that the last approach works this time we upgrade the API because
>> passing an object happens to throw with the existing API, but that approach
>> would fail next time we upgrade the API to take yet another optional param.
>>
>
> Seems bogus to switch from n-ary when n goes past 1 back to 1-ary with
> parameters passed in an object.
>
>
Good advice; Jonas, weren't you prototyping open(dictionary) to handle
specifying storage type and other options?


> New method wins cleanly in my view, with zero doubt if polyfills are
> doable (they do not have to be "perfect").
>
> /be
>
>
Received on Tuesday, 27 August 2013 21:31:59 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:50 UTC