Instance of Promise subclass throws error on then method call
Reported by
drol...@yahoo.com,
Apr 6 2017
|
||||
Issue description
UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
Steps to reproduce the problem:
1. Create a class that extends Promise:
class Test extends Promise {
constructor(){super(resolve=>resolve("test"));}
}
2. Instantiate class: var test = new Test();
3. Call then method on instance: test.then(console.log);
What is the expected behavior?
The string "test" is logged to the console. This is the result in FireFox.
What went wrong?
"Uncaught TypeError: Promise resolve or reject function is not callable" is thrown on call to "test.then".
Did this work before? N/A
Chrome version: 57.0.2987.133 Channel: stable
OS Version: Ubuntu 16.04 LTS
Flash Version:
,
Apr 7 2017
,
Apr 12 2017
Adam/Sathya is this expected behavior?
,
Apr 12 2017
This behavior is spec compliant. A derived Promise constructor should accept an executor function as per -- https://tc39.github.io/ecma262/#sec-newpromisecapability A TypeError is thrown in Safari and Firefox as well. Closing this as WAI, please feel free reopen with a working test case.
,
Apr 12 2017
Firefox (52.0.2 (64-bit) for Ubuntu) does not throw a TypeError when using the constructor as described above. I can't speak to Safari. In Chrome, it's necessary to pass the executor function to the subclass constructor AND call that executor (even if a different function was passed with super and calling the executor has no impact).
For example, calling
new Test((resolve,reject)=>resolve("wrong")).then(console.log)
results in "test" printing to console in Chrome with the following class:
class Test extends Promise {
constructor(executor){
super((resolve,reject)=>
{
executor(()=>null,()=>null);
resolve('test');
});
}
}
while the TypeError is thrown with the following class:
class Test extends Promise {
constructor(executor){
super((resolve,reject)=>
{
resolve('test');
});
}
}
In Firefox, both of these subclasses work without error.
Is Chrome's implementation correct?
,
Apr 12 2017
Chrome's implementation is correct, the second subclass in your example should throw a TypeError. Firefox's implementation seems to reflect Chrome's implementation. Your second subclass does throw a TypeError in Firefox 52 for me. |
||||
►
Sign in to add a comment |
||||
Comment 1 by schenney@chromium.org
, Apr 6 2017