Re: JSON-LD API w/DOM Futures implemented

On 04/25/2013 05:08 AM, Markus Lanthaler wrote:
> On Thursday, April 25, 2013 12:11 AM, Dave Longley wrote:
>> The WebIDL test ( fails 3
>> additional tests now (more than it failed before). The reason for
>> these failures is that it's unclear how exceptions should be raised by
>> a WebIDL function that returns a Future. It could be that there is a
>> bug in the test harness code -- and it should be trying to resolve the
>> returned Future and look for an error there, instead of trying to
>> catch one. Hopefully, this is the case.
> I've fixed all but one failing test (the stringification of
> JsonLdProcessor.prototype still fails).
> I think you refer to the three that check the parameters. I believe that's
> an error in your implementation. If you have a function like
>     Future expand (JsonLdInput input, optional JsonLdOptions options);
> and you call it without any parameters (expand()) it should throw an
> TypeError instead of returning a Future. You have to keep in mind that these
> things will most of the time be implemented in C++. You can't just omit a
> parameter in that case.

The problem is that it is unclear when that error should be thrown. When 
using Futures, it is expected that any errors will propagate via the 
Future's rejection API -- when an attempt is made to resolve the Future. 
It might be incorrect to throw TypeErrors prior to trying to resolve the 
Future. If the behavior is as you changed, then it will cause a lot of 
headache (code duplication) for APIs that are wrapped using Futures, as 
their errors will be passed via callback (eventually to the Future's 
rejected() callback), not immediately thrown. There may be other 
headaches like mixing try/catch with rejection callbacks during 
chaining. It's unclear how a C++ implementation for this would work -- 
it may always generate a Future that will be rejected in this case.

>> In any case, the first implementation of the JSON-LD API using Futures
>> is now live on the playground.
> Awesome.. and it now passes 15 of the 16 tests. Do you think it would make
> sense to extend the this test suite to include all other JSON-LD tests and
> to automatically generate the implementation report? This could then be used
> to verify JSON-LD API Implementations.
> I think it would be quite simple to port the tests you already have to
> testharness.js. The doc is here:

That could probably be done. Unfortunately, I don't have the time to do 
it myself right now, but if someone else wants to try it out, it may be 
a good idea.

> --
> Markus Lanthaler
> @markuslanthaler

Dave Longley
Digital Bazaar, Inc.

Received on Thursday, 25 April 2013 15:52:48 UTC