HtmlUnit / htmlunit

HtmlUnit is a "GUI-Less browser for Java programs".
https://www.htmlunit.org
Apache License 2.0
878 stars 172 forks source link

Setting Symbol.species should change the return value of constructor #239

Open RuralHunter opened 4 years ago

RuralHunter commented 4 years ago

According the spec, if Symbol.species is set, the return value of constructor should be the value of Symbol.species. It seems rhino doesn't do this.

Test case:

            var emptyFunc=function() {};
            var p = Promise.resolve(1);
            p.constructor = {};
            var pt1=p.then(emptyFunc);
            console.log('pt1='+pt1);

            var t = function(e) {
                e(emptyFunc, emptyFunc);
            };
            p.constructor[Symbol.species] = t;
            var pt2=p.then(emptyFunc);
            console.log('pt2='+pt2);
            console.log(pt2 instanceof t);

In htmlunit the output is:

pt1=[object Promise]
pt2=[object Promise]
false

In real browser such as chrome, the output is:

pt1=[object Promise]
pt2=[object Object]
true
RuralHunter commented 4 years ago

This maybe can be handled in Promise. The use cases of Symbol.species is here

RuralHunter commented 4 years ago

https://exploringjs.com/es6/ch_classes.html#sec_species-pattern

rbri commented 8 months ago

see #755