AP2 bugs

Nathan Wall nathan.wall at live.com
Sat Aug 31 09:03:12 PDT 2013


Hi, I do not know if this is the correct list to discuss these things. If it is not, please redirect me.

I have done some work on implementing the AP2 draft I could find here http://github.com/domenic/promises-unwrapping and I have a few potential bugs to report.  If this is not the latest draft, please direct me to the appropriate resource to use.

My implementation is available at http://gist.github.com/anonymous/6399102

## UpdateDerived

**UpdateDerived** step 2.1 says:

    If IsObject(originator.[[Value]]), queue a microtask to run the following:

Am I correct to understand that "queue a microtask" means that the task should be run asynchronously?  For this, I am currently using a function called `defer(f)` which is just a wrapper around `setTimeout(f, 0)`.

Using this code as an example:

    var p = new Promise(function(resolve, reject) {
        resolve('a');
    });

    p.then(function(value) {
       console.log(2, value);
    });

    console.log(1);

I would expect the output to be:

    1
    2 a

The way the draft is currently written (as shown in this gist http://gist.github.com/anonymous/6399102 ), the code above will instead log:

    2 a
    1

However, this code:

    var p = new Promise(function(resolve, reject) {
        resolve({ value: 'a' });
    });

    p.then(function(value) {
       console.log(2, value);
    });

    console.log(1);

will log:

    1
    2 { value: 'a' }

because the "queue a microtask" only happens when the promise is resolved with an object.

I think that "queue a microtask" should be around everything after step 1 in **UpdateDerived** instead, as seen in this gist http://gist.github.com/anonymous/6399033 which will log the values in the expected order.

## UpdateFromReason -> UpdateDerivedFromReason

Additionally, there's a typo where a function named **UpdateFromReason** is defined. I think it is intended to be called **UpdateDerivedFromReason**, as that's what it's called elsewhere in the document.

I welcome any comments on my implementation as well.

Nathan 		 	   		  


More information about the es-discuss mailing list