Closed Bamieh closed 6 years ago
What is input for a promise? Promises just contain values, there is no input.
@rpominov So bare with me here, what is a promise? a promise is a function that takes a resolver function as input and calls it passing resolve
and reject
to the resolver
as params. hence when calling:
var a = new Promise(function resolver(resolve, reject) {
resolve('value');
});
The input is the resolver
function here. For two promises to be equally the same, the input resolver
functions must be equivalent.
The Promise return must be equivalent as well, which is something similar to
Promise {<resolved>: "value"}
And the promise yield is the result returned in the then
payload, this also must be equivalent.
Looking at v8 code, here is how a promise is defined:
var $Promise = function Promise(resolver) {
if (resolver === promiseRaw) return;
if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]);
if (!IS_SPEC_FUNCTION(resolver))
...
///src: https://chromium.googlesource.com/v8/v8/+/3.29.45/src/promise.js?autodive=0%2F#38
hence comes my definition of a promise input.
P.S. philosophical question here, if all instances have no inputs, they are all still required to all have equivalent inputs. 🤔
I think we're confusing the Promise constructor and promise instances. Yes, the promise constructor is a function that takes a resolver and returns a promise instance. But specification talks about promise instances, not constructors.
@rpominov yes indeed, as the only way to interact with a promise instance is to call a new promise.
A promise instance is a plain object with differing [[PromiseResult]]
internal slot values when they resolve. Since a promise instance is a plain object, i got confused, why the fantasyland spec adds any special explanation for it.
I will close this, thank you for your time.
Note that even if we were dealing with constructors, Rice's Theorem shows that there is no general way to determine whether two functions are equivalent.
@CrossEye thanks, i'll have a look at it
Two promises are equivalent when they yield equivalent values for equivalent inputs.