question about Execute Script

Hi again,

Another question. I’m reading Execute Script <https://w3c.github.io/webdriver/webdriver-spec.html#execute-script>, Step 4:

> 4. Let promise be a new Promise.

OK, so we’ve got a Promise called promise. In subsequent steps, we see how promise might be rejected. We also see what we are supposed to do if promise is fulfilled:

> 7. Upon fulfillment of promise with value v, return success with data v.

My question is: how could promise ever be fulfilled? We do not pass promise into the promise-calling step (we only pass in the body and arguments arguments), and we never mention any scenario that contains “… fulfill promise with x…”.

I would have expected that we need to somehow link promise with the result, potentially even just overwriting promise with result since AFAICT result is itself a Promise.

A similar question comes up for this line (substep 2 of step 5):

> 2. If result is an error, reject promise with result.

How could result ever be an error? Looking at the promise-calling algorithm <https://www.w3.org/2001/tag/doc/promises-guide#promise-calling> linked from the spec, I make two notes:

1. No error could ever be returned from this, strictly speaking. An error could be thrown (and caught from the outside), but only an error in the Promise.reject method itself (whose code we can assume is correct and will not throw)
2. Any error thrown in the user-submitted function is caught and returned as a rejected Promise

So in my reading, result would always be a Promise, either fulfilled, rejected, or pending. That makes the conditional “if result is an error” seem odd or imprecise, since result is a Promise and a Promise is not an Error.

If I’m right about all of this (about which I have some doubt), I would propose to do away with the promise variable entirely, and just work with result. Then the only change necessary is to do away with the second substep of step 5, since that case (result being rejected) is already handled in step 8.

Cheers,
Jonathan

Received on Wednesday, 11 October 2017 22:59:59 UTC