2013/4/26 Tab Atkins Jr. <jackalmage@gmail.com>
> On Fri, Apr 26, 2013 at 11:25 AM, Kevin Smith <zenparsing@gmail.com>
> wrote:
> > Actually, I may have gotten it terribly wrong (apologies). In my
> prototype
> > implementation, the following:
> >
> > Future.accept(Future.resolve(1)).then(value => {
> >
> > console.log(value !== 1);
> > return Future.accept(Future.resolve(1));
> >
> > }).then(value => {
> >
> > console.log(value === 1);
> > });
> >
> > logs
> >
> > - true
> > - true
> >
> > Is that what it should be doing, according to the DOM spec? Anne, Alex?
>
> No, it should be "true", then "false".
>
> I think Kevin's assertion is correct. According to the spec, callbacks are
wrapped in something called a "future wrapper callback". When a promise is
returned from the callback, the wrapper does this:
Let value be the result of invoking callback with argument as argument.
> (...) run resolver's *resolve *with value and the synchronous flag set.
*resolve* tries to adopt the promise by being recursive, effectively
flattening the promise:
>
> - If value is a JavaScript Object, set then to the result of calling
> the JavaScript [[Get]] internal method of value with property name then.
> - If JavaScript IsCallable(then) is true *[treats all thenables the
> same way]*, run these substeps and then terminate these steps:
> - Call the JavaScript [[Call]] internal method of then with this value
> value and *resolve *and *reject *as arguments.
>
> If resolved called the thenable's then() with *accept *and reject, it
would only unwrap one layer.
Juan