GithubHelp home page GithubHelp logo

Promise 'then' incorrect? about es6-shim HOT 10 CLOSED

Xotic750 avatar Xotic750 commented on September 6, 2024
Promise 'then' incorrect?

from es6-shim.

Comments (10)

Xotic750 avatar Xotic750 commented on September 6, 2024 1

No, I'm not. I was just running the raw implementation (which as you said, is not designed for this purpose) for interest sake, and came across this and was curious as to why it was failing. Now I understand why, and learnt some stuff in the process. As you rightly point out, this case should never happen within the design of es6-shim.

from es6-shim.

cscott avatar cscott commented on September 6, 2024

Those lines match the spec, eg: https://www.ecma-international.org/ecma-262/6.0/#sec-promise.prototype.then

I believe the real issue is that the ES.SpeciesConstructor method is broken -- and I bet it has something to do with your runtime environment partially implementing Species support and thus fooling the shim. What platform are you running the tests on?

from es6-shim.

Xotic750 avatar Xotic750 commented on September 6, 2024

I'm on Node 8.11.4, but I tried on 10 and 12 too. What I did was at

https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L2624

I added globals.PromiseShim = PromiseShim;

Screenshot 2019-08-03 at 02 05 35

This gives me the implementation on the global.

then in subclass.js

I replaced Promise with PromiseShim to use the implementation.

Screenshot 2019-08-03 at 02 02 37

So, I kind of expected the implementation to pass all tests, perhaps there is is a good reason why it does not. But making those changes in my original post this.constructor, then the tests pass.

Why would I do this you ask, well I was interested about the inner workings of Promise, and I'm a tinkerer. :)

from es6-shim.

ljharb avatar ljharb commented on September 6, 2024

The shims are not designed to be manually installed; if you just replace the global Promise, many things won't work - since that full replacement is only meant to be used on nodes that never had it to begin with.

from es6-shim.

ljharb avatar ljharb commented on September 6, 2024

In other words, the es6-shim must be used in its entirety, or not at all.

from es6-shim.

Xotic750 avatar Xotic750 commented on September 6, 2024

I appreciate that the library is to be used in its entirety. This is something that I came across while experimenting. Still, I find it strange that this should fail, and I thought it was worth mentioning.

from es6-shim.

Xotic750 avatar Xotic750 commented on September 6, 2024

Ok, so PromiseShim does not define Symbol.species. That seems to be the answer?

from es6-shim.

ljharb avatar ljharb commented on September 6, 2024

Sure - I assume because that symbol doesn't exist where Promise needs to be wholesale replaced.

from es6-shim.

Xotic750 avatar Xotic750 commented on September 6, 2024

Yep, I added to PromiseShim

    if (supportsDescriptors) {
      Object.defineProperty(Promise, symbolSpecies, {
        configurable: false,
        enumerable: false,
        get: function() {
          return this;
        }
      });
    } else {
      object[symbolSpecies] = function() {
        return this;
      };
    }

https://www.ecma-international.org/ecma-262/6.0/#sec-get-promise-@@species
and now all tests pass.

So my question is answered. I'm not saying anything is broken in the shim, as it works, but worth a note.

from es6-shim.

ljharb avatar ljharb commented on September 6, 2024

If you’re suggesting there’s an engine which, after including the entire es6-shim, has Symbol.species but doesn’t have it on Promise, then i would consider that a bug.

from es6-shim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.